wevu 6.11.1 → 6.11.4
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/dist/index.d.mts +82 -5
- package/dist/index.mjs +471 -202
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -397,6 +397,7 @@ interface InternalRuntimeStateFields {
|
|
|
397
397
|
__wevu?: RuntimeInstance<any, any, any>;
|
|
398
398
|
__wevuSetPageLayout?: (layout: string | false, props?: Record<string, any>) => void;
|
|
399
399
|
__wevuWatchStops?: WatchStopHandle[];
|
|
400
|
+
__wevuLayoutHostBridge?: Record<string, any>;
|
|
400
401
|
$wevu?: RuntimeInstance<any, any, any>;
|
|
401
402
|
__wevuHooks?: Record<string, any>;
|
|
402
403
|
__wevuExposed?: Record<string, any>;
|
|
@@ -1071,6 +1072,61 @@ type UseIntersectionObserverResult = WechatMiniprogram.IntersectionObserver;
|
|
|
1071
1072
|
*/
|
|
1072
1073
|
declare function useIntersectionObserver(options?: UseIntersectionObserverOptions): UseIntersectionObserverResult;
|
|
1073
1074
|
//#endregion
|
|
1075
|
+
//#region src/runtime/layoutBridge.d.ts
|
|
1076
|
+
type LayoutBridgeContext = Record<string, any>;
|
|
1077
|
+
type LayoutBridgeComponentResolver = (selector: string) => any;
|
|
1078
|
+
type LayoutHostMap = Record<string, unknown>;
|
|
1079
|
+
interface LayoutHostBinding {
|
|
1080
|
+
key: string;
|
|
1081
|
+
refName?: string;
|
|
1082
|
+
selector: string;
|
|
1083
|
+
kind?: 'component';
|
|
1084
|
+
}
|
|
1085
|
+
interface LayoutHostResolveOptions<T = any> {
|
|
1086
|
+
context?: T;
|
|
1087
|
+
fallbackContext?: T;
|
|
1088
|
+
interval?: number;
|
|
1089
|
+
retries?: number;
|
|
1090
|
+
}
|
|
1091
|
+
/**
|
|
1092
|
+
* 为当前页面注册 layout bridge,使页面或子组件可消费 layout 内部能力。
|
|
1093
|
+
*/
|
|
1094
|
+
declare function registerPageLayoutBridge(selectors: string | string[], context?: LayoutBridgeContext): boolean;
|
|
1095
|
+
/**
|
|
1096
|
+
* 移除当前页面的 layout bridge 注册。
|
|
1097
|
+
*/
|
|
1098
|
+
declare function unregisterPageLayoutBridge(selectors: string | string[], context?: LayoutBridgeContext): boolean;
|
|
1099
|
+
/**
|
|
1100
|
+
* 解析当前页面已注册的 layout bridge,找不到时回退到传入上下文。
|
|
1101
|
+
*/
|
|
1102
|
+
declare function resolveLayoutBridge<T = any>(selector: string, fallbackContext?: T): T | undefined;
|
|
1103
|
+
/**
|
|
1104
|
+
* 解析当前页面 layout 内通过指定 key 暴露的宿主实例。
|
|
1105
|
+
*/
|
|
1106
|
+
declare function resolveLayoutHost<T = any, C = any>(key: string, options?: LayoutHostResolveOptions<C>): T | null;
|
|
1107
|
+
/**
|
|
1108
|
+
* 等待当前页面 layout 宿主实例可用,适合页面初次进入时的异步宿主解析。
|
|
1109
|
+
*/
|
|
1110
|
+
declare function waitForLayoutHost<T = any, C = any>(key: string, options?: LayoutHostResolveOptions<C>): Promise<T | null>;
|
|
1111
|
+
/**
|
|
1112
|
+
* 在 layout 生命周期内暴露 bridge,使页面或子组件可访问 layout 内部实例。
|
|
1113
|
+
*/
|
|
1114
|
+
declare function useLayoutBridge(selectors: string | string[], options?: {
|
|
1115
|
+
resolveComponent?: LayoutBridgeComponentResolver;
|
|
1116
|
+
}): void;
|
|
1117
|
+
/**
|
|
1118
|
+
* 使用编译期注入的宿主绑定信息,直接从当前 layout 运行时实例解析子组件宿主并注册 bridge。
|
|
1119
|
+
*/
|
|
1120
|
+
declare function registerRuntimeLayoutHosts(bindings: LayoutHostBinding[], context?: LayoutBridgeContext): any;
|
|
1121
|
+
/**
|
|
1122
|
+
* 移除运行时自动注册的 layout 宿主 bridge。
|
|
1123
|
+
*/
|
|
1124
|
+
declare function unregisterRuntimeLayoutHosts(bindings: LayoutHostBinding[], context?: LayoutBridgeContext): boolean;
|
|
1125
|
+
/**
|
|
1126
|
+
* 使用 key -> 宿主实例的映射批量暴露 layout 内部宿主,适合 toast/dialog 等共享反馈节点。
|
|
1127
|
+
*/
|
|
1128
|
+
declare function useLayoutHosts(hosts: LayoutHostMap): void;
|
|
1129
|
+
//#endregion
|
|
1074
1130
|
//#region src/runtime/noSetData.d.ts
|
|
1075
1131
|
declare function markNoSetData<T extends object>(value: T): T;
|
|
1076
1132
|
declare function isNoSetData(value: unknown): boolean;
|
|
@@ -1326,7 +1382,17 @@ type EmitFn<Options = ObjectEmitsOptions, Event extends keyof Options = keyof Op
|
|
|
1326
1382
|
type ComponentTypeEmits = ((...args: any[]) => any) | Record<string, any>;
|
|
1327
1383
|
type RecordToUnion<T extends Record<string, any>> = T[keyof T];
|
|
1328
1384
|
type ShortEmits<T extends Record<string, any>> = UnionToIntersection<RecordToUnion<{ [K in keyof T]: (evt: K, ...args: T[K]) => void }>>;
|
|
1329
|
-
type
|
|
1385
|
+
type ScriptSetupNativePropertyOption = WechatMiniprogram.Component.PropertyOption;
|
|
1386
|
+
type ScriptSetupNativeMethodOption = WechatMiniprogram.Component.MethodOption;
|
|
1387
|
+
type ScriptSetupNativeBehaviorOption = WechatMiniprogram.Component.IEmptyArray;
|
|
1388
|
+
type ScriptSetupNativeInstance<D extends object, P extends ScriptSetupNativePropertyOption, M extends ScriptSetupNativeMethodOption> = WechatMiniprogram.Component.Instance<D, P, M, ScriptSetupNativeBehaviorOption>;
|
|
1389
|
+
type ScriptSetupObservedProperty<TProperty extends WechatMiniprogram.Component.AllFullProperty, TInstance> = Omit<TProperty, 'observer'> & {
|
|
1390
|
+
observer?: string | ((this: TInstance, newVal: WechatMiniprogram.Component.PropertyToData<TProperty>, oldVal: WechatMiniprogram.Component.PropertyToData<TProperty>, changedPath: Array<string | number>) => void);
|
|
1391
|
+
};
|
|
1392
|
+
type ScriptSetupPropertyObserver<TProperty extends WechatMiniprogram.Component.AllProperty, TInstance> = TProperty extends infer TCurrent extends WechatMiniprogram.Component.AllFullProperty ? ScriptSetupObservedProperty<TCurrent, TInstance> : TProperty;
|
|
1393
|
+
type ScriptSetupNativeProperties<D extends object, P extends ScriptSetupNativePropertyOption, M extends ScriptSetupNativeMethodOption> = { [K in keyof P]: ScriptSetupPropertyObserver<P[K], ScriptSetupNativeInstance<D, P, M>> };
|
|
1394
|
+
type ScriptSetupNativeMethods<D extends object, P extends ScriptSetupNativePropertyOption, M extends ScriptSetupNativeMethodOption> = M & ThisType<ScriptSetupNativeInstance<D, P, M>>;
|
|
1395
|
+
type ScriptSetupDefineOptions<D extends object = Record<string, any>, C extends ComputedDefinitions = ComputedDefinitions, M extends MethodDefinitions = MethodDefinitions, P extends ScriptSetupNativePropertyOption = ScriptSetupNativePropertyOption> = Omit<DefineComponentOptions<ComponentPropsOptions, D, C, M>, 'props' | 'options' | 'data' | 'methods'> & {
|
|
1330
1396
|
/**
|
|
1331
1397
|
* props 必须通过 defineProps() 声明。
|
|
1332
1398
|
*/
|
|
@@ -1347,6 +1413,18 @@ type ScriptSetupDefineOptions<D extends object = Record<string, any>, C extends
|
|
|
1347
1413
|
* 小程序 Component 选项(multipleSlots/styleIsolation 等)。
|
|
1348
1414
|
*/
|
|
1349
1415
|
options?: WechatMiniprogram.Component.ComponentOptions;
|
|
1416
|
+
/**
|
|
1417
|
+
* 小程序原生 properties。
|
|
1418
|
+
*/
|
|
1419
|
+
properties?: ScriptSetupNativeProperties<D, P, M>;
|
|
1420
|
+
/**
|
|
1421
|
+
* 小程序原生 data。
|
|
1422
|
+
*/
|
|
1423
|
+
data?: D | (() => D);
|
|
1424
|
+
/**
|
|
1425
|
+
* 小程序原生 methods。
|
|
1426
|
+
*/
|
|
1427
|
+
methods?: ScriptSetupNativeMethods<D, P, M>;
|
|
1350
1428
|
/**
|
|
1351
1429
|
* setup 执行时机(默认 attached)。
|
|
1352
1430
|
*/
|
|
@@ -1377,9 +1455,8 @@ declare function defineExpose<T extends Record<string, any> = Record<string, any
|
|
|
1377
1455
|
/**
|
|
1378
1456
|
* defineOptions 设置 `<script setup>` 组件选项(仅类型层)。
|
|
1379
1457
|
*/
|
|
1380
|
-
declare function defineOptions<D extends object = Record<string, any>, C extends ComputedDefinitions = ComputedDefinitions, M extends MethodDefinitions = MethodDefinitions>(options?: ScriptSetupDefineOptions<D, C, M>
|
|
1381
|
-
|
|
1382
|
-
}): void;
|
|
1458
|
+
declare function defineOptions<D extends object = Record<string, any>, C extends ComputedDefinitions = ComputedDefinitions, M extends MethodDefinitions = MethodDefinitions, P extends WechatMiniprogram.Component.PropertyOption = WechatMiniprogram.Component.PropertyOption>(options?: ScriptSetupDefineOptions<D, C, M, P>): void;
|
|
1459
|
+
declare function defineOptions<D extends object = Record<string, any>, C extends ComputedDefinitions = ComputedDefinitions, M extends MethodDefinitions = MethodDefinitions, P extends WechatMiniprogram.Component.PropertyOption = WechatMiniprogram.Component.PropertyOption>(options?: () => ScriptSetupDefineOptions<D, C, M, P> | Promise<ScriptSetupDefineOptions<D, C, M, P>>): void;
|
|
1383
1460
|
/**
|
|
1384
1461
|
* defineSlots 声明 slots 类型(仅类型层)。
|
|
1385
1462
|
*/
|
|
@@ -1416,4 +1493,4 @@ declare function defineModel<T = any, M extends PropertyKey = string, G = T, S =
|
|
|
1416
1493
|
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>;
|
|
1417
1494
|
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>;
|
|
1418
1495
|
//#endregion
|
|
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 };
|
|
1496
|
+
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, LayoutHostBinding, 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, registerPageLayoutBridge, registerRuntimeLayoutHosts, removeMutationRecorder, resetWevuDefaults, resolveLayoutBridge, resolveLayoutHost, 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, unregisterPageLayoutBridge, unregisterRuntimeLayoutHosts, useAttrs, useBindModel, useDisposables, useIntersectionObserver, useLayoutBridge, useLayoutHosts, useModel, useNativeInstance, useNativePageRouter, useNativeRouter, usePageLayout, usePageScrollThrottle, useSlots, useTemplateRef, useUpdatePerformanceListener, waitForLayoutHost, watch, watchEffect, withDefaults };
|
package/dist/index.mjs
CHANGED
|
@@ -124,6 +124,81 @@ function traverse(value, depth = Infinity, seen = /* @__PURE__ */ new Map()) {
|
|
|
124
124
|
return value;
|
|
125
125
|
}
|
|
126
126
|
//#endregion
|
|
127
|
+
//#region src/runtime/hooks/vue.ts
|
|
128
|
+
/**
|
|
129
|
+
* Vue 3 对齐:组件/页面已挂载,映射小程序 onReady
|
|
130
|
+
*/
|
|
131
|
+
function onMounted(handler) {
|
|
132
|
+
pushHook(assertInSetup("onMounted"), "onReady", handler);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Vue 3 对齐:组件/页面更新后触发。
|
|
136
|
+
* 小程序没有专用 update 生命周期,这里在每次 setData 完成后调用。
|
|
137
|
+
*/
|
|
138
|
+
function onUpdated(handler) {
|
|
139
|
+
pushHook(assertInSetup("onUpdated"), "__wevuOnUpdated", handler);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Vue 3 对齐:卸载前触发。
|
|
143
|
+
* 小程序无 before-unload 生命周期,setup 时同步执行以保持语义。
|
|
144
|
+
*/
|
|
145
|
+
function onBeforeUnmount(handler) {
|
|
146
|
+
assertInSetup("onBeforeUnmount");
|
|
147
|
+
handler();
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Vue 3 对齐:组件/页面卸载;映射到页面 onUnload 或组件 detached
|
|
151
|
+
*/
|
|
152
|
+
function onUnmounted(handler) {
|
|
153
|
+
pushHook(assertInSetup("onUnmounted"), "onUnload", handler);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Vue 3 对齐:挂载前;setup 时同步触发以模拟 beforeMount 语义
|
|
157
|
+
*/
|
|
158
|
+
function onBeforeMount(handler) {
|
|
159
|
+
assertInSetup("onBeforeMount");
|
|
160
|
+
handler();
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Vue 3 对齐:更新前;在每次 setData 前触发
|
|
164
|
+
*/
|
|
165
|
+
function onBeforeUpdate(handler) {
|
|
166
|
+
pushHook(assertInSetup("onBeforeUpdate"), "__wevuOnBeforeUpdate", handler);
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Vue 3 对齐:错误捕获;映射到小程序 onError
|
|
170
|
+
*/
|
|
171
|
+
function onErrorCaptured(handler) {
|
|
172
|
+
const instance = assertInSetup("onErrorCaptured");
|
|
173
|
+
pushHook(instance, "onError", (err) => handler(err, instance, ""));
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Vue 3 对齐:组件激活;映射到小程序 onShow
|
|
177
|
+
*/
|
|
178
|
+
function onActivated(handler) {
|
|
179
|
+
pushHook(assertInSetup("onActivated"), "onShow", handler);
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Vue 3 对齐:组件失活;映射到小程序 onHide
|
|
183
|
+
*/
|
|
184
|
+
function onDeactivated(handler) {
|
|
185
|
+
pushHook(assertInSetup("onDeactivated"), "onHide", handler);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Vue 3 对齐:服务端渲染前置钩子。
|
|
189
|
+
* 小程序无此场景,保留空实现以保持 API 兼容。
|
|
190
|
+
*/
|
|
191
|
+
function onServerPrefetch(_handler) {
|
|
192
|
+
assertInSetup("onServerPrefetch");
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* 派发更新阶段钩子(框架内部调度入口)。
|
|
196
|
+
* @internal
|
|
197
|
+
*/
|
|
198
|
+
function callUpdateHooks(target, phase) {
|
|
199
|
+
callHookList(target, phase === "before" ? "__wevuOnBeforeUpdate" : "__wevuOnUpdated");
|
|
200
|
+
}
|
|
201
|
+
//#endregion
|
|
127
202
|
//#region src/reactivity/watch/types.ts
|
|
128
203
|
let __deepWatchStrategy = "version";
|
|
129
204
|
/**
|
|
@@ -207,6 +282,7 @@ function dispatchScheduledJob(job, flush, isFirstRun, scheduler) {
|
|
|
207
282
|
//#region src/reactivity/watch.ts
|
|
208
283
|
function watch(source, cb, options = {}) {
|
|
209
284
|
var _options$flush;
|
|
285
|
+
const ownerInstance = getCurrentInstance();
|
|
210
286
|
const watchGetterContext = createWatchGetter(source);
|
|
211
287
|
const getter = applyDeepWatchGetter(watchGetterContext.getter, source, watchGetterContext.isMultiSource, watchGetterContext.isReactiveSource, options.deep);
|
|
212
288
|
let cleanup;
|
|
@@ -228,7 +304,13 @@ function watch(source, cb, options = {}) {
|
|
|
228
304
|
if (!runner.active || paused || token !== pauseToken) return;
|
|
229
305
|
const newValue = runner();
|
|
230
306
|
cleanup === null || cleanup === void 0 || cleanup();
|
|
231
|
-
|
|
307
|
+
const previousInstance = getCurrentInstance();
|
|
308
|
+
setCurrentInstance(ownerInstance);
|
|
309
|
+
try {
|
|
310
|
+
cbWithOnce(newValue, oldValue, onCleanup);
|
|
311
|
+
} finally {
|
|
312
|
+
setCurrentInstance(previousInstance);
|
|
313
|
+
}
|
|
232
314
|
oldValue = newValue;
|
|
233
315
|
};
|
|
234
316
|
const scheduledJob = () => runJob(scheduledToken);
|
|
@@ -272,6 +354,7 @@ function watch(source, cb, options = {}) {
|
|
|
272
354
|
*/
|
|
273
355
|
function watchEffect(effectFn, options = {}) {
|
|
274
356
|
var _options$flush2;
|
|
357
|
+
const ownerInstance = getCurrentInstance();
|
|
275
358
|
let cleanup;
|
|
276
359
|
const onCleanup = (fn) => {
|
|
277
360
|
cleanup = fn;
|
|
@@ -293,7 +376,13 @@ function watchEffect(effectFn, options = {}) {
|
|
|
293
376
|
runner = effect(() => {
|
|
294
377
|
cleanup === null || cleanup === void 0 || cleanup();
|
|
295
378
|
cleanup = void 0;
|
|
296
|
-
|
|
379
|
+
const previousInstance = getCurrentInstance();
|
|
380
|
+
setCurrentInstance(ownerInstance);
|
|
381
|
+
try {
|
|
382
|
+
effectFn(onCleanup);
|
|
383
|
+
} finally {
|
|
384
|
+
setCurrentInstance(previousInstance);
|
|
385
|
+
}
|
|
297
386
|
}, {
|
|
298
387
|
lazy: true,
|
|
299
388
|
scheduler: () => {
|
|
@@ -1678,81 +1767,6 @@ function applyWevuComponentDefaults(options) {
|
|
|
1678
1767
|
return mergeWithDefaults(currentDefaults.component, options);
|
|
1679
1768
|
}
|
|
1680
1769
|
//#endregion
|
|
1681
|
-
//#region src/runtime/hooks/vue.ts
|
|
1682
|
-
/**
|
|
1683
|
-
* Vue 3 对齐:组件/页面已挂载,映射小程序 onReady
|
|
1684
|
-
*/
|
|
1685
|
-
function onMounted(handler) {
|
|
1686
|
-
pushHook(assertInSetup("onMounted"), "onReady", handler);
|
|
1687
|
-
}
|
|
1688
|
-
/**
|
|
1689
|
-
* Vue 3 对齐:组件/页面更新后触发。
|
|
1690
|
-
* 小程序没有专用 update 生命周期,这里在每次 setData 完成后调用。
|
|
1691
|
-
*/
|
|
1692
|
-
function onUpdated(handler) {
|
|
1693
|
-
pushHook(assertInSetup("onUpdated"), "__wevuOnUpdated", handler);
|
|
1694
|
-
}
|
|
1695
|
-
/**
|
|
1696
|
-
* Vue 3 对齐:卸载前触发。
|
|
1697
|
-
* 小程序无 before-unload 生命周期,setup 时同步执行以保持语义。
|
|
1698
|
-
*/
|
|
1699
|
-
function onBeforeUnmount(handler) {
|
|
1700
|
-
assertInSetup("onBeforeUnmount");
|
|
1701
|
-
handler();
|
|
1702
|
-
}
|
|
1703
|
-
/**
|
|
1704
|
-
* Vue 3 对齐:组件/页面卸载;映射到页面 onUnload 或组件 detached
|
|
1705
|
-
*/
|
|
1706
|
-
function onUnmounted(handler) {
|
|
1707
|
-
pushHook(assertInSetup("onUnmounted"), "onUnload", handler);
|
|
1708
|
-
}
|
|
1709
|
-
/**
|
|
1710
|
-
* Vue 3 对齐:挂载前;setup 时同步触发以模拟 beforeMount 语义
|
|
1711
|
-
*/
|
|
1712
|
-
function onBeforeMount(handler) {
|
|
1713
|
-
assertInSetup("onBeforeMount");
|
|
1714
|
-
handler();
|
|
1715
|
-
}
|
|
1716
|
-
/**
|
|
1717
|
-
* Vue 3 对齐:更新前;在每次 setData 前触发
|
|
1718
|
-
*/
|
|
1719
|
-
function onBeforeUpdate(handler) {
|
|
1720
|
-
pushHook(assertInSetup("onBeforeUpdate"), "__wevuOnBeforeUpdate", handler);
|
|
1721
|
-
}
|
|
1722
|
-
/**
|
|
1723
|
-
* Vue 3 对齐:错误捕获;映射到小程序 onError
|
|
1724
|
-
*/
|
|
1725
|
-
function onErrorCaptured(handler) {
|
|
1726
|
-
const instance = assertInSetup("onErrorCaptured");
|
|
1727
|
-
pushHook(instance, "onError", (err) => handler(err, instance, ""));
|
|
1728
|
-
}
|
|
1729
|
-
/**
|
|
1730
|
-
* Vue 3 对齐:组件激活;映射到小程序 onShow
|
|
1731
|
-
*/
|
|
1732
|
-
function onActivated(handler) {
|
|
1733
|
-
pushHook(assertInSetup("onActivated"), "onShow", handler);
|
|
1734
|
-
}
|
|
1735
|
-
/**
|
|
1736
|
-
* Vue 3 对齐:组件失活;映射到小程序 onHide
|
|
1737
|
-
*/
|
|
1738
|
-
function onDeactivated(handler) {
|
|
1739
|
-
pushHook(assertInSetup("onDeactivated"), "onHide", handler);
|
|
1740
|
-
}
|
|
1741
|
-
/**
|
|
1742
|
-
* Vue 3 对齐:服务端渲染前置钩子。
|
|
1743
|
-
* 小程序无此场景,保留空实现以保持 API 兼容。
|
|
1744
|
-
*/
|
|
1745
|
-
function onServerPrefetch(_handler) {
|
|
1746
|
-
assertInSetup("onServerPrefetch");
|
|
1747
|
-
}
|
|
1748
|
-
/**
|
|
1749
|
-
* 派发更新阶段钩子(框架内部调度入口)。
|
|
1750
|
-
* @internal
|
|
1751
|
-
*/
|
|
1752
|
-
function callUpdateHooks(target, phase) {
|
|
1753
|
-
callHookList(target, phase === "before" ? "__wevuOnBeforeUpdate" : "__wevuOnUpdated");
|
|
1754
|
-
}
|
|
1755
|
-
//#endregion
|
|
1756
1770
|
//#region src/runtime/register/inline.ts
|
|
1757
1771
|
const AMP_RE$1 = /&/g;
|
|
1758
1772
|
const QUOT_RE$1 = /"/g;
|
|
@@ -1880,6 +1894,148 @@ function runInlineExpression(ctx, expr, event, inlineMap) {
|
|
|
1880
1894
|
if (typeof handler === "function") return handler.apply(ctx, resolvedArgs);
|
|
1881
1895
|
}
|
|
1882
1896
|
//#endregion
|
|
1897
|
+
//#region src/runtime/register/component/lifecycle/platform.ts
|
|
1898
|
+
let wxPatched = false;
|
|
1899
|
+
let currentPageInstance;
|
|
1900
|
+
const PAGE_SCROLL_HOOK_DEPTH_KEY = "__wevuPageScrollHookDepth";
|
|
1901
|
+
function getCurrentPageInstance() {
|
|
1902
|
+
return currentPageInstance;
|
|
1903
|
+
}
|
|
1904
|
+
function bindCurrentPageInstance(target) {
|
|
1905
|
+
currentPageInstance = target;
|
|
1906
|
+
}
|
|
1907
|
+
function releaseCurrentPageInstance(target) {
|
|
1908
|
+
if (currentPageInstance === target) currentPageInstance = void 0;
|
|
1909
|
+
}
|
|
1910
|
+
function runInPageScrollHook(target, task) {
|
|
1911
|
+
var _PAGE_SCROLL_HOOK_DEP;
|
|
1912
|
+
target[PAGE_SCROLL_HOOK_DEPTH_KEY] = Number((_PAGE_SCROLL_HOOK_DEP = target[PAGE_SCROLL_HOOK_DEPTH_KEY]) !== null && _PAGE_SCROLL_HOOK_DEP !== void 0 ? _PAGE_SCROLL_HOOK_DEP : 0) + 1;
|
|
1913
|
+
try {
|
|
1914
|
+
return task();
|
|
1915
|
+
} finally {
|
|
1916
|
+
var _PAGE_SCROLL_HOOK_DEP2;
|
|
1917
|
+
const nextDepth = Number((_PAGE_SCROLL_HOOK_DEP2 = target[PAGE_SCROLL_HOOK_DEPTH_KEY]) !== null && _PAGE_SCROLL_HOOK_DEP2 !== void 0 ? _PAGE_SCROLL_HOOK_DEP2 : 1) - 1;
|
|
1918
|
+
if (nextDepth <= 0) delete target[PAGE_SCROLL_HOOK_DEPTH_KEY];
|
|
1919
|
+
else target[PAGE_SCROLL_HOOK_DEPTH_KEY] = nextDepth;
|
|
1920
|
+
}
|
|
1921
|
+
}
|
|
1922
|
+
function resolvePageOptions(target) {
|
|
1923
|
+
const direct = target.options;
|
|
1924
|
+
if (direct && typeof direct === "object") return direct;
|
|
1925
|
+
if (typeof getCurrentPages === "function") {
|
|
1926
|
+
const pages = getCurrentPages();
|
|
1927
|
+
const page = Array.isArray(pages) ? pages.at(-1) : void 0;
|
|
1928
|
+
const options = page && typeof page === "object" ? page.options : void 0;
|
|
1929
|
+
if (options && typeof options === "object") return options;
|
|
1930
|
+
}
|
|
1931
|
+
return {};
|
|
1932
|
+
}
|
|
1933
|
+
function ensureWxPatched() {
|
|
1934
|
+
if (wxPatched) return;
|
|
1935
|
+
wxPatched = true;
|
|
1936
|
+
const wxGlobal = getMiniProgramGlobalObject();
|
|
1937
|
+
if (!wxGlobal || typeof wxGlobal !== "object") return;
|
|
1938
|
+
const rawStartPullDownRefresh = wxGlobal.startPullDownRefresh;
|
|
1939
|
+
if (typeof rawStartPullDownRefresh === "function") wxGlobal.startPullDownRefresh = function startPullDownRefreshPatched(...args) {
|
|
1940
|
+
const result = rawStartPullDownRefresh.apply(this, args);
|
|
1941
|
+
if (currentPageInstance) callHookList(currentPageInstance, "onPullDownRefresh", []);
|
|
1942
|
+
return result;
|
|
1943
|
+
};
|
|
1944
|
+
const rawPageScrollTo = wxGlobal.pageScrollTo;
|
|
1945
|
+
if (typeof rawPageScrollTo === "function") wxGlobal.pageScrollTo = function pageScrollToPatched(options, ...rest) {
|
|
1946
|
+
const result = rawPageScrollTo.apply(this, [options, ...rest]);
|
|
1947
|
+
if (currentPageInstance) {
|
|
1948
|
+
const pageInstance = currentPageInstance;
|
|
1949
|
+
runInPageScrollHook(pageInstance, () => {
|
|
1950
|
+
callHookList(pageInstance, "onPageScroll", [options !== null && options !== void 0 ? options : {}]);
|
|
1951
|
+
});
|
|
1952
|
+
}
|
|
1953
|
+
return result;
|
|
1954
|
+
};
|
|
1955
|
+
}
|
|
1956
|
+
function ensurePageShareMenus(options) {
|
|
1957
|
+
const { enableOnShareAppMessage, enableOnShareTimeline } = options;
|
|
1958
|
+
if (!enableOnShareAppMessage && !enableOnShareTimeline) return;
|
|
1959
|
+
const wxGlobal = getMiniProgramGlobalObject();
|
|
1960
|
+
if (!wxGlobal || typeof wxGlobal.showShareMenu !== "function") return;
|
|
1961
|
+
const showMenu = (payload) => {
|
|
1962
|
+
try {
|
|
1963
|
+
wxGlobal.showShareMenu(payload);
|
|
1964
|
+
} catch (_unused) {}
|
|
1965
|
+
};
|
|
1966
|
+
if (!(enableOnShareAppMessage || enableOnShareTimeline)) return;
|
|
1967
|
+
const menus = ["shareAppMessage"];
|
|
1968
|
+
if (enableOnShareTimeline) menus.push("shareTimeline");
|
|
1969
|
+
showMenu({
|
|
1970
|
+
withShareTicket: true,
|
|
1971
|
+
menus
|
|
1972
|
+
});
|
|
1973
|
+
}
|
|
1974
|
+
//#endregion
|
|
1975
|
+
//#region src/runtime/pageLayout.ts
|
|
1976
|
+
const PAGE_LAYOUT_SETTER_KEY = "__wevuSetPageLayout";
|
|
1977
|
+
const NO_LAYOUT_RUNTIME_KEY = "__wv_no_layout";
|
|
1978
|
+
function resolveCurrentPageInstance$1() {
|
|
1979
|
+
const runtimeCurrentPage = getCurrentPageInstance();
|
|
1980
|
+
if (runtimeCurrentPage) return runtimeCurrentPage;
|
|
1981
|
+
const getCurrentPagesFn = globalThis.getCurrentPages;
|
|
1982
|
+
if (typeof getCurrentPagesFn !== "function") return;
|
|
1983
|
+
return getCurrentPagesFn().at(-1);
|
|
1984
|
+
}
|
|
1985
|
+
function normalizeRuntimePageLayoutName(layout) {
|
|
1986
|
+
return layout === NO_LAYOUT_RUNTIME_KEY ? false : layout;
|
|
1987
|
+
}
|
|
1988
|
+
/**
|
|
1989
|
+
* 获取当前页面 layout 状态。
|
|
1990
|
+
*/
|
|
1991
|
+
function usePageLayout() {
|
|
1992
|
+
var _currentInstance$__we, _runtimeState$__wv_pa;
|
|
1993
|
+
if (!getCurrentSetupContext()) throw new Error("usePageLayout() 必须在 setup() 的同步阶段调用");
|
|
1994
|
+
const currentInstance = getCurrentInstance();
|
|
1995
|
+
const runtimeState = currentInstance === null || currentInstance === void 0 || (_currentInstance$__we = currentInstance.__wevu) === null || _currentInstance$__we === void 0 ? void 0 : _currentInstance$__we.state;
|
|
1996
|
+
const pageLayoutState = reactive({
|
|
1997
|
+
name: normalizeRuntimePageLayoutName(runtimeState === null || runtimeState === void 0 ? void 0 : runtimeState.__wv_page_layout_name),
|
|
1998
|
+
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 : {} }
|
|
1999
|
+
});
|
|
2000
|
+
if (currentInstance) currentInstance.__wevuPageLayoutState = pageLayoutState;
|
|
2001
|
+
return readonly(pageLayoutState);
|
|
2002
|
+
}
|
|
2003
|
+
function syncRuntimePageLayoutState(target, layout, props) {
|
|
2004
|
+
const state = target.__wevuPageLayoutState;
|
|
2005
|
+
if (!state) return;
|
|
2006
|
+
state.name = layout;
|
|
2007
|
+
state.props = { ...props };
|
|
2008
|
+
}
|
|
2009
|
+
function syncRuntimePageLayoutStateFromRuntime(target) {
|
|
2010
|
+
var _target$__wevu, _runtimeState$__wv_pa2;
|
|
2011
|
+
const state = target.__wevuPageLayoutState;
|
|
2012
|
+
const runtimeState = (_target$__wevu = target.__wevu) === null || _target$__wevu === void 0 ? void 0 : _target$__wevu.state;
|
|
2013
|
+
if (!state || !runtimeState) return;
|
|
2014
|
+
state.name = normalizeRuntimePageLayoutName(runtimeState.__wv_page_layout_name);
|
|
2015
|
+
state.props = { ...(_runtimeState$__wv_pa2 = runtimeState.__wv_page_layout_props) !== null && _runtimeState$__wv_pa2 !== void 0 ? _runtimeState$__wv_pa2 : {} };
|
|
2016
|
+
}
|
|
2017
|
+
/**
|
|
2018
|
+
* 显式切换当前页面使用的 layout。
|
|
2019
|
+
*/
|
|
2020
|
+
function setPageLayout(layout, props) {
|
|
2021
|
+
const currentInstance = getCurrentInstance();
|
|
2022
|
+
const directSetter = currentInstance === null || currentInstance === void 0 ? void 0 : currentInstance[PAGE_LAYOUT_SETTER_KEY];
|
|
2023
|
+
if (typeof directSetter === "function") {
|
|
2024
|
+
directSetter(layout, props);
|
|
2025
|
+
return;
|
|
2026
|
+
}
|
|
2027
|
+
const currentPage = resolveCurrentPageInstance$1();
|
|
2028
|
+
const pageSetter = currentPage === null || currentPage === void 0 ? void 0 : currentPage[PAGE_LAYOUT_SETTER_KEY];
|
|
2029
|
+
if (typeof pageSetter === "function") {
|
|
2030
|
+
pageSetter(layout, props);
|
|
2031
|
+
return;
|
|
2032
|
+
}
|
|
2033
|
+
throw new Error("setPageLayout() 未找到当前页面实例。请在页面 setup()、事件回调或当前页面上下文中调用。");
|
|
2034
|
+
}
|
|
2035
|
+
function resolveRuntimePageLayoutName(layout) {
|
|
2036
|
+
return layout === false ? NO_LAYOUT_RUNTIME_KEY : layout;
|
|
2037
|
+
}
|
|
2038
|
+
//#endregion
|
|
1883
2039
|
//#region src/runtime/scopedSlots.ts
|
|
1884
2040
|
const ownerStore = /* @__PURE__ */ new Map();
|
|
1885
2041
|
let ownerSeed = 0;
|
|
@@ -1990,14 +2146,18 @@ function mergeComponentRefValue(wrapper, exposed) {
|
|
|
1990
2146
|
return markNoSetData(new Proxy(wrapper, {
|
|
1991
2147
|
get(target, key, receiver) {
|
|
1992
2148
|
if (Reflect.has(target, key)) return Reflect.get(target, key, receiver);
|
|
1993
|
-
|
|
2149
|
+
const value = source[key];
|
|
2150
|
+
if (typeof value === "function") return value.bind(source);
|
|
2151
|
+
return value;
|
|
1994
2152
|
},
|
|
1995
2153
|
set(target, key, value, receiver) {
|
|
2154
|
+
if (Reflect.has(target, key)) return Reflect.set(target, key, value, receiver);
|
|
1996
2155
|
if (key in source) {
|
|
1997
2156
|
source[key] = value;
|
|
1998
2157
|
return true;
|
|
1999
2158
|
}
|
|
2000
|
-
|
|
2159
|
+
source[key] = value;
|
|
2160
|
+
return true;
|
|
2001
2161
|
},
|
|
2002
2162
|
has(target, key) {
|
|
2003
2163
|
return Reflect.has(target, key) || key in source;
|
|
@@ -2847,6 +3007,18 @@ function registerWatches(runtime, watchMap, instance) {
|
|
|
2847
3007
|
}
|
|
2848
3008
|
//#endregion
|
|
2849
3009
|
//#region src/runtime/register/runtimeInstance.ts
|
|
3010
|
+
function attachPageLayoutSetter(target) {
|
|
3011
|
+
if (typeof target.route !== "string" || !target.route) return;
|
|
3012
|
+
target.__wevuSetPageLayout = (layout, props) => {
|
|
3013
|
+
var _target$__wevu;
|
|
3014
|
+
const runtimeState = (_target$__wevu = target.__wevu) === null || _target$__wevu === void 0 ? void 0 : _target$__wevu.state;
|
|
3015
|
+
if (!runtimeState || typeof runtimeState !== "object") return;
|
|
3016
|
+
runtimeState.__wv_page_layout_name = resolveRuntimePageLayoutName(layout);
|
|
3017
|
+
const nextProps = layout === false ? {} : props !== null && props !== void 0 ? props : {};
|
|
3018
|
+
runtimeState.__wv_page_layout_props = nextProps;
|
|
3019
|
+
syncRuntimePageLayoutState(target, layout, nextProps);
|
|
3020
|
+
};
|
|
3021
|
+
}
|
|
2850
3022
|
/**
|
|
2851
3023
|
* 挂载运行时实例(框架内部注册流程使用)。
|
|
2852
3024
|
* @internal
|
|
@@ -2972,6 +3144,7 @@ function mountRuntimeInstance(target, runtimeApp, watchMap, setup, options) {
|
|
|
2972
3144
|
writable: false
|
|
2973
3145
|
});
|
|
2974
3146
|
target.__wevu = runtimeWithDefaults;
|
|
3147
|
+
attachPageLayoutSetter(target);
|
|
2975
3148
|
attachOwnerSnapshot(target, runtimeWithDefaults, ownerId);
|
|
2976
3149
|
if (watchMap) {
|
|
2977
3150
|
const stops = registerWatches(runtimeWithDefaults, watchMap, target);
|
|
@@ -3158,81 +3331,6 @@ function resolveComponentFeatures(options) {
|
|
|
3158
3331
|
};
|
|
3159
3332
|
}
|
|
3160
3333
|
//#endregion
|
|
3161
|
-
//#region src/runtime/register/component/lifecycle/platform.ts
|
|
3162
|
-
let wxPatched = false;
|
|
3163
|
-
let currentPageInstance;
|
|
3164
|
-
const PAGE_SCROLL_HOOK_DEPTH_KEY = "__wevuPageScrollHookDepth";
|
|
3165
|
-
function bindCurrentPageInstance(target) {
|
|
3166
|
-
currentPageInstance = target;
|
|
3167
|
-
}
|
|
3168
|
-
function releaseCurrentPageInstance(target) {
|
|
3169
|
-
if (currentPageInstance === target) currentPageInstance = void 0;
|
|
3170
|
-
}
|
|
3171
|
-
function runInPageScrollHook(target, task) {
|
|
3172
|
-
var _PAGE_SCROLL_HOOK_DEP;
|
|
3173
|
-
target[PAGE_SCROLL_HOOK_DEPTH_KEY] = Number((_PAGE_SCROLL_HOOK_DEP = target[PAGE_SCROLL_HOOK_DEPTH_KEY]) !== null && _PAGE_SCROLL_HOOK_DEP !== void 0 ? _PAGE_SCROLL_HOOK_DEP : 0) + 1;
|
|
3174
|
-
try {
|
|
3175
|
-
return task();
|
|
3176
|
-
} finally {
|
|
3177
|
-
var _PAGE_SCROLL_HOOK_DEP2;
|
|
3178
|
-
const nextDepth = Number((_PAGE_SCROLL_HOOK_DEP2 = target[PAGE_SCROLL_HOOK_DEPTH_KEY]) !== null && _PAGE_SCROLL_HOOK_DEP2 !== void 0 ? _PAGE_SCROLL_HOOK_DEP2 : 1) - 1;
|
|
3179
|
-
if (nextDepth <= 0) delete target[PAGE_SCROLL_HOOK_DEPTH_KEY];
|
|
3180
|
-
else target[PAGE_SCROLL_HOOK_DEPTH_KEY] = nextDepth;
|
|
3181
|
-
}
|
|
3182
|
-
}
|
|
3183
|
-
function resolvePageOptions(target) {
|
|
3184
|
-
const direct = target.options;
|
|
3185
|
-
if (direct && typeof direct === "object") return direct;
|
|
3186
|
-
if (typeof getCurrentPages === "function") {
|
|
3187
|
-
const pages = getCurrentPages();
|
|
3188
|
-
const page = Array.isArray(pages) ? pages.at(-1) : void 0;
|
|
3189
|
-
const options = page && typeof page === "object" ? page.options : void 0;
|
|
3190
|
-
if (options && typeof options === "object") return options;
|
|
3191
|
-
}
|
|
3192
|
-
return {};
|
|
3193
|
-
}
|
|
3194
|
-
function ensureWxPatched() {
|
|
3195
|
-
if (wxPatched) return;
|
|
3196
|
-
wxPatched = true;
|
|
3197
|
-
const wxGlobal = getMiniProgramGlobalObject();
|
|
3198
|
-
if (!wxGlobal || typeof wxGlobal !== "object") return;
|
|
3199
|
-
const rawStartPullDownRefresh = wxGlobal.startPullDownRefresh;
|
|
3200
|
-
if (typeof rawStartPullDownRefresh === "function") wxGlobal.startPullDownRefresh = function startPullDownRefreshPatched(...args) {
|
|
3201
|
-
const result = rawStartPullDownRefresh.apply(this, args);
|
|
3202
|
-
if (currentPageInstance) callHookList(currentPageInstance, "onPullDownRefresh", []);
|
|
3203
|
-
return result;
|
|
3204
|
-
};
|
|
3205
|
-
const rawPageScrollTo = wxGlobal.pageScrollTo;
|
|
3206
|
-
if (typeof rawPageScrollTo === "function") wxGlobal.pageScrollTo = function pageScrollToPatched(options, ...rest) {
|
|
3207
|
-
const result = rawPageScrollTo.apply(this, [options, ...rest]);
|
|
3208
|
-
if (currentPageInstance) {
|
|
3209
|
-
const pageInstance = currentPageInstance;
|
|
3210
|
-
runInPageScrollHook(pageInstance, () => {
|
|
3211
|
-
callHookList(pageInstance, "onPageScroll", [options !== null && options !== void 0 ? options : {}]);
|
|
3212
|
-
});
|
|
3213
|
-
}
|
|
3214
|
-
return result;
|
|
3215
|
-
};
|
|
3216
|
-
}
|
|
3217
|
-
function ensurePageShareMenus(options) {
|
|
3218
|
-
const { enableOnShareAppMessage, enableOnShareTimeline } = options;
|
|
3219
|
-
if (!enableOnShareAppMessage && !enableOnShareTimeline) return;
|
|
3220
|
-
const wxGlobal = getMiniProgramGlobalObject();
|
|
3221
|
-
if (!wxGlobal || typeof wxGlobal.showShareMenu !== "function") return;
|
|
3222
|
-
const showMenu = (payload) => {
|
|
3223
|
-
try {
|
|
3224
|
-
wxGlobal.showShareMenu(payload);
|
|
3225
|
-
} catch (_unused) {}
|
|
3226
|
-
};
|
|
3227
|
-
if (!(enableOnShareAppMessage || enableOnShareTimeline)) return;
|
|
3228
|
-
const menus = ["shareAppMessage"];
|
|
3229
|
-
if (enableOnShareTimeline) menus.push("shareTimeline");
|
|
3230
|
-
showMenu({
|
|
3231
|
-
withShareTicket: true,
|
|
3232
|
-
menus
|
|
3233
|
-
});
|
|
3234
|
-
}
|
|
3235
|
-
//#endregion
|
|
3236
3334
|
//#region src/runtime/register/component/lifecycle/optionalHooks.ts
|
|
3237
3335
|
function attachOptionalPageLifecycleHooks(pageLifecycleHooks, options) {
|
|
3238
3336
|
const { enableOnSaveExitState, enableOnPullDownRefresh, enableOnReachBottom, enableOnPageScroll, enableOnRouteDone, enableOnTabItemTap, enableOnResize, enableOnShareAppMessage, enableOnShareTimeline, enableOnAddToFavorites, effectiveOnSaveExitState, effectiveOnPullDownRefresh, effectiveOnReachBottom, effectiveOnPageScroll, effectiveOnRouteDone, effectiveOnTabItemTap, effectiveOnResize, effectiveOnShareAppMessage, effectiveOnShareTimeline, effectiveOnAddToFavorites, hasHook } = options;
|
|
@@ -3532,6 +3630,7 @@ function prepareComponentOptions(mpOptions) {
|
|
|
3532
3630
|
"definitionFilter",
|
|
3533
3631
|
"export",
|
|
3534
3632
|
"__wevuTemplateRefs",
|
|
3633
|
+
"__wevuLayoutHosts",
|
|
3535
3634
|
"setupLifecycle",
|
|
3536
3635
|
"features",
|
|
3537
3636
|
"__wevu_isPage"
|
|
@@ -3580,6 +3679,8 @@ function prepareComponentOptions(mpOptions) {
|
|
|
3580
3679
|
}
|
|
3581
3680
|
const templateRefs = restOptions.__wevuTemplateRefs;
|
|
3582
3681
|
delete restOptions.__wevuTemplateRefs;
|
|
3682
|
+
const layoutHosts = restOptions.__wevuLayoutHosts;
|
|
3683
|
+
delete restOptions.__wevuLayoutHosts;
|
|
3583
3684
|
const userObservers = restOptions.observers;
|
|
3584
3685
|
const setupLifecycle = restOptions.setupLifecycle === "created" ? "created" : "attached";
|
|
3585
3686
|
delete restOptions.setupLifecycle;
|
|
@@ -3599,6 +3700,7 @@ function prepareComponentOptions(mpOptions) {
|
|
|
3599
3700
|
restOptions,
|
|
3600
3701
|
topLevelMethods,
|
|
3601
3702
|
templateRefs,
|
|
3703
|
+
layoutHosts,
|
|
3602
3704
|
userObservers,
|
|
3603
3705
|
setupLifecycle,
|
|
3604
3706
|
legacyCreated,
|
|
@@ -3742,72 +3844,233 @@ function createPropsSync(options) {
|
|
|
3742
3844
|
};
|
|
3743
3845
|
}
|
|
3744
3846
|
//#endregion
|
|
3745
|
-
//#region src/runtime/
|
|
3746
|
-
const
|
|
3747
|
-
const
|
|
3847
|
+
//#region src/runtime/layoutBridge.ts
|
|
3848
|
+
const pageLayoutBridges = /* @__PURE__ */ new Map();
|
|
3849
|
+
const layoutBridgePageKeys = "__wevuLayoutBridgePageKeys";
|
|
3850
|
+
const LEADING_SLASH_RE = /^\/+/;
|
|
3748
3851
|
function resolveCurrentPageInstance() {
|
|
3749
3852
|
const getCurrentPagesFn = globalThis.getCurrentPages;
|
|
3750
3853
|
if (typeof getCurrentPagesFn !== "function") return;
|
|
3751
3854
|
return getCurrentPagesFn().at(-1);
|
|
3752
3855
|
}
|
|
3753
|
-
function
|
|
3754
|
-
return
|
|
3856
|
+
function normalizeSelectors(selectors) {
|
|
3857
|
+
return Array.from(new Set(Array.isArray(selectors) ? selectors : [selectors])).filter((selector) => typeof selector === "string" && selector.length > 0);
|
|
3858
|
+
}
|
|
3859
|
+
function resolvePageKeys(page) {
|
|
3860
|
+
const keys = [];
|
|
3861
|
+
if (!page || typeof page !== "object") return keys;
|
|
3862
|
+
const webviewId = page.__wxWebviewId__;
|
|
3863
|
+
if (typeof webviewId === "number" || typeof webviewId === "string") keys.push(`webview:${String(webviewId)}`);
|
|
3864
|
+
const exparserNodeId = page.__wxExparserNodeId__;
|
|
3865
|
+
if (typeof exparserNodeId === "number" || typeof exparserNodeId === "string") keys.push(`exparser:${String(exparserNodeId)}`);
|
|
3866
|
+
const route = typeof page.route === "string" ? page.route.replace(LEADING_SLASH_RE, "") : "";
|
|
3867
|
+
if (route) keys.push(`route:${route}`);
|
|
3868
|
+
return Array.from(new Set(keys));
|
|
3869
|
+
}
|
|
3870
|
+
function resolvePageFromContext(context) {
|
|
3871
|
+
if (context && typeof context.__wevuSetPageLayout === "function") return context;
|
|
3872
|
+
return resolveCurrentPageInstance();
|
|
3873
|
+
}
|
|
3874
|
+
function resolveNativeLayoutContext(context) {
|
|
3875
|
+
var _context$__wevu, _context$$state;
|
|
3876
|
+
if (!context || typeof context !== "object") return;
|
|
3877
|
+
const runtimeNativeInstance = (_context$__wevu = context.__wevu) === null || _context$__wevu === void 0 || (_context$__wevu = _context$__wevu.state) === null || _context$__wevu === void 0 ? void 0 : _context$__wevu.__wevuNativeInstance;
|
|
3878
|
+
if (runtimeNativeInstance && typeof runtimeNativeInstance === "object") return runtimeNativeInstance;
|
|
3879
|
+
const stateNativeInstance = (_context$$state = context.$state) === null || _context$$state === void 0 ? void 0 : _context$$state.__wevuNativeInstance;
|
|
3880
|
+
if (stateNativeInstance && typeof stateNativeInstance === "object") return stateNativeInstance;
|
|
3881
|
+
if (context.__wevuNativeInstance && typeof context.__wevuNativeInstance === "object") return context.__wevuNativeInstance;
|
|
3882
|
+
return context;
|
|
3883
|
+
}
|
|
3884
|
+
function resolveHostEntry(entry) {
|
|
3885
|
+
if (typeof entry === "function") return entry();
|
|
3886
|
+
if (isRef(entry)) return entry.value;
|
|
3887
|
+
return entry;
|
|
3888
|
+
}
|
|
3889
|
+
function findLayoutHostBinding(bindings, key) {
|
|
3890
|
+
return bindings.find((binding) => binding.key === key);
|
|
3891
|
+
}
|
|
3892
|
+
function safeSelectComponent(target, selector) {
|
|
3893
|
+
const selectComponent = target === null || target === void 0 ? void 0 : target.selectComponent;
|
|
3894
|
+
if (typeof selectComponent !== "function") return null;
|
|
3895
|
+
try {
|
|
3896
|
+
var _selectComponent$call;
|
|
3897
|
+
return (_selectComponent$call = selectComponent.call(target, selector)) !== null && _selectComponent$call !== void 0 ? _selectComponent$call : null;
|
|
3898
|
+
} catch (_unused) {
|
|
3899
|
+
return null;
|
|
3900
|
+
}
|
|
3901
|
+
}
|
|
3902
|
+
function resolveDeclaredLayoutHostFromRefs(binding, context) {
|
|
3903
|
+
var _ref, _context$__wevu$state, _context$__wevu2, _context$$state2, _refMap$get$value, _refMap$get;
|
|
3904
|
+
if (!binding.refName) return null;
|
|
3905
|
+
const refMap = getTemplateRefMap(context);
|
|
3906
|
+
const stateRefs = (_ref = (_context$__wevu$state = (_context$__wevu2 = context.__wevu) === null || _context$__wevu2 === void 0 || (_context$__wevu2 = _context$__wevu2.state) === null || _context$__wevu2 === void 0 ? void 0 : _context$__wevu2.$refs) !== null && _context$__wevu$state !== void 0 ? _context$__wevu$state : (_context$$state2 = context.$state) === null || _context$$state2 === void 0 ? void 0 : _context$$state2.$refs) !== null && _ref !== void 0 ? _ref : context.$refs;
|
|
3907
|
+
const refValue = (_refMap$get$value = refMap === null || refMap === void 0 || (_refMap$get = refMap.get(binding.refName)) === null || _refMap$get === void 0 ? void 0 : _refMap$get.value) !== null && _refMap$get$value !== void 0 ? _refMap$get$value : stateRefs === null || stateRefs === void 0 ? void 0 : stateRefs[binding.refName];
|
|
3908
|
+
if (Array.isArray(refValue)) {
|
|
3909
|
+
var _refValue$;
|
|
3910
|
+
return (_refValue$ = refValue[0]) !== null && _refValue$ !== void 0 ? _refValue$ : null;
|
|
3911
|
+
}
|
|
3912
|
+
return refValue !== null && refValue !== void 0 ? refValue : null;
|
|
3913
|
+
}
|
|
3914
|
+
function createDeclaredLayoutHostBridge(bindings, context) {
|
|
3915
|
+
const nativeContext = resolveNativeLayoutContext(context);
|
|
3916
|
+
const bridgeBase = nativeContext && typeof nativeContext === "object" ? Object.create(nativeContext) : {};
|
|
3917
|
+
return Object.assign(bridgeBase, { selectComponent(key) {
|
|
3918
|
+
const binding = findLayoutHostBinding(bindings, key);
|
|
3919
|
+
if (!binding) return null;
|
|
3920
|
+
if (binding.kind === "component" || !binding.kind) {
|
|
3921
|
+
var _ref2, _safeSelectComponent;
|
|
3922
|
+
const cachedHost = resolveDeclaredLayoutHostFromRefs(binding, context);
|
|
3923
|
+
if (cachedHost) return cachedHost;
|
|
3924
|
+
return (_ref2 = (_safeSelectComponent = safeSelectComponent(nativeContext, binding.selector)) !== null && _safeSelectComponent !== void 0 ? _safeSelectComponent : safeSelectComponent(resolveCurrentPageInstance(), binding.selector)) !== null && _ref2 !== void 0 ? _ref2 : null;
|
|
3925
|
+
}
|
|
3926
|
+
return null;
|
|
3927
|
+
} });
|
|
3755
3928
|
}
|
|
3756
3929
|
/**
|
|
3757
|
-
*
|
|
3930
|
+
* 为当前页面注册 layout bridge,使页面或子组件可消费 layout 内部能力。
|
|
3758
3931
|
*/
|
|
3759
|
-
function
|
|
3760
|
-
|
|
3761
|
-
|
|
3762
|
-
const
|
|
3763
|
-
|
|
3764
|
-
const
|
|
3765
|
-
|
|
3766
|
-
|
|
3932
|
+
function registerPageLayoutBridge(selectors, context) {
|
|
3933
|
+
const bridgeContext = context !== null && context !== void 0 ? context : getCurrentInstance();
|
|
3934
|
+
const page = resolvePageFromContext(bridgeContext);
|
|
3935
|
+
const pageKeys = resolvePageKeys(page);
|
|
3936
|
+
if (!bridgeContext || !page || pageKeys.length === 0) return false;
|
|
3937
|
+
for (const pageKey of pageKeys) {
|
|
3938
|
+
var _pageLayoutBridges$ge;
|
|
3939
|
+
const registry = (_pageLayoutBridges$ge = pageLayoutBridges.get(pageKey)) !== null && _pageLayoutBridges$ge !== void 0 ? _pageLayoutBridges$ge : /* @__PURE__ */ new Map();
|
|
3940
|
+
for (const selector of normalizeSelectors(selectors)) registry.set(selector, bridgeContext);
|
|
3941
|
+
pageLayoutBridges.set(pageKey, registry);
|
|
3942
|
+
}
|
|
3943
|
+
bridgeContext[layoutBridgePageKeys] = pageKeys;
|
|
3944
|
+
return true;
|
|
3945
|
+
}
|
|
3946
|
+
/**
|
|
3947
|
+
* 移除当前页面的 layout bridge 注册。
|
|
3948
|
+
*/
|
|
3949
|
+
function unregisterPageLayoutBridge(selectors, context) {
|
|
3950
|
+
var _bridgeContext$layout;
|
|
3951
|
+
const bridgeContext = context !== null && context !== void 0 ? context : getCurrentInstance();
|
|
3952
|
+
const page = resolvePageFromContext(bridgeContext);
|
|
3953
|
+
const pageKeys = (_bridgeContext$layout = bridgeContext === null || bridgeContext === void 0 ? void 0 : bridgeContext[layoutBridgePageKeys]) !== null && _bridgeContext$layout !== void 0 ? _bridgeContext$layout : resolvePageKeys(page);
|
|
3954
|
+
if (!bridgeContext || !Array.isArray(pageKeys) || pageKeys.length === 0) return false;
|
|
3955
|
+
let removed = false;
|
|
3956
|
+
for (const pageKey of pageKeys) {
|
|
3957
|
+
const registry = pageLayoutBridges.get(pageKey);
|
|
3958
|
+
if (!registry) continue;
|
|
3959
|
+
for (const selector of normalizeSelectors(selectors)) if (registry.get(selector) === bridgeContext) {
|
|
3960
|
+
registry.delete(selector);
|
|
3961
|
+
removed = true;
|
|
3962
|
+
}
|
|
3963
|
+
if (registry.size === 0) pageLayoutBridges.delete(pageKey);
|
|
3964
|
+
}
|
|
3965
|
+
delete bridgeContext[layoutBridgePageKeys];
|
|
3966
|
+
return removed;
|
|
3967
|
+
}
|
|
3968
|
+
/**
|
|
3969
|
+
* 解析当前页面已注册的 layout bridge,找不到时回退到传入上下文。
|
|
3970
|
+
*/
|
|
3971
|
+
function resolveLayoutBridge(selector, fallbackContext) {
|
|
3972
|
+
var _resolveCurrentPageIn, _ref3;
|
|
3973
|
+
const bridgeContext = resolvePageKeys((_resolveCurrentPageIn = resolveCurrentPageInstance()) !== null && _resolveCurrentPageIn !== void 0 ? _resolveCurrentPageIn : resolvePageFromContext(fallbackContext)).map((pageKey) => {
|
|
3974
|
+
var _pageLayoutBridges$ge2;
|
|
3975
|
+
return (_pageLayoutBridges$ge2 = pageLayoutBridges.get(pageKey)) === null || _pageLayoutBridges$ge2 === void 0 ? void 0 : _pageLayoutBridges$ge2.get(selector);
|
|
3976
|
+
}).find(Boolean);
|
|
3977
|
+
return (_ref3 = bridgeContext !== null && bridgeContext !== void 0 ? bridgeContext : fallbackContext) !== null && _ref3 !== void 0 ? _ref3 : getCurrentInstance();
|
|
3978
|
+
}
|
|
3979
|
+
/**
|
|
3980
|
+
* 解析当前页面 layout 内通过指定 key 暴露的宿主实例。
|
|
3981
|
+
*/
|
|
3982
|
+
function resolveLayoutHost(key, options = {}) {
|
|
3983
|
+
var _options$context, _bridge$selectCompone;
|
|
3984
|
+
const bridge = resolveLayoutBridge(key, (_options$context = options.context) !== null && _options$context !== void 0 ? _options$context : options.fallbackContext);
|
|
3985
|
+
const host = bridge === null || bridge === void 0 || (_bridge$selectCompone = bridge.selectComponent) === null || _bridge$selectCompone === void 0 ? void 0 : _bridge$selectCompone.call(bridge, key);
|
|
3986
|
+
return host !== null && host !== void 0 ? host : null;
|
|
3987
|
+
}
|
|
3988
|
+
/**
|
|
3989
|
+
* 等待当前页面 layout 宿主实例可用,适合页面初次进入时的异步宿主解析。
|
|
3990
|
+
*/
|
|
3991
|
+
function waitForLayoutHost(key, options = {}) {
|
|
3992
|
+
var _options$retries, _options$interval;
|
|
3993
|
+
const retries = (_options$retries = options.retries) !== null && _options$retries !== void 0 ? _options$retries : 20;
|
|
3994
|
+
const interval = (_options$interval = options.interval) !== null && _options$interval !== void 0 ? _options$interval : 16;
|
|
3995
|
+
const host = resolveLayoutHost(key, options);
|
|
3996
|
+
if (host || retries <= 0) return Promise.resolve(host);
|
|
3997
|
+
return new Promise((resolve) => {
|
|
3998
|
+
setTimeout(() => {
|
|
3999
|
+
resolve(waitForLayoutHost(key, {
|
|
4000
|
+
...options,
|
|
4001
|
+
retries: retries - 1
|
|
4002
|
+
}));
|
|
4003
|
+
}, interval);
|
|
3767
4004
|
});
|
|
3768
|
-
if (currentInstance) currentInstance.__wevuPageLayoutState = pageLayoutState;
|
|
3769
|
-
return readonly(pageLayoutState);
|
|
3770
4005
|
}
|
|
3771
|
-
|
|
3772
|
-
|
|
3773
|
-
|
|
3774
|
-
|
|
3775
|
-
|
|
4006
|
+
/**
|
|
4007
|
+
* 在 layout 生命周期内暴露 bridge,使页面或子组件可访问 layout 内部实例。
|
|
4008
|
+
*/
|
|
4009
|
+
function useLayoutBridge(selectors, options = {}) {
|
|
4010
|
+
if (!getCurrentSetupContext()) throw new Error("useLayoutBridge() 必须在 setup() 的同步阶段调用");
|
|
4011
|
+
const context = getCurrentInstance();
|
|
4012
|
+
const normalizedSelectors = normalizeSelectors(selectors);
|
|
4013
|
+
const resolveComponent = options.resolveComponent;
|
|
4014
|
+
const nativeContext = resolveNativeLayoutContext(context);
|
|
4015
|
+
const bridgeBase = nativeContext && typeof nativeContext === "object" ? Object.create(nativeContext) : {};
|
|
4016
|
+
const bridge = Object.assign(bridgeBase, { selectComponent(selector) {
|
|
4017
|
+
var _nativeContext$select, _currentPage$selectCo, _currentPage$selectCo2;
|
|
4018
|
+
if (!normalizedSelectors.includes(selector)) return null;
|
|
4019
|
+
const resolvedComponent = resolveComponent === null || resolveComponent === void 0 ? void 0 : resolveComponent(selector);
|
|
4020
|
+
if (resolvedComponent !== void 0) return resolvedComponent;
|
|
4021
|
+
const nativeContext = resolveNativeLayoutContext(context);
|
|
4022
|
+
const directMatch = nativeContext === null || nativeContext === void 0 || (_nativeContext$select = nativeContext.selectComponent) === null || _nativeContext$select === void 0 ? void 0 : _nativeContext$select.call(nativeContext, selector);
|
|
4023
|
+
if (directMatch) return directMatch;
|
|
4024
|
+
const currentPage = resolveCurrentPageInstance();
|
|
4025
|
+
return (_currentPage$selectCo = currentPage === null || currentPage === void 0 || (_currentPage$selectCo2 = currentPage.selectComponent) === null || _currentPage$selectCo2 === void 0 ? void 0 : _currentPage$selectCo2.call(currentPage, selector)) !== null && _currentPage$selectCo !== void 0 ? _currentPage$selectCo : null;
|
|
4026
|
+
} });
|
|
4027
|
+
registerPageLayoutBridge(normalizedSelectors, bridge);
|
|
4028
|
+
onAttached(() => {
|
|
4029
|
+
registerPageLayoutBridge(normalizedSelectors, bridge);
|
|
4030
|
+
});
|
|
4031
|
+
onDetached(() => {
|
|
4032
|
+
unregisterPageLayoutBridge(normalizedSelectors, bridge);
|
|
4033
|
+
});
|
|
3776
4034
|
}
|
|
3777
|
-
|
|
3778
|
-
|
|
3779
|
-
|
|
3780
|
-
|
|
3781
|
-
if (!
|
|
3782
|
-
|
|
3783
|
-
|
|
4035
|
+
/**
|
|
4036
|
+
* 使用编译期注入的宿主绑定信息,直接从当前 layout 运行时实例解析子组件宿主并注册 bridge。
|
|
4037
|
+
*/
|
|
4038
|
+
function registerRuntimeLayoutHosts(bindings, context) {
|
|
4039
|
+
if (!bindings.length) return null;
|
|
4040
|
+
const bridgeContext = context !== null && context !== void 0 ? context : getCurrentInstance();
|
|
4041
|
+
if (!bridgeContext) return null;
|
|
4042
|
+
const bridge = createDeclaredLayoutHostBridge(bindings, bridgeContext);
|
|
4043
|
+
registerPageLayoutBridge(bindings.map((binding) => binding.key), bridge);
|
|
4044
|
+
return bridge;
|
|
3784
4045
|
}
|
|
3785
4046
|
/**
|
|
3786
|
-
*
|
|
4047
|
+
* 移除运行时自动注册的 layout 宿主 bridge。
|
|
3787
4048
|
*/
|
|
3788
|
-
function
|
|
3789
|
-
|
|
3790
|
-
const
|
|
3791
|
-
if (
|
|
3792
|
-
|
|
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()、事件回调或当前页面上下文中调用。");
|
|
4049
|
+
function unregisterRuntimeLayoutHosts(bindings, context) {
|
|
4050
|
+
if (!bindings.length) return false;
|
|
4051
|
+
const bridgeContext = context !== null && context !== void 0 ? context : getCurrentInstance();
|
|
4052
|
+
if (!bridgeContext) return false;
|
|
4053
|
+
return unregisterPageLayoutBridge(bindings.map((binding) => binding.key), bridgeContext);
|
|
3802
4054
|
}
|
|
3803
|
-
|
|
3804
|
-
|
|
4055
|
+
/**
|
|
4056
|
+
* 使用 key -> 宿主实例的映射批量暴露 layout 内部宿主,适合 toast/dialog 等共享反馈节点。
|
|
4057
|
+
*/
|
|
4058
|
+
function useLayoutHosts(hosts) {
|
|
4059
|
+
useLayoutBridge(Object.keys(hosts), { resolveComponent(key) {
|
|
4060
|
+
return resolveHostEntry(hosts[key]);
|
|
4061
|
+
} });
|
|
3805
4062
|
}
|
|
3806
4063
|
//#endregion
|
|
3807
4064
|
//#region src/runtime/register/component/registerDefinition.ts
|
|
3808
4065
|
function registerComponentDefinition(options) {
|
|
3809
|
-
const { runtimeApp, watch, setup, restOptions, pageLifecycleHooks, finalObservers, userLifetimes, userPageLifetimes, finalMethods, finalOptions, applyExtraInstanceFields, templateRefs, attachWevuPropKeys, setupLifecycle, syncWevuPropsFromInstance, isPage, legacyCreated, getRuntimeOwnerLabel } = options;
|
|
4066
|
+
const { runtimeApp, watch, setup, restOptions, pageLifecycleHooks, finalObservers, userLifetimes, userPageLifetimes, finalMethods, finalOptions, applyExtraInstanceFields, templateRefs, layoutHosts, attachWevuPropKeys, setupLifecycle, syncWevuPropsFromInstance, isPage, legacyCreated, getRuntimeOwnerLabel } = options;
|
|
3810
4067
|
const pageShareMethodBridges = {};
|
|
4068
|
+
const attachRuntimeLayoutHosts = (instance) => {
|
|
4069
|
+
if (!Array.isArray(layoutHosts) || !layoutHosts.length) return;
|
|
4070
|
+
if (instance.__wevuLayoutHostBridge) return;
|
|
4071
|
+
const bridge = registerRuntimeLayoutHosts(layoutHosts, instance);
|
|
4072
|
+
if (bridge) instance.__wevuLayoutHostBridge = bridge;
|
|
4073
|
+
};
|
|
3811
4074
|
const attachPageLayoutSetter = (instance) => {
|
|
3812
4075
|
if (!isPage) return;
|
|
3813
4076
|
instance.__wevuSetPageLayout = (layout, props) => {
|
|
@@ -3881,6 +4144,7 @@ function registerComponentDefinition(options) {
|
|
|
3881
4144
|
}
|
|
3882
4145
|
syncWevuPropsFromInstance(this);
|
|
3883
4146
|
attachPageLayoutSetter(this);
|
|
4147
|
+
attachRuntimeLayoutHosts(this);
|
|
3884
4148
|
if (setupLifecycle === "created") enableDeferredSetData(this);
|
|
3885
4149
|
callHookList(this, "onAttached", args);
|
|
3886
4150
|
if (typeof userLifetimes.attached === "function") userLifetimes.attached.apply(this, args);
|
|
@@ -3910,6 +4174,10 @@ function registerComponentDefinition(options) {
|
|
|
3910
4174
|
return;
|
|
3911
4175
|
}
|
|
3912
4176
|
clearTemplateRefs(this);
|
|
4177
|
+
if (Array.isArray(layoutHosts) && layoutHosts.length && this.__wevuLayoutHostBridge) {
|
|
4178
|
+
unregisterRuntimeLayoutHosts(layoutHosts, this.__wevuLayoutHostBridge);
|
|
4179
|
+
delete this.__wevuLayoutHostBridge;
|
|
4180
|
+
}
|
|
3913
4181
|
teardownRuntimeInstance(this);
|
|
3914
4182
|
if (typeof userLifetimes.detached === "function") userLifetimes.detached.apply(this, args);
|
|
3915
4183
|
},
|
|
@@ -3974,7 +4242,7 @@ function registerComponentDefinition(options) {
|
|
|
3974
4242
|
*/
|
|
3975
4243
|
function registerComponent(runtimeApp, methods, watch, setup, mpOptions) {
|
|
3976
4244
|
var _multipleSlots;
|
|
3977
|
-
const { userMethods, userLifetimes, userPageLifetimes, userOptions, restOptions, topLevelMethods, templateRefs, userObservers, setupLifecycle, legacyCreated, isPage, features, userOnLoad, userOnUnload, userOnShow, userOnHide, userOnReady, userOnSaveExitState, userOnPullDownRefresh, userOnReachBottom, userOnPageScroll, userOnRouteDone, userOnTabItemTap, userOnResize, userOnShareAppMessage, userOnShareTimeline, userOnAddToFavorites, applyExtraInstanceFields } = prepareComponentOptions(mpOptions);
|
|
4245
|
+
const { userMethods, userLifetimes, userPageLifetimes, userOptions, restOptions, topLevelMethods, templateRefs, layoutHosts, userObservers, setupLifecycle, legacyCreated, isPage, features, userOnLoad, userOnUnload, userOnShow, userOnHide, userOnReady, userOnSaveExitState, userOnPullDownRefresh, userOnReachBottom, userOnPageScroll, userOnRouteDone, userOnTabItemTap, userOnResize, userOnShareAppMessage, userOnShareTimeline, userOnAddToFavorites, applyExtraInstanceFields } = prepareComponentOptions(mpOptions);
|
|
3978
4246
|
const { enableOnPullDownRefresh, enableOnReachBottom, enableOnPageScroll, enableOnRouteDone, enableOnRouteDoneFallback, enableOnTabItemTap, enableOnResize, enableOnShareAppMessage, enableOnShareTimeline, enableOnAddToFavorites, enableOnSaveExitState, effectiveOnSaveExitState, effectiveOnPullDownRefresh, effectiveOnReachBottom, effectiveOnPageScroll, effectiveOnRouteDone, effectiveOnTabItemTap, effectiveOnResize, effectiveOnShareAppMessage, effectiveOnShareTimeline, effectiveOnAddToFavorites } = resolveComponentFeatures({
|
|
3979
4247
|
features,
|
|
3980
4248
|
userOnSaveExitState,
|
|
@@ -4069,6 +4337,7 @@ function registerComponent(runtimeApp, methods, watch, setup, mpOptions) {
|
|
|
4069
4337
|
finalOptions,
|
|
4070
4338
|
applyExtraInstanceFields,
|
|
4071
4339
|
templateRefs,
|
|
4340
|
+
layoutHosts,
|
|
4072
4341
|
attachWevuPropKeys,
|
|
4073
4342
|
setupLifecycle,
|
|
4074
4343
|
syncWevuPropsFromInstance,
|
|
@@ -4990,4 +5259,4 @@ function useTemplateRef(name) {
|
|
|
4990
5259
|
return target;
|
|
4991
5260
|
}
|
|
4992
5261
|
//#endregion
|
|
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 };
|
|
5262
|
+
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, registerPageLayoutBridge, registerRuntimeLayoutHosts, removeMutationRecorder, resetWevuDefaults, resolveLayoutBridge, resolveLayoutHost, 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, unregisterPageLayoutBridge, unregisterRuntimeLayoutHosts, useAttrs, useBindModel, useDisposables, useIntersectionObserver, useLayoutBridge, useLayoutHosts, useModel, useNativeInstance, useNativePageRouter, useNativeRouter, usePageLayout, usePageScrollThrottle, useSlots, useTemplateRef, useUpdatePerformanceListener, waitForLayoutHost, watch, watchEffect };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wevu",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "6.11.
|
|
4
|
+
"version": "6.11.4",
|
|
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.11.
|
|
99
|
+
"@wevu/compiler": "6.11.4"
|
|
100
100
|
},
|
|
101
101
|
"scripts": {
|
|
102
102
|
"dev": "tsdown -w",
|