wevu 6.10.1 → 6.11.1

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.
package/README.md CHANGED
@@ -144,7 +144,7 @@ const onActiveChange = bindModel.model<boolean>('isActive').onChange
144
144
 
145
145
  - 更新被批量加入微任务队列,`nextTick` 与 Vue 3 行为一致。
146
146
  - 对状态做快照 diff,只把变更路径传给 `setData`,避免大对象全量下发。
147
- - 提供 `batch`/`startBatch`/`endBatch` 用于同步更新合并触发;以及 `effectScope`/`onScopeDispose` 统一管理 effect/watch 的销毁,便于避免泄漏。
147
+ - 提供 `batch`/`startBatch`/`endBatch` 用于同步更新合并触发;以及 `effectScope`/`getCurrentScope`/`onScopeDispose` 统一管理 effect/watch 的销毁,`setup()` 同步阶段内创建的副作用会自动归属到实例级 scope,便于避免泄漏。
148
148
 
149
149
  ## 本地开发
150
150
 
package/dist/index.d.mts CHANGED
@@ -143,6 +143,14 @@ declare function isRaw(value: unknown): boolean;
143
143
  */
144
144
  declare function readonly<T extends object>(target: T): T;
145
145
  declare function readonly<T>(target: Ref<T>): Readonly<Ref<T>>;
146
+ /**
147
+ * 与 Vue 3 的 `shallowReadonly()` 对齐。
148
+ *
149
+ * 当前 wevu 的只读语义本身就是浅层只读,因此这里直接复用同一套实现,
150
+ * 让依赖 Vue 兼容 API 的代码可以无缝迁移。
151
+ */
152
+ declare function shallowReadonly<T extends object>(target: T): Readonly<T>;
153
+ declare function shallowReadonly<T>(target: Ref<T>): Readonly<Ref<T>>;
146
154
  //#endregion
147
155
  //#region src/reactivity/shallowRef.d.ts
148
156
  declare function shallowRef<T>(value: T): Ref<T>;
@@ -387,11 +395,13 @@ interface RuntimeInstance<D extends object, C extends ComputedDefinitions, M ext
387
395
  }
388
396
  interface InternalRuntimeStateFields {
389
397
  __wevu?: RuntimeInstance<any, any, any>;
398
+ __wevuSetPageLayout?: (layout: string | false, props?: Record<string, any>) => void;
390
399
  __wevuWatchStops?: WatchStopHandle[];
391
400
  $wevu?: RuntimeInstance<any, any, any>;
392
401
  __wevuHooks?: Record<string, any>;
393
402
  __wevuExposed?: Record<string, any>;
394
403
  __wevuAttrs?: Record<string, any>;
404
+ __wevuEffectScope?: EffectScope;
395
405
  __wevuPropKeys?: string[];
396
406
  __wevuTemplateRefs?: unknown[];
397
407
  __wevuTemplateRefMap?: Map<string, Ref<any>>;
@@ -662,6 +672,7 @@ interface SetDataDebugInfo {
662
672
  }
663
673
  //#endregion
664
674
  //#region src/runtime/types/options.d.ts
675
+ type DataOption<D extends object> = D | (() => D);
665
676
  interface DefineComponentOptions<P extends ComponentPropsOptions = ComponentPropsOptions, D extends object = Record<string, any>, C extends ComputedDefinitions = ComputedDefinitions, M extends MethodDefinitions = MethodDefinitions, S extends Record<string, any> | void = Record<string, any> | void> extends MiniProgramComponentOptions, MiniProgramPageLifetimes {
666
677
  /**
667
678
  * 页面特性开关(用于按需注入 Page 事件处理函数)。
@@ -691,7 +702,7 @@ interface DefineComponentOptions<P extends ComponentPropsOptions = ComponentProp
691
702
  /**
692
703
  * 组件 data(建议使用函数返回初始值)。
693
704
  */
694
- data?: () => D;
705
+ data?: DataOption<D>;
695
706
  /**
696
707
  * 组件 computed(会参与快照 diff)。
697
708
  */
@@ -717,7 +728,7 @@ interface DefineAppOptions<D extends object = Record<string, any>, C extends Com
717
728
  [key: string]: any;
718
729
  }
719
730
  interface CreateAppOptions<D extends object = Record<string, any>, C extends ComputedDefinitions = ComputedDefinitions, M extends MethodDefinitions = MethodDefinitions> extends MiniProgramAppOptions {
720
- data?: () => D;
731
+ data?: DataOption<D>;
721
732
  computed?: C;
722
733
  methods?: M;
723
734
  setData?: SetDataSnapshotOptions;
@@ -1064,6 +1075,31 @@ declare function useIntersectionObserver(options?: UseIntersectionObserverOption
1064
1075
  declare function markNoSetData<T extends object>(value: T): T;
1065
1076
  declare function isNoSetData(value: unknown): boolean;
1066
1077
  //#endregion
1078
+ //#region src/runtime/pageLayout.d.ts
1079
+ interface WevuPageLayoutMap {}
1080
+ type ResolveTypedPageLayoutName = keyof WevuPageLayoutMap extends never ? string : Extract<keyof WevuPageLayoutMap, string>;
1081
+ type ResolveTypedPageLayoutProps<Name extends string> = Name extends keyof WevuPageLayoutMap ? WevuPageLayoutMap[Name] : Record<string, any>;
1082
+ type PageLayoutNamedState = { [Name in ResolveTypedPageLayoutName]: {
1083
+ name: Name;
1084
+ props: ResolveTypedPageLayoutProps<Name>;
1085
+ } }[ResolveTypedPageLayoutName];
1086
+ type PageLayoutState = PageLayoutNamedState | {
1087
+ name: false;
1088
+ props: Record<string, any>;
1089
+ } | {
1090
+ name: undefined;
1091
+ props: Record<string, any>;
1092
+ };
1093
+ /**
1094
+ * 获取当前页面 layout 状态。
1095
+ */
1096
+ declare function usePageLayout(): Readonly<PageLayoutState>;
1097
+ declare function syncRuntimePageLayoutState(target: Record<string, any>, layout: string | false, props: Record<string, any>): void;
1098
+ declare function syncRuntimePageLayoutStateFromRuntime(target: Record<string, any>): void;
1099
+ declare function setPageLayout(layout: false): void;
1100
+ declare function setPageLayout<Name extends ResolveTypedPageLayoutName>(layout: Name, props?: ResolveTypedPageLayoutProps<Name>): void;
1101
+ declare function resolveRuntimePageLayoutName(layout: string | false): string;
1102
+ //#endregion
1067
1103
  //#region src/runtime/pageScroll.d.ts
1068
1104
  interface UsePageScrollThrottleOptions {
1069
1105
  /**
@@ -1091,6 +1127,13 @@ type UsePageScrollThrottleStopHandle = () => void;
1091
1127
  declare function usePageScrollThrottle(handler: (opt: WechatMiniprogram.Page.IPageScrollOption) => void, options?: UsePageScrollThrottleOptions): UsePageScrollThrottleStopHandle;
1092
1128
  //#endregion
1093
1129
  //#region src/runtime/provide.d.ts
1130
+ /**
1131
+ * 判断当前是否存在可用的注入上下文。
1132
+ *
1133
+ * wevu 目前的依赖注入上下文来自同步 `setup()` 阶段的当前实例;
1134
+ * 若未来补充 app 级 provider,这里可继续扩展判断来源。
1135
+ */
1136
+ declare function hasInjectionContext(): boolean;
1094
1137
  /**
1095
1138
  * 在组件上下文中向后代注入值(与 Vue 3 行为兼容),若没有当前实例则回落到全局存储。
1096
1139
  *
@@ -1341,6 +1384,18 @@ declare function defineOptions<D extends object = Record<string, any>, C extends
1341
1384
  * defineSlots 声明 slots 类型(仅类型层)。
1342
1385
  */
1343
1386
  declare function defineSlots<T extends Record<string, any> = Record<string, any>>(): T;
1387
+ type PageLayoutMeta = string | false | {
1388
+ name: string;
1389
+ props?: Record<string, unknown>;
1390
+ };
1391
+ interface PageMeta {
1392
+ layout?: PageLayoutMeta;
1393
+ [key: string]: unknown;
1394
+ }
1395
+ /**
1396
+ * definePageMeta 声明页面级元信息(仅类型层)。
1397
+ */
1398
+ declare function definePageMeta(meta: PageMeta): void;
1344
1399
  /**
1345
1400
  * defineModel 声明 v-model 绑定(类型层宏)。
1346
1401
  */
@@ -1361,4 +1416,4 @@ declare function defineModel<T = any, M extends PropertyKey = string, G = T, S =
1361
1416
  declare function defineModel<T = any, M extends PropertyKey = string, G = T, S = T>(options?: DefineModelBaseOptions<T | undefined, M, G | undefined, S | undefined>): ModelRef<T | undefined, M, G | undefined, S | undefined>;
1362
1417
  declare function defineModel<T = any, M extends PropertyKey = string, G = T, S = T>(name?: string, options?: DefineModelBaseOptions<T | undefined, M, G | undefined, S | undefined>): ModelRef<T | undefined, M, G | undefined, S | undefined>;
1363
1418
  //#endregion
1364
- export { ActionContext, ActionSubscriber, type AllowedComponentProps, type AppConfig, type ComponentCustomProps, ComponentDefinition, type ComponentOptionsMixin, type ComponentPropsOptions, type ComponentPublicInstance, type ComponentTypeEmits, type ComputedDefinitions, ComputedGetter, ComputedRef, ComputedSetter, type CreateAppOptions, CustomRefFactory, CustomRefOptions, CustomRefSource, type DefineAppOptions, type DefineComponent, type DefineComponentOptions, DefineModelModifiers, DefineModelTransformOptions, DefineStoreOptions, DisposableBag, DisposableLike, DisposableMethodName, DisposableObject, EffectScope, type EmitFn, type EmitsOptions, type ExtractComputed, type ExtractDefaultPropTypes, type ExtractMethods, type ExtractPropTypes, type ExtractPublicPropTypes, GlobalComponents, GlobalDirectives, type InferNativePropType, type InferNativeProps, type InferPropType, type InferProps, type InternalRuntimeState, type InternalRuntimeStateFields, type MapSources, MaybeRef, MaybeRefOrGetter, type MaybeUndefined, type MethodDefinitions, type MiniProgramAdapter, type MiniProgramAppOptions, type MiniProgramBehaviorIdentifier, type MiniProgramComponentBehaviorOptions, type MiniProgramComponentOptions, type MiniProgramComponentRawOptions, type MiniProgramInstance, type MiniProgramPageLifetimes, type ModelBinding, type ModelBindingOptions, type ModelBindingPayload, ModelModifiers, ModelRef, type MultiWatchSources, type MutationKind, type MutationOp, type MutationRecord, MutationType, type NativeComponent, type NativePropType, type NativePropsOptions, type NativeTypeHint, type NativeTypedProperty, type ObjectDirective, type OnCleanup, type PageFeatures, type PrelinkReactiveTreeOptions, type PropConstructor, type PropOptions, type PropType, type PublicProps, Ref, type RuntimeApp, type RuntimeInstance, type SetDataDebugInfo, type SetDataSnapshotOptions, type SetupContext, type SetupContextNativeInstance, type SetupContextRouter, type SetupFunction, ShallowRef, type ShallowUnwrapRef, StoreManager, StoreSubscribeOptions, StoreToRefsResult, SubscriptionCallback, TemplateRef, TemplateRefValue, TemplateRefs, ToRefs, type TriggerEventOptions, UpdatePerformanceListener, UpdatePerformanceListenerResult, UseIntersectionObserverOptions, UseIntersectionObserverResult, UseModelOptions, UsePageScrollThrottleOptions, UsePageScrollThrottleStopHandle, UseUpdatePerformanceListenerStopHandle, type VNode, type VNodeProps, type WatchCallback, type WatchEffect, type WatchEffectOptions, type WatchMultiSources, type WatchOptions, type WatchScheduler, type WatchSource, type WatchSourceValue, type WatchSources, type WatchStopHandle, WevuComponentConstructor, WevuDefaults, WevuGlobalComponents, WevuGlobalDirectives, type WevuPlugin, type WevuTypedRouterRouteMap, WritableComputedOptions, WritableComputedRef, addMutationRecorder, batch, callHookList, callHookReturn, callUpdateHooks, computed, createApp, createStore, createWevuComponent, createWevuScopedSlotComponent, customRef, defineComponent, defineEmits, defineExpose, defineModel, defineOptions, defineProps, defineSlots, defineStore, effect, effectScope, endBatch, getCurrentInstance, getCurrentScope, getCurrentSetupContext, getDeepWatchStrategy, getReactiveVersion, inject, injectGlobal, isNoSetData, isRaw, isReactive, isRef, isShallowReactive, isShallowRef, markNoSetData, markRaw, mergeModels, mountRuntimeInstance, nextTick, normalizeClass, normalizeStyle, onActivated, onAddToFavorites, onAttached, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onDetached, onError, onErrorCaptured, onHide, onLaunch, onLoad, onMemoryWarning, onMounted, onMoved, onPageNotFound, onPageScroll, onPullDownRefresh, onReachBottom, onReady, onResize, onRouteDone, onSaveExitState, onScopeDispose, onServerPrefetch, onShareAppMessage, onShareTimeline, onShow, onTabItemTap, onThemeChange, onUnhandledRejection, onUnload, onUnmounted, onUpdated, prelinkReactiveTree, provide, provideGlobal, reactive, readonly, ref, registerApp, registerComponent, removeMutationRecorder, resetWevuDefaults, runSetupFunction, setCurrentInstance, setCurrentSetupContext, setDeepWatchStrategy, setRuntimeSetDataVisibility, setWevuDefaults, shallowReactive, shallowRef, startBatch, stop, storeToRefs, teardownRuntimeInstance, toRaw, toRef, toRefs, toValue, touchReactive, traverse, triggerRef, unref, useAttrs, useBindModel, useDisposables, useIntersectionObserver, useModel, useNativeInstance, useNativePageRouter, useNativeRouter, usePageScrollThrottle, useSlots, useTemplateRef, useUpdatePerformanceListener, watch, watchEffect, withDefaults };
1419
+ export { ActionContext, ActionSubscriber, type AllowedComponentProps, type AppConfig, type ComponentCustomProps, ComponentDefinition, type ComponentOptionsMixin, type ComponentPropsOptions, type ComponentPublicInstance, type ComponentTypeEmits, type ComputedDefinitions, ComputedGetter, ComputedRef, ComputedSetter, type CreateAppOptions, CustomRefFactory, CustomRefOptions, CustomRefSource, type DataOption, type DefineAppOptions, type DefineComponent, type DefineComponentOptions, DefineComponentTypePropsOptions, DefineComponentWithTypeProps, DefineModelModifiers, DefineModelTransformOptions, DefineStoreOptions, DisposableBag, DisposableLike, DisposableMethodName, DisposableObject, EffectScope, type EmitFn, type EmitsOptions, type ExtractComputed, type ExtractDefaultPropTypes, type ExtractMethods, type ExtractPropTypes, type ExtractPublicPropTypes, GlobalComponents, GlobalDirectives, type InferNativePropType, type InferNativeProps, type InferPropType, type InferProps, type InternalRuntimeState, type InternalRuntimeStateFields, type MapSources, MaybeRef, MaybeRefOrGetter, type MaybeUndefined, type MethodDefinitions, type MiniProgramAdapter, type MiniProgramAppOptions, type MiniProgramBehaviorIdentifier, type MiniProgramComponentBehaviorOptions, type MiniProgramComponentOptions, type MiniProgramComponentRawOptions, type MiniProgramInstance, type MiniProgramPageLifetimes, type ModelBinding, type ModelBindingOptions, type ModelBindingPayload, ModelModifiers, ModelRef, type MultiWatchSources, type MutationKind, type MutationOp, type MutationRecord, MutationType, type NativeComponent, type NativePropType, type NativePropsOptions, type NativeTypeHint, type NativeTypedProperty, type ObjectDirective, type OnCleanup, type PageFeatures, PageLayoutMeta, PageLayoutState, PageMeta, type PrelinkReactiveTreeOptions, type PropConstructor, type PropOptions, type PropType, type PublicProps, Ref, type RuntimeApp, type RuntimeInstance, type SetDataDebugInfo, type SetDataSnapshotOptions, type SetupContext, type SetupContextNativeInstance, type SetupContextRouter, SetupContextWithTypeProps, type SetupFunction, SetupFunctionWithTypeProps, ShallowRef, type ShallowUnwrapRef, StoreManager, StoreSubscribeOptions, StoreToRefsResult, SubscriptionCallback, TemplateRef, TemplateRefValue, TemplateRefs, ToRefs, type TriggerEventOptions, UpdatePerformanceListener, UpdatePerformanceListenerResult, UseIntersectionObserverOptions, UseIntersectionObserverResult, UseModelOptions, UsePageScrollThrottleOptions, UsePageScrollThrottleStopHandle, UseUpdatePerformanceListenerStopHandle, type VNode, type VNodeProps, type WatchCallback, type WatchEffect, type WatchEffectOptions, type WatchMultiSources, type WatchOptions, type WatchScheduler, type WatchSource, type WatchSourceValue, type WatchSources, type WatchStopHandle, WevuComponentConstructor, WevuDefaults, WevuGlobalComponents, WevuGlobalDirectives, WevuPageLayoutMap, type WevuPlugin, type WevuTypedRouterRouteMap, WritableComputedOptions, WritableComputedRef, addMutationRecorder, batch, callHookList, callHookReturn, callUpdateHooks, computed, createApp, createStore, createWevuComponent, createWevuScopedSlotComponent, customRef, defineComponent, defineEmits, defineExpose, defineModel, defineOptions, definePageMeta, defineProps, defineSlots, defineStore, effect, effectScope, endBatch, getCurrentInstance, getCurrentScope, getCurrentSetupContext, getDeepWatchStrategy, getReactiveVersion, hasInjectionContext, inject, injectGlobal, isNoSetData, isRaw, isReactive, isRef, isShallowReactive, isShallowRef, markNoSetData, markRaw, mergeModels, mountRuntimeInstance, nextTick, normalizeClass, normalizeStyle, onActivated, onAddToFavorites, onAttached, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onDetached, onError, onErrorCaptured, onHide, onLaunch, onLoad, onMemoryWarning, onMounted, onMoved, onPageNotFound, onPageScroll, onPullDownRefresh, onReachBottom, onReady, onResize, onRouteDone, onSaveExitState, onScopeDispose, onServerPrefetch, onShareAppMessage, onShareTimeline, onShow, onTabItemTap, onThemeChange, onUnhandledRejection, onUnload, onUnmounted, onUpdated, prelinkReactiveTree, provide, provideGlobal, reactive, readonly, ref, registerApp, registerComponent, removeMutationRecorder, resetWevuDefaults, resolveRuntimePageLayoutName, runSetupFunction, setCurrentInstance, setCurrentSetupContext, setDeepWatchStrategy, setPageLayout, setRuntimeSetDataVisibility, setWevuDefaults, shallowReactive, shallowReadonly, shallowRef, startBatch, stop, storeToRefs, syncRuntimePageLayoutState, syncRuntimePageLayoutStateFromRuntime, teardownRuntimeInstance, toRaw, toRef, toRefs, toValue, touchReactive, traverse, triggerRef, unref, useAttrs, useBindModel, useDisposables, useIntersectionObserver, useModel, useNativeInstance, useNativePageRouter, useNativeRouter, usePageLayout, usePageScrollThrottle, useSlots, useTemplateRef, useUpdatePerformanceListener, watch, watchEffect, withDefaults };
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { A as track, C as effect, D as onScopeDispose, E as getCurrentScope, M as triggerEffects, N as nextTick, O as startBatch, P as queueJob, S as batch, T as endBatch, _ as ReactiveFlags, a as toValue, b as addMutationRecorder, c as isRaw, d as reactive, f as isShallowReactive, g as touchReactive, h as prelinkReactiveTree, i as ref, j as trigger, k as stop, l as isReactive, m as clearPatchIndices, n as isRef, o as unref, p as shallowReactive, r as markAsRef, s as getReactiveVersion, t as customRef, u as markRaw, v as isObject$1, w as effectScope, x as removeMutationRecorder, y as toRaw } from "./ref-BjmD-qct.mjs";
2
2
  import { i as computed, n as defineStore, r as createStore, t as storeToRefs } from "./store-Ct-o7qtH.mjs";
3
- import { A as onUnload, B as getScopedSlotHostGlobalObject, C as onSaveExitState, D as onTabItemTap, E as onShow, F as getCurrentSetupContext, I as pushHook, L as setCurrentInstance, M as callHookList, N as callHookReturn, O as onThemeChange, P as getCurrentInstance, R as setCurrentSetupContext, S as onRouteDone, T as onShareTimeline, V as readonly, _ as onPageScroll, a as provide, b as onReady, c as onAttached, d as onHide, f as onLaunch, g as onPageNotFound, h as onMoved, i as injectGlobal, j as assertInSetup, k as onUnhandledRejection, l as onDetached, m as onMemoryWarning, n as useNativeRouter, o as provideGlobal, p as onLoad, r as inject, s as onAddToFavorites, t as useNativePageRouter, u as onError, v as onPullDownRefresh, w as onShareAppMessage, x as onResize, y as onReachBottom, z as getMiniProgramGlobalObject } from "./router-BoEmd9rt.mjs";
3
+ import { A as onUnhandledRejection, B as getMiniProgramGlobalObject, C as onRouteDone, D as onShow, E as onShareTimeline, F as getCurrentInstance, H as readonly, I as getCurrentSetupContext, L as pushHook, M as assertInSetup, N as callHookList, O as onTabItemTap, P as callHookReturn, R as setCurrentInstance, S as onResize, T as onShareAppMessage, U as shallowReadonly, V as getScopedSlotHostGlobalObject, _ as onPageNotFound, a as injectGlobal, b as onReachBottom, c as onAddToFavorites, d as onError, f as onHide, g as onMoved, h as onMemoryWarning, i as inject, j as onUnload, k as onThemeChange, l as onAttached, m as onLoad, n as useNativeRouter, o as provide, p as onLaunch, r as hasInjectionContext, s as provideGlobal, t as useNativePageRouter, u as onDetached, v as onPageScroll, w as onSaveExitState, x as onReady, y as onPullDownRefresh, z as setCurrentSetupContext } from "./router-PqZEeqhd.mjs";
4
4
  //#region src/reactivity/shallowRef.ts
5
5
  /**
6
6
  * 创建一个“浅层” ref:它只在 .value 被整体替换时触发依赖,不会对内部对象做深层响应式处理。
@@ -860,7 +860,7 @@ function diffSnapshots(prev, next) {
860
860
  function collapsePayload(input) {
861
861
  const keys = Object.keys(input).sort();
862
862
  if (keys.length <= 1) return input;
863
- const out = Object.create(null);
863
+ const out = {};
864
864
  const prefixStack = [];
865
865
  for (const key of keys) {
866
866
  while (prefixStack.length) {
@@ -971,7 +971,7 @@ function mergeSiblingPayload(options) {
971
971
  out: input,
972
972
  merged: 0
973
973
  };
974
- const out = Object.create(null);
974
+ const out = {};
975
975
  Object.assign(out, input);
976
976
  let merged = 0;
977
977
  const valueSizeCache = /* @__PURE__ */ new WeakMap();
@@ -1019,7 +1019,7 @@ function normalizeSetDataValue(value) {
1019
1019
  function cloneSnapshotValue(value) {
1020
1020
  if (Array.isArray(value)) return value.map((item) => cloneSnapshotValue(item));
1021
1021
  if (!isPlainObjectLike(value)) return value;
1022
- const out = Object.create(null);
1022
+ const out = {};
1023
1023
  for (const key of Object.keys(value)) out[key] = cloneSnapshotValue(value[key]);
1024
1024
  return out;
1025
1025
  }
@@ -1071,7 +1071,7 @@ function applySnapshotUpdate(snapshot, path, value, op) {
1071
1071
  let current = snapshot;
1072
1072
  for (let i = 0; i < segments.length - 1; i++) {
1073
1073
  const key = segments[i];
1074
- if (!Object.hasOwn(current, key) || current[key] == null || typeof current[key] !== "object") current[key] = Object.create(null);
1074
+ if (!Object.hasOwn(current, key) || current[key] == null || typeof current[key] !== "object") current[key] = {};
1075
1075
  current = current[key];
1076
1076
  }
1077
1077
  const leaf = segments.at(-1);
@@ -1085,7 +1085,7 @@ function applySnapshotUpdate(snapshot, path, value, op) {
1085
1085
  function collectSnapshot(options) {
1086
1086
  const { state, computedRefs, includeComputed, shouldIncludeKey, plainCache, toPlainMaxDepth, toPlainMaxKeys } = options;
1087
1087
  const seen = /* @__PURE__ */ new WeakMap();
1088
- const out = Object.create(null);
1088
+ const out = {};
1089
1089
  const budget = Number.isFinite(toPlainMaxKeys) ? { keys: toPlainMaxKeys } : void 0;
1090
1090
  const rawState = isReactive(state) ? toRaw(state) : state;
1091
1091
  const stateKeys = Object.keys(rawState);
@@ -1459,10 +1459,14 @@ function createWatchStopHandle(cleanup, baseHandle) {
1459
1459
  };
1460
1460
  return stopHandle;
1461
1461
  }
1462
+ function resolveDataOption(data) {
1463
+ if (typeof data === "function") return data();
1464
+ return data !== null && data !== void 0 ? data : {};
1465
+ }
1462
1466
  function createRuntimeMount(options) {
1463
1467
  const { data, resolvedComputed, resolvedMethods, appConfig, setDataOptions } = options;
1464
1468
  return (adapter) => {
1465
- const rawState = (data !== null && data !== void 0 ? data : (() => ({})))();
1469
+ const rawState = resolveDataOption(data);
1466
1470
  if (rawState && typeof rawState === "object" && !Object.hasOwn(rawState, "__wevuProps")) try {
1467
1471
  Object.defineProperty(rawState, "__wevuProps", {
1468
1472
  value: shallowReactive(Object.create(null)),
@@ -2558,10 +2562,12 @@ function runRuntimeSetupPhase(options) {
2558
2562
  attrs,
2559
2563
  slots: createSetupSlotsFallback()
2560
2564
  });
2565
+ const instanceScope = effectScope(true);
2566
+ target.__wevuEffectScope = instanceScope;
2561
2567
  setCurrentInstance(target);
2562
2568
  setCurrentSetupContext(context);
2563
2569
  try {
2564
- const result = runSetupFunction(setup, props, context);
2570
+ const result = instanceScope.run(() => runSetupFunction(setup, props, context));
2565
2571
  let methodsChanged = false;
2566
2572
  if (result && typeof result === "object") {
2567
2573
  const runtimeRawState = isReactive(runtime.state) ? toRaw(runtime.state) : runtime.state;
@@ -2604,6 +2610,10 @@ function runRuntimeSetupPhase(options) {
2604
2610
  var _wevu_touchSetupMetho;
2605
2611
  (_wevu_touchSetupMetho = runtime.__wevu_touchSetupMethodsVersion) === null || _wevu_touchSetupMetho === void 0 || _wevu_touchSetupMetho.call(runtime);
2606
2612
  }
2613
+ } catch (error) {
2614
+ instanceScope.stop();
2615
+ target.__wevuEffectScope = void 0;
2616
+ throw error;
2607
2617
  } finally {
2608
2618
  setCurrentSetupContext(void 0);
2609
2619
  setCurrentInstance(void 0);
@@ -2999,6 +3009,7 @@ function setRuntimeSetDataVisibility(target, visible) {
2999
3009
  * @internal
3000
3010
  */
3001
3011
  function teardownRuntimeInstance(target) {
3012
+ var _target$__wevuEffectS;
3002
3013
  const runtime = target.__wevu;
3003
3014
  const ownerId = target.__wvOwnerId;
3004
3015
  if (ownerId) removeOwner(ownerId);
@@ -3010,6 +3021,8 @@ function teardownRuntimeInstance(target) {
3010
3021
  stop();
3011
3022
  } catch (_unused2) {}
3012
3023
  target.__wevuWatchStops = void 0;
3024
+ (_target$__wevuEffectS = target.__wevuEffectScope) === null || _target$__wevuEffectS === void 0 || _target$__wevuEffectS.stop();
3025
+ target.__wevuEffectScope = void 0;
3013
3026
  if (runtime) runtime.unmount();
3014
3027
  delete target.__wevu;
3015
3028
  if ("$wevu" in target) delete target.$wevu;
@@ -3729,10 +3742,84 @@ function createPropsSync(options) {
3729
3742
  };
3730
3743
  }
3731
3744
  //#endregion
3745
+ //#region src/runtime/pageLayout.ts
3746
+ const PAGE_LAYOUT_SETTER_KEY = "__wevuSetPageLayout";
3747
+ const NO_LAYOUT_RUNTIME_KEY = "__wv_no_layout";
3748
+ function resolveCurrentPageInstance() {
3749
+ const getCurrentPagesFn = globalThis.getCurrentPages;
3750
+ if (typeof getCurrentPagesFn !== "function") return;
3751
+ return getCurrentPagesFn().at(-1);
3752
+ }
3753
+ function normalizeRuntimePageLayoutName(layout) {
3754
+ return layout === NO_LAYOUT_RUNTIME_KEY ? false : layout;
3755
+ }
3756
+ /**
3757
+ * 获取当前页面 layout 状态。
3758
+ */
3759
+ function usePageLayout() {
3760
+ var _currentInstance$__we, _runtimeState$__wv_pa;
3761
+ if (!getCurrentSetupContext()) throw new Error("usePageLayout() 必须在 setup() 的同步阶段调用");
3762
+ const currentInstance = getCurrentInstance();
3763
+ const runtimeState = currentInstance === null || currentInstance === void 0 || (_currentInstance$__we = currentInstance.__wevu) === null || _currentInstance$__we === void 0 ? void 0 : _currentInstance$__we.state;
3764
+ const pageLayoutState = reactive({
3765
+ name: normalizeRuntimePageLayoutName(runtimeState === null || runtimeState === void 0 ? void 0 : runtimeState.__wv_page_layout_name),
3766
+ props: { ...(_runtimeState$__wv_pa = runtimeState === null || runtimeState === void 0 ? void 0 : runtimeState.__wv_page_layout_props) !== null && _runtimeState$__wv_pa !== void 0 ? _runtimeState$__wv_pa : {} }
3767
+ });
3768
+ if (currentInstance) currentInstance.__wevuPageLayoutState = pageLayoutState;
3769
+ return readonly(pageLayoutState);
3770
+ }
3771
+ function syncRuntimePageLayoutState(target, layout, props) {
3772
+ const state = target.__wevuPageLayoutState;
3773
+ if (!state) return;
3774
+ state.name = layout;
3775
+ state.props = { ...props };
3776
+ }
3777
+ function syncRuntimePageLayoutStateFromRuntime(target) {
3778
+ var _target$__wevu, _runtimeState$__wv_pa2;
3779
+ const state = target.__wevuPageLayoutState;
3780
+ const runtimeState = (_target$__wevu = target.__wevu) === null || _target$__wevu === void 0 ? void 0 : _target$__wevu.state;
3781
+ if (!state || !runtimeState) return;
3782
+ state.name = normalizeRuntimePageLayoutName(runtimeState.__wv_page_layout_name);
3783
+ state.props = { ...(_runtimeState$__wv_pa2 = runtimeState.__wv_page_layout_props) !== null && _runtimeState$__wv_pa2 !== void 0 ? _runtimeState$__wv_pa2 : {} };
3784
+ }
3785
+ /**
3786
+ * 显式切换当前页面使用的 layout。
3787
+ */
3788
+ function setPageLayout(layout, props) {
3789
+ const currentInstance = getCurrentInstance();
3790
+ const directSetter = currentInstance === null || currentInstance === void 0 ? void 0 : currentInstance[PAGE_LAYOUT_SETTER_KEY];
3791
+ if (typeof directSetter === "function") {
3792
+ directSetter(layout, props);
3793
+ return;
3794
+ }
3795
+ const currentPage = resolveCurrentPageInstance();
3796
+ const pageSetter = currentPage === null || currentPage === void 0 ? void 0 : currentPage[PAGE_LAYOUT_SETTER_KEY];
3797
+ if (typeof pageSetter === "function") {
3798
+ pageSetter(layout, props);
3799
+ return;
3800
+ }
3801
+ throw new Error("setPageLayout() 未找到当前页面实例。请在页面 setup()、事件回调或当前页面上下文中调用。");
3802
+ }
3803
+ function resolveRuntimePageLayoutName(layout) {
3804
+ return layout === false ? NO_LAYOUT_RUNTIME_KEY : layout;
3805
+ }
3806
+ //#endregion
3732
3807
  //#region src/runtime/register/component/registerDefinition.ts
3733
3808
  function registerComponentDefinition(options) {
3734
3809
  const { runtimeApp, watch, setup, restOptions, pageLifecycleHooks, finalObservers, userLifetimes, userPageLifetimes, finalMethods, finalOptions, applyExtraInstanceFields, templateRefs, attachWevuPropKeys, setupLifecycle, syncWevuPropsFromInstance, isPage, legacyCreated, getRuntimeOwnerLabel } = options;
3735
3810
  const pageShareMethodBridges = {};
3811
+ const attachPageLayoutSetter = (instance) => {
3812
+ if (!isPage) return;
3813
+ instance.__wevuSetPageLayout = (layout, props) => {
3814
+ var _instance$__wevu;
3815
+ const runtimeState = (_instance$__wevu = instance.__wevu) === null || _instance$__wevu === void 0 ? void 0 : _instance$__wevu.state;
3816
+ if (!runtimeState || typeof runtimeState !== "object") return;
3817
+ runtimeState.__wv_page_layout_name = resolveRuntimePageLayoutName(layout);
3818
+ const nextProps = layout === false ? {} : props !== null && props !== void 0 ? props : {};
3819
+ runtimeState.__wv_page_layout_props = nextProps;
3820
+ syncRuntimePageLayoutState(instance, layout, nextProps);
3821
+ };
3822
+ };
3736
3823
  if (isPage) for (const hookName of [
3737
3824
  "onShareAppMessage",
3738
3825
  "onShareTimeline",
@@ -3768,6 +3855,7 @@ function registerComponentDefinition(options) {
3768
3855
  throw new Error(`[wevu] mount runtime failed in created (${label}): ${error instanceof Error ? error.message : String(error)}`);
3769
3856
  }
3770
3857
  syncWevuPropsFromInstance(this);
3858
+ attachPageLayoutSetter(this);
3771
3859
  }
3772
3860
  if (typeof legacyCreated === "function") legacyCreated.apply(this, args);
3773
3861
  if (typeof userLifetimes.created === "function") userLifetimes.created.apply(this, args);
@@ -3792,6 +3880,7 @@ function registerComponentDefinition(options) {
3792
3880
  throw new Error(`[wevu] mount runtime failed in attached (${label}): ${error instanceof Error ? error.message : String(error)}`);
3793
3881
  }
3794
3882
  syncWevuPropsFromInstance(this);
3883
+ attachPageLayoutSetter(this);
3795
3884
  if (setupLifecycle === "created") enableDeferredSetData(this);
3796
3885
  callHookList(this, "onAttached", args);
3797
3886
  if (typeof userLifetimes.attached === "function") userLifetimes.attached.apply(this, args);
@@ -4901,4 +4990,4 @@ function useTemplateRef(name) {
4901
4990
  return target;
4902
4991
  }
4903
4992
  //#endregion
4904
- export { addMutationRecorder, batch, callHookList, callHookReturn, callUpdateHooks, computed, createApp, createStore, createWevuComponent, createWevuScopedSlotComponent, customRef, defineComponent, defineStore, effect, effectScope, endBatch, getCurrentInstance, getCurrentScope, getCurrentSetupContext, getDeepWatchStrategy, getReactiveVersion, inject, injectGlobal, isNoSetData, isRaw, isReactive, isRef, isShallowReactive, isShallowRef, markNoSetData, markRaw, mergeModels, mountRuntimeInstance, nextTick, normalizeClass, normalizeStyle, onActivated, onAddToFavorites, onAttached, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onDetached, onError, onErrorCaptured, onHide, onLaunch, onLoad, onMemoryWarning, onMounted, onMoved, onPageNotFound, onPageScroll, onPullDownRefresh, onReachBottom, onReady, onResize, onRouteDone, onSaveExitState, onScopeDispose, onServerPrefetch, onShareAppMessage, onShareTimeline, onShow, onTabItemTap, onThemeChange, onUnhandledRejection, onUnload, onUnmounted, onUpdated, prelinkReactiveTree, provide, provideGlobal, reactive, readonly, ref, registerApp, registerComponent, removeMutationRecorder, resetWevuDefaults, runSetupFunction, setCurrentInstance, setCurrentSetupContext, setDeepWatchStrategy, setRuntimeSetDataVisibility, setWevuDefaults, shallowReactive, shallowRef, startBatch, stop, storeToRefs, teardownRuntimeInstance, toRaw, toRef, toRefs, toValue, touchReactive, traverse, triggerRef, unref, useAttrs, useBindModel, useDisposables, useIntersectionObserver, useModel, useNativeInstance, useNativePageRouter, useNativeRouter, usePageScrollThrottle, useSlots, useTemplateRef, useUpdatePerformanceListener, watch, watchEffect };
4993
+ export { addMutationRecorder, batch, callHookList, callHookReturn, callUpdateHooks, computed, createApp, createStore, createWevuComponent, createWevuScopedSlotComponent, customRef, defineComponent, defineStore, effect, effectScope, endBatch, getCurrentInstance, getCurrentScope, getCurrentSetupContext, getDeepWatchStrategy, getReactiveVersion, hasInjectionContext, inject, injectGlobal, isNoSetData, isRaw, isReactive, isRef, isShallowReactive, isShallowRef, markNoSetData, markRaw, mergeModels, mountRuntimeInstance, nextTick, normalizeClass, normalizeStyle, onActivated, onAddToFavorites, onAttached, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onDetached, onError, onErrorCaptured, onHide, onLaunch, onLoad, onMemoryWarning, onMounted, onMoved, onPageNotFound, onPageScroll, onPullDownRefresh, onReachBottom, onReady, onResize, onRouteDone, onSaveExitState, onScopeDispose, onServerPrefetch, onShareAppMessage, onShareTimeline, onShow, onTabItemTap, onThemeChange, onUnhandledRejection, onUnload, onUnmounted, onUpdated, prelinkReactiveTree, provide, provideGlobal, reactive, readonly, ref, registerApp, registerComponent, removeMutationRecorder, resetWevuDefaults, resolveRuntimePageLayoutName, runSetupFunction, setCurrentInstance, setCurrentSetupContext, setDeepWatchStrategy, setPageLayout, setRuntimeSetDataVisibility, setWevuDefaults, shallowReactive, shallowReadonly, shallowRef, startBatch, stop, storeToRefs, syncRuntimePageLayoutState, syncRuntimePageLayoutStateFromRuntime, teardownRuntimeInstance, toRaw, toRef, toRefs, toValue, touchReactive, traverse, triggerRef, unref, useAttrs, useBindModel, useDisposables, useIntersectionObserver, useModel, useNativeInstance, useNativePageRouter, useNativeRouter, usePageLayout, usePageScrollThrottle, useSlots, useTemplateRef, useUpdatePerformanceListener, watch, watchEffect };
@@ -1,6 +1,6 @@
1
1
  import { n as isRef, r as markAsRef, v as isObject } from "./ref-BjmD-qct.mjs";
2
2
  //#region src/reactivity/readonly.ts
3
- function readonly(target) {
3
+ function createReadonlyWrapper(target) {
4
4
  if (isRef(target)) {
5
5
  const source = target;
6
6
  return markAsRef({
@@ -28,6 +28,12 @@ function readonly(target) {
28
28
  }
29
29
  });
30
30
  }
31
+ function readonly(target) {
32
+ return createReadonlyWrapper(target);
33
+ }
34
+ function shallowReadonly(target) {
35
+ return createReadonlyWrapper(target);
36
+ }
31
37
  //#endregion
32
38
  //#region src/runtime/platform.ts
33
39
  function getGlobalRuntime() {
@@ -266,6 +272,15 @@ function onAddToFavorites(handler) {
266
272
  const PROVIDE_SCOPE_KEY = Symbol("wevu.provideScope");
267
273
  const __wevuGlobalProvideStore = /* @__PURE__ */ new Map();
268
274
  /**
275
+ * 判断当前是否存在可用的注入上下文。
276
+ *
277
+ * wevu 目前的依赖注入上下文来自同步 `setup()` 阶段的当前实例;
278
+ * 若未来补充 app 级 provider,这里可继续扩展判断来源。
279
+ */
280
+ function hasInjectionContext() {
281
+ return Boolean(getCurrentInstance());
282
+ }
283
+ /**
269
284
  * 在组件上下文中向后代注入值(与 Vue 3 行为兼容),若没有当前实例则回落到全局存储。
270
285
  *
271
286
  * @param key 注入键,可为字符串、Symbol 或对象
@@ -407,4 +422,4 @@ function useNativePageRouter() {
407
422
  return useRuntimeRouterByAccessor("pageRouter", "router", "useNativePageRouter");
408
423
  }
409
424
  //#endregion
410
- export { onUnload as A, getScopedSlotHostGlobalObject as B, onSaveExitState as C, onTabItemTap as D, onShow as E, getCurrentSetupContext as F, pushHook as I, setCurrentInstance as L, callHookList as M, callHookReturn as N, onThemeChange as O, getCurrentInstance as P, setCurrentSetupContext as R, onRouteDone as S, onShareTimeline as T, readonly as V, onPageScroll as _, provide as a, onReady as b, onAttached as c, onHide as d, onLaunch as f, onPageNotFound as g, onMoved as h, injectGlobal as i, assertInSetup as j, onUnhandledRejection as k, onDetached as l, onMemoryWarning as m, useNativeRouter as n, provideGlobal as o, onLoad as p, inject as r, onAddToFavorites as s, useNativePageRouter as t, onError as u, onPullDownRefresh as v, onShareAppMessage as w, onResize as x, onReachBottom as y, getMiniProgramGlobalObject as z };
425
+ export { onUnhandledRejection as A, getMiniProgramGlobalObject as B, onRouteDone as C, onShow as D, onShareTimeline as E, getCurrentInstance as F, readonly as H, getCurrentSetupContext as I, pushHook as L, assertInSetup as M, callHookList as N, onTabItemTap as O, callHookReturn as P, setCurrentInstance as R, onResize as S, onShareAppMessage as T, shallowReadonly as U, getScopedSlotHostGlobalObject as V, onPageNotFound as _, injectGlobal as a, onReachBottom as b, onAddToFavorites as c, onError as d, onHide as f, onMoved as g, onMemoryWarning as h, inject as i, onUnload as j, onThemeChange as k, onAttached as l, onLoad as m, useNativeRouter as n, provide as o, onLaunch as p, hasInjectionContext as r, provideGlobal as s, useNativePageRouter as t, onDetached as u, onPageScroll as v, onSaveExitState as w, onReady as x, onPullDownRefresh as y, setCurrentSetupContext as z };
package/dist/router.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { d as reactive } from "./ref-BjmD-qct.mjs";
2
- import { E as onShow, F as getCurrentSetupContext, S as onRouteDone, V as readonly, i as injectGlobal, n as useNativeRouter$1, o as provideGlobal, p as onLoad, t as useNativePageRouter$1 } from "./router-BoEmd9rt.mjs";
2
+ import { C as onRouteDone, D as onShow, H as readonly, I as getCurrentSetupContext, a as injectGlobal, m as onLoad, n as useNativeRouter$1, s as provideGlobal, t as useNativePageRouter$1 } from "./router-PqZEeqhd.mjs";
3
3
  //#region src/routerInternal/path.ts
4
4
  function normalizePathSegments(path) {
5
5
  const segments = [];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "wevu",
3
3
  "type": "module",
4
- "version": "6.10.1",
4
+ "version": "6.11.1",
5
5
  "description": "Vue 3 风格的小程序运行时,包含响应式、diff+setData 与轻量状态管理",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -96,7 +96,7 @@
96
96
  "dependencies": {
97
97
  "vue": "^3.5.30",
98
98
  "@wevu/api": "0.2.2",
99
- "@wevu/compiler": "6.10.1"
99
+ "@wevu/compiler": "6.11.1"
100
100
  },
101
101
  "scripts": {
102
102
  "dev": "tsdown -w",