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

wip(app): wxs

上级 16da9f60
......@@ -13,7 +13,8 @@
const ACTION_TYPE_REMOVE_ATTRIBUTE = 7;
const ACTION_TYPE_ADD_EVENT = 8;
const ACTION_TYPE_REMOVE_EVENT = 9;
const ACTION_TYPE_SET_TEXT = 10;
const ACTION_TYPE_SET_TEXT = 10;
const ACTION_TYPE_ADD_WXS_EVENT = 12;
const ACTION_TYPE_DICT = 0;
......@@ -64,6 +65,8 @@
return decodeRemoveAttributeAction(action, getDict);
case ACTION_TYPE_ADD_EVENT:
return decodeAddEventAction(action, getDict);
case ACTION_TYPE_ADD_WXS_EVENT:
return decodeAddWxsEventAction(action, getDict);
case ACTION_TYPE_REMOVE_EVENT:
return decodeRemoveEventAction(action, getDict);
case ACTION_TYPE_SET_TEXT:
......@@ -87,6 +90,9 @@
if (nodeJson.e) {
nodeJson.e = getDict(nodeJson.e, false);
}
if (nodeJson.w) {
nodeJson.w = getWxsEventDict(nodeJson.w, getDict);
}
if (nodeJson.s) {
nodeJson.s = getDict(nodeJson.s);
}
......@@ -95,6 +101,13 @@
}
return nodeJson;
}
function getWxsEventDict(w, getDict) {
const res = {};
w.forEach(([name, [wxsEvent, flag]]) => {
res[getDict(name)] = [getDict(wxsEvent), flag];
});
return res;
}
function decodeCreateAction([, nodeId, nodeName, parentNodeId, refNodeId, nodeJson], getDict) {
return [
'create',
......@@ -114,6 +127,15 @@
function decodeAddEventAction([, ...action], getDict) {
return ['addEvent', action[0], getDict(action[1]), action[2]];
}
function decodeAddWxsEventAction([, ...action], getDict) {
return [
'addWxsEvent',
action[0],
getDict(action[1]),
getDict(action[2]),
action[3],
];
}
function decodeRemoveEventAction([, ...action], getDict) {
return ['removeEvent', action[0], getDict(action[1])];
}
......
......@@ -1055,6 +1055,7 @@ var serviceContext = (function (vue) {
const ACTION_TYPE_ADD_EVENT = 8;
const ACTION_TYPE_REMOVE_EVENT = 9;
const ACTION_TYPE_SET_TEXT = 10;
const ACTION_TYPE_ADD_WXS_EVENT = 12;
const ACTION_TYPE_PAGE_SCROLL = 15;
const ACTION_TYPE_EVENT = 20;
......@@ -1133,6 +1134,7 @@ var serviceContext = (function (vue) {
const BACKGROUND_COLOR = '#f7f7f7'; // 背景色,如标题栏默认背景色
const SCHEME_RE = /^([a-z-]+:)?\/\//i;
const DATA_RE = /^data:.*,.*/;
const WXS_PROTOCOL = 'wxs://';
// lifecycle
// App and Page
const ON_SHOW = 'onShow';
......@@ -9371,7 +9373,7 @@ var serviceContext = (function (vue) {
}, errorCallback);
}, RequestPaymentProtocol);
function applyOptions(options, instance, publicThis) {
function initHooks(options, instance, publicThis) {
const mpType = options.mpType || publicThis.$mpType;
// 为了组件也可以监听部分生命周期,故不再判断mpType,统一添加on开头的生命周期
Object.keys(options).forEach((name) => {
......@@ -9393,6 +9395,57 @@ var serviceContext = (function (vue) {
}
}
function initRenderjs({ $renderjs }, instance) {
initModules(instance, $renderjs);
}
function initModules(instance, modules) {
if (!isArray(modules)) {
return;
}
const ctx = instance.ctx;
const $wxsModules = (instance.$wxsModules ||
(instance.$wxsModules = []));
modules.forEach((module) => {
ctx[module] = proxyModule(module);
$wxsModules.push(module);
});
}
const renderjsModule = {};
function proxyModule(module) {
return new Proxy(renderjsModule, {
get(_, p) {
return createModuleFunction(module, p);
},
});
}
function renderjsFn() { }
function createModuleFunction(module, name) {
const toJSON = () => WXS_PROTOCOL + JSON.stringify([module + '.' + name]);
return new Proxy(renderjsFn, {
get(_, p) {
if (p === 'toJSON') {
return toJSON;
}
return createModuleFunction(module + '.' + name, p);
},
apply(_target, _thisArg, args) {
return WXS_PROTOCOL + JSON.stringify([module + '.' + name, ...args]);
},
});
}
function initWxs({ $wxs }, instance) {
initModules(instance, $wxs);
}
function applyOptions(options, instance, publicThis) {
{
initWxs(options, instance);
initRenderjs(options, instance);
}
initHooks(options, instance, publicThis);
}
function set(target, key, val) {
return (target[key] = val);
}
......@@ -10467,6 +10520,11 @@ var serviceContext = (function (vue) {
pushAddEventAction(this, thisNode.nodeId, name, flag);
}
}
onAddWxsEvent(thisNode, name, wxsEvent, flag) {
if (thisNode.parentNode) {
pushAddWxsEventAction(this, thisNode.nodeId, name, wxsEvent, flag);
}
}
onRemoveEvent(thisNode, name) {
if (thisNode.parentNode) {
pushRemoveEventAction(this, thisNode.nodeId, name);
......@@ -10622,6 +10680,15 @@ var serviceContext = (function (vue) {
function pushAddEventAction(pageNode, nodeId, name, value) {
pageNode.push([ACTION_TYPE_ADD_EVENT, nodeId, pageNode.addDict(name), value]);
}
function pushAddWxsEventAction(pageNode, nodeId, name, wxsEvent, value) {
pageNode.push([
ACTION_TYPE_ADD_WXS_EVENT,
nodeId,
pageNode.addDict(name),
pageNode.addDict(wxsEvent),
value,
]);
}
function pushRemoveEventAction(pageNode, nodeId, name) {
pageNode.push([ACTION_TYPE_REMOVE_EVENT, nodeId, pageNode.addDict(name)]);
}
......
......@@ -874,6 +874,7 @@
var ACTION_TYPE_ADD_EVENT = 8;
var ACTION_TYPE_REMOVE_EVENT = 9;
var ACTION_TYPE_SET_TEXT = 10;
var ACTION_TYPE_ADD_WXS_EVENT = 12;
var ACTION_TYPE_PAGE_SCROLL = 15;
var ACTION_TYPE_EVENT = 20;
function cache(fn) {
......@@ -7394,6 +7395,9 @@
if (nodeJson.e) {
nodeJson.e = getDict(nodeJson.e, false);
}
if (nodeJson.w) {
nodeJson.w = getWxsEventDict(nodeJson.w, getDict);
}
if (nodeJson.s) {
nodeJson.s = getDict(nodeJson.s);
}
......@@ -7402,6 +7406,13 @@
}
return nodeJson;
}
function getWxsEventDict(w, getDict) {
var res = {};
w.forEach(([name, [wxsEvent, flag]]) => {
res[getDict(name)] = [getDict(wxsEvent), flag];
});
return res;
}
class UniNode {
constructor(id2, tag, parentNodeId, element) {
this.isMounted = false;
......@@ -7545,6 +7556,35 @@
}
return modifiers;
}
function patchWxsEvent(el, name, wxsEvent, flag) {
var [type, options] = parseEventName(name);
if (flag === -1) {
var listener = el.__listeners[type];
if (listener) {
el.removeEventListener(type, listener);
} else {
console.error(formatLog("tag", el.tagName, el.__id, "event[" + type + "] not found"));
}
} else {
if (el.__listeners[type]) {
{
console.error(formatLog("tag", el.tagName, el.__id, "event[" + type + "] already registered"));
}
return;
}
el.__listeners[type] = createWxsEventInvoker(el.__id, wxsEvent, flag, options);
el.addEventListener(type, el.__listeners[type], options);
}
}
function createWxsEventInvoker(id2, wxsEvent, flag, options) {
var invoker = (evt) => {
console.log("call wxsEvent", id2, wxsEvent, flag, options);
};
if (!flag) {
return invoker;
}
return withModifiers(invoker, resolveModifier(flag));
}
var postActionJobs = new Set();
function queuePostActionJob(job) {
postActionJobs.add(job);
......@@ -7591,6 +7631,9 @@
if (hasOwn$1(nodeJson, "e")) {
this.addEvents(nodeJson.e);
}
if (hasOwn$1(nodeJson, "w")) {
this.addWxsEvents(nodeJson.w);
}
super.init(nodeJson);
watch(this.$props, () => {
queuePostActionJob(this._update);
......@@ -7604,11 +7647,20 @@
this.setAttr(name, attrs2[name]);
});
}
addWxsEvents(events) {
Object.keys(events).forEach((name) => {
var [wxsEvent, flag] = events[name];
this.addWxsEvent(name, wxsEvent, flag);
});
}
addEvents(events) {
Object.keys(events).forEach((name) => {
this.addEvent(name, events[name]);
});
}
addWxsEvent(name, wxsEvent, flag) {
patchWxsEvent(this.$, name, wxsEvent, flag);
}
addEvent(name, value) {
patchEvent(this.$, name, value);
}
......@@ -17956,6 +18008,8 @@
return $(action[1]).removeAttr(getDict(action[2]));
case ACTION_TYPE_ADD_EVENT:
return $(action[1]).addEvent(getDict(action[2]), action[3]);
case ACTION_TYPE_ADD_WXS_EVENT:
return $(action[1]).addWxsEvent(getDict(action[2]), getDict(action[3]), action[4]);
case ACTION_TYPE_REMOVE_EVENT:
return $(action[1]).removeEvent(getDict(action[2]));
case ACTION_TYPE_SET_TEXT:
......
......@@ -27,6 +27,7 @@ import {
ON_PAGE_SCROLL,
ON_REACH_BOTTOM,
ACTION_TYPE_PAGE_SCROLL,
ACTION_TYPE_ADD_WXS_EVENT,
} from '@dcloudio/uni-shared'
import { getPageById } from '@dcloudio/uni-core'
......@@ -153,6 +154,16 @@ export default class UniPageNode extends UniNode implements IUniPageNode {
pushAddEventAction(this, thisNode.nodeId!, name, flag)
}
}
onAddWxsEvent(
thisNode: UniNode,
name: string,
wxsEvent: string,
flag: number
) {
if (thisNode.parentNode) {
pushAddWxsEventAction(this, thisNode.nodeId!, name, wxsEvent, flag)
}
}
onRemoveEvent(thisNode: UniNode, name: string) {
if (thisNode.parentNode) {
pushRemoveEventAction(this, thisNode.nodeId!, name)
......@@ -344,6 +355,22 @@ function pushAddEventAction(
pageNode.push([ACTION_TYPE_ADD_EVENT, nodeId, pageNode.addDict(name), value])
}
function pushAddWxsEventAction(
pageNode: UniPageNode,
nodeId: number,
name: string,
wxsEvent: string,
value: number
) {
pageNode.push([
ACTION_TYPE_ADD_WXS_EVENT,
nodeId,
pageNode.addDict(name),
pageNode.addDict(wxsEvent),
value,
])
}
function pushRemoveEventAction(
pageNode: UniPageNode,
nodeId: number,
......
import {
ACTION_TYPE_ADD_EVENT,
ACTION_TYPE_ADD_WXS_EVENT,
ACTION_TYPE_CREATE,
ACTION_TYPE_INSERT,
ACTION_TYPE_PAGE_CREATE,
......@@ -10,6 +11,7 @@ import {
ACTION_TYPE_SET_ATTRIBUTE,
ACTION_TYPE_SET_TEXT,
AddEventAction,
AddWxsEventAction,
CreateAction,
InsertAction,
PageAction,
......@@ -84,6 +86,8 @@ export function decodeActions(actions: (PageAction | DictAction)[]) {
return decodeRemoveAttributeAction(action, getDict)
case ACTION_TYPE_ADD_EVENT:
return decodeAddEventAction(action, getDict)
case ACTION_TYPE_ADD_WXS_EVENT:
return decodeAddWxsEventAction(action, getDict)
case ACTION_TYPE_REMOVE_EVENT:
return decodeRemoveEventAction(action, getDict)
case ACTION_TYPE_SET_TEXT:
......@@ -119,6 +123,12 @@ export function decodeNodeJson(
false
) as Record<string, number>
}
if (nodeJson.w) {
;(nodeJson as unknown as UniNodeJSON).w = getWxsEventDict(
nodeJson.w,
getDict
)
}
if (nodeJson.s) {
;(nodeJson as unknown as UniNodeJSON).s = getDict(
nodeJson.s as [number, number][]
......@@ -130,6 +140,14 @@ export function decodeNodeJson(
return nodeJson as unknown as UniNodeJSON
}
function getWxsEventDict(w: UniNodeJSONMinify['w'], getDict: GetDict) {
const res: UniNodeJSON['w'] = {}
w.forEach(([name, [wxsEvent, flag]]) => {
res[getDict(name)] = [getDict(wxsEvent), flag]
})
return res
}
function decodeCreateAction(
[, nodeId, nodeName, parentNodeId, refNodeId, nodeJson]: CreateAction,
getDict: GetDict
......@@ -156,6 +174,19 @@ function decodeAddEventAction([, ...action]: AddEventAction, getDict: GetDict) {
return ['addEvent', action[0], getDict(action[1] as number), action[2]]
}
function decodeAddWxsEventAction(
[, ...action]: AddWxsEventAction,
getDict: GetDict
) {
return [
'addWxsEvent',
action[0],
getDict(action[1] as number),
getDict(action[2] as number),
action[3],
]
}
function decodeRemoveEventAction(
[, ...action]: RemoveEventAction,
getDict: GetDict
......
......@@ -11,7 +11,7 @@ import { reactive, watch } from 'vue'
import { UniNode } from './UniNode'
import { patchClass } from '../modules/class'
import { patchStyle } from '../modules/style'
import { patchEvent } from '../modules/events'
import { patchEvent, patchWxsEvent } from '../modules/events'
import { UniCustomElement } from '../components'
import { queuePostActionJob } from '../scheduler'
import { decodeAttr } from '../utils'
......@@ -48,6 +48,9 @@ export class UniElement<T extends object> extends UniNode {
if (hasOwn(nodeJson, 'e')) {
this.addEvents(nodeJson.e!)
}
if (hasOwn(nodeJson, 'w')) {
this.addWxsEvents(nodeJson.w!)
}
super.init(nodeJson)
watch(
this.$props,
......@@ -63,11 +66,20 @@ export class UniElement<T extends object> extends UniNode {
this.setAttr(name, attrs[name])
})
}
addWxsEvents(events: Record<string, [string, number]>) {
Object.keys(events).forEach((name) => {
const [wxsEvent, flag] = events[name]
this.addWxsEvent(name, wxsEvent, flag)
})
}
addEvents(events: Record<string, number>) {
Object.keys(events).forEach((name) => {
this.addEvent(name, events[name])
})
}
addWxsEvent(name: string, wxsEvent: string, flag: number) {
patchWxsEvent(this.$, name, wxsEvent, flag)
}
addEvent(name: string, value: number) {
patchEvent(this.$, name, value)
}
......
......@@ -13,6 +13,7 @@ import {
PageCreateAction,
formatLog,
ACTION_TYPE_PAGE_SCROLL,
ACTION_TYPE_ADD_WXS_EVENT,
} from '@dcloudio/uni-shared'
import { UniNodeJSONMinify } from 'packages/uni-shared/src/vdom/Node'
import { ACTION_TYPE_DICT, DictAction, Dictionary } from '../../../constants'
......@@ -76,6 +77,12 @@ function onPageUpdateSync(actions: (PageAction | DictAction)[]) {
return $(action[1]).removeAttr(getDict(action[2] as number))
case ACTION_TYPE_ADD_EVENT:
return $(action[1]).addEvent(getDict(action[2] as number), action[3])
case ACTION_TYPE_ADD_WXS_EVENT:
return $(action[1]).addWxsEvent(
getDict(action[2] as number),
getDict(action[3] as number),
action[4]
)
case ACTION_TYPE_REMOVE_EVENT:
return $(action[1]).removeEvent(getDict(action[2] as number))
case ACTION_TYPE_SET_TEXT:
......
......@@ -71,3 +71,63 @@ function resolveModifier(flag: number) {
}
return modifiers
}
export function patchWxsEvent(
el: UniCustomElement,
name: string,
wxsEvent: 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')
)
}
} else {
// add
if (el.__listeners[type]) {
if (__DEV__) {
console.error(
formatLog(
`tag`,
el.tagName,
el.__id,
'event[' + type + '] already registered'
)
)
}
return
}
el.__listeners[type] = createWxsEventInvoker(
el.__id,
wxsEvent,
flag,
options
)
el.addEventListener(type, el.__listeners[type], options)
}
}
function createWxsEventInvoker(
id: number,
wxsEvent: string,
flag: number,
options?: AddEventListenerOptions
) {
const invoker = (evt: Event) => {
console.log('call wxsEvent', id, wxsEvent, flag, options)
// const event = normalizeNativeEvent(evt)
// ;(event as any).type = normalizeEventType(evt.type, options)
// UniViewJSBridge.publishHandler(VD_SYNC, [[ACTION_TYPE_EVENT, id, event]])
}
if (!flag) {
return invoker
}
return withModifiers(invoker, resolveModifier(flag))
}
......@@ -7,6 +7,7 @@ const mainJs_1 = require("./plugins/mainJs");
const manifestJson_1 = require("./plugins/manifestJson");
const pagesJson_1 = require("./plugins/pagesJson");
const resolveId_1 = require("./plugins/resolveId");
const renderjs_1 = require("./plugins/renderjs");
function initUniCssScopedPluginOptions() {
const styleIsolation = uni_cli_shared_1.getAppStyleIsolation(uni_cli_shared_1.parseManifestJsonOnce(process.env.UNI_INPUT_DIR));
if (styleIsolation === 'shared') {
......@@ -26,6 +27,7 @@ const plugins = [
manifestJson_1.uniManifestJsonPlugin(),
pagesJson_1.uniPagesJsonPlugin(),
uni_cli_shared_1.uniViteInjectPlugin(uni_cli_shared_1.initProvide()),
renderjs_1.uniRenderjsPlugin(),
plugin_1.UniAppPlugin,
];
const uniCssScopedPluginOptions = initUniCssScopedPluginOptions();
......
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.transformRenderjs = void 0;
const transformRenderjs = () => { };
exports.transformRenderjs = transformRenderjs;
......@@ -24,7 +24,9 @@ function uniRenderjsPlugin() {
type: 'asset',
source: code,
});
return '';
return `export default Comp => {
;(Comp.$${type} || (Comp.$${type} = [])).push('${name}')
}`;
},
};
}
......
......@@ -11,6 +11,7 @@ import { uniMainJsPlugin } from './plugins/mainJs'
import { uniManifestJsonPlugin } from './plugins/manifestJson'
import { uniPagesJsonPlugin } from './plugins/pagesJson'
import { uniResolveIdPlugin } from './plugins/resolveId'
import { uniRenderjsPlugin } from './plugins/renderjs'
function initUniCssScopedPluginOptions() {
const styleIsolation = getAppStyleIsolation(
......@@ -34,6 +35,7 @@ const plugins = [
uniManifestJsonPlugin(),
uniPagesJsonPlugin(),
uniViteInjectPlugin(initProvide()),
uniRenderjsPlugin(),
UniAppPlugin,
]
......
import { NodeTransform } from '@vue/compiler-core'
export const transformRenderjs: NodeTransform = () => {}
import debug from 'debug'
import { Plugin } from 'vite'
import { missingModuleName, parseRenderjs } from '@dcloudio/uni-cli-shared'
const debugRenderjs = debug('vite:uni:renderjs')
export function uniRenderjsPlugin(): Plugin {
return {
name: 'vite:uni-app-renderjs',
transform(code, id) {
const { type, name } = parseRenderjs(id)
if (!type) {
return
}
debugRenderjs(id)
if (!name) {
this.error(missingModuleName(type, code))
}
this.emitFile({
fileName: '.renderjs.js',
type: 'asset',
source: code,
})
return `export default Comp => {
;(Comp.$${type} || (Comp.$${type} = [])).push('${name}')
}`
},
}
}
......@@ -410,7 +410,11 @@ export default function vueFactory(exports) {
super.addEventListener(type, listener, options);
if (this.pageNode && !this.pageNode.isUnmounted) {
this.pageNode.onAddEvent(this, normalizeEventType(type, options), encodeModifier(listener.modifiers || []));
if (listener.wxsEvent) {
this.pageNode.onAddWxsEvent(this, normalizeEventType(type, options), listener.wxsEvent, encodeModifier(listener.modifiers || []));
} else {
this.pageNode.onAddEvent(this, normalizeEventType(type, options), encodeModifier(listener.modifiers || []));
}
}
}
......@@ -473,16 +477,35 @@ export default function vueFactory(exports) {
var events = Object.keys(listeners);
if (events.length) {
var w = undefined;
var e = {};
events.forEach(name => {
var handlers = listeners[name];
if (handlers.length) {
// 可能存在多个 handler 且不同 modifiers 吗?
e[name] = encodeModifier(handlers[0].modifiers || []);
var {
wxsEvent,
modifiers
} = handlers[0];
var modifier = encodeModifier(modifiers || []);
if (!wxsEvent) {
e[name] = modifier;
} else {
if (!w) {
w = {};
}
w[name] = [normalize ? normalize(wxsEvent) : wxsEvent, modifier];
}
}
});
res.e = normalize ? normalize(e, false) : e;
if (w) {
res.w = normalize ? normalize(w, false) : w;
}
}
if (style !== null) {
......@@ -2299,7 +2322,8 @@ export default function vueFactory(exports) {
if (throwInDev) {
throw err;
// throw err fixed by xxxxxx 避免 error 导致 App 端不可用(比如跳转时报错)
console.error(err);
} else {
console.error(err);
}
......@@ -5172,6 +5196,7 @@ export default function vueFactory(exports) {
function injectHook(type, hook, target = currentInstance, prepend = false) {
if (target) {
// fixed by xxxxxx
if (isRootHook(type)) {
target = target.root;
}
......@@ -11139,16 +11164,42 @@ export default function vueFactory(exports) {
});
}
});
} else if (invoker.value.modifiers) {
invoker.value.modifiers.forEach(m => {
modifiers.add(m);
});
} else {
if (invoker.value.modifiers) {
invoker.value.modifiers.forEach(m => {
modifiers.add(m);
});
}
initWxsEvent(invoker, instance);
}
invoker.modifiers = [...modifiers];
return invoker;
}
function initWxsEvent(invoker, instance) {
if (!instance) {
return;
}
var {
$wxsModules
} = instance;
if (!$wxsModules) {
return;
}
var invokerSourceCode = invoker.value.toString();
if (!$wxsModules.find(module => invokerSourceCode.indexOf('.' + module + '.') > -1)) {
return;
}
invoker.wxsEvent = invoker.value();
}
var forcePatchProps = {
AD: ['data'],
'AD-DRAW': ['data'],
......@@ -11176,7 +11227,7 @@ export default function vueFactory(exports) {
return false;
};
var patchProp = (el, key, prevValue, nextValue, parentComponent) => {
var patchProp = (el, key, prevValue, nextValue, isSVG = false, prevChildren, parentComponent, parentSuspense, unmountChildren) => {
switch (key) {
// special
case 'class':
......@@ -11191,7 +11242,7 @@ export default function vueFactory(exports) {
if (isOn(key)) {
// ignore v-model listeners
if (!isModelListener(key)) {
patchEvent(el, key, prevValue, nextValue);
patchEvent(el, key, prevValue, nextValue, parentComponent);
}
} else {
// 非基本类型
......
......@@ -1352,7 +1352,8 @@ function logError(err, type, contextVNode, throwInDev = true) {
}
// crash in dev by default so it's more noticeable
if (throwInDev) {
throw err;
// throw err fixed by xxxxxx 避免 error 导致 App 端不可用(比如跳转时报错)
console.error(err);
}
else {
console.error(err);
......@@ -4036,6 +4037,7 @@ function getInnerChild(vnode) {
function injectHook(type, hook, target = currentInstance, prepend = false) {
if (target) {
// fixed by xxxxxx
if (isRootHook(type)) {
target = target.root;
}
......@@ -9122,13 +9124,30 @@ function createInvoker(initialValue, instance) {
}
});
}
else if (invoker.value.modifiers) {
invoker.value.modifiers.forEach((m) => {
modifiers.add(m);
});
else {
if (invoker.value.modifiers) {
invoker.value.modifiers.forEach((m) => {
modifiers.add(m);
});
}
initWxsEvent(invoker, instance);
}
invoker.modifiers = [...modifiers];
return invoker;
}
function initWxsEvent(invoker, instance) {
if (!instance) {
return;
}
const { $wxsModules } = instance;
if (!$wxsModules) {
return;
}
const invokerSourceCode = invoker.value.toString();
if (!$wxsModules.find(module => invokerSourceCode.indexOf('.' + module + '.') > -1)) {
return;
}
invoker.wxsEvent = invoker.value();
}
const forcePatchProps = {
......@@ -9160,7 +9179,7 @@ const forcePatchProp = (_, key) => {
}
return false;
};
const patchProp = (el, key, prevValue, nextValue, parentComponent) => {
const patchProp = (el, key, prevValue, nextValue, isSVG = false, prevChildren, parentComponent, parentSuspense, unmountChildren) => {
switch (key) {
// special
case 'class':
......@@ -9173,7 +9192,7 @@ const patchProp = (el, key, prevValue, nextValue, parentComponent) => {
if (isOn(key)) {
// ignore v-model listeners
if (!isModelListener(key)) {
patchEvent(el, key, prevValue, nextValue);
patchEvent(el, key, prevValue, nextValue, parentComponent);
}
}
else {
......
......@@ -15,6 +15,7 @@ interface UniVitePluginUniOptions {
isNativeTag: ParserOptions['isNativeTag']
isCustomElement: ParserOptions['isCustomElement']
directiveTransforms?: CompilerOptions['directiveTransforms']
nodeTransforms?: CompilerOptions['nodeTransforms']
}
transformEvent?: Record<string, string>
copyOptions?: CopyOptions | (() => CopyOptions)
......
import { provide, ref, SetupContext } from 'vue'
import { provide, ref } from 'vue'
import {
CustomEventTrigger,
EmitEvent,
......
......@@ -6642,7 +6642,7 @@ function useContextInfo(_id) {
const id = _id || vm.id || `context${index$a++}`;
return `${type}.${id}`;
}
function applyOptions(options, instance, publicThis) {
function initHooks(options, instance, publicThis) {
options.mpType || publicThis.$mpType;
Object.keys(options).forEach((name) => {
if (name.indexOf("on") === 0) {
......@@ -6653,6 +6653,9 @@ function applyOptions(options, instance, publicThis) {
}
});
}
function applyOptions(options, instance, publicThis) {
initHooks(options, instance, publicThis);
}
function set(target, key, val) {
return target[key] = val;
}
......
......@@ -13221,7 +13221,7 @@ function useContextInfo(_id) {
function getContextInfo(el) {
return el.__uniContextInfo;
}
function applyOptions(options, instance2, publicThis) {
function initHooks(options, instance2, publicThis) {
options.mpType || publicThis.$mpType;
Object.keys(options).forEach((name) => {
if (name.indexOf("on") === 0) {
......@@ -13232,6 +13232,9 @@ function applyOptions(options, instance2, publicThis) {
}
});
}
function applyOptions(options, instance2, publicThis) {
initHooks(options, instance2, publicThis);
}
function set(target, key, val) {
return target[key] = val;
}
......
......@@ -598,7 +598,12 @@ class UniBaseNode extends UniNode {
addEventListener(type, listener, options) {
super.addEventListener(type, listener, options);
if (this.pageNode && !this.pageNode.isUnmounted) {
this.pageNode.onAddEvent(this, normalizeEventType(type, options), encodeModifier(listener.modifiers || []));
if (listener.wxsEvent) {
this.pageNode.onAddWxsEvent(this, normalizeEventType(type, options), listener.wxsEvent, encodeModifier(listener.modifiers || []));
}
else {
this.pageNode.onAddEvent(this, normalizeEventType(type, options), encodeModifier(listener.modifiers || []));
}
}
}
removeEventListener(type, callback, options) {
......@@ -643,15 +648,29 @@ class UniBaseNode extends UniNode {
}
const events = Object.keys(listeners);
if (events.length) {
let w = undefined;
const e = {};
events.forEach((name) => {
const handlers = listeners[name];
if (handlers.length) {
// 可能存在多个 handler 且不同 modifiers 吗?
e[name] = encodeModifier(handlers[0].modifiers || []);
const { wxsEvent, modifiers } = handlers[0];
const modifier = encodeModifier(modifiers || []);
if (!wxsEvent) {
e[name] = modifier;
}
else {
if (!w) {
w = {};
}
w[name] = [normalize ? normalize(wxsEvent) : wxsEvent, modifier];
}
}
});
res.e = normalize ? normalize(e, false) : e;
if (w) {
res.w = normalize ? normalize(w, false) : w;
}
}
if (style !== null) {
res.s = normalize ? normalize(style) : style;
......@@ -731,6 +750,7 @@ const ACTION_TYPE_REMOVE_ATTRIBUTE = 7;
const ACTION_TYPE_ADD_EVENT = 8;
const ACTION_TYPE_REMOVE_EVENT = 9;
const ACTION_TYPE_SET_TEXT = 10;
const ACTION_TYPE_ADD_WXS_EVENT = 12;
const ACTION_TYPE_PAGE_SCROLL = 15;
const ACTION_TYPE_EVENT = 20;
......@@ -837,7 +857,9 @@ const UNI_SSR_GLOBAL_DATA = 'globalData';
const SCHEME_RE = /^([a-z-]+:)?\/\//i;
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';
......@@ -954,6 +976,7 @@ function getEnvLocale() {
}
exports.ACTION_TYPE_ADD_EVENT = ACTION_TYPE_ADD_EVENT;
exports.ACTION_TYPE_ADD_WXS_EVENT = ACTION_TYPE_ADD_WXS_EVENT;
exports.ACTION_TYPE_CREATE = ACTION_TYPE_CREATE;
exports.ACTION_TYPE_EVENT = ACTION_TYPE_EVENT;
exports.ACTION_TYPE_INSERT = ACTION_TYPE_INSERT;
......@@ -1034,6 +1057,8 @@ 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;
exports.cacheStringFunction = cacheStringFunction;
......
......@@ -2,6 +2,8 @@ import { FontFaceDescriptors } from 'css-font-loading-module';
export declare const ACTION_TYPE_ADD_EVENT = 8;
export declare const ACTION_TYPE_ADD_WXS_EVENT = 12;
export declare const ACTION_TYPE_CREATE = 3;
export declare const ACTION_TYPE_EVENT = 20;
......@@ -38,6 +40,20 @@ number
export declare function addFont(family: string, source: string, desc?: FontFaceDescriptors): Promise<void>;
/**
* nodeId
* event
* wxsEvent
* flag
*/
export declare type AddWxsEventAction = [
typeof ACTION_TYPE_ADD_WXS_EVENT,
number,
string | number,
string | number,
number
];
export declare const ATTR_CLASS = "class";
export declare const ATTR_INNER_HTML = "innerHTML";
......@@ -189,6 +205,7 @@ export declare interface IUniPageNode {
onInsertBefore: (thisNode: UniNode, newChild: UniNode, refChild: UniNode | null) => UniNode;
onRemoveChild: (oldChild: UniNode) => UniNode;
onAddEvent: (thisNode: UniNode, name: string, flag: number) => void;
onAddWxsEvent: (thisNode: UniNode, name: string, wxsEvent: string, flag: number) => void;
onRemoveEvent: (thisNode: UniNode, name: string) => void;
onSetAttribute: (thisNode: UniNode, qualifiedName: string, value: unknown) => void;
onRemoveAttribute: (thisNode: UniNode, qualifiedName: string) => void;
......@@ -318,7 +335,7 @@ export declare interface PageNodeOptions {
*/
export declare type PageScrollAction = [typeof ACTION_TYPE_PAGE_SCROLL, number];
export declare type PageUpdateAction = CreateAction | InsertAction | RemoveAction | AddEventAction | RemoveEventAction | SetAttributeAction | RemoveAttributeAction | SetTextAction;
export declare type PageUpdateAction = CreateAction | InsertAction | RemoveAction | AddEventAction | AddWxsEventAction | RemoveEventAction | SetAttributeAction | RemoveAttributeAction | SetTextAction;
export declare function parseEventName(name: string): [string, EventListenerOptions | undefined];
......@@ -482,6 +499,7 @@ export declare class UniEvent {
export declare interface UniEventListener {
(evt: UniEvent): void;
modifiers?: string[];
wxsEvent?: string;
}
declare interface UniEventOptions {
......@@ -542,6 +560,10 @@ export declare interface UniNodeJSON {
* listeners
*/
e: Record<string, number>;
/**
* wxs listeners
*/
w: Record<string, [string, number]>;
/**
* style
*/
......@@ -569,6 +591,10 @@ declare interface UniNodeJSONMinify {
* listeners
*/
e: DictArray;
/**
* wxs listeners
*/
w: [number, [number, number]][];
/**
* style
*/
......@@ -594,4 +620,8 @@ 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 { }
......@@ -594,7 +594,12 @@ class UniBaseNode extends UniNode {
addEventListener(type, listener, options) {
super.addEventListener(type, listener, options);
if (this.pageNode && !this.pageNode.isUnmounted) {
this.pageNode.onAddEvent(this, normalizeEventType(type, options), encodeModifier(listener.modifiers || []));
if (listener.wxsEvent) {
this.pageNode.onAddWxsEvent(this, normalizeEventType(type, options), listener.wxsEvent, encodeModifier(listener.modifiers || []));
}
else {
this.pageNode.onAddEvent(this, normalizeEventType(type, options), encodeModifier(listener.modifiers || []));
}
}
}
removeEventListener(type, callback, options) {
......@@ -639,15 +644,29 @@ class UniBaseNode extends UniNode {
}
const events = Object.keys(listeners);
if (events.length) {
let w = undefined;
const e = {};
events.forEach((name) => {
const handlers = listeners[name];
if (handlers.length) {
// 可能存在多个 handler 且不同 modifiers 吗?
e[name] = encodeModifier(handlers[0].modifiers || []);
const { wxsEvent, modifiers } = handlers[0];
const modifier = encodeModifier(modifiers || []);
if (!wxsEvent) {
e[name] = modifier;
}
else {
if (!w) {
w = {};
}
w[name] = [normalize ? normalize(wxsEvent) : wxsEvent, modifier];
}
}
});
res.e = normalize ? normalize(e, false) : e;
if (w) {
res.w = normalize ? normalize(w, false) : w;
}
}
if (style !== null) {
res.s = normalize ? normalize(style) : style;
......@@ -727,6 +746,7 @@ const ACTION_TYPE_REMOVE_ATTRIBUTE = 7;
const ACTION_TYPE_ADD_EVENT = 8;
const ACTION_TYPE_REMOVE_EVENT = 9;
const ACTION_TYPE_SET_TEXT = 10;
const ACTION_TYPE_ADD_WXS_EVENT = 12;
const ACTION_TYPE_PAGE_SCROLL = 15;
const ACTION_TYPE_EVENT = 20;
......@@ -833,7 +853,9 @@ const UNI_SSR_GLOBAL_DATA = 'globalData';
const SCHEME_RE = /^([a-z-]+:)?\/\//i;
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';
......@@ -949,4 +971,4 @@ function getEnvLocale() {
return (lang && lang.replace(/[.:].*/, '')) || 'en';
}
export { ACTION_TYPE_ADD_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, 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_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 };
......@@ -20,8 +20,11 @@ export const DATA_RE = /^data:.*,.*/
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
......
......@@ -11,6 +11,7 @@ export const ACTION_TYPE_ADD_EVENT = 8
export const ACTION_TYPE_REMOVE_EVENT = 9
export const ACTION_TYPE_SET_TEXT = 10
export const ACTION_TYPE_ADD_WXS_EVENT = 12
export const ACTION_TYPE_PAGE_SCROLL = 15
export const ACTION_TYPE_EVENT = 20
......@@ -77,6 +78,20 @@ export type AddEventAction = [
number
]
/**
* nodeId
* event
* wxsEvent
* flag
*/
export type AddWxsEventAction = [
typeof ACTION_TYPE_ADD_WXS_EVENT,
number,
string | number,
string | number,
number
]
/**
* nodeId
* event
......@@ -129,6 +144,7 @@ export type PageUpdateAction =
| InsertAction
| RemoveAction
| AddEventAction
| AddWxsEventAction
| RemoveEventAction
| SetAttributeAction
| RemoveAttributeAction
......
......@@ -23,6 +23,7 @@ export function normalizeEventType(
export interface UniEventListener {
(evt: UniEvent): void
modifiers?: string[]
wxsEvent?: string // 'wxs://['animate.start']'
}
interface UniEventOptions {
......
......@@ -53,6 +53,12 @@ export interface IUniPageNode {
) => UniNode
onRemoveChild: (oldChild: UniNode) => UniNode
onAddEvent: (thisNode: UniNode, name: string, flag: number) => void
onAddWxsEvent: (
thisNode: UniNode,
name: string,
wxsEvent: string,
flag: number
) => void
onRemoveEvent: (thisNode: UniNode, name: string) => void
onSetAttribute: (
thisNode: UniNode,
......@@ -216,6 +222,10 @@ export interface UniNodeJSONMinify {
* listeners
*/
e: DictArray
/**
* wxs listeners
*/
w: [number, [number, number]][]
/**
* style
*/
......@@ -242,6 +252,10 @@ export interface UniNodeJSON {
* listeners
*/
e: Record<string, number>
/**
* wxs listeners
*/
w: Record<string, [string, number]>
/**
* style
*/
......@@ -295,11 +309,20 @@ export class UniBaseNode extends UniNode {
) {
super.addEventListener(type, listener, options)
if (this.pageNode && !this.pageNode.isUnmounted) {
this.pageNode.onAddEvent(
this,
normalizeEventType(type, options),
encodeModifier(listener.modifiers || [])
)
if (listener.wxsEvent) {
this.pageNode.onAddWxsEvent(
this,
normalizeEventType(type, options),
listener.wxsEvent,
encodeModifier(listener.modifiers || [])
)
} else {
this.pageNode.onAddEvent(
this,
normalizeEventType(type, options),
encodeModifier(listener.modifiers || [])
)
}
}
}
......@@ -358,15 +381,28 @@ export class UniBaseNode extends UniNode {
}
const events = Object.keys(listeners)
if (events.length) {
let w: Record<string, [string | number, number]> | undefined = undefined
const e: Record<string, number> = {}
events.forEach((name) => {
const handlers = listeners[name]
if (handlers.length) {
// 可能存在多个 handler 且不同 modifiers 吗?
e[name] = encodeModifier(handlers[0].modifiers || [])
const { wxsEvent, modifiers } = handlers[0]
const modifier = encodeModifier(modifiers || [])
if (!wxsEvent) {
e[name] = modifier
} else {
if (!w) {
w = {}
}
w[name] = [normalize ? normalize(wxsEvent!) : wxsEvent, modifier]
}
}
})
res.e = normalize ? normalize(e, false) : e
if (w) {
res.w = normalize ? normalize(w, false) : w
}
}
if (style !== null) {
res.s = normalize ? normalize(style) : style
......
......@@ -10,7 +10,7 @@ import {
// @ts-ignore
import { injectHook } from 'vue'
export function applyOptions(
export function initHooks(
options: ComponentOptions,
instance: ComponentInternalInstance,
publicThis: ComponentPublicInstance
......
import {
ComponentOptions,
ComponentInternalInstance,
ComponentPublicInstance,
} from 'vue'
// @ts-ignore
import { injectHook } from 'vue'
import { initHooks } from './hooks'
import { initRenderjs } from './renderjs'
import { initWxs } from './wxs'
export function applyOptions(
options: ComponentOptions,
instance: ComponentInternalInstance,
publicThis: ComponentPublicInstance
) {
if (__PLATFORM__ === 'app') {
initWxs(options, instance)
initRenderjs(options, instance)
}
initHooks(options, instance, publicThis)
}
import { WXS_PROTOCOL } from '@dcloudio/uni-shared'
import { isArray } from '@vue/shared'
import { ComponentInternalInstance, ComponentOptions } from 'vue'
export function initRenderjs(
{ $renderjs }: ComponentOptions,
instance: ComponentInternalInstance
) {
initModules(instance, $renderjs)
}
export function initModules(
instance: ComponentInternalInstance,
modules: string[]
) {
if (!isArray(modules)) {
return
}
const ctx = (instance as any).ctx
const $wxsModules = (instance.$wxsModules ||
(instance.$wxsModules = [])) as unknown as string[]
modules.forEach((module) => {
ctx[module] = proxyModule(module)
$wxsModules.push(module)
})
}
const renderjsModule = {}
function proxyModule(module: string) {
return new Proxy(renderjsModule, {
get(_, p) {
return createModuleFunction(module, p as string)
},
})
}
function renderjsFn() {}
function createModuleFunction(module: string, name: string): Function {
const toJSON = () => WXS_PROTOCOL + JSON.stringify([module + '.' + name])
return new Proxy(renderjsFn, {
get(_, p) {
if (p === 'toJSON') {
return toJSON
}
return createModuleFunction(module + '.' + name, p as string)
},
apply(_target, _thisArg, args) {
return WXS_PROTOCOL + JSON.stringify([module + '.' + name, ...args])
},
})
}
import { ComponentInternalInstance, ComponentOptions } from 'vue'
import { initModules } from './renderjs'
export function initWxs(
{ $wxs }: ComponentOptions,
instance: ComponentInternalInstance
) {
initModules(instance, $wxs)
}
......@@ -40,7 +40,7 @@
"@types/sass": "^1.16.0"
},
"uni-app": {
"compilerVersion": "3.2.0"
"compilerVersion": "3.2.1"
},
"gitHead": "4dd0e035b52584ff028ee3028c46adc555be0529"
}
......@@ -66,7 +66,12 @@ export function initPluginVueOptions(
templateOptions.compilerOptions || (templateOptions.compilerOptions = {})
const {
compilerOptions: { isNativeTag, isCustomElement, directiveTransforms },
compilerOptions: {
isNativeTag,
isCustomElement,
nodeTransforms,
directiveTransforms,
},
} = uniPluginOptions
compilerOptions.isNativeTag = isNativeTag
compilerOptions.isCustomElement = isCustomElement
......@@ -80,6 +85,9 @@ export function initPluginVueOptions(
if (!compilerOptions.nodeTransforms) {
compilerOptions.nodeTransforms = []
}
if (nodeTransforms) {
compilerOptions.nodeTransforms.push(...nodeTransforms)
}
// const compatConfig = parseCompatConfigOnce(options.inputDir)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册