@aochuang/client-sdk 1.0.310 → 1.0.312

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -36,16 +36,114 @@
36
36
  </div>
37
37
  </template>
38
38
  <script>
39
- import UiContextMenuBox from './context-menu-box'
40
- import UiContextMenuGroup from './context-menu-group'
41
- import UiContextMenuItem from './context-menu-item'
39
+ import UiContextMenuBox from './context-menu-box'
40
+ import UiContextMenuGroup from './context-menu-group'
41
+ import UiContextMenuItem from './context-menu-item'
42
+ import { isMobile } from '@aochuang/common/utils/browse.js'
42
43
 
43
- import {
44
- getOptimalCoordinate,
45
- getWindowRect,
46
- createRectByXY,
47
- getElementRect
48
- } from './utils.js'
44
+ import {
45
+ getOptimalCoordinate,
46
+ getWindowRect,
47
+ createRectByXY,
48
+ getElementRect
49
+ } from './utils.js'
50
+
51
+ let mobileContextMenuMountCount = 0
52
+ let longPressTimer = null
53
+ let longPressStart = null
54
+ let longPressTriggered = false
55
+
56
+ function clearLongPressTimer () {
57
+ clearTimeout(longPressTimer)
58
+ longPressTimer = null
59
+ }
60
+
61
+ function handleDocumentTouchStart (event) {
62
+ if (event.touches.length !== 1) {
63
+ clearLongPressTimer()
64
+ return
65
+ }
66
+ const touch = event.touches[0]
67
+ longPressStart = {
68
+ target: event.target,
69
+ clientX: touch.clientX,
70
+ clientY: touch.clientY
71
+ }
72
+ longPressTriggered = false
73
+ clearLongPressTimer()
74
+ longPressTimer = setTimeout(() => {
75
+ if (!longPressStart || !longPressStart.target) {
76
+ return
77
+ }
78
+ longPressTriggered = true
79
+ longPressStart.target.dispatchEvent(new MouseEvent('contextmenu', {
80
+ bubbles: true,
81
+ cancelable: true,
82
+ clientX: longPressStart.clientX,
83
+ clientY: longPressStart.clientY
84
+ }))
85
+ }, 500)
86
+ }
87
+
88
+ function handleDocumentTouchMove (event) {
89
+ const touch = event.touches[0]
90
+ if (!longPressStart || !touch) {
91
+ return
92
+ }
93
+ if (Math.abs(touch.clientX - longPressStart.clientX) > 10 || Math.abs(touch.clientY - longPressStart.clientY) > 10) {
94
+ clearLongPressTimer()
95
+ longPressStart = null
96
+ }
97
+ }
98
+
99
+ function handleDocumentTouchEnd (event) {
100
+ clearLongPressTimer()
101
+ longPressStart = null
102
+ if (longPressTriggered) {
103
+ event.preventDefault()
104
+ longPressTriggered = false
105
+ }
106
+ }
107
+
108
+ function handleDocumentTouchCancel () {
109
+ clearLongPressTimer()
110
+ longPressStart = null
111
+ longPressTriggered = false
112
+ }
113
+
114
+ function handleDocumentContextMenu (event) {
115
+ event.preventDefault()
116
+ }
117
+
118
+ function addMobileContextMenuListeners () {
119
+ mobileContextMenuMountCount++
120
+ if (mobileContextMenuMountCount !== 1) {
121
+ return
122
+ }
123
+ window.document.addEventListener('touchstart', handleDocumentTouchStart, { passive: true })
124
+ window.document.addEventListener('touchmove', handleDocumentTouchMove, { passive: true })
125
+ window.document.addEventListener('touchend', handleDocumentTouchEnd, { passive: false })
126
+ window.document.addEventListener('touchcancel', handleDocumentTouchCancel, { passive: true })
127
+ window.document.addEventListener('contextmenu', handleDocumentContextMenu)
128
+ window.document.documentElement.classList.add('ui-context-menu-mobile')
129
+ }
130
+
131
+ function removeMobileContextMenuListeners () {
132
+ mobileContextMenuMountCount--
133
+ if (mobileContextMenuMountCount > 0) {
134
+ return
135
+ }
136
+ mobileContextMenuMountCount = 0
137
+ clearLongPressTimer()
138
+ longPressStart = null
139
+ longPressTriggered = false
140
+ window.document.removeEventListener('touchstart', handleDocumentTouchStart)
141
+ window.document.removeEventListener('touchmove', handleDocumentTouchMove)
142
+ window.document.removeEventListener('touchend', handleDocumentTouchEnd)
143
+ window.document.removeEventListener('touchcancel', handleDocumentTouchCancel)
144
+ window.document.removeEventListener('contextmenu', handleDocumentContextMenu)
145
+ window.document.documentElement.classList.remove('ui-context-menu-mobile')
146
+ }
49
147
 
50
148
  export default {
51
149
  name: 'UiContextMenu',
@@ -93,10 +191,12 @@ export default {
93
191
  return this.innerData.filter(v => !v.divided)
94
192
  }
95
193
  },
96
- mounted () {
97
- window.document.addEventListener('mousewheel', this.handleDocumentMouseWheel)
98
- window.document.addEventListener('mousedown', this.handleDocumentMouseDown)
99
- // window.document.addEventListener('contextmenu', this.handleDocumentContextMenu)
194
+ mounted () {
195
+ window.document.addEventListener('mousewheel', this.handleDocumentMouseWheel)
196
+ window.document.addEventListener('mousedown', this.handleDocumentMouseDown)
197
+ if (isMobile()) {
198
+ addMobileContextMenuListeners()
199
+ }
100
200
  },
101
201
  watch: {
102
202
  value: {
@@ -105,9 +205,9 @@ export default {
105
205
  val ? this.open(this.left, this.top) : this.close()
106
206
  }
107
207
  }
108
- },
109
- methods: {
110
- handleGroupClick () {
208
+ },
209
+ methods: {
210
+ handleGroupClick () {
111
211
  this.close()
112
212
  },
113
213
  handleGroupItemClick ({ item }) {
@@ -175,16 +275,21 @@ export default {
175
275
  this.activeSubItem = null
176
276
  this.$emit('input', false)
177
277
  }
178
- },
179
- beforeUnmount () {
180
- window.document.removeEventListener('mousewheel', this.handleDocumentMouseWheel)
181
- window.document.removeEventListener('mousedown', this.handleDocumentMouseDown)
182
- // window.document.removeEventListener('contextmenu', this.handleDocumentContextMenu)
183
- }
184
- }
278
+ },
279
+ beforeDestroy () {
280
+ window.document.removeEventListener('mousewheel', this.handleDocumentMouseWheel)
281
+ window.document.removeEventListener('mousedown', this.handleDocumentMouseDown)
282
+ if (isMobile()) {
283
+ removeMobileContextMenuListeners()
284
+ }
285
+ }
286
+ }
185
287
  </script>
186
- <style>
187
- .ui-context-menu * {
288
+ <style>
289
+ .ui-context-menu-mobile {
290
+ -webkit-touch-callout: none;
291
+ }
292
+ .ui-context-menu * {
188
293
  box-sizing: content-box;
189
294
  }
190
295
  .ui-context-menu{
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <ui-tooltip :disabled="!tips" :content="tips">
2
+ <ui-tooltip :disabled="!tips || isMobile" :content="tips">
3
3
  <div class="sdk-chat-editor-button" :class="{'is-active': active}" @click.stop="handleClick">
4
4
  <template v-if="loading">
5
5
  <ui-loading size="mini"></ui-loading>
@@ -18,6 +18,7 @@
18
18
  </template>
19
19
  <script>
20
20
  import { Tooltip as UiTooltip, Loading as UiLoading } from '@aochuang/common/components'
21
+ import { isMobile } from '@aochuang/common/utils/browse.js'
21
22
 
22
23
  export default {
23
24
  name: 'SdkChatEditorButton',
@@ -25,6 +26,11 @@ export default {
25
26
  UiLoading,
26
27
  UiTooltip
27
28
  },
29
+ data () {
30
+ return {
31
+ isMobile: isMobile()
32
+ }
33
+ },
28
34
  props: {
29
35
  tips: {
30
36
  type: String
@@ -75,4 +81,4 @@ export default {
75
81
  height: 100%;
76
82
  vertical-align: top;
77
83
  }
78
- </style>
84
+ </style>
@@ -1,6 +1,7 @@
1
1
  <template>
2
2
  <div
3
3
  class="sdk-chat-editor-suggestions"
4
+ :class="{'is-mobile': isMobile}"
4
5
  v-if="isShow"
5
6
  >
6
7
  <div class="sdk-chat-editor-suggestions__head">
@@ -49,6 +50,7 @@
49
50
  </template>
50
51
  <script>
51
52
  import { Loading as UiLoading } from '@aochuang/common/components'
53
+ import { isMobile } from '@aochuang/common/utils/browse.js'
52
54
 
53
55
  export default {
54
56
  name: 'SdkChatEditorSuggestions',
@@ -73,7 +75,8 @@ export default {
73
75
  data () {
74
76
  return {
75
77
  closed: false,
76
- focusId: null
78
+ focusId: null,
79
+ isMobile: isMobile()
77
80
  }
78
81
  },
79
82
  computed: {
@@ -227,6 +230,18 @@ export default {
227
230
  display: flex;
228
231
  flex-direction: column;
229
232
  }
233
+ .sdk-chat-editor-suggestions.is-mobile {
234
+ box-sizing: border-box;
235
+ width: 100%;
236
+ min-width: 0;
237
+ max-width: none;
238
+ }
239
+ .sdk-chat-editor-suggestions.is-mobile .sdk-chat-editor-suggestions__body {
240
+ overflow-x: hidden;
241
+ }
242
+ .sdk-chat-editor-suggestions.is-mobile .sdk-chat-editor-suggestions__foot {
243
+ flex-wrap: wrap;
244
+ }
230
245
  .sdk-chat-editor-suggestions__head{
231
246
  line-height: 24px;
232
247
  padding: 4px 12px;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aochuang/client-sdk",
3
- "version": "1.0.310",
3
+ "version": "1.0.312",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"