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

fix(mp): defineExpose (#3180)

上级 b88df708
......@@ -9636,6 +9636,7 @@ function useMovableViewState(props2, trigger, rootRef) {
}
}
function __handleTouchMove(event) {
event.stopPropagation();
if (!_isScaling && !props2.disabled && _isTouching) {
let x = _translateX;
let y = _translateY;
......
import { isPlainObject, hasOwn, isArray, capitalize, isFunction, extend, isString, camelize } from '@vue/shared';
import { injectHook, ref, getExposeProxy, findComponentPropsData, toRaw, updateProps, invalidateJob, EMPTY_OBJ, isRef, setTemplateRef, pruneComponentPropsCache } from 'vue';
import { injectHook, ref, findComponentPropsData, toRaw, updateProps, invalidateJob, getExposeProxy, EMPTY_OBJ, isRef, setTemplateRef, pruneComponentPropsCache } from 'vue';
// quickapp-webview 不能使用 default 作为插槽名称
const SLOT_DEFAULT_NAME = 'd';
......@@ -175,8 +175,6 @@ function initBaseInstance(instance, options) {
if (__VUE_OPTIONS_API__) {
ctx._self = {};
}
// $vm
ctx.$scope.$vm = instance.proxy;
// slots
instance.slots = {};
if (isArray(options.slots) && options.slots.length) {
......@@ -434,13 +432,6 @@ function initWxsCallMethods(methods, wxsCallMethods) {
};
});
}
function findRefValue(component) {
const vm = component.$vm;
if (vm) {
return getExposeProxy(vm.$) || vm;
}
return component;
}
function findVmByVueId(instance, vuePid) {
// 标准 vue3 中 没有 $children,定制了内核
const $children = instance.$children;
......@@ -610,7 +601,8 @@ function $createComponent(initialVNode, options) {
if (!$createComponentFn) {
$createComponentFn = getApp().$vm.$createComponent;
}
return $createComponentFn(initialVNode, options);
const proxy = $createComponentFn(initialVNode, options);
return getExposeProxy(proxy.$) || proxy;
}
function $destroyComponent(instance) {
if (!$destroyComponentFn) {
......@@ -766,7 +758,7 @@ function handleRef(ref) {
const instance = this.$vm.$;
const refs = instance.refs === EMPTY_OBJ ? (instance.refs = {}) : instance.refs;
const { setupState } = instance;
const refValue = findRefValue(ref);
const refValue = ref.$vm;
if (refName) {
if (isString(refName)) {
refs[refName] = refValue;
......
......@@ -17,7 +17,6 @@ import {
initComponentInstance,
CreateComponentOptions,
updateComponentProps,
findRefValue,
findPropsData,
} from '@dcloudio/uni-mp-core'
......@@ -145,7 +144,7 @@ export function handleRef(this: MPComponentInstance, ref: MPComponentInstance) {
instance.refs === EMPTY_OBJ ? (instance.refs = {}) : instance.refs
const { setupState } = instance
const refValue = findRefValue(ref as any)
const refValue = ref.$vm
if (refName) {
if (isString(refName)) {
refs[refName] = refValue
......
import { isPlainObject, isArray, hasOwn, isFunction, extend, camelize } from '@vue/shared';
import { injectHook, ref, nextTick, getExposeProxy, findComponentPropsData, toRaw, updateProps, invalidateJob, pruneComponentPropsCache } from 'vue';
import { injectHook, ref, nextTick, findComponentPropsData, toRaw, updateProps, invalidateJob, getExposeProxy, pruneComponentPropsCache } from 'vue';
// lifecycle
// App and Page
......@@ -241,8 +241,6 @@ function initBaseInstance(instance, options) {
if (__VUE_OPTIONS_API__) {
ctx._self = {};
}
// $vm
ctx.$scope.$vm = instance.proxy;
// slots
instance.slots = {};
if (isArray(options.slots) && options.slots.length) {
......@@ -509,16 +507,9 @@ function selectAllComponents(mpInstance, selector, $refs) {
const components = mpInstance.selectAllComponents(selector);
components.forEach((component) => {
const ref = component.properties.uR;
$refs[ref] = findRefValue(component);
$refs[ref] = component.$vm || component;
});
}
function findRefValue(component) {
const vm = component.$vm;
if (vm) {
return getExposeProxy(vm.$) || vm;
}
return component;
}
function initRefs(instance, mpInstance) {
Object.defineProperty(instance, 'refs', {
get() {
......@@ -533,7 +524,7 @@ function initRefs(instance, mpInstance) {
if (!$refs[ref]) {
$refs[ref] = [];
}
$refs[ref].push(findRefValue(component));
$refs[ref].push(component.$vm || component);
});
return $refs;
},
......@@ -881,7 +872,8 @@ function $createComponent(initialVNode, options) {
if (!$createComponentFn) {
$createComponentFn = getApp().$vm.$createComponent;
}
return $createComponentFn(initialVNode, options);
const proxy = $createComponentFn(initialVNode, options);
return getExposeProxy(proxy.$) || proxy;
}
function $destroyComponent(instance) {
if (!$destroyComponentFn) {
......
......@@ -40,7 +40,6 @@ export {
fixProperties,
nextSetDataTick,
initSetRef,
findRefValue,
} from './runtime/util'
// protocols
......
import { extend } from '@vue/shared'
import { ComponentOptions, ComponentPublicInstance } from 'vue'
// @ts-expect-error
import { getExposeProxy } from 'vue'
import { initExtraOptions, initWxsCallMethods, initBehavior } from './util'
......@@ -149,7 +151,11 @@ export function $createComponent(
if (!$createComponentFn) {
$createComponentFn = getApp().$vm.$createComponent
}
return $createComponentFn(initialVNode, options)
const proxy = $createComponentFn(
initialVNode,
options
) as ComponentPublicInstance
return getExposeProxy(proxy.$) || proxy
}
export function $destroyComponent(instance: ComponentPublicInstance) {
......
......@@ -70,9 +70,6 @@ export function initBaseInstance(
ctx._self = {}
}
// $vm
ctx.$scope.$vm = (instance as any).proxy!
// slots
instance.slots = {}
if (isArray(options.slots) && options.slots.length) {
......
......@@ -4,9 +4,9 @@ import {
ComponentInternalInstance,
ComponentPublicInstance,
nextTick,
markRaw,
proxyRefs,
} from 'vue'
// @ts-ignore
import { getExposeProxy } from 'vue'
import { MPComponentInstance, MPComponentOptions } from './component'
......@@ -67,18 +67,10 @@ function selectAllComponents(
const components = mpInstance.selectAllComponents(selector)
components.forEach((component) => {
const ref = component.properties.uR
$refs[ref] = findRefValue(component as MPComponentInstance)
$refs[ref] = component.$vm || component
})
}
export function findRefValue(component: MPComponentInstance) {
const vm = component.$vm
if (vm) {
return getExposeProxy(vm.$) || vm
}
return component
}
export function initRefs(
instance: ComponentInternalInstance,
mpInstance: MPComponentInstance
......@@ -96,7 +88,7 @@ export function initRefs(
if (!$refs[ref]) {
$refs[ref] = []
}
$refs[ref].push(findRefValue(component as MPComponentInstance))
$refs[ref].push(component.$vm || component)
})
return $refs
},
......
import { isPlainObject, isArray, hasOwn, isFunction, extend, camelize } from '@vue/shared';
import { injectHook, ref, nextTick, getExposeProxy, findComponentPropsData, toRaw, updateProps, invalidateJob, pruneComponentPropsCache } from 'vue';
import { injectHook, ref, nextTick, findComponentPropsData, toRaw, updateProps, invalidateJob, getExposeProxy, pruneComponentPropsCache } from 'vue';
const ON_READY$1 = 'onReady';
......@@ -236,8 +236,6 @@ function initBaseInstance(instance, options) {
if (__VUE_OPTIONS_API__) {
ctx._self = {};
}
// $vm
ctx.$scope.$vm = instance.proxy;
// slots
instance.slots = {};
if (isArray(options.slots) && options.slots.length) {
......@@ -504,16 +502,9 @@ function selectAllComponents(mpInstance, selector, $refs) {
const components = mpInstance.selectAllComponents(selector);
components.forEach((component) => {
const ref = component.properties.uR;
$refs[ref] = findRefValue(component);
$refs[ref] = component.$vm || component;
});
}
function findRefValue(component) {
const vm = component.$vm;
if (vm) {
return getExposeProxy(vm.$) || vm;
}
return component;
}
function initRefs(instance, mpInstance) {
Object.defineProperty(instance, 'refs', {
get() {
......@@ -528,7 +519,7 @@ function initRefs(instance, mpInstance) {
if (!$refs[ref]) {
$refs[ref] = [];
}
$refs[ref].push(findRefValue(component));
$refs[ref].push(component.$vm || component);
});
return $refs;
},
......@@ -865,7 +856,8 @@ function $createComponent(initialVNode, options) {
if (!$createComponentFn) {
$createComponentFn = getApp().$vm.$createComponent;
}
return $createComponentFn(initialVNode, options);
const proxy = $createComponentFn(initialVNode, options);
return getExposeProxy(proxy.$) || proxy;
}
function $destroyComponent(instance) {
if (!$destroyComponentFn) {
......
import { isPlainObject, isArray, hasOwn, isFunction, extend, camelize, isObject } from '@vue/shared';
import { injectHook, ref, nextTick, getExposeProxy, findComponentPropsData, toRaw, updateProps, invalidateJob, pruneComponentPropsCache } from 'vue';
import { injectHook, ref, nextTick, findComponentPropsData, toRaw, updateProps, invalidateJob, getExposeProxy, pruneComponentPropsCache } from 'vue';
const ON_READY$1 = 'onReady';
......@@ -232,8 +232,6 @@ function initBaseInstance(instance, options) {
if (__VUE_OPTIONS_API__) {
ctx._self = {};
}
// $vm
ctx.$scope.$vm = instance.proxy;
// slots
instance.slots = {};
if (isArray(options.slots) && options.slots.length) {
......@@ -503,16 +501,9 @@ function selectAllComponents(mpInstance, selector, $refs) {
const components = mpInstance.selectAllComponents(selector);
components.forEach((component) => {
const ref = component.properties.uR;
$refs[ref] = findRefValue(component);
$refs[ref] = component.$vm || component;
});
}
function findRefValue(component) {
const vm = component.$vm;
if (vm) {
return getExposeProxy(vm.$) || vm;
}
return component;
}
function initRefs(instance, mpInstance) {
Object.defineProperty(instance, 'refs', {
get() {
......@@ -527,7 +518,7 @@ function initRefs(instance, mpInstance) {
if (!$refs[ref]) {
$refs[ref] = [];
}
$refs[ref].push(findRefValue(component));
$refs[ref].push(component.$vm || component);
});
return $refs;
},
......@@ -838,7 +829,8 @@ function $createComponent(initialVNode, options) {
if (!$createComponentFn) {
$createComponentFn = getApp().$vm.$createComponent;
}
return $createComponentFn(initialVNode, options);
const proxy = $createComponentFn(initialVNode, options);
return getExposeProxy(proxy.$) || proxy;
}
function $destroyComponent(instance) {
if (!$destroyComponentFn) {
......
import { isPlainObject, isArray, hasOwn, isFunction, extend, camelize } from '@vue/shared';
import { injectHook, ref, getExposeProxy, findComponentPropsData, toRaw, updateProps, invalidateJob, pruneComponentPropsCache } from 'vue';
import { injectHook, ref, findComponentPropsData, toRaw, updateProps, invalidateJob, getExposeProxy, pruneComponentPropsCache } from 'vue';
const ON_READY$1 = 'onReady';
......@@ -232,8 +232,6 @@ function initBaseInstance(instance, options) {
if (__VUE_OPTIONS_API__) {
ctx._self = {};
}
// $vm
ctx.$scope.$vm = instance.proxy;
// slots
instance.slots = {};
if (isArray(options.slots) && options.slots.length) {
......@@ -500,16 +498,9 @@ function selectAllComponents(mpInstance, selector, $refs) {
const components = mpInstance.selectAllComponents(selector);
components.forEach((component) => {
const ref = component.properties.uR;
$refs[ref] = findRefValue(component);
$refs[ref] = component.$vm || component;
});
}
function findRefValue(component) {
const vm = component.$vm;
if (vm) {
return getExposeProxy(vm.$) || vm;
}
return component;
}
function initRefs(instance, mpInstance) {
Object.defineProperty(instance, 'refs', {
get() {
......@@ -524,7 +515,7 @@ function initRefs(instance, mpInstance) {
if (!$refs[ref]) {
$refs[ref] = [];
}
$refs[ref].push(findRefValue(component));
$refs[ref].push(component.$vm || component);
});
return $refs;
},
......@@ -827,7 +818,8 @@ function $createComponent(initialVNode, options) {
if (!$createComponentFn) {
$createComponentFn = getApp().$vm.$createComponent;
}
return $createComponentFn(initialVNode, options);
const proxy = $createComponentFn(initialVNode, options);
return getExposeProxy(proxy.$) || proxy;
}
function $destroyComponent(instance) {
if (!$destroyComponentFn) {
......
import { isPlainObject, isArray, hasOwn, isFunction, extend, camelize, isObject } from '@vue/shared';
import { injectHook, ref, nextTick, getExposeProxy, findComponentPropsData, toRaw, updateProps, invalidateJob, pruneComponentPropsCache } from 'vue';
import { injectHook, ref, nextTick, findComponentPropsData, toRaw, updateProps, invalidateJob, getExposeProxy, pruneComponentPropsCache } from 'vue';
const ON_READY$1 = 'onReady';
......@@ -232,8 +232,6 @@ function initBaseInstance(instance, options) {
if (__VUE_OPTIONS_API__) {
ctx._self = {};
}
// $vm
ctx.$scope.$vm = instance.proxy;
// slots
instance.slots = {};
if (isArray(options.slots) && options.slots.length) {
......@@ -503,16 +501,9 @@ function selectAllComponents(mpInstance, selector, $refs) {
const components = mpInstance.selectAllComponents(selector);
components.forEach((component) => {
const ref = component.properties.uR;
$refs[ref] = findRefValue(component);
$refs[ref] = component.$vm || component;
});
}
function findRefValue(component) {
const vm = component.$vm;
if (vm) {
return getExposeProxy(vm.$) || vm;
}
return component;
}
function initRefs(instance, mpInstance) {
Object.defineProperty(instance, 'refs', {
get() {
......@@ -527,7 +518,7 @@ function initRefs(instance, mpInstance) {
if (!$refs[ref]) {
$refs[ref] = [];
}
$refs[ref].push(findRefValue(component));
$refs[ref].push(component.$vm || component);
});
return $refs;
},
......@@ -838,7 +829,8 @@ function $createComponent(initialVNode, options) {
if (!$createComponentFn) {
$createComponentFn = getApp().$vm.$createComponent;
}
return $createComponentFn(initialVNode, options);
const proxy = $createComponentFn(initialVNode, options);
return getExposeProxy(proxy.$) || proxy;
}
function $destroyComponent(instance) {
if (!$destroyComponentFn) {
......
......@@ -3520,9 +3520,11 @@ function getExposeProxy(instance) {
if (key in target) {
return target[key];
}
else if (key in publicPropertiesMap) {
return publicPropertiesMap[key](instance);
}
// fixed by xxxxxx 框架内部需要访问很多非 public 属性,暂不做限制
return instance.proxy[key];
// else if (key in publicPropertiesMap) {
// return publicPropertiesMap[key](instance)
// }
}
})));
}
......@@ -4812,7 +4814,7 @@ function mountComponent(initialVNode, options) {
if (__VUE_OPTIONS_API__) {
// $children
if (options.parentComponent && instance.proxy) {
options.parentComponent.ctx.$children.push(instance.proxy);
options.parentComponent.ctx.$children.push(getExposeProxy(instance) || instance.proxy);
}
}
setupRenderEffect(instance);
......
......@@ -3520,9 +3520,11 @@ function getExposeProxy(instance) {
if (key in target) {
return target[key];
}
else if (key in publicPropertiesMap) {
return publicPropertiesMap[key](instance);
}
// fixed by xxxxxx 框架内部需要访问很多非 public 属性,暂不做限制
return instance.proxy[key];
// else if (key in publicPropertiesMap) {
// return publicPropertiesMap[key](instance)
// }
}
})));
}
......@@ -4812,7 +4814,7 @@ function mountComponent(initialVNode, options) {
if (__VUE_OPTIONS_API__) {
// $children
if (options.parentComponent && instance.proxy) {
options.parentComponent.ctx.$children.push(instance.proxy);
options.parentComponent.ctx.$children.push(getExposeProxy(instance) || instance.proxy);
}
}
setupRenderEffect(instance);
......
import { ComponentInternalInstance, getCurrentInstance, Ref } from 'vue'
// @ts-ignore
import { getExposeProxy } from 'vue'
type VNodeRef =
| string
......
import { isPlainObject, isArray, hasOwn, isFunction, extend, camelize } from '@vue/shared';
import { injectHook, ref, getExposeProxy, findComponentPropsData, toRaw, updateProps, invalidateJob, pruneComponentPropsCache } from 'vue';
import { injectHook, ref, findComponentPropsData, toRaw, updateProps, invalidateJob, getExposeProxy, pruneComponentPropsCache } from 'vue';
// quickapp-webview 不能使用 default 作为插槽名称
const SLOT_DEFAULT_NAME = 'd';
......@@ -104,8 +104,6 @@ function initBaseInstance(instance, options) {
if (__VUE_OPTIONS_API__) {
ctx._self = {};
}
// $vm
ctx.$scope.$vm = instance.proxy;
// slots
instance.slots = {};
if (isArray(options.slots) && options.slots.length) {
......@@ -372,16 +370,9 @@ function selectAllComponents(mpInstance, selector, $refs) {
const components = mpInstance.selectAllComponents(selector);
components.forEach((component) => {
const ref = component.properties.uR;
$refs[ref] = findRefValue(component);
$refs[ref] = component.$vm || component;
});
}
function findRefValue(component) {
const vm = component.$vm;
if (vm) {
return getExposeProxy(vm.$) || vm;
}
return component;
}
function initRefs(instance, mpInstance) {
Object.defineProperty(instance, 'refs', {
get() {
......@@ -396,7 +387,7 @@ function initRefs(instance, mpInstance) {
if (!$refs[ref]) {
$refs[ref] = [];
}
$refs[ref].push(findRefValue(component));
$refs[ref].push(component.$vm || component);
});
return $refs;
},
......@@ -699,7 +690,8 @@ function $createComponent(initialVNode, options) {
if (!$createComponentFn) {
$createComponentFn = getApp().$vm.$createComponent;
}
return $createComponentFn(initialVNode, options);
const proxy = $createComponentFn(initialVNode, options);
return getExposeProxy(proxy.$) || proxy;
}
function $destroyComponent(instance) {
if (!$destroyComponentFn) {
......
import { isPlainObject, isArray, hasOwn, isFunction, extend, camelize, isObject } from '@vue/shared';
import { injectHook, ref, nextTick, getExposeProxy, findComponentPropsData, toRaw, updateProps, invalidateJob, pruneComponentPropsCache } from 'vue';
import { injectHook, ref, nextTick, findComponentPropsData, toRaw, updateProps, invalidateJob, getExposeProxy, pruneComponentPropsCache } from 'vue';
const ON_READY$1 = 'onReady';
......@@ -232,8 +232,6 @@ function initBaseInstance(instance, options) {
if (__VUE_OPTIONS_API__) {
ctx._self = {};
}
// $vm
ctx.$scope.$vm = instance.proxy;
// slots
instance.slots = {};
if (isArray(options.slots) && options.slots.length) {
......@@ -500,16 +498,9 @@ function selectAllComponents(mpInstance, selector, $refs) {
const components = mpInstance.selectAllComponents(selector);
components.forEach((component) => {
const ref = component.properties.uR;
$refs[ref] = findRefValue(component);
$refs[ref] = component.$vm || component;
});
}
function findRefValue(component) {
const vm = component.$vm;
if (vm) {
return getExposeProxy(vm.$) || vm;
}
return component;
}
function initRefs(instance, mpInstance) {
Object.defineProperty(instance, 'refs', {
get() {
......@@ -524,7 +515,7 @@ function initRefs(instance, mpInstance) {
if (!$refs[ref]) {
$refs[ref] = [];
}
$refs[ref].push(findRefValue(component));
$refs[ref].push(component.$vm || component);
});
return $refs;
},
......@@ -816,7 +807,8 @@ function $createComponent(initialVNode, options) {
if (!$createComponentFn) {
$createComponentFn = getApp().$vm.$createComponent;
}
return $createComponentFn(initialVNode, options);
const proxy = $createComponentFn(initialVNode, options);
return getExposeProxy(proxy.$) || proxy;
}
function $destroyComponent(instance) {
if (!$destroyComponentFn) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册