@hairy/react-lib-composition 1.47.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
package/dist/index.cjs
CHANGED
|
@@ -1,487 +1,566 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
Fragment: () => import_react9.Fragment,
|
|
24
|
-
TransitionGroup: () => TransitionGroup,
|
|
25
|
-
computed: () => computed,
|
|
26
|
-
customRef: () => customRef,
|
|
27
|
-
defineComponent: () => defineComponent,
|
|
28
|
-
effectScope: () => effectScope,
|
|
29
|
-
getCurrentInstance: () => getCurrentInstance,
|
|
30
|
-
getCurrentScope: () => getCurrentScope,
|
|
31
|
-
h: () => import_react9.createElement,
|
|
32
|
-
hasInjectionContext: () => hasInjectionContext,
|
|
33
|
-
inject: () => inject,
|
|
34
|
-
isProxy: () => import_reactivity8.isProxy,
|
|
35
|
-
isReactive: () => import_reactivity8.isReactive,
|
|
36
|
-
isReadonly: () => import_reactivity8.isReadonly,
|
|
37
|
-
isRef: () => import_reactivity8.isRef,
|
|
38
|
-
isShallow: () => import_reactivity8.isShallow,
|
|
39
|
-
markRaw: () => import_reactivity8.markRaw,
|
|
40
|
-
nextTick: () => nextTick,
|
|
41
|
-
onBeforeMount: () => onBeforeMount,
|
|
42
|
-
onBeforeUnmount: () => onBeforeUnmount,
|
|
43
|
-
onBeforeUpdate: () => onBeforeUpdate,
|
|
44
|
-
onMounted: () => onMounted,
|
|
45
|
-
onScopeDispose: () => onScopeDispose,
|
|
46
|
-
onUnmounted: () => onUnmounted,
|
|
47
|
-
onUpdated: () => onUpdated,
|
|
48
|
-
provide: () => provide,
|
|
49
|
-
reactive: () => reactive,
|
|
50
|
-
reactivity: () => reactivity,
|
|
51
|
-
readonly: () => readonly,
|
|
52
|
-
ref: () => ref,
|
|
53
|
-
shallowReactive: () => shallowReactive,
|
|
54
|
-
shallowReadonly: () => shallowReadonly,
|
|
55
|
-
shallowRef: () => shallowRef,
|
|
56
|
-
toRaw: () => import_reactivity8.toRaw,
|
|
57
|
-
toReactive: () => import_reactivity8.toReactive,
|
|
58
|
-
toReadonly: () => import_reactivity8.toReadonly,
|
|
59
|
-
toRef: () => import_reactivity8.toRef,
|
|
60
|
-
toRefs: () => import_reactivity8.toRefs,
|
|
61
|
-
toValue: () => import_reactivity8.toValue,
|
|
62
|
-
unref: () => import_reactivity8.unref,
|
|
63
|
-
watch: () => watch,
|
|
64
|
-
watchEffect: () => watchEffect,
|
|
65
|
-
withEffectScope: () => withEffectScope
|
|
66
|
-
});
|
|
67
|
-
module.exports = __toCommonJS(index_exports);
|
|
68
|
-
|
|
69
|
-
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_freeGlobal.js
|
|
70
|
-
var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
|
|
71
|
-
var freeGlobal_default = freeGlobal;
|
|
72
|
-
|
|
73
|
-
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_root.js
|
|
74
|
-
var freeSelf = typeof self == "object" && self && self.Object === Object && self;
|
|
75
|
-
var root = freeGlobal_default || freeSelf || Function("return this")();
|
|
76
|
-
var root_default = root;
|
|
77
|
-
|
|
78
|
-
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_Symbol.js
|
|
79
|
-
var Symbol2 = root_default.Symbol;
|
|
80
|
-
var Symbol_default = Symbol2;
|
|
81
|
-
|
|
82
|
-
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_getRawTag.js
|
|
83
|
-
var objectProto = Object.prototype;
|
|
84
|
-
var hasOwnProperty = objectProto.hasOwnProperty;
|
|
85
|
-
var nativeObjectToString = objectProto.toString;
|
|
86
|
-
var symToStringTag = Symbol_default ? Symbol_default.toStringTag : void 0;
|
|
87
|
-
function getRawTag(value) {
|
|
88
|
-
var isOwn = hasOwnProperty.call(value, symToStringTag), tag = value[symToStringTag];
|
|
89
|
-
try {
|
|
90
|
-
value[symToStringTag] = void 0;
|
|
91
|
-
var unmasked = true;
|
|
92
|
-
} catch (e) {
|
|
93
|
-
}
|
|
94
|
-
var result = nativeObjectToString.call(value);
|
|
95
|
-
if (unmasked) {
|
|
96
|
-
if (isOwn) {
|
|
97
|
-
value[symToStringTag] = tag;
|
|
98
|
-
} else {
|
|
99
|
-
delete value[symToStringTag];
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return result;
|
|
103
|
-
}
|
|
104
|
-
var getRawTag_default = getRawTag;
|
|
105
|
-
|
|
106
|
-
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_objectToString.js
|
|
107
|
-
var objectProto2 = Object.prototype;
|
|
108
|
-
var nativeObjectToString2 = objectProto2.toString;
|
|
109
|
-
function objectToString(value) {
|
|
110
|
-
return nativeObjectToString2.call(value);
|
|
111
|
-
}
|
|
112
|
-
var objectToString_default = objectToString;
|
|
113
|
-
|
|
114
|
-
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_baseGetTag.js
|
|
115
|
-
var nullTag = "[object Null]";
|
|
116
|
-
var undefinedTag = "[object Undefined]";
|
|
117
|
-
var symToStringTag2 = Symbol_default ? Symbol_default.toStringTag : void 0;
|
|
118
|
-
function baseGetTag(value) {
|
|
119
|
-
if (value == null) {
|
|
120
|
-
return value === void 0 ? undefinedTag : nullTag;
|
|
121
|
-
}
|
|
122
|
-
return symToStringTag2 && symToStringTag2 in Object(value) ? getRawTag_default(value) : objectToString_default(value);
|
|
123
|
-
}
|
|
124
|
-
var baseGetTag_default = baseGetTag;
|
|
125
|
-
|
|
126
|
-
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isObject.js
|
|
127
|
-
function isObject(value) {
|
|
128
|
-
var type = typeof value;
|
|
129
|
-
return value != null && (type == "object" || type == "function");
|
|
130
|
-
}
|
|
131
|
-
var isObject_default = isObject;
|
|
132
|
-
|
|
133
|
-
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isFunction.js
|
|
134
|
-
var asyncTag = "[object AsyncFunction]";
|
|
135
|
-
var funcTag = "[object Function]";
|
|
136
|
-
var genTag = "[object GeneratorFunction]";
|
|
137
|
-
var proxyTag = "[object Proxy]";
|
|
138
|
-
function isFunction(value) {
|
|
139
|
-
if (!isObject_default(value)) {
|
|
140
|
-
return false;
|
|
141
|
-
}
|
|
142
|
-
var tag = baseGetTag_default(value);
|
|
143
|
-
return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
|
|
144
|
-
}
|
|
145
|
-
var isFunction_default = isFunction;
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
let _hairy_utils = require("@hairy/utils");
|
|
3
|
+
let react = require("react");
|
|
4
|
+
let _vue_reactivity = require("@vue/reactivity");
|
|
146
5
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
try {
|
|
155
|
-
return (0, import_react.useCallback)(callback, deps);
|
|
156
|
-
} catch {
|
|
157
|
-
return callback;
|
|
158
|
-
}
|
|
6
|
+
//#region ../lib-react/src/hooks/tryUseCallback.ts
|
|
7
|
+
const tryUseCallback = (callback, deps) => {
|
|
8
|
+
try {
|
|
9
|
+
return (0, react.useCallback)(callback, deps);
|
|
10
|
+
} catch {
|
|
11
|
+
return callback;
|
|
12
|
+
}
|
|
159
13
|
};
|
|
160
14
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
}
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region ../lib-react/src/hooks/tryUseEffect.ts
|
|
17
|
+
const tryUseEffect = (effect, deps) => {
|
|
18
|
+
try {
|
|
19
|
+
(0, react.useEffect)(effect, deps);
|
|
20
|
+
} catch {}
|
|
168
21
|
};
|
|
169
22
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
}
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region ../lib-react/src/hooks/tryUseInsertionEffect.ts
|
|
25
|
+
const tryUseInsertionEffect = (callback, deps) => {
|
|
26
|
+
try {
|
|
27
|
+
(0, react.useInsertionEffect)(callback, deps);
|
|
28
|
+
} catch {}
|
|
177
29
|
};
|
|
178
30
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
}
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region ../lib-react/src/hooks/tryUseReducer.ts
|
|
33
|
+
const tryUseReducer = (reducer, initializerArg, initializer) => {
|
|
34
|
+
try {
|
|
35
|
+
return (0, react.useReducer)(reducer, initializerArg, initializer);
|
|
36
|
+
} catch {
|
|
37
|
+
return [initializerArg, () => {}];
|
|
38
|
+
}
|
|
188
39
|
};
|
|
189
40
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region ../lib-react/src/hooks/tryUseRef.ts
|
|
43
|
+
const tryUseRef = (initialValue) => {
|
|
44
|
+
try {
|
|
45
|
+
return (0, react.useRef)(initialValue);
|
|
46
|
+
} catch {
|
|
47
|
+
return { current: initialValue };
|
|
48
|
+
}
|
|
198
49
|
};
|
|
199
50
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region ../lib-react/src/hooks/tryUseState.ts
|
|
53
|
+
const tryUseState = (initialState) => {
|
|
54
|
+
try {
|
|
55
|
+
return (0, react.useState)(initialState);
|
|
56
|
+
} catch {
|
|
57
|
+
return [(0, _hairy_utils.isFunction)(initialState) ? initialState() : initialState, _hairy_utils.noop];
|
|
58
|
+
}
|
|
208
59
|
};
|
|
209
60
|
|
|
210
|
-
|
|
211
|
-
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region ../lib-react/src/hooks/useUpdate.ts
|
|
63
|
+
const updateReducer = (num) => (num + 1) % 1e6;
|
|
212
64
|
function useUpdate() {
|
|
213
|
-
|
|
214
|
-
|
|
65
|
+
const [, update] = tryUseReducer(updateReducer, 0);
|
|
66
|
+
return update;
|
|
215
67
|
}
|
|
216
68
|
|
|
217
|
-
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region ../lib-react/src/hooks/tryUseUpdate.ts
|
|
218
71
|
function tryUseUpdate() {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
}
|
|
72
|
+
try {
|
|
73
|
+
return useUpdate();
|
|
74
|
+
} catch {
|
|
75
|
+
return () => {};
|
|
76
|
+
}
|
|
225
77
|
}
|
|
226
78
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region src/lifecycle.ts
|
|
81
|
+
/**
|
|
82
|
+
* The function is called right after the component is mounted.
|
|
83
|
+
*
|
|
84
|
+
* @param fn
|
|
85
|
+
* @see {@link https://react.dev/reference/react/Component#componentdidmount React `componentDidMount()`}
|
|
86
|
+
*/
|
|
234
87
|
function onMounted(fn) {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
88
|
+
tryUseEffect(() => {
|
|
89
|
+
fn();
|
|
90
|
+
}, []);
|
|
238
91
|
}
|
|
239
92
|
function onBeforeMount(fn) {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
93
|
+
const isMounted = tryUseRef(false);
|
|
94
|
+
if (!isMounted.current) {
|
|
95
|
+
fn();
|
|
96
|
+
isMounted.current = true;
|
|
97
|
+
}
|
|
245
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* The function is called right before the component is unmounted.
|
|
101
|
+
*
|
|
102
|
+
* @param fn
|
|
103
|
+
* @see {@link https://react.dev/reference/react/Component#componentwillunmount React `componentWillUnmount()`}
|
|
104
|
+
*/
|
|
246
105
|
function onBeforeUnmount(fn) {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
106
|
+
tryUseEffect(() => {
|
|
107
|
+
return () => {
|
|
108
|
+
fn();
|
|
109
|
+
};
|
|
110
|
+
}, []);
|
|
252
111
|
}
|
|
253
112
|
function onUnmounted(fn) {
|
|
254
|
-
|
|
113
|
+
onBeforeUnmount(() => setTimeout(fn, 0));
|
|
255
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* The function is called immediately after the component is re-rendered with updated props or state.
|
|
117
|
+
* This method is not invoked during the initial render.
|
|
118
|
+
*
|
|
119
|
+
* @param fn
|
|
120
|
+
* @see {@link https://react.dev/reference/react/Component#componentdidupdate React `componentDidUpdate()`}
|
|
121
|
+
*/
|
|
256
122
|
function onUpdated(fn) {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
123
|
+
const isMounted = tryUseRef(false);
|
|
124
|
+
tryUseEffect(() => {
|
|
125
|
+
isMounted.current ? fn() : isMounted.current = true;
|
|
126
|
+
});
|
|
261
127
|
}
|
|
262
128
|
function onBeforeUpdate(fn) {
|
|
263
|
-
|
|
129
|
+
tryUseInsertionEffect(fn);
|
|
264
130
|
}
|
|
265
131
|
|
|
266
|
-
|
|
132
|
+
//#endregion
|
|
133
|
+
//#region src/watch.ts
|
|
267
134
|
function watch(source, callback, options = {}) {
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
}, []);
|
|
289
|
-
!handle.current && create();
|
|
290
|
-
onMounted(create);
|
|
291
|
-
onBeforeUnmount(cancel);
|
|
292
|
-
return cancel;
|
|
135
|
+
const handle = tryUseRef(void 0);
|
|
136
|
+
const cancel = tryUseCallback(() => {
|
|
137
|
+
if (!handle.current) return;
|
|
138
|
+
handle.current();
|
|
139
|
+
handle.current = void 0;
|
|
140
|
+
}, []);
|
|
141
|
+
const create = tryUseCallback(() => {
|
|
142
|
+
handle.current && cancel();
|
|
143
|
+
handle.current = (0, _vue_reactivity.watch)(source, callback, {
|
|
144
|
+
...options,
|
|
145
|
+
scheduler: (job) => job()
|
|
146
|
+
});
|
|
147
|
+
cancel.pause = handle.current.pause;
|
|
148
|
+
cancel.resume = handle.current.resume;
|
|
149
|
+
cancel.stop = handle.current.stop;
|
|
150
|
+
}, []);
|
|
151
|
+
!handle.current && create();
|
|
152
|
+
onMounted(create);
|
|
153
|
+
onBeforeUnmount(cancel);
|
|
154
|
+
return cancel;
|
|
293
155
|
}
|
|
294
156
|
|
|
295
|
-
|
|
157
|
+
//#endregion
|
|
158
|
+
//#region src/computed.ts
|
|
296
159
|
function computed(arg1, arg2) {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
160
|
+
const [ref] = tryUseState(() => (0, _vue_reactivity.computed)(arg1, arg2));
|
|
161
|
+
watch(ref, tryUseUpdate());
|
|
162
|
+
return ref;
|
|
300
163
|
}
|
|
301
164
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
var activeEffectScope;
|
|
165
|
+
//#endregion
|
|
166
|
+
//#region src/effectScope.ts
|
|
167
|
+
let activeEffectScope;
|
|
306
168
|
function createVueEffectScope(...args) {
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
169
|
+
const scope = (0, _vue_reactivity.effectScope)(...args);
|
|
170
|
+
Reflect.set(scope, "parent", activeEffectScope);
|
|
171
|
+
if (!args[0] && activeEffectScope) {
|
|
172
|
+
const scopes = activeEffectScope.scopes || (activeEffectScope.scopes = []);
|
|
173
|
+
Reflect.set(scope, "index", scopes.push(scope) - 1);
|
|
174
|
+
}
|
|
175
|
+
return scope;
|
|
314
176
|
}
|
|
177
|
+
/**
|
|
178
|
+
* Creates an effect scope object which can capture the reactive effects (i.e.
|
|
179
|
+
* computed and watchers) created within it so that these effects can be
|
|
180
|
+
* disposed together. For detailed use cases of this API, please consult its
|
|
181
|
+
* corresponding {@link https://github.com/vuejs/rfcs/blob/master/active-rfcs/0041-reactivity-effect-scope.md | RFC}.
|
|
182
|
+
*
|
|
183
|
+
* @param detached - Can be used to create a "detached" effect scope.
|
|
184
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#effectscope Vue `effectScope()`}
|
|
185
|
+
*/
|
|
315
186
|
function effectScope(...args) {
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
}, []);
|
|
327
|
-
scope.run = runFn;
|
|
328
|
-
return scope;
|
|
187
|
+
const hasRun = tryUseRef(false);
|
|
188
|
+
const [scope] = tryUseState(() => createVueEffectScope(...args));
|
|
189
|
+
const originalRunRef = tryUseRef(scope.run);
|
|
190
|
+
scope.run = tryUseCallback((fn) => {
|
|
191
|
+
if (!hasRun.current) {
|
|
192
|
+
hasRun.current = true;
|
|
193
|
+
return originalRunRef.current.bind(scope)(fn);
|
|
194
|
+
} else return;
|
|
195
|
+
}, []);
|
|
196
|
+
return scope;
|
|
329
197
|
}
|
|
330
198
|
function withEffectScope(fn, detached) {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
199
|
+
let currentEffectScope;
|
|
200
|
+
return ((...props) => {
|
|
201
|
+
const scope = effectScope(detached);
|
|
202
|
+
const element = (0, react.createElement)(fn, ...props);
|
|
203
|
+
onBeforeMount(() => {
|
|
204
|
+
currentEffectScope = activeEffectScope;
|
|
205
|
+
activeEffectScope = scope;
|
|
206
|
+
});
|
|
207
|
+
onMounted(() => activeEffectScope = currentEffectScope);
|
|
208
|
+
onUnmounted(() => scope.stop());
|
|
209
|
+
return element;
|
|
210
|
+
});
|
|
343
211
|
}
|
|
212
|
+
/**
|
|
213
|
+
* Returns the current active effect scope if there is one.
|
|
214
|
+
*
|
|
215
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#getcurrentscope}
|
|
216
|
+
*/
|
|
344
217
|
function getCurrentScope() {
|
|
345
|
-
|
|
346
|
-
|
|
218
|
+
const [effectScope] = tryUseState(() => activeEffectScope || (0, _vue_reactivity.getCurrentScope)());
|
|
219
|
+
return effectScope;
|
|
347
220
|
}
|
|
221
|
+
/**
|
|
222
|
+
* Registers a dispose callback on the current active effect scope. The
|
|
223
|
+
* callback will be invoked when the associated effect scope is stopped.
|
|
224
|
+
*
|
|
225
|
+
* @param fn - The callback function to attach to the scope's cleanup.
|
|
226
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#onscopedispose}
|
|
227
|
+
*/
|
|
348
228
|
function onScopeDispose(fn, _failSilently = false) {
|
|
349
|
-
|
|
350
|
-
Reflect.get(activeEffectScope, "cleanups")?.push(fn);
|
|
229
|
+
if (activeEffectScope) Reflect.get(activeEffectScope, "cleanups")?.push(fn);
|
|
351
230
|
}
|
|
352
231
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
var import_react8 = require("react");
|
|
232
|
+
//#endregion
|
|
233
|
+
//#region src/reactive.ts
|
|
356
234
|
function reactive(target) {
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
235
|
+
const [value] = (0, react.useState)(() => (0, _vue_reactivity.reactive)(target));
|
|
236
|
+
watch(value, tryUseUpdate());
|
|
237
|
+
return value;
|
|
360
238
|
}
|
|
239
|
+
/**
|
|
240
|
+
* Shallow version of {@link reactive()}.
|
|
241
|
+
*
|
|
242
|
+
* Unlike {@link reactive()}, there is no deep conversion: only root-level
|
|
243
|
+
* properties are reactive for a shallow reactive object. Property values are
|
|
244
|
+
* stored and exposed as-is - this also means properties with ref values will
|
|
245
|
+
* not be automatically unwrapped.
|
|
246
|
+
*
|
|
247
|
+
* @param target - The source object.
|
|
248
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#shallowreactive Vue `shallowReactive()`}
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* ```js
|
|
252
|
+
* const state = shallowReactive({
|
|
253
|
+
* foo: 1,
|
|
254
|
+
* nested: {
|
|
255
|
+
* bar: 2
|
|
256
|
+
* }
|
|
257
|
+
* })
|
|
258
|
+
*
|
|
259
|
+
* // mutating state's own properties is reactive
|
|
260
|
+
* state.foo++
|
|
261
|
+
*
|
|
262
|
+
* // ...but does not convert nested objects
|
|
263
|
+
* isReactive(state.nested) // false
|
|
264
|
+
*
|
|
265
|
+
* // NOT reactive
|
|
266
|
+
* state.nested.bar++
|
|
267
|
+
* ```
|
|
268
|
+
*/
|
|
361
269
|
function shallowReactive(target) {
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
270
|
+
const [value] = (0, react.useState)(() => (0, _vue_reactivity.shallowReactive)(target));
|
|
271
|
+
watch(value, tryUseUpdate());
|
|
272
|
+
return value;
|
|
365
273
|
}
|
|
366
274
|
|
|
367
|
-
|
|
275
|
+
//#endregion
|
|
276
|
+
//#region src/reactivity.ts
|
|
277
|
+
/**
|
|
278
|
+
* Converts some of the 'raw Vue' data, which is not already wrapped in a hook,
|
|
279
|
+
* into reactive hook data to ensure proper reactivity within the component.
|
|
280
|
+
*
|
|
281
|
+
* @param getter - A function that returns the data to be deeply watched.
|
|
282
|
+
* @example
|
|
283
|
+
* ```tsx
|
|
284
|
+
* import React from 'react'
|
|
285
|
+
* import { ref, reactivity } from 'veact'
|
|
286
|
+
*
|
|
287
|
+
* const countRef = ref(0)
|
|
288
|
+
*
|
|
289
|
+
* export const Component: React.FC = () => {
|
|
290
|
+
* // Convert to a reactivity hook
|
|
291
|
+
* const count = reactivity(() => countRef)
|
|
292
|
+
* const increment = () => {
|
|
293
|
+
* count.value++
|
|
294
|
+
* }
|
|
295
|
+
*
|
|
296
|
+
* return (
|
|
297
|
+
* <div>
|
|
298
|
+
* <span>{count.value}</span>
|
|
299
|
+
* <button onClick={increment}>Increment</button>
|
|
300
|
+
* </div>
|
|
301
|
+
* )
|
|
302
|
+
* }
|
|
303
|
+
* ```
|
|
304
|
+
*/
|
|
368
305
|
function reactivity(getter) {
|
|
369
|
-
|
|
370
|
-
|
|
306
|
+
watch(() => getter(), tryUseUpdate(), { deep: true });
|
|
307
|
+
return getter();
|
|
371
308
|
}
|
|
372
309
|
|
|
373
|
-
|
|
374
|
-
|
|
310
|
+
//#endregion
|
|
311
|
+
//#region src/readonly.ts
|
|
312
|
+
/**
|
|
313
|
+
* Takes an object (reactive or plain) or a ref and returns a readonly proxy to
|
|
314
|
+
* the original.
|
|
315
|
+
*
|
|
316
|
+
* A readonly proxy is deep: any nested property accessed will be readonly as
|
|
317
|
+
* well. It also has the same ref-unwrapping behavior as {@link reactive()},
|
|
318
|
+
* except the unwrapped values will also be made readonly.
|
|
319
|
+
*
|
|
320
|
+
* @param target - The source object.
|
|
321
|
+
* @see {@link https://vuejs.org/api/reactivity-core.html#readonly Vue `readonly()`}
|
|
322
|
+
*
|
|
323
|
+
* @example
|
|
324
|
+
* ```js
|
|
325
|
+
* const original = reactive({ count: 0 })
|
|
326
|
+
* const copy = readonly(original)
|
|
327
|
+
*
|
|
328
|
+
* useWatchEffect(() => {
|
|
329
|
+
* // works for reactivity tracking
|
|
330
|
+
* console.log(copy.count)
|
|
331
|
+
* })
|
|
332
|
+
*
|
|
333
|
+
* // mutating original will trigger watchers relying on the copy
|
|
334
|
+
* original.count++
|
|
335
|
+
*
|
|
336
|
+
* // mutating the copy will fail and result in a warning
|
|
337
|
+
* copy.count++ // warning!
|
|
338
|
+
* ```
|
|
339
|
+
*/
|
|
375
340
|
function readonly(target) {
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
341
|
+
const [value] = tryUseState(() => (0, _vue_reactivity.readonly)(target));
|
|
342
|
+
watch(value, tryUseUpdate());
|
|
343
|
+
return value;
|
|
379
344
|
}
|
|
345
|
+
/**
|
|
346
|
+
* Shallow version of {@link readonly()}.
|
|
347
|
+
*
|
|
348
|
+
* Unlike {@link readonly()}, there is no deep conversion: only root-level
|
|
349
|
+
* properties are made readonly. Property values are stored and exposed as-is -
|
|
350
|
+
* this also means properties with ref values will not be automatically
|
|
351
|
+
* unwrapped.
|
|
352
|
+
*
|
|
353
|
+
* @param target - The source object.
|
|
354
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#shallowreadonly Vue `shallowReadonly()`}
|
|
355
|
+
*
|
|
356
|
+
* @example
|
|
357
|
+
* ```js
|
|
358
|
+
* const state = shallowReadonly({
|
|
359
|
+
* foo: 1,
|
|
360
|
+
* nested: {
|
|
361
|
+
* bar: 2
|
|
362
|
+
* }
|
|
363
|
+
* })
|
|
364
|
+
*
|
|
365
|
+
* // mutating state's own properties will fail
|
|
366
|
+
* state.foo++
|
|
367
|
+
*
|
|
368
|
+
* // ...but works on nested objects
|
|
369
|
+
* isReadonly(state.nested) // false
|
|
370
|
+
*
|
|
371
|
+
* // works
|
|
372
|
+
* state.nested.bar++
|
|
373
|
+
* ```
|
|
374
|
+
*/
|
|
380
375
|
function shallowReadonly(target) {
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
376
|
+
const [value] = tryUseState(() => (0, _vue_reactivity.shallowReadonly)(target));
|
|
377
|
+
watch(value, tryUseUpdate());
|
|
378
|
+
return value;
|
|
384
379
|
}
|
|
385
380
|
|
|
386
|
-
|
|
387
|
-
|
|
381
|
+
//#endregion
|
|
382
|
+
//#region src/ref.ts
|
|
388
383
|
function ref(initValue) {
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
384
|
+
const [ref] = tryUseState(() => {
|
|
385
|
+
const r = (0, _vue_reactivity.ref)(initValue);
|
|
386
|
+
Object.defineProperty(r, "current", { set: (value) => r.value = value });
|
|
387
|
+
return r;
|
|
388
|
+
});
|
|
389
|
+
watch(ref, tryUseUpdate(), { deep: true });
|
|
390
|
+
return ref;
|
|
396
391
|
}
|
|
392
|
+
/**
|
|
393
|
+
* Creates a customized ref with explicit control over its dependency tracking
|
|
394
|
+
* and updates triggering.
|
|
395
|
+
*
|
|
396
|
+
* @param factory - The function that receives the `track` and `trigger` callbacks.
|
|
397
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#customref Vue `customRef()`}
|
|
398
|
+
*/
|
|
397
399
|
function customRef(factory) {
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
400
|
+
const [ref] = tryUseState(() => (0, _vue_reactivity.customRef)(factory));
|
|
401
|
+
watch(ref, tryUseUpdate());
|
|
402
|
+
return ref;
|
|
401
403
|
}
|
|
402
404
|
function shallowRef(initValue) {
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
405
|
+
const [ref] = tryUseState(() => (0, _vue_reactivity.shallowRef)(initValue));
|
|
406
|
+
watch(ref, tryUseUpdate());
|
|
407
|
+
return ref;
|
|
406
408
|
}
|
|
407
409
|
|
|
408
|
-
|
|
409
|
-
|
|
410
|
+
//#endregion
|
|
411
|
+
//#region src/watchEffect.ts
|
|
412
|
+
/**
|
|
413
|
+
* Runs a function immediately while reactively tracking its dependencies and re-runs it whenever the dependencies are changed.
|
|
414
|
+
*
|
|
415
|
+
* @param effect - The effect function to run.
|
|
416
|
+
* @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).
|
|
417
|
+
* @see {@link https://vuejs.org/api/reactivity-core.html#watcheffect Vue `watchEffect()`}
|
|
418
|
+
*
|
|
419
|
+
* @example
|
|
420
|
+
* ```js
|
|
421
|
+
* const count = useRef(0)
|
|
422
|
+
* watchEffect(() => console.log(count.value))
|
|
423
|
+
* // -> logs 0
|
|
424
|
+
*
|
|
425
|
+
* count.value++
|
|
426
|
+
* // -> logs 1
|
|
427
|
+
* ```
|
|
428
|
+
*/
|
|
410
429
|
function watchEffect(effect, options = {}) {
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
430
|
+
const [watchHandle] = tryUseState(() => (0, _vue_reactivity.watch)(effect, null, {
|
|
431
|
+
...options,
|
|
432
|
+
scheduler: (job) => job()
|
|
433
|
+
}));
|
|
434
|
+
onBeforeUnmount(() => watchHandle.stop());
|
|
435
|
+
return watchHandle;
|
|
417
436
|
}
|
|
418
437
|
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
var TransitionGroup = noop;
|
|
429
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
430
|
-
0 && (module.exports = {
|
|
431
|
-
Fragment,
|
|
432
|
-
TransitionGroup,
|
|
433
|
-
computed,
|
|
434
|
-
customRef,
|
|
435
|
-
defineComponent,
|
|
436
|
-
effectScope,
|
|
437
|
-
getCurrentInstance,
|
|
438
|
-
getCurrentScope,
|
|
439
|
-
h,
|
|
440
|
-
hasInjectionContext,
|
|
441
|
-
inject,
|
|
442
|
-
isProxy,
|
|
443
|
-
isReactive,
|
|
444
|
-
isReadonly,
|
|
445
|
-
isRef,
|
|
446
|
-
isShallow,
|
|
447
|
-
markRaw,
|
|
448
|
-
nextTick,
|
|
449
|
-
onBeforeMount,
|
|
450
|
-
onBeforeUnmount,
|
|
451
|
-
onBeforeUpdate,
|
|
452
|
-
onMounted,
|
|
453
|
-
onScopeDispose,
|
|
454
|
-
onUnmounted,
|
|
455
|
-
onUpdated,
|
|
456
|
-
provide,
|
|
457
|
-
reactive,
|
|
458
|
-
reactivity,
|
|
459
|
-
readonly,
|
|
460
|
-
ref,
|
|
461
|
-
shallowReactive,
|
|
462
|
-
shallowReadonly,
|
|
463
|
-
shallowRef,
|
|
464
|
-
toRaw,
|
|
465
|
-
toReactive,
|
|
466
|
-
toReadonly,
|
|
467
|
-
toRef,
|
|
468
|
-
toRefs,
|
|
469
|
-
toValue,
|
|
470
|
-
unref,
|
|
471
|
-
watch,
|
|
472
|
-
watchEffect,
|
|
473
|
-
withEffectScope
|
|
474
|
-
});
|
|
475
|
-
/*! Bundled license information:
|
|
438
|
+
//#endregion
|
|
439
|
+
//#region src/index.ts
|
|
440
|
+
const getCurrentInstance = _hairy_utils.noop;
|
|
441
|
+
const hasInjectionContext = _hairy_utils.noop;
|
|
442
|
+
const inject = _hairy_utils.noop;
|
|
443
|
+
const provide = _hairy_utils.noop;
|
|
444
|
+
const nextTick = _hairy_utils.noop;
|
|
445
|
+
const defineComponent = _hairy_utils.noop;
|
|
446
|
+
const TransitionGroup = _hairy_utils.noop;
|
|
476
447
|
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
448
|
+
//#endregion
|
|
449
|
+
Object.defineProperty(exports, 'Fragment', {
|
|
450
|
+
enumerable: true,
|
|
451
|
+
get: function () {
|
|
452
|
+
return react.Fragment;
|
|
453
|
+
}
|
|
454
|
+
});
|
|
455
|
+
exports.TransitionGroup = TransitionGroup;
|
|
456
|
+
exports.computed = computed;
|
|
457
|
+
exports.customRef = customRef;
|
|
458
|
+
exports.defineComponent = defineComponent;
|
|
459
|
+
exports.effectScope = effectScope;
|
|
460
|
+
exports.getCurrentInstance = getCurrentInstance;
|
|
461
|
+
exports.getCurrentScope = getCurrentScope;
|
|
462
|
+
Object.defineProperty(exports, 'h', {
|
|
463
|
+
enumerable: true,
|
|
464
|
+
get: function () {
|
|
465
|
+
return react.createElement;
|
|
466
|
+
}
|
|
467
|
+
});
|
|
468
|
+
exports.hasInjectionContext = hasInjectionContext;
|
|
469
|
+
exports.inject = inject;
|
|
470
|
+
Object.defineProperty(exports, 'isProxy', {
|
|
471
|
+
enumerable: true,
|
|
472
|
+
get: function () {
|
|
473
|
+
return _vue_reactivity.isProxy;
|
|
474
|
+
}
|
|
475
|
+
});
|
|
476
|
+
Object.defineProperty(exports, 'isReactive', {
|
|
477
|
+
enumerable: true,
|
|
478
|
+
get: function () {
|
|
479
|
+
return _vue_reactivity.isReactive;
|
|
480
|
+
}
|
|
481
|
+
});
|
|
482
|
+
Object.defineProperty(exports, 'isReadonly', {
|
|
483
|
+
enumerable: true,
|
|
484
|
+
get: function () {
|
|
485
|
+
return _vue_reactivity.isReadonly;
|
|
486
|
+
}
|
|
487
|
+
});
|
|
488
|
+
Object.defineProperty(exports, 'isRef', {
|
|
489
|
+
enumerable: true,
|
|
490
|
+
get: function () {
|
|
491
|
+
return _vue_reactivity.isRef;
|
|
492
|
+
}
|
|
493
|
+
});
|
|
494
|
+
Object.defineProperty(exports, 'isShallow', {
|
|
495
|
+
enumerable: true,
|
|
496
|
+
get: function () {
|
|
497
|
+
return _vue_reactivity.isShallow;
|
|
498
|
+
}
|
|
499
|
+
});
|
|
500
|
+
Object.defineProperty(exports, 'markRaw', {
|
|
501
|
+
enumerable: true,
|
|
502
|
+
get: function () {
|
|
503
|
+
return _vue_reactivity.markRaw;
|
|
504
|
+
}
|
|
505
|
+
});
|
|
506
|
+
exports.nextTick = nextTick;
|
|
507
|
+
exports.onBeforeMount = onBeforeMount;
|
|
508
|
+
exports.onBeforeUnmount = onBeforeUnmount;
|
|
509
|
+
exports.onBeforeUpdate = onBeforeUpdate;
|
|
510
|
+
exports.onMounted = onMounted;
|
|
511
|
+
exports.onScopeDispose = onScopeDispose;
|
|
512
|
+
exports.onUnmounted = onUnmounted;
|
|
513
|
+
exports.onUpdated = onUpdated;
|
|
514
|
+
exports.provide = provide;
|
|
515
|
+
exports.reactive = reactive;
|
|
516
|
+
exports.reactivity = reactivity;
|
|
517
|
+
exports.readonly = readonly;
|
|
518
|
+
exports.ref = ref;
|
|
519
|
+
exports.shallowReactive = shallowReactive;
|
|
520
|
+
exports.shallowReadonly = shallowReadonly;
|
|
521
|
+
exports.shallowRef = shallowRef;
|
|
522
|
+
Object.defineProperty(exports, 'toRaw', {
|
|
523
|
+
enumerable: true,
|
|
524
|
+
get: function () {
|
|
525
|
+
return _vue_reactivity.toRaw;
|
|
526
|
+
}
|
|
527
|
+
});
|
|
528
|
+
Object.defineProperty(exports, 'toReactive', {
|
|
529
|
+
enumerable: true,
|
|
530
|
+
get: function () {
|
|
531
|
+
return _vue_reactivity.toReactive;
|
|
532
|
+
}
|
|
533
|
+
});
|
|
534
|
+
Object.defineProperty(exports, 'toReadonly', {
|
|
535
|
+
enumerable: true,
|
|
536
|
+
get: function () {
|
|
537
|
+
return _vue_reactivity.toReadonly;
|
|
538
|
+
}
|
|
539
|
+
});
|
|
540
|
+
Object.defineProperty(exports, 'toRef', {
|
|
541
|
+
enumerable: true,
|
|
542
|
+
get: function () {
|
|
543
|
+
return _vue_reactivity.toRef;
|
|
544
|
+
}
|
|
545
|
+
});
|
|
546
|
+
Object.defineProperty(exports, 'toRefs', {
|
|
547
|
+
enumerable: true,
|
|
548
|
+
get: function () {
|
|
549
|
+
return _vue_reactivity.toRefs;
|
|
550
|
+
}
|
|
551
|
+
});
|
|
552
|
+
Object.defineProperty(exports, 'toValue', {
|
|
553
|
+
enumerable: true,
|
|
554
|
+
get: function () {
|
|
555
|
+
return _vue_reactivity.toValue;
|
|
556
|
+
}
|
|
557
|
+
});
|
|
558
|
+
Object.defineProperty(exports, 'unref', {
|
|
559
|
+
enumerable: true,
|
|
560
|
+
get: function () {
|
|
561
|
+
return _vue_reactivity.unref;
|
|
562
|
+
}
|
|
563
|
+
});
|
|
564
|
+
exports.watch = watch;
|
|
565
|
+
exports.watchEffect = watchEffect;
|
|
566
|
+
exports.withEffectScope = withEffectScope;
|