提交 dfed3806 编写于 作者: fxy060608's avatar fxy060608

wip(app): wxs

上级 ade726d1
......@@ -10,79 +10,79 @@ const __uniRoutes = instanceContext.__uniRoutes;
var serviceContext = (function (vue) {
'use strict';
/*
* base64-arraybuffer
* https://github.com/niklasvh/base64-arraybuffer
*
* Copyright (c) 2012 Niklas von Hertzen
* Licensed under the MIT license.
*/
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
// Use a lookup table to find the index.
var lookup = /*#__PURE__*/ (function () {
const lookup = new Uint8Array(256);
for (var i = 0; i < chars.length; i++) {
lookup[chars.charCodeAt(i)] = i;
}
return lookup
})();
function encode$3(arraybuffer) {
var bytes = new Uint8Array(arraybuffer),
i,
len = bytes.length,
base64 = '';
for (i = 0; i < len; i += 3) {
base64 += chars[bytes[i] >> 2];
base64 += chars[((bytes[i] & 3) << 4) | (bytes[i + 1] >> 4)];
base64 += chars[((bytes[i + 1] & 15) << 2) | (bytes[i + 2] >> 6)];
base64 += chars[bytes[i + 2] & 63];
}
if (len % 3 === 2) {
base64 = base64.substring(0, base64.length - 1) + '=';
} else if (len % 3 === 1) {
base64 = base64.substring(0, base64.length - 2) + '==';
}
return base64
}
function decode$1(base64) {
var bufferLength = base64.length * 0.75,
len = base64.length,
i,
p = 0,
encoded1,
encoded2,
encoded3,
encoded4;
if (base64[base64.length - 1] === '=') {
bufferLength--;
if (base64[base64.length - 2] === '=') {
bufferLength--;
}
}
var arraybuffer = new ArrayBuffer(bufferLength),
bytes = new Uint8Array(arraybuffer);
for (i = 0; i < len; i += 4) {
encoded1 = lookup[base64.charCodeAt(i)];
encoded2 = lookup[base64.charCodeAt(i + 1)];
encoded3 = lookup[base64.charCodeAt(i + 2)];
encoded4 = lookup[base64.charCodeAt(i + 3)];
bytes[p++] = (encoded1 << 2) | (encoded2 >> 4);
bytes[p++] = ((encoded2 & 15) << 4) | (encoded3 >> 2);
bytes[p++] = ((encoded3 & 3) << 6) | (encoded4 & 63);
}
return arraybuffer
/*
* base64-arraybuffer
* https://github.com/niklasvh/base64-arraybuffer
*
* Copyright (c) 2012 Niklas von Hertzen
* Licensed under the MIT license.
*/
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
// Use a lookup table to find the index.
var lookup = /*#__PURE__*/ (function () {
const lookup = new Uint8Array(256);
for (var i = 0; i < chars.length; i++) {
lookup[chars.charCodeAt(i)] = i;
}
return lookup
})();
function encode$3(arraybuffer) {
var bytes = new Uint8Array(arraybuffer),
i,
len = bytes.length,
base64 = '';
for (i = 0; i < len; i += 3) {
base64 += chars[bytes[i] >> 2];
base64 += chars[((bytes[i] & 3) << 4) | (bytes[i + 1] >> 4)];
base64 += chars[((bytes[i + 1] & 15) << 2) | (bytes[i + 2] >> 6)];
base64 += chars[bytes[i + 2] & 63];
}
if (len % 3 === 2) {
base64 = base64.substring(0, base64.length - 1) + '=';
} else if (len % 3 === 1) {
base64 = base64.substring(0, base64.length - 2) + '==';
}
return base64
}
function decode$1(base64) {
var bufferLength = base64.length * 0.75,
len = base64.length,
i,
p = 0,
encoded1,
encoded2,
encoded3,
encoded4;
if (base64[base64.length - 1] === '=') {
bufferLength--;
if (base64[base64.length - 2] === '=') {
bufferLength--;
}
}
var arraybuffer = new ArrayBuffer(bufferLength),
bytes = new Uint8Array(arraybuffer);
for (i = 0; i < len; i += 4) {
encoded1 = lookup[base64.charCodeAt(i)];
encoded2 = lookup[base64.charCodeAt(i + 1)];
encoded3 = lookup[base64.charCodeAt(i + 2)];
encoded4 = lookup[base64.charCodeAt(i + 3)];
bytes[p++] = (encoded1 << 2) | (encoded2 >> 4);
bytes[p++] = ((encoded2 & 15) << 4) | (encoded3 >> 2);
bytes[p++] = ((encoded3 & 3) << 6) | (encoded4 & 63);
}
return arraybuffer
}
/**
......@@ -1112,7 +1112,7 @@ var serviceContext = (function (vue) {
if (typeof options.complete === 'function') {
options.complete(data);
}
}
}
function debounce(fn, delay) {
let timeout;
......@@ -3503,7 +3503,6 @@ var serviceContext = (function (vue) {
}
}, CreateCanvasContextProtocol);
const canvasGetImageData = defineAsyncApi(API_CANVAS_GET_IMAGE_DATA, ({ canvasId, x, y, width, height }, { resolve, reject }) => {
// onCanvasMethodCallback()
const pageId = getPageIdByVm(getCurrentPageVm());
if (!pageId) {
reject();
......@@ -3536,7 +3535,6 @@ var serviceContext = (function (vue) {
}, callback);
}, CanvasGetImageDataProtocol, CanvasGetImageDataOptions);
const canvasPutImageData = defineAsyncApi(API_CANVAS_PUT_IMAGE_DATA, ({ canvasId, data, x, y, width, height }, { resolve, reject }) => {
// onCanvasMethodCallback()
var pageId = getPageIdByVm(getCurrentPageVm());
if (!pageId) {
reject();
......@@ -3552,7 +3550,7 @@ var serviceContext = (function (vue) {
height,
compressed,
}, (data) => {
if (data.errMsg && data.errMsg.indexOf('fail')) {
if (data.errMsg && data.errMsg.indexOf('fail') !== -1) {
reject();
return;
}
......@@ -3567,12 +3565,11 @@ var serviceContext = (function (vue) {
operate();
});
}
// fix ...
// fix ... fix what?
data = Array.prototype.slice.call(data);
operate();
}, CanvasPutImageDataProtocol, CanvasPutImageDataOptions);
const canvasToTempFilePath = defineAsyncApi(API_CANVAS_TO_TEMP_FILE_PATH, ({ x = 0, y = 0, width, height, destWidth, destHeight, canvasId, fileType, quality, }, { resolve, reject }) => {
// onCanvasMethodCallback()
var pageId = getPageIdByVm(getCurrentPageVm());
if (!pageId) {
reject();
......@@ -3590,7 +3587,7 @@ var serviceContext = (function (vue) {
quality,
dirname,
}, (res) => {
if (res.errMsg && res.errMsg.indexOf('fail')) {
if (res.errMsg && res.errMsg.indexOf('fail') !== -1) {
reject('', res);
return;
}
......@@ -9363,34 +9360,37 @@ var serviceContext = (function (vue) {
if (!isArray(modules)) {
return;
}
// 使用了内部属性__scopeId
const component = instance.type.__scopeId || instance.proxy.route;
const ctx = instance.ctx;
const $wxsModules = (instance.$wxsModules ||
(instance.$wxsModules = []));
modules.forEach((module) => {
ctx[module] = proxyModule(module);
ctx[module] = proxyModule(component, module);
$wxsModules.push(module);
});
}
const renderjsModule = {};
function proxyModule(module) {
function proxyModule(component, module) {
return new Proxy(renderjsModule, {
get(_, p) {
return createModuleFunction(module, p);
return createModuleFunction(component, module, p);
},
});
}
function renderjsFn() { }
function createModuleFunction(module, name) {
const toJSON = () => WXS_PROTOCOL + JSON.stringify([module + '.' + name]);
function createModuleFunction(component, module, name) {
const toJSON = () => WXS_PROTOCOL + JSON.stringify([component, module + '.' + name]);
return new Proxy(renderjsFn, {
get(_, p) {
if (p === 'toJSON') {
return toJSON;
}
return createModuleFunction(module + '.' + name, p);
return createModuleFunction(component, module + '.' + name, p);
},
apply(_target, _thisArg, args) {
return WXS_PROTOCOL + JSON.stringify([module + '.' + name, ...args]);
return (WXS_PROTOCOL +
JSON.stringify([component, module + '.' + name, [...args]]));
},
});
}
......
......@@ -9,36 +9,49 @@ import {
} from '@dcloudio/uni-shared'
import { VD_SYNC } from '../../../../constants'
import { UniCustomElement } from '../components'
import { invokeWxs } from '../wxs'
function removeEventListener(el: UniCustomElement, type: string) {
const listener = el.__listeners[type]
if (listener) {
el.removeEventListener(type, listener)
} else if (__DEV__) {
console.error(
formatLog(`tag`, el.tagName, el.__id, 'event[' + type + '] not found')
)
}
}
function isEventListenerExists(el: UniCustomElement, type: string) {
if (el.__listeners[type]) {
if (__DEV__) {
console.error(
formatLog(
`tag`,
el.tagName,
el.__id,
'event[' + type + '] already registered'
)
)
}
return true
}
}
export function patchEvent(el: UniCustomElement, name: string, flag: number) {
const [type, options] = parseEventName(name)
if (flag === -1) {
// remove
const listener = el.__listeners[type]
if (listener) {
el.removeEventListener(type, listener)
} else if (__DEV__) {
console.error(
formatLog(`tag`, el.tagName, el.__id, 'event[' + type + '] not found')
)
}
removeEventListener(el, type)
} else {
// add
if (el.__listeners[type]) {
if (__DEV__) {
console.error(
formatLog(
`tag`,
el.tagName,
el.__id,
'event[' + type + '] already registered'
)
)
}
return
if (!isEventListenerExists(el, type)) {
el.addEventListener(
type,
(el.__listeners[type] = createInvoker(el.__id, flag, options)),
options
)
}
el.__listeners[type] = createInvoker(el.__id, flag, options)
el.addEventListener(type, el.__listeners[type], options)
}
}
......@@ -81,36 +94,21 @@ export function patchWxsEvent(
const [type, options] = parseEventName(name)
if (flag === -1) {
// remove
const listener = el.__listeners[type]
if (listener) {
el.removeEventListener(type, listener)
} else if (__DEV__) {
console.error(
formatLog(`tag`, el.tagName, el.__id, 'event[' + type + '] not found')
)
}
removeEventListener(el, type)
} else {
// add
if (el.__listeners[type]) {
if (__DEV__) {
console.error(
formatLog(
`tag`,
el.tagName,
el.__id,
'event[' + type + '] already registered'
)
)
}
return
if (!isEventListenerExists(el, type)) {
el.addEventListener(
type,
(el.__listeners[type] = createWxsEventInvoker(
el.__id,
wxsEvent,
flag,
options
)),
options
)
}
el.__listeners[type] = createWxsEventInvoker(
el.__id,
wxsEvent,
flag,
options
)
el.addEventListener(type, el.__listeners[type], options)
}
}
......@@ -122,7 +120,8 @@ function createWxsEventInvoker(
) {
const invoker = (evt: Event) => {
console.log('call wxsEvent', id, wxsEvent, flag, options)
// const event = normalizeNativeEvent(evt)
invokeWxs(wxsEvent, [normalizeNativeEvent(evt)])
// ;(event as any).type = normalizeEventType(evt.type, options)
// UniViewJSBridge.publishHandler(VD_SYNC, [[ACTION_TYPE_EVENT, id, event]])
}
......
import { JSON_PROTOCOL } from '@dcloudio/uni-shared'
import { JSON_PROTOCOL, WXS_PROTOCOL } from '@dcloudio/uni-shared'
import { isString } from '@vue/shared'
import { invokeWxs } from './wxs'
const JSON_PROTOCOL_LEN = JSON_PROTOCOL.length
export function decodeAttr(value: unknown) {
if (isString(value) && value.indexOf(JSON_PROTOCOL) === 0) {
if (!isString(value)) {
return value
}
if (value.indexOf(JSON_PROTOCOL) === 0) {
value = JSON.parse(value.substr(JSON_PROTOCOL_LEN))
} else if (value.indexOf(WXS_PROTOCOL) === 0) {
value = invokeWxs(value)
}
return value
}
import { isArray } from '@vue/shared'
import {
formatLog,
getValueByDataPath,
WXS_PROTOCOL,
} from '@dcloudio/uni-shared'
declare global {
interface Window {
WxsModules: {
[name: string]: Record<string, any>
}
RenderjsModules: {
[name: string]: Record<string, any>
}
}
}
function getWxsModule(component: string) {
const { WxsModules, RenderjsModules } = window
let module = WxsModules && WxsModules[component]
if (!module) {
module = RenderjsModules && RenderjsModules[component]
}
if (!module) {
return console.error(formatLog('wxs or renderjs', component + ' not found'))
}
return module
}
const WXS_PROTOCOL_LEN = WXS_PROTOCOL.length
export function invokeWxs(value: string, invokerArgs?: unknown[]) {
const [component, invoker, args] = JSON.parse(value.substr(WXS_PROTOCOL_LEN))
if (isArray(args)) {
// methods
const [moduleName, mehtodName] = invoker.split('.')
if (invokerArgs) {
args.push(...invokerArgs)
}
return invokeWxsMethod(component, moduleName, mehtodName, args)
}
return getWxsProp(component, invoker)
}
function invokeWxsMethod(
component: string,
moduleName: string,
methodName: string,
args: unknown[]
) {
const modules = getWxsModule(component)
if (!modules) {
return
}
const module = modules[moduleName]
if (!module) {
return console.error(
formatLog('wxs', 'module ' + moduleName + ' not found')
)
}
return module[methodName].apply(module, args)
}
function getWxsProp(component: string, dataPath: string) {
const modules = getWxsModule(component)
if (!modules) {
return
}
return getValueByDataPath(modules, dataPath)
}
......@@ -11835,11 +11835,13 @@ export default function vueFactory(exports) {
var vModelText = {
created(el, {
value,
modifiers: {
trim,
number
}
}, vnode) {
el.value = value == null ? '' : value;
el._assign = getModelAssigner(vnode);
addEventListener(el, 'input', e => {
var domValue = e.detail.value; // 从 view 层接收到新值后,赋值给 service 层元素,注意,需要临时解除 pageNode,否则赋值 value 会触发向 view 层的再次同步数据
......
......@@ -564,7 +564,7 @@ var safeAreaInsets = {
onChange,
offChange
};
var D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out = safeAreaInsets;
var out = safeAreaInsets;
const onEventPrevent = /* @__PURE__ */ withModifiers(() => {
}, ["prevent"]);
const onEventStop = /* @__PURE__ */ withModifiers(() => {
......@@ -576,10 +576,10 @@ function getWindowOffset() {
const left = parseInt(style.getPropertyValue("--window-left"));
const right = parseInt(style.getPropertyValue("--window-right"));
return {
top: top ? top + D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.top : 0,
bottom: bottom ? bottom + D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.bottom : 0,
left: left ? left + D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.left : 0,
right: right ? right + D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.right : 0
top: top ? top + out.top : 0,
bottom: bottom ? bottom + out.bottom : 0,
left: left ? left + out.left : 0,
right: right ? right + out.right : 0
};
}
function updateCssVar(cssVars) {
......@@ -3725,7 +3725,7 @@ const canvasPutImageData = /* @__PURE__ */ defineAsyncApi(API_CANVAS_PUT_IMAGE_D
height,
compressed
}, (data2) => {
if (data2.errMsg && data2.errMsg.indexOf("fail")) {
if (data2.errMsg && data2.errMsg.indexOf("fail") !== -1) {
reject();
return;
}
......@@ -3763,7 +3763,7 @@ const canvasToTempFilePath = /* @__PURE__ */ defineAsyncApi(API_CANVAS_TO_TEMP_F
quality,
dirname
}, (res) => {
if (res.errMsg && res.errMsg.indexOf("fail")) {
if (res.errMsg && res.errMsg.indexOf("fail") !== -1) {
reject("", res);
return;
}
......@@ -13156,7 +13156,7 @@ function normalizePageMeta(pageMeta) {
}, pageMeta.pullToRefresh));
const { type, style } = navigationBar;
if (style !== "custom" && type !== "transparent") {
pullToRefresh.offset += NAVBAR_HEIGHT + D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.top;
pullToRefresh.offset += NAVBAR_HEIGHT + out.top;
}
pageMeta.pullToRefresh = pullToRefresh;
}
......@@ -15354,7 +15354,7 @@ const getSystemInfoSync = /* @__PURE__ */ defineSyncApi("getSystemInfoSync", ()
const windowWidth = getWindowWidth(screenWidth);
let windowHeight = window.innerHeight;
const language = navigator.language;
const statusBarHeight = D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.top;
const statusBarHeight = out.top;
let osname;
let osversion;
let model;
......@@ -15467,12 +15467,12 @@ const getSystemInfoSync = /* @__PURE__ */ defineSyncApi("getSystemInfoSync", ()
const system = `${osname} ${osversion}`;
const platform = osname.toLocaleLowerCase();
const safeArea = {
left: D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.left,
right: windowWidth - D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.right,
top: D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.top,
bottom: windowHeight - D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.bottom,
width: windowWidth - D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.left - D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.right,
height: windowHeight - D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.top - D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.bottom
left: out.left,
right: windowWidth - out.right,
top: out.top,
bottom: windowHeight - out.bottom,
width: windowWidth - out.left - out.right,
height: windowHeight - out.top - out.bottom
};
const { top: windowTop, bottom: windowBottom } = getWindowOffset();
windowHeight -= windowTop;
......@@ -15492,10 +15492,10 @@ const getSystemInfoSync = /* @__PURE__ */ defineSyncApi("getSystemInfoSync", ()
model,
safeArea,
safeAreaInsets: {
top: D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.top,
right: D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.right,
bottom: D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.bottom,
left: D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.left
top: out.top,
right: out.right,
bottom: out.bottom,
left: out.left
}
};
});
......
......@@ -826,6 +826,17 @@ function callOptions(options, data) {
if (typeof options.complete === 'function') {
options.complete(data);
}
}
function getValueByDataPath(obj, path) {
const parts = path.split('.');
let key = parts[0];
if (!obj) {
obj = {};
}
if (parts.length === 1) {
return obj[key];
}
return getValueByDataPath(obj[key], parts.slice(1).join('.'));
}
function debounce(fn, delay) {
......@@ -859,7 +870,6 @@ const DATA_RE = /^data:.*,.*/;
const WEB_INVOKE_APPSERVICE = 'WEB_INVOKE_APPSERVICE';
const WXS_PROTOCOL = 'wxs://';
const JSON_PROTOCOL = 'json://';
const WXS_METHOD_SYMBOL = Symbol('wxs.method');
// lifecycle
// App and Page
const ON_SHOW = 'onShow';
......@@ -1057,7 +1067,6 @@ exports.UniNode = UniNode;
exports.UniTextAreaElement = UniTextAreaElement;
exports.UniTextNode = UniTextNode;
exports.WEB_INVOKE_APPSERVICE = WEB_INVOKE_APPSERVICE;
exports.WXS_METHOD_SYMBOL = WXS_METHOD_SYMBOL;
exports.WXS_PROTOCOL = WXS_PROTOCOL;
exports.addFont = addFont;
exports.cache = cache;
......@@ -1074,6 +1083,7 @@ exports.formatLog = formatLog;
exports.getCustomDataset = getCustomDataset;
exports.getEnvLocale = getEnvLocale;
exports.getLen = getLen;
exports.getValueByDataPath = getValueByDataPath;
exports.initCustomDataset = initCustomDataset;
exports.invokeArrayFns = invokeArrayFns;
exports.isBuiltInComponent = isBuiltInComponent;
......
......@@ -168,6 +168,8 @@ export declare function getEnvLocale(): string;
export declare function getLen(str?: string): number;
export declare function getValueByDataPath(obj: any, path: string): unknown;
declare interface HTMLElementWithDataset extends HTMLElement {
__uniDataset?: Record<string, any>;
}
......@@ -620,8 +622,6 @@ export declare function updateElementStyle(element: HTMLElement, styles: Partial
export declare const WEB_INVOKE_APPSERVICE = "WEB_INVOKE_APPSERVICE";
export declare const WXS_METHOD_SYMBOL: unique symbol;
export declare const WXS_PROTOCOL = "wxs://";
export { }
......@@ -822,6 +822,17 @@ function callOptions(options, data) {
if (typeof options.complete === 'function') {
options.complete(data);
}
}
function getValueByDataPath(obj, path) {
const parts = path.split('.');
let key = parts[0];
if (!obj) {
obj = {};
}
if (parts.length === 1) {
return obj[key];
}
return getValueByDataPath(obj[key], parts.slice(1).join('.'));
}
function debounce(fn, delay) {
......@@ -855,7 +866,6 @@ const DATA_RE = /^data:.*,.*/;
const WEB_INVOKE_APPSERVICE = 'WEB_INVOKE_APPSERVICE';
const WXS_PROTOCOL = 'wxs://';
const JSON_PROTOCOL = 'json://';
const WXS_METHOD_SYMBOL = Symbol('wxs.method');
// lifecycle
// App and Page
const ON_SHOW = 'onShow';
......@@ -971,4 +981,4 @@ function getEnvLocale() {
return (lang && lang.replace(/[.:].*/, '')) || 'en';
}
export { ACTION_TYPE_ADD_EVENT, ACTION_TYPE_ADD_WXS_EVENT, ACTION_TYPE_CREATE, ACTION_TYPE_EVENT, ACTION_TYPE_INSERT, ACTION_TYPE_PAGE_CREATE, ACTION_TYPE_PAGE_CREATED, ACTION_TYPE_PAGE_SCROLL, ACTION_TYPE_REMOVE, ACTION_TYPE_REMOVE_ATTRIBUTE, ACTION_TYPE_REMOVE_EVENT, ACTION_TYPE_SET_ATTRIBUTE, ACTION_TYPE_SET_TEXT, ATTR_CLASS, ATTR_INNER_HTML, ATTR_STYLE, ATTR_TEXT_CONTENT, ATTR_V_SHOW, BACKGROUND_COLOR, BUILT_IN_TAGS, COMPONENT_NAME_PREFIX, COMPONENT_PREFIX, COMPONENT_SELECTOR_PREFIX, DATA_RE, EventChannel, EventModifierFlags, JSON_PROTOCOL, NAVBAR_HEIGHT, NODE_TYPE_COMMENT, NODE_TYPE_ELEMENT, NODE_TYPE_PAGE, NODE_TYPE_TEXT, ON_ADD_TO_FAVORITES, ON_APP_ENTER_BACKGROUND, ON_APP_ENTER_FOREGROUND, ON_BACK_PRESS, ON_ERROR, ON_HIDE, ON_KEYBOARD_HEIGHT_CHANGE, ON_LAUNCH, ON_LOAD, ON_NAVIGATION_BAR_BUTTON_TAP, ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED, ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED, ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED, ON_PAGE_NOT_FOUND, ON_PAGE_SCROLL, ON_PULL_DOWN_REFRESH, ON_REACH_BOTTOM, ON_REACH_BOTTOM_DISTANCE, ON_READY, ON_RESIZE, ON_SHARE_APP_MESSAGE, ON_SHARE_TIMELINE, ON_SHOW, ON_TAB_ITEM_TAP, ON_THEME_CHANGE, ON_UNHANDLE_REJECTION, ON_UNLOAD, ON_WEB_INVOKE_APP_SERVICE, PLUS_RE, PRIMARY_COLOR, RESPONSIVE_MIN_WIDTH, SCHEME_RE, SELECTED_COLOR, TABBAR_HEIGHT, TAGS, UNI_SSR, UNI_SSR_DATA, UNI_SSR_GLOBAL_DATA, UNI_SSR_STORE, UNI_SSR_TITLE, UniBaseNode, UniCommentNode, UniElement, UniEvent, UniInputElement, UniNode, UniTextAreaElement, UniTextNode, WEB_INVOKE_APPSERVICE, WXS_METHOD_SYMBOL, WXS_PROTOCOL, addFont, cache, cacheStringFunction, callOptions, createRpx2Unit, createUniEvent, debounce, decode, decodedQuery, defaultRpx2Unit, formatDateTime, formatLog, getCustomDataset, getEnvLocale, getLen, initCustomDataset, invokeArrayFns, isBuiltInComponent, isCustomElement, isNativeTag, isRootHook, isServiceCustomElement, isServiceNativeTag, normalizeDataset, normalizeEventType, normalizeTarget, once, parseEventName, parseQuery, parseUrl, passive, plusReady, removeLeadingSlash, sanitise, scrollTo, stringifyQuery, updateElementStyle };
export { ACTION_TYPE_ADD_EVENT, ACTION_TYPE_ADD_WXS_EVENT, ACTION_TYPE_CREATE, ACTION_TYPE_EVENT, ACTION_TYPE_INSERT, ACTION_TYPE_PAGE_CREATE, ACTION_TYPE_PAGE_CREATED, ACTION_TYPE_PAGE_SCROLL, ACTION_TYPE_REMOVE, ACTION_TYPE_REMOVE_ATTRIBUTE, ACTION_TYPE_REMOVE_EVENT, ACTION_TYPE_SET_ATTRIBUTE, ACTION_TYPE_SET_TEXT, ATTR_CLASS, ATTR_INNER_HTML, ATTR_STYLE, ATTR_TEXT_CONTENT, ATTR_V_SHOW, BACKGROUND_COLOR, BUILT_IN_TAGS, COMPONENT_NAME_PREFIX, COMPONENT_PREFIX, COMPONENT_SELECTOR_PREFIX, DATA_RE, EventChannel, EventModifierFlags, JSON_PROTOCOL, NAVBAR_HEIGHT, NODE_TYPE_COMMENT, NODE_TYPE_ELEMENT, NODE_TYPE_PAGE, NODE_TYPE_TEXT, ON_ADD_TO_FAVORITES, ON_APP_ENTER_BACKGROUND, ON_APP_ENTER_FOREGROUND, ON_BACK_PRESS, ON_ERROR, ON_HIDE, ON_KEYBOARD_HEIGHT_CHANGE, ON_LAUNCH, ON_LOAD, ON_NAVIGATION_BAR_BUTTON_TAP, ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED, ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED, ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED, ON_PAGE_NOT_FOUND, ON_PAGE_SCROLL, ON_PULL_DOWN_REFRESH, ON_REACH_BOTTOM, ON_REACH_BOTTOM_DISTANCE, ON_READY, ON_RESIZE, ON_SHARE_APP_MESSAGE, ON_SHARE_TIMELINE, ON_SHOW, ON_TAB_ITEM_TAP, ON_THEME_CHANGE, ON_UNHANDLE_REJECTION, ON_UNLOAD, ON_WEB_INVOKE_APP_SERVICE, PLUS_RE, PRIMARY_COLOR, RESPONSIVE_MIN_WIDTH, SCHEME_RE, SELECTED_COLOR, TABBAR_HEIGHT, TAGS, UNI_SSR, UNI_SSR_DATA, UNI_SSR_GLOBAL_DATA, UNI_SSR_STORE, UNI_SSR_TITLE, UniBaseNode, UniCommentNode, UniElement, UniEvent, UniInputElement, UniNode, UniTextAreaElement, UniTextNode, WEB_INVOKE_APPSERVICE, WXS_PROTOCOL, addFont, cache, cacheStringFunction, callOptions, createRpx2Unit, createUniEvent, debounce, decode, decodedQuery, defaultRpx2Unit, formatDateTime, formatLog, getCustomDataset, getEnvLocale, getLen, getValueByDataPath, initCustomDataset, invokeArrayFns, isBuiltInComponent, isCustomElement, isNativeTag, isRootHook, isServiceCustomElement, isServiceNativeTag, normalizeDataset, normalizeEventType, normalizeTarget, once, parseEventName, parseQuery, parseUrl, passive, plusReady, removeLeadingSlash, sanitise, scrollTo, stringifyQuery, updateElementStyle };
......@@ -23,8 +23,6 @@ export const WEB_INVOKE_APPSERVICE = 'WEB_INVOKE_APPSERVICE'
export const WXS_PROTOCOL = 'wxs://'
export const JSON_PROTOCOL = 'json://'
export const WXS_METHOD_SYMBOL = Symbol('wxs.method')
// lifecycle
// App and Page
......
......@@ -103,3 +103,15 @@ export function callOptions(
options.complete(data)
}
}
export function getValueByDataPath(obj: any, path: string): unknown {
const parts = path.split('.')
let key: number | string = parts[0]
if (!obj) {
obj = {}
}
if (parts.length === 1) {
return obj[key]
}
return getValueByDataPath(obj[key], parts.slice(1).join('.'))
}
......@@ -17,39 +17,48 @@ export function initModules(
if (!isArray(modules)) {
return
}
// 使用了内部属性__scopeId
const component = (instance.type as any).__scopeId || instance.proxy!.route
const ctx = (instance as any).ctx
const $wxsModules = (instance.$wxsModules ||
(instance.$wxsModules = [])) as unknown as string[]
modules.forEach((module) => {
ctx[module] = proxyModule(module)
ctx[module] = proxyModule(component, module)
$wxsModules.push(module)
})
}
const renderjsModule = {}
function proxyModule(module: string) {
function proxyModule(component: string, module: string) {
return new Proxy(renderjsModule, {
get(_, p) {
return createModuleFunction(module, p as string)
return createModuleFunction(component, module, p as string)
},
})
}
function renderjsFn() {}
function createModuleFunction(module: string, name: string): Function {
const toJSON = () => WXS_PROTOCOL + JSON.stringify([module + '.' + name])
function createModuleFunction(
component: string,
module: string,
name: string
): Function {
const toJSON = () =>
WXS_PROTOCOL + JSON.stringify([component, module + '.' + name])
return new Proxy(renderjsFn, {
get(_, p) {
if (p === 'toJSON') {
return toJSON
}
return createModuleFunction(module + '.' + name, p as string)
return createModuleFunction(component, module + '.' + name, p as string)
},
apply(_target, _thisArg, args) {
return WXS_PROTOCOL + JSON.stringify([module + '.' + name, ...args])
return (
WXS_PROTOCOL +
JSON.stringify([component, module + '.' + name, [...args]])
)
},
})
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册