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

build(deps): bump vite from 2.0.0-beta.61 to 2.0.1

上级 2f45ca4b
此差异已折叠。
var attrs = ["top", "left", "right", "bottom"];
var inited;
var elementComputedStyle = {};
var support;
function getSupport() {
if (!("CSS" in window) || typeof CSS.supports != "function") {
support = "";
} else if (CSS.supports("top: env(safe-area-inset-top)")) {
support = "env";
} else if (CSS.supports("top: constant(safe-area-inset-top)")) {
support = "constant";
} else {
support = "";
}
return support;
}
function init() {
support = typeof support === "string" ? support : getSupport();
if (!support) {
attrs.forEach(function(attr) {
elementComputedStyle[attr] = 0;
});
return;
}
function setStyle(el, style) {
var elStyle = el.style;
Object.keys(style).forEach(function(key) {
var val = style[key];
elStyle[key] = val;
});
}
var cbs = [];
function parentReady(callback) {
if (callback) {
cbs.push(callback);
} else {
cbs.forEach(function(cb) {
cb();
});
}
}
var passiveEvents = false;
try {
var opts = Object.defineProperty({}, "passive", {
get: function() {
passiveEvents = {passive: true};
}
});
window.addEventListener("test", null, opts);
} catch (e) {
}
function addChild(parent, attr) {
var a1 = document.createElement("div");
var a2 = document.createElement("div");
var a1Children = document.createElement("div");
var a2Children = document.createElement("div");
var W = 100;
var MAX = 1e4;
var aStyle = {
position: "absolute",
width: W + "px",
height: "200px",
boxSizing: "border-box",
overflow: "hidden",
paddingBottom: support + "(safe-area-inset-" + attr + ")"
};
setStyle(a1, aStyle);
setStyle(a2, aStyle);
setStyle(a1Children, {
transition: "0s",
animation: "none",
width: "400px",
height: "400px"
});
setStyle(a2Children, {
transition: "0s",
animation: "none",
width: "250%",
height: "250%"
});
a1.appendChild(a1Children);
a2.appendChild(a2Children);
parent.appendChild(a1);
parent.appendChild(a2);
parentReady(function() {
a1.scrollTop = a2.scrollTop = MAX;
var a1LastScrollTop = a1.scrollTop;
var a2LastScrollTop = a2.scrollTop;
function onScroll() {
if (this.scrollTop === (this === a1 ? a1LastScrollTop : a2LastScrollTop)) {
return;
}
a1.scrollTop = a2.scrollTop = MAX;
a1LastScrollTop = a1.scrollTop;
a2LastScrollTop = a2.scrollTop;
attrChange(attr);
}
a1.addEventListener("scroll", onScroll, passiveEvents);
a2.addEventListener("scroll", onScroll, passiveEvents);
});
var computedStyle = getComputedStyle(a1);
Object.defineProperty(elementComputedStyle, attr, {
configurable: true,
get: function() {
return parseFloat(computedStyle.paddingBottom);
}
});
}
var parentDiv = document.createElement("div");
setStyle(parentDiv, {
position: "absolute",
left: "0",
top: "0",
width: "0",
height: "0",
zIndex: "-1",
overflow: "hidden",
visibility: "hidden"
});
attrs.forEach(function(key) {
addChild(parentDiv, key);
});
document.body.appendChild(parentDiv);
parentReady();
inited = true;
}
function getAttr(attr) {
if (!inited) {
init();
}
return elementComputedStyle[attr];
}
var changeAttrs = [];
function attrChange(attr) {
if (!changeAttrs.length) {
setTimeout(function() {
var style = {};
changeAttrs.forEach(function(attr2) {
style[attr2] = elementComputedStyle[attr2];
});
changeAttrs.length = 0;
callbacks.forEach(function(callback) {
callback(style);
});
}, 0);
}
changeAttrs.push(attr);
}
var callbacks = [];
function onChange(callback) {
if (!getSupport()) {
return;
}
if (!inited) {
init();
}
if (typeof callback === "function") {
callbacks.push(callback);
}
}
function offChange(callback) {
var index = callbacks.indexOf(callback);
if (index >= 0) {
callbacks.splice(index, 1);
}
}
var safeAreaInsets = {
get support() {
return (typeof support === "string" ? support : getSupport()).length != 0;
},
get top() {
return getAttr("top");
},
get left() {
return getAttr("left");
},
get right() {
return getAttr("right");
},
get bottom() {
return getAttr("bottom");
},
onChange,
offChange
};
var out = safeAreaInsets;
export {out as o};
......@@ -66,7 +66,7 @@
"semver": "^7.3.4",
"ts-jest": "^26.4.4",
"typescript": "^4.1.3",
"vite": "^2.0.0-beta.61",
"vite": "^2.0.1",
"vue": "3.0.5",
"yorkie": "^2.0.0"
}
......
import { createOnApi } from '../../src/helpers/api/index'
import { normalizeErrMsg } from '../../src/helpers/api/callback'
describe('api', () => {
test('normalizeErrMsg', () => {
expect(normalizeErrMsg('', 'navigateTo')).toEqual('navigateTo:ok')
expect(normalizeErrMsg('navigateTo:ok', 'navigateTo')).toEqual(
'navigateTo:ok'
)
expect(normalizeErrMsg('navigateTo:fail', 'navigateTo')).toEqual(
'navigateTo:fail'
)
expect(
normalizeErrMsg('redirectTo:fail page not found', 'navigateTo')
).toEqual('navigateTo:fail page not found')
})
test('createOnApi', () => {
createOnApi<typeof uni.onCompassChange>(
'onCompassChange',
(callback: Function) => {}
)
})
})
import { ApiOptions, ApiProtocol, ProtocolOptions } from '../protocols/type'
type ApiProtocols = ApiProtocol | ProtocolOptions[]
interface CreateApiOptions {
type: API_TYPES
name?: string
options?: ApiOptions
}
export const API_TYPE_ON = 0
export const API_TYPE_SYNC = 1
export const API_TYPE_ASYNC = 2
export const API_TYPE_RETURN = 3
type API_TYPES =
| typeof API_TYPE_ON
| typeof API_TYPE_SYNC
| typeof API_TYPE_ASYNC
| typeof API_TYPE_RETURN
function validateProtocol(
_name: string,
_args: any[],
_protocol: ApiProtocols
) {
return true
}
function formatApiArgs(args: any[], options?: ApiOptions) {
if (!options) {
return args
}
}
export function createApi<T extends Function>(
{ type, name, options }: CreateApiOptions,
fn: T,
protocol?: ApiProtocols
) {
return (function (...args: any[]) {
if (type === API_TYPE_SYNC) {
if (!(__DEV__ && protocol && !validateProtocol(name!, args, protocol))) {
return fn.apply(null, formatApiArgs(args, options))
}
}
} as unknown) as T
}
import { isFunction, isPlainObject } from '@vue/shared'
import { ApiOptions } from '../../protocols/type'
import { tryCatch } from './catch'
let invokeCallbackId = 1
const invokeCallbacks: {
[id: string]: {
name: string
keepAlive: boolean
callback: Function
}
} = {}
function createInvokeCallbackName(name: string, callbackId: number) {
return 'api.' + name + '.' + callbackId
}
function addInvokeCallback(
id: number,
name: string,
callback: Function,
keepAlive: boolean = false
) {
invokeCallbacks[id] = {
name,
keepAlive,
callback,
}
return id
}
// onNativeEventReceive((event,data)=>{}) 需要两个参数,目前写死最多两个参数
export function invokeCallback(id: number, res: unknown, extras?: unknown) {
if (typeof id === 'number') {
const opts = invokeCallbacks[id]
if (opts) {
if (!opts.keepAlive) {
delete invokeCallbacks[id]
}
return opts.callback(res, extras)
}
}
return res
}
function getKeepAliveApiCallback(name: string, callback: Function) {
const onName = 'api.' + name.replace('off', 'on')
for (const key in invokeCallbacks) {
const item = invokeCallbacks[key]
if (item.callback === callback && item.name.indexOf(onName) === 0) {
delete invokeCallbacks[key]
return Number(key)
}
}
return -1
}
export function createKeepAliveApiCallback(name: string, callback: Function) {
if (name.indexOf('off') === 0) {
return getKeepAliveApiCallback(name, callback)
}
const id = invokeCallbackId++
return addInvokeCallback(
id,
createInvokeCallbackName(name, id),
callback,
true
)
}
const API_SUCCSS = 'success'
const API_FAIL = 'fail'
const API_COMPLETE = 'complete'
type CALLBACK_TYPES = typeof API_SUCCSS | typeof API_FAIL | typeof API_COMPLETE
type ApiCallbacks = {
[key in CALLBACK_TYPES]?: Function
}
function getApiCallbacks(args: Record<string, any>) {
const apiCallbacks: ApiCallbacks = {}
for (const name in args) {
const fn = args[name]
if (isFunction(fn)) {
apiCallbacks[name as CALLBACK_TYPES] = tryCatch(fn)
delete args[name]
}
}
return apiCallbacks
}
interface ApiRes {
errMsg: string
}
export function normalizeErrMsg(errMsg: string, name: string) {
if (!errMsg || errMsg.indexOf(':fail') === -1) {
return name + ':ok'
}
return name + errMsg.substring(errMsg.indexOf(':fail'))
}
export function createAsyncApiCallback(
name: string,
args: Record<string, any> = {},
{ beforeAll, beforeSuccess }: ApiOptions = {}
) {
if (!isPlainObject(args)) {
args = {}
}
const { success, fail, complete } = getApiCallbacks(args)
const hasSuccess = isFunction(success)
const hasFail = isFunction(fail)
const hasComplete = isFunction(complete)
const callbackId = invokeCallbackId++
addInvokeCallback(
callbackId,
createInvokeCallbackName(name, callbackId),
(res: ApiRes) => {
res.errMsg = normalizeErrMsg(res.errMsg, name)
isFunction(beforeAll) && beforeAll(res)
if (res.errMsg === name + ':ok') {
isFunction(beforeSuccess) && beforeSuccess(res)
hasSuccess && success!(res)
} else {
hasFail && fail!(res)
}
hasComplete && complete!(res)
}
)
return callbackId
}
export function tryCatchFramework(fn: Function): Function {
return function () {
try {
return fn.apply(fn, arguments)
} catch (e) {
// TODO
console.error(e)
}
}
}
export function tryCatch(fn: Function): Function {
return function () {
try {
return fn.apply(fn, arguments)
} catch (e) {
// TODO
console.error(e)
}
}
}
import { ApiOptions, ApiProtocol, ProtocolOptions } from '../../protocols/type'
import {
createAsyncApiCallback,
createKeepAliveApiCallback,
invokeCallback,
} from './callback'
type ApiProtocols = ApiProtocol | ProtocolOptions[]
export const API_TYPE_ON = 0
export const API_TYPE_SYNC = 1
export const API_TYPE_ASYNC = 2
export const API_TYPE_RETURN = 3
type API_TYPES =
| typeof API_TYPE_ON
| typeof API_TYPE_SYNC
| typeof API_TYPE_ASYNC
| typeof API_TYPE_RETURN
function validateProtocol(
_name: string,
_args: any[],
_protocol: ApiProtocols
) {
return true
}
function formatApiArgs(args: any[], options?: ApiOptions) {
return args
}
function wrapperOnApi(name: string, fn: Function) {
return (callback: Function) =>
fn.apply(null, createKeepAliveApiCallback(name, callback))
}
function wrapperSyncApi(fn: Function) {
return (...args: any[]) => fn.apply(null, args)
}
function wrapperAsyncApi(name: string, fn: Function, options?: ApiOptions) {
return (args: Record<string, any>) => {
const callbackId = createAsyncApiCallback(name, args, options)
return invokeCallback(callbackId, fn.apply(null, [args, callbackId]))
}
}
function wrapperReturnApi(name: string, fn: Function, options?: ApiOptions) {
return (args: Record<string, any>) =>
fn.apply(null, [args, createAsyncApiCallback(name, args, options)])
}
function wrapperApi<T extends Function>(
fn: Function,
name?: string,
protocol?: ApiProtocols,
options?: ApiOptions
) {
return (function (...args: any[]) {
if (!(__DEV__ && protocol && !validateProtocol(name!, args, protocol))) {
return fn.apply(null, formatApiArgs(args, options))
}
} as unknown) as T
}
export function createOnApi<T extends Function>(
name: string,
fn: T,
options?: ApiOptions,
protocol?: ApiProtocols
) {
return createApi(API_TYPE_ON, name, fn, protocol, options)
}
export function createSyncApi<T extends Function>(
name: string,
fn: T,
protocol?: ApiProtocols,
options?: ApiOptions
) {
return createApi(API_TYPE_SYNC, name, fn, protocol, options)
}
export function createAsyncApi<T extends Function>(
name: string,
fn: T,
protocol?: ApiProtocols,
options?: ApiOptions
) {
return createApi(API_TYPE_ASYNC, name, fn, protocol, options)
}
export function createReturnApi<T extends Function>(
name: string,
fn: T,
protocol?: ApiProtocols,
options?: ApiOptions
) {
return createApi(API_TYPE_RETURN, name, fn, protocol, options)
}
function createApi<T extends Function>(
type: API_TYPES,
name: string,
fn: T,
protocol?: ApiProtocols,
options?: ApiOptions
) {
switch (type) {
case API_TYPE_ON:
return wrapperApi<T>(wrapperOnApi(name, fn), name, protocol, options)
case API_TYPE_SYNC:
return wrapperApi<T>(wrapperSyncApi(fn), name, protocol, options)
case API_TYPE_ASYNC:
return wrapperApi<T>(
wrapperAsyncApi(name, fn, options),
name,
protocol,
options
)
case API_TYPE_RETURN:
return wrapperApi<T>(wrapperReturnApi(name, fn), name, protocol, options)
}
}
......@@ -23,10 +23,9 @@ export * from './protocols/media/getImageInfo'
// helpers
export {
createApi,
API_TYPE_ON,
API_TYPE_SYNC,
API_TYPE_ASYNC,
API_TYPE_RETURN,
createOnApi,
createSyncApi,
createAsyncApi,
createReturnApi,
} from './helpers/api'
export { isSyncApi, isContextApi, promisify } from './helpers/promise'
......@@ -16,8 +16,8 @@ export interface ApiProtocol {
}
export interface ApiOptions {
beforeAll?: () => void
beforeSuccess?: () => void
beforeAll?: (res: unknown) => void
beforeSuccess?: (res: unknown) => void
formatArgs?: {
[name: string]: Validator
}
......
// @ts-ignore
import { encode, decode } from '../../helpers/base64-arraybuffer'
import { API_TYPE_SYNC, createApi } from '../../helpers/api'
import { createSyncApi } from '../../helpers/api'
import {
Base64ToArrayBufferProtocol,
ArrayBufferToBase64Protocol,
} from '../../protocols/base/base64'
export const base64ToArrayBuffer = createApi<typeof uni.base64ToArrayBuffer>(
{ type: API_TYPE_SYNC, name: 'base64ToArrayBuffer' },
export const base64ToArrayBuffer = createSyncApi<
typeof uni.base64ToArrayBuffer
>(
'base64ToArrayBuffer',
(base64) => {
return decode(base64) as ArrayBuffer
},
Base64ToArrayBufferProtocol
)
export const arrayBufferToBase64 = createApi<typeof uni.arrayBufferToBase64>(
{ type: API_TYPE_SYNC, name: 'arrayBufferToBase64' },
export const arrayBufferToBase64 = createSyncApi<
typeof uni.arrayBufferToBase64
>(
'arrayBufferToBase64',
(arrayBuffer) => {
return encode(arrayBuffer) as string
},
......
......@@ -8,7 +8,7 @@ import {
HOOKS,
} from '../../helpers/interceptor'
import { API_TYPE_SYNC, createApi } from '../../helpers/api'
import { createSyncApi } from '../../helpers/api'
import {
AddInterceptorProtocol,
......@@ -80,8 +80,8 @@ function removeHook(hooks: Function[] | undefined, hook: Function) {
}
}
export const addInterceptor = createApi(
{ type: API_TYPE_SYNC, name: 'addInterceptor' },
export const addInterceptor = createSyncApi(
'addInterceptor',
(method: string | Interceptor, interceptor: Interceptor | undefined) => {
if (typeof method === 'string' && isPlainObject(interceptor)) {
mergeInterceptorHook(
......@@ -95,8 +95,8 @@ export const addInterceptor = createApi(
AddInterceptorProtocol
)
export const removeInterceptor = createApi(
{ type: API_TYPE_SYNC, name: 'removeInterceptor' },
export const removeInterceptor = createSyncApi(
'removeInterceptor',
(method: string | Interceptor, interceptor: Interceptor | undefined) => {
if (typeof method === 'string') {
if (isPlainObject(interceptor)) {
......
import { API_TYPE_SYNC, createApi } from '../../helpers/api'
import { createSyncApi } from '../../helpers/api'
import { Upx2pxProtocol } from '../../protocols/base/upx2px'
const EPS = 1e-4
......@@ -14,8 +14,8 @@ function checkDeviceWidth() {
isIOS = platform === 'ios'
}
export const upx2px = createApi<typeof uni.upx2px>(
{ type: API_TYPE_SYNC, name: 'upx2px' },
export const upx2px = createSyncApi<typeof uni.upx2px>(
'upx2px',
(number, newDeviceWidth?: number) => {
if (deviceWidth === 0) {
checkDeviceWidth()
......
......@@ -2,7 +2,7 @@ import { extend } from '@vue/shared'
import { ServiceJSBridge } from '@dcloudio/uni-core'
import { API_TYPE_RETURN, createApi } from '../../helpers/api'
import { createReturnApi } from '../../helpers/api'
import { getCurrentPageVm } from '../utils'
const defaultOptions = {
......@@ -120,9 +120,9 @@ class ServiceIntersectionObserver {
}
}
export const createIntersectionObserver = createApi<
export const createIntersectionObserver = createReturnApi<
typeof uni.createIntersectionObserver
>({ type: API_TYPE_RETURN }, (context?, options?) => {
>('createIntersectionObserver', (context?, options?) => {
if (!context) {
context = getCurrentPageVm()
}
......
此差异已折叠。
......@@ -27,7 +27,9 @@ export default defineConfig({
external: ['vue', '@vue/shared', '@dcloudio/uni-shared'],
preserveEntrySignatures: 'strict',
output: {
dir: path.resolve(__dirname, 'dist'),
format: 'es',
manualChunks: undefined,
entryFileNames: 'uni-components.esm.js',
assetFileNames(assetInfo) {
if (assetInfo.name === 'style.css') {
......
......@@ -9,5 +9,6 @@
"replacement": "@dcloudio/uni-h5-vue/lib/vue.runtime.esm.js"
}
]
}
},
"external": ["@dcloudio/uni-h5"]
}
import { plugin } from '@dcloudio/uni-h5';
import { isSymbol, extend, isMap, isObject, toRawType, def, isArray, isString, isFunction, isPromise, toHandlerKey, remove, EMPTY_OBJ, camelize, capitalize, EMPTY_ARR, normalizeClass, normalizeStyle, isOn, NOOP, isGloballyWhitelisted, toNumber, invokeArrayFns, looseIndexOf, isSet, looseEqual, hyphenate, isHTMLTag, isSVGTag, isIntegerKey, hasOwn, hasChanged, getGlobalThis, isReservedProp, NO, isModelListener, makeMap, isSpecialBooleanAttr } from '@vue/shared';
export { camelize, capitalize, toDisplayString, toHandlerKey } from '@vue/shared';
......@@ -1284,7 +1285,7 @@ function createRecord(id, component) {
if (!component) {
warn(`HMR API usage is out of date.\n` +
`Please upgrade vue-loader/vite/rollup-plugin-vue or other relevant ` +
`depdendency that handles Vue SFC compilation.`);
`dependency that handles Vue SFC compilation.`);
component = {};
}
if (map.has(id)) {
......@@ -1399,7 +1400,7 @@ function createDevtoolsComponentHook(hook) {
return (component) => {
if (!devtools)
return;
devtools.emit(hook, component.appContext.app, component.uid, component.parent ? component.parent.uid : undefined);
devtools.emit(hook, component.appContext.app, component.uid, component.parent ? component.parent.uid : undefined, component);
};
}
function devtoolsComponentEmit(component, event, params) {
......@@ -7804,7 +7805,7 @@ function createSlots(slots, dynamicSlots) {
}
// Core API ------------------------------------------------------------------
const version = "3.0.4";
const version = "3.0.5";
/**
* SSR utils for \@vue/server-renderer. Only exposed in cjs builds.
* @internal
......@@ -9010,7 +9011,7 @@ const render = ((...args) => {
const hydrate = ((...args) => {
ensureHydrationRenderer().hydrate(...args);
});
const createApp = ((...args) => {
const createVueApp = ((...args) => {
const app = ensureRenderer().createApp(...args);
if ((process.env.NODE_ENV !== 'production')) {
injectNativeTagCheck(app);
......@@ -9121,4 +9122,9 @@ const onNavigationBarSearchInputClicked = /*#__PURE__*/ createHook$1("onNavigati
const onNavigationBarSearchInputConfirmed = /*#__PURE__*/ createHook$1("onNavigationBarSearchInputConfirmed" /* ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED */);
const onNavigationBarSearchInputFocusChanged = /*#__PURE__*/ createHook$1("onNavigationBarSearchInputFocusChanged" /* ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED */);
export { BaseTransition, Comment, Fragment, KeepAlive, Static, Suspense, Teleport, Text, Transition, TransitionGroup, callWithAsyncErrorHandling, callWithErrorHandling, cloneVNode, compile$1 as compile, computed$1 as computed, createApp, createBlock, createCommentVNode, createHook$1 as createHook, createHydrationRenderer, createRenderer, createSSRApp, createSlots, createStaticVNode, createTextVNode, createVNode, customRef, defineAsyncComponent, defineComponent, defineEmit, defineProps, devtools, getCurrentInstance, getTransitionRawChildren, h, handleError, hydrate, initCustomFormatter, inject, injectHook, isInSSRComponentSetup, isProxy, isReactive, isReadonly, isRef, isVNode, markRaw, mergeProps, nextTick, onActivated, onAddToFavorites, onBackPress, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onError, onErrorCaptured, onHide, onLaunch, onLoad, onMounted, onNavigationBarButtonTap, onNavigationBarSearchInputChanged, onNavigationBarSearchInputClicked, onNavigationBarSearchInputConfirmed, onNavigationBarSearchInputFocusChanged, onPageNotFound, onPageScroll, onPullDownRefresh, onReachBottom, onReady, onRenderTracked, onRenderTriggered, onResize, onShareAppMessage, onShareTimeline, onShow, onTabItemTap, onThemeChange, onUnhandledRejection, onUnload, onUnmounted, onUpdated, openBlock, popScopeId, provide, proxyRefs, pushScopeId, queuePostFlushCb, reactive, readonly, ref, registerRuntimeCompiler, render, renderList, renderSlot, resolveComponent, resolveDirective, resolveDynamicComponent, resolveTransitionHooks, setBlockTracking, setDevtoolsHook, setTransitionHooks, shallowReactive, shallowReadonly, shallowRef, ssrContextKey, ssrUtils, toHandlers, toRaw, toRef, toRefs, transformVNodeArgs, triggerRef, unref, useContext, useCssModule, useCssVars, useSSRContext, useTransitionState, vModelCheckbox, vModelDynamic, vModelRadio, vModelSelect, vModelText, vShow, version, warn, watch, watchEffect, withCtx, withDirectives, withKeys, withModifiers, withScopeId };
function createApp(rootComponent, rootProps = null) {
rootComponent && (rootComponent.mpType = 'app');
return createVueApp(rootComponent, rootProps).use(plugin);
}
export { BaseTransition, Comment, Fragment, KeepAlive, Static, Suspense, Teleport, Text, Transition, TransitionGroup, callWithAsyncErrorHandling, callWithErrorHandling, cloneVNode, compile$1 as compile, computed$1 as computed, createApp, createBlock, createCommentVNode, createHook$1 as createHook, createHydrationRenderer, createRenderer, createSSRApp, createSlots, createStaticVNode, createTextVNode, createVNode, createVueApp, customRef, defineAsyncComponent, defineComponent, defineEmit, defineProps, devtools, getCurrentInstance, getTransitionRawChildren, h, handleError, hydrate, initCustomFormatter, inject, injectHook, isInSSRComponentSetup, isProxy, isReactive, isReadonly, isRef, isVNode, markRaw, mergeProps, nextTick, onActivated, onAddToFavorites, onBackPress, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onError, onErrorCaptured, onHide, onLaunch, onLoad, onMounted, onNavigationBarButtonTap, onNavigationBarSearchInputChanged, onNavigationBarSearchInputClicked, onNavigationBarSearchInputConfirmed, onNavigationBarSearchInputFocusChanged, onPageNotFound, onPageScroll, onPullDownRefresh, onReachBottom, onReady, onRenderTracked, onRenderTriggered, onResize, onShareAppMessage, onShareTimeline, onShow, onTabItemTap, onThemeChange, onUnhandledRejection, onUnload, onUnmounted, onUpdated, openBlock, popScopeId, provide, proxyRefs, pushScopeId, queuePostFlushCb, reactive, readonly, ref, registerRuntimeCompiler, render, renderList, renderSlot, resolveComponent, resolveDirective, resolveDynamicComponent, resolveTransitionHooks, setBlockTracking, setDevtoolsHook, setTransitionHooks, shallowReactive, shallowReadonly, shallowRef, ssrContextKey, ssrUtils, toHandlers, toRaw, toRef, toRefs, transformVNodeArgs, triggerRef, unref, useContext, useCssModule, useCssVars, useSSRContext, useTransitionState, vModelCheckbox, vModelDynamic, vModelRadio, vModelSelect, vModelText, vShow, version, warn, watch, watchEffect, withCtx, withDirectives, withKeys, withModifiers, withScopeId };
......@@ -1284,7 +1284,7 @@ function createRecord(id, component) {
if (!component) {
warn(`HMR API usage is out of date.\n` +
`Please upgrade vue-loader/vite/rollup-plugin-vue or other relevant ` +
`depdendency that handles Vue SFC compilation.`);
`dependency that handles Vue SFC compilation.`);
component = {};
}
if (map.has(id)) {
......@@ -1399,7 +1399,7 @@ function createDevtoolsComponentHook(hook) {
return (component) => {
if (!devtools)
return;
devtools.emit(hook, component.appContext.app, component.uid, component.parent ? component.parent.uid : undefined);
devtools.emit(hook, component.appContext.app, component.uid, component.parent ? component.parent.uid : undefined, component);
};
}
function devtoolsComponentEmit(component, event, params) {
......@@ -7804,7 +7804,7 @@ function createSlots(slots, dynamicSlots) {
}
// Core API ------------------------------------------------------------------
const version = "3.0.4";
const version = "3.0.5";
/**
* SSR utils for \@vue/server-renderer. Only exposed in cjs builds.
* @internal
......@@ -9010,7 +9010,7 @@ const render = ((...args) => {
const hydrate = ((...args) => {
ensureHydrationRenderer().hydrate(...args);
});
const createApp = ((...args) => {
const createVueApp = ((...args) => {
const app = ensureRenderer().createApp(...args);
if ((process.env.NODE_ENV !== 'production')) {
injectNativeTagCheck(app);
......@@ -9092,4 +9092,4 @@ const compile$1 = () => {
}
};
export { BaseTransition, Comment, Fragment, KeepAlive, Static, Suspense, Teleport, Text, Transition, TransitionGroup, callWithAsyncErrorHandling, callWithErrorHandling, cloneVNode, compile$1 as compile, computed$1 as computed, createApp, createBlock, createCommentVNode, createHydrationRenderer, createRenderer, createSSRApp, createSlots, createStaticVNode, createTextVNode, createVNode, customRef, defineAsyncComponent, defineComponent, defineEmit, defineProps, devtools, getCurrentInstance, getTransitionRawChildren, h, handleError, hydrate, initCustomFormatter, inject, injectHook, isInSSRComponentSetup, isProxy, isReactive, isReadonly, isRef, isVNode, markRaw, mergeProps, nextTick, onActivated, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onUnmounted, onUpdated, openBlock, popScopeId, provide, proxyRefs, pushScopeId, queuePostFlushCb, reactive, readonly, ref, registerRuntimeCompiler, render, renderList, renderSlot, resolveComponent, resolveDirective, resolveDynamicComponent, resolveTransitionHooks, setBlockTracking, setDevtoolsHook, setTransitionHooks, shallowReactive, shallowReadonly, shallowRef, ssrContextKey, ssrUtils, toHandlers, toRaw, toRef, toRefs, transformVNodeArgs, triggerRef, unref, useContext, useCssModule, useCssVars, useSSRContext, useTransitionState, vModelCheckbox, vModelDynamic, vModelRadio, vModelSelect, vModelText, vShow, version, warn, watch, watchEffect, withCtx, withDirectives, withKeys, withModifiers, withScopeId };
export { BaseTransition, Comment, Fragment, KeepAlive, Static, Suspense, Teleport, Text, Transition, TransitionGroup, callWithAsyncErrorHandling, callWithErrorHandling, cloneVNode, compile$1 as compile, computed$1 as computed, createBlock, createCommentVNode, createHydrationRenderer, createRenderer, createSSRApp, createSlots, createStaticVNode, createTextVNode, createVNode, createVueApp, customRef, defineAsyncComponent, defineComponent, defineEmit, defineProps, devtools, getCurrentInstance, getTransitionRawChildren, h, handleError, hydrate, initCustomFormatter, inject, injectHook, isInSSRComponentSetup, isProxy, isReactive, isReadonly, isRef, isVNode, markRaw, mergeProps, nextTick, onActivated, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onUnmounted, onUpdated, openBlock, popScopeId, provide, proxyRefs, pushScopeId, queuePostFlushCb, reactive, readonly, ref, registerRuntimeCompiler, render, renderList, renderSlot, resolveComponent, resolveDirective, resolveDynamicComponent, resolveTransitionHooks, setBlockTracking, setDevtoolsHook, setTransitionHooks, shallowReactive, shallowReadonly, shallowRef, ssrContextKey, ssrUtils, toHandlers, toRaw, toRef, toRefs, transformVNodeArgs, triggerRef, unref, useContext, useCssModule, useCssVars, useSSRContext, useTransitionState, vModelCheckbox, vModelDynamic, vModelRadio, vModelSelect, vModelText, vShow, version, warn, watch, watchEffect, withCtx, withDirectives, withKeys, withModifiers, withScopeId };
import { plugin } from '@dcloudio/uni-h5'
// @ts-ignore
import { createVueApp } from '../lib/vue.runtime.esm.js'
export function createApp(rootComponent: unknown, rootProps = null) {
rootComponent && ((rootComponent as any).mpType = 'app')
return createVueApp(rootComponent, rootProps).use(plugin)
}
// @ts-ignore
export * from '../lib/vue.runtime.esm.js'
export * from '@dcloudio/uni-vue/src/apiLifecycle'
此差异已折叠。
import { ComponentPublicInstance } from 'vue'
import { App, ComponentPublicInstance } from 'vue'
let appVm: ComponentPublicInstance
......@@ -9,3 +9,23 @@ export function getApp() {
export function getCurrentPages() {
return []
}
let id = 0
export function createPageState(
type: 'navigateTo' | 'redirectTo' | 'reLaunch' | 'switchTab'
) {
return {
__id__: id++,
__type__: type,
}
}
export function initAppMount(app: App) {
const oldMount = app.mount
app.mount = function mount(
rootContainer: any,
isHydrate?: boolean | undefined
) {
return (appVm = oldMount.call(app, rootContainer, isHydrate))
}
}
<template>
<uni-app :class="{'uni-app--showtabbar':showTabBar}">
<uni-app :class="{ 'uni-app--showtabbar': showTabBar }">
<!-- <transition :name="transitionName"> -->
<!-- TODO -->
<router-view :key="key" v-slot="{ Component }">
<keep-alive :include="keepAliveInclude">
<keep-alive :include="keepAliveInclude" :exclude="keepAliveExclude">
<component :is="Component" />
</keep-alive>
</router-view>
......@@ -15,9 +15,17 @@
v-bind="showActionSheet"
@close="_onActionSheetClose"
/>
<modal v-if="$options.components.Modal" v-bind="showModal" @close="_onModalClose" />
<template v-if="sysComponents&&sysComponents.length">
<component :is="item" v-for="(item, index) in sysComponents" :key="index" />
<modal
v-if="$options.components.Modal"
v-bind="showModal"
@close="_onModalClose"
/>
<template v-if="sysComponents && sysComponents.length">
<component
:is="item"
v-for="(item, index) in sysComponents"
:key="index"
/>
</template>
</uni-app>
</template>
......@@ -39,28 +47,28 @@ export default {
props: {
keepAliveInclude: {
type: Array,
default: function() {
default: function () {
return []
}
}
},
},
keepAliveExclude: {
type: Array,
default: function () {
return []
},
},
},
data() {
return {
transitionName: 'fade',
hideTabBar: false,
tabBar: __uniConfig.tabBar || {},
sysComponents: this.$sysComponents
sysComponents: this.$sysComponents,
}
},
computed: {
key() {
return (
this.$route.meta.name +
'-' +
this.$route.params.__id__ +
'-' +
(__uniConfig.reLaunch || 1)
)
return this.$route.path + '-' + (history.state.__id__ || -1)
},
hasTabBar() {
return (
......@@ -71,7 +79,7 @@ export default {
},
showTabBar() {
return this.$route.meta.isTabBar && !this.hideTabBar
}
},
},
watch: {
$route(newRoute, oldRoute) {
......@@ -84,8 +92,8 @@ export default {
const envMethod = canIUse('css.env')
? 'env'
: canIUse('css.constant')
? 'constant'
: ''
? 'constant'
: ''
const windowBottom =
windowBottomValue && envMethod
? `calc(${windowBottomValue}px + ${envMethod}(safe-area-inset-bottom))`
......@@ -102,7 +110,7 @@ export default {
}
// 触发 resize 事件
window.dispatchEvent(new CustomEvent('resize'))
}
},
},
created() {
if (canIUse('css.var')) {
......@@ -110,7 +118,7 @@ export default {
}
},
mounted() {
window.addEventListener('message', function(evt) {
window.addEventListener('message', function (evt) {
if (
isPlainObject(evt.data) &&
evt.data.type === 'WEB_INVOKE_APPSERVICE'
......@@ -122,13 +130,13 @@ export default {
)
}
})
document.addEventListener('visibilitychange', function() {
document.addEventListener('visibilitychange', function () {
if (document.visibilityState === 'visible') {
UniServiceJSBridge.emit('onAppEnterForeground')
} else {
UniServiceJSBridge.emit('onAppEnterBackground')
}
})
}
},
}
</script>
export * from './app'
export { getApp, getCurrentPages } from './app'
......@@ -5,6 +5,7 @@ import { initView, initService } from '@dcloudio/uni-core'
import { isCustomElement } from '@dcloudio/uni-shared'
import { initRouter } from './router'
import { initAppMount } from '../app'
import { initSystemComponents } from './components'
export default {
......@@ -14,6 +15,7 @@ export default {
initApp(app)
initView(app)
initService(app)
initAppMount(app)
initSystemComponents(app)
initRouter(app)
......
import { App } from 'vue'
import { RouteRecordRaw } from 'vue-router'
import {
NavigationGuardWithThis,
NavigationHookAfter,
Router,
RouteRecordRaw,
RouterOptions,
} from 'vue-router'
import {
createRouter,
createWebHashHistory,
createWebHistory,
createWebHashHistory,
} from 'vue-router'
import { getApp } from '../app'
export function initRouter(app: App) {
app.use(createAppRouter(createRouter(createRouterOptions())))
}
const scrollBehavior: RouterOptions['scrollBehavior'] = (
to,
from,
savedPosition
) => {
if (savedPosition) {
return savedPosition
}
// TODO tabBar?
}
function createRouterOptions(): RouterOptions {
const history =
__UNI_ROUTER_MODE__ === 'history'
? createWebHistory()
: createWebHashHistory()
app.use(
createRouter({
history,
strict: !!__uniConfig.router.strict,
routes: __uniRoutes as RouteRecordRaw[],
scrollBehavior(to, from, savedPosition) {
if (savedPosition) {
return savedPosition
}
// TODO tabBar?
},
})
)
return {
history,
strict: !!__uniConfig.router.strict,
routes: __uniRoutes as RouteRecordRaw[],
scrollBehavior,
}
}
function initGuard(router: Router) {
router.beforeEach(beforeEach)
router.afterEach(afterEach)
}
function createAppRouter(router: Router) {
initGuard(router)
return router
}
const beforeEach: NavigationGuardWithThis<undefined> = (to, from, next) => {
const app = getApp()
if (app) next()
}
const afterEach: NavigationHookAfter = (to, from, failure) => {}
import { hasOwn } from '@vue/shared'
import { createApi, CanIUseProtocol, API_TYPE_SYNC } from '@dcloudio/uni-api'
import { CanIUseProtocol, createSyncApi } from '@dcloudio/uni-api'
function cssSupports(css: string) {
return window.CSS && window.CSS.supports && window.CSS.supports(css)
......@@ -12,8 +12,8 @@ const SCHEMA_CSS = {
'css.constant': cssSupports('top:constant(a)'),
}
export const canIUse = createApi<typeof uni.canIUse>(
{ type: API_TYPE_SYNC, name: 'canIUse' },
export const canIUse = createSyncApi<typeof uni.canIUse>(
'canIUse',
(schema: string) => {
if (hasOwn(SCHEMA_CSS, schema)) {
return SCHEMA_CSS[schema]
......
import { API_TYPE_ASYNC, createApi } from '@dcloudio/uni-api'
import { createAsyncApi } from '@dcloudio/uni-api'
import { getSystemInfoSync } from './getSystemInfoSync'
export const getSystemInfo = createApi<typeof uni.getSystemInfo>(
{ type: API_TYPE_ASYNC, name: 'getSystemInfo' },
export const getSystemInfo = createAsyncApi<typeof uni.getSystemInfo>(
'getSystemInfo',
() => {
return getSystemInfoSync()
}
......
import safeAreaInsets from 'safe-area-insets'
import { API_TYPE_SYNC, createApi } from '@dcloudio/uni-api'
import { createSyncApi } from '@dcloudio/uni-api'
import { getWindowOffset } from '@dcloudio/uni-core'
......@@ -16,8 +16,8 @@ const isIOS = /iphone|ipad|ipod/i.test(ua)
/**
* 获取系统信息-同步
*/
export const getSystemInfoSync = createApi<typeof uni.getSystemInfoSync>(
{ type: API_TYPE_SYNC },
export const getSystemInfoSync = createSyncApi<typeof uni.getSystemInfoSync>(
'getSystemInfoSync',
() => {
var screen = window.screen
var pixelRatio = window.devicePixelRatio
......
import {
API_TYPE_ASYNC,
createApi,
MakePhoneCallProtocol,
} from '@dcloudio/uni-api'
import { createAsyncApi, MakePhoneCallProtocol } from '@dcloudio/uni-api'
export const makePhoneCall = createApi<typeof uni.makePhoneCall>(
{ type: API_TYPE_ASYNC, name: 'makePhoneCall' },
export const makePhoneCall = createAsyncApi<typeof uni.makePhoneCall>(
'makePhoneCall',
(option) => {
window.location.href = `tel:${option.phoneNumber}`
},
......
import {
API_TYPE_ASYNC,
createApi,
OpenDocumentProtocol,
} from '@dcloudio/uni-api'
import { createAsyncApi, OpenDocumentProtocol } from '@dcloudio/uni-api'
export const openDocument = createApi<typeof uni.openDocument>(
{ type: API_TYPE_ASYNC, name: 'openDocument' },
export const openDocument = createAsyncApi<typeof uni.openDocument>(
'openDocument',
(option) => {
window.open(option.filePath)
},
......
import {
API_TYPE_ASYNC,
createApi,
createAsyncApi,
GetImageInfoOptions,
GetImageInfoProtocol,
} from '@dcloudio/uni-api'
......@@ -9,8 +8,8 @@ function _getServiceAddress() {
return window.location.protocol + '//' + window.location.host
}
export const getImageInfo = createApi<typeof uni.getImageInfo>(
{ type: API_TYPE_ASYNC, name: 'getImageInfo', options: GetImageInfoOptions },
export const getImageInfo = createAsyncApi<typeof uni.getImageInfo>(
'getImageInfo',
({ src }, callback?: Function) => {
const img = new Image()
img.onload = function () {
......@@ -28,5 +27,6 @@ export const getImageInfo = createApi<typeof uni.getImageInfo>(
}
img.src = src
},
GetImageInfoProtocol
GetImageInfoProtocol,
GetImageInfoOptions
)
import { API_TYPE_ASYNC, createApi } from '@dcloudio/uni-api'
import { createAsyncApi } from '@dcloudio/uni-api'
export const navigateBack = createApi<typeof uni.navigateBack>(
{ type: API_TYPE_ASYNC },
export const navigateBack = createAsyncApi<typeof uni.navigateBack>(
'navigateBack',
() => {}
)
import { API_TYPE_ASYNC, createApi } from '@dcloudio/uni-api'
import { Router } from 'vue-router'
import { createAsyncApi } from '@dcloudio/uni-api'
import { createPageState } from '../../../framework/app'
export const navigateTo = createApi<typeof uni.navigateTo>(
{ type: API_TYPE_ASYNC },
export const navigateTo = createAsyncApi<typeof uni.navigateTo>(
'navigateTo',
(options) => {
const router = getApp().$router
router.push(options.url)
const router = getApp().$router as Router
router.push({
path: options.url,
force: true,
state: createPageState('navigateTo'),
})
}
)
import { API_TYPE_ASYNC, createApi } from '@dcloudio/uni-api'
import { createAsyncApi } from '@dcloudio/uni-api'
export const reLaunch = createApi({ type: API_TYPE_ASYNC }, () => {})
export const reLaunch = createAsyncApi('reLaunch', () => {})
import { API_TYPE_ASYNC, createApi } from '@dcloudio/uni-api'
import { createAsyncApi } from '@dcloudio/uni-api'
export const redirectTo = createApi({ type: API_TYPE_ASYNC }, () => {})
export const redirectTo = createAsyncApi('redirectTo', () => {})
import { API_TYPE_ASYNC, createApi } from '@dcloudio/uni-api'
import { createAsyncApi } from '@dcloudio/uni-api'
export const switchTab = createApi({ type: API_TYPE_ASYNC }, () => {})
export const switchTab = createAsyncApi('switchTab', () => {})
import { API_TYPE_SYNC, createApi } from '@dcloudio/uni-api'
import { createSyncApi } from '@dcloudio/uni-api'
export const getRealPath = createApi(
{ type: API_TYPE_SYNC },
(path: string) => {
return path
}
)
export const getRealPath = createSyncApi('getRealPath', (path: string) => {
return path
})
......@@ -58,7 +58,9 @@ export default defineConfig({
}),
],
output: {
dir: path.resolve(__dirname, 'dist'),
format: 'es',
manualChunks: undefined,
entryFileNames: 'uni-h5.esm.js',
assetFileNames(assetInfo) {
if (assetInfo.name === 'style.css') {
......
import { isArray, isPromise, isFunction, isPlainObject, hasOwn, isString } from '@vue/shared';
import { isPlainObject, isFunction, isArray, isPromise, hasOwn, isString } from '@vue/shared';
function tryCatch(fn) {
return function () {
try {
return fn.apply(fn, arguments);
}
catch (e) {
// TODO
console.error(e);
}
};
}
let invokeCallbackId = 1;
const invokeCallbacks = {};
function createInvokeCallbackName(name, callbackId) {
return 'api.' + name + '.' + callbackId;
}
function addInvokeCallback(id, name, callback, keepAlive = false) {
invokeCallbacks[id] = {
name,
keepAlive,
callback,
};
return id;
}
// onNativeEventReceive((event,data)=>{}) 需要两个参数,目前写死最多两个参数
function invokeCallback(id, res, extras) {
if (typeof id === 'number') {
const opts = invokeCallbacks[id];
if (opts) {
if (!opts.keepAlive) {
delete invokeCallbacks[id];
}
return opts.callback(res, extras);
}
}
return res;
}
function getKeepAliveApiCallback(name, callback) {
const onName = 'api.' + name.replace('off', 'on');
for (const key in invokeCallbacks) {
const item = invokeCallbacks[key];
if (item.callback === callback && item.name.indexOf(onName) === 0) {
delete invokeCallbacks[key];
return Number(key);
}
}
return -1;
}
function createKeepAliveApiCallback(name, callback) {
if (name.indexOf('off') === 0) {
return getKeepAliveApiCallback(name, callback);
}
const id = invokeCallbackId++;
return addInvokeCallback(id, createInvokeCallbackName(name, id), callback, true);
}
function getApiCallbacks(args) {
const apiCallbacks = {};
for (const name in args) {
const fn = args[name];
if (isFunction(fn)) {
apiCallbacks[name] = tryCatch(fn);
delete args[name];
}
}
return apiCallbacks;
}
function normalizeErrMsg(errMsg, name) {
if (!errMsg || errMsg.indexOf(':fail') === -1) {
return name + ':ok';
}
return name + errMsg.substring(errMsg.indexOf(':fail'));
}
function createAsyncApiCallback(name, args = {}, { beforeAll, beforeSuccess } = {}) {
if (!isPlainObject(args)) {
args = {};
}
const { success, fail, complete } = getApiCallbacks(args);
const hasSuccess = isFunction(success);
const hasFail = isFunction(fail);
const hasComplete = isFunction(complete);
const callbackId = invokeCallbackId++;
addInvokeCallback(callbackId, createInvokeCallbackName(name, callbackId), (res) => {
res.errMsg = normalizeErrMsg(res.errMsg, name);
isFunction(beforeAll) && beforeAll(res);
if (res.errMsg === name + ':ok') {
isFunction(beforeSuccess) && beforeSuccess(res);
hasSuccess && success(res);
}
else {
hasFail && fail(res);
}
hasComplete && complete(res);
});
return callbackId;
}
const API_TYPE_ON = 0;
const API_TYPE_SYNC = 1;
const API_TYPE_ASYNC = 2;
const API_TYPE_RETURN = 3;
function validateProtocol(_name, _args, _protocol) {
return true;
}
function formatApiArgs(args, options) {
if (!options) {
return args;
}
return args;
}
function wrapperOnApi(name, fn) {
return (callback) => fn.apply(null, createKeepAliveApiCallback(name, callback));
}
function wrapperSyncApi(fn) {
return (...args) => fn.apply(null, args);
}
function wrapperAsyncApi(name, fn, options) {
return (args) => {
const callbackId = createAsyncApiCallback(name, args, options);
return invokeCallback(callbackId, fn.apply(null, [args, callbackId]));
};
}
function createApi({ type, name, options }, fn, protocol) {
function wrapperReturnApi(name, fn, options) {
return (args) => fn.apply(null, [args, createAsyncApiCallback(name, args, options)]);
}
function wrapperApi(fn, name, protocol, options) {
return function (...args) {
if (type === API_TYPE_SYNC) {
if (!((process.env.NODE_ENV !== 'production') && protocol && !validateProtocol())) {
return fn.apply(null, formatApiArgs(args, options));
}
if (!((process.env.NODE_ENV !== 'production') && protocol && !validateProtocol())) {
return fn.apply(null, formatApiArgs(args));
}
};
}
function createSyncApi(name, fn, protocol, options) {
return createApi(API_TYPE_SYNC, name, fn, protocol, options);
}
function createApi(type, name, fn, protocol, options) {
switch (type) {
case API_TYPE_ON:
return wrapperApi(wrapperOnApi(name, fn), name, protocol);
case API_TYPE_SYNC:
return wrapperApi(wrapperSyncApi(fn), name, protocol);
case API_TYPE_ASYNC:
return wrapperApi(wrapperAsyncApi(name, fn, options), name, protocol);
case API_TYPE_RETURN:
return wrapperApi(wrapperReturnApi(name, fn), name, protocol);
}
}
const Upx2pxProtocol = [
......@@ -38,7 +164,7 @@ function checkDeviceWidth() {
deviceDPR = pixelRatio;
isIOS = platform === 'ios';
}
const upx2px = createApi({ type: API_TYPE_SYNC, name: 'upx2px' }, (number, newDeviceWidth) => {
const upx2px = createSyncApi('upx2px', (number, newDeviceWidth) => {
if (deviceWidth === 0) {
checkDeviceWidth();
}
......@@ -220,7 +346,7 @@ function removeHook(hooks, hook) {
hooks.splice(index, 1);
}
}
const addInterceptor = createApi({ type: API_TYPE_SYNC, name: 'addInterceptor' }, (method, interceptor) => {
const addInterceptor = createSyncApi('addInterceptor', (method, interceptor) => {
if (typeof method === 'string' && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);
}
......@@ -228,7 +354,7 @@ const addInterceptor = createApi({ type: API_TYPE_SYNC, name: 'addInterceptor' }
mergeInterceptorHook(globalInterceptors, method);
}
}, AddInterceptorProtocol);
const removeInterceptor = createApi({ type: API_TYPE_SYNC, name: 'removeInterceptor' }, (method, interceptor) => {
const removeInterceptor = createSyncApi('removeInterceptor', (method, interceptor) => {
if (typeof method === 'string') {
if (isPlainObject(interceptor)) {
removeInterceptorHook(scopedInterceptors[method], interceptor);
......
import { isArray, isPromise, isFunction, isPlainObject, hasOwn, isString } from '@vue/shared';
import { isPlainObject, isFunction, isArray, isPromise, hasOwn, isString } from '@vue/shared';
function tryCatch(fn) {
return function () {
try {
return fn.apply(fn, arguments);
}
catch (e) {
// TODO
console.error(e);
}
};
}
let invokeCallbackId = 1;
const invokeCallbacks = {};
function createInvokeCallbackName(name, callbackId) {
return 'api.' + name + '.' + callbackId;
}
function addInvokeCallback(id, name, callback, keepAlive = false) {
invokeCallbacks[id] = {
name,
keepAlive,
callback,
};
return id;
}
// onNativeEventReceive((event,data)=>{}) 需要两个参数,目前写死最多两个参数
function invokeCallback(id, res, extras) {
if (typeof id === 'number') {
const opts = invokeCallbacks[id];
if (opts) {
if (!opts.keepAlive) {
delete invokeCallbacks[id];
}
return opts.callback(res, extras);
}
}
return res;
}
function getKeepAliveApiCallback(name, callback) {
const onName = 'api.' + name.replace('off', 'on');
for (const key in invokeCallbacks) {
const item = invokeCallbacks[key];
if (item.callback === callback && item.name.indexOf(onName) === 0) {
delete invokeCallbacks[key];
return Number(key);
}
}
return -1;
}
function createKeepAliveApiCallback(name, callback) {
if (name.indexOf('off') === 0) {
return getKeepAliveApiCallback(name, callback);
}
const id = invokeCallbackId++;
return addInvokeCallback(id, createInvokeCallbackName(name, id), callback, true);
}
function getApiCallbacks(args) {
const apiCallbacks = {};
for (const name in args) {
const fn = args[name];
if (isFunction(fn)) {
apiCallbacks[name] = tryCatch(fn);
delete args[name];
}
}
return apiCallbacks;
}
function normalizeErrMsg(errMsg, name) {
if (!errMsg || errMsg.indexOf(':fail') === -1) {
return name + ':ok';
}
return name + errMsg.substring(errMsg.indexOf(':fail'));
}
function createAsyncApiCallback(name, args = {}, { beforeAll, beforeSuccess } = {}) {
if (!isPlainObject(args)) {
args = {};
}
const { success, fail, complete } = getApiCallbacks(args);
const hasSuccess = isFunction(success);
const hasFail = isFunction(fail);
const hasComplete = isFunction(complete);
const callbackId = invokeCallbackId++;
addInvokeCallback(callbackId, createInvokeCallbackName(name, callbackId), (res) => {
res.errMsg = normalizeErrMsg(res.errMsg, name);
isFunction(beforeAll) && beforeAll(res);
if (res.errMsg === name + ':ok') {
isFunction(beforeSuccess) && beforeSuccess(res);
hasSuccess && success(res);
}
else {
hasFail && fail(res);
}
hasComplete && complete(res);
});
return callbackId;
}
const API_TYPE_ON = 0;
const API_TYPE_SYNC = 1;
const API_TYPE_ASYNC = 2;
const API_TYPE_RETURN = 3;
function validateProtocol(_name, _args, _protocol) {
return true;
}
function formatApiArgs(args, options) {
if (!options) {
return args;
}
return args;
}
function wrapperOnApi(name, fn) {
return (callback) => fn.apply(null, createKeepAliveApiCallback(name, callback));
}
function wrapperSyncApi(fn) {
return (...args) => fn.apply(null, args);
}
function wrapperAsyncApi(name, fn, options) {
return (args) => {
const callbackId = createAsyncApiCallback(name, args, options);
return invokeCallback(callbackId, fn.apply(null, [args, callbackId]));
};
}
function createApi({ type, name, options }, fn, protocol) {
function wrapperReturnApi(name, fn, options) {
return (args) => fn.apply(null, [args, createAsyncApiCallback(name, args, options)]);
}
function wrapperApi(fn, name, protocol, options) {
return function (...args) {
if (type === API_TYPE_SYNC) {
if (!((process.env.NODE_ENV !== 'production') && protocol && !validateProtocol())) {
return fn.apply(null, formatApiArgs(args, options));
}
if (!((process.env.NODE_ENV !== 'production') && protocol && !validateProtocol())) {
return fn.apply(null, formatApiArgs(args));
}
};
}
function createSyncApi(name, fn, protocol, options) {
return createApi(API_TYPE_SYNC, name, fn, protocol, options);
}
function createApi(type, name, fn, protocol, options) {
switch (type) {
case API_TYPE_ON:
return wrapperApi(wrapperOnApi(name, fn), name, protocol);
case API_TYPE_SYNC:
return wrapperApi(wrapperSyncApi(fn), name, protocol);
case API_TYPE_ASYNC:
return wrapperApi(wrapperAsyncApi(name, fn, options), name, protocol);
case API_TYPE_RETURN:
return wrapperApi(wrapperReturnApi(name, fn), name, protocol);
}
}
const Upx2pxProtocol = [
......@@ -38,7 +164,7 @@ function checkDeviceWidth() {
deviceDPR = pixelRatio;
isIOS = platform === 'ios';
}
const upx2px = createApi({ type: API_TYPE_SYNC, name: 'upx2px' }, (number, newDeviceWidth) => {
const upx2px = createSyncApi('upx2px', (number, newDeviceWidth) => {
if (deviceWidth === 0) {
checkDeviceWidth();
}
......@@ -220,7 +346,7 @@ function removeHook(hooks, hook) {
hooks.splice(index, 1);
}
}
const addInterceptor = createApi({ type: API_TYPE_SYNC, name: 'addInterceptor' }, (method, interceptor) => {
const addInterceptor = createSyncApi('addInterceptor', (method, interceptor) => {
if (typeof method === 'string' && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);
}
......@@ -228,7 +354,7 @@ const addInterceptor = createApi({ type: API_TYPE_SYNC, name: 'addInterceptor' }
mergeInterceptorHook(globalInterceptors, method);
}
}, AddInterceptorProtocol);
const removeInterceptor = createApi({ type: API_TYPE_SYNC, name: 'removeInterceptor' }, (method, interceptor) => {
const removeInterceptor = createSyncApi('removeInterceptor', (method, interceptor) => {
if (typeof method === 'string') {
if (isPlainObject(interceptor)) {
removeInterceptorHook(scopedInterceptors[method], interceptor);
......
import { isArray, isPromise, isFunction, isPlainObject, hasOwn, isString } from '@vue/shared';
import { isPlainObject, isFunction, isArray, isPromise, hasOwn, isString } from '@vue/shared';
function tryCatch(fn) {
return function () {
try {
return fn.apply(fn, arguments);
}
catch (e) {
// TODO
console.error(e);
}
};
}
let invokeCallbackId = 1;
const invokeCallbacks = {};
function createInvokeCallbackName(name, callbackId) {
return 'api.' + name + '.' + callbackId;
}
function addInvokeCallback(id, name, callback, keepAlive = false) {
invokeCallbacks[id] = {
name,
keepAlive,
callback,
};
return id;
}
// onNativeEventReceive((event,data)=>{}) 需要两个参数,目前写死最多两个参数
function invokeCallback(id, res, extras) {
if (typeof id === 'number') {
const opts = invokeCallbacks[id];
if (opts) {
if (!opts.keepAlive) {
delete invokeCallbacks[id];
}
return opts.callback(res, extras);
}
}
return res;
}
function getKeepAliveApiCallback(name, callback) {
const onName = 'api.' + name.replace('off', 'on');
for (const key in invokeCallbacks) {
const item = invokeCallbacks[key];
if (item.callback === callback && item.name.indexOf(onName) === 0) {
delete invokeCallbacks[key];
return Number(key);
}
}
return -1;
}
function createKeepAliveApiCallback(name, callback) {
if (name.indexOf('off') === 0) {
return getKeepAliveApiCallback(name, callback);
}
const id = invokeCallbackId++;
return addInvokeCallback(id, createInvokeCallbackName(name, id), callback, true);
}
function getApiCallbacks(args) {
const apiCallbacks = {};
for (const name in args) {
const fn = args[name];
if (isFunction(fn)) {
apiCallbacks[name] = tryCatch(fn);
delete args[name];
}
}
return apiCallbacks;
}
function normalizeErrMsg(errMsg, name) {
if (!errMsg || errMsg.indexOf(':fail') === -1) {
return name + ':ok';
}
return name + errMsg.substring(errMsg.indexOf(':fail'));
}
function createAsyncApiCallback(name, args = {}, { beforeAll, beforeSuccess } = {}) {
if (!isPlainObject(args)) {
args = {};
}
const { success, fail, complete } = getApiCallbacks(args);
const hasSuccess = isFunction(success);
const hasFail = isFunction(fail);
const hasComplete = isFunction(complete);
const callbackId = invokeCallbackId++;
addInvokeCallback(callbackId, createInvokeCallbackName(name, callbackId), (res) => {
res.errMsg = normalizeErrMsg(res.errMsg, name);
isFunction(beforeAll) && beforeAll(res);
if (res.errMsg === name + ':ok') {
isFunction(beforeSuccess) && beforeSuccess(res);
hasSuccess && success(res);
}
else {
hasFail && fail(res);
}
hasComplete && complete(res);
});
return callbackId;
}
const API_TYPE_ON = 0;
const API_TYPE_SYNC = 1;
const API_TYPE_ASYNC = 2;
const API_TYPE_RETURN = 3;
function validateProtocol(_name, _args, _protocol) {
return true;
}
function formatApiArgs(args, options) {
if (!options) {
return args;
}
return args;
}
function wrapperOnApi(name, fn) {
return (callback) => fn.apply(null, createKeepAliveApiCallback(name, callback));
}
function wrapperSyncApi(fn) {
return (...args) => fn.apply(null, args);
}
function wrapperAsyncApi(name, fn, options) {
return (args) => {
const callbackId = createAsyncApiCallback(name, args, options);
return invokeCallback(callbackId, fn.apply(null, [args, callbackId]));
};
}
function createApi({ type, name, options }, fn, protocol) {
function wrapperReturnApi(name, fn, options) {
return (args) => fn.apply(null, [args, createAsyncApiCallback(name, args, options)]);
}
function wrapperApi(fn, name, protocol, options) {
return function (...args) {
if (type === API_TYPE_SYNC) {
if (!((process.env.NODE_ENV !== 'production') && protocol && !validateProtocol())) {
return fn.apply(null, formatApiArgs(args, options));
}
if (!((process.env.NODE_ENV !== 'production') && protocol && !validateProtocol())) {
return fn.apply(null, formatApiArgs(args));
}
};
}
function createSyncApi(name, fn, protocol, options) {
return createApi(API_TYPE_SYNC, name, fn, protocol, options);
}
function createApi(type, name, fn, protocol, options) {
switch (type) {
case API_TYPE_ON:
return wrapperApi(wrapperOnApi(name, fn), name, protocol);
case API_TYPE_SYNC:
return wrapperApi(wrapperSyncApi(fn), name, protocol);
case API_TYPE_ASYNC:
return wrapperApi(wrapperAsyncApi(name, fn, options), name, protocol);
case API_TYPE_RETURN:
return wrapperApi(wrapperReturnApi(name, fn), name, protocol);
}
}
const Upx2pxProtocol = [
......@@ -38,7 +164,7 @@ function checkDeviceWidth() {
deviceDPR = pixelRatio;
isIOS = platform === 'ios';
}
const upx2px = createApi({ type: API_TYPE_SYNC, name: 'upx2px' }, (number, newDeviceWidth) => {
const upx2px = createSyncApi('upx2px', (number, newDeviceWidth) => {
if (deviceWidth === 0) {
checkDeviceWidth();
}
......@@ -220,7 +346,7 @@ function removeHook(hooks, hook) {
hooks.splice(index, 1);
}
}
const addInterceptor = createApi({ type: API_TYPE_SYNC, name: 'addInterceptor' }, (method, interceptor) => {
const addInterceptor = createSyncApi('addInterceptor', (method, interceptor) => {
if (typeof method === 'string' && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);
}
......@@ -228,7 +354,7 @@ const addInterceptor = createApi({ type: API_TYPE_SYNC, name: 'addInterceptor' }
mergeInterceptorHook(globalInterceptors, method);
}
}, AddInterceptorProtocol);
const removeInterceptor = createApi({ type: API_TYPE_SYNC, name: 'removeInterceptor' }, (method, interceptor) => {
const removeInterceptor = createSyncApi('removeInterceptor', (method, interceptor) => {
if (typeof method === 'string') {
if (isPlainObject(interceptor)) {
removeInterceptorHook(scopedInterceptors[method], interceptor);
......
import { isArray, isPromise, isFunction, isPlainObject, hasOwn, isString } from '@vue/shared';
import { isPlainObject, isFunction, isArray, isPromise, hasOwn, isString } from '@vue/shared';
function tryCatch(fn) {
return function () {
try {
return fn.apply(fn, arguments);
}
catch (e) {
// TODO
console.error(e);
}
};
}
let invokeCallbackId = 1;
const invokeCallbacks = {};
function createInvokeCallbackName(name, callbackId) {
return 'api.' + name + '.' + callbackId;
}
function addInvokeCallback(id, name, callback, keepAlive = false) {
invokeCallbacks[id] = {
name,
keepAlive,
callback,
};
return id;
}
// onNativeEventReceive((event,data)=>{}) 需要两个参数,目前写死最多两个参数
function invokeCallback(id, res, extras) {
if (typeof id === 'number') {
const opts = invokeCallbacks[id];
if (opts) {
if (!opts.keepAlive) {
delete invokeCallbacks[id];
}
return opts.callback(res, extras);
}
}
return res;
}
function getKeepAliveApiCallback(name, callback) {
const onName = 'api.' + name.replace('off', 'on');
for (const key in invokeCallbacks) {
const item = invokeCallbacks[key];
if (item.callback === callback && item.name.indexOf(onName) === 0) {
delete invokeCallbacks[key];
return Number(key);
}
}
return -1;
}
function createKeepAliveApiCallback(name, callback) {
if (name.indexOf('off') === 0) {
return getKeepAliveApiCallback(name, callback);
}
const id = invokeCallbackId++;
return addInvokeCallback(id, createInvokeCallbackName(name, id), callback, true);
}
function getApiCallbacks(args) {
const apiCallbacks = {};
for (const name in args) {
const fn = args[name];
if (isFunction(fn)) {
apiCallbacks[name] = tryCatch(fn);
delete args[name];
}
}
return apiCallbacks;
}
function normalizeErrMsg(errMsg, name) {
if (!errMsg || errMsg.indexOf(':fail') === -1) {
return name + ':ok';
}
return name + errMsg.substring(errMsg.indexOf(':fail'));
}
function createAsyncApiCallback(name, args = {}, { beforeAll, beforeSuccess } = {}) {
if (!isPlainObject(args)) {
args = {};
}
const { success, fail, complete } = getApiCallbacks(args);
const hasSuccess = isFunction(success);
const hasFail = isFunction(fail);
const hasComplete = isFunction(complete);
const callbackId = invokeCallbackId++;
addInvokeCallback(callbackId, createInvokeCallbackName(name, callbackId), (res) => {
res.errMsg = normalizeErrMsg(res.errMsg, name);
isFunction(beforeAll) && beforeAll(res);
if (res.errMsg === name + ':ok') {
isFunction(beforeSuccess) && beforeSuccess(res);
hasSuccess && success(res);
}
else {
hasFail && fail(res);
}
hasComplete && complete(res);
});
return callbackId;
}
const API_TYPE_ON = 0;
const API_TYPE_SYNC = 1;
const API_TYPE_ASYNC = 2;
const API_TYPE_RETURN = 3;
function validateProtocol(_name, _args, _protocol) {
return true;
}
function formatApiArgs(args, options) {
if (!options) {
return args;
}
return args;
}
function wrapperOnApi(name, fn) {
return (callback) => fn.apply(null, createKeepAliveApiCallback(name, callback));
}
function wrapperSyncApi(fn) {
return (...args) => fn.apply(null, args);
}
function wrapperAsyncApi(name, fn, options) {
return (args) => {
const callbackId = createAsyncApiCallback(name, args, options);
return invokeCallback(callbackId, fn.apply(null, [args, callbackId]));
};
}
function createApi({ type, name, options }, fn, protocol) {
function wrapperReturnApi(name, fn, options) {
return (args) => fn.apply(null, [args, createAsyncApiCallback(name, args, options)]);
}
function wrapperApi(fn, name, protocol, options) {
return function (...args) {
if (type === API_TYPE_SYNC) {
if (!((process.env.NODE_ENV !== 'production') && protocol && !validateProtocol())) {
return fn.apply(null, formatApiArgs(args, options));
}
if (!((process.env.NODE_ENV !== 'production') && protocol && !validateProtocol())) {
return fn.apply(null, formatApiArgs(args));
}
};
}
function createSyncApi(name, fn, protocol, options) {
return createApi(API_TYPE_SYNC, name, fn, protocol, options);
}
function createApi(type, name, fn, protocol, options) {
switch (type) {
case API_TYPE_ON:
return wrapperApi(wrapperOnApi(name, fn), name, protocol);
case API_TYPE_SYNC:
return wrapperApi(wrapperSyncApi(fn), name, protocol);
case API_TYPE_ASYNC:
return wrapperApi(wrapperAsyncApi(name, fn, options), name, protocol);
case API_TYPE_RETURN:
return wrapperApi(wrapperReturnApi(name, fn), name, protocol);
}
}
const Upx2pxProtocol = [
......@@ -38,7 +164,7 @@ function checkDeviceWidth() {
deviceDPR = pixelRatio;
isIOS = platform === 'ios';
}
const upx2px = createApi({ type: API_TYPE_SYNC, name: 'upx2px' }, (number, newDeviceWidth) => {
const upx2px = createSyncApi('upx2px', (number, newDeviceWidth) => {
if (deviceWidth === 0) {
checkDeviceWidth();
}
......@@ -220,7 +346,7 @@ function removeHook(hooks, hook) {
hooks.splice(index, 1);
}
}
const addInterceptor = createApi({ type: API_TYPE_SYNC, name: 'addInterceptor' }, (method, interceptor) => {
const addInterceptor = createSyncApi('addInterceptor', (method, interceptor) => {
if (typeof method === 'string' && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);
}
......@@ -228,7 +354,7 @@ const addInterceptor = createApi({ type: API_TYPE_SYNC, name: 'addInterceptor' }
mergeInterceptorHook(globalInterceptors, method);
}
}, AddInterceptorProtocol);
const removeInterceptor = createApi({ type: API_TYPE_SYNC, name: 'removeInterceptor' }, (method, interceptor) => {
const removeInterceptor = createSyncApi('removeInterceptor', (method, interceptor) => {
if (typeof method === 'string') {
if (isPlainObject(interceptor)) {
removeInterceptorHook(scopedInterceptors[method], interceptor);
......
......@@ -149,7 +149,7 @@ function findHooks(vueOptions, hooks = new Set()) {
function initHook(mpOptions, hook, excludes) {
if (excludes.indexOf(hook) === -1 && !hasOwn(mpOptions, hook)) {
mpOptions[hook] = function (args) {
if ( hook === 'onError') {
if (hook === 'onError') {
return getApp().$vm.$callHook(hook, args);
}
return this.$vm && this.$vm.$callHook(hook, args);
......
......@@ -3771,6 +3771,7 @@ const onNavigationBarSearchInputConfirmed = /*#__PURE__*/ createHook$1("onNaviga
const onNavigationBarSearchInputFocusChanged = /*#__PURE__*/ createHook$1("onNavigationBarSearchInputFocusChanged" /* ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED */);
function createApp(rootComponent, rootProps = null) {
rootComponent && (rootComponent.mpType = 'app');
return createVueApp(rootComponent, rootProps).use(plugin);
}
......
......@@ -2,6 +2,7 @@ import plugin from './plugin'
// @ts-ignore
import { createVueApp } from '../lib/vue.runtime.esm.js'
export function createApp(rootComponent: unknown, rootProps = null) {
rootComponent && ((rootComponent as any).mpType = 'app')
return createVueApp(rootComponent, rootProps).use(plugin)
}
// @ts-ignore
......
......@@ -945,7 +945,7 @@ function initLifetimes$1(lifetimesOptions) {
return extend(initLifetimes(lifetimesOptions), {
ready() {
if (this.$vm && lifetimesOptions.isPage(this)) {
if ( this.pageinstance) {
if (this.pageinstance) {
this.__webviewId__ = this.pageinstance.__pageId__;
}
this.$vm.$callSyncHook('created');
......
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册