vue-editify 0.1.10 → 0.1.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) 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 +5706 -5727
  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.ts +1144 -0
  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/core/function.js +0 -1044
  112. package/src/index.js +0 -24
  113. package/src/locale/index.js +0 -14
@@ -1,713 +0,0 @@
1
- <template>
2
- <Transition :name="animation ? 'editify-layer-' + animation : 'editify-layer'" @enter="handleEnter" @after-enter="handleAfterEnter" @after-leave="handleAfterLeave">
3
- <div v-if="modelValue" class="editify-layer" :data-editify-placement="realPlacement || null" :style="{ zIndex: zIndex }">
4
- <Triangle v-if="showTriangle" :color="border && borderColor ? borderColor : background" :background="background" :placement="triPlacement" ref="triangle" />
5
- <div ref="wrap" class="editify-layer-wrap" :class="{ border: border }" :style="wrapStyle">
6
- <slot></slot>
7
- </div>
8
- </div>
9
- </Transition>
10
- </template>
11
- <script>
12
- import { getCurrentInstance } from 'vue'
13
- import { element as DapElement, event as DapEvent } from 'dap-util'
14
- import Triangle from './Triangle'
15
- export default {
16
- name: 'Layer',
17
- emits: ['update:modelValue', 'show', 'shown', 'hidden'],
18
- props: {
19
- //是否显示
20
- modelValue: {
21
- type: Boolean,
22
- default: false
23
- },
24
- //关联元素
25
- node: {
26
- type: [String, Node],
27
- default: null
28
- },
29
- //是否显示边框
30
- border: {
31
- type: Boolean,
32
- default: false
33
- },
34
- //边框颜色
35
- borderColor: {
36
- type: String,
37
- default: null
38
- },
39
- //背景色
40
- background: {
41
- type: String,
42
- default: null
43
- },
44
- //字体颜色
45
- color: {
46
- type: String,
47
- default: null
48
- },
49
- //位置
50
- placement: {
51
- type: String,
52
- default: 'bottom',
53
- validator(value) {
54
- return ['top', 'bottom', 'top-start', 'top-end', 'bottom-start', 'bottom-end'].includes(value)
55
- }
56
- },
57
- //是否显示三角形
58
- showTriangle: {
59
- type: Boolean,
60
- default: false
61
- },
62
- //层级
63
- zIndex: {
64
- type: Number,
65
- default: 10
66
- },
67
- //动画
68
- animation: {
69
- type: String,
70
- default: null,
71
- validator(value) {
72
- return ['translate', 'fade', null].includes(value)
73
- }
74
- },
75
- //是否根据range对象来定位,此时不需要传入node
76
- useRange: {
77
- type: Boolean,
78
- default: false
79
- }
80
- },
81
- setup() {
82
- const uid = getCurrentInstance().uid
83
- return {
84
- uid
85
- }
86
- },
87
- data() {
88
- return {
89
- realPlacement: null,
90
- //三角图标大小
91
- triangleSize: 6
92
- }
93
- },
94
- components: {
95
- Triangle
96
- },
97
- computed: {
98
- //三角形位置
99
- triPlacement() {
100
- if (this.realPlacement == 'bottom-start' || this.realPlacement == 'bottom' || this.realPlacement == 'bottom-end') {
101
- return 'top'
102
- }
103
- if (this.realPlacement == 'top-start' || this.realPlacement == 'top' || this.realPlacement == 'top-end') {
104
- return 'bottom'
105
- }
106
- if (this.realPlacement == 'left-start' || this.realPlacement == 'left' || this.realPlacement == 'left-end') {
107
- return 'right'
108
- }
109
- if (this.realPlacement == 'right-start' || this.realPlacement == 'right' || this.realPlacement == 'right-end') {
110
- return 'left'
111
- }
112
- return 'top'
113
- },
114
- wrapStyle() {
115
- return {
116
- borderColor: this.border ? this.borderColor || '' : '',
117
- background: this.background || '',
118
- color: this.color || ''
119
- }
120
- }
121
- },
122
- mounted() {
123
- if (this.modelValue) {
124
- this.setPosition()
125
- }
126
- DapEvent.on(window, `click.editify_layer_${this.uid}`, this.handleClick)
127
- DapEvent.on(window, `resize.editify_layer_${this.uid}`, this.handleResize)
128
- },
129
- methods: {
130
- //显示时
131
- handleEnter(el) {
132
- this.setPosition()
133
- this.$emit('show', el)
134
- },
135
- //完全显示后
136
- handleAfterEnter(el) {
137
- this.$emit('shown', el)
138
- },
139
- //完全隐藏后
140
- handleAfterLeave(el) {
141
- this.$emit('hidden', el)
142
- },
143
- //窗口尺寸改动
144
- handleResize() {
145
- if (this.modelValue) {
146
- this.$emit('update:modelValue', false)
147
- }
148
- },
149
- //点击定位父元素外的元素关闭浮层
150
- handleClick(e) {
151
- if (!DapElement.isElement(this.$el)) {
152
- return
153
- }
154
- if (DapElement.isContains(this.$el.offsetParent, e.target)) {
155
- return
156
- }
157
- if (this.modelValue) {
158
- this.$emit('update:modelValue', false)
159
- }
160
- },
161
- //根据range设置三角形位置
162
- setTrianglePositionByRange() {
163
- const selection = window.getSelection()
164
- if (selection.rangeCount) {
165
- const range = selection.getRangeAt(0)
166
- const rects = range.getClientRects()
167
- if (rects.length) {
168
- //range的第一个位置
169
- const firstRect = rects[0]
170
- //range的最后一个位置
171
- const lastRect = rects[rects.length - 1]
172
- if (this.realPlacement == 'top') {
173
- this.$refs.triangle.$el.style.left = this.$refs.wrap.offsetWidth / 2 - this.$refs.triangle.$el.offsetWidth / 2 + 'px'
174
- this.$refs.triangle.$el.style.right = 'auto'
175
- this.$refs.triangle.$el.style.top = this.$refs.wrap.offsetHeight - 1 + 'px'
176
- this.$refs.triangle.$el.style.bottom = 'auto'
177
- } else if (this.realPlacement == 'top-start') {
178
- this.$refs.triangle.$el.style.left = (this.$refs.wrap.offsetWidth > firstRect.width ? firstRect.width : this.$refs.wrap.offsetWidth) / 2 - this.$refs.triangle.$el.offsetWidth / 2 + 'px'
179
- this.$refs.triangle.$el.style.right = 'auto'
180
- this.$refs.triangle.$el.style.top = this.$refs.wrap.offsetHeight - 1 + 'px'
181
- this.$refs.triangle.$el.style.bottom = 'auto'
182
- } else if (this.realPlacement == 'top-end') {
183
- this.$refs.triangle.$el.style.left = 'auto'
184
- this.$refs.triangle.$el.style.right = (this.$refs.wrap.offsetWidth > firstRect.width ? firstRect.width : this.$refs.wrap.offsetWidth) / 2 - this.$refs.triangle.$el.offsetWidth / 2 + 'px'
185
- this.$refs.triangle.$el.style.top = this.$refs.wrap.offsetHeight - 1 + 'px'
186
- this.$refs.triangle.$el.style.bottom = 'auto'
187
- } else if (this.realPlacement == 'bottom') {
188
- this.$refs.triangle.$el.style.left = this.$refs.wrap.offsetWidth / 2 - this.$refs.triangle.$el.offsetWidth / 2 + 'px'
189
- this.$refs.triangle.$el.style.right = 'auto'
190
- this.$refs.triangle.$el.style.top = 'auto'
191
- this.$refs.triangle.$el.style.bottom = this.$refs.wrap.offsetHeight - 1 + 'px'
192
- } else if (this.realPlacement == 'bottom-start') {
193
- this.$refs.triangle.$el.style.left = (this.$refs.wrap.offsetWidth > lastRect.width ? lastRect.width : this.$refs.wrap.offsetWidth) / 2 - this.$refs.triangle.$el.offsetWidth / 2 + 'px'
194
- this.$refs.triangle.$el.style.right = 'auto'
195
- this.$refs.triangle.$el.style.top = 'auto'
196
- this.$refs.triangle.$el.style.bottom = this.$refs.wrap.offsetHeight - 1 + 'px'
197
- } else if (this.realPlacement == 'bottom-end') {
198
- this.$refs.triangle.$el.style.left = 'auto'
199
- this.$refs.triangle.$el.style.right = (this.$refs.wrap.offsetWidth > lastRect.width ? lastRect.width : this.$refs.wrap.offsetWidth) / 2 - this.$refs.triangle.$el.offsetWidth / 2 + 'px'
200
- this.$refs.triangle.$el.style.top = 'auto'
201
- this.$refs.triangle.$el.style.bottom = this.$refs.wrap.offsetHeight - 1 + 'px'
202
- } else {
203
- this.$refs.triangle.$el.style.left = this.$refs.wrap.offsetWidth / 2 - this.$refs.triangle.$el.offsetWidth / 2 + 'px'
204
- this.$refs.triangle.$el.style.right = 'auto'
205
- this.$refs.triangle.$el.style.top = -this.$refs.triangle.$el.offsetHeight + 1 + 'px'
206
- this.$refs.triangle.$el.style.bottom = 'auto'
207
- }
208
- }
209
- }
210
- },
211
- //根据node设置三角形位置
212
- setTrianglePositionByNode() {
213
- const node = this.getNode()
214
- if (!DapElement.isElement(node)) {
215
- return
216
- }
217
- if (this.realPlacement == 'top') {
218
- this.$refs.triangle.$el.style.left = this.$refs.wrap.offsetWidth / 2 - this.$refs.triangle.$el.offsetWidth / 2 + 'px'
219
- this.$refs.triangle.$el.style.right = 'auto'
220
- this.$refs.triangle.$el.style.top = this.$refs.wrap.offsetHeight - 1 + 'px'
221
- this.$refs.triangle.$el.style.bottom = 'auto'
222
- } else if (this.realPlacement == 'top-start') {
223
- this.$refs.triangle.$el.style.left = (this.$refs.wrap.offsetWidth > node.offsetWidth ? node.offsetWidth : this.$refs.wrap.offsetWidth) / 2 - this.$refs.triangle.$el.offsetWidth / 2 + 'px'
224
- this.$refs.triangle.$el.style.right = 'auto'
225
- this.$refs.triangle.$el.style.top = this.$refs.wrap.offsetHeight - 1 + 'px'
226
- this.$refs.triangle.$el.style.bottom = 'auto'
227
- } else if (this.realPlacement == 'top-end') {
228
- this.$refs.triangle.$el.style.left = 'auto'
229
- this.$refs.triangle.$el.style.right = (this.$refs.wrap.offsetWidth > node.offsetWidth ? node.offsetWidth : this.$refs.wrap.offsetWidth) / 2 - this.$refs.triangle.$el.offsetWidth / 2 + 'px'
230
- this.$refs.triangle.$el.style.top = this.$refs.wrap.offsetHeight - 1 + 'px'
231
- this.$refs.triangle.$el.style.bottom = 'auto'
232
- } else if (this.realPlacement == 'bottom') {
233
- this.$refs.triangle.$el.style.left = this.$refs.wrap.offsetWidth / 2 - this.$refs.triangle.$el.offsetWidth / 2 + 'px'
234
- this.$refs.triangle.$el.style.right = 'auto'
235
- this.$refs.triangle.$el.style.top = 'auto'
236
- this.$refs.triangle.$el.style.bottom = this.$refs.wrap.offsetHeight - 1 + 'px'
237
- } else if (this.realPlacement == 'bottom-start') {
238
- this.$refs.triangle.$el.style.left = (this.$refs.wrap.offsetWidth > node.offsetWidth ? node.offsetWidth : this.$refs.wrap.offsetWidth) / 2 - this.$refs.triangle.$el.offsetWidth / 2 + 'px'
239
- this.$refs.triangle.$el.style.right = 'auto'
240
- this.$refs.triangle.$el.style.top = 'auto'
241
- this.$refs.triangle.$el.style.bottom = this.$refs.wrap.offsetHeight - 1 + 'px'
242
- } else if (this.realPlacement == 'bottom-end') {
243
- this.$refs.triangle.$el.style.left = 'auto'
244
- this.$refs.triangle.$el.style.right = (this.$refs.wrap.offsetWidth > node.offsetWidth ? node.offsetWidth : this.$refs.wrap.offsetWidth) / 2 - this.$refs.triangle.$el.offsetWidth / 2 + 'px'
245
- this.$refs.triangle.$el.style.top = 'auto'
246
- this.$refs.triangle.$el.style.bottom = this.$refs.wrap.offsetHeight - 1 + 'px'
247
- } else {
248
- this.$refs.triangle.$el.style.left = this.$refs.wrap.offsetWidth / 2 - this.$refs.triangle.$el.offsetWidth / 2 + 'px'
249
- this.$refs.triangle.$el.style.right = 'auto'
250
- this.$refs.triangle.$el.style.top = -this.$refs.triangle.$el.offsetHeight + 1 + 'px'
251
- this.$refs.triangle.$el.style.bottom = 'auto'
252
- }
253
- },
254
- //根据range设置位置
255
- setPositionByRange() {
256
- //重置
257
- this.realPlacement = null
258
- const selection = window.getSelection()
259
- if (selection.rangeCount) {
260
- const range = selection.getRangeAt(0)
261
- const rects = range.getClientRects()
262
- if (rects.length) {
263
- //range的第一个位置
264
- const firstRect = rects[0]
265
- //range的最后一个位置
266
- const lastRect = rects[rects.length - 1]
267
- //定位父元素的位置
268
- const parentRect = DapElement.getElementBounding(this.$el.offsetParent)
269
- //可视窗口高度
270
- const documentHeight = document.documentElement.clientHeight || window.innerHeight
271
- //可视窗口宽度
272
- const documentWidth = document.documentElement.clientWidth || window.innerWidth
273
-
274
- if (this.placement == 'top' || this.placement == 'top-start' || this.placement == 'top-end') {
275
- if (firstRect.top >= 0 && firstRect.top >= parentRect.top && firstRect.top >= this.$el.offsetHeight) {
276
- this.realPlacement = this.placement
277
- } else if (documentHeight - lastRect.bottom >= 0 && documentHeight - lastRect.bottom >= parentRect.bottom && documentHeight - lastRect.bottom >= this.$el.offsetHeight) {
278
- this.realPlacement = this.placement == 'top' ? 'bottom' : this.placement == 'top-start' ? 'bottom-start' : 'bottom-end'
279
- }
280
- } else if (this.placement == 'bottom' || this.placement == 'bottom-start' || this.placement == 'bottom-end') {
281
- if (documentHeight - lastRect.bottom >= 0 && documentHeight - lastRect.bottom >= parentRect.bottom && documentHeight - lastRect.bottom >= this.$el.offsetHeight) {
282
- this.realPlacement = this.placement
283
- } else if (firstRect.top >= 0 && firstRect.top >= parentRect.top && firstRect.top >= this.$el.offsetHeight) {
284
- this.realPlacement = this.placement == 'bottom' ? 'top' : this.placement == 'bottom-start' ? 'top-start' : 'top-end'
285
- }
286
- }
287
-
288
- //判断左右是否足够空间显示
289
- if (this.realPlacement == 'top') {
290
- if (documentWidth - firstRect.right + firstRect.width / 2 < this.$el.offsetWidth / 2) {
291
- this.realPlacement = 'top-end'
292
- } else if (firstRect.left + firstRect.width / 2 < this.$el.offsetWidth / 2) {
293
- this.realPlacement = 'top-start'
294
- }
295
- } else if (this.realPlacement == 'bottom') {
296
- if (documentWidth - lastRect.right + lastRect.width / 2 < this.$el.offsetWidth / 2) {
297
- this.realPlacement = 'bottom-end'
298
- } else if (lastRect.left + lastRect.width / 2 < this.$el.offsetWidth / 2) {
299
- this.realPlacement = 'bottom-start'
300
- }
301
- } else if (this.realPlacement == 'top-start') {
302
- if (documentWidth - firstRect.right + firstRect.width < this.$el.offsetWidth) {
303
- if (documentWidth - firstRect.right + firstRect.width / 2 >= this.$el.offsetWidth / 2) {
304
- this.realPlacement = 'top'
305
- } else {
306
- this.realPlacement = 'top-end'
307
- }
308
- }
309
- } else if (this.realPlacement == 'bottom-start') {
310
- if (documentWidth - lastRect.right + lastRect.width < this.$el.offsetWidth) {
311
- if (documentWidth - lastRect.right + lastRect.width / 2 >= this.$el.offsetWidth / 2) {
312
- this.realPlacement = 'bottom'
313
- } else {
314
- this.realPlacement = 'bottom-end'
315
- }
316
- }
317
- } else if (this.realPlacement == 'top-end') {
318
- if (firstRect.left + firstRect.width < this.$el.offsetWidth) {
319
- if (firstRect.left + firstRect.width / 2 >= this.$el.offsetWidth / 2) {
320
- this.realPlacement = 'top'
321
- } else {
322
- this.realPlacement = 'top-start'
323
- }
324
- }
325
- } else if (this.realPlacement == 'bottom-end') {
326
- if (lastRect.left + lastRect.width < this.$el.offsetWidth) {
327
- if (lastRect.left + lastRect.width / 2 >= this.$el.offsetWidth / 2) {
328
- this.realPlacement = 'bottom'
329
- } else {
330
- this.realPlacement = 'bottom-start'
331
- }
332
- }
333
- }
334
- this.$nextTick(() => {
335
- //设置位置对应的样式
336
- if (this.realPlacement == 'top') {
337
- this.$el.style.left = firstRect.left - parentRect.left + firstRect.width / 2 - this.$el.offsetWidth / 2 + 'px'
338
- this.$el.style.right = 'auto'
339
- this.$el.style.top = firstRect.top - parentRect.top - this.$el.offsetHeight + 'px'
340
- this.$el.style.bottom = 'auto'
341
- } else if (this.realPlacement == 'top-start') {
342
- this.$el.style.left = firstRect.left - parentRect.left + 'px'
343
- this.$el.style.right = 'auto'
344
- this.$el.style.top = firstRect.top - parentRect.top - this.$el.offsetHeight + 'px'
345
- this.$el.style.bottom = 'auto'
346
- } else if (this.realPlacement == 'top-end') {
347
- this.$el.style.left = 'auto'
348
- this.$el.style.right = documentWidth - firstRect.right - parentRect.right + 'px'
349
- this.$el.style.top = firstRect.top - parentRect.top - this.$el.offsetHeight + 'px'
350
- this.$el.style.bottom = 'auto'
351
- } else if (this.realPlacement == 'bottom') {
352
- this.$el.style.left = lastRect.left - parentRect.left + lastRect.width / 2 - this.$el.offsetWidth / 2 + 'px'
353
- this.$el.style.right = 'auto'
354
- this.$el.style.top = 'auto'
355
- this.$el.style.bottom = documentHeight - lastRect.bottom - parentRect.bottom - this.$el.offsetHeight + 'px'
356
- } else if (this.realPlacement == 'bottom-start') {
357
- this.$el.style.left = lastRect.left - parentRect.left + 'px'
358
- this.$el.style.right = 'auto'
359
- this.$el.style.top = 'auto'
360
- this.$el.style.bottom = documentHeight - lastRect.bottom - parentRect.bottom - this.$el.offsetHeight + 'px'
361
- } else if (this.realPlacement == 'bottom-end') {
362
- this.$el.style.left = 'auto'
363
- this.$el.style.right = documentWidth - lastRect.right - parentRect.right + 'px'
364
- this.$el.style.top = 'auto'
365
- this.$el.style.bottom = documentHeight - lastRect.bottom - parentRect.bottom - this.$el.offsetHeight + 'px'
366
- } else {
367
- this.$el.style.top = 'auto'
368
- this.$el.style.bottom = (parentRect.bottom < 0 ? -parentRect.bottom : 0) + 'px'
369
- if (this.placement == 'top') {
370
- //top-end
371
- if (documentWidth - firstRect.right + firstRect.width / 2 < this.$el.offsetWidth / 2) {
372
- this.$el.style.left = 'auto'
373
- this.$el.style.right = documentWidth - firstRect.right - parentRect.right + 'px'
374
- }
375
- //top-start
376
- else if (firstRect.left + firstRect.width / 2 < this.$el.offsetWidth / 2) {
377
- this.$el.style.left = firstRect.left - parentRect.left + 'px'
378
- this.$el.style.right = 'auto'
379
- }
380
- //top
381
- else {
382
- this.$el.style.left = firstRect.left - parentRect.left + firstRect.width / 2 - this.$el.offsetWidth / 2 + 'px'
383
- this.$el.style.right = 'auto'
384
- }
385
- } else if (this.placement == 'bottom') {
386
- //bottom-end
387
- if (documentWidth - lastRect.right + lastRect.width / 2 < this.$el.offsetWidth / 2) {
388
- this.$el.style.left = 'auto'
389
- this.$el.style.right = documentWidth - lastRect.right - parentRect.right + 'px'
390
- }
391
- //bottom-start
392
- else if (lastRect.left + lastRect.width / 2 < this.$el.offsetWidth / 2) {
393
- this.$el.style.left = lastRect.left - parentRect.left + 'px'
394
- this.$el.style.right = 'auto'
395
- }
396
- //bottom
397
- else {
398
- this.$el.style.left = lastRect.left - parentRect.left + lastRect.width / 2 - this.$el.offsetWidth / 2 + 'px'
399
- this.$el.style.right = 'auto'
400
- }
401
- } else if (this.placement == 'top-start') {
402
- if (documentWidth - firstRect.right + firstRect.width < this.$el.offsetWidth) {
403
- //top
404
- if (documentWidth - firstRect.right + firstRect.width / 2 >= this.$el.offsetWidth / 2) {
405
- this.$el.style.left = firstRect.left - parentRect.left + firstRect.width / 2 - this.$el.offsetWidth / 2 + 'px'
406
- this.$el.style.right = 'auto'
407
- }
408
- //top-end
409
- else {
410
- this.$el.style.left = 'auto'
411
- this.$el.style.right = documentWidth - firstRect.right - parentRect.right + 'px'
412
- }
413
- }
414
- //top-start
415
- else {
416
- this.$el.style.left = firstRect.left - parentRect.left + 'px'
417
- this.$el.style.right = 'auto'
418
- }
419
- } else if (this.placement == 'bottom-start') {
420
- if (documentWidth - lastRect.right + lastRect.width < this.$el.offsetWidth) {
421
- //bottom
422
- if (documentWidth - lastRect.right + lastRect.width / 2 >= this.$el.offsetWidth / 2) {
423
- this.$el.style.left = lastRect.left - parentRect.left + lastRect.width / 2 - this.$el.offsetWidth / 2 + 'px'
424
- this.$el.style.right = 'auto'
425
- }
426
- //bottom-end
427
- else {
428
- this.$el.style.left = 'auto'
429
- this.$el.style.right = documentWidth - lastRect.right - parentRect.right + 'px'
430
- }
431
- }
432
- //bottom-start
433
- else {
434
- this.$el.style.left = lastRect.left - parentRect.left + 'px'
435
- this.$el.style.right = 'auto'
436
- }
437
- } else if (this.placement == 'top-end') {
438
- if (firstRect.left + firstRect.width < this.$el.offsetWidth) {
439
- //top
440
- if (firstRect.left + firstRect.width / 2 >= this.$el.offsetWidth / 2) {
441
- this.$el.style.left = firstRect.left - parentRect.left + firstRect.width / 2 - this.$el.offsetWidth / 2 + 'px'
442
- this.$el.style.right = 'auto'
443
- }
444
- //top-start
445
- else {
446
- this.$el.style.left = firstRect.left - parentRect.left + 'px'
447
- this.$el.style.right = 'auto'
448
- }
449
- }
450
- //top-end
451
- else {
452
- this.$el.style.left = 'auto'
453
- this.$el.style.right = documentWidth - firstRect.right - parentRect.right + 'px'
454
- }
455
- } else if (this.placement == 'bottom-end') {
456
- if (lastRect.left + lastRect.width < this.$el.offsetWidth) {
457
- //bottom
458
- if (lastRect.left + lastRect.width / 2 >= this.$el.offsetWidth / 2) {
459
- this.$el.style.left = lastRect.left - parentRect.left + lastRect.width / 2 - this.$el.offsetWidth / 2 + 'px'
460
- this.$el.style.right = 'auto'
461
- }
462
- //bottom-start
463
- else {
464
- this.$el.style.left = lastRect.left - parentRect.left + 'px'
465
- this.$el.style.right = 'auto'
466
- }
467
- }
468
- //bottom-end
469
- else {
470
- this.$el.style.left = 'auto'
471
- this.$el.style.right = documentWidth - lastRect.right - parentRect.right + 'px'
472
- }
473
- }
474
- }
475
- //三角形位置
476
- if (this.showTriangle) {
477
- this.setTrianglePositionByRange()
478
- }
479
- })
480
- }
481
- }
482
- },
483
- //根据node设置位置
484
- setPositionByNode() {
485
- const node = this.getNode()
486
- if (!DapElement.isElement(node)) {
487
- return
488
- }
489
- //重置
490
- this.realPlacement = null
491
- //关联元素位置
492
- const nodeRect = DapElement.getElementBounding(node)
493
- //定位父元素位置
494
- const parentRect = DapElement.getElementBounding(this.$el.offsetParent)
495
- //设置真实的位置
496
- if (this.placement == 'top' || this.placement == 'top-start' || this.placement == 'top-end') {
497
- if (nodeRect.top >= 0 && nodeRect.top >= parentRect.top && nodeRect.top >= this.$el.offsetHeight) {
498
- this.realPlacement = this.placement
499
- } else if (nodeRect.bottom >= 0 && nodeRect.bottom >= parentRect.bottom && nodeRect.bottom >= this.$el.offsetHeight) {
500
- this.realPlacement = this.placement == 'top' ? 'bottom' : this.placement == 'top-start' ? 'bottom-start' : 'bottom-end'
501
- }
502
- } else if (this.placement == 'bottom' || this.placement == 'bottom-start' || this.placement == 'bottom-end') {
503
- if (nodeRect.bottom >= 0 && nodeRect.bottom >= parentRect.bottom && nodeRect.bottom >= this.$el.offsetHeight) {
504
- this.realPlacement = this.placement
505
- } else if (nodeRect.top >= 0 && nodeRect.top >= parentRect.top && nodeRect.top >= this.$el.offsetHeight) {
506
- this.realPlacement = this.placement == 'bottom' ? 'top' : this.placement == 'bottom-start' ? 'top-start' : 'top-end'
507
- }
508
- }
509
- //判断左右是否足够空间显示
510
- if (this.realPlacement == 'top') {
511
- if (nodeRect.right + node.offsetWidth / 2 < this.$el.offsetWidth / 2) {
512
- this.realPlacement = 'top-end'
513
- } else if (nodeRect.left + node.offsetWidth / 2 < this.$el.offsetWidth / 2) {
514
- this.realPlacement = 'top-start'
515
- }
516
- } else if (this.realPlacement == 'top-start') {
517
- if (nodeRect.right + node.offsetWidth < this.$el.offsetWidth) {
518
- if (nodeRect.right + node.offsetWidth / 2 >= this.$el.offsetWidth / 2) {
519
- this.realPlacement = 'top'
520
- } else {
521
- this.realPlacement = 'top-end'
522
- }
523
- }
524
- } else if (this.realPlacement == 'top-end') {
525
- if (nodeRect.left + node.offsetWidth < this.$el.offsetWidth) {
526
- if (nodeRect.left + node.offsetWidth / 2 >= this.$el.offsetWidth / 2) {
527
- this.realPlacement = 'top'
528
- } else {
529
- this.realPlacement = 'top-start'
530
- }
531
- }
532
- } else if (this.realPlacement == 'bottom') {
533
- if (nodeRect.right + node.offsetWidth / 2 < this.$el.offsetWidth / 2) {
534
- this.realPlacement = 'bottom-end'
535
- } else if (nodeRect.left + node.offsetWidth / 2 < this.$el.offsetWidth / 2) {
536
- this.realPlacement = 'bottom-start'
537
- }
538
- } else if (this.realPlacement == 'bottom-start') {
539
- if (nodeRect.right + node.offsetWidth < this.$el.offsetWidth) {
540
- if (nodeRect.right + node.offsetWidth / 2 >= this.$el.offsetWidth / 2) {
541
- this.realPlacement = 'bottom'
542
- } else {
543
- this.realPlacement = 'bottom-end'
544
- }
545
- }
546
- } else if (this.realPlacement == 'bottom-end') {
547
- if (nodeRect.left + node.offsetWidth < this.$el.offsetWidth) {
548
- if (nodeRect.left + node.offsetWidth / 2 >= this.$el.offsetWidth / 2) {
549
- this.realPlacement = 'bottom'
550
- } else {
551
- this.realPlacement = 'bottom-start'
552
- }
553
- }
554
- }
555
-
556
- this.$nextTick(() => {
557
- //设置位置对应的样式
558
- if (this.realPlacement == 'top') {
559
- this.$el.style.left = nodeRect.left - parentRect.left + node.offsetWidth / 2 - this.$el.offsetWidth / 2 + 'px'
560
- this.$el.style.right = 'auto'
561
- this.$el.style.top = nodeRect.top - parentRect.top - this.$el.offsetHeight + 'px'
562
- this.$el.style.bottom = 'auto'
563
- } else if (this.realPlacement == 'top-start') {
564
- this.$el.style.left = nodeRect.left - parentRect.left + 'px'
565
- this.$el.style.right = 'auto'
566
- this.$el.style.top = nodeRect.top - parentRect.top - this.$el.offsetHeight + 'px'
567
- this.$el.style.bottom = 'auto'
568
- } else if (this.realPlacement == 'top-end') {
569
- this.$el.style.left = 'auto'
570
- this.$el.style.right = nodeRect.right - parentRect.right + 'px'
571
- this.$el.style.top = nodeRect.top - parentRect.top - this.$el.offsetHeight + 'px'
572
- this.$el.style.bottom = 'auto'
573
- } else if (this.realPlacement == 'bottom') {
574
- this.$el.style.left = nodeRect.left - parentRect.left + node.offsetWidth / 2 - this.$el.offsetWidth / 2 + 'px'
575
- this.$el.style.right = 'auto'
576
- this.$el.style.top = 'auto'
577
- this.$el.style.bottom = nodeRect.bottom - parentRect.bottom - this.$el.offsetHeight + 'px'
578
- } else if (this.realPlacement == 'bottom-start') {
579
- this.$el.style.left = nodeRect.left - parentRect.left + 'px'
580
- this.$el.style.right = 'auto'
581
- this.$el.style.top = 'auto'
582
- this.$el.style.bottom = nodeRect.bottom - parentRect.bottom - this.$el.offsetHeight + 'px'
583
- } else if (this.realPlacement == 'bottom-end') {
584
- this.$el.style.left = 'auto'
585
- this.$el.style.right = nodeRect.right - parentRect.right + 'px'
586
- this.$el.style.top = 'auto'
587
- this.$el.style.bottom = nodeRect.bottom - parentRect.bottom - this.$el.offsetHeight + 'px'
588
- } else {
589
- this.$el.style.top = 'auto'
590
- this.$el.style.bottom = (parentRect.bottom < 0 ? -parentRect.bottom : 0) + 'px'
591
- if (this.placement == 'top' || this.placement == 'bottom') {
592
- if (nodeRect.right + node.offsetWidth / 2 < this.$el.offsetWidth / 2) {
593
- this.$el.style.left = 'auto'
594
- this.$el.style.right = nodeRect.right - parentRect.right + 'px'
595
- } else if (nodeRect.left + node.offsetWidth / 2 < this.$el.offsetWidth / 2) {
596
- this.$el.style.left = nodeRect.left - parentRect.left + 'px'
597
- this.$el.style.right = 'auto'
598
- } else {
599
- this.$el.style.left = nodeRect.left - parentRect.left + node.offsetWidth / 2 - this.$el.offsetWidth / 2 + 'px'
600
- this.$el.style.right = 'auto'
601
- }
602
- } else if (this.placement == 'top-start' || this.placement == 'bottom-start') {
603
- if (nodeRect.right + node.offsetWidth < this.$el.offsetWidth) {
604
- if (nodeRect.right + node.offsetWidth / 2 >= this.$el.offsetWidth / 2) {
605
- this.$el.style.left = nodeRect.left - parentRect.left + node.offsetWidth / 2 - this.$el.offsetWidth / 2 + 'px'
606
- this.$el.style.right = 'auto'
607
- } else {
608
- this.$el.style.left = 'auto'
609
- this.$el.style.right = nodeRect.right - parentRect.right + 'px'
610
- }
611
- } else {
612
- this.$el.style.left = nodeRect.left - parentRect.left + 'px'
613
- this.$el.style.right = 'auto'
614
- }
615
- } else if (this.placement == 'top-end' || this.placement == 'bottom-end') {
616
- if (nodeRect.left + node.offsetWidth < this.$el.offsetWidth) {
617
- if (nodeRect.left + node.offsetWidth / 2 >= this.$el.offsetWidth / 2) {
618
- this.$el.style.left = nodeRect.left - parentRect.left + node.offsetWidth / 2 - this.$el.offsetWidth / 2 + 'px'
619
- this.$el.style.right = 'auto'
620
- } else {
621
- this.$el.style.left = nodeRect.left - parentRect.left + 'px'
622
- this.$el.style.right = 'auto'
623
- }
624
- } else {
625
- this.$el.style.left = 'auto'
626
- this.$el.style.right = nodeRect.right - parentRect.right + 'px'
627
- }
628
- }
629
- }
630
- //三角形位置
631
- if (this.showTriangle) {
632
- this.setTrianglePositionByNode()
633
- }
634
- })
635
- },
636
- //设置位置
637
- setPosition() {
638
- //如果根据range来定位
639
- if (this.useRange) {
640
- this.setPositionByRange()
641
- }
642
- //根据传入的node来定位
643
- else {
644
- this.setPositionByNode()
645
- }
646
- },
647
- //获取目标元素
648
- getNode() {
649
- if (!this.node) {
650
- return null
651
- }
652
- if (DapElement.isElement(this.node)) {
653
- return this.node
654
- }
655
- return document.body.querySelector(this.node)
656
- }
657
- },
658
- beforeUnmount() {
659
- DapEvent.off(window, `click.editify_layer_${this.uid} resize.editify_layer_${this.uid}`)
660
- }
661
- }
662
- </script>
663
- <style lang="less" scoped>
664
- .editify-layer-fade-enter-from,
665
- .editify-layer-fade-leave-to {
666
- opacity: 0;
667
- }
668
- .editify-layer-fade-enter-active,
669
- .editify-layer-fade-leave-active {
670
- transition: opacity 200ms linear;
671
- }
672
-
673
- .editify-layer-translate-enter-from,
674
- .editify-layer-translate-leave-to {
675
- opacity: 0;
676
- transform: translateY(20px);
677
- }
678
-
679
- .editify-layer-translate-enter-active,
680
- .editify-layer-translate-leave-active {
681
- transition: opacity 200ms ease-in-out, transform 200ms ease-in-out;
682
- }
683
-
684
- .editify-layer {
685
- display: block;
686
- position: absolute;
687
- padding: 0 0 10px 0;
688
- font-size: @font-size;
689
- color: @font-color;
690
-
691
- &[data-editify-placement='bottom'],
692
- &[data-editify-placement='bottom-start'],
693
- &[data-editify-placement='bottom-end'] {
694
- padding: 10px 0 0 0;
695
- }
696
-
697
- :deep(.editify-triangle) {
698
- position: absolute;
699
- z-index: 1;
700
- }
701
-
702
- .editify-layer-wrap {
703
- display: block;
704
- background-color: @background;
705
- box-shadow: 0px 2px 10px rgba(0, 0, 0, 0.1);
706
- border-radius: 4px;
707
-
708
- &.border {
709
- border: 1px solid @border-color;
710
- }
711
- }
712
- }
713
- </style>