@aochuang/client-sdk 1.0.281 → 1.0.283

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.
@@ -20,8 +20,10 @@
20
20
  @paste="handleInputPaste"
21
21
  @keydown="handleInputKeydown"
22
22
  @keyup="handleInputKeyup"
23
+ @mouseup="handleInputMouseup"
23
24
  @input="handleInputValueChange"
24
25
  @focus="handleInputFocus"
26
+ @blur="handleInputBlur"
25
27
  ></div>
26
28
  </div>
27
29
  <template v-if="$slots.addon">
@@ -147,7 +149,7 @@ export default {
147
149
  if (this.disabled) {
148
150
  return
149
151
  }
150
- this.cacheInputRange = this.getSelectionTextRange()
152
+ this.cacheCurrentInputRange()
151
153
  },
152
154
  handleBeforeInput (evt) {
153
155
  if (this.disabled) {
@@ -199,7 +201,19 @@ export default {
199
201
  if (this.disabled) {
200
202
  return
201
203
  }
202
- this.cacheInputRange = this.getSelectionTextRange()
204
+ this.cacheCurrentInputRange()
205
+ },
206
+ handleInputMouseup () {
207
+ if (this.disabled) {
208
+ return
209
+ }
210
+ this.cacheCurrentInputRange()
211
+ },
212
+ handleInputBlur () {
213
+ if (this.disabled) {
214
+ return
215
+ }
216
+ this.cacheCurrentInputRange()
203
217
  },
204
218
  handleInputPaste (evt) {
205
219
  if (this.disabled) {
@@ -268,7 +282,7 @@ export default {
268
282
  if (!this.hasMaxlength()) {
269
283
  return Infinity
270
284
  }
271
- const range = this.getSelectionTextRange()
285
+ const range = this.getSafeRange() ? this.getSelectionTextRange() : (this.cacheInputRange || this.getSelectionTextRange())
272
286
  const selectedLength = Math.max(0, range.end - range.start)
273
287
  return Math.max(0, this.maxlength - (this.getInputText().length - selectedLength))
274
288
  },
@@ -408,12 +422,23 @@ export default {
408
422
  }
409
423
  return range
410
424
  },
411
- focus () {
425
+ cacheCurrentInputRange () {
426
+ const range = this.getSafeRange()
427
+ if (!range) {
428
+ return false
429
+ }
430
+ this.cacheInputRange = {
431
+ start: this.getTextOffsetByDomPoint(range.startContainer, range.startOffset),
432
+ end: this.getTextOffsetByDomPoint(range.endContainer, range.endOffset)
433
+ }
434
+ return true
435
+ },
436
+ focus (options = {}) {
412
437
  if (!this.$refs.input || this.disabled) {
413
438
  return
414
439
  }
415
440
  this.$refs.input.focus()
416
- if (!this.getSafeRange()) {
441
+ if (options.resetCursor || !this.getSafeRange()) {
417
442
  this.setCursorByTextOffset(this.getInputText().length)
418
443
  }
419
444
  },
@@ -626,7 +651,12 @@ export default {
626
651
  return ['DIV', 'P', 'LI'].includes(node.tagName)
627
652
  },
628
653
  insertNodesAtSelection (nodes) {
654
+ const cachedRange = this.cacheInputRange ? Object.assign({}, this.cacheInputRange) : null
655
+ const shouldRestoreCachedRange = !this.getSafeRange() && cachedRange
629
656
  this.focus()
657
+ if (shouldRestoreCachedRange) {
658
+ this.setSelectionByTextRange(cachedRange.start, cachedRange.end)
659
+ }
630
660
  let range = this.getSafeRange()
631
661
  if (!range) {
632
662
  this.setCursorByTextOffset(this.getInputText().length)
@@ -644,6 +674,7 @@ export default {
644
674
  })
645
675
  if (lastNode) {
646
676
  this.setCursorAfterNode(lastNode)
677
+ this.cacheCurrentInputRange()
647
678
  }
648
679
  },
649
680
  insertFragmentAtSelection (fragment) {
@@ -787,7 +818,7 @@ export default {
787
818
  this.setInputText(this.inputValue.slice(0, this.maxlength))
788
819
  this.setCursorByTextOffset(this.inputValue.length)
789
820
  }
790
- this.cacheInputRange = this.getSelectionTextRange()
821
+ this.cacheCurrentInputRange()
791
822
  if (this._skipNextSuggestionsLoad) {
792
823
  this._skipNextSuggestionsLoad = false
793
824
  } else {
@@ -67,7 +67,7 @@ export default {
67
67
  },
68
68
  avatarField: {
69
69
  type: String,
70
- default: 'avatar'
70
+ default: 'chatroomAvatar'
71
71
  },
72
72
  disabledMethod: {
73
73
  type: Function
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aochuang/client-sdk",
3
- "version": "1.0.281",
3
+ "version": "1.0.283",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"