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