@vueuse/shared 6.3.2 → 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 +1008 -1005
- package/index.d.ts +40 -6
- package/index.iife.js +1009 -1006
- package/index.iife.min.js +1 -1
- package/index.mjs +1007 -1006
- package/package.json +2 -2
package/index.mjs
CHANGED
|
@@ -1,1101 +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 };
|
|
509
|
+
}
|
|
510
|
+
|
|
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
|
+
}
|
|
493
546
|
}
|
|
494
547
|
|
|
495
|
-
function
|
|
496
|
-
|
|
497
|
-
const filteredCb = createFilterWrapper(eventFilter, cb);
|
|
498
|
-
let ignoreUpdates;
|
|
499
|
-
let ignorePrevAsyncUpdates;
|
|
500
|
-
let stop;
|
|
501
|
-
if (watchOptions.flush === 'sync') {
|
|
502
|
-
const ignore = ref(false);
|
|
503
|
-
// no op for flush: sync
|
|
504
|
-
ignorePrevAsyncUpdates = () => { };
|
|
505
|
-
ignoreUpdates = (updater) => {
|
|
506
|
-
// Call the updater function and count how many sync updates are performed,
|
|
507
|
-
// then add them to the ignore count
|
|
508
|
-
ignore.value = true;
|
|
509
|
-
updater();
|
|
510
|
-
ignore.value = false;
|
|
511
|
-
};
|
|
512
|
-
stop = watch(source, (...args) => {
|
|
513
|
-
if (!ignore.value)
|
|
514
|
-
filteredCb(...args);
|
|
515
|
-
}, watchOptions);
|
|
516
|
-
}
|
|
517
|
-
else {
|
|
518
|
-
// flush 'pre' and 'post'
|
|
519
|
-
const disposables = [];
|
|
520
|
-
// counters for how many following changes to be ignored
|
|
521
|
-
// ignoreCounter is incremented before there is a history operation
|
|
522
|
-
// affecting the source ref value (undo, redo, revert).
|
|
523
|
-
// syncCounter is incremented in sync with every change to the
|
|
524
|
-
// source ref value. This let us know how many times the ref
|
|
525
|
-
// was modified and support chained sync operations. If there
|
|
526
|
-
// are more sync triggers than the ignore count, the we now
|
|
527
|
-
// there are modifications in the source ref value that we
|
|
528
|
-
// need to commit
|
|
529
|
-
const ignoreCounter = ref(0);
|
|
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 };
|
|
548
|
+
function not(v) {
|
|
549
|
+
return computed(() => !unref(v));
|
|
560
550
|
}
|
|
561
551
|
|
|
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
|
-
}
|
|
552
|
+
function or(...args) {
|
|
553
|
+
return computed(() => args.some((i) => unref(i)));
|
|
582
554
|
}
|
|
583
555
|
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
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 };
|
|
591
598
|
}
|
|
592
599
|
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
*/
|
|
598
|
-
function or(...args) {
|
|
599
|
-
return computed(() => args.some(i => unref(i)));
|
|
600
|
+
function reactify(fn) {
|
|
601
|
+
return function(...args) {
|
|
602
|
+
return computed(() => fn.apply(this, args.map((i) => unref(i))));
|
|
603
|
+
};
|
|
600
604
|
}
|
|
601
605
|
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
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
|
+
}));
|
|
608
623
|
}
|
|
609
624
|
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
* The converted function accepts refs as it's arguments
|
|
613
|
-
* and returns a ComputedRef, with proper typing.
|
|
614
|
-
*
|
|
615
|
-
* @param fn - Source function
|
|
616
|
-
*/
|
|
617
|
-
function reactify(fn) {
|
|
618
|
-
return function (...args) {
|
|
619
|
-
return computed(() => fn.apply(this, args.map(i => unref(i))));
|
|
620
|
-
};
|
|
625
|
+
function reactivePick(obj, ...keys) {
|
|
626
|
+
return reactive(Object.fromEntries(keys.map((k) => [k, toRef(obj, k)])));
|
|
621
627
|
}
|
|
622
628
|
|
|
623
|
-
function
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
const value = obj[key];
|
|
637
|
-
return [
|
|
638
|
-
key,
|
|
639
|
-
typeof value === 'function'
|
|
640
|
-
? reactify(value.bind(obj))
|
|
641
|
-
: value,
|
|
642
|
-
];
|
|
643
|
-
}));
|
|
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
|
+
}
|
|
644
642
|
}
|
|
645
643
|
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
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
|
+
});
|
|
653
658
|
}
|
|
654
659
|
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
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
|
+
}));
|
|
674
702
|
}
|
|
675
703
|
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
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);
|
|
692
732
|
}
|
|
693
733
|
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
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;
|
|
698
749
|
}
|
|
699
750
|
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
* @see https://vueuse.org/toReactive
|
|
704
|
-
* @param objectRef A ref of object
|
|
705
|
-
*/
|
|
706
|
-
function toReactive(objectRef) {
|
|
707
|
-
if (!isRef(objectRef))
|
|
708
|
-
return reactive(objectRef);
|
|
709
|
-
const proxy = new Proxy({}, {
|
|
710
|
-
get(_, p, receiver) {
|
|
711
|
-
return Reflect.get(objectRef.value, p, receiver);
|
|
712
|
-
},
|
|
713
|
-
set(_, p, value) {
|
|
714
|
-
objectRef.value[p] = value;
|
|
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);
|
|
751
|
+
function tryOnBeforeUnmount(fn) {
|
|
752
|
+
if (getCurrentInstance())
|
|
753
|
+
onBeforeUnmount(fn);
|
|
734
754
|
}
|
|
735
755
|
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
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;
|
|
756
|
+
function tryOnMounted(fn, sync = true) {
|
|
757
|
+
if (getCurrentInstance())
|
|
758
|
+
onMounted(fn);
|
|
759
|
+
else if (sync)
|
|
760
|
+
fn();
|
|
761
|
+
else
|
|
762
|
+
nextTick(fn);
|
|
760
763
|
}
|
|
761
764
|
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
* @param fn
|
|
766
|
-
*/
|
|
767
|
-
function tryOnBeforeUnmount(fn) {
|
|
768
|
-
if (getCurrentInstance())
|
|
769
|
-
onBeforeUnmount(fn);
|
|
765
|
+
function tryOnUnmounted(fn) {
|
|
766
|
+
if (getCurrentInstance())
|
|
767
|
+
onUnmounted(fn);
|
|
770
768
|
}
|
|
771
769
|
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
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
|
+
}
|
|
785
854
|
}
|
|
786
855
|
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
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 };
|
|
795
867
|
}
|
|
796
868
|
|
|
797
|
-
function
|
|
798
|
-
|
|
799
|
-
function toMatch(condition, { flush = 'sync', deep = false, timeout, throwOnTimeout } = {}) {
|
|
800
|
-
let stop = null;
|
|
801
|
-
const watcher = new Promise((resolve) => {
|
|
802
|
-
stop = watch(r, (v) => {
|
|
803
|
-
if (condition(v) === !isNot) {
|
|
804
|
-
stop === null || stop === void 0 ? void 0 : stop();
|
|
805
|
-
resolve();
|
|
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
|
-
}
|
|
869
|
+
function useDebounceFn(fn, ms = 200) {
|
|
870
|
+
return createFilterWrapper(debounceFilter(ms), fn);
|
|
882
871
|
}
|
|
883
872
|
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
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 };
|
|
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;
|
|
901
882
|
}
|
|
902
883
|
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
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
|
+
};
|
|
913
918
|
}
|
|
914
919
|
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
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
|
+
}
|
|
924
950
|
}
|
|
925
951
|
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
* @param options
|
|
932
|
-
*/
|
|
933
|
-
function useIntervalFn(cb, interval = 1000, options = {}) {
|
|
934
|
-
const { immediate = true, immediateCallback = false, } = options;
|
|
935
|
-
let timer = null;
|
|
936
|
-
const isActive = ref(false);
|
|
937
|
-
function clean() {
|
|
938
|
-
if (timer) {
|
|
939
|
-
clearInterval(timer);
|
|
940
|
-
timer = null;
|
|
941
|
-
}
|
|
942
|
-
}
|
|
943
|
-
function pause() {
|
|
944
|
-
isActive.value = false;
|
|
945
|
-
clean();
|
|
946
|
-
}
|
|
947
|
-
function resume() {
|
|
948
|
-
if (interval <= 0)
|
|
949
|
-
return;
|
|
950
|
-
isActive.value = true;
|
|
951
|
-
if (immediateCallback)
|
|
952
|
-
cb();
|
|
953
|
-
clean();
|
|
954
|
-
timer = setInterval(cb, interval);
|
|
955
|
-
}
|
|
956
|
-
if (immediate && isClient)
|
|
957
|
-
resume();
|
|
958
|
-
tryOnScopeDispose(pause);
|
|
959
|
-
return {
|
|
960
|
-
isActive,
|
|
961
|
-
pause,
|
|
962
|
-
resume,
|
|
963
|
-
};
|
|
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;
|
|
964
957
|
}
|
|
965
958
|
|
|
966
|
-
function
|
|
967
|
-
|
|
968
|
-
const counter = ref(0);
|
|
969
|
-
const controls = useIntervalFn(() => counter.value += 1, interval, { immediate });
|
|
970
|
-
if (exposeControls) {
|
|
971
|
-
return Object.assign({ counter }, controls);
|
|
972
|
-
}
|
|
973
|
-
else {
|
|
974
|
-
return counter;
|
|
975
|
-
}
|
|
959
|
+
function useThrottleFn(fn, ms = 200, trailing = true, leading = true) {
|
|
960
|
+
return createFilterWrapper(throttleFilter(ms, trailing, leading), fn);
|
|
976
961
|
}
|
|
977
962
|
|
|
978
|
-
function
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
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;
|
|
983
972
|
}
|
|
984
973
|
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
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
|
+
};
|
|
997
1010
|
}
|
|
998
1011
|
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
if (
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
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
|
+
}
|
|
1014
1041
|
}
|
|
1015
1042
|
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
if (timer) {
|
|
1029
|
-
clearTimeout(timer);
|
|
1030
|
-
timer = null;
|
|
1031
|
-
}
|
|
1032
|
-
}
|
|
1033
|
-
function stop() {
|
|
1034
|
-
isPending.value = false;
|
|
1035
|
-
clear();
|
|
1036
|
-
}
|
|
1037
|
-
function start(...args) {
|
|
1038
|
-
clear();
|
|
1039
|
-
isPending.value = true;
|
|
1040
|
-
timer = setTimeout(() => {
|
|
1041
|
-
isPending.value = false;
|
|
1042
|
-
timer = null;
|
|
1043
|
-
// eslint-disable-next-line node/no-callback-literal
|
|
1044
|
-
cb(...args);
|
|
1045
|
-
}, unref(interval));
|
|
1046
|
-
}
|
|
1047
|
-
if (immediate) {
|
|
1048
|
-
isPending.value = true;
|
|
1049
|
-
if (isClient)
|
|
1050
|
-
start();
|
|
1051
|
-
}
|
|
1052
|
-
tryOnScopeDispose(stop);
|
|
1053
|
-
return {
|
|
1054
|
-
isPending,
|
|
1055
|
-
start,
|
|
1056
|
-
stop,
|
|
1057
|
-
};
|
|
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
|
+
}
|
|
1058
1055
|
}
|
|
1059
1056
|
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
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 };
|
|
1070
1086
|
}
|
|
1071
1087
|
|
|
1072
|
-
function
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
: !initialValue.value;
|
|
1078
|
-
};
|
|
1079
|
-
}
|
|
1080
|
-
else {
|
|
1081
|
-
const boolean = ref(initialValue);
|
|
1082
|
-
const toggle = (value) => {
|
|
1083
|
-
boolean.value = typeof value === 'boolean'
|
|
1084
|
-
? value
|
|
1085
|
-
: !boolean.value;
|
|
1086
|
-
};
|
|
1087
|
-
return [boolean, toggle];
|
|
1088
|
-
}
|
|
1088
|
+
function watchOnce(source, cb, options) {
|
|
1089
|
+
const stop = watch(source, (...args) => {
|
|
1090
|
+
stop();
|
|
1091
|
+
return cb(...args);
|
|
1092
|
+
}, options);
|
|
1089
1093
|
}
|
|
1090
1094
|
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
function whenever(source, cb, options) {
|
|
1097
|
-
return watch(source, (v, ov, onInvalidate) => { if (v)
|
|
1098
|
-
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);
|
|
1099
1100
|
}
|
|
1100
1101
|
|
|
1101
|
-
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, 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 };
|