wevu 7.4.0 → 7.5.0

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.
Files changed (227) hide show
  1. package/README.md +2 -0
  2. package/dist/dev/_virtual/{_@oxc-project_runtime@0.151.0 → _@oxc-project_runtime@0.153.0}/helpers/esm/defineProperty.mjs +1 -1
  3. package/dist/dev/_virtual/{_@oxc-project_runtime@0.151.0 → _@oxc-project_runtime@0.153.0}/helpers/esm/toPrimitive.mjs +1 -1
  4. package/dist/dev/_virtual/{_@oxc-project_runtime@0.151.0 → _@oxc-project_runtime@0.153.0}/helpers/esm/toPropertyKey.mjs +1 -1
  5. package/dist/dev/_virtual/{_@oxc-project_runtime@0.151.0 → _@oxc-project_runtime@0.153.0}/helpers/esm/typeof.mjs +1 -1
  6. package/dist/dev/package.mjs +1 -1
  7. package/dist/dev/reactivity/core.mjs +1 -1
  8. package/dist/dev/reactivity/ref.mjs +1 -1
  9. package/dist/dev/runtime/app/diagnostics.mjs +5 -1
  10. package/dist/dev/runtime/app/diagnostics.mjs.map +1 -1
  11. package/dist/dev/runtime/app/mount.mjs +8 -3
  12. package/dist/dev/runtime/app/mount.mjs.map +1 -1
  13. package/dist/dev/runtime/app/setData/commitTracker.mjs +39 -4
  14. package/dist/dev/runtime/app/setData/commitTracker.mjs.map +1 -1
  15. package/dist/dev/runtime/app/setData/observation.mjs +109 -0
  16. package/dist/dev/runtime/app/setData/observation.mjs.map +1 -0
  17. package/dist/dev/runtime/app/setData/scheduler.mjs +12 -1
  18. package/dist/dev/runtime/app/setData/scheduler.mjs.map +1 -1
  19. package/dist/dev/runtime/app/setDataOptions.mjs +1 -0
  20. package/dist/dev/runtime/app/setDataOptions.mjs.map +1 -1
  21. package/dist/dev/runtime/define/initialComputed.mjs +13 -12
  22. package/dist/dev/runtime/define/initialComputed.mjs.map +1 -1
  23. package/dist/dev/runtime/define/props.mjs +5 -1
  24. package/dist/dev/runtime/define/props.mjs.map +1 -1
  25. package/dist/dev/runtime/define/scopedSlotOptions.mjs +2 -1
  26. package/dist/dev/runtime/define/scopedSlotOptions.mjs.map +1 -1
  27. package/dist/dev/runtime/define.mjs +1 -1
  28. package/dist/dev/runtime/define.mjs.map +1 -1
  29. package/dist/dev/runtime/features/scopedSlots.mjs.map +1 -1
  30. package/dist/dev/runtime/register/component/props.mjs +14 -4
  31. package/dist/dev/runtime/register/component/props.mjs.map +1 -1
  32. package/dist/dev/runtime/register/component/registerDefinition.mjs +27 -17
  33. package/dist/dev/runtime/register/component/registerDefinition.mjs.map +1 -1
  34. package/dist/dev/runtime/register/component.mjs +2 -1
  35. package/dist/dev/runtime/register/component.mjs.map +1 -1
  36. package/dist/dev/runtime/register/runtimeInstance/methodBridge.mjs +14 -7
  37. package/dist/dev/runtime/register/runtimeInstance/methodBridge.mjs.map +1 -1
  38. package/dist/dev/runtime/register/runtimeInstance/nativeDeclaration.mjs +78 -0
  39. package/dist/dev/runtime/register/runtimeInstance/nativeDeclaration.mjs.map +1 -0
  40. package/dist/dev/runtime/register/runtimeInstance/provideContext.mjs +52 -8
  41. package/dist/dev/runtime/register/runtimeInstance/provideContext.mjs.map +1 -1
  42. package/dist/dev/runtime/register/runtimeInstance/utils.mjs.map +1 -1
  43. package/dist/dev/runtime/register/runtimeInstance.mjs +60 -19
  44. package/dist/dev/runtime/register/runtimeInstance.mjs.map +1 -1
  45. package/dist/fetch.mjs +1 -1
  46. package/dist/internal-template.mjs +1 -1
  47. package/dist/package.mjs +1 -1
  48. package/dist/reactivity/core.mjs +1 -1
  49. package/dist/reactivity/reactive/patch.mjs +1 -1
  50. package/dist/reactivity/reactive/patchState.mjs +1 -1
  51. package/dist/reactivity/ref.mjs +1 -1
  52. package/dist/reactivity/watch/helpers.mjs +1 -1
  53. package/dist/router/initialNavigation.mjs +1 -1
  54. package/dist/router/useRoute.mjs +1 -1
  55. package/dist/routerInternal/matching.mjs +1 -1
  56. package/dist/routerInternal/params.mjs +1 -1
  57. package/dist/routerInternal/path.mjs +1 -1
  58. package/dist/routerInternal/query.mjs +1 -1
  59. package/dist/routerInternal/records.mjs +1 -1
  60. package/dist/runtime/app/context.mjs +1 -1
  61. package/dist/runtime/app/diagnostics.mjs +1 -1
  62. package/dist/runtime/app/mount.mjs +1 -1
  63. package/dist/runtime/app/setData/commitTracker.d.mts +2 -1
  64. package/dist/runtime/app/setData/commitTracker.mjs +1 -1
  65. package/dist/runtime/app/setData/observation.d.mts +12 -0
  66. package/dist/runtime/app/setData/observation.mjs +1 -0
  67. package/dist/runtime/app/setData/scheduler.d.mts +1 -0
  68. package/dist/runtime/app/setData/scheduler.mjs +1 -1
  69. package/dist/runtime/app/setDataOptions.mjs +1 -1
  70. package/dist/runtime/define/initialComputed.mjs +1 -1
  71. package/dist/runtime/define/props.mjs +1 -1
  72. package/dist/runtime/define/scopedSlotOptions.mjs +1 -1
  73. package/dist/runtime/define.mjs +1 -1
  74. package/dist/runtime/diff.mjs +1 -1
  75. package/dist/runtime/features/publicLayout.mjs +1 -1
  76. package/dist/runtime/features/scopedSlots.d.mts +2 -1
  77. package/dist/runtime/jsxIsland.mjs +1 -1
  78. package/dist/runtime/pageLayout.mjs +1 -1
  79. package/dist/runtime/pageScroll.mjs +1 -1
  80. package/dist/runtime/register/component/alipayRegistration.mjs +1 -1
  81. package/dist/runtime/register/component/lifecycle.mjs +1 -1
  82. package/dist/runtime/register/component/props.mjs +1 -1
  83. package/dist/runtime/register/component/registerDefinition.mjs +1 -1
  84. package/dist/runtime/register/component/registerNativeDefinition.mjs +1 -1
  85. package/dist/runtime/register/component.mjs +1 -1
  86. package/dist/runtime/register/runtimeInstance/methodBridge.mjs +1 -1
  87. package/dist/runtime/register/runtimeInstance/nativeDeclaration.mjs +1 -0
  88. package/dist/runtime/register/runtimeInstance/provideContext.mjs +1 -1
  89. package/dist/runtime/register/runtimeInstance.d.mts +8 -4
  90. package/dist/runtime/register/runtimeInstance.mjs +1 -1
  91. package/dist/runtime/setupTracking.mjs +1 -1
  92. package/dist/runtime/templateRefs.mjs +1 -1
  93. package/dist/runtime/types/runtime.d.mts +1 -0
  94. package/dist/runtime/types/setData.d.mts +30 -0
  95. package/dist/scheduler.mjs +1 -1
  96. package/dist/web-apis.mjs +1 -1
  97. package/package.json +10 -9
  98. package/dist/dev/api/vitest/setup.d.mts +0 -1
  99. package/dist/dev/api/vitest.d.mts +0 -1
  100. package/dist/dev/api.d.mts +0 -1
  101. package/dist/dev/compiler.d.mts +0 -1
  102. package/dist/dev/fetch.d.mts +0 -9
  103. package/dist/dev/index.d.mts +0 -72
  104. package/dist/dev/internal-reactivity.d.mts +0 -18
  105. package/dist/dev/internal-runtime.d.mts +0 -45
  106. package/dist/dev/internal-template.d.mts +0 -2
  107. package/dist/dev/jsxTypes.d.mts +0 -9
  108. package/dist/dev/macros/shared.d.mts +0 -83
  109. package/dist/dev/macros.d.mts +0 -71
  110. package/dist/dev/reactivity/asyncDerivation.d.mts +0 -41
  111. package/dist/dev/reactivity/computed.d.mts +0 -25
  112. package/dist/dev/reactivity/core.d.mts +0 -35
  113. package/dist/dev/reactivity/index.d.mts +0 -16
  114. package/dist/dev/reactivity/reactive/mutation.d.mts +0 -21
  115. package/dist/dev/reactivity/reactive/patch.d.mts +0 -18
  116. package/dist/dev/reactivity/reactive/shallow.d.mts +0 -22
  117. package/dist/dev/reactivity/reactive/shared.d.mts +0 -4
  118. package/dist/dev/reactivity/reactive.d.mts +0 -42
  119. package/dist/dev/reactivity/readonly.d.mts +0 -27
  120. package/dist/dev/reactivity/ref.d.mts +0 -27
  121. package/dist/dev/reactivity/shallowRef.d.mts +0 -19
  122. package/dist/dev/reactivity/toRefs.d.mts +0 -43
  123. package/dist/dev/reactivity/traverse.d.mts +0 -8
  124. package/dist/dev/reactivity/watch/types.d.mts +0 -43
  125. package/dist/dev/reactivity/watch.d.mts +0 -22
  126. package/dist/dev/router/auto-routes.d.mts +0 -8
  127. package/dist/dev/router/createRouter.d.mts +0 -9
  128. package/dist/dev/router/navigationCore.d.mts +0 -7
  129. package/dist/dev/router/resolve.d.mts +0 -7
  130. package/dist/dev/router/routeSync.d.mts +0 -2
  131. package/dist/dev/router/scrollRestoration/adapters.d.mts +0 -8
  132. package/dist/dev/router/scrollRestoration/controller.d.mts +0 -8
  133. package/dist/dev/router/scrollRestoration/host.d.mts +0 -3
  134. package/dist/dev/router/scrollRestoration/index.d.mts +0 -9
  135. package/dist/dev/router/scrollRestoration/types.d.mts +0 -61
  136. package/dist/dev/router/types.d.mts +0 -267
  137. package/dist/dev/router/useRoute.d.mts +0 -20
  138. package/dist/dev/router/useRouter.d.mts +0 -9
  139. package/dist/dev/router.d.mts +0 -30
  140. package/dist/dev/routerInternal/location.d.mts +0 -2
  141. package/dist/dev/routerInternal/matching.d.mts +0 -2
  142. package/dist/dev/routerInternal/params.d.mts +0 -2
  143. package/dist/dev/routerInternal/query.d.mts +0 -7
  144. package/dist/dev/routerInternal/records.d.mts +0 -2
  145. package/dist/dev/routerInternal/recordsWarnings.d.mts +0 -2
  146. package/dist/dev/routerInternal/shared.d.mts +0 -9
  147. package/dist/dev/routerInternal/snapshots.d.mts +0 -2
  148. package/dist/dev/routerInternal/types.d.mts +0 -9
  149. package/dist/dev/runtime/app/pending.d.mts +0 -10
  150. package/dist/dev/runtime/app/setData/commitTracker.d.mts +0 -13
  151. package/dist/dev/runtime/app/setData/scheduler.d.mts +0 -51
  152. package/dist/dev/runtime/app.d.mts +0 -8
  153. package/dist/dev/runtime/capabilities.d.mts +0 -78
  154. package/dist/dev/runtime/css.d.mts +0 -14
  155. package/dist/dev/runtime/defaults.d.mts +0 -12
  156. package/dist/dev/runtime/define.d.mts +0 -118
  157. package/dist/dev/runtime/disposables.d.mts +0 -31
  158. package/dist/dev/runtime/elementIntersectionObserver.d.mts +0 -26
  159. package/dist/dev/runtime/features/inlineEvents.d.mts +0 -7
  160. package/dist/dev/runtime/features/jsxIslands.d.mts +0 -7
  161. package/dist/dev/runtime/features/layout.d.mts +0 -7
  162. package/dist/dev/runtime/features/patchStrategy.d.mts +0 -7
  163. package/dist/dev/runtime/features/publicLayout.d.mts +0 -24
  164. package/dist/dev/runtime/features/scopedSlots.d.mts +0 -23
  165. package/dist/dev/runtime/features/setDataHighFrequencyWarning.d.mts +0 -7
  166. package/dist/dev/runtime/features/templateRefs.d.mts +0 -7
  167. package/dist/dev/runtime/hooks/base.d.mts +0 -27
  168. package/dist/dev/runtime/hooks/register.d.mts +0 -30
  169. package/dist/dev/runtime/hooks/vue.d.mts +0 -52
  170. package/dist/dev/runtime/hooks.d.mts +0 -4
  171. package/dist/dev/runtime/index.d.mts +0 -46
  172. package/dist/dev/runtime/intersectionObserver.d.mts +0 -14
  173. package/dist/dev/runtime/jsxIsland.d.mts +0 -37
  174. package/dist/dev/runtime/layoutBridge.d.mts +0 -55
  175. package/dist/dev/runtime/noSetData.d.mts +0 -5
  176. package/dist/dev/runtime/pageEnvironment.d.mts +0 -50
  177. package/dist/dev/runtime/pageLayout.d.mts +0 -25
  178. package/dist/dev/runtime/pageScroll.d.mts +0 -29
  179. package/dist/dev/runtime/provide.d.mts +0 -60
  180. package/dist/dev/runtime/provideStore.d.mts +0 -7
  181. package/dist/dev/runtime/publicRuntime.d.mts +0 -22
  182. package/dist/dev/runtime/pullDownRefresh.d.mts +0 -12
  183. package/dist/dev/runtime/register/app.d.mts +0 -14
  184. package/dist/dev/runtime/register/component.d.mts +0 -17
  185. package/dist/dev/runtime/register/inline.d.mts +0 -15
  186. package/dist/dev/runtime/register/runtimeInstance.d.mts +0 -26
  187. package/dist/dev/runtime/register/setup.d.mts +0 -11
  188. package/dist/dev/runtime/register/watch.d.mts +0 -12
  189. package/dist/dev/runtime/register.d.mts +0 -5
  190. package/dist/dev/runtime/selectorQuery.d.mts +0 -54
  191. package/dist/dev/runtime/template.d.mts +0 -6
  192. package/dist/dev/runtime/templateRefTypes.d.mts +0 -12
  193. package/dist/dev/runtime/types/core.d.mts +0 -35
  194. package/dist/dev/runtime/types/miniprogram.d.mts +0 -84
  195. package/dist/dev/runtime/types/miniprogramHost.d.mts +0 -45
  196. package/dist/dev/runtime/types/miniprogramHostSources.d.mts +0 -112
  197. package/dist/dev/runtime/types/options.d.mts +0 -138
  198. package/dist/dev/runtime/types/props/propTypes.d.mts +0 -79
  199. package/dist/dev/runtime/types/props/router.d.mts +0 -51
  200. package/dist/dev/runtime/types/props/setup.d.mts +0 -96
  201. package/dist/dev/runtime/types/props.d.mts +0 -4
  202. package/dist/dev/runtime/types/runtime.d.mts +0 -59
  203. package/dist/dev/runtime/types/setData.d.mts +0 -237
  204. package/dist/dev/runtime/types.d.mts +0 -29
  205. package/dist/dev/runtime/uniAppHost.d.mts +0 -8
  206. package/dist/dev/runtime/updatePerformance.d.mts +0 -13
  207. package/dist/dev/runtime/use.d.mts +0 -13
  208. package/dist/dev/runtime/vueCompat/context.d.mts +0 -8
  209. package/dist/dev/runtime/vueCompat/model.d.mts +0 -30
  210. package/dist/dev/runtime/vueCompat/router.d.mts +0 -29
  211. package/dist/dev/runtime/vueCompat/templateRef.d.mts +0 -9
  212. package/dist/dev/runtime/vueCompat.d.mts +0 -5
  213. package/dist/dev/scheduler.d.mts +0 -4
  214. package/dist/dev/store/define.d.mts +0 -8
  215. package/dist/dev/store/manager.d.mts +0 -16
  216. package/dist/dev/store/storeToRefs.d.mts +0 -11
  217. package/dist/dev/store/types.d.mts +0 -106
  218. package/dist/dev/store.d.mts +0 -5
  219. package/dist/dev/version.d.mts +0 -4
  220. package/dist/dev/vue-augment.d.mts +0 -8
  221. package/dist/dev/vue-demi.d.mts +0 -87
  222. package/dist/dev/vue-types.d.mts +0 -19
  223. package/dist/dev/web-apis.d.mts +0 -3
  224. /package/dist/_virtual/{_@oxc-project_runtime@0.151.0 → _@oxc-project_runtime@0.153.0}/helpers/esm/defineProperty.mjs +0 -0
  225. /package/dist/_virtual/{_@oxc-project_runtime@0.151.0 → _@oxc-project_runtime@0.153.0}/helpers/esm/toPrimitive.mjs +0 -0
  226. /package/dist/_virtual/{_@oxc-project_runtime@0.151.0 → _@oxc-project_runtime@0.153.0}/helpers/esm/toPropertyKey.mjs +0 -0
  227. /package/dist/_virtual/{_@oxc-project_runtime@0.151.0 → _@oxc-project_runtime@0.153.0}/helpers/esm/typeof.mjs +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"methodBridge.mjs","names":[],"sources":["../../../../../src/runtime/register/runtimeInstance/methodBridge.ts"],"sourcesContent":["import type { InternalRuntimeState, RuntimeInstance } from '../../types'\nimport type { SetupInstanceMethodName } from './setupContext'\nimport {\n WEVU_NATIVE_INSTANCE_KEY,\n WEVU_PUBLIC_RUNTIME_KEY,\n} from '@weapp-core/constants'\nimport { isNativeBridgeMethod } from '../../nativeBridge'\nimport { setupInstanceMethodNames } from './setupContext'\n\nfunction hasNativeApis(instance: unknown) {\n if (!instance || typeof instance !== 'object') {\n return false\n }\n return typeof (instance as any).triggerEvent === 'function'\n || typeof (instance as any).createSelectorQuery === 'function'\n || typeof (instance as any).createIntersectionObserver === 'function'\n || typeof (instance as any).setData === 'function'\n}\n\nfunction isBridgeMethod(runtime: RuntimeInstance<any, any, any>, instance: any, methodName: 'triggerEvent' | 'createSelectorQuery' | 'createIntersectionObserver' | 'setData') {\n const instanceMethod = instance?.[methodName]\n if (typeof instanceMethod !== 'function') {\n return false\n }\n if (isNativeBridgeMethod(instanceMethod)) {\n return true\n }\n const runtimeProxy = runtime?.proxy as Record<string, any> | undefined\n return typeof runtimeProxy?.[methodName] === 'function' && instanceMethod === runtimeProxy[methodName]\n}\n\nfunction syncRuntimeNativeInstance(runtime: RuntimeInstance<any, any, any>, instance: unknown) {\n if (!runtime || !hasNativeApis(instance)) {\n return\n }\n if (instance === runtime.proxy) {\n return\n }\n const nativeCandidate = instance as Record<string, any>\n if (\n isBridgeMethod(runtime, nativeCandidate, 'triggerEvent')\n || isBridgeMethod(runtime, nativeCandidate, 'createSelectorQuery')\n || isBridgeMethod(runtime, nativeCandidate, 'createIntersectionObserver')\n || isBridgeMethod(runtime, nativeCandidate, 'setData')\n ) {\n return\n }\n const runtimeState = runtime.state\n if (!runtimeState || typeof runtimeState !== 'object') {\n return\n }\n try {\n Object.defineProperty(runtimeState, WEVU_NATIVE_INSTANCE_KEY, {\n value: nativeCandidate,\n configurable: true,\n enumerable: false,\n writable: true,\n })\n }\n catch {\n ;(runtimeState as any)[WEVU_NATIVE_INSTANCE_KEY] = nativeCandidate\n }\n}\n\nexport function bridgeRuntimeMethodsToTarget(\n target: InternalRuntimeState,\n runtime: RuntimeInstance<any, any, any>,\n) {\n try {\n const methods = (runtime.methods as unknown) as Record<string, any>\n for (const name of Object.keys(methods)) {\n if (setupInstanceMethodNames.includes(name as SetupInstanceMethodName)) {\n continue\n }\n if (typeof (target as any)[name] !== 'function') {\n ;(target as any)[name] = function bridged(this: any, ...args: any[]) {\n const runtime = this[WEVU_PUBLIC_RUNTIME_KEY] ?? target[WEVU_PUBLIC_RUNTIME_KEY]\n syncRuntimeNativeInstance(runtime, this)\n const bound = (runtime?.methods as any)?.[name]\n if (typeof bound === 'function') {\n return bound.apply(runtime.proxy, args)\n }\n }\n }\n }\n }\n catch {\n // 桥接过程中若发生错误(如目标被封装)则忽略,避免阻断后续流程\n }\n}\n"],"mappings":";;;;;AASA,SAAS,cAAc,UAAmB;CACxC,IAAI,CAAC,YAAY,OAAO,aAAa,UACnC,OAAO;CAET,OAAO,OAAQ,SAAiB,iBAAiB,cAC5C,OAAQ,SAAiB,wBAAwB,cACjD,OAAQ,SAAiB,+BAA+B,cACxD,OAAQ,SAAiB,YAAY;AAC5C;AAEA,SAAS,eAAe,SAAyC,UAAe,YAA+F;CAC7K,MAAM,iBAAiB,WAAW;CAClC,IAAI,OAAO,mBAAmB,YAC5B,OAAO;CAET,IAAI,qBAAqB,cAAc,GACrC,OAAO;CAET,MAAM,eAAe,SAAS;CAC9B,OAAO,OAAO,eAAe,gBAAgB,cAAc,mBAAmB,aAAa;AAC7F;AAEA,SAAS,0BAA0B,SAAyC,UAAmB;CAC7F,IAAI,CAAC,WAAW,CAAC,cAAc,QAAQ,GACrC;CAEF,IAAI,aAAa,QAAQ,OACvB;CAEF,MAAM,kBAAkB;CACxB,IACE,eAAe,SAAS,iBAAiB,cAAc,KACpD,eAAe,SAAS,iBAAiB,qBAAqB,KAC9D,eAAe,SAAS,iBAAiB,4BAA4B,KACrE,eAAe,SAAS,iBAAiB,SAAS,GAErD;CAEF,MAAM,eAAe,QAAQ;CAC7B,IAAI,CAAC,gBAAgB,OAAO,iBAAiB,UAC3C;CAEF,IAAI;EACF,OAAO,eAAe,cAAc,0BAA0B;GAC5D,OAAO;GACP,cAAc;GACd,YAAY;GACZ,UAAU;EACZ,CAAC;CACH,QACM;EACH,AAAC,aAAqB,4BAA4B;CACrD;AACF;AAEA,SAAgB,6BACd,QACA,SACA;CACA,IAAI;EACF,MAAM,UAAW,QAAQ;EACzB,KAAK,MAAM,QAAQ,OAAO,KAAK,OAAO,GAAG;GACvC,IAAI,yBAAyB,SAAS,IAA+B,GACnE;GAEF,IAAI,OAAQ,OAAe,UAAU,YAClC,AAAC,OAAe,QAAQ,SAAS,QAAmB,GAAG,MAAa;IACnE,MAAM,UAAU,KAAK,4BAA4B,OAAO;IACxD,0BAA0B,SAAS,IAAI;IACvC,MAAM,SAAS,SAAS,QAAO,GAAW;IAC1C,IAAI,OAAO,UAAU,YACnB,OAAO,MAAM,MAAM,QAAQ,OAAO,IAAI;GAE1C;EAEJ;CACF,QACM,CAEN;AACF"}
1
+ {"version":3,"file":"methodBridge.mjs","names":[],"sources":["../../../../../src/runtime/register/runtimeInstance/methodBridge.ts"],"sourcesContent":["import type { InternalRuntimeState, RuntimeInstance } from '../../types'\nimport type { SetupInstanceMethodName } from './setupContext'\nimport {\n WEVU_HOST_INSTALL_METHOD_KEY,\n WEVU_NATIVE_INSTANCE_KEY,\n WEVU_PUBLIC_RUNTIME_KEY,\n} from '@weapp-core/constants'\nimport { isNativeBridgeMethod } from '../../nativeBridge'\nimport { setupInstanceMethodNames } from './setupContext'\n\nfunction hasNativeApis(instance: unknown) {\n if (!instance || typeof instance !== 'object') {\n return false\n }\n return typeof (instance as any).triggerEvent === 'function'\n || typeof (instance as any).createSelectorQuery === 'function'\n || typeof (instance as any).createIntersectionObserver === 'function'\n || typeof (instance as any).setData === 'function'\n}\n\nfunction isBridgeMethod(runtime: RuntimeInstance<any, any, any>, instance: any, methodName: 'triggerEvent' | 'createSelectorQuery' | 'createIntersectionObserver' | 'setData') {\n const instanceMethod = instance?.[methodName]\n if (typeof instanceMethod !== 'function') {\n return false\n }\n if (isNativeBridgeMethod(instanceMethod)) {\n return true\n }\n const runtimeProxy = runtime?.proxy as Record<string, any> | undefined\n return typeof runtimeProxy?.[methodName] === 'function' && instanceMethod === runtimeProxy[methodName]\n}\n\nfunction syncRuntimeNativeInstance(runtime: RuntimeInstance<any, any, any>, instance: unknown) {\n if (!runtime || !hasNativeApis(instance)) {\n return\n }\n if (instance === runtime.proxy) {\n return\n }\n const nativeCandidate = instance as Record<string, any>\n if (\n isBridgeMethod(runtime, nativeCandidate, 'triggerEvent')\n || isBridgeMethod(runtime, nativeCandidate, 'createSelectorQuery')\n || isBridgeMethod(runtime, nativeCandidate, 'createIntersectionObserver')\n || isBridgeMethod(runtime, nativeCandidate, 'setData')\n ) {\n return\n }\n const runtimeState = runtime.state\n if (!runtimeState || typeof runtimeState !== 'object') {\n return\n }\n try {\n Object.defineProperty(runtimeState, WEVU_NATIVE_INSTANCE_KEY, {\n value: nativeCandidate,\n configurable: true,\n enumerable: false,\n writable: true,\n })\n }\n catch {\n ;(runtimeState as any)[WEVU_NATIVE_INSTANCE_KEY] = nativeCandidate\n }\n}\n\nexport function bridgeRuntimeMethodsToTarget(\n target: InternalRuntimeState,\n runtime: RuntimeInstance<any, any, any>,\n) {\n try {\n const methods = runtime.methods as Record<string, (...args: unknown[]) => unknown>\n const installMethods: unknown = Reflect.get(target, WEVU_HOST_INSTALL_METHOD_KEY)\n const hostMethods: typeof methods | undefined = typeof installMethods === 'function' ? {} : undefined\n for (const name of Object.keys(methods)) {\n if (setupInstanceMethodNames.includes(name as SetupInstanceMethodName)) {\n continue\n }\n if (hostMethods || typeof (target as any)[name] !== 'function') {\n const bridged = function (this: any, ...args: any[]) {\n const runtime = this[WEVU_PUBLIC_RUNTIME_KEY] ?? target[WEVU_PUBLIC_RUNTIME_KEY]\n syncRuntimeNativeInstance(runtime, this)\n const bound = (runtime?.methods as any)?.[name]\n if (typeof bound === 'function') {\n return bound.apply(runtime.proxy, args)\n }\n }\n if (hostMethods) {\n hostMethods[name] = bridged\n }\n else {\n ;(target as any)[name] = bridged\n }\n }\n }\n if (typeof installMethods === 'function') {\n installMethods.call(target, hostMethods)\n }\n }\n catch {\n // 桥接过程中若发生错误(如目标被封装)则忽略,避免阻断后续流程\n }\n}\n"],"mappings":";;;;;AAUA,SAAS,cAAc,UAAmB;CACxC,IAAI,CAAC,YAAY,OAAO,aAAa,UACnC,OAAO;CAET,OAAO,OAAQ,SAAiB,iBAAiB,cAC5C,OAAQ,SAAiB,wBAAwB,cACjD,OAAQ,SAAiB,+BAA+B,cACxD,OAAQ,SAAiB,YAAY;AAC5C;AAEA,SAAS,eAAe,SAAyC,UAAe,YAA+F;CAC7K,MAAM,iBAAiB,WAAW;CAClC,IAAI,OAAO,mBAAmB,YAC5B,OAAO;CAET,IAAI,qBAAqB,cAAc,GACrC,OAAO;CAET,MAAM,eAAe,SAAS;CAC9B,OAAO,OAAO,eAAe,gBAAgB,cAAc,mBAAmB,aAAa;AAC7F;AAEA,SAAS,0BAA0B,SAAyC,UAAmB;CAC7F,IAAI,CAAC,WAAW,CAAC,cAAc,QAAQ,GACrC;CAEF,IAAI,aAAa,QAAQ,OACvB;CAEF,MAAM,kBAAkB;CACxB,IACE,eAAe,SAAS,iBAAiB,cAAc,KACpD,eAAe,SAAS,iBAAiB,qBAAqB,KAC9D,eAAe,SAAS,iBAAiB,4BAA4B,KACrE,eAAe,SAAS,iBAAiB,SAAS,GAErD;CAEF,MAAM,eAAe,QAAQ;CAC7B,IAAI,CAAC,gBAAgB,OAAO,iBAAiB,UAC3C;CAEF,IAAI;EACF,OAAO,eAAe,cAAc,0BAA0B;GAC5D,OAAO;GACP,cAAc;GACd,YAAY;GACZ,UAAU;EACZ,CAAC;CACH,QACM;EACH,AAAC,aAAqB,4BAA4B;CACrD;AACF;AAEA,SAAgB,6BACd,QACA,SACA;CACA,IAAI;EACF,MAAM,UAAU,QAAQ;EACxB,MAAM,iBAA0B,QAAQ,IAAI,QAAQ,4BAA4B;EAChF,MAAM,cAA0C,OAAO,mBAAmB,aAAa,CAAC,IAAI;EAC5F,KAAK,MAAM,QAAQ,OAAO,KAAK,OAAO,GAAG;GACvC,IAAI,yBAAyB,SAAS,IAA+B,GACnE;GAEF,IAAI,eAAe,OAAQ,OAAe,UAAU,YAAY;IAC9D,MAAM,UAAU,SAAqB,GAAG,MAAa;KACnD,MAAM,UAAU,KAAK,4BAA4B,OAAO;KACxD,0BAA0B,SAAS,IAAI;KACvC,MAAM,SAAS,SAAS,QAAO,GAAW;KAC1C,IAAI,OAAO,UAAU,YACnB,OAAO,MAAM,MAAM,QAAQ,OAAO,IAAI;IAE1C;IACA,IAAI,aACF,YAAY,QAAQ;SAGnB,AAAC,OAAe,QAAQ;GAE7B;EACF;EACA,IAAI,OAAO,mBAAmB,YAC5B,eAAe,KAAK,QAAQ,WAAW;CAE3C,QACM,CAEN;AACF"}
@@ -0,0 +1,78 @@
1
+ import { WEVU_NATIVE_DECLARATION_ADDRESS_PROP, WEVU_NATIVE_DECLARATION_EVENT } from "@weapp-core/constants";
2
+
3
+ //#region src/runtime/register/runtimeInstance/nativeDeclaration.ts
4
+ const addressKey = /* @__PURE__ */ Symbol("address");
5
+ const registrationKey = /* @__PURE__ */ Symbol("registration");
6
+ const indexKey = /* @__PURE__ */ Symbol("index");
7
+ function parseAddress(value) {
8
+ return Array.isArray(value) && value.length === 2 && typeof value[0] === "string" && value[0] !== "" && typeof value[1] === "string" ? value : void 0;
9
+ }
10
+ function readAddress(target) {
11
+ return target[addressKey] === void 0 ? parseAddress(target.properties?.[WEVU_NATIVE_DECLARATION_ADDRESS_PROP]) : target[addressKey] ?? void 0;
12
+ }
13
+ function removeRegistration(registration) {
14
+ const { owner, target, selfKey } = registration;
15
+ if (owner[indexKey]?.get(selfKey) === registration) owner[indexKey]?.delete(selfKey);
16
+ if (target[registrationKey] === registration) delete target[registrationKey];
17
+ }
18
+ function installRegistration(registration) {
19
+ const { owner, target, selfKey } = registration;
20
+ const index = owner[indexKey] ?? (owner[indexKey] = /* @__PURE__ */ new Map());
21
+ const previous = index.get(selfKey);
22
+ if (previous && previous !== registration) removeRegistration(previous);
23
+ index.set(selfKey, registration);
24
+ target[registrationKey] = registration;
25
+ }
26
+ function updateNativeDeclarationAddress(target, newValue) {
27
+ const address = parseAddress(newValue);
28
+ target[addressKey] = address ?? null;
29
+ const registration = target[registrationKey];
30
+ if (!registration || registration.selfKey === address?.[0]) return;
31
+ removeRegistration(registration);
32
+ if (address) {
33
+ registration.selfKey = address[0];
34
+ installRegistration(registration);
35
+ }
36
+ }
37
+ function resolveNativeDeclarationHost(owner, key) {
38
+ return key ? owner[indexKey]?.get(key)?.target : owner;
39
+ }
40
+ /** 编译后的直接事件必须在原生方法 this 上注册,不能经过公开 export 或 setup 方法代理。 */
41
+ function receiveNativeDeclaration(event) {
42
+ if (typeof event.detail?.register === "function") event.detail.register(this);
43
+ }
44
+ function resolveNativeDeclarationParent(target) {
45
+ const address = readAddress(target);
46
+ if (!address || typeof target.triggerEvent !== "function") return;
47
+ let parent;
48
+ target.triggerEvent(WEVU_NATIVE_DECLARATION_EVENT, { register(owner) {
49
+ if (owner === target) return;
50
+ const previous = target[registrationKey];
51
+ if (previous) removeRegistration(previous);
52
+ installRegistration({
53
+ owner,
54
+ target,
55
+ selfKey: address[0]
56
+ });
57
+ parent = resolveNativeDeclarationHost(owner, address[1]);
58
+ } }, {
59
+ bubbles: false,
60
+ composed: false
61
+ });
62
+ return parent;
63
+ }
64
+ function releaseNativeDeclaration(target, preserveOwnerIndex = false) {
65
+ const registration = target[registrationKey];
66
+ if (registration) removeRegistration(registration);
67
+ if (preserveOwnerIndex) return;
68
+ const index = target[indexKey];
69
+ if (index) {
70
+ for (const child of index.values()) removeRegistration(child);
71
+ delete target[indexKey];
72
+ }
73
+ delete target[addressKey];
74
+ }
75
+
76
+ //#endregion
77
+ export { receiveNativeDeclaration, releaseNativeDeclaration, resolveNativeDeclarationHost, resolveNativeDeclarationParent, updateNativeDeclarationAddress };
78
+ //# sourceMappingURL=nativeDeclaration.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nativeDeclaration.mjs","names":[],"sources":["../../../../../src/runtime/register/runtimeInstance/nativeDeclaration.ts"],"sourcesContent":["import type { InternalRuntimeState } from '../../types'\nimport {\n WEVU_NATIVE_DECLARATION_ADDRESS_PROP,\n WEVU_NATIVE_DECLARATION_EVENT,\n} from '@weapp-core/constants'\n\n// 平台条件须在调用点直接读取 import.meta.env.PLATFORM;跨模块布尔常量在发布产物\n// 压缩后不一定被下游折叠,会导致未启用原生协议的目标仍保留本模块。\n\nconst addressKey = /* @__PURE__ */ Symbol('address')\nconst registrationKey = /* @__PURE__ */ Symbol('registration')\nconst indexKey = /* @__PURE__ */ Symbol('index')\n\ntype NativeDeclarationAddress = readonly [selfKey: string, parentKey: string]\ntype DeclarationHost = InternalRuntimeState & {\n [addressKey]?: NativeDeclarationAddress | null\n [registrationKey]?: NativeDeclarationRegistration\n [indexKey]?: Map<string, NativeDeclarationRegistration>\n}\n\ninterface NativeDeclarationRegistration {\n owner: DeclarationHost\n target: DeclarationHost\n selfKey: string\n}\n\ninterface NativeDeclarationDetail {\n register: (owner: InternalRuntimeState) => void\n}\n\nfunction parseAddress(value: unknown): NativeDeclarationAddress | undefined {\n return Array.isArray(value) && value.length === 2\n && typeof value[0] === 'string' && value[0] !== '' && typeof value[1] === 'string'\n ? value as unknown as NativeDeclarationAddress\n : undefined\n}\n\nfunction readAddress(target: DeclarationHost) {\n return target[addressKey] === undefined\n ? parseAddress(target.properties?.[WEVU_NATIVE_DECLARATION_ADDRESS_PROP])\n : target[addressKey] ?? undefined\n}\n\nfunction removeRegistration(registration: NativeDeclarationRegistration) {\n const { owner, target, selfKey } = registration\n if (owner[indexKey]?.get(selfKey) === registration) {\n owner[indexKey]?.delete(selfKey)\n }\n if (target[registrationKey] === registration) {\n delete target[registrationKey]\n }\n}\n\nfunction installRegistration(registration: NativeDeclarationRegistration) {\n const { owner, target, selfKey } = registration\n const index = owner[indexKey] ??= new Map()\n const previous = index.get(selfKey)\n // 原生替换允许先 attached 后 detached;旧实例不能删掉或重新索引替代者。\n if (previous && previous !== registration) {\n removeRegistration(previous)\n }\n index.set(selfKey, registration)\n target[registrationKey] = registration\n}\n\nexport function updateNativeDeclarationAddress(target: DeclarationHost, newValue: unknown) {\n const address = parseAddress(newValue)\n target[addressKey] = address ?? null\n const registration = target[registrationKey]\n if (!registration || registration.selfKey === address?.[0]) {\n return\n }\n removeRegistration(registration)\n if (address) {\n registration.selfKey = address[0]\n installRegistration(registration)\n }\n}\n\nexport function resolveNativeDeclarationHost(owner: DeclarationHost, key: string): InternalRuntimeState | undefined {\n return key ? owner[indexKey]?.get(key)?.target : owner\n}\n\n/** 编译后的直接事件必须在原生方法 this 上注册,不能经过公开 export 或 setup 方法代理。 */\nexport function receiveNativeDeclaration(this: InternalRuntimeState, event: { detail?: NativeDeclarationDetail }) {\n if (typeof event.detail?.register === 'function') {\n event.detail.register(this)\n }\n}\n\nexport function resolveNativeDeclarationParent(target: DeclarationHost): InternalRuntimeState | undefined {\n const address = readAddress(target)\n if (!address || typeof target.triggerEvent !== 'function') {\n return undefined\n }\n let parent: InternalRuntimeState | undefined\n target.triggerEvent(WEVU_NATIVE_DECLARATION_EVENT, {\n register(owner: DeclarationHost) {\n if (owner === target) {\n return\n }\n const previous = target[registrationKey]\n if (previous) {\n removeRegistration(previous)\n }\n installRegistration({ owner, target, selfKey: address[0] })\n parent = resolveNativeDeclarationHost(owner, address[1])\n },\n } satisfies NativeDeclarationDetail, { bubbles: false, composed: false })\n return parent\n}\n\nexport function releaseNativeDeclaration(target: DeclarationHost, preserveOwnerIndex = false) {\n const registration = target[registrationKey]\n if (registration) {\n removeRegistration(registration)\n }\n if (preserveOwnerIndex) {\n return\n }\n const index = target[indexKey]\n if (index) {\n for (const child of index.values()) {\n removeRegistration(child)\n }\n delete target[indexKey]\n }\n delete target[addressKey]\n}\n"],"mappings":";;;AASA,MAAM,aAA6B,uBAAO,SAAS;AACnD,MAAM,kBAAkC,uBAAO,cAAc;AAC7D,MAAM,WAA2B,uBAAO,OAAO;AAmB/C,SAAS,aAAa,OAAsD;CAC1E,OAAO,MAAM,QAAQ,KAAK,KAAK,MAAM,WAAW,KAC3C,OAAO,MAAM,OAAO,YAAY,MAAM,OAAO,MAAM,OAAO,MAAM,OAAO,WACxE,QACA;AACN;AAEA,SAAS,YAAY,QAAyB;CAC5C,OAAO,OAAO,gBAAgB,SAC1B,aAAa,OAAO,aAAa,qCAAqC,IACtE,OAAO,eAAe;AAC5B;AAEA,SAAS,mBAAmB,cAA6C;CACvE,MAAM,EAAE,OAAO,QAAQ,YAAY;CACnC,IAAI,MAAM,SAAS,EAAE,IAAI,OAAO,MAAM,cACpC,MAAM,SAAS,EAAE,OAAO,OAAO;CAEjC,IAAI,OAAO,qBAAqB,cAC9B,OAAO,OAAO;AAElB;AAEA,SAAS,oBAAoB,cAA6C;CACxE,MAAM,EAAE,OAAO,QAAQ,YAAY;CACnC,MAAM,QAAQ,MAAM,cAAN,MAAM,4BAAc,IAAI,IAAI;CAC1C,MAAM,WAAW,MAAM,IAAI,OAAO;CAElC,IAAI,YAAY,aAAa,cAC3B,mBAAmB,QAAQ;CAE7B,MAAM,IAAI,SAAS,YAAY;CAC/B,OAAO,mBAAmB;AAC5B;AAEA,SAAgB,+BAA+B,QAAyB,UAAmB;CACzF,MAAM,UAAU,aAAa,QAAQ;CACrC,OAAO,cAAc,WAAW;CAChC,MAAM,eAAe,OAAO;CAC5B,IAAI,CAAC,gBAAgB,aAAa,YAAY,UAAU,IACtD;CAEF,mBAAmB,YAAY;CAC/B,IAAI,SAAS;EACX,aAAa,UAAU,QAAQ;EAC/B,oBAAoB,YAAY;CAClC;AACF;AAEA,SAAgB,6BAA6B,OAAwB,KAA+C;CAClH,OAAO,MAAM,MAAM,SAAS,EAAE,IAAI,GAAG,CAAC,EAAE,SAAS;AACnD;;AAGA,SAAgB,yBAAqD,OAA6C;CAChH,IAAI,OAAO,MAAM,QAAQ,aAAa,YACpC,MAAM,OAAO,SAAS,IAAI;AAE9B;AAEA,SAAgB,+BAA+B,QAA2D;CACxG,MAAM,UAAU,YAAY,MAAM;CAClC,IAAI,CAAC,WAAW,OAAO,OAAO,iBAAiB,YAC7C;CAEF,IAAI;CACJ,OAAO,aAAa,+BAA+B,EACjD,SAAS,OAAwB;EAC/B,IAAI,UAAU,QACZ;EAEF,MAAM,WAAW,OAAO;EACxB,IAAI,UACF,mBAAmB,QAAQ;EAE7B,oBAAoB;GAAE;GAAO;GAAQ,SAAS,QAAQ;EAAG,CAAC;EAC1D,SAAS,6BAA6B,OAAO,QAAQ,EAAE;CACzD,EACF,GAAqC;EAAE,SAAS;EAAO,UAAU;CAAM,CAAC;CACxE,OAAO;AACT;AAEA,SAAgB,yBAAyB,QAAyB,qBAAqB,OAAO;CAC5F,MAAM,eAAe,OAAO;CAC5B,IAAI,cACF,mBAAmB,YAAY;CAEjC,IAAI,oBACF;CAEF,MAAM,QAAQ,OAAO;CACrB,IAAI,OAAO;EACT,KAAK,MAAM,SAAS,MAAM,OAAO,GAC/B,mBAAmB,KAAK;EAE1B,OAAO,OAAO;CAChB;CACA,OAAO,OAAO;AAChB"}
@@ -1,18 +1,61 @@
1
1
  import { getCurrentMiniProgramPages } from "../../platform.mjs";
2
2
  import { attachRuntimeLayoutProvideContext, attachRuntimeProvideContext } from "../../provideContext.mjs";
3
3
  import { isRuntimeLayoutComponentTarget } from "../../layoutComponentMatcher.mjs";
4
- import { WEVU_PARENT_INSTANCE_KEY, WEVU_RUNTIME_APP_KEY } from "@weapp-core/constants";
4
+ import { resolveNativeDeclarationHost, resolveNativeDeclarationParent } from "./nativeDeclaration.mjs";
5
+ import { WEVU_NATIVE_SLOT_CONTEXT_KEY, WEVU_NATIVE_SLOT_PARENT_DATASET_KEY, WEVU_NATIVE_SLOT_PARENT_EVENT, WEVU_PARENT_INSTANCE_KEY, WEVU_PROVIDES_KEY, WEVU_RUNTIME_APP_KEY } from "@weapp-core/constants";
5
6
 
6
7
  //#region src/runtime/register/runtimeInstance/provideContext.ts
7
- function resolveRuntimeParentInstance(target) {
8
- if (isRuntimeLayoutComponentTarget(target)) return;
9
- const cached = target[WEVU_PARENT_INSTANCE_KEY];
10
- if (cached && typeof cached === "object") return cached;
8
+ function isLiveProvideHost(target) {
9
+ return Boolean(target && typeof target === "object" && target.__wevu && target[WEVU_PROVIDES_KEY]);
10
+ }
11
+ /**
12
+ * 编译后的组件节点与 slot 监听器必须保留原始 this,不能经过 setup 方法代理。
13
+ */
14
+ function receiveNativeSlotParent(event) {
15
+ const key = event.currentTarget?.dataset?.[WEVU_NATIVE_SLOT_PARENT_DATASET_KEY];
16
+ const parent = typeof key === "string" ? resolveNativeDeclarationHost(this, key) : this;
17
+ if (isLiveProvideHost(parent) && typeof event.detail?.resolve === "function") event.detail.resolve(parent);
18
+ }
19
+ function resolveNativeOwner(target) {
11
20
  const selectOwnerComponent = target.selectOwnerComponent;
12
21
  if (typeof selectOwnerComponent === "function") try {
13
22
  const owner = selectOwnerComponent.call(target);
14
23
  if (owner && owner !== target && typeof owner === "object" && owner.__wevu) return owner;
15
24
  } catch {}
25
+ }
26
+ function resolveNativeSlotParent(target) {
27
+ if (target[WEVU_NATIVE_SLOT_CONTEXT_KEY] !== true || typeof target.triggerEvent !== "function") return;
28
+ let parent;
29
+ const detail = { resolve(candidate) {
30
+ if (candidate === target || !isLiveProvideHost(candidate) || candidate === parent) return;
31
+ if (!parent) {
32
+ parent = candidate;
33
+ return;
34
+ }
35
+ for (let ancestor = candidate[WEVU_PARENT_INSTANCE_KEY]; ancestor; ancestor = ancestor[WEVU_PARENT_INSTANCE_KEY]) if (ancestor === parent) {
36
+ parent = candidate;
37
+ return;
38
+ }
39
+ } };
40
+ const declarationParent = resolveNativeDeclarationParent(target);
41
+ if (declarationParent) detail.resolve(declarationParent);
42
+ target.triggerEvent(WEVU_NATIVE_SLOT_PARENT_EVENT, detail, {
43
+ bubbles: true,
44
+ composed: true
45
+ });
46
+ return parent;
47
+ }
48
+ function resolveRuntimeParentInstance(target, attached, layoutParent) {
49
+ if (isRuntimeLayoutComponentTarget(target)) return;
50
+ if ((!import.meta.env?.PLATFORM || import.meta.env?.PLATFORM === "weapp") && attached) {
51
+ const slotParent = resolveNativeSlotParent(target);
52
+ if (slotParent) return slotParent;
53
+ }
54
+ const cached = target[WEVU_PARENT_INSTANCE_KEY];
55
+ if (cached && typeof cached === "object") return cached;
56
+ if (layoutParent !== target && isLiveProvideHost(layoutParent)) return layoutParent;
57
+ const owner = resolveNativeOwner(target);
58
+ if (owner) return owner;
16
59
  const pages = getCurrentMiniProgramPages();
17
60
  const currentPage = pages[pages.length - 1];
18
61
  if (currentPage && currentPage !== target && typeof currentPage === "object" && currentPage.__wevu) return currentPage;
@@ -23,12 +66,13 @@ function attachRuntimeLayoutParentContext(target) {
23
66
  const currentPage = pages[pages.length - 1];
24
67
  if (currentPage && currentPage !== target && typeof currentPage === "object" && currentPage.__wevu) attachRuntimeLayoutProvideContext(target, currentPage);
25
68
  }
26
- function attachRuntimeProvideParentContext(target, runtimeApp) {
69
+ function attachRuntimeProvideParentContext(target, runtimeApp, attached = false, layoutParent) {
70
+ const parent = resolveRuntimeParentInstance(target, attached, layoutParent);
27
71
  target[WEVU_RUNTIME_APP_KEY] = runtimeApp;
28
- attachRuntimeProvideContext(target, runtimeApp, resolveRuntimeParentInstance(target));
72
+ attachRuntimeProvideContext(target, runtimeApp, parent);
29
73
  attachRuntimeLayoutParentContext(target);
30
74
  }
31
75
 
32
76
  //#endregion
33
- export { attachRuntimeProvideParentContext };
77
+ export { attachRuntimeProvideParentContext, receiveNativeSlotParent };
34
78
  //# sourceMappingURL=provideContext.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"provideContext.mjs","names":[],"sources":["../../../../../src/runtime/register/runtimeInstance/provideContext.ts"],"sourcesContent":["import type { InternalRuntimeState, RuntimeApp } from '../../types'\nimport {\n WEVU_PARENT_INSTANCE_KEY,\n WEVU_RUNTIME_APP_KEY,\n} from '@weapp-core/constants'\nimport { isRuntimeLayoutComponentTarget } from '../../layoutComponentMatcher'\nimport { getCurrentMiniProgramPages } from '../../platform'\nimport { attachRuntimeLayoutProvideContext, attachRuntimeProvideContext } from '../../provideContext'\n\nfunction resolveRuntimeParentInstance(target: InternalRuntimeState): InternalRuntimeState | undefined {\n if (isRuntimeLayoutComponentTarget(target)) {\n return undefined\n }\n\n const cached = target[WEVU_PARENT_INSTANCE_KEY]\n if (cached && typeof cached === 'object') {\n return cached\n }\n\n const selectOwnerComponent = (target as any).selectOwnerComponent\n if (typeof selectOwnerComponent === 'function') {\n try {\n const owner = selectOwnerComponent.call(target) as InternalRuntimeState | undefined\n if (owner && owner !== target && typeof owner === 'object' && owner.__wevu) {\n return owner\n }\n }\n catch {\n // 部分宿主或生命周期阶段可能暂不支持 owner 查询,继续使用页面兜底。\n }\n }\n\n const pages = getCurrentMiniProgramPages()\n const currentPage = pages[pages.length - 1] as InternalRuntimeState | undefined\n if (\n currentPage\n && currentPage !== target\n && typeof currentPage === 'object'\n && currentPage.__wevu\n ) {\n return currentPage\n }\n\n return undefined\n}\n\nfunction attachRuntimeLayoutParentContext(target: InternalRuntimeState) {\n if (!isRuntimeLayoutComponentTarget(target)) {\n return\n }\n const pages = getCurrentMiniProgramPages()\n const currentPage = pages[pages.length - 1] as InternalRuntimeState | undefined\n if (\n currentPage\n && currentPage !== target\n && typeof currentPage === 'object'\n && currentPage.__wevu\n ) {\n attachRuntimeLayoutProvideContext(target, currentPage)\n }\n}\n\nexport function attachRuntimeProvideParentContext(\n target: InternalRuntimeState,\n runtimeApp: RuntimeApp<any, any, any>,\n) {\n target[WEVU_RUNTIME_APP_KEY] = runtimeApp\n attachRuntimeProvideContext(target, runtimeApp, resolveRuntimeParentInstance(target))\n attachRuntimeLayoutParentContext(target)\n}\n"],"mappings":";;;;;;AASA,SAAS,6BAA6B,QAAgE;CACpG,IAAI,+BAA+B,MAAM,GACvC;CAGF,MAAM,SAAS,OAAO;CACtB,IAAI,UAAU,OAAO,WAAW,UAC9B,OAAO;CAGT,MAAM,uBAAwB,OAAe;CAC7C,IAAI,OAAO,yBAAyB,YAClC,IAAI;EACF,MAAM,QAAQ,qBAAqB,KAAK,MAAM;EAC9C,IAAI,SAAS,UAAU,UAAU,OAAO,UAAU,YAAY,MAAM,QAClE,OAAO;CAEX,QACM,CAEN;CAGF,MAAM,QAAQ,2BAA2B;CACzC,MAAM,cAAc,MAAM,MAAM,SAAS;CACzC,IACE,eACG,gBAAgB,UAChB,OAAO,gBAAgB,YACvB,YAAY,QAEf,OAAO;AAIX;AAEA,SAAS,iCAAiC,QAA8B;CACtE,IAAI,CAAC,+BAA+B,MAAM,GACxC;CAEF,MAAM,QAAQ,2BAA2B;CACzC,MAAM,cAAc,MAAM,MAAM,SAAS;CACzC,IACE,eACG,gBAAgB,UAChB,OAAO,gBAAgB,YACvB,YAAY,QAEf,kCAAkC,QAAQ,WAAW;AAEzD;AAEA,SAAgB,kCACd,QACA,YACA;CACA,OAAO,wBAAwB;CAC/B,4BAA4B,QAAQ,YAAY,6BAA6B,MAAM,CAAC;CACpF,iCAAiC,MAAM;AACzC"}
1
+ {"version":3,"file":"provideContext.mjs","names":[],"sources":["../../../../../src/runtime/register/runtimeInstance/provideContext.ts"],"sourcesContent":["import type { InternalRuntimeState, RuntimeApp } from '../../types'\nimport {\n WEVU_NATIVE_SLOT_CONTEXT_KEY,\n WEVU_NATIVE_SLOT_PARENT_DATASET_KEY,\n WEVU_NATIVE_SLOT_PARENT_EVENT,\n WEVU_PARENT_INSTANCE_KEY,\n WEVU_PROVIDES_KEY,\n WEVU_RUNTIME_APP_KEY,\n} from '@weapp-core/constants'\nimport { isRuntimeLayoutComponentTarget } from '../../layoutComponentMatcher'\nimport { getCurrentMiniProgramPages } from '../../platform'\nimport { attachRuntimeLayoutProvideContext, attachRuntimeProvideContext } from '../../provideContext'\nimport { resolveNativeDeclarationHost, resolveNativeDeclarationParent } from './nativeDeclaration'\n\ntype ImportMetaWithEnv = ImportMeta & { env?: { PLATFORM?: string } }\n\ninterface NativeSlotParentDetail {\n resolve: (parent: InternalRuntimeState) => void\n}\n\nfunction isLiveProvideHost(target: InternalRuntimeState | undefined): target is InternalRuntimeState {\n return Boolean(target && typeof target === 'object' && target.__wevu && target[WEVU_PROVIDES_KEY])\n}\n\n/**\n * 编译后的组件节点与 slot 监听器必须保留原始 this,不能经过 setup 方法代理。\n */\nexport function receiveNativeSlotParent(this: InternalRuntimeState, event: {\n detail?: NativeSlotParentDetail\n currentTarget?: { dataset?: Record<string, unknown> }\n}) {\n const key = event.currentTarget?.dataset?.[WEVU_NATIVE_SLOT_PARENT_DATASET_KEY]\n const parent = typeof key === 'string' ? resolveNativeDeclarationHost(this, key) : this\n if (isLiveProvideHost(parent) && typeof event.detail?.resolve === 'function') {\n event.detail.resolve(parent)\n }\n}\n\nfunction resolveNativeOwner(target: InternalRuntimeState): InternalRuntimeState | undefined {\n const selectOwnerComponent = target.selectOwnerComponent\n if (typeof selectOwnerComponent === 'function') {\n try {\n const owner = selectOwnerComponent.call(target) as InternalRuntimeState | undefined\n if (owner && owner !== target && typeof owner === 'object' && owner.__wevu) {\n return owner\n }\n }\n catch {\n // 部分宿主或生命周期阶段可能暂不支持 owner 查询,继续使用页面兜底。\n }\n }\n return undefined\n}\n\nfunction resolveNativeSlotParent(target: InternalRuntimeState): InternalRuntimeState | undefined {\n if (target[WEVU_NATIVE_SLOT_CONTEXT_KEY] !== true || typeof target.triggerEvent !== 'function') {\n return undefined\n }\n\n let parent: InternalRuntimeState | undefined\n const detail: NativeSlotParentDetail = {\n resolve(candidate) {\n if (candidate === target || !isLiveProvideHost(candidate) || candidate === parent) {\n return\n }\n if (!parent) {\n parent = candidate\n return\n }\n // 词法声明与原生投影共用同一父链,只向仍存活的更近宿主收敛。\n for (let ancestor = candidate[WEVU_PARENT_INSTANCE_KEY]; ancestor; ancestor = ancestor[WEVU_PARENT_INSTANCE_KEY]) {\n if (ancestor === parent) {\n parent = candidate\n return\n }\n }\n },\n }\n const declarationParent = resolveNativeDeclarationParent(target)\n if (declarationParent) {\n detail.resolve(declarationParent)\n }\n target.triggerEvent(WEVU_NATIVE_SLOT_PARENT_EVENT, detail, { bubbles: true, composed: true })\n return parent\n}\n\nfunction resolveRuntimeParentInstance(\n target: InternalRuntimeState,\n attached: boolean,\n layoutParent?: InternalRuntimeState,\n): InternalRuntimeState | undefined {\n if (isRuntimeLayoutComponentTarget(target)) {\n return undefined\n }\n\n // 生命周期由注册入口显式传入;created 和提前恢复不能假定原生投影已就绪。\n if (\n (!(import.meta as ImportMetaWithEnv).env?.PLATFORM || (import.meta as ImportMetaWithEnv).env?.PLATFORM === 'weapp')\n && attached\n ) {\n const slotParent = resolveNativeSlotParent(target)\n if (slotParent) {\n return slotParent\n }\n }\n\n const cached = target[WEVU_PARENT_INSTANCE_KEY]\n if (cached && typeof cached === 'object') {\n return cached\n }\n if (layoutParent !== target && isLiveProvideHost(layoutParent)) {\n return layoutParent\n }\n\n const owner = resolveNativeOwner(target)\n if (owner) {\n return owner\n }\n\n const pages = getCurrentMiniProgramPages()\n const currentPage = pages[pages.length - 1] as InternalRuntimeState | undefined\n if (\n currentPage\n && currentPage !== target\n && typeof currentPage === 'object'\n && currentPage.__wevu\n ) {\n return currentPage\n }\n\n return undefined\n}\n\nfunction attachRuntimeLayoutParentContext(target: InternalRuntimeState) {\n if (!isRuntimeLayoutComponentTarget(target)) {\n return\n }\n const pages = getCurrentMiniProgramPages()\n const currentPage = pages[pages.length - 1] as InternalRuntimeState | undefined\n if (\n currentPage\n && currentPage !== target\n && typeof currentPage === 'object'\n && currentPage.__wevu\n ) {\n attachRuntimeLayoutProvideContext(target, currentPage)\n }\n}\n\nexport function attachRuntimeProvideParentContext(\n target: InternalRuntimeState,\n runtimeApp: RuntimeApp<any, any, any>,\n attached = false,\n layoutParent?: InternalRuntimeState,\n) {\n const parent = resolveRuntimeParentInstance(target, attached, layoutParent)\n target[WEVU_RUNTIME_APP_KEY] = runtimeApp\n attachRuntimeProvideContext(target, runtimeApp, parent)\n attachRuntimeLayoutParentContext(target)\n}\n"],"mappings":";;;;;;;AAoBA,SAAS,kBAAkB,QAA0E;CACnG,OAAO,QAAQ,UAAU,OAAO,WAAW,YAAY,OAAO,UAAU,OAAO,kBAAkB;AACnG;;;;AAKA,SAAgB,wBAAoD,OAGjE;CACD,MAAM,MAAM,MAAM,eAAe,UAAU;CAC3C,MAAM,SAAS,OAAO,QAAQ,WAAW,6BAA6B,MAAM,GAAG,IAAI;CACnF,IAAI,kBAAkB,MAAM,KAAK,OAAO,MAAM,QAAQ,YAAY,YAChE,MAAM,OAAO,QAAQ,MAAM;AAE/B;AAEA,SAAS,mBAAmB,QAAgE;CAC1F,MAAM,uBAAuB,OAAO;CACpC,IAAI,OAAO,yBAAyB,YAClC,IAAI;EACF,MAAM,QAAQ,qBAAqB,KAAK,MAAM;EAC9C,IAAI,SAAS,UAAU,UAAU,OAAO,UAAU,YAAY,MAAM,QAClE,OAAO;CAEX,QACM,CAEN;AAGJ;AAEA,SAAS,wBAAwB,QAAgE;CAC/F,IAAI,OAAO,kCAAkC,QAAQ,OAAO,OAAO,iBAAiB,YAClF;CAGF,IAAI;CACJ,MAAM,SAAiC,EACrC,QAAQ,WAAW;EACjB,IAAI,cAAc,UAAU,CAAC,kBAAkB,SAAS,KAAK,cAAc,QACzE;EAEF,IAAI,CAAC,QAAQ;GACX,SAAS;GACT;EACF;EAEA,KAAK,IAAI,WAAW,UAAU,2BAA2B,UAAU,WAAW,SAAS,2BACrF,IAAI,aAAa,QAAQ;GACvB,SAAS;GACT;EACF;CAEJ,EACF;CACA,MAAM,oBAAoB,+BAA+B,MAAM;CAC/D,IAAI,mBACF,OAAO,QAAQ,iBAAiB;CAElC,OAAO,aAAa,+BAA+B,QAAQ;EAAE,SAAS;EAAM,UAAU;CAAK,CAAC;CAC5F,OAAO;AACT;AAEA,SAAS,6BACP,QACA,UACA,cACkC;CAClC,IAAI,+BAA+B,MAAM,GACvC;CAIF,KACG,CAAE,YAAkC,KAAK,YAAa,YAAkC,KAAK,aAAa,YACxG,UACH;EACA,MAAM,aAAa,wBAAwB,MAAM;EACjD,IAAI,YACF,OAAO;CAEX;CAEA,MAAM,SAAS,OAAO;CACtB,IAAI,UAAU,OAAO,WAAW,UAC9B,OAAO;CAET,IAAI,iBAAiB,UAAU,kBAAkB,YAAY,GAC3D,OAAO;CAGT,MAAM,QAAQ,mBAAmB,MAAM;CACvC,IAAI,OACF,OAAO;CAGT,MAAM,QAAQ,2BAA2B;CACzC,MAAM,cAAc,MAAM,MAAM,SAAS;CACzC,IACE,eACG,gBAAgB,UAChB,OAAO,gBAAgB,YACvB,YAAY,QAEf,OAAO;AAIX;AAEA,SAAS,iCAAiC,QAA8B;CACtE,IAAI,CAAC,+BAA+B,MAAM,GACxC;CAEF,MAAM,QAAQ,2BAA2B;CACzC,MAAM,cAAc,MAAM,MAAM,SAAS;CACzC,IACE,eACG,gBAAgB,UAChB,OAAO,gBAAgB,YACvB,YAAY,QAEf,kCAAkC,QAAQ,WAAW;AAEzD;AAEA,SAAgB,kCACd,QACA,YACA,WAAW,OACX,cACA;CACA,MAAM,SAAS,6BAA6B,QAAQ,UAAU,YAAY;CAC1E,OAAO,wBAAwB;CAC/B,4BAA4B,QAAQ,YAAY,MAAM;CACtD,iCAAiC,MAAM;AACzC"}
@@ -1 +1 @@
1
- {"version":3,"file":"utils.mjs","names":[],"sources":["../../../../../src/runtime/register/runtimeInstance/utils.ts"],"sourcesContent":["import type { SetDataAdapterSettler, SetDataPayload } from '../../app/setData/commitTracker'\nimport type {\n InternalRuntimeState,\n MiniProgramAdapter,\n RuntimeInstance,\n SetupContextNativeInstance,\n} from '../../types'\nimport {\n WEVU_NATIVE_INSTANCE_KEY,\n WEVU_PROP_KEYS_KEY,\n WEVU_PROPS_KEY,\n WEVU_RUNTIME_KEY,\n WEVU_SETUP_CONTEXT_INSTANCE_KEY,\n WEVU_SETUP_STATE_KEY,\n} from '@weapp-core/constants'\nimport { shallowReactive } from '../../../reactivity'\nimport { hasOwn } from '../../../utils'\nimport { isNativeBridgeMethod } from '../../nativeBridge'\n\nexport type AdapterWithSetData = Omit<Required<MiniProgramAdapter>, 'setData'> & {\n setData: (payload: Record<string, any>, callback?: () => void) => void | Promise<void> | undefined\n __wevu_dispatchSetData: (payload: SetDataPayload, settle: SetDataAdapterSettler) => void\n __wevu_enableSetData?: (discardPending?: boolean) => void\n __wevu_setVisibility?: (visible: boolean) => void\n __wevu_reportSetDataError?: (error: Error) => void\n __wevu_disposeSetData?: () => void\n}\n\nexport type NativeSetData = (payload: Record<string, any>, callback?: () => void) => void | Promise<void> | undefined\n\nexport function attachRuntimeProxyProps(state: Record<string, any>, props: Record<string, any>) {\n try {\n Object.defineProperty(state, WEVU_PROPS_KEY, {\n value: props,\n configurable: true,\n enumerable: false,\n writable: false,\n })\n }\n catch {\n ;(state as any)[WEVU_PROPS_KEY] = props\n }\n}\n\nexport function attachRuntimeSetupState(state: Record<string, any>, setupState: Record<string, any>) {\n try {\n Object.defineProperty(state, WEVU_SETUP_STATE_KEY, {\n value: setupState,\n configurable: true,\n enumerable: false,\n writable: false,\n })\n }\n catch {\n ;(state as any)[WEVU_SETUP_STATE_KEY] = setupState\n }\n}\n\nexport function attachNativeInstanceRef(state: Record<string, any>, instance: InternalRuntimeState) {\n try {\n Object.defineProperty(state, WEVU_NATIVE_INSTANCE_KEY, {\n value: instance,\n configurable: true,\n enumerable: false,\n writable: true,\n })\n }\n catch {\n ;(state as any)[WEVU_NATIVE_INSTANCE_KEY] = instance\n }\n}\n\nexport function attachRuntimeRef(state: Record<string, any>, runtime: RuntimeInstance<any, any, any>) {\n try {\n Object.defineProperty(state, WEVU_RUNTIME_KEY, {\n value: runtime,\n configurable: true,\n enumerable: false,\n writable: true,\n })\n }\n catch {\n ;(state as any)[WEVU_RUNTIME_KEY] = runtime\n }\n}\n\nexport function attachRuntimeInstance(runtime: RuntimeInstance<any, any, any>, instance: InternalRuntimeState) {\n try {\n Object.defineProperty(runtime as Record<string, any>, 'instance', {\n value: instance,\n configurable: true,\n enumerable: false,\n writable: true,\n })\n }\n catch {\n try {\n ;(runtime as Record<string, any>).instance = instance\n }\n catch {\n // 忽略冻结对象写入失败\n }\n }\n}\n\nexport function resolveNativeSetData(instance: InternalRuntimeState) {\n const setupInstance = (instance as any)[WEVU_SETUP_CONTEXT_INSTANCE_KEY] as SetupContextNativeInstance | undefined\n const setupOverride = setupInstance && typeof setupInstance.setData === 'function'\n ? setupInstance.setData\n : undefined\n if (typeof setupOverride === 'function' && !isNativeBridgeMethod(setupOverride)) {\n return setupOverride as NativeSetData\n }\n\n const candidate = (instance as any).setData\n if (typeof candidate !== 'function') {\n return undefined\n }\n if (isNativeBridgeMethod(candidate)) {\n return undefined\n }\n return candidate as NativeSetData\n}\n\nfunction getRuntimeOwnerLabel(instance: InternalRuntimeState) {\n const route = (instance as any).route\n if (typeof route === 'string' && route) {\n return route\n }\n const is = (instance as any).is\n if (typeof is === 'string' && is) {\n return is\n }\n return 'unknown'\n}\n\nexport function callNativeSetData(\n instance: InternalRuntimeState,\n setData: NativeSetData,\n payload: Record<string, any>,\n callback?: () => void,\n) {\n try {\n return callback\n ? setData.call(instance, payload, callback)\n : setData.call(instance, payload)\n }\n catch (error) {\n const owner = getRuntimeOwnerLabel(instance)\n throw new Error(`[wevu] setData failed (${owner}): ${error instanceof Error ? error.message : String(error)}`)\n }\n}\n\nexport function syncRuntimeProps(\n props: Record<string, any>,\n mpProperties: Record<string, any>,\n declaredPropKeys?: readonly string[],\n) {\n const declaredPropKeySet = declaredPropKeys ? new Set(declaredPropKeys) : undefined\n const currentKeys = Object.keys(props)\n for (const key of currentKeys) {\n if (!hasOwn(mpProperties, key) || (declaredPropKeySet && !declaredPropKeySet.has(key))) {\n try {\n delete props[key]\n }\n catch {\n // 忽略异常\n }\n }\n }\n const nextKeys = declaredPropKeys ?? Object.keys(mpProperties)\n for (const key of nextKeys) {\n if (hasOwn(mpProperties, key)) {\n props[key] = mpProperties[key]\n }\n }\n}\n\nexport function ensureRuntimeProps(\n target: InternalRuntimeState,\n runtimeState: Record<string, any>,\n mpProperties: Record<string, any> = ((target as any).properties || {}) as Record<string, any>,\n) {\n const runtimeProps = runtimeState && typeof runtimeState === 'object'\n ? ((runtimeState as any)[WEVU_PROPS_KEY] as Record<string, any> | undefined)\n : undefined\n const props = runtimeProps && typeof runtimeProps === 'object'\n ? runtimeProps\n : shallowReactive({}) as Record<string, any>\n\n const declaredPropKeys = Array.isArray((target as any)[WEVU_PROP_KEYS_KEY])\n ? ((target as any)[WEVU_PROP_KEYS_KEY] as string[])\n : undefined\n syncRuntimeProps(props, mpProperties, declaredPropKeys)\n if (runtimeState && typeof runtimeState === 'object') {\n attachRuntimeProxyProps(runtimeState, props)\n }\n try {\n Object.defineProperty(target, WEVU_PROPS_KEY, {\n value: props,\n configurable: true,\n enumerable: false,\n writable: true,\n })\n }\n catch {\n ;(target as any)[WEVU_PROPS_KEY] = props\n }\n\n return props\n}\n"],"mappings":"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"}
1
+ {"version":3,"file":"utils.mjs","names":[],"sources":["../../../../../src/runtime/register/runtimeInstance/utils.ts"],"sourcesContent":["import type { CommitAwareSetDataAdapter } from '../../app/setData/commitTracker'\nimport type {\n InternalRuntimeState,\n MiniProgramAdapter,\n RuntimeInstance,\n SetupContextNativeInstance,\n} from '../../types'\nimport {\n WEVU_NATIVE_INSTANCE_KEY,\n WEVU_PROP_KEYS_KEY,\n WEVU_PROPS_KEY,\n WEVU_RUNTIME_KEY,\n WEVU_SETUP_CONTEXT_INSTANCE_KEY,\n WEVU_SETUP_STATE_KEY,\n} from '@weapp-core/constants'\nimport { shallowReactive } from '../../../reactivity'\nimport { hasOwn } from '../../../utils'\nimport { isNativeBridgeMethod } from '../../nativeBridge'\n\nexport type AdapterWithSetData = Omit<Required<MiniProgramAdapter>, 'setData'> & {\n setData: (payload: Record<string, any>, callback?: () => void) => void | Promise<void> | undefined\n __wevu_dispatchSetData: NonNullable<CommitAwareSetDataAdapter['__wevu_dispatchSetData']>\n __wevu_enableSetData?: (discardPending?: boolean) => void\n __wevu_setVisibility?: (visible: boolean) => void\n __wevu_reportSetDataError?: (error: Error) => void\n __wevu_disposeSetData?: () => void\n}\n\nexport type NativeSetData = (payload: Record<string, any>, callback?: () => void) => void | Promise<void> | undefined\n\nexport function attachRuntimeProxyProps(state: Record<string, any>, props: Record<string, any>) {\n try {\n Object.defineProperty(state, WEVU_PROPS_KEY, {\n value: props,\n configurable: true,\n enumerable: false,\n writable: false,\n })\n }\n catch {\n ;(state as any)[WEVU_PROPS_KEY] = props\n }\n}\n\nexport function attachRuntimeSetupState(state: Record<string, any>, setupState: Record<string, any>) {\n try {\n Object.defineProperty(state, WEVU_SETUP_STATE_KEY, {\n value: setupState,\n configurable: true,\n enumerable: false,\n writable: false,\n })\n }\n catch {\n ;(state as any)[WEVU_SETUP_STATE_KEY] = setupState\n }\n}\n\nexport function attachNativeInstanceRef(state: Record<string, any>, instance: InternalRuntimeState) {\n try {\n Object.defineProperty(state, WEVU_NATIVE_INSTANCE_KEY, {\n value: instance,\n configurable: true,\n enumerable: false,\n writable: true,\n })\n }\n catch {\n ;(state as any)[WEVU_NATIVE_INSTANCE_KEY] = instance\n }\n}\n\nexport function attachRuntimeRef(state: Record<string, any>, runtime: RuntimeInstance<any, any, any>) {\n try {\n Object.defineProperty(state, WEVU_RUNTIME_KEY, {\n value: runtime,\n configurable: true,\n enumerable: false,\n writable: true,\n })\n }\n catch {\n ;(state as any)[WEVU_RUNTIME_KEY] = runtime\n }\n}\n\nexport function attachRuntimeInstance(runtime: RuntimeInstance<any, any, any>, instance: InternalRuntimeState) {\n try {\n Object.defineProperty(runtime as Record<string, any>, 'instance', {\n value: instance,\n configurable: true,\n enumerable: false,\n writable: true,\n })\n }\n catch {\n try {\n ;(runtime as Record<string, any>).instance = instance\n }\n catch {\n // 忽略冻结对象写入失败\n }\n }\n}\n\nexport function resolveNativeSetData(instance: InternalRuntimeState) {\n const setupInstance = (instance as any)[WEVU_SETUP_CONTEXT_INSTANCE_KEY] as SetupContextNativeInstance | undefined\n const setupOverride = setupInstance && typeof setupInstance.setData === 'function'\n ? setupInstance.setData\n : undefined\n if (typeof setupOverride === 'function' && !isNativeBridgeMethod(setupOverride)) {\n return setupOverride as NativeSetData\n }\n\n const candidate = (instance as any).setData\n if (typeof candidate !== 'function') {\n return undefined\n }\n if (isNativeBridgeMethod(candidate)) {\n return undefined\n }\n return candidate as NativeSetData\n}\n\nfunction getRuntimeOwnerLabel(instance: InternalRuntimeState) {\n const route = (instance as any).route\n if (typeof route === 'string' && route) {\n return route\n }\n const is = (instance as any).is\n if (typeof is === 'string' && is) {\n return is\n }\n return 'unknown'\n}\n\nexport function callNativeSetData(\n instance: InternalRuntimeState,\n setData: NativeSetData,\n payload: Record<string, any>,\n callback?: () => void,\n) {\n try {\n return callback\n ? setData.call(instance, payload, callback)\n : setData.call(instance, payload)\n }\n catch (error) {\n const owner = getRuntimeOwnerLabel(instance)\n throw new Error(`[wevu] setData failed (${owner}): ${error instanceof Error ? error.message : String(error)}`)\n }\n}\n\nexport function syncRuntimeProps(\n props: Record<string, any>,\n mpProperties: Record<string, any>,\n declaredPropKeys?: readonly string[],\n) {\n const declaredPropKeySet = declaredPropKeys ? new Set(declaredPropKeys) : undefined\n const currentKeys = Object.keys(props)\n for (const key of currentKeys) {\n if (!hasOwn(mpProperties, key) || (declaredPropKeySet && !declaredPropKeySet.has(key))) {\n try {\n delete props[key]\n }\n catch {\n // 忽略异常\n }\n }\n }\n const nextKeys = declaredPropKeys ?? Object.keys(mpProperties)\n for (const key of nextKeys) {\n if (hasOwn(mpProperties, key)) {\n props[key] = mpProperties[key]\n }\n }\n}\n\nexport function ensureRuntimeProps(\n target: InternalRuntimeState,\n runtimeState: Record<string, any>,\n mpProperties: Record<string, any> = ((target as any).properties || {}) as Record<string, any>,\n) {\n const runtimeProps = runtimeState && typeof runtimeState === 'object'\n ? ((runtimeState as any)[WEVU_PROPS_KEY] as Record<string, any> | undefined)\n : undefined\n const props = runtimeProps && typeof runtimeProps === 'object'\n ? runtimeProps\n : shallowReactive({}) as Record<string, any>\n\n const declaredPropKeys = Array.isArray((target as any)[WEVU_PROP_KEYS_KEY])\n ? ((target as any)[WEVU_PROP_KEYS_KEY] as string[])\n : undefined\n syncRuntimeProps(props, mpProperties, declaredPropKeys)\n if (runtimeState && typeof runtimeState === 'object') {\n attachRuntimeProxyProps(runtimeState, props)\n }\n try {\n Object.defineProperty(target, WEVU_PROPS_KEY, {\n value: props,\n configurable: true,\n enumerable: false,\n writable: true,\n })\n }\n catch {\n ;(target as any)[WEVU_PROPS_KEY] = props\n }\n\n return props\n}\n"],"mappings":"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"}
@@ -5,16 +5,19 @@ import { getMiniProgramRuntimeGlobalObject } from "../platform.mjs";
5
5
  import { callHookList } from "../hooks/base.mjs";
6
6
  import { isSetDataHighFrequencyWarningRequested, requireRuntimeCapability, runtimeCapabilityRegistry } from "../capabilities.mjs";
7
7
  import { runTeardownSteps } from "../teardown.mjs";
8
+ import { observePhysicalDispatch } from "../app/setData/observation.mjs";
8
9
  import { applySnapshotUpdate, isDeepEqualValue } from "../app/setData/snapshot.mjs";
9
10
  import { observeSetDataCompletion } from "../app/setData/commitTracker.mjs";
11
+ import { isRuntimeLayoutComponentTarget } from "../layoutComponentMatcher.mjs";
10
12
  import { attachRuntimeSlots, createNoopWatchStopHandle, safeMarkNoSetData } from "./runtimeInstance/setupContext.mjs";
11
13
  import { bridgeRuntimeMethodsToTarget } from "./runtimeInstance/methodBridge.mjs";
14
+ import { releaseNativeDeclaration } from "./runtimeInstance/nativeDeclaration.mjs";
12
15
  import { attachRuntimeProvideParentContext } from "./runtimeInstance/provideContext.mjs";
13
16
  import { attachNativeInstanceRef, attachRuntimeInstance, attachRuntimeRef, callNativeSetData, ensureRuntimeProps, resolveNativeSetData } from "./runtimeInstance/utils.mjs";
14
17
  import { runRuntimeSetupPhase } from "./runtimeInstance/setupPhase.mjs";
15
18
  import { restoreReactiveSetupSnapshot } from "./runtimeInstance/setupSnapshot.mjs";
16
19
  import { registerWatches } from "./watch.mjs";
17
- import { WEAPP_VITE_STATEFUL_HMR_BRIDGE_KEY, WEVU_EFFECT_SCOPE_KEY, WEVU_EXPOSED_KEY, WEVU_HOOKS_KEY, WEVU_HOST_COMMIT_PROMISE_KEY, WEVU_ON_BEFORE_UNMOUNT_HOOK, WEVU_PAGE_SCROLL_HOOK_DEPTH_KEY, WEVU_PROPS_DERIVED_KEYS_KEY, WEVU_PUBLIC_RUNTIME_KEY, WEVU_SETUP_CONTEXT_INSTANCE_KEY, WEVU_SLOT_OWNER_ID_KEY, WEVU_WATCH_STOPS_KEY } from "@weapp-core/constants";
20
+ import { WEAPP_VITE_STATEFUL_HMR_BRIDGE_KEY, WEVU_EFFECT_SCOPE_KEY, WEVU_EXPOSED_KEY, WEVU_HOOKS_KEY, WEVU_HOST_COMMIT_PROMISE_KEY, WEVU_ON_BEFORE_UNMOUNT_HOOK, WEVU_PAGE_SCROLL_HOOK_DEPTH_KEY, WEVU_PARENT_INSTANCE_KEY, WEVU_PROPS_DERIVED_KEYS_KEY, WEVU_PROVIDES_KEY, WEVU_PUBLIC_RUNTIME_KEY, WEVU_RUNTIME_APP_KEY, WEVU_SETUP_CONTEXT_INSTANCE_KEY, WEVU_SLOT_OWNER_ID_KEY, WEVU_WATCH_STOPS_KEY } from "@weapp-core/constants";
18
21
 
19
22
  //#region src/runtime/register/runtimeInstance.ts
20
23
  const initialReactiveSetupSnapshots = /* @__PURE__ */ new WeakMap();
@@ -78,14 +81,30 @@ function hasTemplateRuntimeBindings(runtimeApp) {
78
81
  * @internal
79
82
  */
80
83
  function mountRuntimeInstance(target, runtimeApp, watchMap, setup, options) {
81
- if (target.__wevu) return target.__wevu;
84
+ if (target.__wevu) {
85
+ if (import.meta.env?.PROD !== true && target[WEVU_RUNTIME_APP_KEY] && target[WEVU_RUNTIME_APP_KEY] !== runtimeApp) return refreshRuntimeInstance(target, runtimeApp, watchMap, setup, {
86
+ snapshotOmitKeys: options?.snapshotOmitKeys,
87
+ attached: options?.attached
88
+ });
89
+ return target.__wevu;
90
+ }
91
+ try {
92
+ return mountRuntimeInstanceWithContext(target, runtimeApp, watchMap, setup, options);
93
+ } catch (error) {
94
+ try {
95
+ teardownRuntimeInstance(target, { skipHooks: true });
96
+ } catch {}
97
+ throw error;
98
+ }
99
+ }
100
+ function mountRuntimeInstanceWithContext(target, runtimeApp, watchMap, setup, options) {
82
101
  const runtimeSetDataOptions = runtimeApp.__wevuSetDataOptions;
83
102
  const scopedSlotHooks = hasTemplateRuntimeBindings(runtimeApp) ? requireRuntimeCapability("scopedSlots", "mountRuntimeInstance(scoped-slot bindings)") : void 0;
84
103
  const scopedSlotState = scopedSlotHooks?.prepareMount(target);
85
104
  const templateRefBindings = target.__wevuTemplateRefs;
86
105
  if (Array.isArray(templateRefBindings) && templateRefBindings.length) requireRuntimeCapability("templateRefs", "mountRuntimeInstance(template refs)");
87
106
  const highFrequencyWarningHooks = isSetDataHighFrequencyWarningRequested(runtimeSetDataOptions?.highFrequencyWarning) ? requireRuntimeCapability("setDataHighFrequencyWarning", "mountRuntimeInstance(setData.highFrequencyWarning)") : void 0;
88
- attachRuntimeProvideParentContext(target, runtimeApp);
107
+ attachRuntimeProvideParentContext(target, runtimeApp, options?.attached, options?.layoutParent);
89
108
  safeMarkNoSetData(target);
90
109
  const suspendWhenHidden = Boolean(runtimeSetDataOptions?.suspendWhenHidden);
91
110
  const targetLabel = typeof target.route === "string" && target.route ? `page:${target.route}` : typeof target.is === "string" && target.is ? `component:${target.is}` : "unknown-target";
@@ -101,6 +120,7 @@ function mountRuntimeInstance(target, runtimeApp, watchMap, setup, options) {
101
120
  let pendingPayload;
102
121
  let pendingSettlementHead;
103
122
  let pendingSettlementTail;
123
+ let pendingObservers;
104
124
  let pendingRawCallbacks = [];
105
125
  const ownsHostCommit = !(WEVU_HOST_COMMIT_PROMISE_KEY in target);
106
126
  let pendingHostCommits = 0;
@@ -163,7 +183,7 @@ function mountRuntimeInstance(target, runtimeApp, watchMap, setup, options) {
163
183
  const syncNativeOwnerId = () => {
164
184
  if (scopedSlotState) scopedSlotHooks?.syncNativeOwnerId(target, scopedSlotState);
165
185
  };
166
- const appendPendingSettlement = (settle) => {
186
+ const appendPendingSettlement = (settle, observer) => {
167
187
  const record = {
168
188
  settle,
169
189
  next: void 0
@@ -171,6 +191,7 @@ function mountRuntimeInstance(target, runtimeApp, watchMap, setup, options) {
171
191
  if (pendingSettlementTail) pendingSettlementTail.next = record;
172
192
  else pendingSettlementHead = record;
173
193
  pendingSettlementTail = record;
194
+ if (observer) (pendingObservers ?? (pendingObservers = [])).push(observer);
174
195
  };
175
196
  const settlePendingRecords = (first, settlement, cause) => {
176
197
  let current = first;
@@ -184,17 +205,19 @@ function mountRuntimeInstance(target, runtimeApp, watchMap, setup, options) {
184
205
  isFirst = false;
185
206
  }
186
207
  };
187
- const dispatchPhysicalSetData = (payload, settle) => {
208
+ const dispatchPhysicalSetData = (payload, settle, observer) => {
188
209
  const generation = dispatchGeneration;
189
210
  beginHostCommit();
190
211
  refreshOwnerSnapshot();
191
212
  observeSetDataCompletion({
213
+ observer,
192
214
  invoke: (callback) => {
193
215
  const setData = resolveNativeSetData(target);
194
216
  if (!setData) {
195
217
  callback();
196
218
  return;
197
219
  }
220
+ if (observer) observePhysicalDispatch(observer, payload);
198
221
  return callNativeSetData(target, setData, payload, callback);
199
222
  },
200
223
  completion: "callback",
@@ -224,6 +247,8 @@ function mountRuntimeInstance(target, runtimeApp, watchMap, setup, options) {
224
247
  pendingSettlementHead = void 0;
225
248
  pendingSettlementTail = void 0;
226
249
  pendingRawCallbacks = [];
250
+ const observers = pendingObservers;
251
+ pendingObservers = void 0;
227
252
  dispatchPhysicalSetData(payload, (settlement, cause) => {
228
253
  if (settlement === "committed") {
229
254
  try {
@@ -234,9 +259,14 @@ function mountRuntimeInstance(target, runtimeApp, watchMap, setup, options) {
234
259
  return;
235
260
  }
236
261
  settlePendingRecords(settlements, settlement, cause);
262
+ }, observers && {
263
+ dispatch: (info) => observers.forEach((item) => item.dispatch(info)),
264
+ returned: (returnedAt) => observers.forEach((item) => item.returned(returnedAt)),
265
+ complete: (boundary) => observers.forEach((item) => item.complete(boundary))
237
266
  });
238
267
  };
239
268
  const abandonPendingSetData = () => {
269
+ pendingObservers = void 0;
240
270
  const settlements = pendingSettlementHead;
241
271
  pendingPayload = void 0;
242
272
  pendingSettlementHead = void 0;
@@ -317,7 +347,7 @@ function mountRuntimeInstance(target, runtimeApp, watchMap, setup, options) {
317
347
  if (callbackCalled) handleSuccess();
318
348
  return result;
319
349
  },
320
- __wevu_dispatchSetData(payload, settle) {
350
+ __wevu_dispatchSetData(payload, settle, observer) {
321
351
  highFrequencyWarning?.();
322
352
  if (disposed) {
323
353
  settle("abandoned");
@@ -325,12 +355,12 @@ function mountRuntimeInstance(target, runtimeApp, watchMap, setup, options) {
325
355
  }
326
356
  if (!enabled || suspendWhenHidden && !visible) {
327
357
  bufferPayload(payload);
328
- appendPendingSettlement(settle);
358
+ appendPendingSettlement(settle, observer);
329
359
  refreshOwnerSnapshot();
330
360
  return;
331
361
  }
332
362
  resetHostCommitFailure();
333
- dispatchPhysicalSetData(payload, settle);
363
+ dispatchPhysicalSetData(payload, settle, observer);
334
364
  },
335
365
  __wevu_enableSetData(discardPending = false) {
336
366
  enabled = true;
@@ -469,7 +499,7 @@ function mountRuntimeInstance(target, runtimeApp, watchMap, setup, options) {
469
499
  syncNativeOwnerId();
470
500
  const watchStops = watchMap ? registerWatches(runtimeWithDefaults, watchMap, target, { deferMissingSourceBaseline: Boolean(setup) }) : [];
471
501
  if (watchStops.length) target[WEVU_WATCH_STOPS_KEY] = watchStops;
472
- if (setup) try {
502
+ if (setup) {
473
503
  runRuntimeSetupPhase({
474
504
  target,
475
505
  runtime,
@@ -478,7 +508,7 @@ function mountRuntimeInstance(target, runtimeApp, watchMap, setup, options) {
478
508
  runtimeProxy,
479
509
  setup
480
510
  });
481
- if (typeof getMiniProgramRuntimeGlobalObject()?.[WEAPP_VITE_STATEFUL_HMR_BRIDGE_KEY]?.trackWevuComponent === "function") {
511
+ if (import.meta.env?.PROD !== true && typeof getMiniProgramRuntimeGlobalObject()?.[WEAPP_VITE_STATEFUL_HMR_BRIDGE_KEY]?.trackWevuComponent === "function") {
482
512
  const initialReactiveSetupSnapshot = {};
483
513
  for (const [key, value] of Object.entries(runtimeWithDefaults.setupState ?? {})) if (isReactive(value)) initialReactiveSetupSnapshot[key] = cloneInitialSnapshotValue(value);
484
514
  initialReactiveSetupSnapshots.set(runtimeWithDefaults, initialReactiveSetupSnapshot);
@@ -486,13 +516,7 @@ function mountRuntimeInstance(target, runtimeApp, watchMap, setup, options) {
486
516
  if (!options?.deferSetData) runtimeWithSyncFlush.__wevu_flushSetupSnapshotSync?.();
487
517
  if (!options?.deferSetData) refreshOwnerSnapshot();
488
518
  for (const stop of watchStops) stop.resume();
489
- } catch (error) {
490
- try {
491
- teardownRuntimeInstance(target, { skipHooks: true });
492
- } catch {}
493
- throw error;
494
- }
495
- else if (!options?.deferSetData && target.properties && typeof target.properties === "object" && Object.keys(target.properties).length > 0) {
519
+ } else if (!options?.deferSetData && target.properties && typeof target.properties === "object" && Object.keys(target.properties).length > 0) {
496
520
  runtimeWithSyncFlush.__wevu_flushSetupSnapshotSync?.();
497
521
  refreshOwnerSnapshot();
498
522
  }
@@ -598,6 +622,7 @@ function teardownRuntimeInstance(target, options) {
598
622
  }
599
623
  }
600
624
  },
625
+ ...!import.meta.env?.PLATFORM || import.meta.env?.PLATFORM === "weapp" ? [() => releaseNativeDeclaration(target, options?.preserveNativeDeclarationChildren)] : [],
601
626
  () => runtimeCapabilityRegistry.scopedSlots?.teardown(target),
602
627
  () => {
603
628
  if (Array.isArray(target.__wevuTemplateRefs) && target.__wevuTemplateRefs.length > 0) requireRuntimeCapability("templateRefs", "teardownRuntimeInstance(template refs)").clear(target);
@@ -635,6 +660,15 @@ function teardownRuntimeInstance(target, options) {
635
660
  },
636
661
  () => {
637
662
  if (WEVU_PUBLIC_RUNTIME_KEY in target) delete target[WEVU_PUBLIC_RUNTIME_KEY];
663
+ },
664
+ () => {
665
+ delete target[WEVU_PARENT_INSTANCE_KEY];
666
+ },
667
+ () => {
668
+ delete target[WEVU_PROVIDES_KEY];
669
+ },
670
+ () => {
671
+ delete target[WEVU_RUNTIME_APP_KEY];
638
672
  }
639
673
  ]);
640
674
  }
@@ -646,10 +680,17 @@ function refreshRuntimeInstance(target, runtimeApp, watchMap, setup, options) {
646
680
  const previousRuntime = target.__wevu;
647
681
  const initialSetupState = previousRuntime ? initialReactiveSetupSnapshots.get(previousRuntime) : void 0;
648
682
  const previousRuntimeState = previousRuntime ? createRuntimeStateSnapshot(previousRuntime, target.data, options?.stateSnapshot) : void 0;
649
- teardownRuntimeInstance(target, { skipHooks: true });
683
+ const parent = target[WEVU_PARENT_INSTANCE_KEY];
684
+ const layoutParent = parent && isRuntimeLayoutComponentTarget(parent) ? parent : void 0;
685
+ teardownRuntimeInstance(target, {
686
+ skipHooks: true,
687
+ preserveNativeDeclarationChildren: true
688
+ });
650
689
  const nextRuntime = mountRuntimeInstance(target, runtimeApp, watchMap, setup, {
651
690
  deferSetData: true,
652
- snapshotOmitKeys: options?.snapshotOmitKeys
691
+ snapshotOmitKeys: options?.snapshotOmitKeys,
692
+ attached: options?.attached,
693
+ layoutParent
653
694
  });
654
695
  const stateSnapshot = previousRuntimeState ?? (options?.stateSnapshot ? createRuntimeStateSnapshot(nextRuntime, options.stateSnapshot, options.stateSnapshot) : void 0);
655
696
  if (stateSnapshot) {