提交 f737694f 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

wip(uts): automator element.attribute

上级 8e0c1c35
......@@ -265,3 +265,26 @@ function getTouches(touches: any[]): Touch[] {
return result
})
}
export type GetAttributesParams = {
pageId: number
elementId?: string | null
nodeId?: number | null
names: string[]
callback: (res?: any | null) => void
}
export const getAttributes = (params: GetAttributesParams): void => {
let dom: INode | null = null
if (params.elementId !== null) {
dom = getElementById(params.pageId, params.elementId!, params.callback)
} else if (params.nodeId !== null) {
dom = getComponentDomByNodeId(params.pageId, params.nodeId!, params.callback)
}
if (dom !== null) {
const attributes = params.names.map((name: string): any | null => {
return dom.getAttribute(name)
})
params.callback({ attributes })
}
}
......@@ -46,6 +46,8 @@ import {
longpress,
HandleTouchEventParams,
handleTouchEvent,
GetAttributesParams,
getAttributes,
} from './apis/Element.uts'
let socketTask: SocketTask | null = null
......@@ -200,6 +202,11 @@ export function onMessage(msg: string) {
const touchstartChangedTouches = ((params['changedTouches'] as UTSJSONObject).toJSONObject() as JSONArray).toUTSArray()
handleTouchEvent({ pageId, elementId: touchstartElementId, nodeId: touchstartNodeId, eventName, touches: touchstartTouches, changedTouches: touchstartChangedTouches, callback } as HandleTouchEventParams)
break
case 'Element.getAttributes':
const getAttributesElementId = params['elementId'] !== null ? params['elementId'] as string : null
const getAttributesNodeId = params['nodeId'] !== null ? params['nodeId'] as number : null
const getAttributesNames = ((params['names'] as UTSJSONObject).toJSONObject() as JSONArray).toUTSArray() as string[]
getAttributes({ pageId, elementId: getAttributesElementId, nodeId: getAttributesNodeId, names: getAttributesNames, callback } as GetAttributesParams)
}
}
} catch (error) {
......
process.env.DEBUG = "automator:*"
"use strict"; Object.defineProperty(exports, "__esModule", { value: !0 }); var t = require("fs"), e = require("path"), n = require("debug"), s = require("merge"), o = require("jsonc-parser"), i = require("licia/isRelative"), r = require("ws"), a = require("events"), c = require("licia/uuid"), l = require("licia/stringify"), p = require("licia/dateFormat"), u = require("licia/waitUntil"), h = require("licia/fs"), d = require("licia/isFn"), m = require("licia/trim"), g = require("licia/isStr"), y = require("licia/startWith"), v = require("licia/isNum"), f = require("licia/sleep"), w = require("licia/isUndef"), P = require("address"), M = require("default-gateway"), k = require("licia/getPort"), E = require("qrcode-terminal"), I = require("child_process"), b = require("licia/toStr"); function C(t) { return t && "object" == typeof t && "default" in t ? t : { default: t } } var T = C(t), A = C(e), N = C(n), S = C(i), U = C(r), D = C(c), j = C(l), R = C(p), _ = C(u), x = C(h), O = C(d), q = C(m), $ = C(g), F = C(y), L = C(v), H = C(f), W = C(w), B = C(P), J = C(M), X = C(k), V = C(E), G = C(b); class z extends a.EventEmitter{ constructor(t) { super(), this.ws = t, this.ws.addEventListener("message", (t => { this.emit("message", t.data) })), this.ws.addEventListener("close", (() => { this.emit("close") })) } send(t) { this.ws.send(t) } close() { this.ws.close() } } const K = new Map, Y = ["onCompassChange", "onThemeChange", "onUserCaptureScreen", "onWindowResize", "onMemoryWarning", "onAccelerometerChange", "onKeyboardHeightChange", "onNetworkStatusChange", "onPushMessage", "onLocationChange", "onGetWifiList", "onWifiConnected", "onWifiConnectedWithPartialInfo"]; const Q = new Map; function Z(t, e) { (null == t ? void 0 : t.success) && "function" == typeof (null == t ? void 0 : t.success) && (e ? t.success(e) : t.success()), (null == t ? void 0 : t.complete) && "function" == typeof (null == t ? void 0 : t.complete) && (e ? t.complete(e) : t.complete()) } function tt(t, e) { (null == t ? void 0 : t.fail) && "function" == typeof (null == t ? void 0 : t.fail) && (e ? t.fail(e) : t.fail()), (null == t ? void 0 : t.complete) && "function" == typeof (null == t ? void 0 : t.complete) && (e ? t.complete(e) : t.complete()) } const et = "Connection closed"; class nt extends a.EventEmitter{ constructor(t, e, n) { super(), this.puppet = e, this.namespace = n, this.callbacks = new Map, this.transport = t, this.debug = N.default("automator:protocol:" + this.namespace), this.onMessage = t => { var e, n; this.debug(`${R.default("yyyy-mm-dd HH:MM:ss:l")} ◀ RECV ${t}`); const { id: s, method: o, error: i, result: r, params: a } = JSON.parse(t); if (null === (e = null == r ? void 0 : r.method) || void 0 === e ? void 0 : e.startsWith("on")) return void ((t, e, n) => { const s = K.get(t); (null == s ? void 0 : s.has(e)) && s.get(e)(n) })(r.method, s, r); if (null === (n = null == r ? void 0 : r.method) || void 0 === n ? void 0 : n.startsWith("Socket.")) { return void ((t, e, n) => { const s = Q.get(e); (null == s ? void 0 : s.has(t)) && s.get(t)(n) })(r.method.replace("Socket.", ""), r.id, r.data) } if (!s) return this.puppet.emit(o, a); const { callbacks: c } = this; if (s && c.has(s)) { const t = c.get(s); c.delete(s), i ? t.reject(Error(i.message || i.detailMessage)) : t.resolve(r) } }, this.onClose = () => { this.callbacks.forEach((t => { t.reject(Error(et)) })) }, this.transport.on("message", this.onMessage), this.transport.on("close", this.onClose) } send(t, e = {}, n = !0) { if (n && this.puppet.adapter.has(t)) return this.puppet.adapter.send(this, t, e); const s = D.default(), o = j.default({ id: s, method: t, params: e }); return this.debug(`${R.default("yyyy-mm-dd HH:MM:ss:l")} SEND ► ${o}`), new Promise(((t, e) => { try { this.transport.send(o) } catch (t) { e(Error(et)) } this.callbacks.set(s, { resolve: t, reject: e }) })) } dispose() { this.transport.close() } static createDevtoolConnection(t, e) { return new Promise(((n, s) => { const o = new U.default(t); o.addEventListener("open", (() => { n(new nt(new z(o), e, "devtool")) })), o.addEventListener("error", s) })) } static createRuntimeConnection(t, e, n) { return new Promise(((s, o) => { N.default("automator:runtime")(`${R.default("yyyy-mm-dd HH:MM:ss:l")} port=${t}`); const i = new U.default.Server({ port: t }); _.default((async () => { if (e.runtimeConnection) return !0 }), n, 1e3).catch((() => { i.close(), o("Failed to connect to runtime, please make sure the project is running") })), i.on("connection", (function (t) { N.default("automator:runtime")(`${R.default("yyyy-mm-dd HH:MM:ss:l")} connected`); const n = new nt(new z(t), e, "runtime"); e.setRuntimeConnection(n), s(n) })), e.setRuntimeServer(i) })) } } async function st(t, e) { const [n, s] = function (t) { return $.default(t) ? [!0, [t]] : [!1, t] }(e), o = await t(s); return n ? o[0] : o } function ot(t) { try { return require(t) } catch (e) { return require(require.resolve(t, { paths: [process.cwd()] })) } }
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册