@vueuse/shared 6.4.1 → 6.5.3
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/index.cjs +1005 -1020
- package/index.d.ts +13 -6
- package/index.iife.js +1006 -1021
- package/index.iife.min.js +1 -1
- package/index.mjs +1005 -1021
- package/package.json +2 -2
package/index.mjs
CHANGED
|
@@ -1,1118 +1,1102 @@
|
|
|
1
1
|
import { computed, unref, watch, ref, customRef, isVue3, isRef, effectScope, getCurrentScope, onScopeDispose, shallowRef, watchSyncEffect, readonly, reactive, toRef, isVue2, toRefs as toRefs$1, getCurrentInstance, onBeforeUnmount, onMounted, nextTick, onUnmounted } from 'vue-demi';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*
|
|
6
|
-
* @see https://vueuse.org/and
|
|
7
|
-
*/
|
|
8
|
-
function and(...args) {
|
|
9
|
-
return computed(() => args.every(i => unref(i)));
|
|
3
|
+
function and(...args) {
|
|
4
|
+
return computed(() => args.every((i) => unref(i)));
|
|
10
5
|
}
|
|
11
6
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
immediate: true,
|
|
31
|
-
});
|
|
32
|
-
return () => {
|
|
33
|
-
stop1();
|
|
34
|
-
stop2();
|
|
35
|
-
};
|
|
7
|
+
function biSyncRef(a, b) {
|
|
8
|
+
const flush = "sync";
|
|
9
|
+
const stop1 = watch(a, (newValue) => {
|
|
10
|
+
b.value = newValue;
|
|
11
|
+
}, {
|
|
12
|
+
flush,
|
|
13
|
+
immediate: true
|
|
14
|
+
});
|
|
15
|
+
const stop2 = watch(b, (newValue) => {
|
|
16
|
+
a.value = newValue;
|
|
17
|
+
}, {
|
|
18
|
+
flush,
|
|
19
|
+
immediate: true
|
|
20
|
+
});
|
|
21
|
+
return () => {
|
|
22
|
+
stop1();
|
|
23
|
+
stop2();
|
|
24
|
+
};
|
|
36
25
|
}
|
|
37
26
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
return v;
|
|
64
|
-
},
|
|
65
|
-
set() { },
|
|
66
|
-
};
|
|
67
|
-
});
|
|
27
|
+
function controlledComputed(source, fn) {
|
|
28
|
+
let v = void 0;
|
|
29
|
+
let track;
|
|
30
|
+
let trigger;
|
|
31
|
+
const dirty = ref(true);
|
|
32
|
+
watch(source, () => {
|
|
33
|
+
dirty.value = true;
|
|
34
|
+
trigger();
|
|
35
|
+
}, { flush: "sync" });
|
|
36
|
+
return customRef((_track, _trigger) => {
|
|
37
|
+
track = _track;
|
|
38
|
+
trigger = _trigger;
|
|
39
|
+
return {
|
|
40
|
+
get() {
|
|
41
|
+
if (dirty.value) {
|
|
42
|
+
v = fn();
|
|
43
|
+
dirty.value = false;
|
|
44
|
+
}
|
|
45
|
+
track();
|
|
46
|
+
return v;
|
|
47
|
+
},
|
|
48
|
+
set() {
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
});
|
|
68
52
|
}
|
|
69
53
|
|
|
70
|
-
function __onlyVue3(name =
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
54
|
+
function __onlyVue3(name = "this function") {
|
|
55
|
+
if (isVue3)
|
|
56
|
+
return;
|
|
57
|
+
throw new Error(`[VueUse] ${name} is only works on Vue 3.`);
|
|
74
58
|
}
|
|
75
59
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
return ref;
|
|
60
|
+
function extendRef(ref, extend, { enumerable = false, unwrap = true } = {}) {
|
|
61
|
+
__onlyVue3();
|
|
62
|
+
for (const [key, value] of Object.entries(extend)) {
|
|
63
|
+
if (key === "value")
|
|
64
|
+
continue;
|
|
65
|
+
if (isRef(value) && unwrap) {
|
|
66
|
+
Object.defineProperty(ref, key, {
|
|
67
|
+
get() {
|
|
68
|
+
return value.value;
|
|
69
|
+
},
|
|
70
|
+
set(v) {
|
|
71
|
+
value.value = v;
|
|
72
|
+
},
|
|
73
|
+
enumerable
|
|
74
|
+
});
|
|
75
|
+
} else {
|
|
76
|
+
Object.defineProperty(ref, key, { value, enumerable });
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return ref;
|
|
98
80
|
}
|
|
99
81
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
*/
|
|
146
|
-
const silentSet = (v) => set(v, false);
|
|
147
|
-
/**
|
|
148
|
-
* Get the value without tracked in the reactivity system.
|
|
149
|
-
*
|
|
150
|
-
* Alias for `untrackedGet()`
|
|
151
|
-
*/
|
|
152
|
-
const peek = () => get(false);
|
|
153
|
-
/**
|
|
154
|
-
* Set the value without triggering the reactivity system
|
|
155
|
-
*
|
|
156
|
-
* Alias for `silentSet(v)`
|
|
157
|
-
*/
|
|
158
|
-
const lay = (v) => set(v, false);
|
|
159
|
-
return extendRef(ref, {
|
|
160
|
-
get,
|
|
161
|
-
set,
|
|
162
|
-
untrackedGet,
|
|
163
|
-
silentSet,
|
|
164
|
-
peek,
|
|
165
|
-
lay,
|
|
166
|
-
}, { enumerable: true });
|
|
82
|
+
function controlledRef(initial, options = {}) {
|
|
83
|
+
let source = initial;
|
|
84
|
+
let track;
|
|
85
|
+
let trigger;
|
|
86
|
+
const ref = customRef((_track, _trigger) => {
|
|
87
|
+
track = _track;
|
|
88
|
+
trigger = _trigger;
|
|
89
|
+
return {
|
|
90
|
+
get() {
|
|
91
|
+
return get();
|
|
92
|
+
},
|
|
93
|
+
set(v) {
|
|
94
|
+
set(v);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
});
|
|
98
|
+
function get(tracking = true) {
|
|
99
|
+
if (tracking)
|
|
100
|
+
track();
|
|
101
|
+
return source;
|
|
102
|
+
}
|
|
103
|
+
function set(value, triggering = true) {
|
|
104
|
+
var _a, _b;
|
|
105
|
+
if (value === source)
|
|
106
|
+
return;
|
|
107
|
+
const old = source;
|
|
108
|
+
if (((_a = options.onBeforeChange) == null ? void 0 : _a.call(options, value, old)) === false)
|
|
109
|
+
return;
|
|
110
|
+
source = value;
|
|
111
|
+
(_b = options.onChanged) == null ? void 0 : _b.call(options, value, old);
|
|
112
|
+
if (triggering)
|
|
113
|
+
trigger();
|
|
114
|
+
}
|
|
115
|
+
const untrackedGet = () => get(false);
|
|
116
|
+
const silentSet = (v) => set(v, false);
|
|
117
|
+
const peek = () => get(false);
|
|
118
|
+
const lay = (v) => set(v, false);
|
|
119
|
+
return extendRef(ref, {
|
|
120
|
+
get,
|
|
121
|
+
set,
|
|
122
|
+
untrackedGet,
|
|
123
|
+
silentSet,
|
|
124
|
+
peek,
|
|
125
|
+
lay
|
|
126
|
+
}, { enumerable: true });
|
|
167
127
|
}
|
|
168
128
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
};
|
|
191
|
-
const trigger = (param) => {
|
|
192
|
-
fns.forEach(fn => fn(param));
|
|
193
|
-
};
|
|
194
|
-
return {
|
|
195
|
-
on,
|
|
196
|
-
off,
|
|
197
|
-
trigger,
|
|
198
|
-
};
|
|
129
|
+
function createEventHook() {
|
|
130
|
+
const fns = [];
|
|
131
|
+
const off = (fn) => {
|
|
132
|
+
const index = fns.indexOf(fn);
|
|
133
|
+
if (index !== -1)
|
|
134
|
+
fns.splice(index, 1);
|
|
135
|
+
};
|
|
136
|
+
const on = (fn) => {
|
|
137
|
+
fns.push(fn);
|
|
138
|
+
return {
|
|
139
|
+
off: () => off(fn)
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
const trigger = (param) => {
|
|
143
|
+
fns.forEach((fn) => fn(param));
|
|
144
|
+
};
|
|
145
|
+
return {
|
|
146
|
+
on,
|
|
147
|
+
off,
|
|
148
|
+
trigger
|
|
149
|
+
};
|
|
199
150
|
}
|
|
200
151
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
if (!initialized) {
|
|
213
|
-
state = scope.run(stateFactory);
|
|
214
|
-
initialized = true;
|
|
215
|
-
}
|
|
216
|
-
return state;
|
|
217
|
-
};
|
|
152
|
+
function createGlobalState(stateFactory) {
|
|
153
|
+
let initialized = false;
|
|
154
|
+
let state;
|
|
155
|
+
const scope = effectScope(true);
|
|
156
|
+
return () => {
|
|
157
|
+
if (!initialized) {
|
|
158
|
+
state = scope.run(stateFactory);
|
|
159
|
+
initialized = true;
|
|
160
|
+
}
|
|
161
|
+
return state;
|
|
162
|
+
};
|
|
218
163
|
}
|
|
219
164
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
if (getCurrentScope()) {
|
|
227
|
-
onScopeDispose(fn);
|
|
228
|
-
return true;
|
|
229
|
-
}
|
|
230
|
-
return false;
|
|
165
|
+
function tryOnScopeDispose(fn) {
|
|
166
|
+
if (getCurrentScope()) {
|
|
167
|
+
onScopeDispose(fn);
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
return false;
|
|
231
171
|
}
|
|
232
172
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
state = scope.run(() => composable(...args));
|
|
255
|
-
}
|
|
256
|
-
tryOnScopeDispose(dispose);
|
|
257
|
-
return state;
|
|
258
|
-
});
|
|
173
|
+
function createSharedComposable(composable) {
|
|
174
|
+
let subscribers = 0;
|
|
175
|
+
let state;
|
|
176
|
+
let scope;
|
|
177
|
+
const dispose = () => {
|
|
178
|
+
subscribers -= 1;
|
|
179
|
+
if (scope && subscribers <= 0) {
|
|
180
|
+
scope.stop();
|
|
181
|
+
state = void 0;
|
|
182
|
+
scope = void 0;
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
return (...args) => {
|
|
186
|
+
subscribers += 1;
|
|
187
|
+
if (!state) {
|
|
188
|
+
scope = effectScope(true);
|
|
189
|
+
state = scope.run(() => composable(...args));
|
|
190
|
+
}
|
|
191
|
+
tryOnScopeDispose(dispose);
|
|
192
|
+
return state;
|
|
193
|
+
};
|
|
259
194
|
}
|
|
260
195
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
}
|
|
285
|
-
return t;
|
|
286
|
-
}
|
|
196
|
+
const isClient = typeof window !== "undefined";
|
|
197
|
+
const isDef = (val) => typeof val !== "undefined";
|
|
198
|
+
const assert = (condition, ...infos) => {
|
|
199
|
+
if (!condition)
|
|
200
|
+
console.warn(...infos);
|
|
201
|
+
};
|
|
202
|
+
const toString = Object.prototype.toString;
|
|
203
|
+
const isBoolean = (val) => typeof val === "boolean";
|
|
204
|
+
const isFunction = (val) => typeof val === "function";
|
|
205
|
+
const isNumber = (val) => typeof val === "number";
|
|
206
|
+
const isString = (val) => typeof val === "string";
|
|
207
|
+
const isObject = (val) => toString.call(val) === "[object Object]";
|
|
208
|
+
const isWindow = (val) => typeof window !== "undefined" && toString.call(val) === "[object Window]";
|
|
209
|
+
const now = () => Date.now();
|
|
210
|
+
const timestamp = () => +Date.now();
|
|
211
|
+
const clamp = (n, min, max) => Math.min(max, Math.max(min, n));
|
|
212
|
+
const noop = () => {
|
|
213
|
+
};
|
|
214
|
+
const rand = (min, max) => {
|
|
215
|
+
min = Math.ceil(min);
|
|
216
|
+
max = Math.floor(max);
|
|
217
|
+
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
218
|
+
};
|
|
287
219
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
const isBoolean = (val) => typeof val === 'boolean';
|
|
297
|
-
const isFunction = (val) => typeof val === 'function';
|
|
298
|
-
const isNumber = (val) => typeof val === 'number';
|
|
299
|
-
const isString = (val) => typeof val === 'string';
|
|
300
|
-
const isObject = (val) => toString.call(val) === '[object Object]';
|
|
301
|
-
const isWindow = (val) => typeof window !== 'undefined' && toString.call(val) === '[object Window]';
|
|
302
|
-
const now = () => Date.now();
|
|
303
|
-
const timestamp = () => +Date.now();
|
|
304
|
-
const clamp = (n, min, max) => Math.min(max, Math.max(min, n));
|
|
305
|
-
const noop = () => { };
|
|
306
|
-
const rand = (min, max) => {
|
|
307
|
-
min = Math.ceil(min);
|
|
308
|
-
max = Math.floor(max);
|
|
309
|
-
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
220
|
+
function createFilterWrapper(filter, fn) {
|
|
221
|
+
function wrapper(...args) {
|
|
222
|
+
filter(() => fn.apply(this, args), { fn, thisArg: this, args });
|
|
223
|
+
}
|
|
224
|
+
return wrapper;
|
|
225
|
+
}
|
|
226
|
+
const bypassFilter = (invoke) => {
|
|
227
|
+
return invoke();
|
|
310
228
|
};
|
|
229
|
+
function debounceFilter(ms) {
|
|
230
|
+
let timer;
|
|
231
|
+
const filter = (invoke) => {
|
|
232
|
+
const duration = unref(ms);
|
|
233
|
+
if (timer)
|
|
234
|
+
clearTimeout(timer);
|
|
235
|
+
if (duration <= 0)
|
|
236
|
+
return invoke();
|
|
237
|
+
timer = setTimeout(invoke, duration);
|
|
238
|
+
};
|
|
239
|
+
return filter;
|
|
240
|
+
}
|
|
241
|
+
function throttleFilter(ms, trailing = true, leading = true) {
|
|
242
|
+
let lastExec = 0;
|
|
243
|
+
let timer;
|
|
244
|
+
let preventLeading = !leading;
|
|
245
|
+
const clear = () => {
|
|
246
|
+
if (timer) {
|
|
247
|
+
clearTimeout(timer);
|
|
248
|
+
timer = void 0;
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
const filter = (invoke) => {
|
|
252
|
+
const duration = unref(ms);
|
|
253
|
+
const elapsed = Date.now() - lastExec;
|
|
254
|
+
clear();
|
|
255
|
+
if (duration <= 0) {
|
|
256
|
+
lastExec = Date.now();
|
|
257
|
+
return invoke();
|
|
258
|
+
}
|
|
259
|
+
if (elapsed > duration) {
|
|
260
|
+
lastExec = Date.now();
|
|
261
|
+
if (preventLeading)
|
|
262
|
+
preventLeading = false;
|
|
263
|
+
else
|
|
264
|
+
invoke();
|
|
265
|
+
} else if (trailing) {
|
|
266
|
+
timer = setTimeout(() => {
|
|
267
|
+
lastExec = Date.now();
|
|
268
|
+
if (!leading)
|
|
269
|
+
preventLeading = true;
|
|
270
|
+
clear();
|
|
271
|
+
invoke();
|
|
272
|
+
}, duration);
|
|
273
|
+
}
|
|
274
|
+
if (!leading && !timer)
|
|
275
|
+
timer = setTimeout(() => preventLeading = true, duration);
|
|
276
|
+
};
|
|
277
|
+
return filter;
|
|
278
|
+
}
|
|
279
|
+
function pausableFilter(extendFilter = bypassFilter) {
|
|
280
|
+
const isActive = ref(true);
|
|
281
|
+
function pause() {
|
|
282
|
+
isActive.value = false;
|
|
283
|
+
}
|
|
284
|
+
function resume() {
|
|
285
|
+
isActive.value = true;
|
|
286
|
+
}
|
|
287
|
+
const eventFilter = (...args) => {
|
|
288
|
+
if (isActive.value)
|
|
289
|
+
extendFilter(...args);
|
|
290
|
+
};
|
|
291
|
+
return { isActive, pause, resume, eventFilter };
|
|
292
|
+
}
|
|
311
293
|
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
const
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
}
|
|
364
|
-
if (elapsed > duration) {
|
|
365
|
-
lastExec = Date.now();
|
|
366
|
-
invoke();
|
|
367
|
-
}
|
|
368
|
-
else if (trailing) {
|
|
369
|
-
timer = setTimeout(() => {
|
|
370
|
-
lastExec = Date.now();
|
|
371
|
-
clear();
|
|
372
|
-
invoke();
|
|
373
|
-
}, duration);
|
|
374
|
-
}
|
|
375
|
-
};
|
|
376
|
-
return filter;
|
|
377
|
-
}
|
|
378
|
-
/**
|
|
379
|
-
* EventFilter that gives extra controls to pause and resume the filter
|
|
380
|
-
*
|
|
381
|
-
* @param extendFilter Extra filter to apply when the PauseableFilter is active, default to none
|
|
382
|
-
*
|
|
383
|
-
*/
|
|
384
|
-
function pausableFilter(extendFilter = bypassFilter) {
|
|
385
|
-
const isActive = ref(true);
|
|
386
|
-
function pause() {
|
|
387
|
-
isActive.value = false;
|
|
388
|
-
}
|
|
389
|
-
function resume() {
|
|
390
|
-
isActive.value = true;
|
|
391
|
-
}
|
|
392
|
-
const eventFilter = (...args) => {
|
|
393
|
-
if (isActive.value)
|
|
394
|
-
extendFilter(...args);
|
|
395
|
-
};
|
|
396
|
-
return { isActive, pause, resume, eventFilter };
|
|
294
|
+
function promiseTimeout(ms, throwOnTimeout = false, reason = "Timeout") {
|
|
295
|
+
return new Promise((resolve, reject) => {
|
|
296
|
+
if (throwOnTimeout)
|
|
297
|
+
setTimeout(() => reject(reason), ms);
|
|
298
|
+
else
|
|
299
|
+
setTimeout(resolve, ms);
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
function identity(arg) {
|
|
303
|
+
return arg;
|
|
304
|
+
}
|
|
305
|
+
function createSingletonPromise(fn) {
|
|
306
|
+
let _promise;
|
|
307
|
+
function wrapper() {
|
|
308
|
+
if (!_promise)
|
|
309
|
+
_promise = fn();
|
|
310
|
+
return _promise;
|
|
311
|
+
}
|
|
312
|
+
wrapper.reset = async () => {
|
|
313
|
+
const _prev = _promise;
|
|
314
|
+
_promise = void 0;
|
|
315
|
+
if (_prev)
|
|
316
|
+
await _prev;
|
|
317
|
+
};
|
|
318
|
+
return wrapper;
|
|
319
|
+
}
|
|
320
|
+
function invoke(fn) {
|
|
321
|
+
return fn();
|
|
322
|
+
}
|
|
323
|
+
function containsProp(obj, ...props) {
|
|
324
|
+
return props.some((k) => k in obj);
|
|
325
|
+
}
|
|
326
|
+
function increaseWithUnit(target, delta) {
|
|
327
|
+
var _a;
|
|
328
|
+
if (typeof target === "number")
|
|
329
|
+
return target + delta;
|
|
330
|
+
const value = ((_a = target.match(/^-?[0-9]+\.?[0-9]*/)) == null ? void 0 : _a[0]) || "";
|
|
331
|
+
const unit = target.slice(value.length);
|
|
332
|
+
const result = parseFloat(value) + delta;
|
|
333
|
+
if (Number.isNaN(result))
|
|
334
|
+
return target;
|
|
335
|
+
return result + unit;
|
|
336
|
+
}
|
|
337
|
+
function objectPick(obj, keys, omitUndefined = false) {
|
|
338
|
+
return keys.reduce((n, k) => {
|
|
339
|
+
if (k in obj) {
|
|
340
|
+
if (!omitUndefined || !obj[k] === void 0)
|
|
341
|
+
n[k] = obj[k];
|
|
342
|
+
}
|
|
343
|
+
return n;
|
|
344
|
+
}, {});
|
|
397
345
|
}
|
|
398
346
|
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
*/
|
|
422
|
-
function createSingletonPromise(fn) {
|
|
423
|
-
let _promise;
|
|
424
|
-
function wrapper() {
|
|
425
|
-
if (!_promise)
|
|
426
|
-
_promise = fn();
|
|
427
|
-
return _promise;
|
|
428
|
-
}
|
|
429
|
-
wrapper.reset = async () => {
|
|
430
|
-
const _prev = _promise;
|
|
431
|
-
_promise = undefined;
|
|
432
|
-
if (_prev)
|
|
433
|
-
await _prev;
|
|
434
|
-
};
|
|
435
|
-
return wrapper;
|
|
436
|
-
}
|
|
437
|
-
function invoke(fn) {
|
|
438
|
-
return fn();
|
|
439
|
-
}
|
|
440
|
-
function containsProp(obj, ...props) {
|
|
441
|
-
return props.some(k => k in obj);
|
|
442
|
-
}
|
|
443
|
-
function increaseWithUnit(target, delta) {
|
|
444
|
-
var _a;
|
|
445
|
-
if (typeof target === 'number')
|
|
446
|
-
return target + delta;
|
|
447
|
-
const value = ((_a = target.match(/^-?[0-9]+\.?[0-9]*/)) === null || _a === void 0 ? void 0 : _a[0]) || '';
|
|
448
|
-
const unit = target.slice(value.length);
|
|
449
|
-
const result = (parseFloat(value) + delta);
|
|
450
|
-
if (Number.isNaN(result))
|
|
451
|
-
return target;
|
|
452
|
-
return result + unit;
|
|
453
|
-
}
|
|
454
|
-
/**
|
|
455
|
-
* Create a new subset object by giving keys
|
|
456
|
-
*
|
|
457
|
-
* @category Object
|
|
458
|
-
*/
|
|
459
|
-
function objectPick(obj, keys, omitUndefined = false) {
|
|
460
|
-
return keys.reduce((n, k) => {
|
|
461
|
-
if (k in obj)
|
|
462
|
-
if (!omitUndefined || !obj[k] === undefined)
|
|
463
|
-
n[k] = obj[k];
|
|
464
|
-
return n;
|
|
465
|
-
}, {});
|
|
347
|
+
var __getOwnPropSymbols$8 = Object.getOwnPropertySymbols;
|
|
348
|
+
var __hasOwnProp$8 = Object.prototype.hasOwnProperty;
|
|
349
|
+
var __propIsEnum$8 = Object.prototype.propertyIsEnumerable;
|
|
350
|
+
var __objRest$5 = (source, exclude) => {
|
|
351
|
+
var target = {};
|
|
352
|
+
for (var prop in source)
|
|
353
|
+
if (__hasOwnProp$8.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
354
|
+
target[prop] = source[prop];
|
|
355
|
+
if (source != null && __getOwnPropSymbols$8)
|
|
356
|
+
for (var prop of __getOwnPropSymbols$8(source)) {
|
|
357
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum$8.call(source, prop))
|
|
358
|
+
target[prop] = source[prop];
|
|
359
|
+
}
|
|
360
|
+
return target;
|
|
361
|
+
};
|
|
362
|
+
function watchWithFilter(source, cb, options = {}) {
|
|
363
|
+
const _a = options, {
|
|
364
|
+
eventFilter = bypassFilter
|
|
365
|
+
} = _a, watchOptions = __objRest$5(_a, [
|
|
366
|
+
"eventFilter"
|
|
367
|
+
]);
|
|
368
|
+
return watch(source, createFilterWrapper(eventFilter, cb), watchOptions);
|
|
466
369
|
}
|
|
467
370
|
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
371
|
+
var __defProp$6 = Object.defineProperty;
|
|
372
|
+
var __defProps$3 = Object.defineProperties;
|
|
373
|
+
var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
|
|
374
|
+
var __getOwnPropSymbols$7 = Object.getOwnPropertySymbols;
|
|
375
|
+
var __hasOwnProp$7 = Object.prototype.hasOwnProperty;
|
|
376
|
+
var __propIsEnum$7 = Object.prototype.propertyIsEnumerable;
|
|
377
|
+
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
378
|
+
var __spreadValues$6 = (a, b) => {
|
|
379
|
+
for (var prop in b || (b = {}))
|
|
380
|
+
if (__hasOwnProp$7.call(b, prop))
|
|
381
|
+
__defNormalProp$6(a, prop, b[prop]);
|
|
382
|
+
if (__getOwnPropSymbols$7)
|
|
383
|
+
for (var prop of __getOwnPropSymbols$7(b)) {
|
|
384
|
+
if (__propIsEnum$7.call(b, prop))
|
|
385
|
+
__defNormalProp$6(a, prop, b[prop]);
|
|
386
|
+
}
|
|
387
|
+
return a;
|
|
388
|
+
};
|
|
389
|
+
var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
|
|
390
|
+
var __objRest$4 = (source, exclude) => {
|
|
391
|
+
var target = {};
|
|
392
|
+
for (var prop in source)
|
|
393
|
+
if (__hasOwnProp$7.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
394
|
+
target[prop] = source[prop];
|
|
395
|
+
if (source != null && __getOwnPropSymbols$7)
|
|
396
|
+
for (var prop of __getOwnPropSymbols$7(source)) {
|
|
397
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum$7.call(source, prop))
|
|
398
|
+
target[prop] = source[prop];
|
|
399
|
+
}
|
|
400
|
+
return target;
|
|
401
|
+
};
|
|
402
|
+
function debouncedWatch(source, cb, options = {}) {
|
|
403
|
+
const _a = options, {
|
|
404
|
+
debounce = 0
|
|
405
|
+
} = _a, watchOptions = __objRest$4(_a, [
|
|
406
|
+
"debounce"
|
|
407
|
+
]);
|
|
408
|
+
return watchWithFilter(source, cb, __spreadProps$3(__spreadValues$6({}, watchOptions), {
|
|
409
|
+
eventFilter: debounceFilter(debounce)
|
|
410
|
+
}));
|
|
472
411
|
}
|
|
473
412
|
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
413
|
+
function eagerComputed(fn) {
|
|
414
|
+
const result = shallowRef();
|
|
415
|
+
watchSyncEffect(() => {
|
|
416
|
+
result.value = fn();
|
|
417
|
+
});
|
|
418
|
+
return readonly(result);
|
|
478
419
|
}
|
|
479
420
|
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
result.value = fn();
|
|
485
|
-
});
|
|
486
|
-
return readonly(result);
|
|
421
|
+
function get(obj, key) {
|
|
422
|
+
if (key == null)
|
|
423
|
+
return unref(obj);
|
|
424
|
+
return unref(obj)[key];
|
|
487
425
|
}
|
|
488
426
|
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
427
|
+
var __defProp$5 = Object.defineProperty;
|
|
428
|
+
var __defProps$2 = Object.defineProperties;
|
|
429
|
+
var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
|
|
430
|
+
var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
|
|
431
|
+
var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
|
|
432
|
+
var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
|
|
433
|
+
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
434
|
+
var __spreadValues$5 = (a, b) => {
|
|
435
|
+
for (var prop in b || (b = {}))
|
|
436
|
+
if (__hasOwnProp$6.call(b, prop))
|
|
437
|
+
__defNormalProp$5(a, prop, b[prop]);
|
|
438
|
+
if (__getOwnPropSymbols$6)
|
|
439
|
+
for (var prop of __getOwnPropSymbols$6(b)) {
|
|
440
|
+
if (__propIsEnum$6.call(b, prop))
|
|
441
|
+
__defNormalProp$5(a, prop, b[prop]);
|
|
442
|
+
}
|
|
443
|
+
return a;
|
|
444
|
+
};
|
|
445
|
+
var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
|
|
446
|
+
var __objRest$3 = (source, exclude) => {
|
|
447
|
+
var target = {};
|
|
448
|
+
for (var prop in source)
|
|
449
|
+
if (__hasOwnProp$6.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
450
|
+
target[prop] = source[prop];
|
|
451
|
+
if (source != null && __getOwnPropSymbols$6)
|
|
452
|
+
for (var prop of __getOwnPropSymbols$6(source)) {
|
|
453
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum$6.call(source, prop))
|
|
454
|
+
target[prop] = source[prop];
|
|
455
|
+
}
|
|
456
|
+
return target;
|
|
457
|
+
};
|
|
458
|
+
function ignorableWatch(source, cb, options = {}) {
|
|
459
|
+
const _a = options, {
|
|
460
|
+
eventFilter = bypassFilter
|
|
461
|
+
} = _a, watchOptions = __objRest$3(_a, [
|
|
462
|
+
"eventFilter"
|
|
463
|
+
]);
|
|
464
|
+
const filteredCb = createFilterWrapper(eventFilter, cb);
|
|
465
|
+
let ignoreUpdates;
|
|
466
|
+
let ignorePrevAsyncUpdates;
|
|
467
|
+
let stop;
|
|
468
|
+
if (watchOptions.flush === "sync") {
|
|
469
|
+
const ignore = ref(false);
|
|
470
|
+
ignorePrevAsyncUpdates = () => {
|
|
471
|
+
};
|
|
472
|
+
ignoreUpdates = (updater) => {
|
|
473
|
+
ignore.value = true;
|
|
474
|
+
updater();
|
|
475
|
+
ignore.value = false;
|
|
476
|
+
};
|
|
477
|
+
stop = watch(source, (...args) => {
|
|
478
|
+
if (!ignore.value)
|
|
479
|
+
filteredCb(...args);
|
|
480
|
+
}, watchOptions);
|
|
481
|
+
} else {
|
|
482
|
+
const disposables = [];
|
|
483
|
+
const ignoreCounter = ref(0);
|
|
484
|
+
const syncCounter = ref(0);
|
|
485
|
+
ignorePrevAsyncUpdates = () => {
|
|
486
|
+
ignoreCounter.value = syncCounter.value;
|
|
487
|
+
};
|
|
488
|
+
disposables.push(watch(source, () => {
|
|
489
|
+
syncCounter.value++;
|
|
490
|
+
}, __spreadProps$2(__spreadValues$5({}, watchOptions), { flush: "sync" })));
|
|
491
|
+
ignoreUpdates = (updater) => {
|
|
492
|
+
const syncCounterPrev = syncCounter.value;
|
|
493
|
+
updater();
|
|
494
|
+
ignoreCounter.value += syncCounter.value - syncCounterPrev;
|
|
495
|
+
};
|
|
496
|
+
disposables.push(watch(source, (...args) => {
|
|
497
|
+
const ignore = ignoreCounter.value > 0 && ignoreCounter.value === syncCounter.value;
|
|
498
|
+
ignoreCounter.value = 0;
|
|
499
|
+
syncCounter.value = 0;
|
|
500
|
+
if (ignore)
|
|
501
|
+
return;
|
|
502
|
+
filteredCb(...args);
|
|
503
|
+
}, watchOptions));
|
|
504
|
+
stop = () => {
|
|
505
|
+
disposables.forEach((fn) => fn());
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
return { stop, ignoreUpdates, ignorePrevAsyncUpdates };
|
|
493
509
|
}
|
|
494
510
|
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
const syncCounter = ref(0);
|
|
531
|
-
ignorePrevAsyncUpdates = () => {
|
|
532
|
-
ignoreCounter.value = syncCounter.value;
|
|
533
|
-
};
|
|
534
|
-
// Sync watch to count modifications to the source
|
|
535
|
-
disposables.push(watch(source, () => {
|
|
536
|
-
syncCounter.value++;
|
|
537
|
-
}, Object.assign(Object.assign({}, watchOptions), { flush: 'sync' })));
|
|
538
|
-
ignoreUpdates = (updater) => {
|
|
539
|
-
// Call the updater function and count how many sync updates are performed,
|
|
540
|
-
// then add them to the ignore count
|
|
541
|
-
const syncCounterPrev = syncCounter.value;
|
|
542
|
-
updater();
|
|
543
|
-
ignoreCounter.value += syncCounter.value - syncCounterPrev;
|
|
544
|
-
};
|
|
545
|
-
disposables.push(watch(source, (...args) => {
|
|
546
|
-
// If a history operation was performed (ignoreCounter > 0) and there are
|
|
547
|
-
// no other changes to the source ref value afterwards, then ignore this commit
|
|
548
|
-
const ignore = ignoreCounter.value > 0 && ignoreCounter.value === syncCounter.value;
|
|
549
|
-
ignoreCounter.value = 0;
|
|
550
|
-
syncCounter.value = 0;
|
|
551
|
-
if (ignore)
|
|
552
|
-
return;
|
|
553
|
-
filteredCb(...args);
|
|
554
|
-
}, watchOptions));
|
|
555
|
-
stop = () => {
|
|
556
|
-
disposables.forEach(fn => fn());
|
|
557
|
-
};
|
|
558
|
-
}
|
|
559
|
-
return { stop, ignoreUpdates, ignorePrevAsyncUpdates };
|
|
511
|
+
var __defProp$4 = Object.defineProperty;
|
|
512
|
+
var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
|
|
513
|
+
var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
|
|
514
|
+
var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
|
|
515
|
+
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
516
|
+
var __spreadValues$4 = (a, b) => {
|
|
517
|
+
for (var prop in b || (b = {}))
|
|
518
|
+
if (__hasOwnProp$5.call(b, prop))
|
|
519
|
+
__defNormalProp$4(a, prop, b[prop]);
|
|
520
|
+
if (__getOwnPropSymbols$5)
|
|
521
|
+
for (var prop of __getOwnPropSymbols$5(b)) {
|
|
522
|
+
if (__propIsEnum$5.call(b, prop))
|
|
523
|
+
__defNormalProp$4(a, prop, b[prop]);
|
|
524
|
+
}
|
|
525
|
+
return a;
|
|
526
|
+
};
|
|
527
|
+
function makeDestructurable(obj, arr) {
|
|
528
|
+
if (typeof Symbol !== "undefined") {
|
|
529
|
+
const clone = __spreadValues$4({}, obj);
|
|
530
|
+
Object.defineProperty(clone, Symbol.iterator, {
|
|
531
|
+
enumerable: false,
|
|
532
|
+
value() {
|
|
533
|
+
let index = 0;
|
|
534
|
+
return {
|
|
535
|
+
next: () => ({
|
|
536
|
+
value: arr[index++],
|
|
537
|
+
done: index > arr.length
|
|
538
|
+
})
|
|
539
|
+
};
|
|
540
|
+
}
|
|
541
|
+
});
|
|
542
|
+
return clone;
|
|
543
|
+
} else {
|
|
544
|
+
return Object.assign([...arr], obj);
|
|
545
|
+
}
|
|
560
546
|
}
|
|
561
547
|
|
|
562
|
-
function
|
|
563
|
-
|
|
564
|
-
const clone = Object.assign({}, obj);
|
|
565
|
-
Object.defineProperty(clone, Symbol.iterator, {
|
|
566
|
-
enumerable: false,
|
|
567
|
-
value() {
|
|
568
|
-
let index = 0;
|
|
569
|
-
return {
|
|
570
|
-
next: () => ({
|
|
571
|
-
value: arr[index++],
|
|
572
|
-
done: index > arr.length,
|
|
573
|
-
}),
|
|
574
|
-
};
|
|
575
|
-
},
|
|
576
|
-
});
|
|
577
|
-
return clone;
|
|
578
|
-
}
|
|
579
|
-
else {
|
|
580
|
-
return Object.assign([...arr], obj);
|
|
581
|
-
}
|
|
548
|
+
function not(v) {
|
|
549
|
+
return computed(() => !unref(v));
|
|
582
550
|
}
|
|
583
551
|
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
*
|
|
587
|
-
* @see https://vueuse.org/not
|
|
588
|
-
*/
|
|
589
|
-
function not(v) {
|
|
590
|
-
return computed(() => !unref(v));
|
|
552
|
+
function or(...args) {
|
|
553
|
+
return computed(() => args.some((i) => unref(i)));
|
|
591
554
|
}
|
|
592
555
|
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
556
|
+
var __defProp$3 = Object.defineProperty;
|
|
557
|
+
var __defProps$1 = Object.defineProperties;
|
|
558
|
+
var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
|
|
559
|
+
var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
|
|
560
|
+
var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
|
|
561
|
+
var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
|
|
562
|
+
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
563
|
+
var __spreadValues$3 = (a, b) => {
|
|
564
|
+
for (var prop in b || (b = {}))
|
|
565
|
+
if (__hasOwnProp$4.call(b, prop))
|
|
566
|
+
__defNormalProp$3(a, prop, b[prop]);
|
|
567
|
+
if (__getOwnPropSymbols$4)
|
|
568
|
+
for (var prop of __getOwnPropSymbols$4(b)) {
|
|
569
|
+
if (__propIsEnum$4.call(b, prop))
|
|
570
|
+
__defNormalProp$3(a, prop, b[prop]);
|
|
571
|
+
}
|
|
572
|
+
return a;
|
|
573
|
+
};
|
|
574
|
+
var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
|
|
575
|
+
var __objRest$2 = (source, exclude) => {
|
|
576
|
+
var target = {};
|
|
577
|
+
for (var prop in source)
|
|
578
|
+
if (__hasOwnProp$4.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
579
|
+
target[prop] = source[prop];
|
|
580
|
+
if (source != null && __getOwnPropSymbols$4)
|
|
581
|
+
for (var prop of __getOwnPropSymbols$4(source)) {
|
|
582
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum$4.call(source, prop))
|
|
583
|
+
target[prop] = source[prop];
|
|
584
|
+
}
|
|
585
|
+
return target;
|
|
586
|
+
};
|
|
587
|
+
function pausableWatch(source, cb, options = {}) {
|
|
588
|
+
const _a = options, {
|
|
589
|
+
eventFilter: filter
|
|
590
|
+
} = _a, watchOptions = __objRest$2(_a, [
|
|
591
|
+
"eventFilter"
|
|
592
|
+
]);
|
|
593
|
+
const { eventFilter, pause, resume, isActive } = pausableFilter(filter);
|
|
594
|
+
const stop = watchWithFilter(source, cb, __spreadProps$1(__spreadValues$3({}, watchOptions), {
|
|
595
|
+
eventFilter
|
|
596
|
+
}));
|
|
597
|
+
return { stop, pause, resume, isActive };
|
|
600
598
|
}
|
|
601
599
|
|
|
602
|
-
|
|
603
|
-
function
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
const stop = watchWithFilter(source, cb, Object.assign(Object.assign({}, watchOptions), { eventFilter }));
|
|
607
|
-
return { stop, pause, resume, isActive };
|
|
600
|
+
function reactify(fn) {
|
|
601
|
+
return function(...args) {
|
|
602
|
+
return computed(() => fn.apply(this, args.map((i) => unref(i))));
|
|
603
|
+
};
|
|
608
604
|
}
|
|
609
605
|
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
606
|
+
function reactifyObject(obj, optionsOrKeys = {}) {
|
|
607
|
+
let keys = [];
|
|
608
|
+
if (Array.isArray(optionsOrKeys)) {
|
|
609
|
+
keys = optionsOrKeys;
|
|
610
|
+
} else {
|
|
611
|
+
const { includeOwnProperties = true } = optionsOrKeys;
|
|
612
|
+
keys.push(...Object.keys(obj));
|
|
613
|
+
if (includeOwnProperties)
|
|
614
|
+
keys.push(...Object.getOwnPropertyNames(obj));
|
|
615
|
+
}
|
|
616
|
+
return Object.fromEntries(keys.map((key) => {
|
|
617
|
+
const value = obj[key];
|
|
618
|
+
return [
|
|
619
|
+
key,
|
|
620
|
+
typeof value === "function" ? reactify(value.bind(obj)) : value
|
|
621
|
+
];
|
|
622
|
+
}));
|
|
621
623
|
}
|
|
622
624
|
|
|
623
|
-
function
|
|
624
|
-
|
|
625
|
-
if (Array.isArray(optionsOrKeys)) {
|
|
626
|
-
keys = optionsOrKeys;
|
|
627
|
-
}
|
|
628
|
-
else {
|
|
629
|
-
const { includeOwnProperties = true } = optionsOrKeys;
|
|
630
|
-
keys.push(...Object.keys(obj));
|
|
631
|
-
if (includeOwnProperties)
|
|
632
|
-
keys.push(...Object.getOwnPropertyNames(obj));
|
|
633
|
-
}
|
|
634
|
-
return Object.fromEntries(keys
|
|
635
|
-
.map((key) => {
|
|
636
|
-
const value = obj[key];
|
|
637
|
-
return [
|
|
638
|
-
key,
|
|
639
|
-
typeof value === 'function'
|
|
640
|
-
? reactify(value.bind(obj))
|
|
641
|
-
: value,
|
|
642
|
-
];
|
|
643
|
-
}));
|
|
625
|
+
function reactivePick(obj, ...keys) {
|
|
626
|
+
return reactive(Object.fromEntries(keys.map((k) => [k, toRef(obj, k)])));
|
|
644
627
|
}
|
|
645
628
|
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
629
|
+
function set(...args) {
|
|
630
|
+
if (args.length === 2) {
|
|
631
|
+
const [ref, value] = args;
|
|
632
|
+
ref.value = value;
|
|
633
|
+
}
|
|
634
|
+
if (args.length === 3) {
|
|
635
|
+
if (isVue2) {
|
|
636
|
+
require("vue-demi").set(...args);
|
|
637
|
+
} else {
|
|
638
|
+
const [target, key, value] = args;
|
|
639
|
+
target[key] = value;
|
|
640
|
+
}
|
|
641
|
+
}
|
|
653
642
|
}
|
|
654
643
|
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
else {
|
|
670
|
-
const [target, key, value] = args;
|
|
671
|
-
target[key] = value;
|
|
672
|
-
}
|
|
673
|
-
}
|
|
644
|
+
function syncRef(source, targets, {
|
|
645
|
+
flush = "sync",
|
|
646
|
+
deep = false,
|
|
647
|
+
immediate = true
|
|
648
|
+
} = {}) {
|
|
649
|
+
if (!Array.isArray(targets))
|
|
650
|
+
targets = [targets];
|
|
651
|
+
return watch(source, (newValue) => {
|
|
652
|
+
targets.forEach((target) => target.value = newValue);
|
|
653
|
+
}, {
|
|
654
|
+
flush,
|
|
655
|
+
deep,
|
|
656
|
+
immediate
|
|
657
|
+
});
|
|
674
658
|
}
|
|
675
659
|
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
}
|
|
660
|
+
var __defProp$2 = Object.defineProperty;
|
|
661
|
+
var __defProps = Object.defineProperties;
|
|
662
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
663
|
+
var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
|
|
664
|
+
var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
|
|
665
|
+
var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
|
|
666
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
667
|
+
var __spreadValues$2 = (a, b) => {
|
|
668
|
+
for (var prop in b || (b = {}))
|
|
669
|
+
if (__hasOwnProp$3.call(b, prop))
|
|
670
|
+
__defNormalProp$2(a, prop, b[prop]);
|
|
671
|
+
if (__getOwnPropSymbols$3)
|
|
672
|
+
for (var prop of __getOwnPropSymbols$3(b)) {
|
|
673
|
+
if (__propIsEnum$3.call(b, prop))
|
|
674
|
+
__defNormalProp$2(a, prop, b[prop]);
|
|
675
|
+
}
|
|
676
|
+
return a;
|
|
677
|
+
};
|
|
678
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
679
|
+
var __objRest$1 = (source, exclude) => {
|
|
680
|
+
var target = {};
|
|
681
|
+
for (var prop in source)
|
|
682
|
+
if (__hasOwnProp$3.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
683
|
+
target[prop] = source[prop];
|
|
684
|
+
if (source != null && __getOwnPropSymbols$3)
|
|
685
|
+
for (var prop of __getOwnPropSymbols$3(source)) {
|
|
686
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum$3.call(source, prop))
|
|
687
|
+
target[prop] = source[prop];
|
|
688
|
+
}
|
|
689
|
+
return target;
|
|
690
|
+
};
|
|
691
|
+
function throttledWatch(source, cb, options = {}) {
|
|
692
|
+
const _a = options, {
|
|
693
|
+
throttle = 0,
|
|
694
|
+
trailing = true
|
|
695
|
+
} = _a, watchOptions = __objRest$1(_a, [
|
|
696
|
+
"throttle",
|
|
697
|
+
"trailing"
|
|
698
|
+
]);
|
|
699
|
+
return watchWithFilter(source, cb, __spreadProps(__spreadValues$2({}, watchOptions), {
|
|
700
|
+
eventFilter: throttleFilter(throttle, trailing)
|
|
701
|
+
}));
|
|
692
702
|
}
|
|
693
703
|
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
704
|
+
function toReactive(objectRef) {
|
|
705
|
+
if (!isRef(objectRef))
|
|
706
|
+
return reactive(objectRef);
|
|
707
|
+
const proxy = new Proxy({}, {
|
|
708
|
+
get(_, p, receiver) {
|
|
709
|
+
return Reflect.get(objectRef.value, p, receiver);
|
|
710
|
+
},
|
|
711
|
+
set(_, p, value) {
|
|
712
|
+
objectRef.value[p] = value;
|
|
713
|
+
return true;
|
|
714
|
+
},
|
|
715
|
+
deleteProperty(_, p) {
|
|
716
|
+
return Reflect.deleteProperty(objectRef.value, p);
|
|
717
|
+
},
|
|
718
|
+
has(_, p) {
|
|
719
|
+
return Reflect.has(objectRef.value, p);
|
|
720
|
+
},
|
|
721
|
+
ownKeys() {
|
|
722
|
+
return Object.keys(objectRef.value);
|
|
723
|
+
},
|
|
724
|
+
getOwnPropertyDescriptor() {
|
|
725
|
+
return {
|
|
726
|
+
enumerable: true,
|
|
727
|
+
configurable: true
|
|
728
|
+
};
|
|
729
|
+
}
|
|
730
|
+
});
|
|
731
|
+
return reactive(proxy);
|
|
698
732
|
}
|
|
699
733
|
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
return true;
|
|
716
|
-
},
|
|
717
|
-
deleteProperty(_, p) {
|
|
718
|
-
return Reflect.deleteProperty(objectRef.value, p);
|
|
719
|
-
},
|
|
720
|
-
has(_, p) {
|
|
721
|
-
return Reflect.has(objectRef.value, p);
|
|
722
|
-
},
|
|
723
|
-
ownKeys() {
|
|
724
|
-
return Object.keys(objectRef.value);
|
|
725
|
-
},
|
|
726
|
-
getOwnPropertyDescriptor() {
|
|
727
|
-
return {
|
|
728
|
-
enumerable: true,
|
|
729
|
-
configurable: true,
|
|
730
|
-
};
|
|
731
|
-
},
|
|
732
|
-
});
|
|
733
|
-
return reactive(proxy);
|
|
734
|
+
function toRefs(objectRef) {
|
|
735
|
+
if (!isRef(objectRef))
|
|
736
|
+
return toRefs$1(objectRef);
|
|
737
|
+
const result = Array.isArray(objectRef.value) ? new Array(objectRef.value.length) : {};
|
|
738
|
+
for (const key in objectRef.value) {
|
|
739
|
+
result[key] = customRef(() => ({
|
|
740
|
+
get() {
|
|
741
|
+
return objectRef.value[key];
|
|
742
|
+
},
|
|
743
|
+
set(v) {
|
|
744
|
+
objectRef.value[key] = v;
|
|
745
|
+
}
|
|
746
|
+
}));
|
|
747
|
+
}
|
|
748
|
+
return result;
|
|
734
749
|
}
|
|
735
750
|
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
* @see https://vueuse.org/toRefs
|
|
740
|
-
* @param objectRef A ref or normal object or array.
|
|
741
|
-
*/
|
|
742
|
-
function toRefs(objectRef) {
|
|
743
|
-
if (!isRef(objectRef))
|
|
744
|
-
return toRefs$1(objectRef);
|
|
745
|
-
const result = Array.isArray(objectRef.value)
|
|
746
|
-
? new Array(objectRef.value.length)
|
|
747
|
-
: {};
|
|
748
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
749
|
-
for (const key in objectRef.value) {
|
|
750
|
-
result[key] = customRef(() => ({
|
|
751
|
-
get() {
|
|
752
|
-
return objectRef.value[key];
|
|
753
|
-
},
|
|
754
|
-
set(v) {
|
|
755
|
-
objectRef.value[key] = v;
|
|
756
|
-
},
|
|
757
|
-
}));
|
|
758
|
-
}
|
|
759
|
-
return result;
|
|
751
|
+
function tryOnBeforeUnmount(fn) {
|
|
752
|
+
if (getCurrentInstance())
|
|
753
|
+
onBeforeUnmount(fn);
|
|
760
754
|
}
|
|
761
755
|
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
onBeforeUnmount(fn);
|
|
756
|
+
function tryOnMounted(fn, sync = true) {
|
|
757
|
+
if (getCurrentInstance())
|
|
758
|
+
onMounted(fn);
|
|
759
|
+
else if (sync)
|
|
760
|
+
fn();
|
|
761
|
+
else
|
|
762
|
+
nextTick(fn);
|
|
770
763
|
}
|
|
771
764
|
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
* @param fn
|
|
776
|
-
* @param sync if set to false, it will run in the nextTick() of Vue
|
|
777
|
-
*/
|
|
778
|
-
function tryOnMounted(fn, sync = true) {
|
|
779
|
-
if (getCurrentInstance())
|
|
780
|
-
onMounted(fn);
|
|
781
|
-
else if (sync)
|
|
782
|
-
fn();
|
|
783
|
-
else
|
|
784
|
-
nextTick(fn);
|
|
765
|
+
function tryOnUnmounted(fn) {
|
|
766
|
+
if (getCurrentInstance())
|
|
767
|
+
onUnmounted(fn);
|
|
785
768
|
}
|
|
786
769
|
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
770
|
+
function until(r) {
|
|
771
|
+
let isNot = false;
|
|
772
|
+
function toMatch(condition, { flush = "sync", deep = false, timeout, throwOnTimeout } = {}) {
|
|
773
|
+
let stop = null;
|
|
774
|
+
const watcher = new Promise((resolve) => {
|
|
775
|
+
stop = watch(r, (v) => {
|
|
776
|
+
if (condition(v) === !isNot) {
|
|
777
|
+
stop == null ? void 0 : stop();
|
|
778
|
+
resolve();
|
|
779
|
+
}
|
|
780
|
+
}, {
|
|
781
|
+
flush,
|
|
782
|
+
deep,
|
|
783
|
+
immediate: true
|
|
784
|
+
});
|
|
785
|
+
});
|
|
786
|
+
const promises = [watcher];
|
|
787
|
+
if (timeout) {
|
|
788
|
+
promises.push(promiseTimeout(timeout, throwOnTimeout).finally(() => {
|
|
789
|
+
stop == null ? void 0 : stop();
|
|
790
|
+
}));
|
|
791
|
+
}
|
|
792
|
+
return Promise.race(promises);
|
|
793
|
+
}
|
|
794
|
+
function toBe(value, options) {
|
|
795
|
+
return toMatch((v) => v === unref(value), options);
|
|
796
|
+
}
|
|
797
|
+
function toBeTruthy(options) {
|
|
798
|
+
return toMatch((v) => Boolean(v), options);
|
|
799
|
+
}
|
|
800
|
+
function toBeNull(options) {
|
|
801
|
+
return toBe(null, options);
|
|
802
|
+
}
|
|
803
|
+
function toBeUndefined(options) {
|
|
804
|
+
return toBe(void 0, options);
|
|
805
|
+
}
|
|
806
|
+
function toBeNaN(options) {
|
|
807
|
+
return toMatch(Number.isNaN, options);
|
|
808
|
+
}
|
|
809
|
+
function toContains(value, options) {
|
|
810
|
+
return toMatch((v) => {
|
|
811
|
+
const array = Array.from(v);
|
|
812
|
+
return array.includes(value) || array.includes(unref(value));
|
|
813
|
+
}, options);
|
|
814
|
+
}
|
|
815
|
+
function changed(options) {
|
|
816
|
+
return changedTimes(1, options);
|
|
817
|
+
}
|
|
818
|
+
function changedTimes(n = 1, options) {
|
|
819
|
+
let count = -1;
|
|
820
|
+
return toMatch(() => {
|
|
821
|
+
count += 1;
|
|
822
|
+
return count >= n;
|
|
823
|
+
}, options);
|
|
824
|
+
}
|
|
825
|
+
if (Array.isArray(unref(r))) {
|
|
826
|
+
const instance = {
|
|
827
|
+
toMatch,
|
|
828
|
+
toContains,
|
|
829
|
+
changed,
|
|
830
|
+
changedTimes,
|
|
831
|
+
get not() {
|
|
832
|
+
isNot = !isNot;
|
|
833
|
+
return this;
|
|
834
|
+
}
|
|
835
|
+
};
|
|
836
|
+
return instance;
|
|
837
|
+
} else {
|
|
838
|
+
const instance = {
|
|
839
|
+
toMatch,
|
|
840
|
+
toBe,
|
|
841
|
+
toBeTruthy,
|
|
842
|
+
toBeNull,
|
|
843
|
+
toBeNaN,
|
|
844
|
+
toBeUndefined,
|
|
845
|
+
changed,
|
|
846
|
+
changedTimes,
|
|
847
|
+
get not() {
|
|
848
|
+
isNot = !isNot;
|
|
849
|
+
return this;
|
|
850
|
+
}
|
|
851
|
+
};
|
|
852
|
+
return instance;
|
|
853
|
+
}
|
|
795
854
|
}
|
|
796
855
|
|
|
797
|
-
function
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
flush,
|
|
809
|
-
deep,
|
|
810
|
-
immediate: true,
|
|
811
|
-
});
|
|
812
|
-
});
|
|
813
|
-
const promises = [watcher];
|
|
814
|
-
if (timeout) {
|
|
815
|
-
promises.push(promiseTimeout(timeout, throwOnTimeout).finally(() => {
|
|
816
|
-
stop === null || stop === void 0 ? void 0 : stop();
|
|
817
|
-
}));
|
|
818
|
-
}
|
|
819
|
-
return Promise.race(promises);
|
|
820
|
-
}
|
|
821
|
-
function toBe(value, options) {
|
|
822
|
-
return toMatch(v => v === unref(value), options);
|
|
823
|
-
}
|
|
824
|
-
function toBeTruthy(options) {
|
|
825
|
-
return toMatch(v => Boolean(v), options);
|
|
826
|
-
}
|
|
827
|
-
function toBeNull(options) {
|
|
828
|
-
return toBe(null, options);
|
|
829
|
-
}
|
|
830
|
-
function toBeUndefined(options) {
|
|
831
|
-
return toBe(undefined, options);
|
|
832
|
-
}
|
|
833
|
-
function toBeNaN(options) {
|
|
834
|
-
return toMatch(Number.isNaN, options);
|
|
835
|
-
}
|
|
836
|
-
function toContains(value, options) {
|
|
837
|
-
return toMatch((v) => {
|
|
838
|
-
const array = Array.from(v);
|
|
839
|
-
return array.includes(value) || array.includes(unref(value));
|
|
840
|
-
}, options);
|
|
841
|
-
}
|
|
842
|
-
function changed(options) {
|
|
843
|
-
return changedTimes(1, options);
|
|
844
|
-
}
|
|
845
|
-
function changedTimes(n = 1, options) {
|
|
846
|
-
let count = -1; // skip the immediate check
|
|
847
|
-
return toMatch(() => {
|
|
848
|
-
count += 1;
|
|
849
|
-
return count >= n;
|
|
850
|
-
}, options);
|
|
851
|
-
}
|
|
852
|
-
if (Array.isArray(unref(r))) {
|
|
853
|
-
const instance = {
|
|
854
|
-
toMatch,
|
|
855
|
-
toContains,
|
|
856
|
-
changed,
|
|
857
|
-
changedTimes,
|
|
858
|
-
get not() {
|
|
859
|
-
isNot = !isNot;
|
|
860
|
-
return this;
|
|
861
|
-
},
|
|
862
|
-
};
|
|
863
|
-
return instance;
|
|
864
|
-
}
|
|
865
|
-
else {
|
|
866
|
-
const instance = {
|
|
867
|
-
toMatch,
|
|
868
|
-
toBe,
|
|
869
|
-
toBeTruthy,
|
|
870
|
-
toBeNull,
|
|
871
|
-
toBeNaN,
|
|
872
|
-
toBeUndefined,
|
|
873
|
-
changed,
|
|
874
|
-
changedTimes,
|
|
875
|
-
get not() {
|
|
876
|
-
isNot = !isNot;
|
|
877
|
-
return this;
|
|
878
|
-
},
|
|
879
|
-
};
|
|
880
|
-
return instance;
|
|
881
|
-
}
|
|
856
|
+
function useCounter(initialValue = 0) {
|
|
857
|
+
const count = ref(initialValue);
|
|
858
|
+
const inc = (delta = 1) => count.value += delta;
|
|
859
|
+
const dec = (delta = 1) => count.value -= delta;
|
|
860
|
+
const get = () => count.value;
|
|
861
|
+
const set = (val) => count.value = val;
|
|
862
|
+
const reset = (val = initialValue) => {
|
|
863
|
+
initialValue = val;
|
|
864
|
+
return set(val);
|
|
865
|
+
};
|
|
866
|
+
return { count, inc, dec, get, set, reset };
|
|
882
867
|
}
|
|
883
868
|
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
*
|
|
887
|
-
* @see https://vueuse.org/useCounter
|
|
888
|
-
* @param [initialValue=0]
|
|
889
|
-
*/
|
|
890
|
-
function useCounter(initialValue = 0) {
|
|
891
|
-
const count = ref(initialValue);
|
|
892
|
-
const inc = (delta = 1) => (count.value += delta);
|
|
893
|
-
const dec = (delta = 1) => (count.value -= delta);
|
|
894
|
-
const get = () => count.value;
|
|
895
|
-
const set = (val) => (count.value = val);
|
|
896
|
-
const reset = (val = initialValue) => {
|
|
897
|
-
initialValue = val;
|
|
898
|
-
return set(val);
|
|
899
|
-
};
|
|
900
|
-
return { count, inc, dec, get, set, reset };
|
|
869
|
+
function useDebounceFn(fn, ms = 200) {
|
|
870
|
+
return createFilterWrapper(debounceFilter(ms), fn);
|
|
901
871
|
}
|
|
902
872
|
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
return createFilterWrapper(debounceFilter(ms), fn);
|
|
873
|
+
function useDebounce(value, ms = 200) {
|
|
874
|
+
if (ms <= 0)
|
|
875
|
+
return value;
|
|
876
|
+
const debounced = ref(value.value);
|
|
877
|
+
const updater = useDebounceFn(() => {
|
|
878
|
+
debounced.value = value.value;
|
|
879
|
+
}, ms);
|
|
880
|
+
watch(value, () => updater());
|
|
881
|
+
return debounced;
|
|
913
882
|
}
|
|
914
883
|
|
|
915
|
-
function
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
884
|
+
function useIntervalFn(cb, interval = 1e3, options = {}) {
|
|
885
|
+
const {
|
|
886
|
+
immediate = true,
|
|
887
|
+
immediateCallback = false
|
|
888
|
+
} = options;
|
|
889
|
+
let timer = null;
|
|
890
|
+
const isActive = ref(false);
|
|
891
|
+
function clean() {
|
|
892
|
+
if (timer) {
|
|
893
|
+
clearInterval(timer);
|
|
894
|
+
timer = null;
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
function pause() {
|
|
898
|
+
isActive.value = false;
|
|
899
|
+
clean();
|
|
900
|
+
}
|
|
901
|
+
function resume() {
|
|
902
|
+
if (interval <= 0)
|
|
903
|
+
return;
|
|
904
|
+
isActive.value = true;
|
|
905
|
+
if (immediateCallback)
|
|
906
|
+
cb();
|
|
907
|
+
clean();
|
|
908
|
+
timer = setInterval(cb, interval);
|
|
909
|
+
}
|
|
910
|
+
if (immediate && isClient)
|
|
911
|
+
resume();
|
|
912
|
+
tryOnScopeDispose(pause);
|
|
913
|
+
return {
|
|
914
|
+
isActive,
|
|
915
|
+
pause,
|
|
916
|
+
resume
|
|
917
|
+
};
|
|
924
918
|
}
|
|
925
919
|
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
if (immediate && isClient)
|
|
957
|
-
resume();
|
|
958
|
-
tryOnScopeDispose(pause);
|
|
959
|
-
return {
|
|
960
|
-
isActive,
|
|
961
|
-
pause,
|
|
962
|
-
resume,
|
|
963
|
-
};
|
|
920
|
+
var __defProp$1 = Object.defineProperty;
|
|
921
|
+
var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
|
|
922
|
+
var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
|
|
923
|
+
var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
|
|
924
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
925
|
+
var __spreadValues$1 = (a, b) => {
|
|
926
|
+
for (var prop in b || (b = {}))
|
|
927
|
+
if (__hasOwnProp$2.call(b, prop))
|
|
928
|
+
__defNormalProp$1(a, prop, b[prop]);
|
|
929
|
+
if (__getOwnPropSymbols$2)
|
|
930
|
+
for (var prop of __getOwnPropSymbols$2(b)) {
|
|
931
|
+
if (__propIsEnum$2.call(b, prop))
|
|
932
|
+
__defNormalProp$1(a, prop, b[prop]);
|
|
933
|
+
}
|
|
934
|
+
return a;
|
|
935
|
+
};
|
|
936
|
+
function useInterval(interval = 1e3, options = {}) {
|
|
937
|
+
const {
|
|
938
|
+
controls: exposeControls = false,
|
|
939
|
+
immediate = true
|
|
940
|
+
} = options;
|
|
941
|
+
const counter = ref(0);
|
|
942
|
+
const controls = useIntervalFn(() => counter.value += 1, interval, { immediate });
|
|
943
|
+
if (exposeControls) {
|
|
944
|
+
return __spreadValues$1({
|
|
945
|
+
counter
|
|
946
|
+
}, controls);
|
|
947
|
+
} else {
|
|
948
|
+
return counter;
|
|
949
|
+
}
|
|
964
950
|
}
|
|
965
951
|
|
|
966
|
-
function
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
return Object.assign({ counter }, controls);
|
|
972
|
-
}
|
|
973
|
-
else {
|
|
974
|
-
return counter;
|
|
975
|
-
}
|
|
952
|
+
function useLastChanged(source, options = {}) {
|
|
953
|
+
var _a;
|
|
954
|
+
const ms = ref((_a = options.initialValue) != null ? _a : null);
|
|
955
|
+
watch(source, () => ms.value = timestamp(), options);
|
|
956
|
+
return ms;
|
|
976
957
|
}
|
|
977
958
|
|
|
978
|
-
function
|
|
979
|
-
|
|
980
|
-
const ms = ref((_a = options.initialValue) !== null && _a !== void 0 ? _a : null);
|
|
981
|
-
watch(source, () => ms.value = timestamp(), options);
|
|
982
|
-
return ms;
|
|
959
|
+
function useThrottleFn(fn, ms = 200, trailing = true, leading = true) {
|
|
960
|
+
return createFilterWrapper(throttleFilter(ms, trailing, leading), fn);
|
|
983
961
|
}
|
|
984
962
|
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
*
|
|
995
|
-
* @return A new, throttled, function.
|
|
996
|
-
*/
|
|
997
|
-
function useThrottleFn(fn, ms = 200, trailing = true) {
|
|
998
|
-
return createFilterWrapper(throttleFilter(ms, trailing), fn);
|
|
963
|
+
function useThrottle(value, delay = 200, trailing = true, leading = true) {
|
|
964
|
+
if (delay <= 0)
|
|
965
|
+
return value;
|
|
966
|
+
const throttled = ref(value.value);
|
|
967
|
+
const updater = useThrottleFn(() => {
|
|
968
|
+
throttled.value = value.value;
|
|
969
|
+
}, delay, trailing, leading);
|
|
970
|
+
watch(value, () => updater());
|
|
971
|
+
return throttled;
|
|
999
972
|
}
|
|
1000
973
|
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
974
|
+
function useTimeoutFn(cb, interval, options = {}) {
|
|
975
|
+
const {
|
|
976
|
+
immediate = true
|
|
977
|
+
} = options;
|
|
978
|
+
const isPending = ref(false);
|
|
979
|
+
let timer = null;
|
|
980
|
+
function clear() {
|
|
981
|
+
if (timer) {
|
|
982
|
+
clearTimeout(timer);
|
|
983
|
+
timer = null;
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
function stop() {
|
|
987
|
+
isPending.value = false;
|
|
988
|
+
clear();
|
|
989
|
+
}
|
|
990
|
+
function start(...args) {
|
|
991
|
+
clear();
|
|
992
|
+
isPending.value = true;
|
|
993
|
+
timer = setTimeout(() => {
|
|
994
|
+
isPending.value = false;
|
|
995
|
+
timer = null;
|
|
996
|
+
cb(...args);
|
|
997
|
+
}, unref(interval));
|
|
998
|
+
}
|
|
999
|
+
if (immediate) {
|
|
1000
|
+
isPending.value = true;
|
|
1001
|
+
if (isClient)
|
|
1002
|
+
start();
|
|
1003
|
+
}
|
|
1004
|
+
tryOnScopeDispose(stop);
|
|
1005
|
+
return {
|
|
1006
|
+
isPending,
|
|
1007
|
+
start,
|
|
1008
|
+
stop
|
|
1009
|
+
};
|
|
1018
1010
|
}
|
|
1019
1011
|
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
}, unref(interval));
|
|
1050
|
-
}
|
|
1051
|
-
if (immediate) {
|
|
1052
|
-
isPending.value = true;
|
|
1053
|
-
if (isClient)
|
|
1054
|
-
start();
|
|
1055
|
-
}
|
|
1056
|
-
tryOnScopeDispose(stop);
|
|
1057
|
-
return {
|
|
1058
|
-
isPending,
|
|
1059
|
-
start,
|
|
1060
|
-
stop,
|
|
1061
|
-
};
|
|
1012
|
+
var __defProp = Object.defineProperty;
|
|
1013
|
+
var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
|
|
1014
|
+
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
1015
|
+
var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
|
|
1016
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1017
|
+
var __spreadValues = (a, b) => {
|
|
1018
|
+
for (var prop in b || (b = {}))
|
|
1019
|
+
if (__hasOwnProp$1.call(b, prop))
|
|
1020
|
+
__defNormalProp(a, prop, b[prop]);
|
|
1021
|
+
if (__getOwnPropSymbols$1)
|
|
1022
|
+
for (var prop of __getOwnPropSymbols$1(b)) {
|
|
1023
|
+
if (__propIsEnum$1.call(b, prop))
|
|
1024
|
+
__defNormalProp(a, prop, b[prop]);
|
|
1025
|
+
}
|
|
1026
|
+
return a;
|
|
1027
|
+
};
|
|
1028
|
+
function useTimeout(interval = 1e3, options = {}) {
|
|
1029
|
+
const {
|
|
1030
|
+
controls: exposeControls = false
|
|
1031
|
+
} = options;
|
|
1032
|
+
const controls = useTimeoutFn(noop, interval, options);
|
|
1033
|
+
const ready = computed(() => !controls.isPending.value);
|
|
1034
|
+
if (exposeControls) {
|
|
1035
|
+
return __spreadValues({
|
|
1036
|
+
ready
|
|
1037
|
+
}, controls);
|
|
1038
|
+
} else {
|
|
1039
|
+
return ready;
|
|
1040
|
+
}
|
|
1062
1041
|
}
|
|
1063
1042
|
|
|
1064
|
-
function
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
}
|
|
1043
|
+
function useToggle(initialValue = false) {
|
|
1044
|
+
if (isRef(initialValue)) {
|
|
1045
|
+
return (value) => {
|
|
1046
|
+
initialValue.value = typeof value === "boolean" ? value : !initialValue.value;
|
|
1047
|
+
};
|
|
1048
|
+
} else {
|
|
1049
|
+
const boolean = ref(initialValue);
|
|
1050
|
+
const toggle = (value) => {
|
|
1051
|
+
boolean.value = typeof value === "boolean" ? value : !boolean.value;
|
|
1052
|
+
};
|
|
1053
|
+
return [boolean, toggle];
|
|
1054
|
+
}
|
|
1074
1055
|
}
|
|
1075
1056
|
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1057
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
1058
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
1059
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
1060
|
+
var __objRest = (source, exclude) => {
|
|
1061
|
+
var target = {};
|
|
1062
|
+
for (var prop in source)
|
|
1063
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
1064
|
+
target[prop] = source[prop];
|
|
1065
|
+
if (source != null && __getOwnPropSymbols)
|
|
1066
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
1067
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
1068
|
+
target[prop] = source[prop];
|
|
1069
|
+
}
|
|
1070
|
+
return target;
|
|
1071
|
+
};
|
|
1072
|
+
function watchAtMost(source, cb, options) {
|
|
1073
|
+
const _a = options, {
|
|
1074
|
+
count
|
|
1075
|
+
} = _a, watchOptions = __objRest(_a, [
|
|
1076
|
+
"count"
|
|
1077
|
+
]);
|
|
1078
|
+
const current = ref(0);
|
|
1079
|
+
const stop = watchWithFilter(source, (...args) => {
|
|
1080
|
+
current.value += 1;
|
|
1081
|
+
if (current.value >= unref(count))
|
|
1082
|
+
stop();
|
|
1083
|
+
cb(...args);
|
|
1084
|
+
}, watchOptions);
|
|
1085
|
+
return { count: current, stop };
|
|
1093
1086
|
}
|
|
1094
1087
|
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
current.value += 1;
|
|
1101
|
-
if (current.value >= unref(count))
|
|
1102
|
-
stop();
|
|
1103
|
-
cb(...args);
|
|
1104
|
-
}, watchOptions);
|
|
1105
|
-
return { count: current, stop };
|
|
1088
|
+
function watchOnce(source, cb, options) {
|
|
1089
|
+
const stop = watch(source, (...args) => {
|
|
1090
|
+
stop();
|
|
1091
|
+
return cb(...args);
|
|
1092
|
+
}, options);
|
|
1106
1093
|
}
|
|
1107
1094
|
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
function whenever(source, cb, options) {
|
|
1114
|
-
return watch(source, (v, ov, onInvalidate) => { if (v)
|
|
1115
|
-
cb(v, ov, onInvalidate); }, options);
|
|
1095
|
+
function whenever(source, cb, options) {
|
|
1096
|
+
return watch(source, (v, ov, onInvalidate) => {
|
|
1097
|
+
if (v)
|
|
1098
|
+
cb(v, ov, onInvalidate);
|
|
1099
|
+
}, options);
|
|
1116
1100
|
}
|
|
1117
1101
|
|
|
1118
|
-
export { and, assert, biSyncRef, bypassFilter, clamp, containsProp, controlledComputed, controlledRef, createEventHook, createFilterWrapper, createGlobalState, createSharedComposable, createSingletonPromise, debounceFilter, debouncedWatch, eagerComputed, extendRef, get, identity, ignorableWatch, increaseWithUnit, invoke, isBoolean, isClient, isDef, isFunction, isNumber, isObject, isString, isWindow, makeDestructurable, noop, not, now, objectPick, or, pausableFilter, pausableWatch, promiseTimeout, rand, reactify, reactifyObject, reactivePick, set, syncRef, throttleFilter, throttledWatch, timestamp, toReactive, toRefs, tryOnBeforeUnmount, tryOnMounted, tryOnScopeDispose, tryOnUnmounted, until, useCounter, useDebounce, useDebounceFn, useInterval, useIntervalFn, useLastChanged, useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useToggle, watchAtMost, watchWithFilter, whenever };
|
|
1102
|
+
export { and, assert, biSyncRef, bypassFilter, clamp, containsProp, controlledComputed, controlledRef, createEventHook, createFilterWrapper, createGlobalState, createSharedComposable, createSingletonPromise, debounceFilter, debouncedWatch, eagerComputed, extendRef, get, identity, ignorableWatch, increaseWithUnit, invoke, isBoolean, isClient, isDef, isFunction, isNumber, isObject, isString, isWindow, makeDestructurable, noop, not, now, objectPick, or, pausableFilter, pausableWatch, promiseTimeout, rand, reactify, reactifyObject, reactivePick, set, syncRef, throttleFilter, throttledWatch, timestamp, toReactive, toRefs, tryOnBeforeUnmount, tryOnMounted, tryOnScopeDispose, tryOnUnmounted, until, useCounter, useDebounce, useDebounceFn, useInterval, useIntervalFn, useLastChanged, useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useToggle, watchAtMost, watchOnce, watchWithFilter, whenever };
|