提交 31337c86 编写于 作者: Q qiang

Merge branch 'dev' into alpha

import { isPlainObject, hasOwn, isArray, toNumber, isObject, capitalize, isFunction, extend, NOOP, EMPTY_OBJ, camelize } from '@vue/shared';
import { isPlainObject, isArray, extend, hyphenate, isObject, hasOwn, toNumber, capitalize, isFunction, NOOP, EMPTY_OBJ, camelize } from '@vue/shared';
const encode = encodeURIComponent;
function stringifyQuery(obj, encodeStr = encode) {
......@@ -19,6 +19,14 @@ function stringifyQuery(obj, encodeStr = encode) {
: null;
return res ? `?${res}` : '';
}
function cache(fn) {
const cache = Object.create(null);
return (str) => {
const hit = cache[str];
return hit || (cache[str] = fn(str));
};
}
const invokeArrayFns = (fns, arg) => {
let ret;
for (let i = 0; i < fns.length; i++) {
......@@ -121,6 +129,167 @@ function getEventChannel(id) {
return eventChannelStack.shift();
}
function initVueIds(vueIds, mpInstance) {
if (!vueIds) {
return;
}
const ids = vueIds.split(',');
const len = ids.length;
if (len === 1) {
mpInstance._$vueId = ids[0];
}
else if (len === 2) {
mpInstance._$vueId = ids[0];
mpInstance._$vuePid = ids[1];
}
}
function initWxsCallMethods(methods, wxsCallMethods) {
if (!isArray(wxsCallMethods)) {
return;
}
wxsCallMethods.forEach((callMethod) => {
methods[callMethod] = function (args) {
return this.$vm[callMethod](args);
};
});
}
function findVmByVueId(instance, vuePid) {
// 标准 vue3 中 没有 $children,定制了内核
const $children = instance.$children;
// 优先查找直属(反向查找:https://github.com/dcloudio/uni-app/issues/1200)
for (let i = $children.length - 1; i >= 0; i--) {
const childVm = $children[i];
if (childVm.$scope._$vueId === vuePid) {
return childVm;
}
}
// 反向递归查找
let parentVm;
for (let i = $children.length - 1; i >= 0; i--) {
parentVm = findVmByVueId($children[i], vuePid);
if (parentVm) {
return parentVm;
}
}
}
function getTarget(obj, path) {
const parts = path.split('.');
let key = parts[0];
if (key.indexOf('__$n') === 0) {
//number index
key = parseInt(key.replace('__$n', ''));
}
if (!obj) {
obj = {};
}
if (parts.length === 1) {
return obj[key];
}
return getTarget(obj[key], parts.slice(1).join('.'));
}
function getValue(dataPath, target) {
return getTarget(target || this, dataPath);
}
function getClass(dynamicClass, staticClass) {
return renderClass(staticClass, dynamicClass);
}
function getStyle(dynamicStyle, staticStyle) {
if (!dynamicStyle && !staticStyle) {
return '';
}
var dynamicStyleObj = normalizeStyleBinding(dynamicStyle);
var styleObj = staticStyle
? extend(staticStyle, dynamicStyleObj)
: dynamicStyleObj;
return Object.keys(styleObj)
.map(function (name) {
return hyphenate(name) + ':' + styleObj[name];
})
.join(';');
}
function toObject(arr) {
var res = {};
for (var i = 0; i < arr.length; i++) {
if (arr[i]) {
extend(res, arr[i]);
}
}
return res;
}
function normalizeStyleBinding(bindingStyle) {
if (Array.isArray(bindingStyle)) {
return toObject(bindingStyle);
}
if (typeof bindingStyle === 'string') {
return parseStyleText(bindingStyle);
}
return bindingStyle;
}
var parseStyleText = cache(function parseStyleText(cssText) {
var res = {};
var listDelimiter = /;(?![^(]*\))/g;
var propertyDelimiter = /:(.+)/;
cssText.split(listDelimiter).forEach(function (item) {
if (item) {
var tmp = item.split(propertyDelimiter);
tmp.length > 1 && (res[tmp[0].trim()] = tmp[1].trim());
}
});
return res;
});
function isDef(v) {
return v !== undefined && v !== null;
}
function renderClass(staticClass, dynamicClass) {
if (isDef(staticClass) || isDef(dynamicClass)) {
return concat(staticClass, stringifyClass(dynamicClass));
}
/* istanbul ignore next */
return '';
}
function concat(a, b) {
return a ? (b ? a + ' ' + b : a) : b || '';
}
function stringifyClass(value) {
if (Array.isArray(value)) {
return stringifyArray(value);
}
if (isObject(value)) {
return stringifyObject(value);
}
if (typeof value === 'string') {
return value;
}
/* istanbul ignore next */
return '';
}
function stringifyArray(value) {
var res = '';
var stringified;
for (var i = 0, l = value.length; i < l; i++) {
if (isDef((stringified = stringifyClass(value[i]))) && stringified !== '') {
if (res) {
res += ' ';
}
res += stringified;
}
}
return res;
}
function stringifyObject(value) {
var res = '';
for (var key in value) {
if (value[key]) {
if (res) {
res += ' ';
}
res += key;
}
}
return res;
}
function setModel(target, key, value, modifiers) {
if (isArray(modifiers)) {
if (modifiers.indexOf('trim') !== -1) {
......@@ -239,7 +408,9 @@ function initComponentInstance(instance, options) {
ctx.__set_sync = setSync;
ctx.__get_orig = getOrig;
// TODO
// ctx.__get_style = getStyle
ctx.__get_value = getValue;
ctx.__get_class = getClass;
ctx.__get_style = getStyle;
ctx.__map = map;
}
function initMocks(instance, mpInstance, mocks) {
......@@ -366,50 +537,6 @@ function initCreateApp(parseAppOptions) {
};
}
function initVueIds(vueIds, mpInstance) {
if (!vueIds) {
return;
}
const ids = vueIds.split(',');
const len = ids.length;
if (len === 1) {
mpInstance._$vueId = ids[0];
}
else if (len === 2) {
mpInstance._$vueId = ids[0];
mpInstance._$vuePid = ids[1];
}
}
function initWxsCallMethods(methods, wxsCallMethods) {
if (!isArray(wxsCallMethods)) {
return;
}
wxsCallMethods.forEach((callMethod) => {
methods[callMethod] = function (args) {
return this.$vm[callMethod](args);
};
});
}
function findVmByVueId(instance, vuePid) {
// 标准 vue3 中 没有 $children,定制了内核
const $children = instance.$children;
// 优先查找直属(反向查找:https://github.com/dcloudio/uni-app/issues/1200)
for (let i = $children.length - 1; i >= 0; i--) {
const childVm = $children[i];
if (childVm.$scope._$vueId === vuePid) {
return childVm;
}
}
// 反向递归查找
let parentVm;
for (let i = $children.length - 1; i >= 0; i--) {
parentVm = findVmByVueId($children[i], vuePid);
if (parentVm) {
return parentVm;
}
}
}
const PROP_TYPES = [String, Number, Boolean, Object, Array, null];
function parsePropType(key, type, defaultValue) {
// [String]=>String
......@@ -556,18 +683,6 @@ function initBehaviors(vueOptions, initBehavior) {
return behaviors;
}
function getValue(obj, path) {
const parts = path.split('.');
let key = parts[0];
if (key.indexOf('__$n') === 0) {
//number index
key = parseInt(key.replace('__$n', ''));
}
if (parts.length === 1) {
return obj[key];
}
return getValue(obj[key], parts.slice(1).join('.'));
}
function getExtraValue(instance, dataPathsArray) {
let context = instance;
dataPathsArray.forEach((dataPathArray) => {
......@@ -589,7 +704,7 @@ function getExtraValue(instance, dataPathsArray) {
vFor = dataPath.substr(3);
}
else {
vFor = getValue(context, dataPath);
vFor = getTarget(context, dataPath);
}
}
if (Number.isInteger(vFor)) {
......@@ -601,12 +716,12 @@ function getExtraValue(instance, dataPathsArray) {
else {
if (isArray(vFor)) {
context = vFor.find((vForItem) => {
return getValue(vForItem, propPath) === value;
return getTarget(vForItem, propPath) === value;
});
}
else if (isPlainObject(vFor)) {
context = Object.keys(vFor).find((vForKey) => {
return getValue(vFor[vForKey], propPath) === value;
return getTarget(vFor[vForKey], propPath) === value;
});
}
else {
......@@ -614,7 +729,7 @@ function getExtraValue(instance, dataPathsArray) {
}
}
if (valuePath) {
context = getValue(context, valuePath);
context = getTarget(context, valuePath);
}
}
});
......@@ -655,10 +770,10 @@ function processEventExtra(instance, extra, event) {
}
else if (dataPath.indexOf('$event.') === 0) {
// $event.target.value
extraObj['$' + index] = getValue(event, dataPath.replace('$event.', ''));
extraObj['$' + index] = getTarget(event, dataPath.replace('$event.', ''));
}
else {
extraObj['$' + index] = getValue(instance, dataPath);
extraObj['$' + index] = getTarget(instance, dataPath);
}
}
}
......@@ -795,7 +910,14 @@ function handleEvent(event) {
}
handler.once = true;
}
ret.push(handler.apply(handlerCtx, processEventArgs(this.$vm, event, eventArray[1], eventArray[2], isCustom, methodName)));
let params = processEventArgs(this.$vm, event, eventArray[1], eventArray[2], isCustom, methodName);
params = Array.isArray(params) ? params : [];
// 参数尾部增加原始事件对象用于复杂表达式内获取额外数据
if (/=\s*\S+\.eventParams\s*\|\|\s*\S+\[['"]event-params['"]\]/.test(handler.toString())) {
// eslint-disable-next-line no-sparse-arrays
params = params.concat([, , , , , , , , , , event]);
}
ret.push(handler.apply(handlerCtx, params));
}
});
}
......
import { isPlainObject, isArray, hasOwn, toNumber, isObject, isFunction, extend, NOOP, camelize } from '@vue/shared';
import { isPlainObject, hasOwn, isArray, extend, hyphenate, isObject, toNumber, isFunction, NOOP, camelize } from '@vue/shared';
const encode = encodeURIComponent;
function stringifyQuery(obj, encodeStr = encode) {
......@@ -19,6 +19,14 @@ function stringifyQuery(obj, encodeStr = encode) {
: null;
return res ? `?${res}` : '';
}
function cache(fn) {
const cache = Object.create(null);
return (str) => {
const hit = cache[str];
return hit || (cache[str] = fn(str));
};
}
const invokeArrayFns = (fns, arg) => {
let ret;
for (let i = 0; i < fns.length; i++) {
......@@ -120,6 +128,202 @@ function getEventChannel(id) {
return eventChannelStack.shift();
}
function initBehavior(options) {
return Behavior(options);
}
function initVueIds(vueIds, mpInstance) {
if (!vueIds) {
return;
}
const ids = vueIds.split(',');
const len = ids.length;
if (len === 1) {
mpInstance._$vueId = ids[0];
}
else if (len === 2) {
mpInstance._$vueId = ids[0];
mpInstance._$vuePid = ids[1];
}
}
const EXTRAS = ['externalClasses'];
function initExtraOptions(miniProgramComponentOptions, vueOptions) {
EXTRAS.forEach((name) => {
if (hasOwn(vueOptions, name)) {
miniProgramComponentOptions[name] = vueOptions[name];
}
});
}
function initWxsCallMethods(methods, wxsCallMethods) {
if (!isArray(wxsCallMethods)) {
return;
}
wxsCallMethods.forEach((callMethod) => {
methods[callMethod] = function (args) {
return this.$vm[callMethod](args);
};
});
}
function selectAllComponents(mpInstance, selector, $refs) {
const components = mpInstance.selectAllComponents(selector);
components.forEach((component) => {
const ref = component.dataset.ref;
$refs[ref] = component.$vm || component;
});
}
function initRefs(instance, mpInstance) {
Object.defineProperty(instance, 'refs', {
get() {
const $refs = {};
selectAllComponents(mpInstance, '.vue-ref', $refs);
const forComponents = mpInstance.selectAllComponents('.vue-ref-in-for');
forComponents.forEach((component) => {
const ref = component.dataset.ref;
if (!$refs[ref]) {
$refs[ref] = [];
}
$refs[ref].push(component.$vm || component);
});
return $refs;
},
});
}
function findVmByVueId(instance, vuePid) {
// 标准 vue3 中 没有 $children,定制了内核
const $children = instance.$children;
// 优先查找直属(反向查找:https://github.com/dcloudio/uni-app/issues/1200)
for (let i = $children.length - 1; i >= 0; i--) {
const childVm = $children[i];
if (childVm.$scope._$vueId === vuePid) {
return childVm;
}
}
// 反向递归查找
let parentVm;
for (let i = $children.length - 1; i >= 0; i--) {
parentVm = findVmByVueId($children[i], vuePid);
if (parentVm) {
return parentVm;
}
}
}
function getTarget(obj, path) {
const parts = path.split('.');
let key = parts[0];
if (key.indexOf('__$n') === 0) {
//number index
key = parseInt(key.replace('__$n', ''));
}
if (!obj) {
obj = {};
}
if (parts.length === 1) {
return obj[key];
}
return getTarget(obj[key], parts.slice(1).join('.'));
}
function getValue(dataPath, target) {
return getTarget(target || this, dataPath);
}
function getClass(dynamicClass, staticClass) {
return renderClass(staticClass, dynamicClass);
}
function getStyle(dynamicStyle, staticStyle) {
if (!dynamicStyle && !staticStyle) {
return '';
}
var dynamicStyleObj = normalizeStyleBinding(dynamicStyle);
var styleObj = staticStyle
? extend(staticStyle, dynamicStyleObj)
: dynamicStyleObj;
return Object.keys(styleObj)
.map(function (name) {
return hyphenate(name) + ':' + styleObj[name];
})
.join(';');
}
function toObject(arr) {
var res = {};
for (var i = 0; i < arr.length; i++) {
if (arr[i]) {
extend(res, arr[i]);
}
}
return res;
}
function normalizeStyleBinding(bindingStyle) {
if (Array.isArray(bindingStyle)) {
return toObject(bindingStyle);
}
if (typeof bindingStyle === 'string') {
return parseStyleText(bindingStyle);
}
return bindingStyle;
}
var parseStyleText = cache(function parseStyleText(cssText) {
var res = {};
var listDelimiter = /;(?![^(]*\))/g;
var propertyDelimiter = /:(.+)/;
cssText.split(listDelimiter).forEach(function (item) {
if (item) {
var tmp = item.split(propertyDelimiter);
tmp.length > 1 && (res[tmp[0].trim()] = tmp[1].trim());
}
});
return res;
});
function isDef(v) {
return v !== undefined && v !== null;
}
function renderClass(staticClass, dynamicClass) {
if (isDef(staticClass) || isDef(dynamicClass)) {
return concat(staticClass, stringifyClass(dynamicClass));
}
/* istanbul ignore next */
return '';
}
function concat(a, b) {
return a ? (b ? a + ' ' + b : a) : b || '';
}
function stringifyClass(value) {
if (Array.isArray(value)) {
return stringifyArray(value);
}
if (isObject(value)) {
return stringifyObject(value);
}
if (typeof value === 'string') {
return value;
}
/* istanbul ignore next */
return '';
}
function stringifyArray(value) {
var res = '';
var stringified;
for (var i = 0, l = value.length; i < l; i++) {
if (isDef((stringified = stringifyClass(value[i]))) && stringified !== '') {
if (res) {
res += ' ';
}
res += stringified;
}
}
return res;
}
function stringifyObject(value) {
var res = '';
for (var key in value) {
if (value[key]) {
if (res) {
res += ' ';
}
res += key;
}
}
return res;
}
function setModel(target, key, value, modifiers) {
if (isArray(modifiers)) {
if (modifiers.indexOf('trim') !== -1) {
......@@ -229,7 +433,9 @@ function initComponentInstance(instance, options) {
ctx.__set_sync = setSync;
ctx.__get_orig = getOrig;
// TODO
// ctx.__get_style = getStyle
ctx.__get_value = getValue;
ctx.__get_class = getClass;
ctx.__get_style = getStyle;
ctx.__map = map;
}
function initMocks(instance, mpInstance, mocks) {
......@@ -356,85 +562,6 @@ function initCreateApp(parseAppOptions) {
};
}
function initBehavior(options) {
return Behavior(options);
}
function initVueIds(vueIds, mpInstance) {
if (!vueIds) {
return;
}
const ids = vueIds.split(',');
const len = ids.length;
if (len === 1) {
mpInstance._$vueId = ids[0];
}
else if (len === 2) {
mpInstance._$vueId = ids[0];
mpInstance._$vuePid = ids[1];
}
}
const EXTRAS = ['externalClasses'];
function initExtraOptions(miniProgramComponentOptions, vueOptions) {
EXTRAS.forEach((name) => {
if (hasOwn(vueOptions, name)) {
miniProgramComponentOptions[name] = vueOptions[name];
}
});
}
function initWxsCallMethods(methods, wxsCallMethods) {
if (!isArray(wxsCallMethods)) {
return;
}
wxsCallMethods.forEach((callMethod) => {
methods[callMethod] = function (args) {
return this.$vm[callMethod](args);
};
});
}
function selectAllComponents(mpInstance, selector, $refs) {
const components = mpInstance.selectAllComponents(selector);
components.forEach((component) => {
const ref = component.dataset.ref;
$refs[ref] = component.$vm || component;
});
}
function initRefs(instance, mpInstance) {
Object.defineProperty(instance, 'refs', {
get() {
const $refs = {};
selectAllComponents(mpInstance, '.vue-ref', $refs);
const forComponents = mpInstance.selectAllComponents('.vue-ref-in-for');
forComponents.forEach((component) => {
const ref = component.dataset.ref;
if (!$refs[ref]) {
$refs[ref] = [];
}
$refs[ref].push(component.$vm || component);
});
return $refs;
},
});
}
function findVmByVueId(instance, vuePid) {
// 标准 vue3 中 没有 $children,定制了内核
const $children = instance.$children;
// 优先查找直属(反向查找:https://github.com/dcloudio/uni-app/issues/1200)
for (let i = $children.length - 1; i >= 0; i--) {
const childVm = $children[i];
if (childVm.$scope._$vueId === vuePid) {
return childVm;
}
}
// 反向递归查找
let parentVm;
for (let i = $children.length - 1; i >= 0; i--) {
parentVm = findVmByVueId($children[i], vuePid);
if (parentVm) {
return parentVm;
}
}
}
const PROP_TYPES = [String, Number, Boolean, Object, Array, null];
function createObserver(name) {
return function observer(newVal) {
......@@ -602,18 +729,6 @@ function applyOptions(componentOptions, vueOptions, initBehavior) {
componentOptions.behaviors = initBehaviors(vueOptions, initBehavior);
}
function getValue(obj, path) {
const parts = path.split('.');
let key = parts[0];
if (key.indexOf('__$n') === 0) {
//number index
key = parseInt(key.replace('__$n', ''));
}
if (parts.length === 1) {
return obj[key];
}
return getValue(obj[key], parts.slice(1).join('.'));
}
function getExtraValue(instance, dataPathsArray) {
let context = instance;
dataPathsArray.forEach((dataPathArray) => {
......@@ -635,7 +750,7 @@ function getExtraValue(instance, dataPathsArray) {
vFor = dataPath.substr(3);
}
else {
vFor = getValue(context, dataPath);
vFor = getTarget(context, dataPath);
}
}
if (Number.isInteger(vFor)) {
......@@ -647,12 +762,12 @@ function getExtraValue(instance, dataPathsArray) {
else {
if (isArray(vFor)) {
context = vFor.find((vForItem) => {
return getValue(vForItem, propPath) === value;
return getTarget(vForItem, propPath) === value;
});
}
else if (isPlainObject(vFor)) {
context = Object.keys(vFor).find((vForKey) => {
return getValue(vFor[vForKey], propPath) === value;
return getTarget(vFor[vForKey], propPath) === value;
});
}
else {
......@@ -660,7 +775,7 @@ function getExtraValue(instance, dataPathsArray) {
}
}
if (valuePath) {
context = getValue(context, valuePath);
context = getTarget(context, valuePath);
}
}
});
......@@ -701,10 +816,10 @@ function processEventExtra(instance, extra, event) {
}
else if (dataPath.indexOf('$event.') === 0) {
// $event.target.value
extraObj['$' + index] = getValue(event, dataPath.replace('$event.', ''));
extraObj['$' + index] = getTarget(event, dataPath.replace('$event.', ''));
}
else {
extraObj['$' + index] = getValue(instance, dataPath);
extraObj['$' + index] = getTarget(instance, dataPath);
}
}
}
......@@ -849,7 +964,14 @@ function handleEvent(event) {
}
handler.once = true;
}
ret.push(handler.apply(handlerCtx, processEventArgs(this.$vm, event, eventArray[1], eventArray[2], isCustom, methodName)));
let params = processEventArgs(this.$vm, event, eventArray[1], eventArray[2], isCustom, methodName);
params = Array.isArray(params) ? params : [];
// 参数尾部增加原始事件对象用于复杂表达式内获取额外数据
if (/=\s*\S+\.eventParams\s*\|\|\s*\S+\[['"]event-params['"]\]/.test(handler.toString())) {
// eslint-disable-next-line no-sparse-arrays
params = params.concat([, , , , , , , , , , event]);
}
ret.push(handler.apply(handlerCtx, params));
}
});
}
......
import { isPlainObject, isArray, hasOwn, toNumber, isObject, isFunction, extend, NOOP, camelize } from '@vue/shared';
import { isPlainObject, hasOwn, isArray, extend, hyphenate, isObject, toNumber, isFunction, NOOP, camelize } from '@vue/shared';
const encode = encodeURIComponent;
function stringifyQuery(obj, encodeStr = encode) {
......@@ -19,6 +19,14 @@ function stringifyQuery(obj, encodeStr = encode) {
: null;
return res ? `?${res}` : '';
}
function cache(fn) {
const cache = Object.create(null);
return (str) => {
const hit = cache[str];
return hit || (cache[str] = fn(str));
};
}
const invokeArrayFns = (fns, arg) => {
let ret;
for (let i = 0; i < fns.length; i++) {
......@@ -120,6 +128,202 @@ function getEventChannel(id) {
return eventChannelStack.shift();
}
function initBehavior(options) {
return Behavior(options);
}
function initVueIds(vueIds, mpInstance) {
if (!vueIds) {
return;
}
const ids = vueIds.split(',');
const len = ids.length;
if (len === 1) {
mpInstance._$vueId = ids[0];
}
else if (len === 2) {
mpInstance._$vueId = ids[0];
mpInstance._$vuePid = ids[1];
}
}
const EXTRAS = ['externalClasses'];
function initExtraOptions(miniProgramComponentOptions, vueOptions) {
EXTRAS.forEach((name) => {
if (hasOwn(vueOptions, name)) {
miniProgramComponentOptions[name] = vueOptions[name];
}
});
}
function initWxsCallMethods(methods, wxsCallMethods) {
if (!isArray(wxsCallMethods)) {
return;
}
wxsCallMethods.forEach((callMethod) => {
methods[callMethod] = function (args) {
return this.$vm[callMethod](args);
};
});
}
function selectAllComponents(mpInstance, selector, $refs) {
const components = mpInstance.selectAllComponents(selector);
components.forEach((component) => {
const ref = component.dataset.ref;
$refs[ref] = component.$vm || component;
});
}
function initRefs(instance, mpInstance) {
Object.defineProperty(instance, 'refs', {
get() {
const $refs = {};
selectAllComponents(mpInstance, '.vue-ref', $refs);
const forComponents = mpInstance.selectAllComponents('.vue-ref-in-for');
forComponents.forEach((component) => {
const ref = component.dataset.ref;
if (!$refs[ref]) {
$refs[ref] = [];
}
$refs[ref].push(component.$vm || component);
});
return $refs;
},
});
}
function findVmByVueId(instance, vuePid) {
// 标准 vue3 中 没有 $children,定制了内核
const $children = instance.$children;
// 优先查找直属(反向查找:https://github.com/dcloudio/uni-app/issues/1200)
for (let i = $children.length - 1; i >= 0; i--) {
const childVm = $children[i];
if (childVm.$scope._$vueId === vuePid) {
return childVm;
}
}
// 反向递归查找
let parentVm;
for (let i = $children.length - 1; i >= 0; i--) {
parentVm = findVmByVueId($children[i], vuePid);
if (parentVm) {
return parentVm;
}
}
}
function getTarget(obj, path) {
const parts = path.split('.');
let key = parts[0];
if (key.indexOf('__$n') === 0) {
//number index
key = parseInt(key.replace('__$n', ''));
}
if (!obj) {
obj = {};
}
if (parts.length === 1) {
return obj[key];
}
return getTarget(obj[key], parts.slice(1).join('.'));
}
function getValue(dataPath, target) {
return getTarget(target || this, dataPath);
}
function getClass(dynamicClass, staticClass) {
return renderClass(staticClass, dynamicClass);
}
function getStyle(dynamicStyle, staticStyle) {
if (!dynamicStyle && !staticStyle) {
return '';
}
var dynamicStyleObj = normalizeStyleBinding(dynamicStyle);
var styleObj = staticStyle
? extend(staticStyle, dynamicStyleObj)
: dynamicStyleObj;
return Object.keys(styleObj)
.map(function (name) {
return hyphenate(name) + ':' + styleObj[name];
})
.join(';');
}
function toObject(arr) {
var res = {};
for (var i = 0; i < arr.length; i++) {
if (arr[i]) {
extend(res, arr[i]);
}
}
return res;
}
function normalizeStyleBinding(bindingStyle) {
if (Array.isArray(bindingStyle)) {
return toObject(bindingStyle);
}
if (typeof bindingStyle === 'string') {
return parseStyleText(bindingStyle);
}
return bindingStyle;
}
var parseStyleText = cache(function parseStyleText(cssText) {
var res = {};
var listDelimiter = /;(?![^(]*\))/g;
var propertyDelimiter = /:(.+)/;
cssText.split(listDelimiter).forEach(function (item) {
if (item) {
var tmp = item.split(propertyDelimiter);
tmp.length > 1 && (res[tmp[0].trim()] = tmp[1].trim());
}
});
return res;
});
function isDef(v) {
return v !== undefined && v !== null;
}
function renderClass(staticClass, dynamicClass) {
if (isDef(staticClass) || isDef(dynamicClass)) {
return concat(staticClass, stringifyClass(dynamicClass));
}
/* istanbul ignore next */
return '';
}
function concat(a, b) {
return a ? (b ? a + ' ' + b : a) : b || '';
}
function stringifyClass(value) {
if (Array.isArray(value)) {
return stringifyArray(value);
}
if (isObject(value)) {
return stringifyObject(value);
}
if (typeof value === 'string') {
return value;
}
/* istanbul ignore next */
return '';
}
function stringifyArray(value) {
var res = '';
var stringified;
for (var i = 0, l = value.length; i < l; i++) {
if (isDef((stringified = stringifyClass(value[i]))) && stringified !== '') {
if (res) {
res += ' ';
}
res += stringified;
}
}
return res;
}
function stringifyObject(value) {
var res = '';
for (var key in value) {
if (value[key]) {
if (res) {
res += ' ';
}
res += key;
}
}
return res;
}
function setModel(target, key, value, modifiers) {
if (isArray(modifiers)) {
if (modifiers.indexOf('trim') !== -1) {
......@@ -229,7 +433,9 @@ function initComponentInstance(instance, options) {
ctx.__set_sync = setSync;
ctx.__get_orig = getOrig;
// TODO
// ctx.__get_style = getStyle
ctx.__get_value = getValue;
ctx.__get_class = getClass;
ctx.__get_style = getStyle;
ctx.__map = map;
}
function initMocks(instance, mpInstance, mocks) {
......@@ -356,85 +562,6 @@ function initCreateApp(parseAppOptions) {
};
}
function initBehavior(options) {
return Behavior(options);
}
function initVueIds(vueIds, mpInstance) {
if (!vueIds) {
return;
}
const ids = vueIds.split(',');
const len = ids.length;
if (len === 1) {
mpInstance._$vueId = ids[0];
}
else if (len === 2) {
mpInstance._$vueId = ids[0];
mpInstance._$vuePid = ids[1];
}
}
const EXTRAS = ['externalClasses'];
function initExtraOptions(miniProgramComponentOptions, vueOptions) {
EXTRAS.forEach((name) => {
if (hasOwn(vueOptions, name)) {
miniProgramComponentOptions[name] = vueOptions[name];
}
});
}
function initWxsCallMethods(methods, wxsCallMethods) {
if (!isArray(wxsCallMethods)) {
return;
}
wxsCallMethods.forEach((callMethod) => {
methods[callMethod] = function (args) {
return this.$vm[callMethod](args);
};
});
}
function selectAllComponents(mpInstance, selector, $refs) {
const components = mpInstance.selectAllComponents(selector);
components.forEach((component) => {
const ref = component.dataset.ref;
$refs[ref] = component.$vm || component;
});
}
function initRefs(instance, mpInstance) {
Object.defineProperty(instance, 'refs', {
get() {
const $refs = {};
selectAllComponents(mpInstance, '.vue-ref', $refs);
const forComponents = mpInstance.selectAllComponents('.vue-ref-in-for');
forComponents.forEach((component) => {
const ref = component.dataset.ref;
if (!$refs[ref]) {
$refs[ref] = [];
}
$refs[ref].push(component.$vm || component);
});
return $refs;
},
});
}
function findVmByVueId(instance, vuePid) {
// 标准 vue3 中 没有 $children,定制了内核
const $children = instance.$children;
// 优先查找直属(反向查找:https://github.com/dcloudio/uni-app/issues/1200)
for (let i = $children.length - 1; i >= 0; i--) {
const childVm = $children[i];
if (childVm.$scope._$vueId === vuePid) {
return childVm;
}
}
// 反向递归查找
let parentVm;
for (let i = $children.length - 1; i >= 0; i--) {
parentVm = findVmByVueId($children[i], vuePid);
if (parentVm) {
return parentVm;
}
}
}
const PROP_TYPES = [String, Number, Boolean, Object, Array, null];
function createObserver(name) {
return function observer(newVal) {
......@@ -591,18 +718,6 @@ function applyOptions(componentOptions, vueOptions, initBehavior) {
componentOptions.behaviors = initBehaviors(vueOptions, initBehavior);
}
function getValue(obj, path) {
const parts = path.split('.');
let key = parts[0];
if (key.indexOf('__$n') === 0) {
//number index
key = parseInt(key.replace('__$n', ''));
}
if (parts.length === 1) {
return obj[key];
}
return getValue(obj[key], parts.slice(1).join('.'));
}
function getExtraValue(instance, dataPathsArray) {
let context = instance;
dataPathsArray.forEach((dataPathArray) => {
......@@ -624,7 +739,7 @@ function getExtraValue(instance, dataPathsArray) {
vFor = dataPath.substr(3);
}
else {
vFor = getValue(context, dataPath);
vFor = getTarget(context, dataPath);
}
}
if (Number.isInteger(vFor)) {
......@@ -636,12 +751,12 @@ function getExtraValue(instance, dataPathsArray) {
else {
if (isArray(vFor)) {
context = vFor.find((vForItem) => {
return getValue(vForItem, propPath) === value;
return getTarget(vForItem, propPath) === value;
});
}
else if (isPlainObject(vFor)) {
context = Object.keys(vFor).find((vForKey) => {
return getValue(vFor[vForKey], propPath) === value;
return getTarget(vFor[vForKey], propPath) === value;
});
}
else {
......@@ -649,7 +764,7 @@ function getExtraValue(instance, dataPathsArray) {
}
}
if (valuePath) {
context = getValue(context, valuePath);
context = getTarget(context, valuePath);
}
}
});
......@@ -690,10 +805,10 @@ function processEventExtra(instance, extra, event) {
}
else if (dataPath.indexOf('$event.') === 0) {
// $event.target.value
extraObj['$' + index] = getValue(event, dataPath.replace('$event.', ''));
extraObj['$' + index] = getTarget(event, dataPath.replace('$event.', ''));
}
else {
extraObj['$' + index] = getValue(instance, dataPath);
extraObj['$' + index] = getTarget(instance, dataPath);
}
}
}
......@@ -830,7 +945,14 @@ function handleEvent(event) {
}
handler.once = true;
}
ret.push(handler.apply(handlerCtx, processEventArgs(this.$vm, event, eventArray[1], eventArray[2], isCustom, methodName)));
let params = processEventArgs(this.$vm, event, eventArray[1], eventArray[2], isCustom, methodName);
params = Array.isArray(params) ? params : [];
// 参数尾部增加原始事件对象用于复杂表达式内获取额外数据
if (/=\s*\S+\.eventParams\s*\|\|\s*\S+\[['"]event-params['"]\]/.test(handler.toString())) {
// eslint-disable-next-line no-sparse-arrays
params = params.concat([, , , , , , , , , , event]);
}
ret.push(handler.apply(handlerCtx, params));
}
});
}
......
import { isPlainObject, isArray, hasOwn, toNumber, isObject, isFunction, extend, NOOP, camelize } from '@vue/shared';
import { isPlainObject, hasOwn, isArray, extend, hyphenate, isObject, toNumber, isFunction, NOOP, camelize } from '@vue/shared';
const encode = encodeURIComponent;
function stringifyQuery(obj, encodeStr = encode) {
......@@ -19,6 +19,14 @@ function stringifyQuery(obj, encodeStr = encode) {
: null;
return res ? `?${res}` : '';
}
function cache(fn) {
const cache = Object.create(null);
return (str) => {
const hit = cache[str];
return hit || (cache[str] = fn(str));
};
}
const invokeArrayFns = (fns, arg) => {
let ret;
for (let i = 0; i < fns.length; i++) {
......@@ -120,6 +128,183 @@ function getEventChannel(id) {
return eventChannelStack.shift();
}
function initBehavior(options) {
return Behavior(options);
}
function initVueIds(vueIds, mpInstance) {
if (!vueIds) {
return;
}
const ids = vueIds.split(',');
const len = ids.length;
if (len === 1) {
mpInstance._$vueId = ids[0];
}
else if (len === 2) {
mpInstance._$vueId = ids[0];
mpInstance._$vuePid = ids[1];
}
}
const EXTRAS = ['externalClasses'];
function initExtraOptions(miniProgramComponentOptions, vueOptions) {
EXTRAS.forEach((name) => {
if (hasOwn(vueOptions, name)) {
miniProgramComponentOptions[name] = vueOptions[name];
}
});
}
function initWxsCallMethods(methods, wxsCallMethods) {
if (!isArray(wxsCallMethods)) {
return;
}
wxsCallMethods.forEach((callMethod) => {
methods[callMethod] = function (args) {
return this.$vm[callMethod](args);
};
});
}
function selectAllComponents(mpInstance, selector, $refs) {
const components = mpInstance.selectAllComponents(selector);
components.forEach((component) => {
const ref = component.dataset.ref;
$refs[ref] = component.$vm || component;
});
}
function initRefs(instance, mpInstance) {
Object.defineProperty(instance, 'refs', {
get() {
const $refs = {};
selectAllComponents(mpInstance, '.vue-ref', $refs);
const forComponents = mpInstance.selectAllComponents('.vue-ref-in-for');
forComponents.forEach((component) => {
const ref = component.dataset.ref;
if (!$refs[ref]) {
$refs[ref] = [];
}
$refs[ref].push(component.$vm || component);
});
return $refs;
},
});
}
function getTarget(obj, path) {
const parts = path.split('.');
let key = parts[0];
if (key.indexOf('__$n') === 0) {
//number index
key = parseInt(key.replace('__$n', ''));
}
if (!obj) {
obj = {};
}
if (parts.length === 1) {
return obj[key];
}
return getTarget(obj[key], parts.slice(1).join('.'));
}
function getValue(dataPath, target) {
return getTarget(target || this, dataPath);
}
function getClass(dynamicClass, staticClass) {
return renderClass(staticClass, dynamicClass);
}
function getStyle(dynamicStyle, staticStyle) {
if (!dynamicStyle && !staticStyle) {
return '';
}
var dynamicStyleObj = normalizeStyleBinding(dynamicStyle);
var styleObj = staticStyle
? extend(staticStyle, dynamicStyleObj)
: dynamicStyleObj;
return Object.keys(styleObj)
.map(function (name) {
return hyphenate(name) + ':' + styleObj[name];
})
.join(';');
}
function toObject(arr) {
var res = {};
for (var i = 0; i < arr.length; i++) {
if (arr[i]) {
extend(res, arr[i]);
}
}
return res;
}
function normalizeStyleBinding(bindingStyle) {
if (Array.isArray(bindingStyle)) {
return toObject(bindingStyle);
}
if (typeof bindingStyle === 'string') {
return parseStyleText(bindingStyle);
}
return bindingStyle;
}
var parseStyleText = cache(function parseStyleText(cssText) {
var res = {};
var listDelimiter = /;(?![^(]*\))/g;
var propertyDelimiter = /:(.+)/;
cssText.split(listDelimiter).forEach(function (item) {
if (item) {
var tmp = item.split(propertyDelimiter);
tmp.length > 1 && (res[tmp[0].trim()] = tmp[1].trim());
}
});
return res;
});
function isDef(v) {
return v !== undefined && v !== null;
}
function renderClass(staticClass, dynamicClass) {
if (isDef(staticClass) || isDef(dynamicClass)) {
return concat(staticClass, stringifyClass(dynamicClass));
}
/* istanbul ignore next */
return '';
}
function concat(a, b) {
return a ? (b ? a + ' ' + b : a) : b || '';
}
function stringifyClass(value) {
if (Array.isArray(value)) {
return stringifyArray(value);
}
if (isObject(value)) {
return stringifyObject(value);
}
if (typeof value === 'string') {
return value;
}
/* istanbul ignore next */
return '';
}
function stringifyArray(value) {
var res = '';
var stringified;
for (var i = 0, l = value.length; i < l; i++) {
if (isDef((stringified = stringifyClass(value[i]))) && stringified !== '') {
if (res) {
res += ' ';
}
res += stringified;
}
}
return res;
}
function stringifyObject(value) {
var res = '';
for (var key in value) {
if (value[key]) {
if (res) {
res += ' ';
}
res += key;
}
}
return res;
}
function setModel(target, key, value, modifiers) {
if (isArray(modifiers)) {
if (modifiers.indexOf('trim') !== -1) {
......@@ -229,7 +414,9 @@ function initComponentInstance(instance, options) {
ctx.__set_sync = setSync;
ctx.__get_orig = getOrig;
// TODO
// ctx.__get_style = getStyle
ctx.__get_value = getValue;
ctx.__get_class = getClass;
ctx.__get_style = getStyle;
ctx.__map = map;
}
function initMocks(instance, mpInstance, mocks) {
......@@ -356,66 +543,6 @@ function initCreateApp(parseAppOptions) {
};
}
function initBehavior(options) {
return Behavior(options);
}
function initVueIds(vueIds, mpInstance) {
if (!vueIds) {
return;
}
const ids = vueIds.split(',');
const len = ids.length;
if (len === 1) {
mpInstance._$vueId = ids[0];
}
else if (len === 2) {
mpInstance._$vueId = ids[0];
mpInstance._$vuePid = ids[1];
}
}
const EXTRAS = ['externalClasses'];
function initExtraOptions(miniProgramComponentOptions, vueOptions) {
EXTRAS.forEach((name) => {
if (hasOwn(vueOptions, name)) {
miniProgramComponentOptions[name] = vueOptions[name];
}
});
}
function initWxsCallMethods(methods, wxsCallMethods) {
if (!isArray(wxsCallMethods)) {
return;
}
wxsCallMethods.forEach((callMethod) => {
methods[callMethod] = function (args) {
return this.$vm[callMethod](args);
};
});
}
function selectAllComponents(mpInstance, selector, $refs) {
const components = mpInstance.selectAllComponents(selector);
components.forEach((component) => {
const ref = component.dataset.ref;
$refs[ref] = component.$vm || component;
});
}
function initRefs(instance, mpInstance) {
Object.defineProperty(instance, 'refs', {
get() {
const $refs = {};
selectAllComponents(mpInstance, '.vue-ref', $refs);
const forComponents = mpInstance.selectAllComponents('.vue-ref-in-for');
forComponents.forEach((component) => {
const ref = component.dataset.ref;
if (!$refs[ref]) {
$refs[ref] = [];
}
$refs[ref].push(component.$vm || component);
});
return $refs;
},
});
}
const PROP_TYPES = [String, Number, Boolean, Object, Array, null];
function createObserver(name) {
return function observer(newVal) {
......@@ -572,18 +699,6 @@ function applyOptions(componentOptions, vueOptions, initBehavior) {
componentOptions.behaviors = initBehaviors(vueOptions, initBehavior);
}
function getValue(obj, path) {
const parts = path.split('.');
let key = parts[0];
if (key.indexOf('__$n') === 0) {
//number index
key = parseInt(key.replace('__$n', ''));
}
if (parts.length === 1) {
return obj[key];
}
return getValue(obj[key], parts.slice(1).join('.'));
}
function getExtraValue(instance, dataPathsArray) {
let context = instance;
dataPathsArray.forEach((dataPathArray) => {
......@@ -605,7 +720,7 @@ function getExtraValue(instance, dataPathsArray) {
vFor = dataPath.substr(3);
}
else {
vFor = getValue(context, dataPath);
vFor = getTarget(context, dataPath);
}
}
if (Number.isInteger(vFor)) {
......@@ -617,12 +732,12 @@ function getExtraValue(instance, dataPathsArray) {
else {
if (isArray(vFor)) {
context = vFor.find((vForItem) => {
return getValue(vForItem, propPath) === value;
return getTarget(vForItem, propPath) === value;
});
}
else if (isPlainObject(vFor)) {
context = Object.keys(vFor).find((vForKey) => {
return getValue(vFor[vForKey], propPath) === value;
return getTarget(vFor[vForKey], propPath) === value;
});
}
else {
......@@ -630,7 +745,7 @@ function getExtraValue(instance, dataPathsArray) {
}
}
if (valuePath) {
context = getValue(context, valuePath);
context = getTarget(context, valuePath);
}
}
});
......@@ -671,10 +786,10 @@ function processEventExtra(instance, extra, event) {
}
else if (dataPath.indexOf('$event.') === 0) {
// $event.target.value
extraObj['$' + index] = getValue(event, dataPath.replace('$event.', ''));
extraObj['$' + index] = getTarget(event, dataPath.replace('$event.', ''));
}
else {
extraObj['$' + index] = getValue(instance, dataPath);
extraObj['$' + index] = getTarget(instance, dataPath);
}
}
}
......@@ -811,7 +926,14 @@ function handleEvent(event) {
}
handler.once = true;
}
ret.push(handler.apply(handlerCtx, processEventArgs(this.$vm, event, eventArray[1], eventArray[2], isCustom, methodName)));
let params = processEventArgs(this.$vm, event, eventArray[1], eventArray[2], isCustom, methodName);
params = Array.isArray(params) ? params : [];
// 参数尾部增加原始事件对象用于复杂表达式内获取额外数据
if (/=\s*\S+\.eventParams\s*\|\|\s*\S+\[['"]event-params['"]\]/.test(handler.toString())) {
// eslint-disable-next-line no-sparse-arrays
params = params.concat([, , , , , , , , , , event]);
}
ret.push(handler.apply(handlerCtx, params));
}
});
}
......
......@@ -94,6 +94,7 @@ module.exports = function chainWebpack (platformOptions, vueOptions, api) {
process.env.UNI_PLATFORM === 'quickapp-webview'
const defines = {
// UNI_ENV好像没用
__UNI_FEATURE_PROMISE__: JSON.stringify(false),
'process.env.UNI_ENV': JSON.stringify(process.env.UNI_PLATFORM),
'process.env.UNI_APP_ID': JSON.stringify(process.env.UNI_APP_ID),
'process.env.UNI_APP_NAME': JSON.stringify(process.env.UNI_APP_NAME),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册