提交 cb81e195 编写于 作者: D DCloud_LXH

chore: ServiceJSBridge -> UniServiceJSBridge

上级 b6b97c02
......@@ -33,7 +33,6 @@ import {
getPageIdByVm,
getCurrentPageVm,
createCallbacks,
ServiceJSBridge,
} from '@dcloudio/uni-core'
import { TEMP_PATH } from '@dcloudio/uni-platform'
......@@ -43,22 +42,26 @@ import { TEMP_PATH } from '@dcloudio/uni-platform'
//#region UniServiceJSBridge
const canvasEventCallbacks = createCallbacks('canvasEvent')
ServiceJSBridge.subscribe!(
'onCanvasMethodCallback',
({ callbackId, data }: { callbackId: number | string; data: any }) => {
const callback = canvasEventCallbacks.pop(callbackId)
if (callback) {
callback(data)
const onCanvasMethodCallback = /*#__PURE__*/ once(() => {
UniServiceJSBridge.subscribe(
'onCanvasMethodCallback',
({ callbackId, data }: { callbackId: number | string; data: any }) => {
const callback = canvasEventCallbacks.pop(callbackId)
if (callback) {
callback(data)
}
}
}
)
)
})
function operateCanvas(
canvasId: string,
pageId: number,
type: unknown,
data: any
) {
ServiceJSBridge.publishHandler!(
UniServiceJSBridge.publishHandler(
'canvas.' + canvasId,
{
canvasId,
......@@ -1043,6 +1046,7 @@ export const canvasGetImageData =
defineAsyncApi<API_TYPE_CANVAS_GET_IMAGE_DATA>(
API_CANVAS_GET_IMAGE_DATA,
({ canvasId, x, y, width, height }, { resolve, reject }) => {
onCanvasMethodCallback()
const pageId = getPageIdByVm(getCurrentPageVm()!)!
if (!pageId) {
reject()
......@@ -1078,6 +1082,7 @@ export const canvasPutImageData =
defineAsyncApi<API_TYPE_CANVAS_PUT_IMAGE_DATA>(
API_CANVAS_PUT_IMAGE_DATA,
async ({ canvasId, data, x, y, width, height }, { resolve, reject }) => {
onCanvasMethodCallback()
var pageId = getPageIdByVm(getCurrentPageVm()!)!
if (!pageId) {
reject()
......@@ -1133,6 +1138,7 @@ export const canvasToTempFilePath =
},
{ resolve, reject }
) => {
onCanvasMethodCallback()
var pageId = getPageIdByVm(getCurrentPageVm()!)!
if (!pageId) {
reject()
......
import { ServiceJSBridge } from '@dcloudio/uni-core'
import { callOptions } from '@dcloudio/uni-shared'
let eventReady = false
......@@ -19,7 +18,7 @@ function operateEditor(
data.callbackId = callbackId
optionsCache[callbackId] = options
if (!eventReady) {
ServiceJSBridge.subscribe!(
UniServiceJSBridge.subscribe(
'onEditorMethodCallback',
({ callbackId, data }: { callbackId: string; data: any }) => {
callOptions(optionsCache[callbackId], data)
......@@ -30,7 +29,7 @@ function operateEditor(
}
}
data.options = options
ServiceJSBridge.publishHandler!(
UniServiceJSBridge.publishHandler(
'editor.' + componentId,
{
componentId,
......
import {
createCallbacks,
getCurrentPageId,
ServiceJSBridge,
} from '@dcloudio/uni-core'
import { createCallbacks, getCurrentPageId } from '@dcloudio/uni-core'
import {
API_GET_SELECTED_TEXT_RANGE,
API_TYPE_GET_SELECTED_TEXT_RANGE,
} from '../../protocols/keyboard/getSelectedTextRange'
import { defineAsyncApi } from '../../helpers/api'
import { once } from '@dcloudio/uni-shared'
const getSelectedTextRangeEventCallbacks = createCallbacks(
'getSelectedTextRangeEvent'
)
ServiceJSBridge.subscribe &&
ServiceJSBridge.subscribe(
const onGetSelectedTextRange = /*#__PURE__*/ once(() => {
UniServiceJSBridge.subscribe(
'onGetSelectedTextRange',
({ callbackId, data }: { callbackId: number; data: Data }) => {
const callback = getSelectedTextRangeEventCallbacks.pop(callbackId)
......@@ -22,31 +20,32 @@ ServiceJSBridge.subscribe &&
}
}
)
})
export const getSelectedTextRange =
defineAsyncApi<API_TYPE_GET_SELECTED_TEXT_RANGE>(
API_GET_SELECTED_TEXT_RANGE,
(_, { resolve, reject }) => {
onGetSelectedTextRange()
const pageId = getCurrentPageId()
ServiceJSBridge.publishHandler &&
ServiceJSBridge.publishHandler(
'getSelectedTextRange',
{
pageId,
callbackId: getSelectedTextRangeEventCallbacks.push(function (
res: UniApp.GetSelectedTextRangeSuccessCallbackResult
UniServiceJSBridge.publishHandler(
'getSelectedTextRange',
{
pageId,
callbackId: getSelectedTextRangeEventCallbacks.push(function (
res: UniApp.GetSelectedTextRangeSuccessCallbackResult
) {
if (
typeof res.end === 'undefined' &&
typeof res.start === 'undefined'
) {
if (
typeof res.end === 'undefined' &&
typeof res.start === 'undefined'
) {
reject('no focused')
} else {
resolve(res)
}
}),
},
pageId
)
reject('no focused')
} else {
resolve(res)
}
}),
},
pageId
)
}
)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册