@hairy/react-lib-composition 1.46.0 → 1.49.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/LICENSE.md +21 -21
- package/README.md +36 -36
- package/dist/index.cjs +493 -414
- package/dist/{index.d.ts → index.d.cts} +28 -32
- package/dist/index.d.mts +344 -0
- package/dist/index.mjs +448 -0
- package/package.json +19 -20
- package/dist/index.global.js +0 -5252
- package/dist/index.js +0 -435
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
import { ComputedGetter, DebuggerOptions,
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import { FunctionComponent, Ref as Ref$2, RefObject } from 'react';
|
|
5
|
-
export { Fragment, createElement as h } from 'react';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @module veact.computed
|
|
9
|
-
* @author Surmon <https://github.com/surmon-china>
|
|
10
|
-
*/
|
|
1
|
+
import { ComputedGetter, ComputedRef, CustomRefFactory, DebuggerOptions, DeepReadonly, EffectScope, Reactive, ReactiveMarker, Ref as Ref$1, ShallowReactive, ShallowRef, UnwrapNestedRefs, UnwrapRef, WatchCallback, WatchEffect, WatchHandle, WatchSource, WritableComputedOptions, WritableComputedRef, effectScope as effectScope$1, isProxy, isReactive, isReadonly, isRef, isShallow, markRaw, toRaw, toReactive, toReadonly, toRef, toRefs, toValue, unref } from "@vue/reactivity";
|
|
2
|
+
import { ArgumentsType, IfAny } from "@hairy/utils";
|
|
3
|
+
import { Fragment, FunctionComponent, Ref as Ref$2, RefObject, createElement as h } from "react";
|
|
11
4
|
|
|
5
|
+
//#region src/computed.d.ts
|
|
12
6
|
/**
|
|
13
7
|
* Takes a getter function and returns a readonly reactive ref object for the
|
|
14
8
|
* returned value from the getter. It can also take an object with get and set
|
|
@@ -45,7 +39,8 @@ export { Fragment, createElement as h } from 'react';
|
|
|
45
39
|
*/
|
|
46
40
|
declare function computed<T>(getter: ComputedGetter<T>, debugOptions?: DebuggerOptions): ComputedRef<T>;
|
|
47
41
|
declare function computed<T, S = T>(options: WritableComputedOptions<T, S>, debugOptions?: DebuggerOptions): WritableComputedRef<T, S>;
|
|
48
|
-
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region src/effectScope.d.ts
|
|
49
44
|
/**
|
|
50
45
|
* Creates an effect scope object which can capture the reactive effects (i.e.
|
|
51
46
|
* computed and watchers) created within it so that these effects can be
|
|
@@ -71,7 +66,8 @@ declare function getCurrentScope(): EffectScope | undefined;
|
|
|
71
66
|
* @see {@link https://vuejs.org/api/reactivity-advanced.html#onscopedispose}
|
|
72
67
|
*/
|
|
73
68
|
declare function onScopeDispose(fn: () => void, _failSilently?: boolean): void;
|
|
74
|
-
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region src/lifecycle.d.ts
|
|
75
71
|
/**
|
|
76
72
|
* The function is called right after the component is mounted.
|
|
77
73
|
*
|
|
@@ -97,7 +93,8 @@ declare function onUnmounted(fn: () => void): void;
|
|
|
97
93
|
*/
|
|
98
94
|
declare function onUpdated(fn: () => void): void;
|
|
99
95
|
declare function onBeforeUpdate(fn: () => void): void;
|
|
100
|
-
|
|
96
|
+
//#endregion
|
|
97
|
+
//#region src/reactive.d.ts
|
|
101
98
|
/**
|
|
102
99
|
* Returns a reactive proxy of the object.
|
|
103
100
|
*
|
|
@@ -145,7 +142,8 @@ declare function reactive<T extends object>(target: T): Reactive<T>;
|
|
|
145
142
|
* ```
|
|
146
143
|
*/
|
|
147
144
|
declare function shallowReactive<T extends object>(target: T): ShallowReactive<T>;
|
|
148
|
-
|
|
145
|
+
//#endregion
|
|
146
|
+
//#region src/reactivity.d.ts
|
|
149
147
|
/**
|
|
150
148
|
* Converts some of the 'raw Vue' data, which is not already wrapped in a hook,
|
|
151
149
|
* into reactive hook data to ensure proper reactivity within the component.
|
|
@@ -175,12 +173,8 @@ declare function shallowReactive<T extends object>(target: T): ShallowReactive<T
|
|
|
175
173
|
* ```
|
|
176
174
|
*/
|
|
177
175
|
declare function reactivity<T = any>(getter: () => T): T;
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
* @module veact.readonly
|
|
181
|
-
* @author Surmon <https://github.com/surmon-china>
|
|
182
|
-
*/
|
|
183
|
-
|
|
176
|
+
//#endregion
|
|
177
|
+
//#region src/readonly.d.ts
|
|
184
178
|
/**
|
|
185
179
|
* Takes an object (reactive or plain) or a ref and returns a readonly proxy to
|
|
186
180
|
* the original.
|
|
@@ -241,7 +235,8 @@ declare function readonly<T extends object>(target: T): DeepReadonly<UnwrapNeste
|
|
|
241
235
|
* ```
|
|
242
236
|
*/
|
|
243
237
|
declare function shallowReadonly<T extends object>(target: T): Readonly<T>;
|
|
244
|
-
|
|
238
|
+
//#endregion
|
|
239
|
+
//#region src/ref.d.ts
|
|
245
240
|
type Ref<T = any, S = T> = Ref$1<T, S> & Ref$2<NonNullable<T>> & RefObject<NonNullable<T>>;
|
|
246
241
|
/**
|
|
247
242
|
* Takes an inner value and returns a reactive and mutable ref object, which
|
|
@@ -285,17 +280,16 @@ declare function customRef<T>(factory: CustomRefFactory<T>): Ref<T>;
|
|
|
285
280
|
*/
|
|
286
281
|
declare function shallowRef<T>(value: T): Ref extends T ? (T extends Ref ? IfAny<T, ShallowRef<T>, T> : ShallowRef<T>) : ShallowRef<T>;
|
|
287
282
|
declare function shallowRef<T = any>(): ShallowRef<T | undefined>;
|
|
288
|
-
|
|
283
|
+
//#endregion
|
|
284
|
+
//#region src/watch.d.ts
|
|
289
285
|
interface WatchOptions<Immediate = boolean> extends DebuggerOptions {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
286
|
+
immediate?: Immediate;
|
|
287
|
+
deep?: boolean | number;
|
|
288
|
+
once?: boolean;
|
|
293
289
|
}
|
|
294
290
|
type MultiWatchSources = (WatchSource<unknown> | object)[];
|
|
295
291
|
type MaybeUndefined<T, I> = I extends true ? T | undefined : T;
|
|
296
|
-
type MapSources<T, Immediate> = {
|
|
297
|
-
[K in keyof T]: T[K] extends WatchSource<infer V> ? MaybeUndefined<V, Immediate> : T[K] extends object ? MaybeUndefined<T[K], Immediate> : never;
|
|
298
|
-
};
|
|
292
|
+
type MapSources<T, Immediate> = { [K in keyof T]: T[K] extends WatchSource<infer V> ? MaybeUndefined<V, Immediate> : T[K] extends object ? MaybeUndefined<T[K], Immediate> : never };
|
|
299
293
|
/**
|
|
300
294
|
* Watches one or more reactive data sources and invokes a callback function when the sources change.
|
|
301
295
|
*
|
|
@@ -316,7 +310,8 @@ declare function watch<T, Immediate extends Readonly<boolean> = false>(source: W
|
|
|
316
310
|
declare function watch<T extends Readonly<MultiWatchSources>, Immediate extends Readonly<boolean> = false>(sources: readonly [...T] | T, callback: [T] extends [ReactiveMarker] ? WatchCallback<T, MaybeUndefined<T, Immediate>> : WatchCallback<MapSources<T, false>, MapSources<T, Immediate>>, options?: WatchOptions<Immediate>): WatchHandle;
|
|
317
311
|
declare function watch<T extends MultiWatchSources, Immediate extends Readonly<boolean> = false>(sources: [...T], callback: WatchCallback<MapSources<T, false>, MapSources<T, Immediate>>, options?: WatchOptions<Immediate>): WatchHandle;
|
|
318
312
|
declare function watch<T extends object, Immediate extends Readonly<boolean> = false>(source: T, callback: WatchCallback<T, MaybeUndefined<T, Immediate>>, options?: WatchOptions<Immediate>): WatchHandle;
|
|
319
|
-
|
|
313
|
+
//#endregion
|
|
314
|
+
//#region src/watchEffect.d.ts
|
|
320
315
|
type WatchEffectOptions = DebuggerOptions;
|
|
321
316
|
/**
|
|
322
317
|
* Runs a function immediately while reactively tracking its dependencies and re-runs it whenever the dependencies are changed.
|
|
@@ -336,7 +331,8 @@ type WatchEffectOptions = DebuggerOptions;
|
|
|
336
331
|
* ```
|
|
337
332
|
*/
|
|
338
333
|
declare function watchEffect(effect: WatchEffect, options?: WatchEffectOptions): WatchHandle;
|
|
339
|
-
|
|
334
|
+
//#endregion
|
|
335
|
+
//#region src/index.d.ts
|
|
340
336
|
declare const getCurrentInstance: (...args: any) => any;
|
|
341
337
|
declare const hasInjectionContext: (...args: any) => any;
|
|
342
338
|
declare const inject: (...args: any) => any;
|
|
@@ -344,5 +340,5 @@ declare const provide: (...args: any) => any;
|
|
|
344
340
|
declare const nextTick: (...args: any) => any;
|
|
345
341
|
declare const defineComponent: (...args: any) => any;
|
|
346
342
|
declare const TransitionGroup: (...args: any) => any;
|
|
347
|
-
|
|
348
|
-
export {
|
|
343
|
+
//#endregion
|
|
344
|
+
export { Fragment, MultiWatchSources, Ref, TransitionGroup, WatchEffectOptions, WatchOptions, computed, customRef, defineComponent, effectScope, getCurrentInstance, getCurrentScope, h, hasInjectionContext, inject, isProxy, isReactive, isReadonly, isRef, isShallow, markRaw, nextTick, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onMounted, onScopeDispose, onUnmounted, onUpdated, provide, reactive, reactivity, readonly, ref, shallowReactive, shallowReadonly, shallowRef, toRaw, toReactive, toReadonly, toRef, toRefs, toValue, unref, watch, watchEffect, withEffectScope };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
import { ArgumentsType, IfAny } from "@hairy/utils";
|
|
2
|
+
import { Fragment, FunctionComponent, Ref as Ref$1, RefObject, createElement as h } from "react";
|
|
3
|
+
import { ComputedGetter, ComputedRef, CustomRefFactory, DebuggerOptions, DeepReadonly, EffectScope, Reactive, ReactiveMarker, Ref as Ref$2, ShallowReactive, ShallowRef, UnwrapNestedRefs, UnwrapRef, WatchCallback, WatchEffect, WatchHandle, WatchSource, WritableComputedOptions, WritableComputedRef, effectScope as effectScope$1, isProxy, isReactive, isReadonly, isRef, isShallow, markRaw, toRaw, toReactive, toReadonly, toRef, toRefs, toValue, unref } from "@vue/reactivity";
|
|
4
|
+
|
|
5
|
+
//#region src/computed.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Takes a getter function and returns a readonly reactive ref object for the
|
|
8
|
+
* returned value from the getter. It can also take an object with get and set
|
|
9
|
+
* functions to create a writable ref object.
|
|
10
|
+
*
|
|
11
|
+
* @param getter - Function that produces the next value.
|
|
12
|
+
* @param debugOptions - For debugging. See {@link https://vuejs.org/guide/extras/reactivity-in-depth.html#computed-debugging Vue Computed Debugging}.
|
|
13
|
+
* @see {@link https://vuejs.org/api/reactivity-core.html#computed Vue `computed()`}
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```js
|
|
17
|
+
* // Creating a readonly computed ref:
|
|
18
|
+
* const count = useRef(1)
|
|
19
|
+
* const plusOne = computed(() => count.value + 1)
|
|
20
|
+
*
|
|
21
|
+
* console.log(plusOne.value) // 2
|
|
22
|
+
* plusOne.value++ // error
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```js
|
|
27
|
+
* // Creating a writable computed ref:
|
|
28
|
+
* const count = useRef(1)
|
|
29
|
+
* const plusOne = computed({
|
|
30
|
+
* get: () => count.value + 1,
|
|
31
|
+
* set: (val) => {
|
|
32
|
+
* count.value = val - 1
|
|
33
|
+
* }
|
|
34
|
+
* })
|
|
35
|
+
*
|
|
36
|
+
* plusOne.value = 1
|
|
37
|
+
* console.log(count.value) // 0
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
declare function computed<T>(getter: ComputedGetter<T>, debugOptions?: DebuggerOptions): ComputedRef<T>;
|
|
41
|
+
declare function computed<T, S = T>(options: WritableComputedOptions<T, S>, debugOptions?: DebuggerOptions): WritableComputedRef<T, S>;
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region src/effectScope.d.ts
|
|
44
|
+
/**
|
|
45
|
+
* Creates an effect scope object which can capture the reactive effects (i.e.
|
|
46
|
+
* computed and watchers) created within it so that these effects can be
|
|
47
|
+
* disposed together. For detailed use cases of this API, please consult its
|
|
48
|
+
* corresponding {@link https://github.com/vuejs/rfcs/blob/master/active-rfcs/0041-reactivity-effect-scope.md | RFC}.
|
|
49
|
+
*
|
|
50
|
+
* @param detached - Can be used to create a "detached" effect scope.
|
|
51
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#effectscope Vue `effectScope()`}
|
|
52
|
+
*/
|
|
53
|
+
declare function effectScope(...args: ArgumentsType<typeof effectScope$1>): EffectScope;
|
|
54
|
+
declare function withEffectScope<T extends FunctionComponent>(fn: T, detached?: boolean): T;
|
|
55
|
+
/**
|
|
56
|
+
* Returns the current active effect scope if there is one.
|
|
57
|
+
*
|
|
58
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#getcurrentscope}
|
|
59
|
+
*/
|
|
60
|
+
declare function getCurrentScope(): EffectScope | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* Registers a dispose callback on the current active effect scope. The
|
|
63
|
+
* callback will be invoked when the associated effect scope is stopped.
|
|
64
|
+
*
|
|
65
|
+
* @param fn - The callback function to attach to the scope's cleanup.
|
|
66
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#onscopedispose}
|
|
67
|
+
*/
|
|
68
|
+
declare function onScopeDispose(fn: () => void, _failSilently?: boolean): void;
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region src/lifecycle.d.ts
|
|
71
|
+
/**
|
|
72
|
+
* The function is called right after the component is mounted.
|
|
73
|
+
*
|
|
74
|
+
* @param fn
|
|
75
|
+
* @see {@link https://react.dev/reference/react/Component#componentdidmount React `componentDidMount()`}
|
|
76
|
+
*/
|
|
77
|
+
declare function onMounted(fn: () => any): void;
|
|
78
|
+
declare function onBeforeMount(fn: () => any): void;
|
|
79
|
+
/**
|
|
80
|
+
* The function is called right before the component is unmounted.
|
|
81
|
+
*
|
|
82
|
+
* @param fn
|
|
83
|
+
* @see {@link https://react.dev/reference/react/Component#componentwillunmount React `componentWillUnmount()`}
|
|
84
|
+
*/
|
|
85
|
+
declare function onBeforeUnmount(fn: () => void): void;
|
|
86
|
+
declare function onUnmounted(fn: () => void): void;
|
|
87
|
+
/**
|
|
88
|
+
* The function is called immediately after the component is re-rendered with updated props or state.
|
|
89
|
+
* This method is not invoked during the initial render.
|
|
90
|
+
*
|
|
91
|
+
* @param fn
|
|
92
|
+
* @see {@link https://react.dev/reference/react/Component#componentdidupdate React `componentDidUpdate()`}
|
|
93
|
+
*/
|
|
94
|
+
declare function onUpdated(fn: () => void): void;
|
|
95
|
+
declare function onBeforeUpdate(fn: () => void): void;
|
|
96
|
+
//#endregion
|
|
97
|
+
//#region src/reactive.d.ts
|
|
98
|
+
/**
|
|
99
|
+
* Returns a reactive proxy of the object.
|
|
100
|
+
*
|
|
101
|
+
* The reactive conversion is "deep": it affects all nested properties. A
|
|
102
|
+
* reactive object also deeply unwraps any properties that are refs while
|
|
103
|
+
* maintaining reactivity.
|
|
104
|
+
*
|
|
105
|
+
* @param target - The source object.
|
|
106
|
+
* @see {@link https://vuejs.org/api/reactivity-core.html#reactive Vue `reactive()`}
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```js
|
|
110
|
+
* const obj = reactive({ count: 0 })
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
declare function reactive<T extends object>(target: T): Reactive<T>;
|
|
114
|
+
/**
|
|
115
|
+
* Shallow version of {@link reactive()}.
|
|
116
|
+
*
|
|
117
|
+
* Unlike {@link reactive()}, there is no deep conversion: only root-level
|
|
118
|
+
* properties are reactive for a shallow reactive object. Property values are
|
|
119
|
+
* stored and exposed as-is - this also means properties with ref values will
|
|
120
|
+
* not be automatically unwrapped.
|
|
121
|
+
*
|
|
122
|
+
* @param target - The source object.
|
|
123
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#shallowreactive Vue `shallowReactive()`}
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```js
|
|
127
|
+
* const state = shallowReactive({
|
|
128
|
+
* foo: 1,
|
|
129
|
+
* nested: {
|
|
130
|
+
* bar: 2
|
|
131
|
+
* }
|
|
132
|
+
* })
|
|
133
|
+
*
|
|
134
|
+
* // mutating state's own properties is reactive
|
|
135
|
+
* state.foo++
|
|
136
|
+
*
|
|
137
|
+
* // ...but does not convert nested objects
|
|
138
|
+
* isReactive(state.nested) // false
|
|
139
|
+
*
|
|
140
|
+
* // NOT reactive
|
|
141
|
+
* state.nested.bar++
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
declare function shallowReactive<T extends object>(target: T): ShallowReactive<T>;
|
|
145
|
+
//#endregion
|
|
146
|
+
//#region src/reactivity.d.ts
|
|
147
|
+
/**
|
|
148
|
+
* Converts some of the 'raw Vue' data, which is not already wrapped in a hook,
|
|
149
|
+
* into reactive hook data to ensure proper reactivity within the component.
|
|
150
|
+
*
|
|
151
|
+
* @param getter - A function that returns the data to be deeply watched.
|
|
152
|
+
* @example
|
|
153
|
+
* ```tsx
|
|
154
|
+
* import React from 'react'
|
|
155
|
+
* import { ref, reactivity } from 'veact'
|
|
156
|
+
*
|
|
157
|
+
* const countRef = ref(0)
|
|
158
|
+
*
|
|
159
|
+
* export const Component: React.FC = () => {
|
|
160
|
+
* // Convert to a reactivity hook
|
|
161
|
+
* const count = reactivity(() => countRef)
|
|
162
|
+
* const increment = () => {
|
|
163
|
+
* count.value++
|
|
164
|
+
* }
|
|
165
|
+
*
|
|
166
|
+
* return (
|
|
167
|
+
* <div>
|
|
168
|
+
* <span>{count.value}</span>
|
|
169
|
+
* <button onClick={increment}>Increment</button>
|
|
170
|
+
* </div>
|
|
171
|
+
* )
|
|
172
|
+
* }
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
declare function reactivity<T = any>(getter: () => T): T;
|
|
176
|
+
//#endregion
|
|
177
|
+
//#region src/readonly.d.ts
|
|
178
|
+
/**
|
|
179
|
+
* Takes an object (reactive or plain) or a ref and returns a readonly proxy to
|
|
180
|
+
* the original.
|
|
181
|
+
*
|
|
182
|
+
* A readonly proxy is deep: any nested property accessed will be readonly as
|
|
183
|
+
* well. It also has the same ref-unwrapping behavior as {@link reactive()},
|
|
184
|
+
* except the unwrapped values will also be made readonly.
|
|
185
|
+
*
|
|
186
|
+
* @param target - The source object.
|
|
187
|
+
* @see {@link https://vuejs.org/api/reactivity-core.html#readonly Vue `readonly()`}
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```js
|
|
191
|
+
* const original = reactive({ count: 0 })
|
|
192
|
+
* const copy = readonly(original)
|
|
193
|
+
*
|
|
194
|
+
* useWatchEffect(() => {
|
|
195
|
+
* // works for reactivity tracking
|
|
196
|
+
* console.log(copy.count)
|
|
197
|
+
* })
|
|
198
|
+
*
|
|
199
|
+
* // mutating original will trigger watchers relying on the copy
|
|
200
|
+
* original.count++
|
|
201
|
+
*
|
|
202
|
+
* // mutating the copy will fail and result in a warning
|
|
203
|
+
* copy.count++ // warning!
|
|
204
|
+
* ```
|
|
205
|
+
*/
|
|
206
|
+
declare function readonly<T extends object>(target: T): DeepReadonly<UnwrapNestedRefs<T>>;
|
|
207
|
+
/**
|
|
208
|
+
* Shallow version of {@link readonly()}.
|
|
209
|
+
*
|
|
210
|
+
* Unlike {@link readonly()}, there is no deep conversion: only root-level
|
|
211
|
+
* properties are made readonly. Property values are stored and exposed as-is -
|
|
212
|
+
* this also means properties with ref values will not be automatically
|
|
213
|
+
* unwrapped.
|
|
214
|
+
*
|
|
215
|
+
* @param target - The source object.
|
|
216
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#shallowreadonly Vue `shallowReadonly()`}
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```js
|
|
220
|
+
* const state = shallowReadonly({
|
|
221
|
+
* foo: 1,
|
|
222
|
+
* nested: {
|
|
223
|
+
* bar: 2
|
|
224
|
+
* }
|
|
225
|
+
* })
|
|
226
|
+
*
|
|
227
|
+
* // mutating state's own properties will fail
|
|
228
|
+
* state.foo++
|
|
229
|
+
*
|
|
230
|
+
* // ...but works on nested objects
|
|
231
|
+
* isReadonly(state.nested) // false
|
|
232
|
+
*
|
|
233
|
+
* // works
|
|
234
|
+
* state.nested.bar++
|
|
235
|
+
* ```
|
|
236
|
+
*/
|
|
237
|
+
declare function shallowReadonly<T extends object>(target: T): Readonly<T>;
|
|
238
|
+
//#endregion
|
|
239
|
+
//#region src/ref.d.ts
|
|
240
|
+
type Ref<T = any, S = T> = Ref$2<T, S> & Ref$1<NonNullable<T>> & RefObject<NonNullable<T>>;
|
|
241
|
+
/**
|
|
242
|
+
* Takes an inner value and returns a reactive and mutable ref object, which
|
|
243
|
+
* has a single property `.value` that points to the inner value.
|
|
244
|
+
*
|
|
245
|
+
* @param value - The object to wrap in the ref.
|
|
246
|
+
* @see {@link https://vuejs.org/api/reactivity-core.html#ref Vue `ref()`}
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
* ```js
|
|
250
|
+
* const count = ref(0)
|
|
251
|
+
* console.log(count.value) // 0
|
|
252
|
+
*
|
|
253
|
+
* count.value = 1
|
|
254
|
+
* console.log(count.value) // 1
|
|
255
|
+
* ```
|
|
256
|
+
*/
|
|
257
|
+
declare function ref<T>(value: T): [T] extends [Ref] ? IfAny<T, Ref<T>, T> : Ref<UnwrapRef<T>, UnwrapRef<T> | T>;
|
|
258
|
+
declare function ref<T = any>(): Ref<T | undefined>;
|
|
259
|
+
/**
|
|
260
|
+
* Creates a customized ref with explicit control over its dependency tracking
|
|
261
|
+
* and updates triggering.
|
|
262
|
+
*
|
|
263
|
+
* @param factory - The function that receives the `track` and `trigger` callbacks.
|
|
264
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#customref Vue `customRef()`}
|
|
265
|
+
*/
|
|
266
|
+
declare function customRef<T>(factory: CustomRefFactory<T>): Ref<T>;
|
|
267
|
+
/**
|
|
268
|
+
*
|
|
269
|
+
* @param value - The "inner value" for the shallow ref.
|
|
270
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#shallowref Vue `shallowRef()`}
|
|
271
|
+
*
|
|
272
|
+
* @example
|
|
273
|
+
* ```js
|
|
274
|
+
* const state = shallowRef({ count: 1 })
|
|
275
|
+
* // does NOT trigger change
|
|
276
|
+
* state.value.count = 2
|
|
277
|
+
* // does trigger change
|
|
278
|
+
* state.value = { count: 2 }
|
|
279
|
+
* ```
|
|
280
|
+
*/
|
|
281
|
+
declare function shallowRef<T>(value: T): Ref extends T ? (T extends Ref ? IfAny<T, ShallowRef<T>, T> : ShallowRef<T>) : ShallowRef<T>;
|
|
282
|
+
declare function shallowRef<T = any>(): ShallowRef<T | undefined>;
|
|
283
|
+
//#endregion
|
|
284
|
+
//#region src/watch.d.ts
|
|
285
|
+
interface WatchOptions<Immediate = boolean> extends DebuggerOptions {
|
|
286
|
+
immediate?: Immediate;
|
|
287
|
+
deep?: boolean | number;
|
|
288
|
+
once?: boolean;
|
|
289
|
+
}
|
|
290
|
+
type MultiWatchSources = (WatchSource<unknown> | object)[];
|
|
291
|
+
type MaybeUndefined<T, I> = I extends true ? T | undefined : T;
|
|
292
|
+
type MapSources<T, Immediate> = { [K in keyof T]: T[K] extends WatchSource<infer V> ? MaybeUndefined<V, Immediate> : T[K] extends object ? MaybeUndefined<T[K], Immediate> : never };
|
|
293
|
+
/**
|
|
294
|
+
* Watches one or more reactive data sources and invokes a callback function when the sources change.
|
|
295
|
+
*
|
|
296
|
+
* @param source - The watcher's source.
|
|
297
|
+
* @param callback - This function will be called when the source is changed.
|
|
298
|
+
* @param options - An optional options object that does not support the `flush` option compared to Vue (3.5.0).
|
|
299
|
+
* @see {@link https://vuejs.org/api/reactivity-core.html#watch Vue `watch()`}
|
|
300
|
+
*
|
|
301
|
+
* @example
|
|
302
|
+
* ```js
|
|
303
|
+
* const count = ref(0)
|
|
304
|
+
* watch(count, (count, prevCount) => {
|
|
305
|
+
* // ...
|
|
306
|
+
* })
|
|
307
|
+
* ```
|
|
308
|
+
*/
|
|
309
|
+
declare function watch<T, Immediate extends Readonly<boolean> = false>(source: WatchSource<T>, callback: WatchCallback<T, MaybeUndefined<T, Immediate>>, options?: WatchOptions<Immediate>): WatchHandle;
|
|
310
|
+
declare function watch<T extends Readonly<MultiWatchSources>, Immediate extends Readonly<boolean> = false>(sources: readonly [...T] | T, callback: [T] extends [ReactiveMarker] ? WatchCallback<T, MaybeUndefined<T, Immediate>> : WatchCallback<MapSources<T, false>, MapSources<T, Immediate>>, options?: WatchOptions<Immediate>): WatchHandle;
|
|
311
|
+
declare function watch<T extends MultiWatchSources, Immediate extends Readonly<boolean> = false>(sources: [...T], callback: WatchCallback<MapSources<T, false>, MapSources<T, Immediate>>, options?: WatchOptions<Immediate>): WatchHandle;
|
|
312
|
+
declare function watch<T extends object, Immediate extends Readonly<boolean> = false>(source: T, callback: WatchCallback<T, MaybeUndefined<T, Immediate>>, options?: WatchOptions<Immediate>): WatchHandle;
|
|
313
|
+
//#endregion
|
|
314
|
+
//#region src/watchEffect.d.ts
|
|
315
|
+
type WatchEffectOptions = DebuggerOptions;
|
|
316
|
+
/**
|
|
317
|
+
* Runs a function immediately while reactively tracking its dependencies and re-runs it whenever the dependencies are changed.
|
|
318
|
+
*
|
|
319
|
+
* @param effect - The effect function to run.
|
|
320
|
+
* @param options - An optional options object that can be used to adjust the effect's flush timing or to debug the effect's dependencies; the `flush` option is not supported compared to Vue (3.5.0).
|
|
321
|
+
* @see {@link https://vuejs.org/api/reactivity-core.html#watcheffect Vue `watchEffect()`}
|
|
322
|
+
*
|
|
323
|
+
* @example
|
|
324
|
+
* ```js
|
|
325
|
+
* const count = useRef(0)
|
|
326
|
+
* watchEffect(() => console.log(count.value))
|
|
327
|
+
* // -> logs 0
|
|
328
|
+
*
|
|
329
|
+
* count.value++
|
|
330
|
+
* // -> logs 1
|
|
331
|
+
* ```
|
|
332
|
+
*/
|
|
333
|
+
declare function watchEffect(effect: WatchEffect, options?: WatchEffectOptions): WatchHandle;
|
|
334
|
+
//#endregion
|
|
335
|
+
//#region src/index.d.ts
|
|
336
|
+
declare const getCurrentInstance: (...args: any) => any;
|
|
337
|
+
declare const hasInjectionContext: (...args: any) => any;
|
|
338
|
+
declare const inject: (...args: any) => any;
|
|
339
|
+
declare const provide: (...args: any) => any;
|
|
340
|
+
declare const nextTick: (...args: any) => any;
|
|
341
|
+
declare const defineComponent: (...args: any) => any;
|
|
342
|
+
declare const TransitionGroup: (...args: any) => any;
|
|
343
|
+
//#endregion
|
|
344
|
+
export { Fragment, MultiWatchSources, Ref, TransitionGroup, WatchEffectOptions, WatchOptions, computed, customRef, defineComponent, effectScope, getCurrentInstance, getCurrentScope, h, hasInjectionContext, inject, isProxy, isReactive, isReadonly, isRef, isShallow, markRaw, nextTick, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onMounted, onScopeDispose, onUnmounted, onUpdated, provide, reactive, reactivity, readonly, ref, shallowReactive, shallowReadonly, shallowRef, toRaw, toReactive, toReadonly, toRef, toRefs, toValue, unref, watch, watchEffect, withEffectScope };
|