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
@@ -1,237 +0,0 @@
|
|
1
|
-
import { ComponentInternalInstance, h } from 'vue'
|
2
|
-
import { AlexEditor, AlexElement, AlexElementsRangeType } from 'alex-editor'
|
3
|
-
import { event as DapEvent, common as DapCommon } from 'dap-util'
|
4
|
-
import { ObjectType, PluginType } from '@/core/tool'
|
5
|
-
import Button from '@/components/button/button.vue'
|
6
|
-
import Icon from '@/components/icon/icon.vue'
|
7
|
-
import InsertAttachment from './insertAttachment/insertAttachment.vue'
|
8
|
-
import { InsertAttachmentUploadErrorType } from './insertAttachment/props'
|
9
|
-
import { hasPreInRange } from '@/core/function'
|
10
|
-
import { hasMathformulaInRange } from '@/plugins/mathformula'
|
11
|
-
|
12
|
-
export type AttachmentOptionsType = {
|
13
|
-
//排序
|
14
|
-
sequence?: number
|
15
|
-
//工具提示内容
|
16
|
-
title?: string
|
17
|
-
//按钮是否显示左侧边框
|
18
|
-
leftBorder?: boolean
|
19
|
-
//按钮是否显示右侧边框
|
20
|
-
rightBorder?: boolean
|
21
|
-
//按钮是否禁用
|
22
|
-
disabled?: boolean
|
23
|
-
//定义可选择的文件类型,默认不限制类型,设定此参数后选择文件时会自动过滤非符合的文件类型
|
24
|
-
accept?: string
|
25
|
-
//支持的类型数组
|
26
|
-
allowedFileType?: string[]
|
27
|
-
//是否多选
|
28
|
-
multiple?: boolean
|
29
|
-
//选择的单个文件最大值,单位kb,不设置将不限制
|
30
|
-
maxSize?: number
|
31
|
-
//选择的单个文件最小值,单位kb,不设置将不限制
|
32
|
-
minSize?: number
|
33
|
-
//是否自定义上传附件
|
34
|
-
customUpload?: ((files: File[]) => string[]) | ((files: File[]) => Promise<string[]>)
|
35
|
-
//处理上传附件异常
|
36
|
-
handleError?: (error: InsertAttachmentUploadErrorType, file: File) => void
|
37
|
-
}
|
38
|
-
|
39
|
-
/**
|
40
|
-
* 元素是否附件
|
41
|
-
* @param element
|
42
|
-
* @returns
|
43
|
-
*/
|
44
|
-
export const isAttachment = (element: AlexElement) => {
|
45
|
-
if (element.isEmpty()) {
|
46
|
-
return false
|
47
|
-
}
|
48
|
-
return element.parsedom == 'span' && element.type == 'closed' && element.hasMarks() && element.marks!['data-editify-attachment']
|
49
|
-
}
|
50
|
-
|
51
|
-
/**
|
52
|
-
* 选区是否含有附件
|
53
|
-
* @param editor
|
54
|
-
* @param dataRangeCaches
|
55
|
-
* @returns
|
56
|
-
*/
|
57
|
-
export const hasAttachmentInRange = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType) => {
|
58
|
-
if (!editor.range) {
|
59
|
-
return false
|
60
|
-
}
|
61
|
-
if (editor.range.anchor.isEqual(editor.range.focus)) {
|
62
|
-
return isAttachment(editor.range.anchor.element)
|
63
|
-
}
|
64
|
-
return dataRangeCaches.flatList.some(item => {
|
65
|
-
return isAttachment(item.element)
|
66
|
-
})
|
67
|
-
}
|
68
|
-
|
69
|
-
/**
|
70
|
-
* 附件插件
|
71
|
-
* @param options
|
72
|
-
* @returns
|
73
|
-
*/
|
74
|
-
export const attachment = (options?: AttachmentOptionsType) => {
|
75
|
-
if (!DapCommon.isObject(options)) {
|
76
|
-
options = {}
|
77
|
-
}
|
78
|
-
const plugin: PluginType = (editifyInstance: ComponentInternalInstance, editTrans: (key: string) => any) => {
|
79
|
-
let isDisabled = false
|
80
|
-
//如果光标选区内有数学公式、代码块则禁用
|
81
|
-
if (editifyInstance.exposed!.editor.value) {
|
82
|
-
isDisabled = hasMathformulaInRange(editifyInstance.exposed!.editor.value, editifyInstance.exposed!.dataRangeCaches.value) || hasPreInRange(editifyInstance.exposed!.editor.value, editifyInstance.exposed!.dataRangeCaches.value)
|
83
|
-
}
|
84
|
-
return {
|
85
|
-
name: 'attachment',
|
86
|
-
//附件菜单项配置
|
87
|
-
menu: {
|
88
|
-
sequence: options!.sequence || 100,
|
89
|
-
extraDisabled: (name: string) => {
|
90
|
-
//如果光标选区内有附件则禁用链接菜单、代码块菜单
|
91
|
-
if (name == 'link' || name == 'codeBlock') {
|
92
|
-
return hasAttachmentInRange(editifyInstance.exposed!.editor.value, editifyInstance.exposed!.dataRangeCaches.value)
|
93
|
-
}
|
94
|
-
return false
|
95
|
-
},
|
96
|
-
extend: {
|
97
|
-
type: 'select',
|
98
|
-
title: options!.title || editTrans('insertAttachment'),
|
99
|
-
leftBorder: options!.leftBorder,
|
100
|
-
rightBorder: options!.rightBorder,
|
101
|
-
hideScroll: true,
|
102
|
-
active: false,
|
103
|
-
disabled: isDisabled || options!.disabled,
|
104
|
-
default: () => h(Icon, { value: 'attachment' }),
|
105
|
-
layer: (_name: string, btnInstance: InstanceType<typeof Button>) =>
|
106
|
-
h(InsertAttachment, {
|
107
|
-
color: <string | null>editifyInstance.props.color,
|
108
|
-
accept: options!.accept,
|
109
|
-
allowedFileType: options!.allowedFileType || [],
|
110
|
-
multiple: !!options!.multiple,
|
111
|
-
maxSize: options!.maxSize,
|
112
|
-
minSize: options!.minSize,
|
113
|
-
customUpload: options!.customUpload,
|
114
|
-
handleError: options!.handleError,
|
115
|
-
onChange: () => {
|
116
|
-
btnInstance.layerRef!.setPosition()
|
117
|
-
},
|
118
|
-
onInsert: (name: string, urls: string[]) => {
|
119
|
-
//过滤掉空的地址
|
120
|
-
urls = urls.filter(url => {
|
121
|
-
return !!url
|
122
|
-
})
|
123
|
-
//如果有地址存在
|
124
|
-
if (urls.length) {
|
125
|
-
//获取editor对象
|
126
|
-
const editor = <AlexEditor>editifyInstance.exposed!.editor.value
|
127
|
-
//遍历地址数组
|
128
|
-
urls.forEach(url => {
|
129
|
-
const marks: ObjectType = {
|
130
|
-
'data-editify-attachment': url,
|
131
|
-
'data-editify-attachment-name': name || editTrans('attachmentDefaultName')
|
132
|
-
}
|
133
|
-
//创建元素
|
134
|
-
const attachmentElement = AlexElement.create({
|
135
|
-
type: 'closed',
|
136
|
-
parsedom: 'span',
|
137
|
-
marks
|
138
|
-
})
|
139
|
-
//插入编辑器
|
140
|
-
editor.insertElement(attachmentElement)
|
141
|
-
//移动光标到新插入的元素
|
142
|
-
editor.range!.anchor.moveToEnd(attachmentElement)
|
143
|
-
editor.range!.focus.moveToEnd(attachmentElement)
|
144
|
-
})
|
145
|
-
//渲染
|
146
|
-
editor.formatElementStack()
|
147
|
-
editor.domRender()
|
148
|
-
editor.rangeRender()
|
149
|
-
}
|
150
|
-
//关闭浮层
|
151
|
-
btnInstance.show = false
|
152
|
-
}
|
153
|
-
})
|
154
|
-
}
|
155
|
-
},
|
156
|
-
//找到附件元素点击下载
|
157
|
-
updateView: () => {
|
158
|
-
const editor = <AlexEditor>editifyInstance.exposed!.editor.value
|
159
|
-
AlexElement.flatElements(editor.stack).forEach(el => {
|
160
|
-
if (el.parsedom == 'span' && el.hasMarks() && el.marks!['data-editify-attachment']) {
|
161
|
-
DapEvent.off(<HTMLElement>el.elm, 'click')
|
162
|
-
//单击下载
|
163
|
-
DapEvent.on(<HTMLElement>el.elm, 'click', async () => {
|
164
|
-
//获取文件地址
|
165
|
-
const url = el.marks!['data-editify-attachment']
|
166
|
-
//使用fetch读取文件地址
|
167
|
-
const res = await fetch(url, {
|
168
|
-
method: 'GET'
|
169
|
-
})
|
170
|
-
//获取blob数据
|
171
|
-
const blob = await res.blob()
|
172
|
-
//创建a标签进行下载
|
173
|
-
const a = document.createElement('a')
|
174
|
-
a.setAttribute('target', '_blank')
|
175
|
-
a.setAttribute('href', URL.createObjectURL(blob))
|
176
|
-
a.setAttribute('download', el.marks!['data-editify-attachment-name'])
|
177
|
-
a.click()
|
178
|
-
})
|
179
|
-
}
|
180
|
-
})
|
181
|
-
},
|
182
|
-
//span含有data-editify-attachment的元素设为自闭合元素
|
183
|
-
customParseNode: (el: AlexElement) => {
|
184
|
-
if (el.hasMarks() && el.marks!['data-editify-attachment'] && el.parsedom == 'span') {
|
185
|
-
el.type = 'closed'
|
186
|
-
}
|
187
|
-
return el
|
188
|
-
},
|
189
|
-
//附件文件自定义保留的标记
|
190
|
-
pasteKeepMarks: el => {
|
191
|
-
const marks: ObjectType = {}
|
192
|
-
if (el.parsedom == 'span' && el.hasMarks() && el.marks!['data-editify-attachment']) {
|
193
|
-
marks['data-editify-attachment'] = el.marks!['data-editify-attachment']
|
194
|
-
if (el.marks!['data-editify-attachment-name']) {
|
195
|
-
marks['data-editify-attachment-name'] = el.marks!['data-editify-attachment-name']
|
196
|
-
}
|
197
|
-
}
|
198
|
-
return marks
|
199
|
-
},
|
200
|
-
//自定义渲染规范
|
201
|
-
renderRule: (el: AlexElement) => {
|
202
|
-
if (el.hasMarks() && el.marks!['data-editify-attachment']) {
|
203
|
-
//设置title
|
204
|
-
el.marks!['title'] = editTrans('attachmentDownloadTitle')
|
205
|
-
//如果名称没有则设置名称
|
206
|
-
if (!el.marks!['data-editify-attachment-name']) {
|
207
|
-
el.marks!['data-editify-attachment-name'] = editTrans('attachmentDefaultName')
|
208
|
-
}
|
209
|
-
//获取editor对象
|
210
|
-
const editor = <AlexEditor>editifyInstance.exposed!.editor.value
|
211
|
-
//前一个元素
|
212
|
-
const previousElement = editor.getPreviousElement(el)
|
213
|
-
//后一个元素
|
214
|
-
const newTextElement = editor.getNextElement(el)
|
215
|
-
//如果不存在前一个元素或者前一个元素不是空白元素则设置空白元素
|
216
|
-
if (!previousElement || !previousElement.isSpaceText()) {
|
217
|
-
const spaceText = AlexElement.getSpaceElement()
|
218
|
-
editor.addElementBefore(spaceText, el)
|
219
|
-
}
|
220
|
-
//如果不存在后一个元素或者后一个元素不是空白元素则设置空白元素
|
221
|
-
if (!newTextElement || !newTextElement.isSpaceText()) {
|
222
|
-
const spaceText = AlexElement.getSpaceElement()
|
223
|
-
editor.addElementAfter(spaceText, el)
|
224
|
-
}
|
225
|
-
//如果光标在元素上则更新光标位置
|
226
|
-
if (editor.range && el.isContains(editor.range.anchor.element)) {
|
227
|
-
editor.range.anchor.moveToEnd(editor.getNextElement(el)!)
|
228
|
-
}
|
229
|
-
if (editor.range && el.isContains(editor.range.focus.element)) {
|
230
|
-
editor.range.focus.moveToEnd(editor.getNextElement(el)!)
|
231
|
-
}
|
232
|
-
}
|
233
|
-
}
|
234
|
-
}
|
235
|
-
}
|
236
|
-
return plugin
|
237
|
-
}
|
@@ -1,238 +0,0 @@
|
|
1
|
-
import { common as DapCommon, color as DapColor } from 'dap-util'
|
2
|
-
import { ComponentInternalInstance, h } from 'vue'
|
3
|
-
import { AlexEditor, AlexElement, AlexElementsRangeType } from 'alex-editor'
|
4
|
-
import { PluginType } from '@/core/tool'
|
5
|
-
import Icon from '@/components/icon/icon.vue'
|
6
|
-
import { elementToParagraph, hasPreInRange, hasTableInRange } from '@/core/function'
|
7
|
-
import { hasPanelInRange } from '@/plugins/panel'
|
8
|
-
|
9
|
-
export type InfoBlockOptionsType = {
|
10
|
-
//排序
|
11
|
-
sequence?: number
|
12
|
-
//工具提示内容
|
13
|
-
title?: string
|
14
|
-
//按钮是否显示左侧边框
|
15
|
-
leftBorder?: boolean
|
16
|
-
//按钮是否显示右侧边框
|
17
|
-
rightBorder?: boolean
|
18
|
-
//按钮是否禁用
|
19
|
-
disabled?: boolean
|
20
|
-
}
|
21
|
-
|
22
|
-
/**
|
23
|
-
* 是否信息元素
|
24
|
-
* @param el
|
25
|
-
* @returns
|
26
|
-
*/
|
27
|
-
export const isInfoBlock = (el: AlexElement) => {
|
28
|
-
return el.parsedom == 'div' && el.hasMarks() && el.marks!['data-editify-info']
|
29
|
-
}
|
30
|
-
|
31
|
-
/**
|
32
|
-
* 判断某个元素是否在信息元素内
|
33
|
-
* @param el
|
34
|
-
* @returns
|
35
|
-
*/
|
36
|
-
export const isUnderInfoBlock = (el: AlexElement): boolean => {
|
37
|
-
if (isInfoBlock(el)) {
|
38
|
-
return true
|
39
|
-
}
|
40
|
-
if (el.parent) {
|
41
|
-
return isUnderInfoBlock(el.parent)
|
42
|
-
}
|
43
|
-
return false
|
44
|
-
}
|
45
|
-
|
46
|
-
/**
|
47
|
-
* 根据某个元素获取所在的信息元素,如果不在信息元素内则返回null
|
48
|
-
* @param el
|
49
|
-
* @returns
|
50
|
-
*/
|
51
|
-
export const getInfoBlockElement = (el: AlexElement): AlexElement | null => {
|
52
|
-
if (isInfoBlock(el)) {
|
53
|
-
return el
|
54
|
-
}
|
55
|
-
if (el.parent) {
|
56
|
-
return getInfoBlockElement(el.parent)
|
57
|
-
}
|
58
|
-
return null
|
59
|
-
}
|
60
|
-
|
61
|
-
/**
|
62
|
-
* 选区是否含有信息元素
|
63
|
-
* @param editor
|
64
|
-
* @param dataRangeCaches
|
65
|
-
* @returns
|
66
|
-
*/
|
67
|
-
export const hasInfoBlockInRange = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType) => {
|
68
|
-
if (!editor.range) {
|
69
|
-
return false
|
70
|
-
}
|
71
|
-
if (editor.range.anchor.isEqual(editor.range.focus)) {
|
72
|
-
return isUnderInfoBlock(editor.range.anchor.element)
|
73
|
-
}
|
74
|
-
return dataRangeCaches.flatList.some(item => {
|
75
|
-
return isUnderInfoBlock(item.element)
|
76
|
-
})
|
77
|
-
}
|
78
|
-
|
79
|
-
/**
|
80
|
-
* 选区是否都在信息块内
|
81
|
-
* @param editor
|
82
|
-
* @param dataRangeCaches
|
83
|
-
* @returns
|
84
|
-
*/
|
85
|
-
export const isRangeInInfoBlock = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType) => {
|
86
|
-
if (!editor.range) {
|
87
|
-
return false
|
88
|
-
}
|
89
|
-
if (editor.range.anchor.isEqual(editor.range.focus)) {
|
90
|
-
return isUnderInfoBlock(editor.range.anchor.element)
|
91
|
-
}
|
92
|
-
return dataRangeCaches.flatList.every(item => {
|
93
|
-
return isUnderInfoBlock(item.element)
|
94
|
-
})
|
95
|
-
}
|
96
|
-
|
97
|
-
/**
|
98
|
-
* 选区是否在某个信息元素下,如果是返回该信息元素否则返回null
|
99
|
-
* @param editor
|
100
|
-
* @param dataRangeCaches
|
101
|
-
* @returns
|
102
|
-
*/
|
103
|
-
export const getInfoBlockElementByRange = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType) => {
|
104
|
-
if (!editor.range) {
|
105
|
-
return null
|
106
|
-
}
|
107
|
-
if (editor.range.anchor.element.isEqual(editor.range.focus.element)) {
|
108
|
-
return getInfoBlockElement(editor.range.anchor.element)
|
109
|
-
}
|
110
|
-
const arr = dataRangeCaches.list.map(item => {
|
111
|
-
return getInfoBlockElement(item.element)
|
112
|
-
})
|
113
|
-
let hasNull = arr.some(el => {
|
114
|
-
return el == null
|
115
|
-
})
|
116
|
-
//如果存在null,则表示有的选区元素不在公式元素下,返回null
|
117
|
-
if (hasNull) {
|
118
|
-
return null
|
119
|
-
}
|
120
|
-
//如果只有一个元素,则返回该元素
|
121
|
-
if (arr.length == 1) {
|
122
|
-
return arr[0]!
|
123
|
-
}
|
124
|
-
//默认数组中的元素都相等
|
125
|
-
let flag = true
|
126
|
-
for (let i = 1; i < arr.length; i++) {
|
127
|
-
if (!arr[i]!.isEqual(arr[0]!)) {
|
128
|
-
flag = false
|
129
|
-
break
|
130
|
-
}
|
131
|
-
}
|
132
|
-
//如果相等,则返回该元素
|
133
|
-
if (flag) {
|
134
|
-
return arr[0]
|
135
|
-
}
|
136
|
-
return null
|
137
|
-
}
|
138
|
-
|
139
|
-
/**
|
140
|
-
* 信息插件
|
141
|
-
* @param options
|
142
|
-
* @returns
|
143
|
-
*/
|
144
|
-
export const infoBlock = (options?: InfoBlockOptionsType) => {
|
145
|
-
if (!DapCommon.isObject(options)) {
|
146
|
-
options = {}
|
147
|
-
}
|
148
|
-
const plugin: PluginType = (editifyInstance: ComponentInternalInstance, editTrans: (key: string) => any) => {
|
149
|
-
let isDisabled: boolean = false
|
150
|
-
//光标在表格、代码块和面板中则禁用
|
151
|
-
if (editifyInstance.exposed!.editor.value) {
|
152
|
-
isDisabled = hasTableInRange(editifyInstance.exposed!.editor.value, editifyInstance.exposed!.dataRangeCaches.value) || hasPreInRange(editifyInstance.exposed!.editor.value, editifyInstance.exposed!.dataRangeCaches.value) || hasPanelInRange(editifyInstance.exposed!.editor.value, editifyInstance.exposed!.dataRangeCaches.value)
|
153
|
-
}
|
154
|
-
return {
|
155
|
-
//插件名称
|
156
|
-
name: 'infoBlock',
|
157
|
-
//菜单项配置
|
158
|
-
menu: {
|
159
|
-
sequence: options!.sequence || 103,
|
160
|
-
extend: {
|
161
|
-
type: 'default',
|
162
|
-
title: options!.title || editTrans('insertInfoBlock'),
|
163
|
-
leftBorder: options!.leftBorder,
|
164
|
-
rightBorder: options!.rightBorder,
|
165
|
-
hideScroll: true,
|
166
|
-
active: editifyInstance.exposed!.editor.value ? isRangeInInfoBlock(editifyInstance.exposed!.editor.value, editifyInstance.exposed!.dataRangeCaches.value) : false,
|
167
|
-
disabled: isDisabled || options!.disabled,
|
168
|
-
default: () => h(Icon, { value: 'info' }),
|
169
|
-
onOperate: () => {
|
170
|
-
const editor = <AlexEditor>editifyInstance.exposed!.editor.value
|
171
|
-
const dataRangeCaches = <AlexElementsRangeType>editifyInstance.exposed!.dataRangeCaches.value
|
172
|
-
//是否都在引用里
|
173
|
-
const flag = isRangeInInfoBlock(editor, dataRangeCaches)
|
174
|
-
//起点和终点在一起
|
175
|
-
if (editor.range!.anchor.isEqual(editor.range!.focus)) {
|
176
|
-
const block = editor.range!.anchor.element.getBlock()
|
177
|
-
elementToParagraph(block)
|
178
|
-
if (!flag) {
|
179
|
-
block.parsedom = 'div'
|
180
|
-
block.marks = {
|
181
|
-
'data-editify-info': 'true'
|
182
|
-
}
|
183
|
-
}
|
184
|
-
}
|
185
|
-
//起点和终点不在一起
|
186
|
-
else {
|
187
|
-
let blocks: AlexElement[] = []
|
188
|
-
dataRangeCaches.list.forEach(item => {
|
189
|
-
const block = item.element.getBlock()
|
190
|
-
const exist = blocks.some(el => block.isEqual(el))
|
191
|
-
if (!exist) {
|
192
|
-
blocks.push(block)
|
193
|
-
}
|
194
|
-
})
|
195
|
-
blocks.forEach(block => {
|
196
|
-
elementToParagraph(block)
|
197
|
-
if (!flag) {
|
198
|
-
block.parsedom = 'div'
|
199
|
-
block.marks = {
|
200
|
-
'data-editify-info': 'true'
|
201
|
-
}
|
202
|
-
}
|
203
|
-
})
|
204
|
-
}
|
205
|
-
//渲染
|
206
|
-
editor.formatElementStack()
|
207
|
-
editor.domRender()
|
208
|
-
editor.rangeRender()
|
209
|
-
}
|
210
|
-
}
|
211
|
-
},
|
212
|
-
//粘贴保留的属性
|
213
|
-
pasteKeepMarks: (element: AlexElement) => {
|
214
|
-
if (isInfoBlock(element)) {
|
215
|
-
return {
|
216
|
-
'data-editify-info': 'true'
|
217
|
-
}
|
218
|
-
}
|
219
|
-
return {}
|
220
|
-
},
|
221
|
-
renderRule: (el: AlexElement) => {
|
222
|
-
if (isInfoBlock(el)) {
|
223
|
-
const color = DapColor.hex2rgb(editifyInstance.props.color as string)
|
224
|
-
if (el.hasStyles()) {
|
225
|
-
el.styles!['background-color'] = `rgba(${color[0]},${color[1]},${color[2]},0.15)`
|
226
|
-
el.styles!['color'] = editifyInstance.props.color
|
227
|
-
} else {
|
228
|
-
el.styles = {
|
229
|
-
'background-color': `rgba(${color[0]},${color[1]},${color[2]},0.15)`,
|
230
|
-
color: editifyInstance.props.color
|
231
|
-
}
|
232
|
-
}
|
233
|
-
}
|
234
|
-
}
|
235
|
-
}
|
236
|
-
}
|
237
|
-
return plugin
|
238
|
-
}
|