vue-editify 0.1.10 → 0.1.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. package/examples/App.vue +21 -96
  2. package/examples/main.ts +4 -0
  3. package/lib/components/button/button.vue.d.ts +143 -0
  4. package/lib/components/button/props.d.ts +73 -0
  5. package/lib/components/checkbox/checkbox.vue.d.ts +80 -0
  6. package/lib/components/checkbox/props.d.ts +36 -0
  7. package/lib/components/colors/colors.vue.d.ts +47 -0
  8. package/lib/components/colors/props.d.ts +22 -0
  9. package/lib/components/icon/icon.vue.d.ts +14 -0
  10. package/lib/components/icon/props.d.ts +9 -0
  11. package/lib/components/insertImage/insertImage.vue.d.ts +74 -0
  12. package/lib/components/insertImage/props.d.ts +34 -0
  13. package/lib/components/insertLink/insertLink.vue.d.ts +27 -0
  14. package/lib/components/insertLink/props.d.ts +13 -0
  15. package/lib/components/insertTable/insertTable.vue.d.ts +36 -0
  16. package/lib/components/insertTable/props.d.ts +22 -0
  17. package/lib/components/insertVideo/insertVideo.vue.d.ts +74 -0
  18. package/lib/components/insertVideo/props.d.ts +34 -0
  19. package/lib/components/layer/layer.vue.d.ts +129 -0
  20. package/lib/components/layer/props.d.ts +53 -0
  21. package/lib/components/menu/menu.vue.d.ts +25 -0
  22. package/lib/components/menu/props.d.ts +14 -0
  23. package/lib/components/toolbar/props.d.ts +27 -0
  24. package/lib/components/toolbar/toolbar.vue.d.ts +56 -0
  25. package/lib/components/tooltip/props.d.ts +17 -0
  26. package/lib/components/tooltip/tooltip.vue.d.ts +39 -0
  27. package/lib/components/triangle/props.d.ts +19 -0
  28. package/lib/components/triangle/triangle.vue.d.ts +34 -0
  29. package/lib/core/function.d.ts +45 -0
  30. package/lib/core/rule.d.ts +9 -0
  31. package/lib/core/tool.d.ts +185 -0
  32. package/lib/editify/editify.vue.d.ts +676 -0
  33. package/lib/editify/props.d.ts +110 -0
  34. package/lib/editify.es.js +5541 -5661
  35. package/lib/editify.umd.js +1 -1
  36. package/lib/hljs/index.d.ts +7 -0
  37. package/lib/index.d.ts +17 -0
  38. package/lib/locale/en_US.d.ts +3 -0
  39. package/lib/locale/index.d.ts +2 -0
  40. package/lib/locale/zh_CN.d.ts +3 -0
  41. package/lib/style.css +1 -1
  42. package/package.json +16 -8
  43. package/src/components/button/button.less +145 -0
  44. package/src/components/button/button.vue +197 -0
  45. package/src/components/button/props.ts +95 -0
  46. package/src/components/checkbox/checkbox.less +84 -0
  47. package/src/components/checkbox/checkbox.vue +68 -0
  48. package/src/components/checkbox/props.ts +49 -0
  49. package/src/components/colors/colors.less +75 -0
  50. package/src/components/colors/colors.vue +36 -0
  51. package/src/components/colors/props.ts +29 -0
  52. package/src/components/{base/Icon.vue → icon/icon.less} +0 -17
  53. package/src/components/icon/icon.vue +12 -0
  54. package/src/components/icon/props.ts +11 -0
  55. package/src/components/insertImage/insertImage.less +135 -0
  56. package/src/components/insertImage/insertImage.vue +146 -0
  57. package/src/components/insertImage/props.ts +43 -0
  58. package/src/components/insertLink/insertLink.less +64 -0
  59. package/src/components/insertLink/insertLink.vue +58 -0
  60. package/src/components/insertLink/props.ts +16 -0
  61. package/src/components/insertTable/insertTable.less +54 -0
  62. package/src/components/insertTable/insertTable.vue +85 -0
  63. package/src/components/insertTable/props.ts +27 -0
  64. package/src/components/insertVideo/insertVideo.less +135 -0
  65. package/src/components/insertVideo/insertVideo.vue +146 -0
  66. package/src/components/insertVideo/props.ts +43 -0
  67. package/src/components/layer/layer.less +49 -0
  68. package/src/components/layer/layer.vue +598 -0
  69. package/src/components/layer/props.ts +71 -0
  70. package/src/components/menu/menu.less +64 -0
  71. package/src/components/menu/menu.vue +1570 -0
  72. package/src/components/menu/props.ts +17 -0
  73. package/src/components/toolbar/props.ts +35 -0
  74. package/src/components/toolbar/toolbar.less +89 -0
  75. package/src/components/toolbar/toolbar.vue +1101 -0
  76. package/src/components/tooltip/props.ts +21 -0
  77. package/src/components/tooltip/tooltip.less +23 -0
  78. package/src/components/tooltip/tooltip.vue +37 -0
  79. package/src/components/triangle/props.ts +26 -0
  80. package/src/components/triangle/triangle.less +79 -0
  81. package/src/components/triangle/triangle.vue +65 -0
  82. package/src/core/{function.js → function.ts} +268 -267
  83. package/src/core/{rule.js → rule.ts} +33 -33
  84. package/src/core/{tool.js → tool.ts} +221 -145
  85. package/src/editify/editify.less +404 -0
  86. package/src/editify/editify.vue +805 -0
  87. package/src/editify/props.ts +141 -0
  88. package/src/hljs/{index.js → index.ts} +7 -4
  89. package/src/index.ts +32 -0
  90. package/src/locale/{en_US.js → en_US.ts} +3 -1
  91. package/src/locale/index.ts +12 -0
  92. package/src/locale/{zh_CN.js → zh_CN.ts} +3 -1
  93. package/tsconfig.json +27 -0
  94. package/tsconfig.node.json +11 -0
  95. package/vite-env.d.ts +1 -0
  96. package/vite.config.ts +39 -0
  97. package/examples/main.js +0 -4
  98. package/src/Editify.vue +0 -1184
  99. package/src/components/Menu.vue +0 -1623
  100. package/src/components/Toolbar.vue +0 -1215
  101. package/src/components/base/Button.vue +0 -450
  102. package/src/components/base/Checkbox.vue +0 -196
  103. package/src/components/base/Layer.vue +0 -713
  104. package/src/components/base/Tooltip.vue +0 -82
  105. package/src/components/base/Triangle.vue +0 -159
  106. package/src/components/common/Colors.vue +0 -138
  107. package/src/components/common/InsertImage.vue +0 -316
  108. package/src/components/common/InsertLink.vue +0 -136
  109. package/src/components/common/InsertTable.vue +0 -157
  110. package/src/components/common/InsertVideo.vue +0 -316
  111. package/src/index.js +0 -24
  112. package/src/locale/index.js +0 -14
@@ -0,0 +1,135 @@
1
+ .editify-video {
2
+ display: block;
3
+ width: 280px;
4
+ padding: 10px 14px;
5
+
6
+ .editify-video-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-video-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-video-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-video-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-video-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-video-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-video">
3
+ <div class="editify-video-header">
4
+ <div @click="current = 'upload'" class="editify-video-header-item" :class="{ active: current == 'upload' }" :style="activeStyle('upload')">{{ $editTrans('uploadVideo') }}</div>
5
+ <div @click="current = 'remote'" class="editify-video-header-item" :class="{ active: current == 'remote' }" :style="activeStyle('remote')">{{ $editTrans('remoteVideo') }}</div>
6
+ <div class="editify-video-header-slider" :class="current" :style="{ backgroundColor: color || '' }"></div>
7
+ </div>
8
+ <!-- 网络视频 -->
9
+ <div class="editify-video-remote" v-if="current == 'remote'">
10
+ <input v-model.trim="remoteUrl" :placeholder="$editTrans('videoUrlPlaceholder')" @blur="handleInputBlur" @focus="handleInputFocus" />
11
+ <div class="editify-video-remote-footer" :style="{ color: color }">
12
+ <span @click="insertRemoteVideo">{{ $editTrans('insert') }}</span>
13
+ </div>
14
+ </div>
15
+ <!-- 上传视频 -->
16
+ <div class="editify-video-upload" v-else>
17
+ <Icon value="upload"></Icon>
18
+ <input :multiple="multiple" accept="video/*" @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 { InsertVideoProps } from './props'
26
+ import { ComponentInternalInstance, computed, inject, ref, watch } from 'vue'
27
+ import { ObjectType } from '../../core/tool'
28
+
29
+ defineOptions({
30
+ name: 'InsertVideo'
31
+ })
32
+ const props = defineProps(InsertVideoProps)
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 insertRemoteVideo = () => {
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 videos = []
119
+ //自定义上传方法
120
+ if (typeof props.customUpload == 'function') {
121
+ videos = (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
+ videos.push(url)
128
+ }
129
+ }
130
+ videos.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="./insertVideo.less"></style>
@@ -0,0 +1,43 @@
1
+ import { ExtractPublicPropTypes, PropType } from 'vue'
2
+
3
+ export type InsertVideoUploadErrorType = 'suffixError' | 'maxSizeError' | 'minSizeError'
4
+
5
+ export const InsertVideoProps = {
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: InsertVideoUploadErrorType, file: File) => void>,
39
+ default: null
40
+ }
41
+ }
42
+
43
+ export type InsertVideoPropsType = ExtractPublicPropTypes<typeof InsertVideoProps>
@@ -0,0 +1,49 @@
1
+ .editify-layer-fade-enter-from,
2
+ .editify-layer-fade-leave-to {
3
+ opacity: 0;
4
+ }
5
+ .editify-layer-fade-enter-active,
6
+ .editify-layer-fade-leave-active {
7
+ transition: opacity 200ms linear;
8
+ }
9
+
10
+ .editify-layer-translate-enter-from,
11
+ .editify-layer-translate-leave-to {
12
+ opacity: 0;
13
+ transform: translateY(20px);
14
+ }
15
+
16
+ .editify-layer-translate-enter-active,
17
+ .editify-layer-translate-leave-active {
18
+ transition: opacity 200ms ease-in-out, transform 200ms ease-in-out;
19
+ }
20
+
21
+ .editify-layer {
22
+ display: block;
23
+ position: absolute;
24
+ padding: 0 0 10px 0;
25
+ font-size: @font-size;
26
+ color: @font-color;
27
+
28
+ &[data-editify-placement='bottom'],
29
+ &[data-editify-placement='bottom-start'],
30
+ &[data-editify-placement='bottom-end'] {
31
+ padding: 10px 0 0 0;
32
+ }
33
+
34
+ :deep(.editify-triangle) {
35
+ position: absolute;
36
+ z-index: 1;
37
+ }
38
+
39
+ .editify-layer-wrap {
40
+ display: block;
41
+ background-color: @background;
42
+ box-shadow: 0px 2px 10px rgba(0, 0, 0, 0.1);
43
+ border-radius: 4px;
44
+
45
+ &.border {
46
+ border: 1px solid @border-color;
47
+ }
48
+ }
49
+ }