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