vue-editify 0.1.9 → 0.1.12
Sign up to get free protection for your applications and to get access to all the features.
- package/examples/App.vue +22 -5644
- package/examples/main.ts +4 -0
- package/lib/components/button/button.vue.d.ts +143 -0
- package/lib/components/button/props.d.ts +73 -0
- package/lib/components/checkbox/checkbox.vue.d.ts +80 -0
- package/lib/components/checkbox/props.d.ts +36 -0
- package/lib/components/colors/colors.vue.d.ts +47 -0
- package/lib/components/colors/props.d.ts +22 -0
- package/lib/components/icon/icon.vue.d.ts +14 -0
- package/lib/components/icon/props.d.ts +9 -0
- package/lib/components/insertImage/insertImage.vue.d.ts +74 -0
- package/lib/components/insertImage/props.d.ts +34 -0
- package/lib/components/insertLink/insertLink.vue.d.ts +27 -0
- package/lib/components/insertLink/props.d.ts +13 -0
- package/lib/components/insertTable/insertTable.vue.d.ts +36 -0
- package/lib/components/insertTable/props.d.ts +22 -0
- package/lib/components/insertVideo/insertVideo.vue.d.ts +74 -0
- package/lib/components/insertVideo/props.d.ts +34 -0
- package/lib/components/layer/layer.vue.d.ts +129 -0
- package/lib/components/layer/props.d.ts +53 -0
- package/lib/components/menu/menu.vue.d.ts +25 -0
- package/lib/components/menu/props.d.ts +14 -0
- package/lib/components/toolbar/props.d.ts +27 -0
- package/lib/components/toolbar/toolbar.vue.d.ts +56 -0
- package/lib/components/tooltip/props.d.ts +17 -0
- package/lib/components/tooltip/tooltip.vue.d.ts +39 -0
- package/lib/components/triangle/props.d.ts +19 -0
- package/lib/components/triangle/triangle.vue.d.ts +34 -0
- package/lib/core/function.d.ts +45 -0
- package/lib/core/rule.d.ts +9 -0
- package/lib/core/tool.d.ts +185 -0
- package/lib/editify/editify.vue.d.ts +676 -0
- package/lib/editify/props.d.ts +110 -0
- package/lib/editify.es.js +5547 -5667
- package/lib/editify.umd.js +1 -1
- package/lib/hljs/index.d.ts +7 -0
- package/lib/index.d.ts +17 -0
- package/lib/locale/en_US.d.ts +3 -0
- package/lib/locale/index.d.ts +2 -0
- package/lib/locale/zh_CN.d.ts +3 -0
- package/lib/style.css +1 -1
- package/package.json +16 -8
- package/src/components/button/button.less +145 -0
- package/src/components/button/button.vue +197 -0
- package/src/components/button/props.ts +95 -0
- package/src/components/checkbox/checkbox.less +84 -0
- package/src/components/checkbox/checkbox.vue +68 -0
- package/src/components/checkbox/props.ts +49 -0
- package/src/components/colors/colors.less +75 -0
- package/src/components/colors/colors.vue +36 -0
- package/src/components/colors/props.ts +29 -0
- package/src/components/{base/Icon.vue → icon/icon.less} +0 -17
- package/src/components/icon/icon.vue +12 -0
- package/src/components/icon/props.ts +11 -0
- package/src/components/insertImage/insertImage.less +135 -0
- package/src/components/insertImage/insertImage.vue +146 -0
- package/src/components/insertImage/props.ts +43 -0
- package/src/components/insertLink/insertLink.less +64 -0
- package/src/components/insertLink/insertLink.vue +58 -0
- package/src/components/insertLink/props.ts +16 -0
- package/src/components/insertTable/insertTable.less +54 -0
- package/src/components/insertTable/insertTable.vue +85 -0
- package/src/components/insertTable/props.ts +27 -0
- package/src/components/insertVideo/insertVideo.less +135 -0
- package/src/components/insertVideo/insertVideo.vue +146 -0
- package/src/components/insertVideo/props.ts +43 -0
- package/src/components/layer/layer.less +49 -0
- package/src/components/layer/layer.vue +598 -0
- package/src/components/layer/props.ts +71 -0
- package/src/components/menu/menu.less +64 -0
- package/src/components/menu/menu.vue +1570 -0
- package/src/components/menu/props.ts +17 -0
- package/src/components/toolbar/props.ts +35 -0
- package/src/components/toolbar/toolbar.less +89 -0
- package/src/components/toolbar/toolbar.vue +1101 -0
- package/src/components/tooltip/props.ts +21 -0
- package/src/components/tooltip/tooltip.less +23 -0
- package/src/components/tooltip/tooltip.vue +37 -0
- package/src/components/triangle/props.ts +26 -0
- package/src/components/triangle/triangle.less +79 -0
- package/src/components/triangle/triangle.vue +65 -0
- package/src/core/{function.js → function.ts} +268 -267
- package/src/core/{rule.js → rule.ts} +33 -33
- package/src/core/{tool.js → tool.ts} +221 -145
- package/src/editify/editify.less +404 -0
- package/src/editify/editify.vue +805 -0
- package/src/editify/props.ts +141 -0
- package/src/hljs/{index.js → index.ts} +7 -4
- package/src/index.ts +32 -0
- package/src/locale/{en_US.js → en_US.ts} +3 -1
- package/src/locale/index.ts +12 -0
- package/src/locale/{zh_CN.js → zh_CN.ts} +3 -1
- package/tsconfig.json +27 -0
- package/tsconfig.node.json +11 -0
- package/vite-env.d.ts +1 -0
- package/vite.config.ts +39 -0
- package/examples/main.js +0 -4
- package/src/Editify.vue +0 -1184
- package/src/components/Menu.vue +0 -1623
- package/src/components/Toolbar.vue +0 -1215
- package/src/components/base/Button.vue +0 -450
- package/src/components/base/Checkbox.vue +0 -196
- package/src/components/base/Layer.vue +0 -713
- package/src/components/base/Tooltip.vue +0 -82
- package/src/components/base/Triangle.vue +0 -159
- package/src/components/common/Colors.vue +0 -138
- package/src/components/common/InsertImage.vue +0 -316
- package/src/components/common/InsertLink.vue +0 -136
- package/src/components/common/InsertTable.vue +0 -157
- package/src/components/common/InsertVideo.vue +0 -316
- package/src/index.js +0 -24
- package/src/locale/index.js +0 -14
@@ -0,0 +1,135 @@
|
|
1
|
+
.editify-image {
|
2
|
+
display: block;
|
3
|
+
width: 280px;
|
4
|
+
padding: 10px 14px;
|
5
|
+
|
6
|
+
.editify-image-header {
|
7
|
+
display: flex;
|
8
|
+
justify-content: flex-start;
|
9
|
+
align-items: center;
|
10
|
+
width: 100%;
|
11
|
+
margin-bottom: 20px;
|
12
|
+
position: relative;
|
13
|
+
padding-bottom: 6px;
|
14
|
+
|
15
|
+
.editify-image-header-slider {
|
16
|
+
position: absolute;
|
17
|
+
width: 50px;
|
18
|
+
height: 2px;
|
19
|
+
border-radius: 2px;
|
20
|
+
left: 0;
|
21
|
+
bottom: 0;
|
22
|
+
transition: left 200ms;
|
23
|
+
|
24
|
+
&.upload {
|
25
|
+
left: 5px;
|
26
|
+
}
|
27
|
+
|
28
|
+
&.remote {
|
29
|
+
left: 85px;
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
.editify-image-header-item {
|
34
|
+
display: block;
|
35
|
+
text-align: center;
|
36
|
+
font-size: @font-size;
|
37
|
+
color: @font-color;
|
38
|
+
opacity: 0.8;
|
39
|
+
transition: all 200ms;
|
40
|
+
width: 60px;
|
41
|
+
overflow: hidden;
|
42
|
+
white-space: nowrap;
|
43
|
+
text-overflow: ellipsis;
|
44
|
+
|
45
|
+
&:hover {
|
46
|
+
opacity: 1;
|
47
|
+
cursor: pointer;
|
48
|
+
}
|
49
|
+
|
50
|
+
&:first-child {
|
51
|
+
margin-right: 20px;
|
52
|
+
}
|
53
|
+
|
54
|
+
&.active {
|
55
|
+
opacity: 1;
|
56
|
+
color: @font-color-dark;
|
57
|
+
}
|
58
|
+
}
|
59
|
+
}
|
60
|
+
|
61
|
+
.editify-image-remote {
|
62
|
+
display: block;
|
63
|
+
width: 100%;
|
64
|
+
|
65
|
+
input {
|
66
|
+
appearance: none;
|
67
|
+
-webkit-appearance: none;
|
68
|
+
-moz-appearance: none;
|
69
|
+
display: block;
|
70
|
+
width: 100%;
|
71
|
+
margin: 0 0 10px 0;
|
72
|
+
padding: 4px 2px;
|
73
|
+
border: none;
|
74
|
+
font-size: @font-size;
|
75
|
+
color: @font-color;
|
76
|
+
border-bottom: 1px solid @border-color;
|
77
|
+
line-height: 1.5;
|
78
|
+
transition: border-color 500ms;
|
79
|
+
background-color: transparent;
|
80
|
+
outline: none;
|
81
|
+
box-sizing: border-box;
|
82
|
+
|
83
|
+
&::-webkit-input-placeholder,
|
84
|
+
&::placeholder {
|
85
|
+
color: @font-color-disabled;
|
86
|
+
font-family: inherit;
|
87
|
+
font-size: inherit;
|
88
|
+
vertical-align: middle;
|
89
|
+
}
|
90
|
+
}
|
91
|
+
|
92
|
+
.editify-image-remote-footer {
|
93
|
+
display: flex;
|
94
|
+
justify-content: flex-end;
|
95
|
+
align-items: center;
|
96
|
+
width: 100%;
|
97
|
+
font-size: @font-size;
|
98
|
+
opacity: 0.8;
|
99
|
+
transition: all 200ms;
|
100
|
+
|
101
|
+
&:hover {
|
102
|
+
cursor: pointer;
|
103
|
+
opacity: 1;
|
104
|
+
}
|
105
|
+
}
|
106
|
+
}
|
107
|
+
|
108
|
+
.editify-image-upload {
|
109
|
+
display: flex;
|
110
|
+
justify-content: center;
|
111
|
+
align-items: center;
|
112
|
+
width: 100%;
|
113
|
+
padding: 15px 0;
|
114
|
+
font-size: 36px;
|
115
|
+
opacity: 0.8;
|
116
|
+
transition: all 200ms;
|
117
|
+
position: relative;
|
118
|
+
|
119
|
+
&:hover {
|
120
|
+
cursor: pointer;
|
121
|
+
opacity: 1;
|
122
|
+
}
|
123
|
+
|
124
|
+
input {
|
125
|
+
opacity: 0;
|
126
|
+
position: absolute;
|
127
|
+
left: 0;
|
128
|
+
top: 0;
|
129
|
+
width: 100%;
|
130
|
+
height: 100%;
|
131
|
+
z-index: 1;
|
132
|
+
cursor: pointer;
|
133
|
+
}
|
134
|
+
}
|
135
|
+
}
|
@@ -0,0 +1,146 @@
|
|
1
|
+
<template>
|
2
|
+
<div class="editify-image">
|
3
|
+
<div class="editify-image-header">
|
4
|
+
<div @click="current = 'upload'" class="editify-image-header-item" :class="{ active: current == 'upload' }" :style="activeStyle('upload')">{{ $editTrans('uploadImage') }}</div>
|
5
|
+
<div @click="current = 'remote'" class="editify-image-header-item" :class="{ active: current == 'remote' }" :style="activeStyle('remote')">{{ $editTrans('remoteImage') }}</div>
|
6
|
+
<div class="editify-image-header-slider" :class="current" :style="{ backgroundColor: color || '' }"></div>
|
7
|
+
</div>
|
8
|
+
<!-- 网络图片 -->
|
9
|
+
<div class="editify-image-remote" v-if="current == 'remote'">
|
10
|
+
<input v-model.trim="remoteUrl" :placeholder="$editTrans('imageUrlPlaceholder')" @blur="handleInputBlur" @focus="handleInputFocus" />
|
11
|
+
<div class="editify-image-remote-footer" :style="{ color: color }">
|
12
|
+
<span @click="insertRemoteImage">{{ $editTrans('insert') }}</span>
|
13
|
+
</div>
|
14
|
+
</div>
|
15
|
+
<!-- 上传图片 -->
|
16
|
+
<div class="editify-image-upload" v-else>
|
17
|
+
<Icon value="upload"></Icon>
|
18
|
+
<input :multiple="multiple" accept="image/*" @change="selectFile" type="file" />
|
19
|
+
</div>
|
20
|
+
</div>
|
21
|
+
</template>
|
22
|
+
<script setup lang="ts">
|
23
|
+
import { file as DapFile } from 'dap-util'
|
24
|
+
import Icon from '../icon/icon.vue'
|
25
|
+
import { InsertImageProps } from './props'
|
26
|
+
import { ComponentInternalInstance, computed, inject, ref, watch } from 'vue'
|
27
|
+
import { ObjectType } from '../../core/tool'
|
28
|
+
|
29
|
+
defineOptions({
|
30
|
+
name: 'InsertImage'
|
31
|
+
})
|
32
|
+
const props = defineProps(InsertImageProps)
|
33
|
+
const emits = defineEmits(['change', 'insert'])
|
34
|
+
|
35
|
+
const $editTrans = inject<(key: string) => any>('$editTrans')!
|
36
|
+
const editify = inject<ComponentInternalInstance>('editify')!
|
37
|
+
|
38
|
+
//当前展示的面板,取值remote和upload
|
39
|
+
const current = ref<'remote' | 'upload'>('upload')
|
40
|
+
//远程图片链接
|
41
|
+
const remoteUrl = ref<string>('')
|
42
|
+
|
43
|
+
const activeStyle = computed<(name: 'remote' | 'upload') => ObjectType>(() => {
|
44
|
+
return (name: 'remote' | 'upload') => {
|
45
|
+
if (current.value == name) {
|
46
|
+
return {
|
47
|
+
color: props.color
|
48
|
+
}
|
49
|
+
}
|
50
|
+
return {}
|
51
|
+
}
|
52
|
+
})
|
53
|
+
|
54
|
+
//获取文件后缀
|
55
|
+
const getSuffix = (file: File) => {
|
56
|
+
const index = file.name.lastIndexOf('.')
|
57
|
+
if (index <= 0) {
|
58
|
+
return ''
|
59
|
+
}
|
60
|
+
return file.name.substring(index + 1)
|
61
|
+
}
|
62
|
+
//输入框获取焦点
|
63
|
+
const handleInputFocus = (e: Event) => {
|
64
|
+
if (props.color) {
|
65
|
+
;(<HTMLInputElement>e.currentTarget).style.borderColor = props.color
|
66
|
+
}
|
67
|
+
}
|
68
|
+
//输入框失去焦点
|
69
|
+
const handleInputBlur = (e: Event) => {
|
70
|
+
;(<HTMLInputElement>e.currentTarget).style.borderColor = ''
|
71
|
+
}
|
72
|
+
//插入网络图片
|
73
|
+
const insertRemoteImage = () => {
|
74
|
+
emits('insert', remoteUrl.value)
|
75
|
+
}
|
76
|
+
//选择文件
|
77
|
+
const selectFile = async (e: Event) => {
|
78
|
+
const inputEle = <HTMLInputElement>e.currentTarget
|
79
|
+
const files = inputEle.files
|
80
|
+
if (!files || !files.length) {
|
81
|
+
return
|
82
|
+
}
|
83
|
+
let filterFiles = []
|
84
|
+
for (let i = 0; i < files.length; i++) {
|
85
|
+
const file = files[i]
|
86
|
+
const suffix = getSuffix(file)
|
87
|
+
const isMatch = props.accept.some(item => {
|
88
|
+
return item.toLocaleLowerCase() == suffix.toLocaleLowerCase()
|
89
|
+
})
|
90
|
+
//后缀不符合
|
91
|
+
if (!isMatch) {
|
92
|
+
//如果自定义了异常处理
|
93
|
+
if (typeof props.handleError == 'function') {
|
94
|
+
props.handleError.apply(editify.proxy!, ['suffixError', file])
|
95
|
+
}
|
96
|
+
continue
|
97
|
+
}
|
98
|
+
//超过最大值
|
99
|
+
if (props.maxSize && file.size / 1024 > props.maxSize) {
|
100
|
+
//如果自定义了异常处理
|
101
|
+
if (typeof props.handleError == 'function') {
|
102
|
+
props.handleError.apply(editify.proxy!, ['maxSizeError', file])
|
103
|
+
}
|
104
|
+
continue
|
105
|
+
}
|
106
|
+
//没达到最小值
|
107
|
+
if (props.minSize && file.size / 1024 < props.minSize) {
|
108
|
+
//如果自定义了异常处理
|
109
|
+
if (typeof props.handleError == 'function') {
|
110
|
+
props.handleError.apply(editify.proxy!, ['minSizeError', file])
|
111
|
+
}
|
112
|
+
continue
|
113
|
+
}
|
114
|
+
filterFiles.push(file)
|
115
|
+
}
|
116
|
+
//有文件可上传
|
117
|
+
if (filterFiles.length) {
|
118
|
+
let images = []
|
119
|
+
//自定义上传方法
|
120
|
+
if (typeof props.customUpload == 'function') {
|
121
|
+
images = (await props.customUpload.apply(editify.proxy!, [filterFiles])) || []
|
122
|
+
}
|
123
|
+
//默认上传方法
|
124
|
+
else {
|
125
|
+
for (let i = 0; i < filterFiles.length; i++) {
|
126
|
+
const url = await DapFile.dataFileToBase64(filterFiles[i])
|
127
|
+
images.push(url)
|
128
|
+
}
|
129
|
+
}
|
130
|
+
images.forEach(url => {
|
131
|
+
emits('insert', url)
|
132
|
+
})
|
133
|
+
}
|
134
|
+
//清空文件选择框
|
135
|
+
inputEle.value = ''
|
136
|
+
}
|
137
|
+
|
138
|
+
//监听current变更触发change事件
|
139
|
+
watch(
|
140
|
+
() => current.value,
|
141
|
+
() => {
|
142
|
+
emits('change')
|
143
|
+
}
|
144
|
+
)
|
145
|
+
</script>
|
146
|
+
<style scoped src="./insertImage.less"></style>
|
@@ -0,0 +1,43 @@
|
|
1
|
+
import { ExtractPublicPropTypes, PropType } from 'vue'
|
2
|
+
|
3
|
+
export type InsertImageUploadErrorType = 'suffixError' | 'maxSizeError' | 'minSizeError'
|
4
|
+
|
5
|
+
export const InsertImageProps = {
|
6
|
+
//主题色
|
7
|
+
color: {
|
8
|
+
type: String,
|
9
|
+
default: ''
|
10
|
+
},
|
11
|
+
//支持的图片类型数组
|
12
|
+
accept: {
|
13
|
+
type: Array as PropType<string[]>,
|
14
|
+
default: null
|
15
|
+
},
|
16
|
+
//是否支持多选
|
17
|
+
multiple: {
|
18
|
+
type: Boolean,
|
19
|
+
default: false
|
20
|
+
},
|
21
|
+
//单个文件最大值
|
22
|
+
maxSize: {
|
23
|
+
type: Number,
|
24
|
+
default: null
|
25
|
+
},
|
26
|
+
//单个文件最小值
|
27
|
+
minSize: {
|
28
|
+
type: Number,
|
29
|
+
default: null
|
30
|
+
},
|
31
|
+
//是否自定义上传图片
|
32
|
+
customUpload: {
|
33
|
+
type: Function as PropType<(files: File[]) => string[] | Promise<string[]>>,
|
34
|
+
default: null
|
35
|
+
},
|
36
|
+
//处理上传图片异常
|
37
|
+
handleError: {
|
38
|
+
type: Function as PropType<(error: InsertImageUploadErrorType, file: File) => void>,
|
39
|
+
default: null
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
export type InsertImagePropsType = ExtractPublicPropTypes<typeof InsertImageProps>
|
@@ -0,0 +1,64 @@
|
|
1
|
+
.editify-link {
|
2
|
+
display: block;
|
3
|
+
width: 280px;
|
4
|
+
padding: 10px 14px;
|
5
|
+
|
6
|
+
.editify-link-label {
|
7
|
+
display: block;
|
8
|
+
text-align: left;
|
9
|
+
margin-bottom: 10px;
|
10
|
+
font-size: @font-size;
|
11
|
+
color: @font-color;
|
12
|
+
}
|
13
|
+
|
14
|
+
input {
|
15
|
+
appearance: none;
|
16
|
+
-webkit-appearance: none;
|
17
|
+
-moz-appearance: none;
|
18
|
+
display: block;
|
19
|
+
width: 100%;
|
20
|
+
margin: 0 0 10px 0;
|
21
|
+
padding: 4px 2px;
|
22
|
+
border: none;
|
23
|
+
font-size: @font-size;
|
24
|
+
color: @font-color;
|
25
|
+
border-bottom: 1px solid @border-color;
|
26
|
+
line-height: 1.5;
|
27
|
+
transition: border-color 500ms;
|
28
|
+
background-color: transparent;
|
29
|
+
outline: none;
|
30
|
+
box-sizing: border-box;
|
31
|
+
|
32
|
+
&::-webkit-input-placeholder,
|
33
|
+
&::placeholder {
|
34
|
+
color: @font-color-disabled;
|
35
|
+
font-family: inherit;
|
36
|
+
font-size: inherit;
|
37
|
+
vertical-align: middle;
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
.editify-link-footer {
|
42
|
+
display: flex;
|
43
|
+
justify-content: space-between;
|
44
|
+
align-items: center;
|
45
|
+
width: 100%;
|
46
|
+
|
47
|
+
.editify-link-operations {
|
48
|
+
display: flex;
|
49
|
+
justify-content: flex-start;
|
50
|
+
align-items: center;
|
51
|
+
|
52
|
+
& > span {
|
53
|
+
cursor: pointer;
|
54
|
+
opacity: 0.8;
|
55
|
+
transition: all 200ms;
|
56
|
+
font-size: @font-size;
|
57
|
+
|
58
|
+
&:hover {
|
59
|
+
opacity: 1;
|
60
|
+
}
|
61
|
+
}
|
62
|
+
}
|
63
|
+
}
|
64
|
+
}
|
@@ -0,0 +1,58 @@
|
|
1
|
+
<template>
|
2
|
+
<div class="editify-link">
|
3
|
+
<div class="editify-link-label">{{ $editTrans('linkAddress') }}</div>
|
4
|
+
<input @focus="handleInputFocus" @blur="handleInputBlur" :placeholder="$editTrans('linkTextEnterPlaceholder')" v-model.trim="linkText" type="text" />
|
5
|
+
<input @focus="handleInputFocus" @blur="handleInputBlur" :placeholder="$editTrans('linkUrlEnterPlaceholder')" v-model.trim="linkUrl" type="url" />
|
6
|
+
<div class="editify-link-footer">
|
7
|
+
<Checkbox v-model="newOpen" :label="$editTrans('newWindowOpen')" :color="color" :size="10"></Checkbox>
|
8
|
+
<div class="editify-link-operations">
|
9
|
+
<span :style="{ color: color }" @click="insertLink">{{ $editTrans('insertLink') }}</span>
|
10
|
+
</div>
|
11
|
+
</div>
|
12
|
+
</div>
|
13
|
+
</template>
|
14
|
+
<script setup lang="ts">
|
15
|
+
import { inject, ref, watch } from 'vue'
|
16
|
+
import Checkbox from '../checkbox/checkbox.vue'
|
17
|
+
import { InsertLinkProps } from './props'
|
18
|
+
|
19
|
+
defineOptions({
|
20
|
+
name: 'InsertLink'
|
21
|
+
})
|
22
|
+
const props = defineProps(InsertLinkProps)
|
23
|
+
const emits = defineEmits(['insert'])
|
24
|
+
|
25
|
+
const $editTrans = inject<(key: string) => any>('$editTrans')!
|
26
|
+
|
27
|
+
//链接地址
|
28
|
+
const linkUrl = ref<string>('')
|
29
|
+
//链接文本
|
30
|
+
const linkText = ref<string>('')
|
31
|
+
//是否新窗口打开
|
32
|
+
const newOpen = ref<boolean>(false)
|
33
|
+
|
34
|
+
watch(
|
35
|
+
() => props.text,
|
36
|
+
newVal => {
|
37
|
+
linkText.value = newVal
|
38
|
+
},
|
39
|
+
{
|
40
|
+
immediate: true
|
41
|
+
}
|
42
|
+
)
|
43
|
+
//输入框获取焦点
|
44
|
+
const handleInputFocus = (e: Event) => {
|
45
|
+
if (props.color) {
|
46
|
+
;(<HTMLInputElement>e.currentTarget).style.borderColor = props.color
|
47
|
+
}
|
48
|
+
}
|
49
|
+
//输入框失去焦点
|
50
|
+
const handleInputBlur = (e: Event) => {
|
51
|
+
;(<HTMLInputElement>e.currentTarget).style.borderColor = ''
|
52
|
+
}
|
53
|
+
//插入链接
|
54
|
+
const insertLink = () => {
|
55
|
+
emits('insert', linkText.value, linkUrl.value, newOpen.value)
|
56
|
+
}
|
57
|
+
</script>
|
58
|
+
<style scoped src="./insertLink.less"></style>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import { ExtractPublicPropTypes } from 'vue'
|
2
|
+
|
3
|
+
export const InsertLinkProps = {
|
4
|
+
//主题色
|
5
|
+
color: {
|
6
|
+
type: String,
|
7
|
+
default: ''
|
8
|
+
},
|
9
|
+
//预置的链接文本值
|
10
|
+
text: {
|
11
|
+
type: String,
|
12
|
+
default: ''
|
13
|
+
}
|
14
|
+
}
|
15
|
+
|
16
|
+
export type InsertLinkPropsType = ExtractPublicPropTypes<typeof InsertLinkProps>
|
@@ -0,0 +1,54 @@
|
|
1
|
+
.editify-table {
|
2
|
+
display: block;
|
3
|
+
position: relative;
|
4
|
+
padding: 10px 10px 32px 10px;
|
5
|
+
box-sizing: border-box;
|
6
|
+
|
7
|
+
table {
|
8
|
+
border: 1px solid @border-color;
|
9
|
+
margin: 0;
|
10
|
+
padding: 0;
|
11
|
+
border-collapse: collapse;
|
12
|
+
|
13
|
+
tr {
|
14
|
+
margin: 0;
|
15
|
+
padding: 0;
|
16
|
+
|
17
|
+
td {
|
18
|
+
margin: 0;
|
19
|
+
padding: 0;
|
20
|
+
border: 1px solid @border-color;
|
21
|
+
|
22
|
+
span {
|
23
|
+
display: block;
|
24
|
+
width: 15px;
|
25
|
+
height: 15px;
|
26
|
+
}
|
27
|
+
|
28
|
+
&:hover {
|
29
|
+
cursor: pointer;
|
30
|
+
}
|
31
|
+
|
32
|
+
&.inside {
|
33
|
+
background-color: @background-darker;
|
34
|
+
}
|
35
|
+
}
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
.editify-table-footer {
|
40
|
+
text-align: center;
|
41
|
+
color: @font-color-light;
|
42
|
+
line-height: 1;
|
43
|
+
font-size: 12px;
|
44
|
+
position: absolute;
|
45
|
+
padding: 0 10px;
|
46
|
+
bottom: 10px;
|
47
|
+
left: 0;
|
48
|
+
width: 100%;
|
49
|
+
overflow: hidden;
|
50
|
+
text-overflow: ellipsis;
|
51
|
+
white-space: nowrap;
|
52
|
+
box-sizing: border-box;
|
53
|
+
}
|
54
|
+
}
|
@@ -0,0 +1,85 @@
|
|
1
|
+
<template>
|
2
|
+
<div class="editify-table">
|
3
|
+
<table>
|
4
|
+
<tr v-for="row in tableGrids">
|
5
|
+
<td :class="{ inside: column.inside }" v-for="column in row" @mouseenter="changeTableSize(column)" @click="createTable(column)">
|
6
|
+
<span></span>
|
7
|
+
</td>
|
8
|
+
</tr>
|
9
|
+
</table>
|
10
|
+
<div class="editify-table-footer">
|
11
|
+
<span v-if="specification">{{ specification.x }} x {{ specification.y }}</span>
|
12
|
+
<span v-else>{{ $editTrans('insertTable') }}</span>
|
13
|
+
</div>
|
14
|
+
</div>
|
15
|
+
</template>
|
16
|
+
<script setup lang="ts">
|
17
|
+
import { computed, inject, ref } from 'vue'
|
18
|
+
import { InsertTableGridType, InsertTableProps } from './props'
|
19
|
+
|
20
|
+
defineOptions({
|
21
|
+
name: 'InsertTable'
|
22
|
+
})
|
23
|
+
const props = defineProps(InsertTableProps)
|
24
|
+
const emits = defineEmits(['insert'])
|
25
|
+
|
26
|
+
const $editTrans = inject<(key: string) => any>('$editTrans')!
|
27
|
+
|
28
|
+
//获取表格
|
29
|
+
const getTableGrids = () => {
|
30
|
+
const grids: InsertTableGridType[][] = []
|
31
|
+
for (let i = 1; i <= props.maxRows; i++) {
|
32
|
+
let row: InsertTableGridType[] = []
|
33
|
+
for (let j = 1; j <= props.maxColumns; j++) {
|
34
|
+
row.push({
|
35
|
+
x: i,
|
36
|
+
y: j,
|
37
|
+
inside: false //是否被选中
|
38
|
+
})
|
39
|
+
}
|
40
|
+
grids.push(row)
|
41
|
+
}
|
42
|
+
return grids
|
43
|
+
}
|
44
|
+
|
45
|
+
const tableGrids = ref<InsertTableGridType[][]>(getTableGrids())
|
46
|
+
|
47
|
+
//表格规格
|
48
|
+
const specification = computed<InsertTableGridType>(() => {
|
49
|
+
return tableGrids.value
|
50
|
+
.flat()
|
51
|
+
.filter(item => {
|
52
|
+
return item.inside
|
53
|
+
})
|
54
|
+
.sort((a, b) => {
|
55
|
+
if (a.x > b.x && a.y > b.y) {
|
56
|
+
return -1
|
57
|
+
}
|
58
|
+
if (a.x > b.x) {
|
59
|
+
return -1
|
60
|
+
}
|
61
|
+
if (a.y > b.y) {
|
62
|
+
return -1
|
63
|
+
}
|
64
|
+
return 1
|
65
|
+
})[0]
|
66
|
+
})
|
67
|
+
//改变表格大小
|
68
|
+
const changeTableSize = (data: InsertTableGridType) => {
|
69
|
+
for (let i in tableGrids.value) {
|
70
|
+
const grid = tableGrids.value[i]
|
71
|
+
for (let j in grid) {
|
72
|
+
if (grid[j].x <= data.x && grid[j].y <= data.y) {
|
73
|
+
tableGrids.value[i][j].inside = true
|
74
|
+
} else {
|
75
|
+
tableGrids.value[i][j].inside = false
|
76
|
+
}
|
77
|
+
}
|
78
|
+
}
|
79
|
+
}
|
80
|
+
//确认创立表格
|
81
|
+
const createTable = (data: InsertTableGridType) => {
|
82
|
+
emits('insert', data.x, data.y)
|
83
|
+
}
|
84
|
+
</script>
|
85
|
+
<style scoped src="./insertTable.less"></style>
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import { ExtractPublicPropTypes } from 'vue'
|
2
|
+
|
3
|
+
export type InsertTableGridType = {
|
4
|
+
x: number
|
5
|
+
y: number
|
6
|
+
inside: boolean
|
7
|
+
}
|
8
|
+
|
9
|
+
export const InsertTableProps = {
|
10
|
+
//主题色
|
11
|
+
color: {
|
12
|
+
type: String,
|
13
|
+
default: ''
|
14
|
+
},
|
15
|
+
//最大行数
|
16
|
+
maxRows: {
|
17
|
+
type: Number,
|
18
|
+
default: 10
|
19
|
+
},
|
20
|
+
//最大列数
|
21
|
+
maxColumns: {
|
22
|
+
type: Number,
|
23
|
+
default: 10
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
export type InsertTablePropsType = ExtractPublicPropTypes<typeof InsertTableProps>
|