@dcloudio/uni-quickapp-webview 3.0.0-5010520260709002 → 3.0.0-5020320260806002

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1311,6 +1311,9 @@ const baseApis = {
1311
1311
  invokePushCallback,
1312
1312
  __f__,
1313
1313
  };
1314
+ function normalizeApi(name, api) {
1315
+ return api;
1316
+ }
1314
1317
  function initUni(api, protocols, platform = qa) {
1315
1318
  const wrapper = initWrapper(protocols);
1316
1319
  const UniProxyHandlers = {
@@ -1319,14 +1322,14 @@ function initUni(api, protocols, platform = qa) {
1319
1322
  return target[key];
1320
1323
  }
1321
1324
  if (hasOwn(api, key)) {
1322
- return promisify(key, api[key]);
1325
+ return normalizeApi(key, promisify(key, api[key]));
1323
1326
  }
1324
1327
  if (hasOwn(baseApis, key)) {
1325
- return promisify(key, baseApis[key]);
1328
+ return normalizeApi(key, promisify(key, baseApis[key]));
1326
1329
  }
1327
1330
  // event-api
1328
1331
  // provider-api?
1329
- return promisify(key, wrapper(key, platform[key]));
1332
+ return normalizeApi(key, promisify(key, wrapper(key, platform[key])));
1330
1333
  },
1331
1334
  };
1332
1335
  // 处理 api mp 打包后为不同js,getEventChannel 无法共享问题
@@ -277,6 +277,46 @@ function initMixinRuntimeHooks(mpOptions) {
277
277
  initHooks(mpOptions, findMixinRuntimeHooks());
278
278
  }
279
279
 
280
+ let runtimeSubpackageRoot;
281
+ const runtimeSubpackages = Object.create(null);
282
+ function resolveSubpackageRoot(root) {
283
+ return (normalizeSubpackageRoot(root) ||
284
+ normalizeSubpackageRoot(process.env.UNI_SUBPACKAGE));
285
+ }
286
+ function setRuntimeSubpackageRoot(root) {
287
+ runtimeSubpackageRoot = normalizeSubpackageRoot(root);
288
+ }
289
+ function getRuntimeSubpackageRoot() {
290
+ return runtimeSubpackageRoot;
291
+ }
292
+ function setSubpackageAppVm(root, vm, independent) {
293
+ const subpackageRoot = normalizeSubpackageRoot(root);
294
+ if (!subpackageRoot) {
295
+ return;
296
+ }
297
+ setRuntimeSubpackageRoot(subpackageRoot);
298
+ {
299
+ // 普通分包保留旧的全局存储策略,兼容 UNI_SUBPACKAGE 单独编译等历史路径。
300
+ const globalObject = qa;
301
+ (globalObject.$subpackages || (globalObject.$subpackages = {}))[subpackageRoot] = {
302
+ $vm: vm,
303
+ };
304
+ }
305
+ }
306
+ function getSubpackageAppVm() {
307
+ var _a, _b, _c;
308
+ const subpackageRoot = getRuntimeSubpackageRoot();
309
+ if (!subpackageRoot) {
310
+ return;
311
+ }
312
+ // 独立分包优先命中 runtime 内缓存;普通分包继续回退到历史的全局缓存。
313
+ return (((_a = runtimeSubpackages[subpackageRoot]) === null || _a === void 0 ? void 0 : _a.$vm) ||
314
+ ((_c = (_b = qa.$subpackages) === null || _b === void 0 ? void 0 : _b[subpackageRoot]) === null || _c === void 0 ? void 0 : _c.$vm));
315
+ }
316
+ function normalizeSubpackageRoot(root) {
317
+ return typeof root === 'string' ? root.replace(/^\/+|\/+$/g, '') : undefined;
318
+ }
319
+
280
320
  const HOOKS = [
281
321
  ON_SHOW,
282
322
  ON_HIDE,
@@ -338,7 +378,7 @@ function initCreateApp(parseAppOptions) {
338
378
  };
339
379
  }
340
380
  function initCreateSubpackageApp(parseAppOptions) {
341
- return function createApp(vm) {
381
+ return function createApp(vm, root) {
342
382
  const appOptions = parseApp(vm);
343
383
  const app = isFunction(getApp) &&
344
384
  getApp({
@@ -361,11 +401,7 @@ function initCreateSubpackageApp(parseAppOptions) {
361
401
  }
362
402
  });
363
403
  initAppLifecycle(appOptions, vm);
364
- if (process.env.UNI_SUBPACKAGE) {
365
- (qa.$subpackages || (qa.$subpackages = {}))[process.env.UNI_SUBPACKAGE] = {
366
- $vm: vm,
367
- };
368
- }
404
+ setSubpackageAppVm(resolveSubpackageRoot(root), vm);
369
405
  };
370
406
  }
371
407
  function initAppLifecycle(appOptions, vm) {
@@ -712,27 +748,50 @@ function initCreateComponent(parseOptions) {
712
748
  }
713
749
  let $createComponentFn;
714
750
  let $destroyComponentFn;
751
+ let $createComponentAppVm;
752
+ let $destroyComponentAppVm;
753
+ const componentAppVmMap = new WeakMap();
715
754
  function getAppVm() {
716
755
  if (process.env.UNI_MP_PLUGIN) {
717
756
  return qa.$vm;
718
757
  }
719
- if (process.env.UNI_SUBPACKAGE) {
720
- return qa.$subpackages[process.env.UNI_SUBPACKAGE].$vm;
758
+ const subpackageAppVm = getSubpackageAppVm();
759
+ if (subpackageAppVm) {
760
+ return subpackageAppVm;
721
761
  }
722
762
  return getApp().$vm;
723
763
  }
724
764
  function $createComponent(initialVNode, options) {
725
- if (!$createComponentFn) {
726
- $createComponentFn = getAppVm().$createComponent;
765
+ const appVm = getAppVm();
766
+ if (!$createComponentFn || $createComponentAppVm !== appVm) {
767
+ $createComponentAppVm = appVm;
768
+ $createComponentFn = appVm.$createComponent;
727
769
  }
728
770
  const proxy = $createComponentFn(initialVNode, options);
729
- return getExposeProxy(proxy.$) || proxy;
771
+ const exposeProxy = getComponentExposeProxy(proxy);
772
+ componentAppVmMap.set(proxy, appVm);
773
+ if (exposeProxy && typeof exposeProxy === 'object') {
774
+ componentAppVmMap.set(exposeProxy, appVm);
775
+ }
776
+ return exposeProxy || proxy;
730
777
  }
731
778
  function $destroyComponent(instance) {
732
- if (!$destroyComponentFn) {
733
- $destroyComponentFn = getAppVm().$destroyComponent;
779
+ const appVm = componentAppVmMap.get(instance) || getAppVm();
780
+ if (!$destroyComponentFn || $destroyComponentAppVm !== appVm) {
781
+ $destroyComponentAppVm = appVm;
782
+ $destroyComponentFn = appVm.$destroyComponent;
783
+ }
784
+ try {
785
+ return $destroyComponentFn(instance);
734
786
  }
735
- return $destroyComponentFn(instance);
787
+ finally {
788
+ componentAppVmMap.delete(instance);
789
+ }
790
+ }
791
+ function getComponentExposeProxy(proxy) {
792
+ return typeof getExposeProxy === 'function'
793
+ ? getExposeProxy(proxy.$)
794
+ : undefined;
736
795
  }
737
796
 
738
797
  function parsePage(vueOptions, parseOptions) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcloudio/uni-quickapp-webview",
3
- "version": "3.0.0-5010520260709002",
3
+ "version": "3.0.0-5020320260806002",
4
4
  "description": "uni-app quickapp-webview",
5
5
  "main": "dist/index.js",
6
6
  "files": [
@@ -23,14 +23,14 @@
23
23
  },
24
24
  "gitHead": "33e807d66e1fe47e2ee08ad9c59247e37b8884da",
25
25
  "devDependencies": {
26
- "@dcloudio/uni-mp-compiler": "3.0.0-5010520260709002"
26
+ "@dcloudio/uni-mp-compiler": "3.0.0-5020320260806002"
27
27
  },
28
28
  "dependencies": {
29
29
  "@vue/shared": "3.4.21",
30
- "@dcloudio/uni-cli-shared": "3.0.0-5010520260709002",
31
- "@dcloudio/uni-mp-vite": "3.0.0-5010520260709002",
32
- "@dcloudio/uni-mp-vue": "3.0.0-5010520260709002",
33
- "@dcloudio/uni-shared": "3.0.0-5010520260709002"
30
+ "@dcloudio/uni-cli-shared": "3.0.0-5020320260806002",
31
+ "@dcloudio/uni-mp-vite": "3.0.0-5020320260806002",
32
+ "@dcloudio/uni-mp-vue": "3.0.0-5020320260806002",
33
+ "@dcloudio/uni-shared": "3.0.0-5020320260806002"
34
34
  },
35
35
  "scripts": {
36
36
  "test": "echo \"Error: no test specified\" && exit 1"