wevu 7.4.0 → 7.6.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 (291) hide show
  1. package/README.md +2 -0
  2. package/dist/config/defaults.d.mts +44 -0
  3. package/dist/config/pageFeatures.d.mts +51 -0
  4. package/dist/config.d.mts +4 -0
  5. package/dist/config.mjs +1 -0
  6. package/dist/dev/_virtual/{_@oxc-project_runtime@0.151.0 → _@oxc-project_runtime@0.154.0}/helpers/esm/defineProperty.mjs +1 -1
  7. package/dist/dev/_virtual/{_@oxc-project_runtime@0.151.0 → _@oxc-project_runtime@0.154.0}/helpers/esm/toPrimitive.mjs +1 -1
  8. package/dist/dev/_virtual/{_@oxc-project_runtime@0.151.0 → _@oxc-project_runtime@0.154.0}/helpers/esm/toPropertyKey.mjs +1 -1
  9. package/dist/dev/_virtual/{_@oxc-project_runtime@0.151.0 → _@oxc-project_runtime@0.154.0}/helpers/esm/typeof.mjs +1 -1
  10. package/dist/dev/package.mjs +1 -1
  11. package/dist/dev/reactivity/computed.mjs.map +1 -1
  12. package/dist/dev/reactivity/core.mjs +1 -1
  13. package/dist/dev/reactivity/ref.mjs +1 -1
  14. package/dist/dev/reactivity/ref.mjs.map +1 -1
  15. package/dist/dev/runtime/app/diagnostics.mjs +5 -1
  16. package/dist/dev/runtime/app/diagnostics.mjs.map +1 -1
  17. package/dist/dev/runtime/app/mount.mjs +8 -3
  18. package/dist/dev/runtime/app/mount.mjs.map +1 -1
  19. package/dist/dev/runtime/app/setData/commitTracker.mjs +39 -4
  20. package/dist/dev/runtime/app/setData/commitTracker.mjs.map +1 -1
  21. package/dist/dev/runtime/app/setData/observation.mjs +109 -0
  22. package/dist/dev/runtime/app/setData/observation.mjs.map +1 -0
  23. package/dist/dev/runtime/app/setData/scheduler.mjs +12 -1
  24. package/dist/dev/runtime/app/setData/scheduler.mjs.map +1 -1
  25. package/dist/dev/runtime/app/setDataOptions.mjs +1 -0
  26. package/dist/dev/runtime/app/setDataOptions.mjs.map +1 -1
  27. package/dist/dev/runtime/define/initialComputed.mjs +13 -12
  28. package/dist/dev/runtime/define/initialComputed.mjs.map +1 -1
  29. package/dist/dev/runtime/define/props.mjs +5 -1
  30. package/dist/dev/runtime/define/props.mjs.map +1 -1
  31. package/dist/dev/runtime/define/scopedSlotOptions.mjs +2 -1
  32. package/dist/dev/runtime/define/scopedSlotOptions.mjs.map +1 -1
  33. package/dist/dev/runtime/define/setupResult.mjs +3 -5
  34. package/dist/dev/runtime/define/setupResult.mjs.map +1 -1
  35. package/dist/dev/runtime/define.mjs +3 -8
  36. package/dist/dev/runtime/define.mjs.map +1 -1
  37. package/dist/dev/runtime/features/scopedSlots.mjs.map +1 -1
  38. package/dist/dev/runtime/pageLayout.mjs.map +1 -1
  39. package/dist/dev/runtime/register/component/hmrRegistration.mjs +15 -0
  40. package/dist/dev/runtime/register/component/hmrRegistration.mjs.map +1 -0
  41. package/dist/dev/runtime/register/component/props.mjs +15 -5
  42. package/dist/dev/runtime/register/component/props.mjs.map +1 -1
  43. package/dist/dev/runtime/register/component/registerDefinition.mjs +30 -18
  44. package/dist/dev/runtime/register/component/registerDefinition.mjs.map +1 -1
  45. package/dist/dev/runtime/register/component.mjs +23 -12
  46. package/dist/dev/runtime/register/component.mjs.map +1 -1
  47. package/dist/dev/runtime/register/runtimeInstance/methodBridge.mjs +14 -7
  48. package/dist/dev/runtime/register/runtimeInstance/methodBridge.mjs.map +1 -1
  49. package/dist/dev/runtime/register/runtimeInstance/nativeDeclaration.mjs +78 -0
  50. package/dist/dev/runtime/register/runtimeInstance/nativeDeclaration.mjs.map +1 -0
  51. package/dist/dev/runtime/register/runtimeInstance/provideContext.mjs +52 -8
  52. package/dist/dev/runtime/register/runtimeInstance/provideContext.mjs.map +1 -1
  53. package/dist/dev/runtime/register/runtimeInstance/setupPhase.mjs +2 -25
  54. package/dist/dev/runtime/register/runtimeInstance/setupPhase.mjs.map +1 -1
  55. package/dist/dev/runtime/register/runtimeInstance/utils.mjs.map +1 -1
  56. package/dist/dev/runtime/register/runtimeInstance.mjs +69 -29
  57. package/dist/dev/runtime/register/runtimeInstance.mjs.map +1 -1
  58. package/dist/dev/runtime/register/watch.mjs +1 -3
  59. package/dist/dev/runtime/register/watch.mjs.map +1 -1
  60. package/dist/fetch.mjs +1 -1
  61. package/dist/index.d.mts +13 -8
  62. package/dist/internal-reactivity.d.mts +2 -1
  63. package/dist/internal-template.mjs +1 -1
  64. package/dist/jsx-runtime.d.mts +2 -1
  65. package/dist/macros/shared.d.mts +3 -2
  66. package/dist/macros.d.mts +3 -10
  67. package/dist/package.mjs +1 -1
  68. package/dist/reactivity/asyncDerivation.d.mts +2 -1
  69. package/dist/reactivity/computed.d.mts +3 -7
  70. package/dist/reactivity/core.mjs +1 -1
  71. package/dist/reactivity/index.d.mts +2 -1
  72. package/dist/reactivity/reactive/mutation.d.mts +2 -1
  73. package/dist/reactivity/reactive/patch.mjs +1 -1
  74. package/dist/reactivity/reactive/patchState.mjs +1 -1
  75. package/dist/reactivity/ref.d.mts +1 -1
  76. package/dist/reactivity/ref.mjs +1 -1
  77. package/dist/reactivity/toRefs.d.mts +2 -1
  78. package/dist/reactivity/watch/helpers.mjs +1 -1
  79. package/dist/reactivity/watch/types.d.mts +2 -1
  80. package/dist/router/initialNavigation.mjs +1 -1
  81. package/dist/router/types.d.mts +2 -1
  82. package/dist/router/useRoute.mjs +1 -1
  83. package/dist/routerInternal/matching.mjs +1 -1
  84. package/dist/routerInternal/params.mjs +1 -1
  85. package/dist/routerInternal/path.mjs +1 -1
  86. package/dist/routerInternal/query.mjs +1 -1
  87. package/dist/routerInternal/records.mjs +1 -1
  88. package/dist/runtime/app/context.mjs +1 -1
  89. package/dist/runtime/app/diagnostics.mjs +1 -1
  90. package/dist/runtime/app/mount.mjs +1 -1
  91. package/dist/runtime/app/setData/commitTracker.d.mts +2 -1
  92. package/dist/runtime/app/setData/commitTracker.mjs +1 -1
  93. package/dist/runtime/app/setData/observation.d.mts +13 -0
  94. package/dist/runtime/app/setData/observation.mjs +1 -0
  95. package/dist/runtime/app/setData/scheduler.d.mts +1 -0
  96. package/dist/runtime/app/setData/scheduler.mjs +1 -1
  97. package/dist/runtime/app/setDataOptions.mjs +1 -1
  98. package/dist/runtime/app.d.mts +1 -1
  99. package/dist/runtime/capabilities.d.mts +2 -2
  100. package/dist/runtime/define/initialComputed.mjs +1 -1
  101. package/dist/runtime/define/props.mjs +1 -1
  102. package/dist/runtime/define/scopedSlotOptions.mjs +1 -1
  103. package/dist/runtime/define/setupResult.mjs +1 -1
  104. package/dist/runtime/define.d.mts +5 -3
  105. package/dist/runtime/define.mjs +1 -1
  106. package/dist/runtime/diff.mjs +1 -1
  107. package/dist/runtime/features/publicLayout.d.mts +2 -1
  108. package/dist/runtime/features/publicLayout.mjs +1 -1
  109. package/dist/runtime/features/scopedSlots.d.mts +3 -2
  110. package/dist/runtime/index.d.mts +7 -4
  111. package/dist/runtime/jsxIsland.mjs +1 -1
  112. package/dist/runtime/pageLayout.d.mts +3 -2
  113. package/dist/runtime/pageLayout.mjs +1 -1
  114. package/dist/runtime/pageScroll.mjs +1 -1
  115. package/dist/runtime/register/app.d.mts +1 -1
  116. package/dist/runtime/register/component/alipayRegistration.mjs +1 -1
  117. package/dist/runtime/register/component/hmrRegistration.mjs +1 -0
  118. package/dist/runtime/register/component/lifecycle.mjs +1 -1
  119. package/dist/runtime/register/component/props.mjs +1 -1
  120. package/dist/runtime/register/component/registerDefinition.mjs +1 -1
  121. package/dist/runtime/register/component/registerNativeDefinition.mjs +1 -1
  122. package/dist/runtime/register/component.d.mts +1 -1
  123. package/dist/runtime/register/component.mjs +1 -1
  124. package/dist/runtime/register/inline.d.mts +2 -1
  125. package/dist/runtime/register/runtimeInstance/methodBridge.mjs +1 -1
  126. package/dist/runtime/register/runtimeInstance/nativeDeclaration.mjs +1 -0
  127. package/dist/runtime/register/runtimeInstance/provideContext.mjs +1 -1
  128. package/dist/runtime/register/runtimeInstance/setupPhase.mjs +1 -1
  129. package/dist/runtime/register/runtimeInstance.d.mts +11 -6
  130. package/dist/runtime/register/runtimeInstance.mjs +1 -1
  131. package/dist/runtime/register/setup.d.mts +2 -1
  132. package/dist/runtime/register/watch.d.mts +2 -1
  133. package/dist/runtime/register/watch.mjs +1 -1
  134. package/dist/runtime/setupTracking.mjs +1 -1
  135. package/dist/runtime/templateRefTypes.d.mts +3 -5
  136. package/dist/runtime/templateRefs.mjs +1 -1
  137. package/dist/runtime/types/core.d.mts +3 -7
  138. package/dist/runtime/types/miniprogramHostSources.d.mts +1 -0
  139. package/dist/runtime/types/options.d.mts +6 -52
  140. package/dist/runtime/types/props/propTypes.d.mts +2 -1
  141. package/dist/runtime/types/props/router.d.mts +2 -1
  142. package/dist/runtime/types/props/setup.d.mts +2 -1
  143. package/dist/runtime/types/runtime.d.mts +3 -1
  144. package/dist/runtime/types/setData.d.mts +30 -0
  145. package/dist/runtime/types.d.mts +5 -3
  146. package/dist/runtime/uniAppHost.d.mts +2 -1
  147. package/dist/runtime/vueCompat/model.d.mts +3 -2
  148. package/dist/runtime/vueCompat/router.d.mts +2 -1
  149. package/dist/scheduler.mjs +1 -1
  150. package/dist/store/storeToRefs.d.mts +2 -1
  151. package/dist/store/types.d.mts +4 -3
  152. package/dist/types/definitions.d.mts +7 -0
  153. package/dist/types/pageLayout.d.mts +4 -0
  154. package/dist/types/pageMeta.d.mts +10 -0
  155. package/dist/types/reactivity.d.mts +13 -0
  156. package/dist/types.d.mts +5 -0
  157. package/dist/types.mjs +1 -0
  158. package/dist/vue-demi.d.mts +13 -7
  159. package/dist/vue-types.d.mts +3 -4
  160. package/dist/web-apis.mjs +1 -1
  161. package/package.json +23 -13
  162. package/dist/dev/api/vitest/setup.d.mts +0 -1
  163. package/dist/dev/api/vitest.d.mts +0 -1
  164. package/dist/dev/api.d.mts +0 -1
  165. package/dist/dev/compiler.d.mts +0 -1
  166. package/dist/dev/fetch.d.mts +0 -9
  167. package/dist/dev/index.d.mts +0 -72
  168. package/dist/dev/internal-reactivity.d.mts +0 -18
  169. package/dist/dev/internal-runtime.d.mts +0 -45
  170. package/dist/dev/internal-template.d.mts +0 -2
  171. package/dist/dev/jsxTypes.d.mts +0 -9
  172. package/dist/dev/macros/shared.d.mts +0 -83
  173. package/dist/dev/macros.d.mts +0 -71
  174. package/dist/dev/reactivity/asyncDerivation.d.mts +0 -41
  175. package/dist/dev/reactivity/computed.d.mts +0 -25
  176. package/dist/dev/reactivity/core.d.mts +0 -35
  177. package/dist/dev/reactivity/index.d.mts +0 -16
  178. package/dist/dev/reactivity/reactive/mutation.d.mts +0 -21
  179. package/dist/dev/reactivity/reactive/patch.d.mts +0 -18
  180. package/dist/dev/reactivity/reactive/shallow.d.mts +0 -22
  181. package/dist/dev/reactivity/reactive/shared.d.mts +0 -4
  182. package/dist/dev/reactivity/reactive.d.mts +0 -42
  183. package/dist/dev/reactivity/readonly.d.mts +0 -27
  184. package/dist/dev/reactivity/ref.d.mts +0 -27
  185. package/dist/dev/reactivity/shallowRef.d.mts +0 -19
  186. package/dist/dev/reactivity/toRefs.d.mts +0 -43
  187. package/dist/dev/reactivity/traverse.d.mts +0 -8
  188. package/dist/dev/reactivity/watch/types.d.mts +0 -43
  189. package/dist/dev/reactivity/watch.d.mts +0 -22
  190. package/dist/dev/router/auto-routes.d.mts +0 -8
  191. package/dist/dev/router/createRouter.d.mts +0 -9
  192. package/dist/dev/router/navigationCore.d.mts +0 -7
  193. package/dist/dev/router/resolve.d.mts +0 -7
  194. package/dist/dev/router/routeSync.d.mts +0 -2
  195. package/dist/dev/router/scrollRestoration/adapters.d.mts +0 -8
  196. package/dist/dev/router/scrollRestoration/controller.d.mts +0 -8
  197. package/dist/dev/router/scrollRestoration/host.d.mts +0 -3
  198. package/dist/dev/router/scrollRestoration/index.d.mts +0 -9
  199. package/dist/dev/router/scrollRestoration/types.d.mts +0 -61
  200. package/dist/dev/router/types.d.mts +0 -267
  201. package/dist/dev/router/useRoute.d.mts +0 -20
  202. package/dist/dev/router/useRouter.d.mts +0 -9
  203. package/dist/dev/router.d.mts +0 -30
  204. package/dist/dev/routerInternal/location.d.mts +0 -2
  205. package/dist/dev/routerInternal/matching.d.mts +0 -2
  206. package/dist/dev/routerInternal/params.d.mts +0 -2
  207. package/dist/dev/routerInternal/query.d.mts +0 -7
  208. package/dist/dev/routerInternal/records.d.mts +0 -2
  209. package/dist/dev/routerInternal/recordsWarnings.d.mts +0 -2
  210. package/dist/dev/routerInternal/shared.d.mts +0 -9
  211. package/dist/dev/routerInternal/snapshots.d.mts +0 -2
  212. package/dist/dev/routerInternal/types.d.mts +0 -9
  213. package/dist/dev/runtime/app/pending.d.mts +0 -10
  214. package/dist/dev/runtime/app/setData/commitTracker.d.mts +0 -13
  215. package/dist/dev/runtime/app/setData/scheduler.d.mts +0 -51
  216. package/dist/dev/runtime/app.d.mts +0 -8
  217. package/dist/dev/runtime/capabilities.d.mts +0 -78
  218. package/dist/dev/runtime/css.d.mts +0 -14
  219. package/dist/dev/runtime/defaults.d.mts +0 -12
  220. package/dist/dev/runtime/define.d.mts +0 -118
  221. package/dist/dev/runtime/disposables.d.mts +0 -31
  222. package/dist/dev/runtime/elementIntersectionObserver.d.mts +0 -26
  223. package/dist/dev/runtime/features/inlineEvents.d.mts +0 -7
  224. package/dist/dev/runtime/features/jsxIslands.d.mts +0 -7
  225. package/dist/dev/runtime/features/layout.d.mts +0 -7
  226. package/dist/dev/runtime/features/patchStrategy.d.mts +0 -7
  227. package/dist/dev/runtime/features/publicLayout.d.mts +0 -24
  228. package/dist/dev/runtime/features/scopedSlots.d.mts +0 -23
  229. package/dist/dev/runtime/features/setDataHighFrequencyWarning.d.mts +0 -7
  230. package/dist/dev/runtime/features/templateRefs.d.mts +0 -7
  231. package/dist/dev/runtime/hooks/base.d.mts +0 -27
  232. package/dist/dev/runtime/hooks/register.d.mts +0 -30
  233. package/dist/dev/runtime/hooks/vue.d.mts +0 -52
  234. package/dist/dev/runtime/hooks.d.mts +0 -4
  235. package/dist/dev/runtime/index.d.mts +0 -46
  236. package/dist/dev/runtime/intersectionObserver.d.mts +0 -14
  237. package/dist/dev/runtime/jsxIsland.d.mts +0 -37
  238. package/dist/dev/runtime/layoutBridge.d.mts +0 -55
  239. package/dist/dev/runtime/noSetData.d.mts +0 -5
  240. package/dist/dev/runtime/pageEnvironment.d.mts +0 -50
  241. package/dist/dev/runtime/pageLayout.d.mts +0 -25
  242. package/dist/dev/runtime/pageScroll.d.mts +0 -29
  243. package/dist/dev/runtime/provide.d.mts +0 -60
  244. package/dist/dev/runtime/provideStore.d.mts +0 -7
  245. package/dist/dev/runtime/publicRuntime.d.mts +0 -22
  246. package/dist/dev/runtime/pullDownRefresh.d.mts +0 -12
  247. package/dist/dev/runtime/register/app.d.mts +0 -14
  248. package/dist/dev/runtime/register/component.d.mts +0 -17
  249. package/dist/dev/runtime/register/inline.d.mts +0 -15
  250. package/dist/dev/runtime/register/runtimeInstance.d.mts +0 -26
  251. package/dist/dev/runtime/register/setup.d.mts +0 -11
  252. package/dist/dev/runtime/register/watch.d.mts +0 -12
  253. package/dist/dev/runtime/register.d.mts +0 -5
  254. package/dist/dev/runtime/selectorQuery.d.mts +0 -54
  255. package/dist/dev/runtime/template.d.mts +0 -6
  256. package/dist/dev/runtime/templateRefTypes.d.mts +0 -12
  257. package/dist/dev/runtime/types/core.d.mts +0 -35
  258. package/dist/dev/runtime/types/miniprogram.d.mts +0 -84
  259. package/dist/dev/runtime/types/miniprogramHost.d.mts +0 -45
  260. package/dist/dev/runtime/types/miniprogramHostSources.d.mts +0 -112
  261. package/dist/dev/runtime/types/options.d.mts +0 -138
  262. package/dist/dev/runtime/types/props/propTypes.d.mts +0 -79
  263. package/dist/dev/runtime/types/props/router.d.mts +0 -51
  264. package/dist/dev/runtime/types/props/setup.d.mts +0 -96
  265. package/dist/dev/runtime/types/props.d.mts +0 -4
  266. package/dist/dev/runtime/types/runtime.d.mts +0 -59
  267. package/dist/dev/runtime/types/setData.d.mts +0 -237
  268. package/dist/dev/runtime/types.d.mts +0 -29
  269. package/dist/dev/runtime/uniAppHost.d.mts +0 -8
  270. package/dist/dev/runtime/updatePerformance.d.mts +0 -13
  271. package/dist/dev/runtime/use.d.mts +0 -13
  272. package/dist/dev/runtime/vueCompat/context.d.mts +0 -8
  273. package/dist/dev/runtime/vueCompat/model.d.mts +0 -30
  274. package/dist/dev/runtime/vueCompat/router.d.mts +0 -29
  275. package/dist/dev/runtime/vueCompat/templateRef.d.mts +0 -9
  276. package/dist/dev/runtime/vueCompat.d.mts +0 -5
  277. package/dist/dev/scheduler.d.mts +0 -4
  278. package/dist/dev/store/define.d.mts +0 -8
  279. package/dist/dev/store/manager.d.mts +0 -16
  280. package/dist/dev/store/storeToRefs.d.mts +0 -11
  281. package/dist/dev/store/types.d.mts +0 -106
  282. package/dist/dev/store.d.mts +0 -5
  283. package/dist/dev/version.d.mts +0 -4
  284. package/dist/dev/vue-augment.d.mts +0 -8
  285. package/dist/dev/vue-demi.d.mts +0 -87
  286. package/dist/dev/vue-types.d.mts +0 -19
  287. package/dist/dev/web-apis.d.mts +0 -3
  288. /package/dist/_virtual/{_@oxc-project_runtime@0.151.0 → _@oxc-project_runtime@0.154.0}/helpers/esm/defineProperty.mjs +0 -0
  289. /package/dist/_virtual/{_@oxc-project_runtime@0.151.0 → _@oxc-project_runtime@0.154.0}/helpers/esm/toPrimitive.mjs +0 -0
  290. /package/dist/_virtual/{_@oxc-project_runtime@0.151.0 → _@oxc-project_runtime@0.154.0}/helpers/esm/toPropertyKey.mjs +0 -0
  291. /package/dist/_virtual/{_@oxc-project_runtime@0.151.0 → _@oxc-project_runtime@0.154.0}/helpers/esm/typeof.mjs +0 -0
@@ -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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from "../../../reactivity/reactive/shared.mjs";
3
2
  import { shallowReactive } from "../../../reactivity/reactive/shallow.mjs";
4
- import { isReactive } from "../../../reactivity/reactive.mjs";
5
3
  import { getCurrentInstance, getCurrentSetupContext, setCurrentInstance, setCurrentSetupContext } from "../../hooks/base.mjs";
6
4
  import { hasOwn } from "../../../utils.mjs";
7
- import { hasTrackableSetupBinding } from "../../setupTracking.mjs";
8
5
  import { normalizeEmitEventName, normalizeEmitPayload } from "../../emit.mjs";
9
6
  import { attachRuntimeSlots, ensureSetupContextInstance, safeMarkNoSetData } from "./setupContext.mjs";
10
- import { preserveSetupAccessor } from "../../define/setupResult.mjs";
7
+ import { applySetupResult } from "../../define/setupResult.mjs";
11
8
  import { runSetupFunction } from "../setup.mjs";
12
9
  import { attachRuntimeSetupState, ensureRuntimeProps } from "./utils.mjs";
13
10
  import { WEVU_ATTRS_KEY, WEVU_EFFECT_SCOPE_KEY, WEVU_EXPOSED_KEY, WEVU_PROP_KEYS_KEY } from "@weapp-core/constants";
@@ -140,27 +137,7 @@ function runRuntimeSetupPhase(options) {
140
137
  setCurrentSetupContext(context);
141
138
  try {
142
139
  const result = instanceScope.run(() => runSetupFunction(setup, props, context));
143
- let methodsChanged = false;
144
- if (result && typeof result === "object") {
145
- const setupResult = result;
146
- const runtimeSetupState = runtime.setupState && typeof runtime.setupState === "object" ? isReactive(runtime.setupState) ? toRaw(runtime.setupState) : runtime.setupState : Object.create(null);
147
- Object.keys(setupResult).forEach((key) => {
148
- const val = setupResult[key];
149
- const preservesAccessor = preserveSetupAccessor(runtimeSetupState, setupResult, key);
150
- if (typeof val === "function" && !preservesAccessor) {
151
- const bound = (...args) => val.apply(runtime.proxy, args);
152
- runtime.methods[key] = bound;
153
- runtime.state[key] = bound;
154
- runtimeSetupState[key] = bound;
155
- methodsChanged = true;
156
- } else {
157
- if (hasTrackableSetupBinding(val)) runtime.__wevu_trackSetupReactiveKey?.(key);
158
- runtime.state[key] = val;
159
- if (!preservesAccessor) runtimeSetupState[key] = val;
160
- }
161
- });
162
- }
163
- if (methodsChanged) runtime.__wevu_touchSetupMethodsVersion?.();
140
+ if (result && typeof result === "object") applySetupResult(runtimeWithDefaults, target, result);
164
141
  } finally {
165
142
  restoreSetupContext();
166
143
  }
@@ -1 +1 @@
1
- {"version":3,"file":"setupPhase.mjs","names":[],"sources":["../../../../../src/runtime/register/runtimeInstance/setupPhase.ts"],"sourcesContent":["import type {\n ComponentPropsOptions,\n ComputedDefinitions,\n DefineAppOptions,\n DefineComponentOptions,\n InternalRuntimeState,\n MethodDefinitions,\n RuntimeInstance,\n} from '../../types'\nimport {\n WEVU_ATTRS_KEY,\n WEVU_EFFECT_SCOPE_KEY,\n WEVU_EXPOSED_KEY,\n WEVU_PROP_KEYS_KEY,\n} from '@weapp-core/constants'\nimport { effectScope, isReactive, shallowReactive, toRaw } from '../../../reactivity'\nimport { hasOwn } from '../../../utils'\nimport { preserveSetupAccessor } from '../../define/setupResult'\nimport { normalizeEmitEventName } from '../../emit'\nimport { getCurrentInstance, getCurrentSetupContext, setCurrentInstance, setCurrentSetupContext } from '../../hooks'\nimport { hasTrackableSetupBinding } from '../../setupTracking'\nimport { runSetupFunction } from '../setup'\nimport {\n attachRuntimeSlots,\n ensureSetupContextInstance,\n normalizeEmitPayload,\n safeMarkNoSetData,\n} from './setupContext'\nimport { attachRuntimeSetupState, ensureRuntimeProps } from './utils'\n\ntype RuntimeSetupFunction<\n D extends object,\n C extends ComputedDefinitions,\n M extends MethodDefinitions,\n> = DefineComponentOptions<ComponentPropsOptions, D, C, M>['setup']\n | DefineAppOptions<D, C, M>['setup']\n\nlet vueCompatInstanceUid = 0\n\nfunction attachVueCompatInstanceView(target: InternalRuntimeState, proxy: Record<string, any>) {\n // 已排队的用户回调可以持有实例;兼容视图与宿主注册表的销毁周期分离。\n let exposedView: Record<string, any> | undefined\n const internal = target as Record<string, any>\n const descriptors: PropertyDescriptorMap = {\n proxy: {\n configurable: true,\n enumerable: false,\n value: proxy,\n writable: false,\n },\n $: {\n configurable: true,\n enumerable: false,\n value: target,\n writable: false,\n },\n uid: {\n configurable: true,\n enumerable: false,\n value: ++vueCompatInstanceUid,\n writable: false,\n },\n exposed: {\n configurable: true,\n enumerable: false,\n get: () => exposedView,\n },\n }\n for (const [key, descriptor] of Object.entries(descriptors)) {\n try {\n Object.defineProperty(internal, key, descriptor)\n }\n catch {\n if ('value' in descriptor) {\n internal[key] = descriptor.value\n }\n }\n }\n const publicDescriptors: PropertyDescriptorMap = {\n $: {\n configurable: true,\n enumerable: false,\n value: target,\n writable: false,\n },\n $el: {\n configurable: true,\n enumerable: false,\n value: target,\n writable: false,\n },\n }\n for (const [key, descriptor] of Object.entries(publicDescriptors)) {\n try {\n Object.defineProperty(proxy, key, descriptor)\n }\n catch {\n proxy[key] = descriptor.value\n }\n }\n return (exposed: Record<string, any>) => {\n exposedView = exposed\n }\n}\n\nfunction isInternalAttrKey(key: string) {\n return key.startsWith('__wv_')\n}\n\nexport function runRuntimeSetupPhase<D extends object, C extends ComputedDefinitions, M extends MethodDefinitions>(options: {\n target: InternalRuntimeState\n runtime: RuntimeInstance<D, C, M>\n runtimeWithDefaults: RuntimeInstance<any, any, any>\n runtimeState: Record<string, any>\n runtimeProxy: Record<string, any>\n setup: RuntimeSetupFunction<D, C, M>\n}) {\n const {\n target,\n runtime,\n runtimeWithDefaults,\n runtimeState,\n runtimeProxy,\n setup,\n } = options\n\n // 从小程序 properties 提取 props 供 setup 使用,并复用 runtime state 上的 props 容器,\n // 避免 computed 首次求值早于 setup 时丢失依赖。\n const mpProperties = ((target as any).properties || {}) as Record<string, any>\n const props = ensureRuntimeProps(target, runtimeState, mpProperties)\n\n // 与 Vue 3 对齐:attrs = 非 props 的 attributes。\n // 在小程序场景中,attrs 来源于 instance.properties 中“未声明在 props/properties 的字段”。\n const attrs = shallowReactive(Object.create(null)) as Record<string, any>\n const declaredPropKeys = new Set(\n Array.isArray((target as any)[WEVU_PROP_KEYS_KEY])\n ? ((target as any)[WEVU_PROP_KEYS_KEY] as string[])\n : [],\n )\n const hasRuntimeStateKey = (key: string) => {\n return runtimeState != null\n && typeof runtimeState === 'object'\n && hasOwn(runtimeState as Record<string, unknown>, key)\n }\n const syncAttrsFromProperties = () => {\n const next = ((target as any).properties && typeof (target as any).properties === 'object')\n ? ((target as any).properties as Record<string, unknown>)\n : undefined\n\n for (const existingKey of Object.keys(attrs)) {\n if (\n !next\n || !hasOwn(next, existingKey)\n || isInternalAttrKey(existingKey)\n || declaredPropKeys.has(existingKey)\n || hasRuntimeStateKey(existingKey)\n ) {\n delete attrs[existingKey]\n }\n }\n\n if (!next) {\n return\n }\n\n for (const [key, value] of Object.entries(next)) {\n if (isInternalAttrKey(key) || declaredPropKeys.has(key) || hasRuntimeStateKey(key)) {\n continue\n }\n attrs[key] = value\n }\n }\n syncAttrsFromProperties()\n\n try {\n Object.defineProperty(target, WEVU_ATTRS_KEY, {\n value: attrs,\n configurable: true,\n enumerable: false,\n writable: false,\n })\n }\n catch {\n ;(target as any)[WEVU_ATTRS_KEY] = attrs\n }\n\n const setupInstance = ensureSetupContextInstance(target, runtimeWithDefaults)\n const updateExposedView = attachVueCompatInstanceView(target, setupInstance as Record<string, any>)\n const slots = attachRuntimeSlots(runtimeState, props)\n const setupState = runtimeWithDefaults.setupState ?? Object.create(null)\n attachRuntimeSetupState(runtimeState, setupState)\n\n const context = safeMarkNoSetData({\n // 与 Vue 3 对齐的 ctx.props\n props,\n\n // 现有运行时能力\n runtime: runtimeWithDefaults,\n state: runtimeState,\n proxy: runtimeProxy,\n bindModel: runtime.bindModel.bind(runtimeWithDefaults),\n watch: runtime.watch.bind(runtimeWithDefaults),\n instance: setupInstance,\n\n // 通过小程序 triggerEvent 派发事件,并兼容 Vue 3 的 emit(event, ...args) 形式。\n emit: (event: string, ...args: any[]) => {\n const { detail, options } = normalizeEmitPayload(args)\n const eventName = normalizeEmitEventName(event)\n setupInstance.triggerEvent(eventName, detail, options)\n },\n\n // 与 Vue 3 对齐的 expose\n expose: (exposed: Record<string, any>) => {\n target[WEVU_EXPOSED_KEY] = exposed\n updateExposedView(exposed)\n },\n\n // 与 Vue 3 对齐的 attrs(小程序中为非 props 属性集合)\n attrs,\n\n // 与 Vue 3 对齐的 slots(由编译期传入的 slot 名元数据驱动)\n slots,\n }) as any\n\n // 仅在同步 setup 执行期间暴露 current instance\n const instanceScope = effectScope(true)\n const previousInstance = getCurrentInstance()\n const previousSetupContext = getCurrentSetupContext()\n const restoreSetupContext = () => {\n // 仅当全局上下文仍属于本次 setup 时恢复父级;嵌套或重入 setup\n // 可能已经建立了新的上下文,不能被旧调用覆盖。\n if (getCurrentInstance() !== target || getCurrentSetupContext() !== context) {\n return\n }\n setCurrentSetupContext(previousSetupContext)\n setCurrentInstance(previousInstance)\n }\n target[WEVU_EFFECT_SCOPE_KEY] = instanceScope\n setCurrentInstance(target)\n setCurrentSetupContext(context)\n try {\n const result = instanceScope.run(() => runSetupFunction(setup, props, context))\n let methodsChanged = false\n if (result && typeof result === 'object') {\n const setupResult = result as Record<string, unknown>\n const runtimeSetupState = (runtime as any).setupState && typeof (runtime as any).setupState === 'object'\n ? (isReactive((runtime as any).setupState) ? toRaw((runtime as any).setupState) : (runtime as any).setupState)\n : Object.create(null)\n Object.keys(setupResult).forEach((key) => {\n const val = setupResult[key]\n const preservesAccessor = preserveSetupAccessor(runtimeSetupState, setupResult, key)\n if (typeof val === 'function' && !preservesAccessor) {\n const bound = (...args: any[]) => (val as any).apply((runtime as any).proxy, args)\n ;(runtime.methods as any)[key] = bound\n ;(runtime.state as any)[key] = bound\n ;(runtimeSetupState as any)[key] = bound\n methodsChanged = true\n }\n else {\n if (hasTrackableSetupBinding(val)) {\n ;(runtime as any).__wevu_trackSetupReactiveKey?.(key)\n }\n ;(runtime.state as any)[key] = val\n if (!preservesAccessor) {\n ;(runtimeSetupState as any)[key] = val\n }\n }\n })\n }\n if (methodsChanged) {\n ;(runtime as any).__wevu_touchSetupMethodsVersion?.()\n }\n }\n finally {\n // current instance/context 只属于本次同步 setup 调用;异步 continuation\n // 不能继续占用全局上下文,否则会污染随后挂载的组件。\n restoreSetupContext()\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAqCA,IAAI,uBAAuB;AAE3B,SAAS,4BAA4B,QAA8B,OAA4B;CAE7F,IAAI;CACJ,MAAM,WAAW;CACjB,MAAM,cAAqC;EACzC,OAAO;GACL,cAAc;GACd,YAAY;GACZ,OAAO;GACP,UAAU;EACZ;EACA,GAAG;GACD,cAAc;GACd,YAAY;GACZ,OAAO;GACP,UAAU;EACZ;EACA,KAAK;GACH,cAAc;GACd,YAAY;GACZ,OAAO,EAAE;GACT,UAAU;EACZ;EACA,SAAS;GACP,cAAc;GACd,YAAY;GACZ,WAAW;EACb;CACF;CACA,KAAK,MAAM,CAAC,KAAK,eAAe,OAAO,QAAQ,WAAW,GACxD,IAAI;EACF,OAAO,eAAe,UAAU,KAAK,UAAU;CACjD,QACM;EACJ,IAAI,WAAW,YACb,SAAS,OAAO,WAAW;CAE/B;CAEF,MAAM,oBAA2C;EAC/C,GAAG;GACD,cAAc;GACd,YAAY;GACZ,OAAO;GACP,UAAU;EACZ;EACA,KAAK;GACH,cAAc;GACd,YAAY;GACZ,OAAO;GACP,UAAU;EACZ;CACF;CACA,KAAK,MAAM,CAAC,KAAK,eAAe,OAAO,QAAQ,iBAAiB,GAC9D,IAAI;EACF,OAAO,eAAe,OAAO,KAAK,UAAU;CAC9C,QACM;EACJ,MAAM,OAAO,WAAW;CAC1B;CAEF,QAAQ,YAAiC;EACvC,cAAc;CAChB;AACF;AAEA,SAAS,kBAAkB,KAAa;CACtC,OAAO,IAAI,WAAW,OAAO;AAC/B;AAEA,SAAgB,qBAAmG,SAOhH;CACD,MAAM,EACJ,QACA,SACA,qBACA,cACA,cACA,UACE;CAIJ,MAAM,eAAiB,OAAe,cAAc,CAAC;CACrD,MAAM,QAAQ,mBAAmB,QAAQ,cAAc,YAAY;CAInE,MAAM,QAAQ,gBAAgB,OA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AI,CAAC,mBACF,AAAC,kBAA0B,OAAO;IAEvC;GACF,CAAC;EACH;EACA,IAAI,gBACD,AAAC,QAAgB,kCAAkC;CAExD,UACQ;EAGN,oBAAoB;CACtB;AACF"}
1
+ {"version":3,"file":"setupPhase.mjs","names":[],"sources":["../../../../../src/runtime/register/runtimeInstance/setupPhase.ts"],"sourcesContent":["import type {\n ComponentPropsOptions,\n ComputedDefinitions,\n DefineAppOptions,\n DefineComponentOptions,\n InternalRuntimeState,\n MethodDefinitions,\n RuntimeInstance,\n} from '../../types'\nimport {\n WEVU_ATTRS_KEY,\n WEVU_EFFECT_SCOPE_KEY,\n WEVU_EXPOSED_KEY,\n WEVU_PROP_KEYS_KEY,\n} from '@weapp-core/constants'\nimport { effectScope, shallowReactive } from '../../../reactivity'\nimport { hasOwn } from '../../../utils'\nimport { applySetupResult } from '../../define/setupResult'\nimport { normalizeEmitEventName } from '../../emit'\nimport { getCurrentInstance, getCurrentSetupContext, setCurrentInstance, setCurrentSetupContext } from '../../hooks'\nimport { runSetupFunction } from '../setup'\nimport {\n attachRuntimeSlots,\n ensureSetupContextInstance,\n normalizeEmitPayload,\n safeMarkNoSetData,\n} from './setupContext'\nimport { attachRuntimeSetupState, ensureRuntimeProps } from './utils'\n\ntype RuntimeSetupFunction<\n D extends object,\n C extends ComputedDefinitions,\n M extends MethodDefinitions,\n> = DefineComponentOptions<ComponentPropsOptions, D, C, M>['setup']\n | DefineAppOptions<D, C, M>['setup']\n\nlet vueCompatInstanceUid = 0\n\nfunction attachVueCompatInstanceView(target: InternalRuntimeState, proxy: Record<string, any>) {\n // 已排队的用户回调可以持有实例;兼容视图与宿主注册表的销毁周期分离。\n let exposedView: Record<string, any> | undefined\n const internal = target as Record<string, any>\n const descriptors: PropertyDescriptorMap = {\n proxy: {\n configurable: true,\n enumerable: false,\n value: proxy,\n writable: false,\n },\n $: {\n configurable: true,\n enumerable: false,\n value: target,\n writable: false,\n },\n uid: {\n configurable: true,\n enumerable: false,\n value: ++vueCompatInstanceUid,\n writable: false,\n },\n exposed: {\n configurable: true,\n enumerable: false,\n get: () => exposedView,\n },\n }\n for (const [key, descriptor] of Object.entries(descriptors)) {\n try {\n Object.defineProperty(internal, key, descriptor)\n }\n catch {\n if ('value' in descriptor) {\n internal[key] = descriptor.value\n }\n }\n }\n const publicDescriptors: PropertyDescriptorMap = {\n $: {\n configurable: true,\n enumerable: false,\n value: target,\n writable: false,\n },\n $el: {\n configurable: true,\n enumerable: false,\n value: target,\n writable: false,\n },\n }\n for (const [key, descriptor] of Object.entries(publicDescriptors)) {\n try {\n Object.defineProperty(proxy, key, descriptor)\n }\n catch {\n proxy[key] = descriptor.value\n }\n }\n return (exposed: Record<string, any>) => {\n exposedView = exposed\n }\n}\n\nfunction isInternalAttrKey(key: string) {\n return key.startsWith('__wv_')\n}\n\nexport function runRuntimeSetupPhase<D extends object, C extends ComputedDefinitions, M extends MethodDefinitions>(options: {\n target: InternalRuntimeState\n runtime: RuntimeInstance<D, C, M>\n runtimeWithDefaults: RuntimeInstance<any, any, any>\n runtimeState: Record<string, any>\n runtimeProxy: Record<string, any>\n setup: RuntimeSetupFunction<D, C, M>\n}) {\n const {\n target,\n runtime,\n runtimeWithDefaults,\n runtimeState,\n runtimeProxy,\n setup,\n } = options\n\n // 从小程序 properties 提取 props 供 setup 使用,并复用 runtime state 上的 props 容器,\n // 避免 computed 首次求值早于 setup 时丢失依赖。\n const mpProperties = ((target as any).properties || {}) as Record<string, any>\n const props = ensureRuntimeProps(target, runtimeState, mpProperties)\n\n // 与 Vue 3 对齐:attrs = 非 props 的 attributes。\n // 在小程序场景中,attrs 来源于 instance.properties 中“未声明在 props/properties 的字段”。\n const attrs = shallowReactive(Object.create(null)) as Record<string, any>\n const declaredPropKeys = new Set(\n Array.isArray((target as any)[WEVU_PROP_KEYS_KEY])\n ? ((target as any)[WEVU_PROP_KEYS_KEY] as string[])\n : [],\n )\n const hasRuntimeStateKey = (key: string) => {\n return runtimeState != null\n && typeof runtimeState === 'object'\n && hasOwn(runtimeState as Record<string, unknown>, key)\n }\n const syncAttrsFromProperties = () => {\n const next = ((target as any).properties && typeof (target as any).properties === 'object')\n ? ((target as any).properties as Record<string, unknown>)\n : undefined\n\n for (const existingKey of Object.keys(attrs)) {\n if (\n !next\n || !hasOwn(next, existingKey)\n || isInternalAttrKey(existingKey)\n || declaredPropKeys.has(existingKey)\n || hasRuntimeStateKey(existingKey)\n ) {\n delete attrs[existingKey]\n }\n }\n\n if (!next) {\n return\n }\n\n for (const [key, value] of Object.entries(next)) {\n if (isInternalAttrKey(key) || declaredPropKeys.has(key) || hasRuntimeStateKey(key)) {\n continue\n }\n attrs[key] = value\n }\n }\n syncAttrsFromProperties()\n\n try {\n Object.defineProperty(target, WEVU_ATTRS_KEY, {\n value: attrs,\n configurable: true,\n enumerable: false,\n writable: false,\n })\n }\n catch {\n ;(target as any)[WEVU_ATTRS_KEY] = attrs\n }\n\n const setupInstance = ensureSetupContextInstance(target, runtimeWithDefaults)\n const updateExposedView = attachVueCompatInstanceView(target, setupInstance as Record<string, any>)\n const slots = attachRuntimeSlots(runtimeState, props)\n const setupState = runtimeWithDefaults.setupState ?? Object.create(null)\n attachRuntimeSetupState(runtimeState, setupState)\n\n const context = safeMarkNoSetData({\n // 与 Vue 3 对齐的 ctx.props\n props,\n\n // 现有运行时能力\n runtime: runtimeWithDefaults,\n state: runtimeState,\n proxy: runtimeProxy,\n bindModel: runtime.bindModel.bind(runtimeWithDefaults),\n watch: runtime.watch.bind(runtimeWithDefaults),\n instance: setupInstance,\n\n // 通过小程序 triggerEvent 派发事件,并兼容 Vue 3 的 emit(event, ...args) 形式。\n emit: (event: string, ...args: any[]) => {\n const { detail, options } = normalizeEmitPayload(args)\n const eventName = normalizeEmitEventName(event)\n setupInstance.triggerEvent(eventName, detail, options)\n },\n\n // 与 Vue 3 对齐的 expose\n expose: (exposed: Record<string, any>) => {\n target[WEVU_EXPOSED_KEY] = exposed\n updateExposedView(exposed)\n },\n\n // 与 Vue 3 对齐的 attrs(小程序中为非 props 属性集合)\n attrs,\n\n // 与 Vue 3 对齐的 slots(由编译期传入的 slot 名元数据驱动)\n slots,\n }) as any\n\n // 仅在同步 setup 执行期间暴露 current instance\n const instanceScope = effectScope(true)\n const previousInstance = getCurrentInstance()\n const previousSetupContext = getCurrentSetupContext()\n const restoreSetupContext = () => {\n // 仅当全局上下文仍属于本次 setup 时恢复父级;嵌套或重入 setup\n // 可能已经建立了新的上下文,不能被旧调用覆盖。\n if (getCurrentInstance() !== target || getCurrentSetupContext() !== context) {\n return\n }\n setCurrentSetupContext(previousSetupContext)\n setCurrentInstance(previousInstance)\n }\n target[WEVU_EFFECT_SCOPE_KEY] = instanceScope\n setCurrentInstance(target)\n setCurrentSetupContext(context)\n try {\n const result = instanceScope.run(() => runSetupFunction(setup, props, context))\n if (result && typeof result === 'object') {\n applySetupResult(runtimeWithDefaults, target, result)\n }\n }\n finally {\n // current instance/context 只属于本次同步 setup 调用;异步 continuation\n // 不能继续占用全局上下文,否则会污染随后挂载的组件。\n restoreSetupContext()\n }\n}\n"],"mappings":";;;;;;;;;;;;AAoCA,IAAI,uBAAuB;AAE3B,SAAS,4BAA4B,QAA8B,OAA4B;CAE7F,IAAI;CACJ,MAAM,WAAW;CACjB,MAAM,cAAqC;EACzC,OAAO;GACL,cAAc;GACd,YAAY;GACZ,OAAO;GACP,UAAU;EACZ;EACA,GAAG;GACD,cAAc;GACd,YAAY;GACZ,OAAO;GACP,UAAU;EACZ;EACA,KAAK;GACH,cAAc;GACd,YAAY;GACZ,OAAO,EAAE;GACT,UAAU;EACZ;EACA,SAAS;GACP,cAAc;GACd,YAAY;GACZ,WAAW;EACb;CACF;CACA,KAAK,MAAM,CAAC,KAAK,eAAe,OAAO,QAAQ,WAAW,GACxD,IAAI;EACF,OAAO,eAAe,UAAU,KAAK,UAAU;CACjD,QACM;EACJ,IAAI,WAAW,YACb,SAAS,OAAO,WAAW;CAE/B;CAEF,MAAM,oBAA2C;EAC/C,GAA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ACF"}
@@ -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":";;;;;;AA8BA,SAAgB,wBAAwB,OAA4B,OAA4B;CAC9F,IAAI;EACF,OAAO,eAAe,OAAO,gBAAgB;GAC3C,OAAO;GACP,cAAc;GACd,YAAY;GACZ,UAAU;EACZ,CAAC;CACH,QACM;EACH,AAAC,MAAc,kBAAkB;CACpC;AACF;A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../../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":";;;;;;AA8BA,SAAgB,wBAAwB,OAA4B,OAA4B;CAC9F,IAAI;EACF,OAAO,eAAe,OAAO,gBAAgB;GAC3C,OAAO;GACP,cAAc;GACd,YAAY;GACZ,UAAU;EACZ,CAAC;CACH,QACM;EACH,AAAC,MAAc,kBAAkB;CACpC;AACF;AAEA,SAAgB,wBAAwB,OAA4B,YAAiC;CACnG,IAAI;EACF,OAAO,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AAO,WACH,QAAQ,KAAK,UAAU,SAAS,QAAQ,IACxC,QAAQ,KAAK,UAAU,OAAO;CACpC,SACO,OAAO;EACZ,MAAM,QAAQ,qBAAqB,QAAQ;EAC3C,MAAM,IAAI,MAAM,0BAA0B,MAAM,KAAK,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,GAAG;CAC/G;AACF;AAEA,SAAgB,iBACd,OACA,cACA,kBACA;CACA,MAAM,qBAAqB,mBAAmB,IAAI,IAAI,gBAAgB,IAAI;CAC1E,MAAM,cAAc,OAAO,KAAK,KAAK;CACrC,KAAK,MAAM,OAAO,aAChB,IAAI,CAAC,OAAO,cAAc,GAAG,KAAM,sBAAsB,CAAC,mBAAmB,IAAI,GAAG,GAClF,IAAI;EACF,OAAO,MAAM;CACf,QACM,CAEN;CAGJ,MAAM,WAAW,oBAAoB,OAAO,KAAK,YAAY;CAC7D,KAAK,MAAM,OAAO,UAChB,IAAI,OAAO,cAAc,GAAG,GAC1B,MAAM,OAAO,aAAa;AAGhC;AAEA,SAAgB,mBACd,QACA,cACA,eAAsC,OAAe,cAAc,CAAC,GACpE;CACA,MAAM,eAAe,gBAAgB,OAAO,iBAAiB,WACvD,aAAqB,kBACvB;CACJ,MAAM,QAAQ,gBAAgB,OAAO,iBAAiB,WAClD,eACA,gBAAgB,CAAC,CAAC;CAKtB,iBAAiB,OAAO,cAHC,MAAM,QAAS,OAAe,mBAAmB,IACpE,OAAe,sBACjB,MACkD;CACtD,IAAI,gBAAgB,OAAO,iBAAiB,UAC1C,wBAAwB,cAAc,KAAK;CAE7C,IAAI;EACF,OAAO,eAAe,QAAQ,gBAAgB;GAC5C,OAAO;GACP,cAAc;GACd,YAAY;GACZ,UAAU;EACZ,CAAC;CACH,QACM;EACH,AAAC,OAAe,kBAAkB;CACrC;CAEA,OAAO;AACT"}
@@ -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_NATIVE_SLOT_CONTEXT_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;
@@ -467,32 +497,25 @@ function mountRuntimeInstance(target, runtimeApp, watchMap, setup, options) {
467
497
  attachRuntimeSlots(runtimeState, runtimeProps);
468
498
  if (scopedSlotState) scopedSlotHooks?.attachMount(target, runtimeWithDefaults, scopedSlotState, Boolean(options?.deferSetData));
469
499
  syncNativeOwnerId();
470
- const watchStops = watchMap ? registerWatches(runtimeWithDefaults, watchMap, target, { deferMissingSourceBaseline: Boolean(setup) }) : [];
500
+ if (setup) runRuntimeSetupPhase({
501
+ target,
502
+ runtime,
503
+ runtimeWithDefaults,
504
+ runtimeState,
505
+ runtimeProxy,
506
+ setup
507
+ });
508
+ const watchStops = watchMap ? registerWatches(runtimeWithDefaults, watchMap, target) : [];
471
509
  if (watchStops.length) target[WEVU_WATCH_STOPS_KEY] = watchStops;
472
- if (setup) try {
473
- runRuntimeSetupPhase({
474
- target,
475
- runtime,
476
- runtimeWithDefaults,
477
- runtimeState,
478
- runtimeProxy,
479
- setup
480
- });
481
- if (typeof getMiniProgramRuntimeGlobalObject()?.[WEAPP_VITE_STATEFUL_HMR_BRIDGE_KEY]?.trackWevuComponent === "function") {
510
+ if (setup) {
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);
485
515
  }
486
516
  if (!options?.deferSetData) runtimeWithSyncFlush.__wevu_flushSetupSnapshotSync?.();
487
517
  if (!options?.deferSetData) refreshOwnerSnapshot();
488
- 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) {
518
+ } else if (!options?.deferSetData && target.properties && typeof target.properties === "object" && Object.keys(target.properties).length > 0) {
496
519
  runtimeWithSyncFlush.__wevu_flushSetupSnapshotSync?.();
497
520
  refreshOwnerSnapshot();
498
521
  }
@@ -598,6 +621,7 @@ function teardownRuntimeInstance(target, options) {
598
621
  }
599
622
  }
600
623
  },
624
+ ...(!import.meta.env?.PLATFORM || import.meta.env?.PLATFORM === "weapp") && target[WEVU_NATIVE_SLOT_CONTEXT_KEY] === true ? [() => releaseNativeDeclaration(target, options?.preserveNativeDeclarationChildren)] : [],
601
625
  () => runtimeCapabilityRegistry.scopedSlots?.teardown(target),
602
626
  () => {
603
627
  if (Array.isArray(target.__wevuTemplateRefs) && target.__wevuTemplateRefs.length > 0) requireRuntimeCapability("templateRefs", "teardownRuntimeInstance(template refs)").clear(target);
@@ -635,6 +659,15 @@ function teardownRuntimeInstance(target, options) {
635
659
  },
636
660
  () => {
637
661
  if (WEVU_PUBLIC_RUNTIME_KEY in target) delete target[WEVU_PUBLIC_RUNTIME_KEY];
662
+ },
663
+ () => {
664
+ delete target[WEVU_PARENT_INSTANCE_KEY];
665
+ },
666
+ () => {
667
+ delete target[WEVU_PROVIDES_KEY];
668
+ },
669
+ () => {
670
+ delete target[WEVU_RUNTIME_APP_KEY];
638
671
  }
639
672
  ]);
640
673
  }
@@ -646,10 +679,17 @@ function refreshRuntimeInstance(target, runtimeApp, watchMap, setup, options) {
646
679
  const previousRuntime = target.__wevu;
647
680
  const initialSetupState = previousRuntime ? initialReactiveSetupSnapshots.get(previousRuntime) : void 0;
648
681
  const previousRuntimeState = previousRuntime ? createRuntimeStateSnapshot(previousRuntime, target.data, options?.stateSnapshot) : void 0;
649
- teardownRuntimeInstance(target, { skipHooks: true });
682
+ const parent = target[WEVU_PARENT_INSTANCE_KEY];
683
+ const layoutParent = parent && isRuntimeLayoutComponentTarget(parent) ? parent : void 0;
684
+ teardownRuntimeInstance(target, {
685
+ skipHooks: true,
686
+ preserveNativeDeclarationChildren: true
687
+ });
650
688
  const nextRuntime = mountRuntimeInstance(target, runtimeApp, watchMap, setup, {
651
689
  deferSetData: true,
652
- snapshotOmitKeys: options?.snapshotOmitKeys
690
+ snapshotOmitKeys: options?.snapshotOmitKeys,
691
+ attached: options?.attached,
692
+ layoutParent
653
693
  });
654
694
  const stateSnapshot = previousRuntimeState ?? (options?.stateSnapshot ? createRuntimeStateSnapshot(nextRuntime, options.stateSnapshot, options.stateSnapshot) : void 0);
655
695
  if (stateSnapshot) {