'f'
mh-two-thousand-and-two
2024-04-12 26f2711ef9461961fb953e2b497bd314ef95e345
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import {
  callback
} from 'uni-shared'
 
function operateEditor (componentId, pageId, type, data) {
  UniServiceJSBridge.publishHandler(pageId + '-editor-' + componentId, {
    componentId,
    type,
    data
  }, pageId)
}
 
UniServiceJSBridge.subscribe('onEditorMethodCallback', ({
  callbackId,
  data
}) => {
  callback.invoke(callbackId, data)
})
 
const methods = ['insertDivider', 'insertImage', 'insertText', 'setContents', 'getContents', 'clear', 'removeFormat', 'undo', 'redo', 'blur', 'getSelectionText', 'scrollIntoView']
 
export class EditorContext {
  constructor (id, pageId) {
    this.id = id
    this.pageId = pageId
  }
 
  format (name, value) {
    operateEditor(this.id, this.pageId, 'format', {
      options: {
        name,
        value
      }
    })
  }
}
 
methods.forEach(function (method) {
  EditorContext.prototype[method] = callback.warp(function (options, callbackId) {
    operateEditor(this.id, this.pageId, method, {
      options,
      callbackId
    })
  })
})