From a5f0a378455a1efa35d2d33d2aa40d09a5663b76 Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Thu, 26 May 2022 19:04:25 +0800 Subject: [PATCH] chore: build --- .../test-uniplugin/android/src/test.uts | 4 + .../src/io/dcloud/uniplugin/TestModule.kt | 2 +- .../src/io/dcloud/uniplugin/TestModule.kt.map | 2 +- .../src/io/dcloud/uniplugin/log.kt.map | 2 +- .../test-uniplugin/android/src/test.kt | 5 + .../test-uniplugin/android/src/test.kt.map | 1 + packages/uni-api/src/service/plugin/push.ts | 23 +- packages/uni-app-plus/dist/uni.runtime.esm.js | 143 +- packages/uni-h5-vue/dist/vue.runtime.cjs.js | 3574 ++++++------ packages/uni-h5-vue/dist/vue.runtime.esm.js | 4956 +++++++++-------- packages/uni-h5-vue/package.json | 5 +- packages/uni-h5/dist/uni-h5.cjs.js | 239 + packages/uni-h5/dist/uni-h5.es.js | 203 +- packages/uni-mp-alipay/dist/uni.api.esm.js | 57 +- packages/uni-mp-baidu/dist/uni.api.esm.js | 66 +- packages/uni-mp-kuaishou/dist/uni.api.esm.js | 58 +- packages/uni-mp-lark/dist/uni.api.esm.js | 58 +- packages/uni-mp-qq/dist/uni.api.esm.js | 54 +- packages/uni-mp-toutiao/dist/uni.api.esm.js | 58 +- packages/uni-mp-weixin/dist/uni.api.esm.js | 63 +- packages/uni-push/dist/uni-push.plus.es.js | 1 + packages/uni-push/src/plus.ts | 1 + .../uni-quickapp-webview/dist/uni.api.esm.js | 54 +- .../uts-darwin-arm64/uts.darwin-arm64.node | Bin 2607144 -> 2673496 bytes packages/uts-darwin-x64/uts.darwin-x64.node | Bin 2935320 -> 3017904 bytes pnpm-lock.yaml | 6 +- 26 files changed, 5071 insertions(+), 4564 deletions(-) create mode 100644 packages/playground/uts/nativeplugins/test-uniplugin/android/src/test.uts create mode 100644 packages/playground/uts/unpackage/nativeplugins/test-uniplugin/android/src/test.kt create mode 100644 packages/playground/uts/unpackage/nativeplugins/test-uniplugin/android/src/test.kt.map diff --git a/packages/playground/uts/nativeplugins/test-uniplugin/android/src/test.uts b/packages/playground/uts/nativeplugins/test-uniplugin/android/src/test.uts new file mode 100644 index 000000000..f6886d51d --- /dev/null +++ b/packages/playground/uts/nativeplugins/test-uniplugin/android/src/test.uts @@ -0,0 +1,4 @@ +import Log from "android.util.Log"; +export default function log(tag: string, msg: string) { + Log.e(tag, msg); +} diff --git a/packages/playground/uts/unpackage/nativeplugins/test-uniplugin/android/src/io/dcloud/uniplugin/TestModule.kt b/packages/playground/uts/unpackage/nativeplugins/test-uniplugin/android/src/io/dcloud/uniplugin/TestModule.kt index a0d2a0091..63f849135 100644 --- a/packages/playground/uts/unpackage/nativeplugins/test-uniplugin/android/src/io/dcloud/uniplugin/TestModule.kt +++ b/packages/playground/uts/unpackage/nativeplugins/test-uniplugin/android/src/io/dcloud/uniplugin/TestModule.kt @@ -22,7 +22,7 @@ open class TestModule : UniModule() { data["code"] = "success456"; return data; } - override open fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) { + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) { if (requestCode == TestModule.REQUEST_CODE && data.hasExtra("respond")) { log(this.TAG, "原生页面返回----" + data.getStringExtra("respond")); } diff --git a/packages/playground/uts/unpackage/nativeplugins/test-uniplugin/android/src/io/dcloud/uniplugin/TestModule.kt.map b/packages/playground/uts/unpackage/nativeplugins/test-uniplugin/android/src/io/dcloud/uniplugin/TestModule.kt.map index 2f7bbc05f..47c9a85e0 100644 --- a/packages/playground/uts/unpackage/nativeplugins/test-uniplugin/android/src/io/dcloud/uniplugin/TestModule.kt.map +++ b/packages/playground/uts/unpackage/nativeplugins/test-uniplugin/android/src/io/dcloud/uniplugin/TestModule.kt.map @@ -1 +1 @@ -{"version":3,"sources":["/Users/fxy/Documents/projects/GitHub/uni-app/uni-app-next/packages/playground/uts/nativeplugins/test-uniplugin/android/src/io/dcloud/uniplugin/TestModule.uts"],"names":["TestModule","UniModule","TAG","UniJSMethod","uiThread","testAsyncFunc","options","callback","log","data","JSONObject","invoke","testSyncFunc","onActivityResult","requestCode","resultCode","REQUEST_CODE","hasExtra","getStringExtra"],"mappings":"AAAA;AAAA,OAAmB,sBAAwB,CAAC;AAC5C,OAAuB,+BAAiC,CAAC;AACzD,OAAsB,yCAA2C,CAAC;AAClE,OAAwB,+CAAiD,CAAC;AAC1E,OAA0B,6CAA+C,CAAC;AAC1E,OAAgB,2BAAO,CAAC;AACT,WAAMA,UAAU,GAASC,SAAS,EAAE;IACjDC,SAAAA,GAAG,GAAG,YAAY,CAAC;IAGnB,CAACC,WAAW,CAAC,CAAEC,QAAQ,GAAE,IAAI,CAAE,CAAC;IAAA,SAChCC,aAAa,CAACC,OAAmB,EAAV,UAAU,EAAEC,QAAwB,EAAb,aAAa,CAAA,EAAE;QAC3DC,GAAG,CAAC,IAAI,CAACN,GAAG,EAAE,yBAAyB,CAAC,CAAC;QACzC,IAAIK,QAAQ,IAAI,IAAI,EAAE;YACpB,IAAME,IAAI,GAAG,AAAIC,UAAU,EAAE,AAAC;YAC9BD,IAAI,CAAC,MAAM,CAAC,GAAG,cAAc,CAAC;YAC9BF,QAAQ,CAACI,MAAM,CAACF,IAAI,CAAC,CAAC;;;IAI1B,CAACN,WAAW,CAAC,CAAEC,QAAQ,GAAE,KAAK,CAAE,CAAC;IAAA,SACjCQ,YAAY,CAACN,OAAmB,EAAV,UAAU,GAAG,UAAU,CAAC;QAC5C,IAAMG,IAAI,GAAG,AAAIC,UAAU,EAAE,AAAC;QAC9BD,IAAI,CAAC,MAAM,CAAC,GAAG,YAAY,CAAC;QAC5B,OAAOA,IAAI,CAAC;;IAEd,kBAASI,gBAAgB,CAACC,WAAgB,EAAH,GAAG,EAAEC,UAAe,EAAH,GAAG,EAAEN,IAAY,EAAN,MAAM,EAAE;QACzE,IAAIK,WAAW,IAAId,UAAU,CAACgB,YAAY,IAAIP,IAAI,CAACQ,QAAQ,CAAC,SAAS,CAAC,EAAE;YACtET,GAAG,CAAC,IAAI,CAACN,GAAG,EAAE,wBAAY,GAAGO,IAAI,CAACS,cAAc,CAAC,SAAS,CAAC,CAAC,CAAC;;QAC9D,MAAM;YACL,KAAK,CAACL,gBAAgB,CAACC,WAAW,EAAEC,UAAU,EAAEN,IAAI,CAAC,CAAC;;;;QAtB1D,IAAOO,YAAY,GAAG,IAAI,CAAC;;CAyB5B"} \ No newline at end of file +{"version":3,"sources":["/Users/fxy/Documents/projects/GitHub/uni-app/uni-app-next/packages/playground/uts/nativeplugins/test-uniplugin/android/src/io/dcloud/uniplugin/TestModule.uts"],"names":["TestModule","UniModule","TAG","UniJSMethod","uiThread","testAsyncFunc","options","callback","log","data","JSONObject","invoke","testSyncFunc","onActivityResult","requestCode","resultCode","REQUEST_CODE","hasExtra","getStringExtra"],"mappings":"AAAA;AAAA,OAAmB,sBAAwB,CAAC;AAC5C,OAAuB,+BAAiC,CAAC;AACzD,OAAsB,yCAA2C,CAAC;AAClE,OAAwB,+CAAiD,CAAC;AAC1E,OAA0B,6CAA+C,CAAC;AAC1E,OAAgB,2BAAO,CAAC;AACT,WAAMA,UAAU,GAASC,SAAS,EAAE;IACjDC,SAAAA,GAAG,GAAG,YAAY,CAAC;IAGnB,CAACC,WAAW,CAAC,CAAEC,QAAQ,GAAE,IAAI,CAAE,CAAC;IAAA,SAChCC,aAAa,CAACC,OAAmB,EAAV,UAAU,EAAEC,QAAwB,EAAb,aAAa,CAAA,EAAE;QAC3DC,GAAG,CAAC,IAAI,CAACN,GAAG,EAAE,yBAAyB,CAAC,CAAC;QACzC,IAAIK,QAAQ,IAAI,IAAI,EAAE;YACpB,IAAME,IAAI,GAAG,AAAIC,UAAU,EAAE,AAAC;YAC9BD,IAAI,CAAC,MAAM,CAAC,GAAG,cAAc,CAAC;YAC9BF,QAAQ,CAACI,MAAM,CAACF,IAAI,CAAC,CAAC;;;IAI1B,CAACN,WAAW,CAAC,CAAEC,QAAQ,GAAE,KAAK,CAAE,CAAC;IAAA,SACjCQ,YAAY,CAACN,OAAmB,EAAV,UAAU,GAAG,UAAU,CAAC;QAC5C,IAAMG,IAAI,GAAG,AAAIC,UAAU,EAAE,AAAC;QAC9BD,IAAI,CAAC,MAAM,CAAC,GAAG,YAAY,CAAC;QAC5B,OAAOA,IAAI,CAAC;;IAEd,aAASI,gBAAgB,CAACC,WAAgB,EAAH,GAAG,EAAEC,UAAe,EAAH,GAAG,EAAEN,IAAY,EAAN,MAAM,EAAE;QACzE,IAAIK,WAAW,IAAId,UAAU,CAACgB,YAAY,IAAIP,IAAI,CAACQ,QAAQ,CAAC,SAAS,CAAC,EAAE;YACtET,GAAG,CAAC,IAAI,CAACN,GAAG,EAAE,wBAAY,GAAGO,IAAI,CAACS,cAAc,CAAC,SAAS,CAAC,CAAC,CAAC;;QAC9D,MAAM;YACL,KAAK,CAACL,gBAAgB,CAACC,WAAW,EAAEC,UAAU,EAAEN,IAAI,CAAC,CAAC;;;;QAtB1D,IAAOO,YAAY,GAAG,IAAI,CAAC;;CAyB5B"} \ No newline at end of file diff --git a/packages/playground/uts/unpackage/nativeplugins/test-uniplugin/android/src/io/dcloud/uniplugin/log.kt.map b/packages/playground/uts/unpackage/nativeplugins/test-uniplugin/android/src/io/dcloud/uniplugin/log.kt.map index a6da1cd11..21d478e0c 100644 --- a/packages/playground/uts/unpackage/nativeplugins/test-uniplugin/android/src/io/dcloud/uniplugin/log.kt.map +++ b/packages/playground/uts/unpackage/nativeplugins/test-uniplugin/android/src/io/dcloud/uniplugin/log.kt.map @@ -1 +1 @@ -{"version":3,"sources":["/Users/fxy/Documents/projects/GitHub/uni-app/uni-app-next/packages/playground/uts/nativeplugins/test-uniplugin/android/src/io/dcloud/uniplugin/log.uts"],"names":["log","tag","msg","Log","e"],"mappings":";AAAA,OAAgB,gBAAkB,CAAC;AACpB,IAASA,GAAG,CAACC,GAAW,EAAN,MAAM,EAAEC,GAAW,EAAN,MAAM,EAAE;IACpDC,GAAG,CAACC,CAAC,CAACH,GAAG,EAAEC,GAAG,CAAC,CAAC"} \ No newline at end of file +{"version":3,"sources":["/Users/fxy/Documents/projects/GitHub/uni-app/uni-app-next/packages/playground/uts/nativeplugins/test-uniplugin/android/src/io/dcloud/uniplugin/log.uts"],"names":["log","tag","msg","Log","e"],"mappings":"AAAA;AAAA,OAAgB,gBAAkB,CAAC;AACpB,IAASA,GAAG,CAACC,GAAW,EAAN,MAAM,EAAEC,GAAW,EAAN,MAAM,EAAE;IACpDC,GAAG,CAACC,CAAC,CAACH,GAAG,EAAEC,GAAG,CAAC,CAAC"} \ No newline at end of file diff --git a/packages/playground/uts/unpackage/nativeplugins/test-uniplugin/android/src/test.kt b/packages/playground/uts/unpackage/nativeplugins/test-uniplugin/android/src/test.kt new file mode 100644 index 000000000..2e832fb92 --- /dev/null +++ b/packages/playground/uts/unpackage/nativeplugins/test-uniplugin/android/src/test.kt @@ -0,0 +1,5 @@ +package test; +import android.util.Log; +fun log(tag: String, msg: String) { + Log.e(tag, msg); +} diff --git a/packages/playground/uts/unpackage/nativeplugins/test-uniplugin/android/src/test.kt.map b/packages/playground/uts/unpackage/nativeplugins/test-uniplugin/android/src/test.kt.map new file mode 100644 index 000000000..e3ca742c4 --- /dev/null +++ b/packages/playground/uts/unpackage/nativeplugins/test-uniplugin/android/src/test.kt.map @@ -0,0 +1 @@ +{"version":3,"sources":["/Users/fxy/Documents/projects/GitHub/uni-app/uni-app-next/packages/playground/uts/nativeplugins/test-uniplugin/android/src/test.uts"],"names":["log","tag","msg","Log","e"],"mappings":";AAAA,OAAgB,gBAAkB,CAAC;AACpB,IAASA,GAAG,CAACC,GAAW,EAAN,MAAM,EAAEC,GAAW,EAAN,MAAM,EAAE;IACpDC,GAAG,CAACC,CAAC,CAACH,GAAG,EAAEC,GAAG,CAAC,CAAC"} \ No newline at end of file diff --git a/packages/uni-api/src/service/plugin/push.ts b/packages/uni-api/src/service/plugin/push.ts index 78d26337d..5da52856f 100644 --- a/packages/uni-api/src/service/plugin/push.ts +++ b/packages/uni-api/src/service/plugin/push.ts @@ -24,24 +24,9 @@ interface OnPushClickCallback { let cid: string | undefined let cidErrMsg: string | undefined -function normalizePushMessage(type: 'receive' | 'click', message: unknown) { +function normalizePushMessage(message: unknown) { try { - const res = JSON.parse(message as string) as Record - if (type === 'receive') { - if (res.payload) { - if (res.aps) { - res.payload.aps = res.aps - } - return res.payload - } - } else if (type === 'click') { - delete res.type - delete res.__UUID__ - delete res.appid - if (res.aps && res.aps.alert) { - res.title = res.aps.alert.title - } - } + return JSON.parse(message as string) as Record } catch (e: any) {} return message } @@ -64,14 +49,14 @@ export function invokePushCallback( onPushMessageCallbacks.forEach((callback) => { callback({ type: 'receive', - data: normalizePushMessage('receive', args.message), + data: normalizePushMessage(args.message), }) }) } else if (args.type === 'click') { onPushMessageCallbacks.forEach((callback) => { callback({ type: 'click', - data: normalizePushMessage('click', args.message), + data: normalizePushMessage(args.message), }) }) } diff --git a/packages/uni-app-plus/dist/uni.runtime.esm.js b/packages/uni-app-plus/dist/uni.runtime.esm.js index 67eab4598..5300467e5 100644 --- a/packages/uni-app-plus/dist/uni.runtime.esm.js +++ b/packages/uni-app-plus/dist/uni.runtime.esm.js @@ -11057,25 +11057,9 @@ const getLaunchOptionsSync = defineSyncApi(API_GET_LAUNCH_OPTIONS_SYNC, () => { let cid; let cidErrMsg; -function normalizePushMessage(type, message) { +function normalizePushMessage(message) { try { - const res = JSON.parse(message); - if (type === 'receive') { - if (res.payload) { - if (res.aps) { - res.payload.aps = res.aps; - } - return res.payload; - } - } - else if (type === 'click') { - delete res.type; - delete res.__UUID__; - delete res.appid; - if (res.aps && res.aps.alert) { - res.title = res.aps.alert.title; - } - } + return JSON.parse(message); } catch (e) { } return message; @@ -11094,7 +11078,7 @@ function invokePushCallback(args) { onPushMessageCallbacks.forEach((callback) => { callback({ type: 'receive', - data: normalizePushMessage('receive', args.message), + data: normalizePushMessage(args.message), }); }); } @@ -11102,7 +11086,7 @@ function invokePushCallback(args) { onPushMessageCallbacks.forEach((callback) => { callback({ type: 'click', - data: normalizePushMessage('click', args.message), + data: normalizePushMessage(args.message), }); }); } @@ -13020,6 +13004,12 @@ const canIUse = defineSyncApi(API_CAN_I_USE, (schema) => { return false; }, CanIUseProtocol); +let deviceId; +function deviceId$1 () { + deviceId = deviceId || plus.device.uuid; + return deviceId; +} + const isIOS = plus.os.name === 'iOS'; let config; /** @@ -13282,12 +13272,6 @@ function getStatusBarStyle() { return style; } -let deviceId; -function deviceId$1 () { - deviceId = deviceId || plus.device.uuid; - return deviceId; -} - function getScreenInfo() { // 好像开发时刷新,偶发的 plus.screen.getCurrentSize 为 undefined const { resolutionWidth, resolutionHeight } = plus.screen.getCurrentSize() || { @@ -13299,13 +13283,8 @@ function getScreenInfo() { screenHeight: Math.round(resolutionHeight), }; } -const getSystemInfoSync = defineSyncApi('getSystemInfoSync', () => { - const { getSystemInfoSync } = weex.requireModule('plus'); - const info = getSystemInfoSync(); - const { deviceBrand, deviceModel, osName, osVersion, osLanguage } = info; - const brand = deviceBrand.toLowerCase(); - const _osName = osName.toLowerCase(); - const ios = _osName === 'ios'; +const getWindowInfo = defineSyncApi('getWindowInfo', () => { + const ios = plus.os.name.toLowerCase() === 'ios'; const { screenWidth, screenHeight } = getScreenInfo(); const statusBarHeight = getStatusbarHeight(); let safeAreaInsets; @@ -13365,22 +13344,13 @@ const getSystemInfoSync = defineSyncApi('getSystemInfoSync', () => { width: windowWidth - safeAreaInsets.left - safeAreaInsets.right, height: windowHeightReal - safeAreaInsets.top - safeAreaInsets.bottom, }; - return extend({ - brand: brand, - model: deviceModel, + return { pixelRatio: plus.screen.scale, screenWidth, screenHeight, windowWidth, windowHeight, statusBarHeight, - language: osLanguage, - system: `${osName} ${osVersion}`, - version: plus.runtime.innerVersion, - platform: _osName, - SDKVersion: '', - windowTop, - windowBottom, safeArea, safeAreaInsets: { top: safeAreaInsets.top, @@ -13388,11 +13358,87 @@ const getSystemInfoSync = defineSyncApi('getSystemInfoSync', () => { bottom: safeAreaInsets.bottom, left: safeAreaInsets.left, }, - deviceId: deviceId$1(), - }, info, { + windowTop, + windowBottom, + screenTop: screenHeight - windowHeight, + }; +}); + +let systemInfo; +let _initSystemInfo = true; +function weexGetSystemInfoSync() { + if (!_initSystemInfo) + return; + const { getSystemInfoSync } = weex.requireModule('plus'); + systemInfo = getSystemInfoSync(); +} +const getDeviceInfo = defineSyncApi('getDeviceInfo', () => { + weexGetSystemInfoSync(); + const { deviceBrand, deviceModel, osName, osVersion } = systemInfo; + const brand = deviceBrand.toLowerCase(); + return { deviceBrand: brand, - osName: _osName, - }); + deviceModel, + brand, + model: deviceModel, + system: `${osName === 'ios' ? 'iOS' : 'Android'} ${osVersion}`, + platform: osName, + }; +}); +const getAppBaseInfo = defineSyncApi('getAppBaseInfo', () => { + weexGetSystemInfoSync(); + const { hostPackageName, hostName, osLanguage, hostVersion, hostLanguage, hostTheme, appId, appName, appVersion, appVersionCode, } = systemInfo; + return { + SDKVersion: '', + hostSDKVersion: '', + enableDebug: false, + appId, + appName, + appVersion, + appVersionCode, + appLanguage: uni.getLocale(), + version: plus.runtime.innerVersion, + language: osLanguage, + theme: '', + hostPackageName, + hostName, + hostVersion, + hostLanguage, + hostTheme, + hostFontSizeSetting: undefined, + }; +}); +const getSystemInfoSync = defineSyncApi('getSystemInfoSync', () => { + _initSystemInfo = true; + weexGetSystemInfoSync(); + _initSystemInfo = false; + const windowInfo = getWindowInfo(); + const deviceInfo = getDeviceInfo(); + const appBaseInfo = getAppBaseInfo(); + _initSystemInfo = true; + const { osName, osLanguage, osVersion } = systemInfo; + const { pixelRatio } = windowInfo; + const osLanguageSplit = osLanguage.split('-'); + const osLanguageSplitLast = osLanguageSplit[osLanguageSplit.length - 1]; + let _osLanguage = `${osLanguageSplit[0]}${osLanguageSplitLast ? '-' + osLanguageSplitLast : ''}`; + let extraData = { + errMsg: 'getSystemInfo:ok', + fontSizeSetting: appBaseInfo.hostFontSizeSetting, + devicePixelRatio: pixelRatio, + deviceId: deviceId$1(), + uniCompileVersion: __uniConfig.compilerVersion, + uniRuntimeVersion: __uniConfig.compilerVersion, + osLanguage: _osLanguage, + }; + if (osName === 'ios') { + extraData.romName = osName; + extraData.romVersion = osVersion; + } + const _systemInfo = extend(windowInfo, systemInfo, deviceInfo, appBaseInfo, extraData); + delete _systemInfo.screenTop; + delete _systemInfo.enableDebug; + delete _systemInfo.theme; + return _systemInfo; }); const getSystemInfo = defineAsyncApi('getSystemInfo', (_, { resolve }) => { return resolve(getSystemInfoSync()); @@ -19039,6 +19085,8 @@ var uni$1 = { removeSavedFile: removeSavedFile, openDocument: openDocument, canIUse: canIUse, + getDeviceInfo: getDeviceInfo, + getAppBaseInfo: getAppBaseInfo, getSystemInfoSync: getSystemInfoSync, getSystemInfo: getSystemInfo, onCompassChange: onCompassChange, @@ -19091,6 +19139,7 @@ var uni$1 = { getScreenBrightness: getScreenBrightness, setScreenBrightness: setScreenBrightness, setKeepScreenOn: setKeepScreenOn, + getWindowInfo: getWindowInfo, getImageInfo: getImageInfo, getVideoInfo: getVideoInfo, previewImage: previewImage, diff --git a/packages/uni-h5-vue/dist/vue.runtime.cjs.js b/packages/uni-h5-vue/dist/vue.runtime.cjs.js index 64f012310..85324ce2e 100644 --- a/packages/uni-h5-vue/dist/vue.runtime.cjs.js +++ b/packages/uni-h5-vue/dist/vue.runtime.cjs.js @@ -286,7 +286,10 @@ function trackEffects(dep, debuggerEventExtraInfo) { dep.add(activeEffect); activeEffect.deps.push(dep); if (activeEffect.onTrack) { - activeEffect.onTrack(Object.assign({ effect: activeEffect }, debuggerEventExtraInfo)); + activeEffect.onTrack({ + effect: activeEffect, + ...debuggerEventExtraInfo + }); } } } @@ -366,17 +369,28 @@ function trigger(target, type, key, newValue, oldValue, oldTarget) { } function triggerEffects(dep, debuggerEventExtraInfo) { // spread into array for stabilization - for (const effect of shared.isArray(dep) ? dep : [...dep]) { - if (effect !== activeEffect || effect.allowRecurse) { - if (effect.onTrigger) { - effect.onTrigger(shared.extend({ effect }, debuggerEventExtraInfo)); - } - if (effect.scheduler) { - effect.scheduler(); - } - else { - effect.run(); - } + const effects = shared.isArray(dep) ? dep : [...dep]; + for (const effect of effects) { + if (effect.computed) { + triggerEffect(effect, debuggerEventExtraInfo); + } + } + for (const effect of effects) { + if (!effect.computed) { + triggerEffect(effect, debuggerEventExtraInfo); + } + } +} +function triggerEffect(effect, debuggerEventExtraInfo) { + if (effect !== activeEffect || effect.allowRecurse) { + if (effect.onTrigger) { + effect.onTrigger(shared.extend({ effect }, debuggerEventExtraInfo)); + } + if (effect.scheduler) { + effect.scheduler(); + } + else { + effect.run(); } } } @@ -385,6 +399,10 @@ const isNonTrackableKeys = /*#__PURE__*/ shared.makeMap(`__proto__,__v_isRef,__i const builtInSymbols = new Set( /*#__PURE__*/ Object.getOwnPropertyNames(Symbol) + // ios10.x Object.getOwnPropertyNames(Symbol) can enumerate 'arguments' and 'caller' + // but accessing them on Symbol leads to TypeError because Symbol is a strict mode + // function + .filter(key => key !== 'arguments' && key !== 'caller') .map(key => Symbol[key]) .filter(shared.isSymbol)); const get = /*#__PURE__*/ createGetter(); @@ -458,9 +476,8 @@ function createGetter(isReadonly = false, shallow = false) { return res; } if (isRef(res)) { - // ref unwrapping - does not apply for Array + integer key. - const shouldUnwrap = !targetIsArray || !shared.isIntegerKey(key); - return shouldUnwrap ? res.value : res; + // ref unwrapping - skip unwrap for Array + integer key. + return targetIsArray && shared.isIntegerKey(key) ? res : res.value; } if (shared.isObject(res)) { // Convert returned value into a proxy as well. we do the isObject check @@ -566,10 +583,12 @@ function get$1(target, key, isReadonly = false, isShallow = false) { target = target["__v_raw" /* RAW */]; const rawTarget = toRaw(target); const rawKey = toRaw(key); - if (key !== rawKey) { - !isReadonly && track(rawTarget, "get" /* GET */, key); + if (!isReadonly) { + if (key !== rawKey) { + track(rawTarget, "get" /* GET */, key); + } + track(rawTarget, "get" /* GET */, rawKey); } - !isReadonly && track(rawTarget, "get" /* GET */, rawKey); const { has } = getProto(rawTarget); const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive; if (has.call(rawTarget, key)) { @@ -588,10 +607,12 @@ function has$1(key, isReadonly = false) { const target = this["__v_raw" /* RAW */]; const rawTarget = toRaw(target); const rawKey = toRaw(key); - if (key !== rawKey) { - !isReadonly && track(rawTarget, "has" /* HAS */, key); + if (!isReadonly) { + if (key !== rawKey) { + track(rawTarget, "has" /* HAS */, key); + } + track(rawTarget, "has" /* HAS */, rawKey); } - !isReadonly && track(rawTarget, "has" /* HAS */, rawKey); return key === rawKey ? target.has(key) : target.has(key) || target.has(rawKey); @@ -917,7 +938,7 @@ function createReactiveObject(target, isReadonly, baseHandlers, collectionHandle if (existingProxy) { return existingProxy; } - // only a whitelist of value types can be observed. + // only specific value types can be observed. const targetType = getTargetType(target); if (targetType === 0 /* INVALID */) { return target; @@ -1472,6 +1493,8 @@ function flushPreFlushCbs(seen, parentJob = null) { } } function flushPostFlushCbs(seen) { + // flush any pre cbs queued during the flush (e.g. pre watchers) + flushPreFlushCbs(); if (pendingPostFlushCbs.length) { const deduped = [...new Set(pendingPostFlushCbs)]; pendingPostFlushCbs.length = 0; @@ -1736,7 +1759,6 @@ function setDevtoolsHook(hook, target) { // handle late devtools injection - only do this if we are in an actual // browser environment to avoid the timer handle stalling test runner exit // (#4815) - // eslint-disable-next-line no-restricted-globals typeof window !== 'undefined' && // some envs mock window but not fully // eslint-disable-next-line no-restricted-globals @@ -1832,7 +1854,7 @@ function emit$1(instance, event, ...rawArgs) { if (trim) { args = rawArgs.map(a => a.trim()); } - else if (number) { + if (number) { args = rawArgs.map(shared.toNumber); } } @@ -2175,6 +2197,8 @@ function renderComponentRoot(instance) { warn$1(`Runtime directive used on component with non-element root node. ` + `The directives will not function as intended.`); } + // clone before mutating since the root may be a hoisted vnode + root = cloneVNode(root); root.dirs = root.dirs ? root.dirs.concat(vnode.dirs) : vnode.dirs; } // inherit transition data @@ -2836,10 +2860,12 @@ function watchEffect(effect, options) { return doWatch(effect, null, options); } function watchPostEffect(effect, options) { - return doWatch(effect, null, (Object.assign(Object.assign({}, options), { flush: 'post' }) )); + return doWatch(effect, null, ({ ...options, flush: 'post' } + )); } function watchSyncEffect(effect, options) { - return doWatch(effect, null, (Object.assign(Object.assign({}, options), { flush: 'sync' }) )); + return doWatch(effect, null, ({ ...options, flush: 'sync' } + )); } // initial value for watchers to trigger on undefined initial values const INITIAL_WATCHER_VALUE = {}; @@ -2881,7 +2907,7 @@ function doWatch(source, cb, { immediate, deep, flush, onTrack, onTrigger } = sh } else if (shared.isArray(source)) { isMultiSource = true; - forceTrigger = source.some(isReactive); + forceTrigger = source.some(s => isReactive(s) || isShallow(s)); getter = () => source.map(s => { if (isRef(s)) { return s.value; @@ -2990,16 +3016,7 @@ function doWatch(source, cb, { immediate, deep, flush, onTrack, onTrigger } = sh } else { // default: 'pre' - scheduler = () => { - if (!instance || instance.isMounted) { - queuePreFlushCb(job); - } - else { - // with 'pre' option, the first call must happen before - // the component is mounted so it is called synchronously. - job(); - } - }; + scheduler = () => queuePreFlushCb(job); } const effect = new ReactiveEffect(getter, scheduler); { @@ -3252,6 +3269,17 @@ function resolveTransitionHooks(vnode, props, state, instance) { hook && callWithAsyncErrorHandling(hook, instance, 9 /* TRANSITION_HOOK */, args); }; + const callAsyncHook = (hook, args) => { + const done = args[1]; + callHook(hook, args); + if (shared.isArray(hook)) { + if (hook.every(hook => hook.length <= 1)) + done(); + } + else if (hook.length <= 1) { + done(); + } + }; const hooks = { mode, persisted, @@ -3310,10 +3338,7 @@ function resolveTransitionHooks(vnode, props, state, instance) { el._enterCb = undefined; }); if (hook) { - hook(el, done); - if (hook.length <= 1) { - done(); - } + callAsyncHook(hook, [el, done]); } else { done(); @@ -3347,10 +3372,7 @@ function resolveTransitionHooks(vnode, props, state, instance) { }); leavingVNodesCache[key] = vnode; if (onLeave) { - onLeave(el, done); - if (onLeave.length <= 1) { - done(); - } + callAsyncHook(onLeave, [el, done]); } else { done(); @@ -3560,7 +3582,7 @@ function defineAsyncComponent(source) { } }); } -function createInnerComp(comp, { vnode: { ref, props, children } }) { +function createInnerComp(comp, { vnode: { ref, props, children, shapeFlag }, parent }) { const vnode = createVNode(comp, props, children); // ensure inner component inherits the async wrapper's ref owner vnode.ref = ref; @@ -3632,7 +3654,10 @@ const KeepAliveImpl = { // if the internal renderer is not registered, it indicates that this is server-side rendering, // for KeepAlive, we just need to render its children if (!sharedContext.renderer) { - return () => slots.default && slots.default()[0]; // fixed by xxxxxx + return () => { + const children = slots.default && slots.default(); + return children && children.length === 1 ? children[0] : children; + }; } if (props.cache && props.max) { // fixed by xxxxxx @@ -3927,13 +3952,13 @@ function resetHookState(hooks) { function injectHook(type, hook, target = currentInstance, prepend = false) { if (target) { // fixed by xxxxxx - if (uniShared.isRootHook(type) && target.$pageInstance) { + if (uniShared.isRootHook(type)) { // 系统保留组件,如 view,app 等 if (target.type.__reserved) { return; } - if (target !== target.$pageInstance) { - target = target.$pageInstance; + if (target !== target.root) { + target = target.root; if (uniShared.isRootImmediateHook(type)) { // 作用域应该是组件还是页面?目前绑定的是页面 const proxy = target.proxy; @@ -3998,1101 +4023,1588 @@ function onErrorCaptured(hook, target = currentInstance) { injectHook("ec" /* ERROR_CAPTURED */, hook, target); } -function createDuplicateChecker() { - const cache = Object.create(null); - return (type, key) => { - if (cache[key]) { - warn$1(`${type} property "${key}" is already defined in ${cache[key]}.`); +/** +Runtime helper for applying directives to a vnode. Example usage: + +const comp = resolveComponent('comp') +const foo = resolveDirective('foo') +const bar = resolveDirective('bar') + +return withDirectives(h(comp), [ + [foo, this.x], + [bar, this.y] +]) +*/ +function validateDirectiveName(name) { + if (shared.isBuiltInDirective(name)) { + warn$1('Do not use built-in directive ids as custom directive id: ' + name); + } +} +/** + * Adds directives to a VNode. + */ +function withDirectives(vnode, directives) { + const internalInstance = currentRenderingInstance; + if (internalInstance === null) { + warn$1(`withDirectives can only be used inside render functions.`); + return vnode; + } + const instance = getExposeProxy(internalInstance) || + internalInstance.proxy; + const bindings = vnode.dirs || (vnode.dirs = []); + for (let i = 0; i < directives.length; i++) { + let [dir, value, arg, modifiers = shared.EMPTY_OBJ] = directives[i]; + if (shared.isFunction(dir)) { + dir = { + mounted: dir, + updated: dir + }; } - else { - cache[key] = type; + if (dir.deep) { + traverse(value); } - }; -} -let shouldCacheAccess = true; -function applyOptions(instance) { - const options = resolveMergedOptions(instance); - const publicThis = instance.proxy; - const ctx = instance.ctx; - // do not cache property access on public proxy during state initialization - shouldCacheAccess = false; - // call beforeCreate first before accessing other options since - // the hook may mutate resolved options (#2791) - if (options.beforeCreate) { - callHook(options.beforeCreate, instance, "bc" /* BEFORE_CREATE */); + bindings.push({ + dir, + instance, + value, + oldValue: void 0, + arg, + modifiers + }); } - const { - // state - data: dataOptions, computed: computedOptions, methods, watch: watchOptions, provide: provideOptions, inject: injectOptions, - // lifecycle - created, beforeMount, mounted, beforeUpdate, updated, activated, deactivated, beforeDestroy, beforeUnmount, destroyed, unmounted, render, renderTracked, renderTriggered, errorCaptured, serverPrefetch, - // public API - expose, inheritAttrs, - // assets - components, directives, filters } = options; - const checkDuplicateProperties = createDuplicateChecker() ; - { - const [propsOptions] = instance.propsOptions; - if (propsOptions) { - for (const key in propsOptions) { - checkDuplicateProperties("Props" /* PROPS */, key); - } + return vnode; +} +function invokeDirectiveHook(vnode, prevVNode, instance, name) { + const bindings = vnode.dirs; + const oldBindings = prevVNode && prevVNode.dirs; + for (let i = 0; i < bindings.length; i++) { + const binding = bindings[i]; + if (oldBindings) { + binding.oldValue = oldBindings[i].value; + } + let hook = binding.dir[name]; + if (hook) { + // disable tracking inside all lifecycle hooks + // since they can potentially be called inside effects. + pauseTracking(); + callWithAsyncErrorHandling(hook, instance, 8 /* DIRECTIVE_HOOK */, [ + vnode.el, + binding, + vnode, + prevVNode + ]); + resetTracking(); } } - // options initialization order (to be consistent with Vue 2): - // - props (already done outside of this function) - // - inject - // - methods - // - data (deferred since it relies on `this` access) - // - computed - // - watch (deferred since it relies on `this` access) - if (injectOptions) { - resolveInjections(injectOptions, ctx, checkDuplicateProperties, instance.appContext.config.unwrapInjectedRef); +} + +const COMPONENTS = 'components'; +const DIRECTIVES = 'directives'; +/** + * @private + */ +function resolveComponent(name, maybeSelfReference) { + return resolveAsset(COMPONENTS, name, true, maybeSelfReference) || name; +} +const NULL_DYNAMIC_COMPONENT = Symbol(); +/** + * @private + */ +function resolveDynamicComponent(component) { + if (shared.isString(component)) { + return resolveAsset(COMPONENTS, component, false) || component; } - if (methods) { - for (const key in methods) { - const methodHandler = methods[key]; - if (shared.isFunction(methodHandler)) { - // In dev mode, we use the `createRenderContext` function to define - // methods to the proxy target, and those are read-only but - // reconfigurable, so it needs to be redefined here - { - Object.defineProperty(ctx, key, { - value: methodHandler.bind(publicThis), - configurable: true, - enumerable: true, - writable: true - }); - } - { - checkDuplicateProperties("Methods" /* METHODS */, key); - } - } - else { - warn$1(`Method "${key}" has type "${typeof methodHandler}" in the component definition. ` + - `Did you reference the function correctly?`); - } - } + else { + // invalid types will fallthrough to createVNode and raise warning + return (component || NULL_DYNAMIC_COMPONENT); } - if (dataOptions) { - if (!shared.isFunction(dataOptions)) { - warn$1(`The data option must be a function. ` + - `Plain object usage is no longer supported.`); - } - const data = dataOptions.call(publicThis, publicThis); - if (shared.isPromise(data)) { - warn$1(`data() returned a Promise - note data() cannot be async; If you ` + - `intend to perform data fetching before component renders, use ` + - `async setup() + .`); +} +/** + * @private + */ +function resolveDirective(name) { + return resolveAsset(DIRECTIVES, name); +} +// implementation +function resolveAsset(type, name, warnMissing = true, maybeSelfReference = false) { + const instance = currentRenderingInstance || currentInstance; + if (instance) { + const Component = instance.type; + // explicit self name has highest priority + if (type === COMPONENTS) { + const selfName = getComponentName(Component); + if (selfName && + (selfName === name || + selfName === shared.camelize(name) || + selfName === shared.capitalize(shared.camelize(name)))) { + return Component; + } } - if (!shared.isObject(data)) { - warn$1(`data() should return an object.`); + const res = + // local registration + // check instance[type] first which is resolved for options API + resolve(instance[type] || Component[type], name) || + // global registration + resolve(instance.appContext[type], name); + if (!res && maybeSelfReference) { + // fallback to implicit self-reference + return Component; } - else { - instance.data = reactive(data); - { - for (const key in data) { - checkDuplicateProperties("Data" /* DATA */, key); - // expose data on ctx during dev - if (key[0] !== '$' && key[0] !== '_') { - Object.defineProperty(ctx, key, { - configurable: true, - enumerable: true, - get: () => data[key], - set: shared.NOOP - }); - } - } - } + if (warnMissing && !res) { + const extra = type === COMPONENTS + ? `\nIf this is a native custom element, make sure to exclude it from ` + + `component resolution via compilerOptions.isCustomElement.` + : ``; + warn$1(`Failed to resolve ${type.slice(0, -1)}: ${name}${extra}`); } + return res; } - // state initialization complete at this point - start caching access - shouldCacheAccess = true; - if (computedOptions) { - for (const key in computedOptions) { - const opt = computedOptions[key]; - const get = shared.isFunction(opt) - ? opt.bind(publicThis, publicThis) - : shared.isFunction(opt.get) - ? opt.get.bind(publicThis, publicThis) - : shared.NOOP; - if (get === shared.NOOP) { - warn$1(`Computed property "${key}" has no getter.`); - } - const set = !shared.isFunction(opt) && shared.isFunction(opt.set) - ? opt.set.bind(publicThis) - : () => { - warn$1(`Write operation failed: computed property "${key}" is readonly.`); - } - ; - const c = computed$1({ - get, - set - }); - Object.defineProperty(ctx, key, { - enumerable: true, - configurable: true, - get: () => c.value, - set: v => (c.value = v) - }); - { - checkDuplicateProperties("Computed" /* COMPUTED */, key); - } - } - } - if (watchOptions) { - for (const key in watchOptions) { - createWatcher(watchOptions[key], ctx, publicThis, key); - } - } - if (provideOptions) { - const provides = shared.isFunction(provideOptions) - ? provideOptions.call(publicThis) - : provideOptions; - Reflect.ownKeys(provides).forEach(key => { - provide(key, provides[key]); - }); - } - if (created) { - callHook(created, instance, "c" /* CREATED */); - } - function registerLifecycleHook(register, hook) { - if (shared.isArray(hook)) { - hook.forEach(_hook => register(_hook.bind(publicThis))); - } - else if (hook) { - register(hook.bind(publicThis)); - } - } - registerLifecycleHook(onBeforeMount, beforeMount); - registerLifecycleHook(onMounted, mounted); - registerLifecycleHook(onBeforeUpdate, beforeUpdate); - registerLifecycleHook(onUpdated, updated); - registerLifecycleHook(onActivated, activated); - registerLifecycleHook(onDeactivated, deactivated); - registerLifecycleHook(onErrorCaptured, errorCaptured); - registerLifecycleHook(onRenderTracked, renderTracked); - registerLifecycleHook(onRenderTriggered, renderTriggered); - registerLifecycleHook(onBeforeUnmount, beforeUnmount); - registerLifecycleHook(onUnmounted, unmounted); - registerLifecycleHook(onServerPrefetch, serverPrefetch); - if (shared.isArray(expose)) { - if (expose.length) { - const exposed = instance.exposed || (instance.exposed = {}); - expose.forEach(key => { - Object.defineProperty(exposed, key, { - get: () => publicThis[key], - set: val => (publicThis[key] = val) - }); - }); - } - else if (!instance.exposed) { - instance.exposed = {}; - } - } - // options that are handled when creating the instance but also need to be - // applied from mixins - if (render && instance.render === shared.NOOP) { - instance.render = render; - } - if (inheritAttrs != null) { - instance.inheritAttrs = inheritAttrs; - } - // asset options. - if (components) - instance.components = components; - if (directives) - instance.directives = directives; - // fixed by xxxxxx - const customApplyOptions = instance.appContext.config.globalProperties - .$applyOptions; - if (customApplyOptions) { - customApplyOptions(options, instance, publicThis); + else { + warn$1(`resolve${shared.capitalize(type.slice(0, -1))} ` + + `can only be used in render() or setup().`); } } -function resolveInjections(injectOptions, ctx, checkDuplicateProperties = shared.NOOP, unwrapRef = false) { - if (shared.isArray(injectOptions)) { - injectOptions = normalizeInject(injectOptions); - } - for (const key in injectOptions) { - const opt = injectOptions[key]; - let injected; - if (shared.isObject(opt)) { - if ('default' in opt) { - injected = inject(opt.from || key, opt.default, true /* treat default function as factory */); - } - else { - injected = inject(opt.from || key); - } - } - else { - injected = inject(opt); - } - if (isRef(injected)) { - // TODO remove the check in 3.3 - if (unwrapRef) { - Object.defineProperty(ctx, key, { - enumerable: true, - configurable: true, - get: () => injected.value, - set: v => (injected.value = v) - }); - } - else { - { - warn$1(`injected property "${key}" is a ref and will be auto-unwrapped ` + - `and no longer needs \`.value\` in the next minor release. ` + - `To opt-in to the new behavior now, ` + - `set \`app.config.unwrapInjectedRef = true\` (this config is ` + - `temporary and will not be needed in the future.)`); - } - ctx[key] = injected; - } - } - else { - ctx[key] = injected; - } - { - checkDuplicateProperties("Inject" /* INJECT */, key); +function resolve(registry, name) { + return (registry && + (registry[name] || + registry[shared.camelize(name)] || + registry[shared.capitalize(shared.camelize(name))])); +} + +/** + * Actual implementation + */ +function renderList(source, renderItem, cache, index) { + let ret; + const cached = (cache && cache[index]); + if (shared.isArray(source) || shared.isString(source)) { + ret = new Array(source.length); + for (let i = 0, l = source.length; i < l; i++) { + ret[i] = renderItem(source[i], i, undefined, cached && cached[i]); } } -} -function callHook(hook, instance, type) { - callWithAsyncErrorHandling(shared.isArray(hook) - ? hook.map(h => h.bind(instance.proxy)) - : hook.bind(instance.proxy), instance, type); -} -function createWatcher(raw, ctx, publicThis, key) { - const getter = key.includes('.') - ? createPathGetter(publicThis, key) - : () => publicThis[key]; - if (shared.isString(raw)) { - const handler = ctx[raw]; - if (shared.isFunction(handler)) { - watch(getter, handler); + else if (typeof source === 'number') { + if (!Number.isInteger(source)) { + warn$1(`The v-for range expect an integer value but got ${source}.`); } - else { - warn$1(`Invalid watch handler specified by key "${raw}"`, handler); + ret = new Array(source); + for (let i = 0; i < source; i++) { + ret[i] = renderItem(i + 1, i, undefined, cached && cached[i]); } } - else if (shared.isFunction(raw)) { - watch(getter, raw.bind(publicThis)); - } - else if (shared.isObject(raw)) { - if (shared.isArray(raw)) { - raw.forEach(r => createWatcher(r, ctx, publicThis, key)); + else if (shared.isObject(source)) { + if (source[Symbol.iterator]) { + ret = Array.from(source, (item, i) => renderItem(item, i, undefined, cached && cached[i])); } else { - const handler = shared.isFunction(raw.handler) - ? raw.handler.bind(publicThis) - : ctx[raw.handler]; - if (shared.isFunction(handler)) { - watch(getter, handler, raw); - } - else { - warn$1(`Invalid watch handler specified by key "${raw.handler}"`, handler); + const keys = Object.keys(source); + ret = new Array(keys.length); + for (let i = 0, l = keys.length; i < l; i++) { + const key = keys[i]; + ret[i] = renderItem(source[key], key, i, cached && cached[i]); } } } else { - warn$1(`Invalid watch option: "${key}"`, raw); + ret = []; } -} + if (cache) { + cache[index] = ret; + } + return ret; +} + /** - * Resolve merged options and cache it on the component. - * This is done only once per-component since the merging does not involve - * instances. + * Compiler runtime helper for creating dynamic slots object + * @private */ -function resolveMergedOptions(instance) { - const base = instance.type; - const { mixins, extends: extendsOptions } = base; - const { mixins: globalMixins, optionsCache: cache, config: { optionMergeStrategies } } = instance.appContext; - const cached = cache.get(base); - let resolved; - if (cached) { - resolved = cached; - } - else if (!globalMixins.length && !mixins && !extendsOptions) { - { - resolved = base; +function createSlots(slots, dynamicSlots) { + for (let i = 0; i < dynamicSlots.length; i++) { + const slot = dynamicSlots[i]; + // array of dynamic slot generated by