wevu 0.0.1 → 1.0.0-alpha.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 +119 -0
- package/dist/index-0dF4y5p6.d.mts +80 -0
- package/dist/index-DVEFI-Uo.d.cts +80 -0
- package/dist/index.cjs +525 -154
- package/dist/index.d.cts +397 -54
- package/dist/index.d.mts +397 -54
- package/dist/index.mjs +465 -119
- package/dist/store-BcU7YVhB.mjs +638 -0
- package/dist/store-Cmw9vWBT.cjs +764 -0
- package/dist/store.cjs +4 -246
- package/dist/store.d.cts +2 -69
- package/dist/store.d.mts +2 -69
- package/dist/store.mjs +1 -243
- package/package.json +24 -16
- package/dist/ref-0isFdYQ8.d.cts +0 -9
- package/dist/ref-BHYwO374.d.mts +0 -9
- package/dist/ref-DS-k2oUF.mjs +0 -271
- package/dist/ref-DtCdcykK.cjs +0 -349
package/dist/index.d.mts
CHANGED
|
@@ -1,33 +1,36 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as DefineStoreOptions, c as SubscriptionCallback, d as ref, f as unref, i as ActionSubscriber, l as Ref, n as createStore, o as MutationType, r as defineStore, s as StoreManager, t as storeToRefs, u as isRef } from "./index-0dF4y5p6.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/reactivity/computed.d.ts
|
|
4
|
-
type ComputedGetter<T> = () => T;
|
|
5
|
-
type ComputedSetter<T> = (value: T) => void;
|
|
6
|
-
interface
|
|
7
|
-
|
|
4
|
+
type ComputedGetter<T$1> = () => T$1;
|
|
5
|
+
type ComputedSetter<T$1> = (value: T$1) => void;
|
|
6
|
+
interface BaseComputedRef<T$1, S = T$1> extends Ref<T$1, S> {
|
|
7
|
+
[key: symbol]: any;
|
|
8
8
|
}
|
|
9
|
-
interface
|
|
10
|
-
value: T;
|
|
9
|
+
interface ComputedRef<T$1 = any> extends BaseComputedRef<T$1> {
|
|
10
|
+
readonly value: T$1;
|
|
11
11
|
}
|
|
12
|
-
interface
|
|
13
|
-
|
|
14
|
-
set: ComputedSetter<T>;
|
|
12
|
+
interface WritableComputedRef<T$1, S = T$1> extends BaseComputedRef<T$1, S> {
|
|
13
|
+
value: T$1;
|
|
15
14
|
}
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
interface WritableComputedOptions<T$1> {
|
|
16
|
+
get: ComputedGetter<T$1>;
|
|
17
|
+
set: ComputedSetter<T$1>;
|
|
18
|
+
}
|
|
19
|
+
declare function computed<T$1>(getter: ComputedGetter<T$1>): ComputedRef<T$1>;
|
|
20
|
+
declare function computed<T$1>(options: WritableComputedOptions<T$1>): WritableComputedRef<T$1>;
|
|
18
21
|
//#endregion
|
|
19
22
|
//#region src/scheduler.d.ts
|
|
20
|
-
declare function nextTick<T>(fn?: () => T): Promise<T>;
|
|
23
|
+
declare function nextTick<T$1>(fn?: () => T$1): Promise<T$1>;
|
|
21
24
|
//#endregion
|
|
22
25
|
//#region src/reactivity/core.d.ts
|
|
23
26
|
type EffectScheduler = () => void;
|
|
24
27
|
type Dep = Set<ReactiveEffect>;
|
|
25
|
-
interface ReactiveEffect<T = any> {
|
|
26
|
-
(): T;
|
|
28
|
+
interface ReactiveEffect<T$1 = any> {
|
|
29
|
+
(): T$1;
|
|
27
30
|
deps: Dep[];
|
|
28
31
|
scheduler?: EffectScheduler;
|
|
29
32
|
active: boolean;
|
|
30
|
-
_fn: () => T;
|
|
33
|
+
_fn: () => T$1;
|
|
31
34
|
onStop?: () => void;
|
|
32
35
|
}
|
|
33
36
|
interface EffectOptions {
|
|
@@ -35,27 +38,144 @@ interface EffectOptions {
|
|
|
35
38
|
lazy?: boolean;
|
|
36
39
|
onStop?: () => void;
|
|
37
40
|
}
|
|
38
|
-
declare function effect<T = any>(fn: () => T, options?: EffectOptions): ReactiveEffect<T>;
|
|
41
|
+
declare function effect<T$1 = any>(fn: () => T$1, options?: EffectOptions): ReactiveEffect<T$1>;
|
|
39
42
|
declare function stop(runner: ReactiveEffect): void;
|
|
40
43
|
//#endregion
|
|
41
44
|
//#region src/reactivity/reactive.d.ts
|
|
42
|
-
declare function reactive<T extends object>(target: T): T;
|
|
45
|
+
declare function reactive<T$1 extends object>(target: T$1): T$1;
|
|
43
46
|
declare function isReactive(value: unknown): boolean;
|
|
44
|
-
declare function toRaw<T>(observed: T): T;
|
|
47
|
+
declare function toRaw<T$1>(observed: T$1): T$1;
|
|
45
48
|
/**
|
|
46
49
|
* Establish a dependency on the whole reactive object "version".
|
|
47
|
-
*
|
|
50
|
+
* 让 effect 订阅整个对象的“版本号”,无需深度遍历即可对任何字段变化做出响应。
|
|
48
51
|
*/
|
|
49
52
|
declare function touchReactive(target: object): void;
|
|
53
|
+
/**
|
|
54
|
+
* 创建一个浅层响应式代理:仅跟踪第一层属性变更,不深度递归嵌套对象。
|
|
55
|
+
*
|
|
56
|
+
* @param target 待转换的对象
|
|
57
|
+
* @returns 浅层响应式代理
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* const state = shallowReactive({ nested: { count: 0 } })
|
|
62
|
+
*
|
|
63
|
+
* state.nested.count++ // 不会触发 effect(嵌套对象未深度代理)
|
|
64
|
+
* state.nested = { count: 1 } // 会触发 effect(顶层属性变更)
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
declare function shallowReactive<T$1 extends object>(target: T$1): T$1;
|
|
68
|
+
/**
|
|
69
|
+
* Checks if a value is a shallow reactive object
|
|
70
|
+
*/
|
|
71
|
+
declare function isShallowReactive(value: unknown): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* 标记对象为“原始”状态,后续不会被转换为响应式,返回原对象本身。
|
|
74
|
+
*
|
|
75
|
+
* @param value 需要标记的对象
|
|
76
|
+
* @returns 带有跳过标记的原对象
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```ts
|
|
80
|
+
* const foo = markRaw({
|
|
81
|
+
* nested: {}
|
|
82
|
+
* })
|
|
83
|
+
*
|
|
84
|
+
* const state = reactive({
|
|
85
|
+
* foo
|
|
86
|
+
* })
|
|
87
|
+
*
|
|
88
|
+
* state.foo // 不是响应式对象
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
declare function markRaw<T$1 extends object>(value: T$1): T$1;
|
|
92
|
+
/**
|
|
93
|
+
* 判断某个值是否被标记为原始(即不应转换为响应式)。
|
|
94
|
+
*
|
|
95
|
+
* @param value 待检测的值
|
|
96
|
+
* @returns 若含有跳过标记则返回 true
|
|
97
|
+
*/
|
|
98
|
+
declare function isRaw(value: unknown): boolean;
|
|
50
99
|
//#endregion
|
|
51
100
|
//#region src/reactivity/readonly.d.ts
|
|
52
101
|
/**
|
|
53
|
-
* readonly
|
|
54
|
-
*
|
|
55
|
-
*
|
|
102
|
+
* readonly 会为对象/数组创建一个“浅层”只读代理,并为 Ref 创建只读包装。
|
|
103
|
+
* 选择浅层而非深层递归,是为了在小程序环境中保持实现和运行时开销最小,
|
|
104
|
+
* 仅阻止直接属性写入/删除,嵌套对象仍按原样透传。
|
|
105
|
+
*/
|
|
106
|
+
declare function readonly<T$1 extends object>(target: T$1): T$1;
|
|
107
|
+
declare function readonly<T$1>(target: Ref<T$1>): Readonly<Ref<T$1>>;
|
|
108
|
+
//#endregion
|
|
109
|
+
//#region src/reactivity/shallowRef.d.ts
|
|
110
|
+
/**
|
|
111
|
+
* 创建一个“浅层” ref:它只在 .value 被整体替换时触发依赖,不会对内部对象做深层响应式处理。
|
|
112
|
+
*
|
|
113
|
+
* @param value 初始值
|
|
114
|
+
* @param defaultValue 传递给 customRef 的默认值,可用于兜底
|
|
115
|
+
* @returns 仅跟踪自身 .value 变更的浅层 ref
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```ts
|
|
119
|
+
* const state = shallowRef({ count: 0 })
|
|
120
|
+
* state.value = { count: 1 } // 会触发依赖
|
|
121
|
+
* state.value.count++ // 不会触发依赖(内部属性未被深度代理)
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
declare function shallowRef<T$1>(value: T$1): Ref<T$1>;
|
|
125
|
+
declare function shallowRef<T$1>(value: T$1, defaultValue: T$1): Ref<T$1>;
|
|
126
|
+
/**
|
|
127
|
+
* 判断传入值是否为浅层 ref。
|
|
128
|
+
*
|
|
129
|
+
* @param r 待判断的值
|
|
130
|
+
* @returns 若为浅层 ref 则返回 true
|
|
131
|
+
*/
|
|
132
|
+
declare function isShallowRef(r: any): r is Ref<any>;
|
|
133
|
+
/**
|
|
134
|
+
* 主动触发一次浅层 ref 的更新(无需深度比较)。
|
|
135
|
+
*
|
|
136
|
+
* @param ref 需要触发的 ref
|
|
56
137
|
*/
|
|
57
|
-
declare function
|
|
58
|
-
|
|
138
|
+
declare function triggerRef<T$1>(ref: Ref<T$1>): void;
|
|
139
|
+
//#endregion
|
|
140
|
+
//#region src/reactivity/toRefs.d.ts
|
|
141
|
+
/**
|
|
142
|
+
* 将一个响应式对象转换成“同结构的普通对象”,其中每个字段都是指向原对象对应属性的 ref。
|
|
143
|
+
*
|
|
144
|
+
* @param object 待转换的响应式对象
|
|
145
|
+
* @returns 包含若干 ref 的普通对象
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```ts
|
|
149
|
+
* const state = reactive({ foo: 1, bar: 2 })
|
|
150
|
+
* const stateAsRefs = toRefs(state)
|
|
151
|
+
*
|
|
152
|
+
* stateAsRefs.foo.value++ // 2
|
|
153
|
+
* state.foo // 2
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
declare function toRefs<T$1 extends object>(object: T$1): ToRefs<T$1>;
|
|
157
|
+
/**
|
|
158
|
+
* 为源响应式对象的单个属性创建 ref,可读可写并与原属性保持同步。
|
|
159
|
+
*
|
|
160
|
+
* @param object 源响应式对象
|
|
161
|
+
* @param key 属性名
|
|
162
|
+
* @returns 指向该属性的 ref
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```ts
|
|
166
|
+
* const state = reactive({ foo: 1 })
|
|
167
|
+
* const fooRef = toRef(state, 'foo')
|
|
168
|
+
*
|
|
169
|
+
* fooRef.value++
|
|
170
|
+
* console.log(state.foo) // 2
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
declare function toRef<T$1 extends object, K$1 extends keyof T$1>(object: T$1, key: K$1): Ref<T$1[K$1]>;
|
|
174
|
+
declare function toRef<T$1 extends object, K$1 extends keyof T$1>(object: T$1, key: K$1, defaultValue: T$1[K$1]): Ref<T$1[K$1]>;
|
|
175
|
+
/**
|
|
176
|
+
* toRefs 返回值的类型辅助
|
|
177
|
+
*/
|
|
178
|
+
type ToRefs<T$1 extends object> = { [K in keyof T$1]: Ref<T$1[K]> };
|
|
59
179
|
//#endregion
|
|
60
180
|
//#region src/reactivity/traverse.d.ts
|
|
61
181
|
declare function traverse(value: any, seen?: Set<object>): any;
|
|
@@ -65,15 +185,15 @@ interface WatchOptions {
|
|
|
65
185
|
immediate?: boolean;
|
|
66
186
|
deep?: boolean;
|
|
67
187
|
}
|
|
68
|
-
type WatchSource<T = any> = (() => T) | Ref<T> | object;
|
|
188
|
+
type WatchSource<T$1 = any> = (() => T$1) | Ref<T$1> | object;
|
|
69
189
|
type WatchStopHandle = () => void;
|
|
70
190
|
type DeepWatchStrategy = 'version' | 'traverse';
|
|
71
191
|
declare function setDeepWatchStrategy(strategy: DeepWatchStrategy): void;
|
|
72
192
|
declare function getDeepWatchStrategy(): DeepWatchStrategy;
|
|
73
|
-
declare function watch<T>(source: WatchSource<T>, cb: (value: T, oldValue: T, onCleanup: (cleanupFn: () => void) => void) => void, options?: WatchOptions): WatchStopHandle;
|
|
193
|
+
declare function watch<T$1>(source: WatchSource<T$1>, cb: (value: T$1, oldValue: T$1, onCleanup: (cleanupFn: () => void) => void) => void, options?: WatchOptions): WatchStopHandle;
|
|
74
194
|
/**
|
|
75
|
-
* watchEffect
|
|
76
|
-
*
|
|
195
|
+
* watchEffect 注册一个响应式副作用,可选清理函数。
|
|
196
|
+
* 副作用会立即执行,并在依赖变化时重新运行。
|
|
77
197
|
*/
|
|
78
198
|
declare function watchEffect(effectFn: (onCleanup: (cleanupFn: () => void) => void) => void): WatchStopHandle;
|
|
79
199
|
//#endregion
|
|
@@ -86,16 +206,16 @@ type ComponentPublicInstance<D extends object, C extends ComputedDefinitions, M
|
|
|
86
206
|
interface MiniProgramAdapter {
|
|
87
207
|
setData?: (payload: Record<string, any>) => void | Promise<void>;
|
|
88
208
|
}
|
|
89
|
-
interface ModelBindingOptions<T = any> {
|
|
209
|
+
interface ModelBindingOptions<T$1 = any> {
|
|
90
210
|
event?: string;
|
|
91
211
|
valueProp?: string;
|
|
92
|
-
parser?: (payload: any) => T;
|
|
93
|
-
formatter?: (value: T) => any;
|
|
212
|
+
parser?: (payload: any) => T$1;
|
|
213
|
+
formatter?: (value: T$1) => any;
|
|
94
214
|
}
|
|
95
|
-
interface ModelBinding<T = any> {
|
|
96
|
-
value: T;
|
|
97
|
-
update: (value: T) => void;
|
|
98
|
-
model: (options?: ModelBindingOptions<T>) => Record<string, any>;
|
|
215
|
+
interface ModelBinding<T$1 = any> {
|
|
216
|
+
value: T$1;
|
|
217
|
+
update: (value: T$1) => void;
|
|
218
|
+
model: (options?: ModelBindingOptions<T$1>) => Record<string, any>;
|
|
99
219
|
}
|
|
100
220
|
interface AppConfig {
|
|
101
221
|
globalProperties: Record<string, any>;
|
|
@@ -114,29 +234,114 @@ interface RuntimeInstance<D extends object, C extends ComputedDefinitions, M ext
|
|
|
114
234
|
readonly methods: ExtractMethods<M>;
|
|
115
235
|
readonly computed: Readonly<ExtractComputed<C>>;
|
|
116
236
|
readonly adapter?: MiniProgramAdapter;
|
|
117
|
-
bindModel: <T = any>(path: string, options?: ModelBindingOptions<T>) => ModelBinding<T>;
|
|
118
|
-
watch: <T>(source: (() => T) | Record<string, any>, cb: (value: T, oldValue: T) => void, options?: WatchOptions) => WatchStopHandle;
|
|
237
|
+
bindModel: <T$1 = any>(path: string, options?: ModelBindingOptions<T$1>) => ModelBinding<T$1>;
|
|
238
|
+
watch: <T$1>(source: (() => T$1) | Record<string, any>, cb: (value: T$1, oldValue: T$1) => void, options?: WatchOptions) => WatchStopHandle;
|
|
119
239
|
snapshot: () => Record<string, any>;
|
|
120
240
|
unmount: () => void;
|
|
121
241
|
}
|
|
122
|
-
|
|
242
|
+
type PropMethod<T$1, TConstructor = any> = [T$1] extends [((...args: any) => any) | undefined] ? {
|
|
243
|
+
new (): TConstructor;
|
|
244
|
+
(): T$1;
|
|
245
|
+
readonly prototype: TConstructor;
|
|
246
|
+
} : never;
|
|
247
|
+
type PropConstructor<T$1 = any> = {
|
|
248
|
+
new (...args: any[]): T$1 & object;
|
|
249
|
+
} | {
|
|
250
|
+
(): T$1;
|
|
251
|
+
} | PropMethod<T$1>;
|
|
252
|
+
type PropType<T$1> = PropConstructor<T$1> | PropConstructor<T$1>[];
|
|
253
|
+
type ComponentPropsOptions = Record<string, PropOptions<any> | PropType<any> | null>;
|
|
254
|
+
interface PropOptions<T$1 = any> {
|
|
255
|
+
type?: PropType<T$1> | true | null;
|
|
256
|
+
/**
|
|
257
|
+
* Default value (mirrors Vue `default`; will be assigned to mini-program property `value`)
|
|
258
|
+
*/
|
|
259
|
+
default?: T$1 | (() => T$1);
|
|
260
|
+
/**
|
|
261
|
+
* Alias for mini-program `value`
|
|
262
|
+
*/
|
|
263
|
+
value?: T$1 | (() => T$1);
|
|
264
|
+
required?: boolean;
|
|
265
|
+
}
|
|
266
|
+
type HasDefault<T$1> = T$1 extends {
|
|
267
|
+
default: infer D;
|
|
268
|
+
} ? D extends (() => undefined) | undefined ? false : true : T$1 extends {
|
|
269
|
+
value: infer V;
|
|
270
|
+
} ? V extends (() => undefined) | undefined ? false : true : false;
|
|
271
|
+
type IsBooleanProp<T$1> = T$1 extends {
|
|
272
|
+
type?: infer U;
|
|
273
|
+
} ? IsBooleanProp<U> : T$1 extends readonly any[] ? true extends IsBooleanProp<T$1[number]> ? true : false : T$1 extends BooleanConstructor ? true : false;
|
|
274
|
+
type RequiredKeys<T$1> = { [K in keyof T$1]: T$1[K] extends {
|
|
275
|
+
required: true;
|
|
276
|
+
} ? K : HasDefault<T$1[K]> extends true ? K : IsBooleanProp<T$1[K]> extends true ? K : never }[keyof T$1];
|
|
277
|
+
type OptionalKeys<T$1> = Exclude<keyof T$1, RequiredKeys<T$1>>;
|
|
278
|
+
type InferPropType<O> = O extends null ? any : O extends {
|
|
279
|
+
type?: infer T;
|
|
280
|
+
} ? InferPropConstructor<T> : O extends PropType<infer V> ? V : InferPropConstructor<O>;
|
|
281
|
+
type InferPropConstructor<T$1> = T$1 extends readonly any[] ? InferPropConstructor<T$1[number]> : T$1 extends undefined ? any : T$1 extends null ? any : T$1 extends BooleanConstructor ? boolean : T$1 extends NumberConstructor ? number : T$1 extends StringConstructor ? string : T$1 extends DateConstructor ? Date : T$1 extends ArrayConstructor ? any[] : T$1 extends ObjectConstructor ? Record<string, any> : T$1 extends PropConstructor<infer V> ? V : any;
|
|
282
|
+
type InferProps<P$1 extends ComponentPropsOptions = ComponentPropsOptions> = { [K in keyof Pick<P$1, RequiredKeys<P$1>>]: HasDefault<P$1[K]> extends true ? Exclude<InferPropType<P$1[K]>, undefined> : InferPropType<P$1[K]> } & { [K in keyof Pick<P$1, OptionalKeys<P$1>>]?: InferPropType<P$1[K]> };
|
|
283
|
+
type SetupFunction<P$1 extends ComponentPropsOptions, D extends object, C extends ComputedDefinitions, M extends MethodDefinitions> = (props: InferProps<P$1>, ctx: SetupContext<D, C, M, P$1>) => Record<string, any> | void;
|
|
284
|
+
interface SetupContext<D extends object, C extends ComputedDefinitions, M extends MethodDefinitions, P$1 extends ComponentPropsOptions = ComponentPropsOptions> {
|
|
285
|
+
/**
|
|
286
|
+
* Component props (from mini-program properties)
|
|
287
|
+
*/
|
|
288
|
+
props: InferProps<P$1>;
|
|
289
|
+
/**
|
|
290
|
+
* Runtime instance
|
|
291
|
+
*/
|
|
123
292
|
runtime: RuntimeInstance<D, C, M>;
|
|
293
|
+
/**
|
|
294
|
+
* Reactive state
|
|
295
|
+
*/
|
|
124
296
|
state: D;
|
|
297
|
+
/**
|
|
298
|
+
* Public instance proxy
|
|
299
|
+
*/
|
|
125
300
|
proxy: ComponentPublicInstance<D, C, M>;
|
|
301
|
+
/**
|
|
302
|
+
* Model binding helper
|
|
303
|
+
*/
|
|
126
304
|
bindModel: RuntimeInstance<D, C, M>['bindModel'];
|
|
305
|
+
/**
|
|
306
|
+
* Watch helper
|
|
307
|
+
*/
|
|
127
308
|
watch: RuntimeInstance<D, C, M>['watch'];
|
|
309
|
+
/**
|
|
310
|
+
* Internal mini-program instance
|
|
311
|
+
*/
|
|
128
312
|
instance: InternalRuntimeState;
|
|
313
|
+
/**
|
|
314
|
+
* Vue 3 compatible: emit events
|
|
315
|
+
*/
|
|
316
|
+
emit: (event: string, ...args: any[]) => void;
|
|
317
|
+
/**
|
|
318
|
+
* Vue 3 compatible: expose public properties
|
|
319
|
+
*/
|
|
320
|
+
expose?: (exposed: Record<string, any>) => void;
|
|
321
|
+
/**
|
|
322
|
+
* Vue 3 compatible: attrs (fallback to empty object for mini-programs)
|
|
323
|
+
*/
|
|
324
|
+
attrs?: Record<string, any>;
|
|
129
325
|
}
|
|
130
326
|
interface InternalRuntimeState {
|
|
131
327
|
__wevu?: RuntimeInstance<any, any, any>;
|
|
132
328
|
__wevuWatchStops?: WatchStopHandle[];
|
|
133
329
|
$wevu?: RuntimeInstance<any, any, any>;
|
|
134
330
|
__wevuHooks?: Record<string, any>;
|
|
331
|
+
__wevuExposed?: Record<string, any>;
|
|
135
332
|
}
|
|
136
|
-
interface DefineComponentOptions<D extends object = Record<string, any>, C extends ComputedDefinitions = ComputedDefinitions, M extends MethodDefinitions = MethodDefinitions> extends CreateAppOptions<D, C, M> {
|
|
137
|
-
|
|
333
|
+
interface DefineComponentOptions<P$1 extends ComponentPropsOptions = ComponentPropsOptions, D extends object = Record<string, any>, C extends ComputedDefinitions = ComputedDefinitions, M extends MethodDefinitions = MethodDefinitions> extends Omit<CreateAppOptions<D, C, M>, 'setup'> {
|
|
334
|
+
/**
|
|
335
|
+
* Page-only feature gates (e.g. scroll/share hooks).
|
|
336
|
+
* Only takes effect on page entries.
|
|
337
|
+
*/
|
|
338
|
+
features?: PageFeatures;
|
|
339
|
+
/**
|
|
340
|
+
* Vue-like props definition (will be normalized to mini-program `properties`)
|
|
341
|
+
*/
|
|
342
|
+
props?: P$1;
|
|
138
343
|
watch?: Record<string, any>;
|
|
139
|
-
setup?:
|
|
344
|
+
setup?: SetupFunction<P$1, D, C, M>;
|
|
140
345
|
[key: string]: any;
|
|
141
346
|
}
|
|
142
347
|
interface DefineAppOptions<D extends object = Record<string, any>, C extends ComputedDefinitions = ComputedDefinitions, M extends MethodDefinitions = MethodDefinitions> {
|
|
@@ -163,12 +368,66 @@ interface PageFeatures {
|
|
|
163
368
|
declare function createApp<D extends object, C extends ComputedDefinitions, M extends MethodDefinitions>(options: CreateAppOptions<D, C, M>): RuntimeApp<D, C, M>;
|
|
164
369
|
//#endregion
|
|
165
370
|
//#region src/runtime/define.d.ts
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
371
|
+
/**
|
|
372
|
+
* defineComponent 返回的组件定义描述,用于手动注册或高级用法。
|
|
373
|
+
*/
|
|
374
|
+
interface ComponentDefinition<D extends object, C extends ComputedDefinitions, M extends MethodDefinitions> {
|
|
375
|
+
/**
|
|
376
|
+
* 内部 runtime app(高级能力使用),不对外暴露正式 API。
|
|
377
|
+
* @internal
|
|
378
|
+
*/
|
|
379
|
+
__wevu_runtime: RuntimeApp<D, C, M>;
|
|
380
|
+
/**
|
|
381
|
+
* 内部选项快照(高级能力使用),包含 data/computed/methods 等。
|
|
382
|
+
* @internal
|
|
383
|
+
*/
|
|
384
|
+
__wevu_options: {
|
|
385
|
+
data: () => D;
|
|
386
|
+
computed: C;
|
|
387
|
+
methods: M;
|
|
388
|
+
watch: Record<string, any> | undefined;
|
|
389
|
+
setup: DefineComponentOptions<ComponentPropsOptions, D, C, M>['setup'];
|
|
390
|
+
mpOptions: Record<string, any>;
|
|
391
|
+
features?: DefineComponentOptions<ComponentPropsOptions, D, C, M>['features'];
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* 按 Vue 3 风格定义一个小程序组件/页面。
|
|
396
|
+
*
|
|
397
|
+
* - 统一注册为 `Component()`
|
|
398
|
+
*
|
|
399
|
+
* @param options 组件定义项
|
|
400
|
+
* @returns 可手动注册的组件定义
|
|
401
|
+
*
|
|
402
|
+
* @example
|
|
403
|
+
* ```ts
|
|
404
|
+
* defineComponent({
|
|
405
|
+
* data: () => ({ count: 0 }),
|
|
406
|
+
* setup() {
|
|
407
|
+
* onMounted(() => console.log('mounted'))
|
|
408
|
+
* }
|
|
409
|
+
* })
|
|
410
|
+
* ```
|
|
411
|
+
*
|
|
412
|
+
* @example
|
|
413
|
+
* ```ts
|
|
414
|
+
* defineComponent({
|
|
415
|
+
* features: { listenPageScroll: true },
|
|
416
|
+
* setup() {
|
|
417
|
+
* onPageScroll(() => {})
|
|
418
|
+
* }
|
|
419
|
+
* })
|
|
420
|
+
* ```
|
|
421
|
+
*/
|
|
422
|
+
declare function defineComponent<P$1 extends ComponentPropsOptions = ComponentPropsOptions, D extends object = Record<string, any>, C extends ComputedDefinitions = ComputedDefinitions, M extends MethodDefinitions = MethodDefinitions>(options: DefineComponentOptions<P$1, D, C, M>): ComponentDefinition<D, C, M>;
|
|
423
|
+
/**
|
|
424
|
+
* 从 Vue SFC 选项创建 wevu 组件,供 weapp-vite 编译产物直接调用的兼容入口。
|
|
425
|
+
*
|
|
426
|
+
* @param options 组件选项,可能包含小程序特有的 properties
|
|
427
|
+
*/
|
|
428
|
+
declare function createWevuComponent<D extends object, C extends ComputedDefinitions, M extends MethodDefinitions>(options: DefineComponentOptions<ComponentPropsOptions, D, C, M> & {
|
|
429
|
+
properties?: Record<string, any>;
|
|
430
|
+
}): void;
|
|
172
431
|
//#endregion
|
|
173
432
|
//#region src/runtime/hooks.d.ts
|
|
174
433
|
declare function getCurrentInstance(): any;
|
|
@@ -189,10 +448,94 @@ declare function onSaveExitState(handler: () => any): void;
|
|
|
189
448
|
declare function onShareAppMessage(handler: (...args: any[]) => any): void;
|
|
190
449
|
declare function onShareTimeline(handler: (...args: any[]) => any): void;
|
|
191
450
|
declare function onAddToFavorites(handler: (...args: any[]) => any): void;
|
|
451
|
+
/**
|
|
452
|
+
* Vue 3 对齐:组件/页面已挂载,映射小程序 onReady
|
|
453
|
+
*/
|
|
454
|
+
declare function onMounted(handler: () => void): void;
|
|
455
|
+
/**
|
|
456
|
+
* Vue 3 对齐:组件/页面更新后触发。
|
|
457
|
+
* 小程序没有专用 update 生命周期,这里在每次 setData 完成后调用。
|
|
458
|
+
*/
|
|
459
|
+
declare function onUpdated(handler: () => void): void;
|
|
460
|
+
/**
|
|
461
|
+
* Vue 3 对齐:卸载前触发。
|
|
462
|
+
* 小程序无 before-unload 生命周期,setup 时同步执行以保持语义。
|
|
463
|
+
*/
|
|
464
|
+
declare function onBeforeUnmount(handler: () => void): void;
|
|
465
|
+
/**
|
|
466
|
+
* Vue 3 对齐:组件/页面卸载;映射到页面 onUnload 或组件 detached
|
|
467
|
+
*/
|
|
468
|
+
declare function onUnmounted(handler: () => void): void;
|
|
469
|
+
/**
|
|
470
|
+
* Vue 3 对齐:挂载前;setup 时同步触发以模拟 beforeMount 语义
|
|
471
|
+
*/
|
|
472
|
+
declare function onBeforeMount(handler: () => void): void;
|
|
473
|
+
/**
|
|
474
|
+
* Vue 3 对齐:更新前;在每次 setData 前触发
|
|
475
|
+
*/
|
|
476
|
+
declare function onBeforeUpdate(handler: () => void): void;
|
|
477
|
+
/**
|
|
478
|
+
* Vue 3 对齐:错误捕获;映射到小程序 onError
|
|
479
|
+
*/
|
|
480
|
+
declare function onErrorCaptured(handler: (err: any, instance: any, info: string) => void): void;
|
|
481
|
+
/**
|
|
482
|
+
* Vue 3 对齐:组件激活;映射到小程序 onShow
|
|
483
|
+
*/
|
|
484
|
+
declare function onActivated(handler: () => void): void;
|
|
485
|
+
/**
|
|
486
|
+
* Vue 3 对齐:组件失活;映射到小程序 onHide
|
|
487
|
+
*/
|
|
488
|
+
declare function onDeactivated(handler: () => void): void;
|
|
489
|
+
/**
|
|
490
|
+
* Vue 3 对齐:服务端渲染前置钩子。
|
|
491
|
+
* 小程序无此场景,保留空实现以保持 API 兼容。
|
|
492
|
+
*/
|
|
493
|
+
declare function onServerPrefetch(_handler: () => void): void;
|
|
494
|
+
declare function callUpdateHooks(target: InternalRuntimeState, phase: 'before' | 'after'): void;
|
|
192
495
|
//#endregion
|
|
193
496
|
//#region src/runtime/provide.d.ts
|
|
194
|
-
|
|
195
|
-
|
|
497
|
+
/**
|
|
498
|
+
* 在组件上下文中向后代注入值(与 Vue 3 行为兼容),若没有当前实例则回落到全局存储。
|
|
499
|
+
*
|
|
500
|
+
* @param key 注入键,可为字符串、Symbol 或对象
|
|
501
|
+
* @param value 提供的值
|
|
502
|
+
*
|
|
503
|
+
* @example
|
|
504
|
+
* ```ts
|
|
505
|
+
* defineComponent({
|
|
506
|
+
* setup() {
|
|
507
|
+
* provide(TOKEN_KEY, { data: 'value' })
|
|
508
|
+
* }
|
|
509
|
+
* })
|
|
510
|
+
* ```
|
|
511
|
+
*/
|
|
512
|
+
declare function provide<T$1>(key: any, value: T$1): void;
|
|
513
|
+
/**
|
|
514
|
+
* 从祖先组件(或全局存储)读取提供的值。
|
|
515
|
+
*
|
|
516
|
+
* @param key 注入键,需与 provide 使用的键保持一致
|
|
517
|
+
* @param defaultValue 未找到提供者时的默认值
|
|
518
|
+
* @returns 匹配到的值或默认值
|
|
519
|
+
*
|
|
520
|
+
* @example
|
|
521
|
+
* ```ts
|
|
522
|
+
* defineComponent({
|
|
523
|
+
* setup() {
|
|
524
|
+
* const data = inject(TOKEN_KEY)
|
|
525
|
+
* const value = inject('key', 'default')
|
|
526
|
+
* }
|
|
527
|
+
* })
|
|
528
|
+
* ```
|
|
529
|
+
*/
|
|
530
|
+
declare function inject<T$1>(key: any, defaultValue?: T$1): T$1;
|
|
531
|
+
/**
|
|
532
|
+
* 全局注入值,适用于组件外部调用场景。
|
|
533
|
+
*/
|
|
534
|
+
declare function provideGlobal<T$1>(key: any, value: T$1): void;
|
|
535
|
+
/**
|
|
536
|
+
* 从全局存储读取值,适用于组件外部调用场景。
|
|
537
|
+
*/
|
|
538
|
+
declare function injectGlobal<T$1>(key: any, defaultValue?: T$1): T$1;
|
|
196
539
|
//#endregion
|
|
197
540
|
//#region src/runtime/register.d.ts
|
|
198
541
|
type WatchHandler = (this: any, value: any, oldValue: any) => void;
|
|
@@ -202,10 +545,10 @@ type WatchDescriptor = WatchHandler | string | {
|
|
|
202
545
|
deep?: boolean;
|
|
203
546
|
};
|
|
204
547
|
type WatchMap = Record<string, WatchDescriptor>;
|
|
205
|
-
declare function
|
|
548
|
+
declare function runSetupFunction(setup: ((...args: any[]) => any) | undefined, props: Record<string, any>, context: any): any;
|
|
549
|
+
declare function mountRuntimeInstance<D extends object, C extends ComputedDefinitions, M extends MethodDefinitions>(target: InternalRuntimeState, runtimeApp: RuntimeApp<D, C, M>, watchMap: WatchMap | undefined, setup?: DefineComponentOptions<ComponentPropsOptions, D, C, M>['setup']): RuntimeInstance<D, C, M>;
|
|
206
550
|
declare function teardownRuntimeInstance(target: InternalRuntimeState): void;
|
|
207
551
|
declare function registerApp<D extends object, C extends ComputedDefinitions, M extends MethodDefinitions>(runtimeApp: RuntimeApp<D, C, M>, methods: MethodDefinitions, watch: WatchMap | undefined, setup: DefineAppOptions<D, C, M>['setup'], mpOptions: Record<string, any>): void;
|
|
208
|
-
declare function
|
|
209
|
-
declare function registerComponent<D extends object, C extends ComputedDefinitions, M extends MethodDefinitions>(runtimeApp: RuntimeApp<D, C, M>, methods: MethodDefinitions, watch: WatchMap | undefined, setup: DefineComponentOptions<D, C, M>['setup'], mpOptions: Record<string, any>): void;
|
|
552
|
+
declare function registerComponent<D extends object, C extends ComputedDefinitions, M extends MethodDefinitions>(runtimeApp: RuntimeApp<D, C, M>, methods: MethodDefinitions, watch: WatchMap | undefined, setup: DefineComponentOptions<ComponentPropsOptions, D, C, M>['setup'], mpOptions: Record<string, any>, features?: PageFeatures): void;
|
|
210
553
|
//#endregion
|
|
211
|
-
export { AppConfig, ComponentPublicInstance, ComputedDefinitions, ComputedGetter, ComputedRef, ComputedSetter, CreateAppOptions, DefineAppOptions, DefineComponentOptions, ExtractComputed, ExtractMethods, InternalRuntimeState, MethodDefinitions, MiniProgramAdapter, ModelBinding, ModelBindingOptions, PageFeatures, Ref, RuntimeApp, RuntimeInstance, SetupContext, WatchOptions, WatchStopHandle, WevuPlugin, WritableComputedOptions, WritableComputedRef, callHookList, callHookReturn, computed, createApp, defineComponent,
|
|
554
|
+
export { ActionSubscriber, AppConfig, ComponentDefinition, ComponentPropsOptions, ComponentPublicInstance, ComputedDefinitions, ComputedGetter, ComputedRef, ComputedSetter, CreateAppOptions, DefineAppOptions, DefineComponentOptions, DefineStoreOptions, ExtractComputed, ExtractMethods, InferPropType, InferProps, InternalRuntimeState, MethodDefinitions, MiniProgramAdapter, ModelBinding, ModelBindingOptions, MutationType, PageFeatures, PropConstructor, PropOptions, PropType, Ref, RuntimeApp, RuntimeInstance, SetupContext, SetupFunction, StoreManager, SubscriptionCallback, ToRefs, WatchOptions, WatchStopHandle, WevuPlugin, WritableComputedOptions, WritableComputedRef, callHookList, callHookReturn, callUpdateHooks, computed, createApp, createStore, createWevuComponent, defineComponent, defineStore, effect, getCurrentInstance, getDeepWatchStrategy, inject, injectGlobal, isRaw, isReactive, isRef, isShallowReactive, isShallowRef, markRaw, mountRuntimeInstance, nextTick, onActivated, onAddToFavorites, onAppError, onAppHide, onAppShow, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onHide, onMounted, onPageScroll, onReady, onRouteDone, onSaveExitState, onServerPrefetch, onShareAppMessage, onShareTimeline, onShow, onTabItemTap, onUnload, onUnmounted, onUpdated, provide, provideGlobal, reactive, readonly, ref, registerApp, registerComponent, runSetupFunction, setCurrentInstance, setDeepWatchStrategy, shallowReactive, shallowRef, stop, storeToRefs, teardownRuntimeInstance, toRaw, toRef, toRefs, touchReactive, traverse, triggerRef, unref, watch, watchEffect };
|