@vueuse/shared 14.0.0-alpha.3 → 14.0.0-beta.1
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/dist/index.iife.js +1774 -1774
- package/package.json +1 -1
package/dist/index.iife.js
CHANGED
|
@@ -1,2092 +1,2092 @@
|
|
|
1
1
|
(function(exports, vue) {
|
|
2
2
|
|
|
3
3
|
//#region rolldown:runtime
|
|
4
|
-
var __create = Object.create;
|
|
5
|
-
var __defProp = Object.defineProperty;
|
|
6
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}) : target, mod));
|
|
4
|
+
var __create = Object.create;
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
12
|
+
key = keys[i];
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
21
|
+
value: mod,
|
|
22
|
+
enumerable: true
|
|
23
|
+
}) : target, mod));
|
|
24
24
|
|
|
25
25
|
//#endregion
|
|
26
26
|
vue = __toESM(vue);
|
|
27
27
|
|
|
28
28
|
//#region computedEager/index.ts
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
31
|
-
* @deprecated This function will be removed in future version.
|
|
32
|
-
*
|
|
33
|
-
* Note: If you are using Vue 3.4+, you can straight use computed instead.
|
|
34
|
-
* Because in Vue 3.4+, if computed new value does not change,
|
|
35
|
-
* computed, effect, watch, watchEffect, render dependencies will not be triggered.
|
|
36
|
-
* refer: https://github.com/vuejs/core/pull/5912
|
|
37
|
-
*
|
|
38
|
-
* @param fn effect function
|
|
39
|
-
* @param options WatchOptionsBase
|
|
40
|
-
* @returns readonly shallowRef
|
|
41
|
-
*/
|
|
42
|
-
function computedEager(fn, options) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
/** @deprecated use `computedEager` instead */
|
|
54
|
-
const eagerComputed = computedEager;
|
|
30
|
+
*
|
|
31
|
+
* @deprecated This function will be removed in future version.
|
|
32
|
+
*
|
|
33
|
+
* Note: If you are using Vue 3.4+, you can straight use computed instead.
|
|
34
|
+
* Because in Vue 3.4+, if computed new value does not change,
|
|
35
|
+
* computed, effect, watch, watchEffect, render dependencies will not be triggered.
|
|
36
|
+
* refer: https://github.com/vuejs/core/pull/5912
|
|
37
|
+
*
|
|
38
|
+
* @param fn effect function
|
|
39
|
+
* @param options WatchOptionsBase
|
|
40
|
+
* @returns readonly shallowRef
|
|
41
|
+
*/
|
|
42
|
+
function computedEager(fn, options) {
|
|
43
|
+
var _options$flush;
|
|
44
|
+
const result = (0, vue.shallowRef)();
|
|
45
|
+
(0, vue.watchEffect)(() => {
|
|
46
|
+
result.value = fn();
|
|
47
|
+
}, {
|
|
48
|
+
...options,
|
|
49
|
+
flush: (_options$flush = options === null || options === void 0 ? void 0 : options.flush) !== null && _options$flush !== void 0 ? _options$flush : "sync"
|
|
50
|
+
});
|
|
51
|
+
return (0, vue.readonly)(result);
|
|
52
|
+
}
|
|
53
|
+
/** @deprecated use `computedEager` instead */
|
|
54
|
+
const eagerComputed = computedEager;
|
|
55
55
|
|
|
56
56
|
//#endregion
|
|
57
57
|
//#region computedWithControl/index.ts
|
|
58
58
|
/**
|
|
59
|
-
* Explicitly define the deps of computed.
|
|
60
|
-
*
|
|
61
|
-
* @param source
|
|
62
|
-
* @param fn
|
|
63
|
-
*/
|
|
64
|
-
function computedWithControl(source, fn, options = {}) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
};
|
|
73
|
-
(0, vue.watch)(source, update, {
|
|
74
|
-
flush: "sync",
|
|
75
|
-
...options
|
|
76
|
-
});
|
|
77
|
-
const get$1 = typeof fn === "function" ? fn : fn.get;
|
|
78
|
-
const set$1 = typeof fn === "function" ? void 0 : fn.set;
|
|
79
|
-
const result = (0, vue.customRef)((_track, _trigger) => {
|
|
80
|
-
track = _track;
|
|
81
|
-
trigger = _trigger;
|
|
82
|
-
return {
|
|
83
|
-
get() {
|
|
84
|
-
if (dirty) {
|
|
85
|
-
v = get$1(v);
|
|
86
|
-
dirty = false;
|
|
87
|
-
}
|
|
88
|
-
track();
|
|
89
|
-
return v;
|
|
90
|
-
},
|
|
91
|
-
set(v$1) {
|
|
92
|
-
set$1 === null || set$1 === void 0 || set$1(v$1);
|
|
93
|
-
}
|
|
59
|
+
* Explicitly define the deps of computed.
|
|
60
|
+
*
|
|
61
|
+
* @param source
|
|
62
|
+
* @param fn
|
|
63
|
+
*/
|
|
64
|
+
function computedWithControl(source, fn, options = {}) {
|
|
65
|
+
let v = void 0;
|
|
66
|
+
let track;
|
|
67
|
+
let trigger;
|
|
68
|
+
let dirty = true;
|
|
69
|
+
const update = () => {
|
|
70
|
+
dirty = true;
|
|
71
|
+
trigger();
|
|
94
72
|
};
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const
|
|
73
|
+
(0, vue.watch)(source, update, {
|
|
74
|
+
flush: "sync",
|
|
75
|
+
...options
|
|
76
|
+
});
|
|
77
|
+
const get$1 = typeof fn === "function" ? fn : fn.get;
|
|
78
|
+
const set$1 = typeof fn === "function" ? void 0 : fn.set;
|
|
79
|
+
const result = (0, vue.customRef)((_track, _trigger) => {
|
|
80
|
+
track = _track;
|
|
81
|
+
trigger = _trigger;
|
|
82
|
+
return {
|
|
83
|
+
get() {
|
|
84
|
+
if (dirty) {
|
|
85
|
+
v = get$1(v);
|
|
86
|
+
dirty = false;
|
|
87
|
+
}
|
|
88
|
+
track();
|
|
89
|
+
return v;
|
|
90
|
+
},
|
|
91
|
+
set(v$1) {
|
|
92
|
+
set$1 === null || set$1 === void 0 || set$1(v$1);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
});
|
|
96
|
+
result.trigger = update;
|
|
97
|
+
return result;
|
|
98
|
+
}
|
|
99
|
+
/** @deprecated use `computedWithControl` instead */
|
|
100
|
+
const controlledComputed = computedWithControl;
|
|
101
101
|
|
|
102
102
|
//#endregion
|
|
103
103
|
//#region tryOnScopeDispose/index.ts
|
|
104
104
|
/**
|
|
105
|
-
* Call onScopeDispose() if it's inside an effect scope lifecycle, if not, do nothing
|
|
106
|
-
*
|
|
107
|
-
* @param fn
|
|
108
|
-
*/
|
|
109
|
-
function tryOnScopeDispose(fn) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
105
|
+
* Call onScopeDispose() if it's inside an effect scope lifecycle, if not, do nothing
|
|
106
|
+
*
|
|
107
|
+
* @param fn
|
|
108
|
+
*/
|
|
109
|
+
function tryOnScopeDispose(fn) {
|
|
110
|
+
if ((0, vue.getCurrentScope)()) {
|
|
111
|
+
(0, vue.onScopeDispose)(fn);
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
return false;
|
|
113
115
|
}
|
|
114
|
-
return false;
|
|
115
|
-
}
|
|
116
116
|
|
|
117
117
|
//#endregion
|
|
118
118
|
//#region createEventHook/index.ts
|
|
119
119
|
/**
|
|
120
|
-
* Utility for creating event hooks
|
|
121
|
-
*
|
|
122
|
-
* @see https://vueuse.org/createEventHook
|
|
123
|
-
*
|
|
124
|
-
* @__NO_SIDE_EFFECTS__
|
|
125
|
-
*/
|
|
126
|
-
function createEventHook() {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
120
|
+
* Utility for creating event hooks
|
|
121
|
+
*
|
|
122
|
+
* @see https://vueuse.org/createEventHook
|
|
123
|
+
*
|
|
124
|
+
* @__NO_SIDE_EFFECTS__
|
|
125
|
+
*/
|
|
126
|
+
function createEventHook() {
|
|
127
|
+
const fns = /* @__PURE__ */ new Set();
|
|
128
|
+
const off = (fn) => {
|
|
129
|
+
fns.delete(fn);
|
|
130
|
+
};
|
|
131
|
+
const clear = () => {
|
|
132
|
+
fns.clear();
|
|
133
|
+
};
|
|
134
|
+
const on = (fn) => {
|
|
135
|
+
fns.add(fn);
|
|
136
|
+
const offFn = () => off(fn);
|
|
137
|
+
tryOnScopeDispose(offFn);
|
|
138
|
+
return { off: offFn };
|
|
139
|
+
};
|
|
140
|
+
const trigger = (...args) => {
|
|
141
|
+
return Promise.all(Array.from(fns).map((fn) => fn(...args)));
|
|
142
|
+
};
|
|
143
|
+
return {
|
|
144
|
+
on,
|
|
145
|
+
off,
|
|
146
|
+
trigger,
|
|
147
|
+
clear
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
150
|
|
|
151
151
|
//#endregion
|
|
152
152
|
//#region createGlobalState/index.ts
|
|
153
153
|
/**
|
|
154
|
-
* Keep states in the global scope to be reusable across Vue instances.
|
|
155
|
-
*
|
|
156
|
-
* @see https://vueuse.org/createGlobalState
|
|
157
|
-
* @param stateFactory A factory function to create the state
|
|
158
|
-
*
|
|
159
|
-
* @__NO_SIDE_EFFECTS__
|
|
160
|
-
*/
|
|
161
|
-
function createGlobalState(stateFactory) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
}
|
|
154
|
+
* Keep states in the global scope to be reusable across Vue instances.
|
|
155
|
+
*
|
|
156
|
+
* @see https://vueuse.org/createGlobalState
|
|
157
|
+
* @param stateFactory A factory function to create the state
|
|
158
|
+
*
|
|
159
|
+
* @__NO_SIDE_EFFECTS__
|
|
160
|
+
*/
|
|
161
|
+
function createGlobalState(stateFactory) {
|
|
162
|
+
let initialized = false;
|
|
163
|
+
let state;
|
|
164
|
+
const scope = (0, vue.effectScope)(true);
|
|
165
|
+
return ((...args) => {
|
|
166
|
+
if (!initialized) {
|
|
167
|
+
state = scope.run(() => stateFactory(...args));
|
|
168
|
+
initialized = true;
|
|
169
|
+
}
|
|
170
|
+
return state;
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
173
|
|
|
174
174
|
//#endregion
|
|
175
175
|
//#region provideLocal/map.ts
|
|
176
|
-
const localProvidedStateMap = /* @__PURE__ */ new WeakMap();
|
|
176
|
+
const localProvidedStateMap = /* @__PURE__ */ new WeakMap();
|
|
177
177
|
|
|
178
178
|
//#endregion
|
|
179
179
|
//#region injectLocal/index.ts
|
|
180
180
|
/**
|
|
181
|
-
* On the basis of `inject`, it is allowed to directly call inject to obtain the value after call provide in the same component.
|
|
182
|
-
*
|
|
183
|
-
* @example
|
|
184
|
-
* ```ts
|
|
185
|
-
* injectLocal('MyInjectionKey', 1)
|
|
186
|
-
* const injectedValue = injectLocal('MyInjectionKey') // injectedValue === 1
|
|
187
|
-
* ```
|
|
188
|
-
*
|
|
189
|
-
* @__NO_SIDE_EFFECTS__
|
|
190
|
-
*/
|
|
191
|
-
const injectLocal = (...args) => {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
};
|
|
181
|
+
* On the basis of `inject`, it is allowed to directly call inject to obtain the value after call provide in the same component.
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* ```ts
|
|
185
|
+
* injectLocal('MyInjectionKey', 1)
|
|
186
|
+
* const injectedValue = injectLocal('MyInjectionKey') // injectedValue === 1
|
|
187
|
+
* ```
|
|
188
|
+
*
|
|
189
|
+
* @__NO_SIDE_EFFECTS__
|
|
190
|
+
*/
|
|
191
|
+
const injectLocal = (...args) => {
|
|
192
|
+
var _getCurrentInstance;
|
|
193
|
+
const key = args[0];
|
|
194
|
+
const instance = (_getCurrentInstance = (0, vue.getCurrentInstance)()) === null || _getCurrentInstance === void 0 ? void 0 : _getCurrentInstance.proxy;
|
|
195
|
+
if (instance == null && !(0, vue.hasInjectionContext)()) throw new Error("injectLocal must be called in setup");
|
|
196
|
+
if (instance && localProvidedStateMap.has(instance) && key in localProvidedStateMap.get(instance)) return localProvidedStateMap.get(instance)[key];
|
|
197
|
+
return (0, vue.inject)(...args);
|
|
198
|
+
};
|
|
199
199
|
|
|
200
200
|
//#endregion
|
|
201
201
|
//#region provideLocal/index.ts
|
|
202
202
|
/**
|
|
203
|
-
* On the basis of `provide`, it is allowed to directly call inject to obtain the value after call provide in the same component.
|
|
204
|
-
*
|
|
205
|
-
* @example
|
|
206
|
-
* ```ts
|
|
207
|
-
* provideLocal('MyInjectionKey', 1)
|
|
208
|
-
* const injectedValue = injectLocal('MyInjectionKey') // injectedValue === 1
|
|
209
|
-
* ```
|
|
210
|
-
*/
|
|
211
|
-
function provideLocal(key, value) {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
}
|
|
203
|
+
* On the basis of `provide`, it is allowed to directly call inject to obtain the value after call provide in the same component.
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```ts
|
|
207
|
+
* provideLocal('MyInjectionKey', 1)
|
|
208
|
+
* const injectedValue = injectLocal('MyInjectionKey') // injectedValue === 1
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
211
|
+
function provideLocal(key, value) {
|
|
212
|
+
var _getCurrentInstance;
|
|
213
|
+
const instance = (_getCurrentInstance = (0, vue.getCurrentInstance)()) === null || _getCurrentInstance === void 0 ? void 0 : _getCurrentInstance.proxy;
|
|
214
|
+
if (instance == null) throw new Error("provideLocal must be called in setup");
|
|
215
|
+
if (!localProvidedStateMap.has(instance)) localProvidedStateMap.set(instance, Object.create(null));
|
|
216
|
+
const localProvidedState = localProvidedStateMap.get(instance);
|
|
217
|
+
localProvidedState[key] = value;
|
|
218
|
+
return (0, vue.provide)(key, value);
|
|
219
|
+
}
|
|
220
220
|
|
|
221
221
|
//#endregion
|
|
222
222
|
//#region createInjectionState/index.ts
|
|
223
223
|
/**
|
|
224
|
-
* Create global state that can be injected into components.
|
|
225
|
-
*
|
|
226
|
-
* @see https://vueuse.org/createInjectionState
|
|
227
|
-
*
|
|
228
|
-
* @__NO_SIDE_EFFECTS__
|
|
229
|
-
*/
|
|
230
|
-
function createInjectionState(composable, options) {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
}
|
|
224
|
+
* Create global state that can be injected into components.
|
|
225
|
+
*
|
|
226
|
+
* @see https://vueuse.org/createInjectionState
|
|
227
|
+
*
|
|
228
|
+
* @__NO_SIDE_EFFECTS__
|
|
229
|
+
*/
|
|
230
|
+
function createInjectionState(composable, options) {
|
|
231
|
+
const key = (options === null || options === void 0 ? void 0 : options.injectionKey) || Symbol(composable.name || "InjectionState");
|
|
232
|
+
const defaultValue = options === null || options === void 0 ? void 0 : options.defaultValue;
|
|
233
|
+
const useProvidingState = (...args) => {
|
|
234
|
+
const state = composable(...args);
|
|
235
|
+
provideLocal(key, state);
|
|
236
|
+
return state;
|
|
237
|
+
};
|
|
238
|
+
const useInjectedState = () => injectLocal(key, defaultValue);
|
|
239
|
+
return [useProvidingState, useInjectedState];
|
|
240
|
+
}
|
|
241
241
|
|
|
242
242
|
//#endregion
|
|
243
243
|
//#region createRef/index.ts
|
|
244
244
|
/**
|
|
245
|
-
* Returns a `deepRef` or `shallowRef` depending on the `deep` param.
|
|
246
|
-
*
|
|
247
|
-
* @example createRef(1) // ShallowRef<number>
|
|
248
|
-
* @example createRef(1, false) // ShallowRef<number>
|
|
249
|
-
* @example createRef(1, true) // Ref<number>
|
|
250
|
-
* @example createRef("string") // ShallowRef<string>
|
|
251
|
-
* @example createRef<"A"|"B">("A", true) // Ref<"A"|"B">
|
|
252
|
-
*
|
|
253
|
-
* @param value
|
|
254
|
-
* @param deep
|
|
255
|
-
* @returns the `deepRef` or `shallowRef`
|
|
256
|
-
*
|
|
257
|
-
* @__NO_SIDE_EFFECTS__
|
|
258
|
-
*/
|
|
259
|
-
function createRef(value, deep) {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
}
|
|
245
|
+
* Returns a `deepRef` or `shallowRef` depending on the `deep` param.
|
|
246
|
+
*
|
|
247
|
+
* @example createRef(1) // ShallowRef<number>
|
|
248
|
+
* @example createRef(1, false) // ShallowRef<number>
|
|
249
|
+
* @example createRef(1, true) // Ref<number>
|
|
250
|
+
* @example createRef("string") // ShallowRef<string>
|
|
251
|
+
* @example createRef<"A"|"B">("A", true) // Ref<"A"|"B">
|
|
252
|
+
*
|
|
253
|
+
* @param value
|
|
254
|
+
* @param deep
|
|
255
|
+
* @returns the `deepRef` or `shallowRef`
|
|
256
|
+
*
|
|
257
|
+
* @__NO_SIDE_EFFECTS__
|
|
258
|
+
*/
|
|
259
|
+
function createRef(value, deep) {
|
|
260
|
+
if (deep === true) return (0, vue.ref)(value);
|
|
261
|
+
else return (0, vue.shallowRef)(value);
|
|
262
|
+
}
|
|
263
263
|
|
|
264
264
|
//#endregion
|
|
265
265
|
//#region utils/is.ts
|
|
266
|
-
const isClient = typeof window !== "undefined" && typeof document !== "undefined";
|
|
267
|
-
const isWorker = typeof WorkerGlobalScope !== "undefined" && globalThis instanceof WorkerGlobalScope;
|
|
268
|
-
const isDef = (val) => typeof val !== "undefined";
|
|
269
|
-
const notNullish = (val) => val != null;
|
|
270
|
-
const assert = (condition, ...infos) => {
|
|
271
|
-
|
|
272
|
-
};
|
|
273
|
-
const toString = Object.prototype.toString;
|
|
274
|
-
const isObject = (val) => toString.call(val) === "[object Object]";
|
|
275
|
-
const now = () => Date.now();
|
|
276
|
-
const timestamp = () => +Date.now();
|
|
277
|
-
const clamp = (n, min, max) => Math.min(max, Math.max(min, n));
|
|
278
|
-
const noop = () => {};
|
|
279
|
-
const rand = (min, max) => {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
};
|
|
284
|
-
const hasOwn = (val, key) => Object.prototype.hasOwnProperty.call(val, key);
|
|
285
|
-
const isIOS = /* @__PURE__ */ getIsIOS();
|
|
286
|
-
function getIsIOS() {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
}
|
|
266
|
+
const isClient = typeof window !== "undefined" && typeof document !== "undefined";
|
|
267
|
+
const isWorker = typeof WorkerGlobalScope !== "undefined" && globalThis instanceof WorkerGlobalScope;
|
|
268
|
+
const isDef = (val) => typeof val !== "undefined";
|
|
269
|
+
const notNullish = (val) => val != null;
|
|
270
|
+
const assert = (condition, ...infos) => {
|
|
271
|
+
if (!condition) console.warn(...infos);
|
|
272
|
+
};
|
|
273
|
+
const toString = Object.prototype.toString;
|
|
274
|
+
const isObject = (val) => toString.call(val) === "[object Object]";
|
|
275
|
+
const now = () => Date.now();
|
|
276
|
+
const timestamp = () => +Date.now();
|
|
277
|
+
const clamp = (n, min, max) => Math.min(max, Math.max(min, n));
|
|
278
|
+
const noop = () => {};
|
|
279
|
+
const rand = (min, max) => {
|
|
280
|
+
min = Math.ceil(min);
|
|
281
|
+
max = Math.floor(max);
|
|
282
|
+
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
283
|
+
};
|
|
284
|
+
const hasOwn = (val, key) => Object.prototype.hasOwnProperty.call(val, key);
|
|
285
|
+
const isIOS = /* @__PURE__ */ getIsIOS();
|
|
286
|
+
function getIsIOS() {
|
|
287
|
+
var _window, _window2, _window3;
|
|
288
|
+
return isClient && ((_window = window) === null || _window === void 0 || (_window = _window.navigator) === null || _window === void 0 ? void 0 : _window.userAgent) && (/iP(?:ad|hone|od)/.test(window.navigator.userAgent) || ((_window2 = window) === null || _window2 === void 0 || (_window2 = _window2.navigator) === null || _window2 === void 0 ? void 0 : _window2.maxTouchPoints) > 2 && /iPad|Macintosh/.test((_window3 = window) === null || _window3 === void 0 ? void 0 : _window3.navigator.userAgent));
|
|
289
|
+
}
|
|
290
290
|
|
|
291
291
|
//#endregion
|
|
292
292
|
//#region toRef/index.ts
|
|
293
|
-
function toRef(...args) {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
}
|
|
293
|
+
function toRef(...args) {
|
|
294
|
+
if (args.length !== 1) return (0, vue.toRef)(...args);
|
|
295
|
+
const r = args[0];
|
|
296
|
+
return typeof r === "function" ? (0, vue.readonly)((0, vue.customRef)(() => ({
|
|
297
|
+
get: r,
|
|
298
|
+
set: noop
|
|
299
|
+
}))) : (0, vue.ref)(r);
|
|
300
|
+
}
|
|
301
301
|
|
|
302
302
|
//#endregion
|
|
303
303
|
//#region utils/filters.ts
|
|
304
304
|
/**
|
|
305
|
-
* @internal
|
|
306
|
-
*/
|
|
307
|
-
function createFilterWrapper(filter, fn) {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
}
|
|
317
|
-
return wrapper;
|
|
318
|
-
}
|
|
319
|
-
const bypassFilter = (invoke$1) => {
|
|
320
|
-
return invoke$1();
|
|
321
|
-
};
|
|
322
|
-
/**
|
|
323
|
-
* Create an EventFilter that debounce the events
|
|
324
|
-
*/
|
|
325
|
-
function debounceFilter(ms, options = {}) {
|
|
326
|
-
let timer;
|
|
327
|
-
let maxTimer;
|
|
328
|
-
let lastRejector = noop;
|
|
329
|
-
const _clearTimeout = (timer$1) => {
|
|
330
|
-
clearTimeout(timer$1);
|
|
331
|
-
lastRejector();
|
|
332
|
-
lastRejector = noop;
|
|
333
|
-
};
|
|
334
|
-
let lastInvoker;
|
|
335
|
-
const filter = (invoke$1) => {
|
|
336
|
-
const duration = (0, vue.toValue)(ms);
|
|
337
|
-
const maxDuration = (0, vue.toValue)(options.maxWait);
|
|
338
|
-
if (timer) _clearTimeout(timer);
|
|
339
|
-
if (duration <= 0 || maxDuration !== void 0 && maxDuration <= 0) {
|
|
340
|
-
if (maxTimer) {
|
|
341
|
-
_clearTimeout(maxTimer);
|
|
342
|
-
maxTimer = void 0;
|
|
343
|
-
}
|
|
344
|
-
return Promise.resolve(invoke$1());
|
|
305
|
+
* @internal
|
|
306
|
+
*/
|
|
307
|
+
function createFilterWrapper(filter, fn) {
|
|
308
|
+
function wrapper(...args) {
|
|
309
|
+
return new Promise((resolve, reject) => {
|
|
310
|
+
Promise.resolve(filter(() => fn.apply(this, args), {
|
|
311
|
+
fn,
|
|
312
|
+
thisArg: this,
|
|
313
|
+
args
|
|
314
|
+
})).then(resolve).catch(reject);
|
|
315
|
+
});
|
|
345
316
|
}
|
|
346
|
-
return
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
if (timer) _clearTimeout(timer);
|
|
351
|
-
maxTimer = void 0;
|
|
352
|
-
resolve(lastInvoker());
|
|
353
|
-
}, maxDuration);
|
|
354
|
-
timer = setTimeout(() => {
|
|
355
|
-
if (maxTimer) _clearTimeout(maxTimer);
|
|
356
|
-
maxTimer = void 0;
|
|
357
|
-
resolve(invoke$1());
|
|
358
|
-
}, duration);
|
|
359
|
-
});
|
|
317
|
+
return wrapper;
|
|
318
|
+
}
|
|
319
|
+
const bypassFilter = (invoke$1) => {
|
|
320
|
+
return invoke$1();
|
|
360
321
|
};
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
let trailing;
|
|
371
|
-
let leading;
|
|
372
|
-
let rejectOnCancel;
|
|
373
|
-
if (!(0, vue.isRef)(args[0]) && typeof args[0] === "object") ({delay: ms, trailing = true, leading = true, rejectOnCancel = false} = args[0]);
|
|
374
|
-
else [ms, trailing = true, leading = true, rejectOnCancel = false] = args;
|
|
375
|
-
const clear = () => {
|
|
376
|
-
if (timer) {
|
|
377
|
-
clearTimeout(timer);
|
|
378
|
-
timer = void 0;
|
|
322
|
+
/**
|
|
323
|
+
* Create an EventFilter that debounce the events
|
|
324
|
+
*/
|
|
325
|
+
function debounceFilter(ms, options = {}) {
|
|
326
|
+
let timer;
|
|
327
|
+
let maxTimer;
|
|
328
|
+
let lastRejector = noop;
|
|
329
|
+
const _clearTimeout = (timer$1) => {
|
|
330
|
+
clearTimeout(timer$1);
|
|
379
331
|
lastRejector();
|
|
380
332
|
lastRejector = noop;
|
|
381
|
-
}
|
|
382
|
-
};
|
|
383
|
-
const filter = (_invoke) => {
|
|
384
|
-
const duration = (0, vue.toValue)(ms);
|
|
385
|
-
const elapsed = Date.now() - lastExec;
|
|
386
|
-
const invoke$1 = () => {
|
|
387
|
-
return lastValue = _invoke();
|
|
388
333
|
};
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
334
|
+
let lastInvoker;
|
|
335
|
+
const filter = (invoke$1) => {
|
|
336
|
+
const duration = (0, vue.toValue)(ms);
|
|
337
|
+
const maxDuration = (0, vue.toValue)(options.maxWait);
|
|
338
|
+
if (timer) _clearTimeout(timer);
|
|
339
|
+
if (duration <= 0 || maxDuration !== void 0 && maxDuration <= 0) {
|
|
340
|
+
if (maxTimer) {
|
|
341
|
+
_clearTimeout(maxTimer);
|
|
342
|
+
maxTimer = void 0;
|
|
343
|
+
}
|
|
344
|
+
return Promise.resolve(invoke$1());
|
|
345
|
+
}
|
|
346
|
+
return new Promise((resolve, reject) => {
|
|
347
|
+
lastRejector = options.rejectOnCancel ? reject : resolve;
|
|
348
|
+
lastInvoker = invoke$1;
|
|
349
|
+
if (maxDuration && !maxTimer) maxTimer = setTimeout(() => {
|
|
350
|
+
if (timer) _clearTimeout(timer);
|
|
351
|
+
maxTimer = void 0;
|
|
352
|
+
resolve(lastInvoker());
|
|
353
|
+
}, maxDuration);
|
|
354
|
+
timer = setTimeout(() => {
|
|
355
|
+
if (maxTimer) _clearTimeout(maxTimer);
|
|
356
|
+
maxTimer = void 0;
|
|
357
|
+
resolve(invoke$1());
|
|
358
|
+
}, duration);
|
|
359
|
+
});
|
|
360
|
+
};
|
|
361
|
+
return filter;
|
|
362
|
+
}
|
|
363
|
+
function throttleFilter(...args) {
|
|
364
|
+
let lastExec = 0;
|
|
365
|
+
let timer;
|
|
366
|
+
let isLeading = true;
|
|
367
|
+
let lastRejector = noop;
|
|
368
|
+
let lastValue;
|
|
369
|
+
let ms;
|
|
370
|
+
let trailing;
|
|
371
|
+
let leading;
|
|
372
|
+
let rejectOnCancel;
|
|
373
|
+
if (!(0, vue.isRef)(args[0]) && typeof args[0] === "object") ({delay: ms, trailing = true, leading = true, rejectOnCancel = false} = args[0]);
|
|
374
|
+
else [ms, trailing = true, leading = true, rejectOnCancel = false] = args;
|
|
375
|
+
const clear = () => {
|
|
376
|
+
if (timer) {
|
|
377
|
+
clearTimeout(timer);
|
|
378
|
+
timer = void 0;
|
|
379
|
+
lastRejector();
|
|
380
|
+
lastRejector = noop;
|
|
381
|
+
}
|
|
382
|
+
};
|
|
383
|
+
const filter = (_invoke) => {
|
|
384
|
+
const duration = (0, vue.toValue)(ms);
|
|
385
|
+
const elapsed = Date.now() - lastExec;
|
|
386
|
+
const invoke$1 = () => {
|
|
387
|
+
return lastValue = _invoke();
|
|
388
|
+
};
|
|
389
|
+
clear();
|
|
390
|
+
if (duration <= 0) {
|
|
400
391
|
lastExec = Date.now();
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
resume
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
392
|
+
return invoke$1();
|
|
393
|
+
}
|
|
394
|
+
if (elapsed > duration) {
|
|
395
|
+
lastExec = Date.now();
|
|
396
|
+
if (leading || !isLeading) invoke$1();
|
|
397
|
+
} else if (trailing) lastValue = new Promise((resolve, reject) => {
|
|
398
|
+
lastRejector = rejectOnCancel ? reject : resolve;
|
|
399
|
+
timer = setTimeout(() => {
|
|
400
|
+
lastExec = Date.now();
|
|
401
|
+
isLeading = true;
|
|
402
|
+
resolve(invoke$1());
|
|
403
|
+
clear();
|
|
404
|
+
}, Math.max(0, duration - elapsed));
|
|
405
|
+
});
|
|
406
|
+
if (!leading && !timer) timer = setTimeout(() => isLeading = true, duration);
|
|
407
|
+
isLeading = false;
|
|
408
|
+
return lastValue;
|
|
409
|
+
};
|
|
410
|
+
return filter;
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* EventFilter that gives extra controls to pause and resume the filter
|
|
414
|
+
*
|
|
415
|
+
* @param extendFilter Extra filter to apply when the PausableFilter is active, default to none
|
|
416
|
+
* @param options Options to configure the filter
|
|
417
|
+
*/
|
|
418
|
+
function pausableFilter(extendFilter = bypassFilter, options = {}) {
|
|
419
|
+
const { initialState = "active" } = options;
|
|
420
|
+
const isActive = toRef(initialState === "active");
|
|
421
|
+
function pause() {
|
|
422
|
+
isActive.value = false;
|
|
423
|
+
}
|
|
424
|
+
function resume() {
|
|
425
|
+
isActive.value = true;
|
|
426
|
+
}
|
|
427
|
+
const eventFilter = (...args) => {
|
|
428
|
+
if (isActive.value) extendFilter(...args);
|
|
429
|
+
};
|
|
430
|
+
return {
|
|
431
|
+
isActive: (0, vue.readonly)(isActive),
|
|
432
|
+
pause,
|
|
433
|
+
resume,
|
|
434
|
+
eventFilter
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
437
|
|
|
438
438
|
//#endregion
|
|
439
439
|
//#region utils/general.ts
|
|
440
|
-
function promiseTimeout(ms, throwOnTimeout = false, reason = "Timeout") {
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
}
|
|
446
|
-
function identity(arg) {
|
|
447
|
-
|
|
448
|
-
}
|
|
449
|
-
/**
|
|
450
|
-
* Create singleton promise function
|
|
451
|
-
*
|
|
452
|
-
* @example
|
|
453
|
-
* ```
|
|
454
|
-
* const promise = createSingletonPromise(async () => { ... })
|
|
455
|
-
*
|
|
456
|
-
* await promise()
|
|
457
|
-
* await promise() // all of them will be bind to a single promise instance
|
|
458
|
-
* await promise() // and be resolved together
|
|
459
|
-
* ```
|
|
460
|
-
*/
|
|
461
|
-
function createSingletonPromise(fn) {
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
}
|
|
467
|
-
wrapper.reset = async () => {
|
|
468
|
-
const _prev = _promise;
|
|
469
|
-
_promise = void 0;
|
|
470
|
-
if (_prev) await _prev;
|
|
471
|
-
};
|
|
472
|
-
return wrapper;
|
|
473
|
-
}
|
|
474
|
-
function invoke(fn) {
|
|
475
|
-
return fn();
|
|
476
|
-
}
|
|
477
|
-
function containsProp(obj, ...props) {
|
|
478
|
-
return props.some((k) => k in obj);
|
|
479
|
-
}
|
|
480
|
-
function increaseWithUnit(target, delta) {
|
|
481
|
-
var _target$match;
|
|
482
|
-
if (typeof target === "number") return target + delta;
|
|
483
|
-
const value = ((_target$match = target.match(/^-?\d+\.?\d*/)) === null || _target$match === void 0 ? void 0 : _target$match[0]) || "";
|
|
484
|
-
const unit = target.slice(value.length);
|
|
485
|
-
const result = Number.parseFloat(value) + delta;
|
|
486
|
-
if (Number.isNaN(result)) return target;
|
|
487
|
-
return result + unit;
|
|
488
|
-
}
|
|
489
|
-
/**
|
|
490
|
-
* Get a px value for SSR use, do not rely on this method outside of SSR as REM unit is assumed at 16px, which might not be the case on the client
|
|
491
|
-
*/
|
|
492
|
-
function pxValue(px) {
|
|
493
|
-
return px.endsWith("rem") ? Number.parseFloat(px) * 16 : Number.parseFloat(px);
|
|
494
|
-
}
|
|
495
|
-
/**
|
|
496
|
-
* Create a new subset object by giving keys
|
|
497
|
-
*/
|
|
498
|
-
function objectPick(obj, keys, omitUndefined = false) {
|
|
499
|
-
return keys.reduce((n, k) => {
|
|
500
|
-
if (k in obj) {
|
|
501
|
-
if (!omitUndefined || obj[k] !== void 0) n[k] = obj[k];
|
|
440
|
+
function promiseTimeout(ms, throwOnTimeout = false, reason = "Timeout") {
|
|
441
|
+
return new Promise((resolve, reject) => {
|
|
442
|
+
if (throwOnTimeout) setTimeout(() => reject(reason), ms);
|
|
443
|
+
else setTimeout(resolve, ms);
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
function identity(arg) {
|
|
447
|
+
return arg;
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Create singleton promise function
|
|
451
|
+
*
|
|
452
|
+
* @example
|
|
453
|
+
* ```
|
|
454
|
+
* const promise = createSingletonPromise(async () => { ... })
|
|
455
|
+
*
|
|
456
|
+
* await promise()
|
|
457
|
+
* await promise() // all of them will be bind to a single promise instance
|
|
458
|
+
* await promise() // and be resolved together
|
|
459
|
+
* ```
|
|
460
|
+
*/
|
|
461
|
+
function createSingletonPromise(fn) {
|
|
462
|
+
let _promise;
|
|
463
|
+
function wrapper() {
|
|
464
|
+
if (!_promise) _promise = fn();
|
|
465
|
+
return _promise;
|
|
502
466
|
}
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
return (
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
467
|
+
wrapper.reset = async () => {
|
|
468
|
+
const _prev = _promise;
|
|
469
|
+
_promise = void 0;
|
|
470
|
+
if (_prev) await _prev;
|
|
471
|
+
};
|
|
472
|
+
return wrapper;
|
|
473
|
+
}
|
|
474
|
+
function invoke(fn) {
|
|
475
|
+
return fn();
|
|
476
|
+
}
|
|
477
|
+
function containsProp(obj, ...props) {
|
|
478
|
+
return props.some((k) => k in obj);
|
|
479
|
+
}
|
|
480
|
+
function increaseWithUnit(target, delta) {
|
|
481
|
+
var _target$match;
|
|
482
|
+
if (typeof target === "number") return target + delta;
|
|
483
|
+
const value = ((_target$match = target.match(/^-?\d+\.?\d*/)) === null || _target$match === void 0 ? void 0 : _target$match[0]) || "";
|
|
484
|
+
const unit = target.slice(value.length);
|
|
485
|
+
const result = Number.parseFloat(value) + delta;
|
|
486
|
+
if (Number.isNaN(result)) return target;
|
|
487
|
+
return result + unit;
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* Get a px value for SSR use, do not rely on this method outside of SSR as REM unit is assumed at 16px, which might not be the case on the client
|
|
491
|
+
*/
|
|
492
|
+
function pxValue(px) {
|
|
493
|
+
return px.endsWith("rem") ? Number.parseFloat(px) * 16 : Number.parseFloat(px);
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* Create a new subset object by giving keys
|
|
497
|
+
*/
|
|
498
|
+
function objectPick(obj, keys, omitUndefined = false) {
|
|
499
|
+
return keys.reduce((n, k) => {
|
|
500
|
+
if (k in obj) {
|
|
501
|
+
if (!omitUndefined || obj[k] !== void 0) n[k] = obj[k];
|
|
502
|
+
}
|
|
503
|
+
return n;
|
|
504
|
+
}, {});
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* Create a new subset object by omit giving keys
|
|
508
|
+
*/
|
|
509
|
+
function objectOmit(obj, keys, omitUndefined = false) {
|
|
510
|
+
return Object.fromEntries(Object.entries(obj).filter(([key, value]) => {
|
|
511
|
+
return (!omitUndefined || value !== void 0) && !keys.includes(key);
|
|
512
|
+
}));
|
|
513
|
+
}
|
|
514
|
+
function objectEntries(obj) {
|
|
515
|
+
return Object.entries(obj);
|
|
516
|
+
}
|
|
517
|
+
function toArray(value) {
|
|
518
|
+
return Array.isArray(value) ? value : [value];
|
|
519
|
+
}
|
|
520
520
|
|
|
521
521
|
//#endregion
|
|
522
522
|
//#region utils/port.ts
|
|
523
|
-
function cacheStringFunction(fn) {
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
523
|
+
function cacheStringFunction(fn) {
|
|
524
|
+
const cache = Object.create(null);
|
|
525
|
+
return ((str) => {
|
|
526
|
+
return cache[str] || (cache[str] = fn(str));
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
const hyphenateRE = /\B([A-Z])/g;
|
|
530
|
+
const hyphenate = cacheStringFunction((str) => str.replace(hyphenateRE, "-$1").toLowerCase());
|
|
531
|
+
const camelizeRE = /-(\w)/g;
|
|
532
|
+
const camelize = cacheStringFunction((str) => {
|
|
533
|
+
return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : "");
|
|
527
534
|
});
|
|
528
|
-
}
|
|
529
|
-
const hyphenateRE = /\B([A-Z])/g;
|
|
530
|
-
const hyphenate = cacheStringFunction((str) => str.replace(hyphenateRE, "-$1").toLowerCase());
|
|
531
|
-
const camelizeRE = /-(\w)/g;
|
|
532
|
-
const camelize = cacheStringFunction((str) => {
|
|
533
|
-
return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : "");
|
|
534
|
-
});
|
|
535
535
|
|
|
536
536
|
//#endregion
|
|
537
537
|
//#region utils/vue.ts
|
|
538
|
-
function getLifeCycleTarget(target) {
|
|
539
|
-
|
|
540
|
-
}
|
|
538
|
+
function getLifeCycleTarget(target) {
|
|
539
|
+
return target || (0, vue.getCurrentInstance)();
|
|
540
|
+
}
|
|
541
541
|
|
|
542
542
|
//#endregion
|
|
543
543
|
//#region createSharedComposable/index.ts
|
|
544
544
|
/**
|
|
545
|
-
* Make a composable function usable with multiple Vue instances.
|
|
546
|
-
*
|
|
547
|
-
* @see https://vueuse.org/createSharedComposable
|
|
548
|
-
*
|
|
549
|
-
* @__NO_SIDE_EFFECTS__
|
|
550
|
-
*/
|
|
551
|
-
function createSharedComposable(composable) {
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
}
|
|
545
|
+
* Make a composable function usable with multiple Vue instances.
|
|
546
|
+
*
|
|
547
|
+
* @see https://vueuse.org/createSharedComposable
|
|
548
|
+
*
|
|
549
|
+
* @__NO_SIDE_EFFECTS__
|
|
550
|
+
*/
|
|
551
|
+
function createSharedComposable(composable) {
|
|
552
|
+
if (!isClient) return composable;
|
|
553
|
+
let subscribers = 0;
|
|
554
|
+
let state;
|
|
555
|
+
let scope;
|
|
556
|
+
const dispose = () => {
|
|
557
|
+
subscribers -= 1;
|
|
558
|
+
if (scope && subscribers <= 0) {
|
|
559
|
+
scope.stop();
|
|
560
|
+
state = void 0;
|
|
561
|
+
scope = void 0;
|
|
562
|
+
}
|
|
563
|
+
};
|
|
564
|
+
return ((...args) => {
|
|
565
|
+
subscribers += 1;
|
|
566
|
+
if (!scope) {
|
|
567
|
+
scope = (0, vue.effectScope)(true);
|
|
568
|
+
state = scope.run(() => composable(...args));
|
|
569
|
+
}
|
|
570
|
+
tryOnScopeDispose(dispose);
|
|
571
|
+
return state;
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
574
|
|
|
575
575
|
//#endregion
|
|
576
576
|
//#region extendRef/index.ts
|
|
577
|
-
function extendRef(ref, extend, { enumerable = false, unwrap = true } = {}) {
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
577
|
+
function extendRef(ref, extend, { enumerable = false, unwrap = true } = {}) {
|
|
578
|
+
for (const [key, value] of Object.entries(extend)) {
|
|
579
|
+
if (key === "value") continue;
|
|
580
|
+
if ((0, vue.isRef)(value) && unwrap) Object.defineProperty(ref, key, {
|
|
581
|
+
get() {
|
|
582
|
+
return value.value;
|
|
583
|
+
},
|
|
584
|
+
set(v) {
|
|
585
|
+
value.value = v;
|
|
586
|
+
},
|
|
587
|
+
enumerable
|
|
588
|
+
});
|
|
589
|
+
else Object.defineProperty(ref, key, {
|
|
590
|
+
value,
|
|
591
|
+
enumerable
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
return ref;
|
|
593
595
|
}
|
|
594
|
-
return ref;
|
|
595
|
-
}
|
|
596
596
|
|
|
597
597
|
//#endregion
|
|
598
598
|
//#region get/index.ts
|
|
599
|
-
function get(obj, key) {
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
}
|
|
599
|
+
function get(obj, key) {
|
|
600
|
+
if (key == null) return (0, vue.unref)(obj);
|
|
601
|
+
return (0, vue.unref)(obj)[key];
|
|
602
|
+
}
|
|
603
603
|
|
|
604
604
|
//#endregion
|
|
605
605
|
//#region isDefined/index.ts
|
|
606
|
-
function isDefined(v) {
|
|
607
|
-
|
|
608
|
-
}
|
|
606
|
+
function isDefined(v) {
|
|
607
|
+
return (0, vue.unref)(v) != null;
|
|
608
|
+
}
|
|
609
609
|
|
|
610
610
|
//#endregion
|
|
611
611
|
//#region makeDestructurable/index.ts
|
|
612
|
-
/* @__NO_SIDE_EFFECTS__ */
|
|
613
|
-
function makeDestructurable(obj, arr) {
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
}
|
|
612
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
613
|
+
function makeDestructurable(obj, arr) {
|
|
614
|
+
if (typeof Symbol !== "undefined") {
|
|
615
|
+
const clone = { ...obj };
|
|
616
|
+
Object.defineProperty(clone, Symbol.iterator, {
|
|
617
|
+
enumerable: false,
|
|
618
|
+
value() {
|
|
619
|
+
let index = 0;
|
|
620
|
+
return { next: () => ({
|
|
621
|
+
value: arr[index++],
|
|
622
|
+
done: index > arr.length
|
|
623
|
+
}) };
|
|
624
|
+
}
|
|
625
|
+
});
|
|
626
|
+
return clone;
|
|
627
|
+
} else return Object.assign([...arr], obj);
|
|
628
|
+
}
|
|
629
629
|
|
|
630
630
|
//#endregion
|
|
631
631
|
//#region reactify/index.ts
|
|
632
632
|
/**
|
|
633
|
-
* Converts plain function into a reactive function.
|
|
634
|
-
* The converted function accepts refs as it's arguments
|
|
635
|
-
* and returns a ComputedRef, with proper typing.
|
|
636
|
-
*
|
|
637
|
-
* @param fn - Source function
|
|
638
|
-
* @param options - Options
|
|
639
|
-
*
|
|
640
|
-
* @__NO_SIDE_EFFECTS__
|
|
641
|
-
*/
|
|
642
|
-
function reactify(fn, options) {
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
}
|
|
648
|
-
/** @deprecated use `reactify` instead */
|
|
649
|
-
const createReactiveFn = reactify;
|
|
633
|
+
* Converts plain function into a reactive function.
|
|
634
|
+
* The converted function accepts refs as it's arguments
|
|
635
|
+
* and returns a ComputedRef, with proper typing.
|
|
636
|
+
*
|
|
637
|
+
* @param fn - Source function
|
|
638
|
+
* @param options - Options
|
|
639
|
+
*
|
|
640
|
+
* @__NO_SIDE_EFFECTS__
|
|
641
|
+
*/
|
|
642
|
+
function reactify(fn, options) {
|
|
643
|
+
const unrefFn = (options === null || options === void 0 ? void 0 : options.computedGetter) === false ? vue.unref : vue.toValue;
|
|
644
|
+
return function(...args) {
|
|
645
|
+
return (0, vue.computed)(() => fn.apply(this, args.map((i) => unrefFn(i))));
|
|
646
|
+
};
|
|
647
|
+
}
|
|
648
|
+
/** @deprecated use `reactify` instead */
|
|
649
|
+
const createReactiveFn = reactify;
|
|
650
650
|
|
|
651
651
|
//#endregion
|
|
652
652
|
//#region reactifyObject/index.ts
|
|
653
653
|
/**
|
|
654
|
-
* Apply `reactify` to an object
|
|
655
|
-
*
|
|
656
|
-
* @__NO_SIDE_EFFECTS__
|
|
657
|
-
*/
|
|
658
|
-
function reactifyObject(obj, optionsOrKeys = {}) {
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
}
|
|
654
|
+
* Apply `reactify` to an object
|
|
655
|
+
*
|
|
656
|
+
* @__NO_SIDE_EFFECTS__
|
|
657
|
+
*/
|
|
658
|
+
function reactifyObject(obj, optionsOrKeys = {}) {
|
|
659
|
+
let keys = [];
|
|
660
|
+
let options;
|
|
661
|
+
if (Array.isArray(optionsOrKeys)) keys = optionsOrKeys;
|
|
662
|
+
else {
|
|
663
|
+
options = optionsOrKeys;
|
|
664
|
+
const { includeOwnProperties = true } = optionsOrKeys;
|
|
665
|
+
keys.push(...Object.keys(obj));
|
|
666
|
+
if (includeOwnProperties) keys.push(...Object.getOwnPropertyNames(obj));
|
|
667
|
+
}
|
|
668
|
+
return Object.fromEntries(keys.map((key) => {
|
|
669
|
+
const value = obj[key];
|
|
670
|
+
return [key, typeof value === "function" ? reactify(value.bind(obj), options) : value];
|
|
671
|
+
}));
|
|
672
|
+
}
|
|
673
673
|
|
|
674
674
|
//#endregion
|
|
675
675
|
//#region toReactive/index.ts
|
|
676
676
|
/**
|
|
677
|
-
* Converts ref to reactive.
|
|
678
|
-
*
|
|
679
|
-
* @see https://vueuse.org/toReactive
|
|
680
|
-
* @param objectRef A ref of object
|
|
681
|
-
*/
|
|
682
|
-
function toReactive(objectRef) {
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
}
|
|
677
|
+
* Converts ref to reactive.
|
|
678
|
+
*
|
|
679
|
+
* @see https://vueuse.org/toReactive
|
|
680
|
+
* @param objectRef A ref of object
|
|
681
|
+
*/
|
|
682
|
+
function toReactive(objectRef) {
|
|
683
|
+
if (!(0, vue.isRef)(objectRef)) return (0, vue.reactive)(objectRef);
|
|
684
|
+
const proxy = new Proxy({}, {
|
|
685
|
+
get(_, p, receiver) {
|
|
686
|
+
return (0, vue.unref)(Reflect.get(objectRef.value, p, receiver));
|
|
687
|
+
},
|
|
688
|
+
set(_, p, value) {
|
|
689
|
+
if ((0, vue.isRef)(objectRef.value[p]) && !(0, vue.isRef)(value)) objectRef.value[p].value = value;
|
|
690
|
+
else objectRef.value[p] = value;
|
|
691
|
+
return true;
|
|
692
|
+
},
|
|
693
|
+
deleteProperty(_, p) {
|
|
694
|
+
return Reflect.deleteProperty(objectRef.value, p);
|
|
695
|
+
},
|
|
696
|
+
has(_, p) {
|
|
697
|
+
return Reflect.has(objectRef.value, p);
|
|
698
|
+
},
|
|
699
|
+
ownKeys() {
|
|
700
|
+
return Object.keys(objectRef.value);
|
|
701
|
+
},
|
|
702
|
+
getOwnPropertyDescriptor() {
|
|
703
|
+
return {
|
|
704
|
+
enumerable: true,
|
|
705
|
+
configurable: true
|
|
706
|
+
};
|
|
707
|
+
}
|
|
708
|
+
});
|
|
709
|
+
return (0, vue.reactive)(proxy);
|
|
710
|
+
}
|
|
711
711
|
|
|
712
712
|
//#endregion
|
|
713
713
|
//#region reactiveComputed/index.ts
|
|
714
714
|
/**
|
|
715
|
-
* Computed reactive object.
|
|
716
|
-
*/
|
|
717
|
-
function reactiveComputed(fn) {
|
|
718
|
-
|
|
719
|
-
}
|
|
715
|
+
* Computed reactive object.
|
|
716
|
+
*/
|
|
717
|
+
function reactiveComputed(fn) {
|
|
718
|
+
return toReactive((0, vue.computed)(fn));
|
|
719
|
+
}
|
|
720
720
|
|
|
721
721
|
//#endregion
|
|
722
722
|
//#region reactiveOmit/index.ts
|
|
723
723
|
/**
|
|
724
|
-
* Reactively omit fields from a reactive object
|
|
725
|
-
*
|
|
726
|
-
* @see https://vueuse.org/reactiveOmit
|
|
727
|
-
*/
|
|
728
|
-
function reactiveOmit(obj, ...keys) {
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
}
|
|
724
|
+
* Reactively omit fields from a reactive object
|
|
725
|
+
*
|
|
726
|
+
* @see https://vueuse.org/reactiveOmit
|
|
727
|
+
*/
|
|
728
|
+
function reactiveOmit(obj, ...keys) {
|
|
729
|
+
const flatKeys = keys.flat();
|
|
730
|
+
const predicate = flatKeys[0];
|
|
731
|
+
return reactiveComputed(() => typeof predicate === "function" ? Object.fromEntries(Object.entries((0, vue.toRefs)(obj)).filter(([k, v]) => !predicate((0, vue.toValue)(v), k))) : Object.fromEntries(Object.entries((0, vue.toRefs)(obj)).filter((e) => !flatKeys.includes(e[0]))));
|
|
732
|
+
}
|
|
733
733
|
|
|
734
734
|
//#endregion
|
|
735
735
|
//#region reactivePick/index.ts
|
|
736
736
|
/**
|
|
737
|
-
* Reactively pick fields from a reactive object
|
|
738
|
-
*
|
|
739
|
-
* @see https://vueuse.org/reactivePick
|
|
740
|
-
*/
|
|
741
|
-
function reactivePick(obj, ...keys) {
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
}
|
|
737
|
+
* Reactively pick fields from a reactive object
|
|
738
|
+
*
|
|
739
|
+
* @see https://vueuse.org/reactivePick
|
|
740
|
+
*/
|
|
741
|
+
function reactivePick(obj, ...keys) {
|
|
742
|
+
const flatKeys = keys.flat();
|
|
743
|
+
const predicate = flatKeys[0];
|
|
744
|
+
return reactiveComputed(() => typeof predicate === "function" ? Object.fromEntries(Object.entries((0, vue.toRefs)(obj)).filter(([k, v]) => predicate((0, vue.toValue)(v), k))) : Object.fromEntries(flatKeys.map((k) => [k, toRef(obj, k)])));
|
|
745
|
+
}
|
|
746
746
|
|
|
747
747
|
//#endregion
|
|
748
748
|
//#region refAutoReset/index.ts
|
|
749
749
|
/**
|
|
750
|
-
* Create a ref which will be reset to the default value after some time.
|
|
751
|
-
*
|
|
752
|
-
* @see https://vueuse.org/refAutoReset
|
|
753
|
-
* @param defaultValue The value which will be set.
|
|
754
|
-
* @param afterMs A zero-or-greater delay in milliseconds.
|
|
755
|
-
*/
|
|
756
|
-
function refAutoReset(defaultValue, afterMs = 1e4) {
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
trigger();
|
|
763
|
-
}, (0, vue.toValue)(afterMs));
|
|
764
|
-
tryOnScopeDispose(() => {
|
|
765
|
-
clearTimeout(timer);
|
|
766
|
-
});
|
|
767
|
-
return {
|
|
768
|
-
get() {
|
|
769
|
-
track();
|
|
770
|
-
return value;
|
|
771
|
-
},
|
|
772
|
-
set(newValue) {
|
|
773
|
-
value = newValue;
|
|
750
|
+
* Create a ref which will be reset to the default value after some time.
|
|
751
|
+
*
|
|
752
|
+
* @see https://vueuse.org/refAutoReset
|
|
753
|
+
* @param defaultValue The value which will be set.
|
|
754
|
+
* @param afterMs A zero-or-greater delay in milliseconds.
|
|
755
|
+
*/
|
|
756
|
+
function refAutoReset(defaultValue, afterMs = 1e4) {
|
|
757
|
+
return (0, vue.customRef)((track, trigger) => {
|
|
758
|
+
let value = (0, vue.toValue)(defaultValue);
|
|
759
|
+
let timer;
|
|
760
|
+
const resetAfter = () => setTimeout(() => {
|
|
761
|
+
value = (0, vue.toValue)(defaultValue);
|
|
774
762
|
trigger();
|
|
763
|
+
}, (0, vue.toValue)(afterMs));
|
|
764
|
+
tryOnScopeDispose(() => {
|
|
775
765
|
clearTimeout(timer);
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
766
|
+
});
|
|
767
|
+
return {
|
|
768
|
+
get() {
|
|
769
|
+
track();
|
|
770
|
+
return value;
|
|
771
|
+
},
|
|
772
|
+
set(newValue) {
|
|
773
|
+
value = newValue;
|
|
774
|
+
trigger();
|
|
775
|
+
clearTimeout(timer);
|
|
776
|
+
timer = resetAfter();
|
|
777
|
+
}
|
|
778
|
+
};
|
|
779
|
+
});
|
|
780
|
+
}
|
|
781
|
+
/** @deprecated use `refAutoReset` instead */
|
|
782
|
+
const autoResetRef = refAutoReset;
|
|
783
783
|
|
|
784
784
|
//#endregion
|
|
785
785
|
//#region useDebounceFn/index.ts
|
|
786
786
|
/**
|
|
787
|
-
* Debounce execution of a function.
|
|
788
|
-
*
|
|
789
|
-
* @see https://vueuse.org/useDebounceFn
|
|
790
|
-
* @param fn A function to be executed after delay milliseconds debounced.
|
|
791
|
-
* @param ms A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.
|
|
792
|
-
* @param options Options
|
|
793
|
-
*
|
|
794
|
-
* @return A new, debounce, function.
|
|
795
|
-
*
|
|
796
|
-
* @__NO_SIDE_EFFECTS__
|
|
797
|
-
*/
|
|
798
|
-
function useDebounceFn(fn, ms = 200, options = {}) {
|
|
799
|
-
|
|
800
|
-
}
|
|
787
|
+
* Debounce execution of a function.
|
|
788
|
+
*
|
|
789
|
+
* @see https://vueuse.org/useDebounceFn
|
|
790
|
+
* @param fn A function to be executed after delay milliseconds debounced.
|
|
791
|
+
* @param ms A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.
|
|
792
|
+
* @param options Options
|
|
793
|
+
*
|
|
794
|
+
* @return A new, debounce, function.
|
|
795
|
+
*
|
|
796
|
+
* @__NO_SIDE_EFFECTS__
|
|
797
|
+
*/
|
|
798
|
+
function useDebounceFn(fn, ms = 200, options = {}) {
|
|
799
|
+
return createFilterWrapper(debounceFilter(ms, options), fn);
|
|
800
|
+
}
|
|
801
801
|
|
|
802
802
|
//#endregion
|
|
803
803
|
//#region refDebounced/index.ts
|
|
804
804
|
/**
|
|
805
|
-
* Debounce updates of a ref.
|
|
806
|
-
*
|
|
807
|
-
* @return A new debounced ref.
|
|
808
|
-
*/
|
|
809
|
-
function refDebounced(value, ms = 200, options = {}) {
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
}
|
|
817
|
-
/** @deprecated use `refDebounced` instead */
|
|
818
|
-
const debouncedRef = refDebounced;
|
|
819
|
-
/** @deprecated use `refDebounced` instead */
|
|
820
|
-
const useDebounce = refDebounced;
|
|
805
|
+
* Debounce updates of a ref.
|
|
806
|
+
*
|
|
807
|
+
* @return A new debounced ref.
|
|
808
|
+
*/
|
|
809
|
+
function refDebounced(value, ms = 200, options = {}) {
|
|
810
|
+
const debounced = (0, vue.ref)((0, vue.toValue)(value));
|
|
811
|
+
const updater = useDebounceFn(() => {
|
|
812
|
+
debounced.value = value.value;
|
|
813
|
+
}, ms, options);
|
|
814
|
+
(0, vue.watch)(value, () => updater());
|
|
815
|
+
return (0, vue.shallowReadonly)(debounced);
|
|
816
|
+
}
|
|
817
|
+
/** @deprecated use `refDebounced` instead */
|
|
818
|
+
const debouncedRef = refDebounced;
|
|
819
|
+
/** @deprecated use `refDebounced` instead */
|
|
820
|
+
const useDebounce = refDebounced;
|
|
821
821
|
|
|
822
822
|
//#endregion
|
|
823
823
|
//#region refDefault/index.ts
|
|
824
824
|
/**
|
|
825
|
-
* Apply default value to a ref.
|
|
826
|
-
*
|
|
827
|
-
* @__NO_SIDE_EFFECTS__
|
|
828
|
-
*/
|
|
829
|
-
function refDefault(source, defaultValue) {
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
}
|
|
825
|
+
* Apply default value to a ref.
|
|
826
|
+
*
|
|
827
|
+
* @__NO_SIDE_EFFECTS__
|
|
828
|
+
*/
|
|
829
|
+
function refDefault(source, defaultValue) {
|
|
830
|
+
return (0, vue.computed)({
|
|
831
|
+
get() {
|
|
832
|
+
var _source$value;
|
|
833
|
+
return (_source$value = source.value) !== null && _source$value !== void 0 ? _source$value : defaultValue;
|
|
834
|
+
},
|
|
835
|
+
set(value) {
|
|
836
|
+
source.value = value;
|
|
837
|
+
}
|
|
838
|
+
});
|
|
839
|
+
}
|
|
840
840
|
|
|
841
841
|
//#endregion
|
|
842
842
|
//#region refManualReset/index.ts
|
|
843
843
|
/**
|
|
844
|
-
* Create a ref with manual reset functionality.
|
|
845
|
-
*
|
|
846
|
-
* @see https://vueuse.org/refManualReset
|
|
847
|
-
* @param defaultValue The value which will be set.
|
|
848
|
-
*/
|
|
849
|
-
function refManualReset(defaultValue) {
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
};
|
|
856
|
-
const refValue = (0, vue.customRef)((track, _trigger) => {
|
|
857
|
-
trigger = _trigger;
|
|
858
|
-
return {
|
|
859
|
-
get() {
|
|
860
|
-
track();
|
|
861
|
-
return value;
|
|
862
|
-
},
|
|
863
|
-
set(newValue) {
|
|
864
|
-
value = newValue;
|
|
865
|
-
trigger();
|
|
866
|
-
}
|
|
844
|
+
* Create a ref with manual reset functionality.
|
|
845
|
+
*
|
|
846
|
+
* @see https://vueuse.org/refManualReset
|
|
847
|
+
* @param defaultValue The value which will be set.
|
|
848
|
+
*/
|
|
849
|
+
function refManualReset(defaultValue) {
|
|
850
|
+
let value = (0, vue.toValue)(defaultValue);
|
|
851
|
+
let trigger;
|
|
852
|
+
const reset = () => {
|
|
853
|
+
value = (0, vue.toValue)(defaultValue);
|
|
854
|
+
trigger();
|
|
867
855
|
};
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
856
|
+
const refValue = (0, vue.customRef)((track, _trigger) => {
|
|
857
|
+
trigger = _trigger;
|
|
858
|
+
return {
|
|
859
|
+
get() {
|
|
860
|
+
track();
|
|
861
|
+
return value;
|
|
862
|
+
},
|
|
863
|
+
set(newValue) {
|
|
864
|
+
value = newValue;
|
|
865
|
+
trigger();
|
|
866
|
+
}
|
|
867
|
+
};
|
|
868
|
+
});
|
|
869
|
+
refValue.reset = reset;
|
|
870
|
+
return refValue;
|
|
871
|
+
}
|
|
872
872
|
|
|
873
873
|
//#endregion
|
|
874
874
|
//#region useThrottleFn/index.ts
|
|
875
875
|
/**
|
|
876
|
-
* Throttle execution of a function. Especially useful for rate limiting
|
|
877
|
-
* execution of handlers on events like resize and scroll.
|
|
878
|
-
*
|
|
879
|
-
* @param fn A function to be executed after delay milliseconds. The `this` context and all arguments are passed through, as-is,
|
|
880
|
-
* to `callback` when the throttled-function is executed.
|
|
881
|
-
* @param ms A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.
|
|
882
|
-
* (default value: 200)
|
|
883
|
-
*
|
|
884
|
-
* @param [trailing] if true, call fn again after the time is up (default value: false)
|
|
885
|
-
*
|
|
886
|
-
* @param [leading] if true, call fn on the leading edge of the ms timeout (default value: true)
|
|
887
|
-
*
|
|
888
|
-
* @param [rejectOnCancel] if true, reject the last call if it's been cancel (default value: false)
|
|
889
|
-
*
|
|
890
|
-
* @return A new, throttled, function.
|
|
891
|
-
*
|
|
892
|
-
* @__NO_SIDE_EFFECTS__
|
|
893
|
-
*/
|
|
894
|
-
function useThrottleFn(fn, ms = 200, trailing = false, leading = true, rejectOnCancel = false) {
|
|
895
|
-
|
|
896
|
-
}
|
|
876
|
+
* Throttle execution of a function. Especially useful for rate limiting
|
|
877
|
+
* execution of handlers on events like resize and scroll.
|
|
878
|
+
*
|
|
879
|
+
* @param fn A function to be executed after delay milliseconds. The `this` context and all arguments are passed through, as-is,
|
|
880
|
+
* to `callback` when the throttled-function is executed.
|
|
881
|
+
* @param ms A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.
|
|
882
|
+
* (default value: 200)
|
|
883
|
+
*
|
|
884
|
+
* @param [trailing] if true, call fn again after the time is up (default value: false)
|
|
885
|
+
*
|
|
886
|
+
* @param [leading] if true, call fn on the leading edge of the ms timeout (default value: true)
|
|
887
|
+
*
|
|
888
|
+
* @param [rejectOnCancel] if true, reject the last call if it's been cancel (default value: false)
|
|
889
|
+
*
|
|
890
|
+
* @return A new, throttled, function.
|
|
891
|
+
*
|
|
892
|
+
* @__NO_SIDE_EFFECTS__
|
|
893
|
+
*/
|
|
894
|
+
function useThrottleFn(fn, ms = 200, trailing = false, leading = true, rejectOnCancel = false) {
|
|
895
|
+
return createFilterWrapper(throttleFilter(ms, trailing, leading, rejectOnCancel), fn);
|
|
896
|
+
}
|
|
897
897
|
|
|
898
898
|
//#endregion
|
|
899
899
|
//#region refThrottled/index.ts
|
|
900
900
|
/**
|
|
901
|
-
* Throttle execution of a function. Especially useful for rate limiting
|
|
902
|
-
* execution of handlers on events like resize and scroll.
|
|
903
|
-
*
|
|
904
|
-
* @param value Ref value to be watched with throttle effect
|
|
905
|
-
* @param delay A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.
|
|
906
|
-
* @param trailing if true, update the value again after the delay time is up
|
|
907
|
-
* @param leading if true, update the value on the leading edge of the ms timeout
|
|
908
|
-
*/
|
|
909
|
-
function refThrottled(value, delay = 200, trailing = true, leading = true) {
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
}
|
|
918
|
-
/** @deprecated use `refThrottled` instead */
|
|
919
|
-
const throttledRef = refThrottled;
|
|
920
|
-
/** @deprecated use `refThrottled` instead */
|
|
921
|
-
const useThrottle = refThrottled;
|
|
901
|
+
* Throttle execution of a function. Especially useful for rate limiting
|
|
902
|
+
* execution of handlers on events like resize and scroll.
|
|
903
|
+
*
|
|
904
|
+
* @param value Ref value to be watched with throttle effect
|
|
905
|
+
* @param delay A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.
|
|
906
|
+
* @param trailing if true, update the value again after the delay time is up
|
|
907
|
+
* @param leading if true, update the value on the leading edge of the ms timeout
|
|
908
|
+
*/
|
|
909
|
+
function refThrottled(value, delay = 200, trailing = true, leading = true) {
|
|
910
|
+
if (delay <= 0) return value;
|
|
911
|
+
const throttled = (0, vue.ref)((0, vue.toValue)(value));
|
|
912
|
+
const updater = useThrottleFn(() => {
|
|
913
|
+
throttled.value = value.value;
|
|
914
|
+
}, delay, trailing, leading);
|
|
915
|
+
(0, vue.watch)(value, () => updater());
|
|
916
|
+
return throttled;
|
|
917
|
+
}
|
|
918
|
+
/** @deprecated use `refThrottled` instead */
|
|
919
|
+
const throttledRef = refThrottled;
|
|
920
|
+
/** @deprecated use `refThrottled` instead */
|
|
921
|
+
const useThrottle = refThrottled;
|
|
922
922
|
|
|
923
923
|
//#endregion
|
|
924
924
|
//#region refWithControl/index.ts
|
|
925
925
|
/**
|
|
926
|
-
* Fine-grained controls over ref and its reactivity.
|
|
927
|
-
*
|
|
928
|
-
* @__NO_SIDE_EFFECTS__
|
|
929
|
-
*/
|
|
930
|
-
function refWithControl(initial, options = {}) {
|
|
931
|
-
let source = initial;
|
|
932
|
-
let track;
|
|
933
|
-
let trigger;
|
|
934
|
-
const ref = (0, vue.customRef)((_track, _trigger) => {
|
|
935
|
-
track = _track;
|
|
936
|
-
trigger = _trigger;
|
|
937
|
-
return {
|
|
938
|
-
get() {
|
|
939
|
-
return get$1();
|
|
940
|
-
},
|
|
941
|
-
set(v) {
|
|
942
|
-
set$1(v);
|
|
943
|
-
}
|
|
944
|
-
};
|
|
945
|
-
});
|
|
946
|
-
function get$1(tracking = true) {
|
|
947
|
-
if (tracking) track();
|
|
948
|
-
return source;
|
|
949
|
-
}
|
|
950
|
-
function set$1(value, triggering = true) {
|
|
951
|
-
var _options$onBeforeChan, _options$onChanged;
|
|
952
|
-
if (value === source) return;
|
|
953
|
-
const old = source;
|
|
954
|
-
if (((_options$onBeforeChan = options.onBeforeChange) === null || _options$onBeforeChan === void 0 ? void 0 : _options$onBeforeChan.call(options, value, old)) === false) return;
|
|
955
|
-
source = value;
|
|
956
|
-
(_options$onChanged = options.onChanged) === null || _options$onChanged === void 0 || _options$onChanged.call(options, value, old);
|
|
957
|
-
if (triggering) trigger();
|
|
958
|
-
}
|
|
959
|
-
/**
|
|
960
|
-
* Get the value without tracked in the reactivity system
|
|
961
|
-
*/
|
|
962
|
-
const untrackedGet = () => get$1(false);
|
|
963
|
-
/**
|
|
964
|
-
* Set the value without triggering the reactivity system
|
|
965
|
-
*/
|
|
966
|
-
const silentSet = (v) => set$1(v, false);
|
|
967
|
-
/**
|
|
968
|
-
* Get the value without tracked in the reactivity system.
|
|
969
|
-
*
|
|
970
|
-
* Alias for `untrackedGet()`
|
|
971
|
-
*/
|
|
972
|
-
const peek = () => get$1(false);
|
|
973
|
-
/**
|
|
974
|
-
* Set the value without triggering the reactivity system
|
|
926
|
+
* Fine-grained controls over ref and its reactivity.
|
|
975
927
|
*
|
|
976
|
-
*
|
|
928
|
+
* @__NO_SIDE_EFFECTS__
|
|
977
929
|
*/
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
930
|
+
function refWithControl(initial, options = {}) {
|
|
931
|
+
let source = initial;
|
|
932
|
+
let track;
|
|
933
|
+
let trigger;
|
|
934
|
+
const ref = (0, vue.customRef)((_track, _trigger) => {
|
|
935
|
+
track = _track;
|
|
936
|
+
trigger = _trigger;
|
|
937
|
+
return {
|
|
938
|
+
get() {
|
|
939
|
+
return get$1();
|
|
940
|
+
},
|
|
941
|
+
set(v) {
|
|
942
|
+
set$1(v);
|
|
943
|
+
}
|
|
944
|
+
};
|
|
945
|
+
});
|
|
946
|
+
function get$1(tracking = true) {
|
|
947
|
+
if (tracking) track();
|
|
948
|
+
return source;
|
|
949
|
+
}
|
|
950
|
+
function set$1(value, triggering = true) {
|
|
951
|
+
var _options$onBeforeChan, _options$onChanged;
|
|
952
|
+
if (value === source) return;
|
|
953
|
+
const old = source;
|
|
954
|
+
if (((_options$onBeforeChan = options.onBeforeChange) === null || _options$onBeforeChan === void 0 ? void 0 : _options$onBeforeChan.call(options, value, old)) === false) return;
|
|
955
|
+
source = value;
|
|
956
|
+
(_options$onChanged = options.onChanged) === null || _options$onChanged === void 0 || _options$onChanged.call(options, value, old);
|
|
957
|
+
if (triggering) trigger();
|
|
958
|
+
}
|
|
959
|
+
/**
|
|
960
|
+
* Get the value without tracked in the reactivity system
|
|
961
|
+
*/
|
|
962
|
+
const untrackedGet = () => get$1(false);
|
|
963
|
+
/**
|
|
964
|
+
* Set the value without triggering the reactivity system
|
|
965
|
+
*/
|
|
966
|
+
const silentSet = (v) => set$1(v, false);
|
|
967
|
+
/**
|
|
968
|
+
* Get the value without tracked in the reactivity system.
|
|
969
|
+
*
|
|
970
|
+
* Alias for `untrackedGet()`
|
|
971
|
+
*/
|
|
972
|
+
const peek = () => get$1(false);
|
|
973
|
+
/**
|
|
974
|
+
* Set the value without triggering the reactivity system
|
|
975
|
+
*
|
|
976
|
+
* Alias for `silentSet(v)`
|
|
977
|
+
*/
|
|
978
|
+
const lay = (v) => set$1(v, false);
|
|
979
|
+
return extendRef(ref, {
|
|
980
|
+
get: get$1,
|
|
981
|
+
set: set$1,
|
|
982
|
+
untrackedGet,
|
|
983
|
+
silentSet,
|
|
984
|
+
peek,
|
|
985
|
+
lay
|
|
986
|
+
}, { enumerable: true });
|
|
987
|
+
}
|
|
988
|
+
/** @deprecated use `refWithControl` instead */
|
|
989
|
+
const controlledRef = refWithControl;
|
|
990
990
|
|
|
991
991
|
//#endregion
|
|
992
992
|
//#region set/index.ts
|
|
993
993
|
/**
|
|
994
|
-
* Shorthand for `ref.value = x`
|
|
995
|
-
*/
|
|
996
|
-
function set(...args) {
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
994
|
+
* Shorthand for `ref.value = x`
|
|
995
|
+
*/
|
|
996
|
+
function set(...args) {
|
|
997
|
+
if (args.length === 2) {
|
|
998
|
+
const [ref, value] = args;
|
|
999
|
+
ref.value = value;
|
|
1000
|
+
}
|
|
1001
|
+
if (args.length === 3) {
|
|
1002
|
+
const [target, key, value] = args;
|
|
1003
|
+
target[key] = value;
|
|
1004
|
+
}
|
|
1004
1005
|
}
|
|
1005
|
-
}
|
|
1006
1006
|
|
|
1007
1007
|
//#endregion
|
|
1008
1008
|
//#region watchWithFilter/index.ts
|
|
1009
|
-
function watchWithFilter(source, cb, options = {}) {
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
}
|
|
1009
|
+
function watchWithFilter(source, cb, options = {}) {
|
|
1010
|
+
const { eventFilter = bypassFilter,...watchOptions } = options;
|
|
1011
|
+
return (0, vue.watch)(source, createFilterWrapper(eventFilter, cb), watchOptions);
|
|
1012
|
+
}
|
|
1013
1013
|
|
|
1014
1014
|
//#endregion
|
|
1015
1015
|
//#region watchPausable/index.ts
|
|
1016
|
-
function watchPausable(source, cb, options = {}) {
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
}
|
|
1029
|
-
/** @deprecated use `watchPausable` instead */
|
|
1030
|
-
const pausableWatch = watchPausable;
|
|
1016
|
+
function watchPausable(source, cb, options = {}) {
|
|
1017
|
+
const { eventFilter: filter, initialState = "active",...watchOptions } = options;
|
|
1018
|
+
const { eventFilter, pause, resume, isActive } = pausableFilter(filter, { initialState });
|
|
1019
|
+
return {
|
|
1020
|
+
stop: watchWithFilter(source, cb, {
|
|
1021
|
+
...watchOptions,
|
|
1022
|
+
eventFilter
|
|
1023
|
+
}),
|
|
1024
|
+
pause,
|
|
1025
|
+
resume,
|
|
1026
|
+
isActive
|
|
1027
|
+
};
|
|
1028
|
+
}
|
|
1029
|
+
/** @deprecated use `watchPausable` instead */
|
|
1030
|
+
const pausableWatch = watchPausable;
|
|
1031
1031
|
|
|
1032
1032
|
//#endregion
|
|
1033
1033
|
//#region syncRef/index.ts
|
|
1034
1034
|
/**
|
|
1035
|
-
* Two-way refs synchronization.
|
|
1036
|
-
* From the set theory perspective to restrict the option's type
|
|
1037
|
-
* Check in the following order:
|
|
1038
|
-
* 1. L = R
|
|
1039
|
-
* 2. L ∩ R ≠ ∅
|
|
1040
|
-
* 3. L ⊆ R
|
|
1041
|
-
* 4. L ∩ R = ∅
|
|
1042
|
-
*/
|
|
1043
|
-
function syncRef(left, right, ...[options]) {
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
}
|
|
1035
|
+
* Two-way refs synchronization.
|
|
1036
|
+
* From the set theory perspective to restrict the option's type
|
|
1037
|
+
* Check in the following order:
|
|
1038
|
+
* 1. L = R
|
|
1039
|
+
* 2. L ∩ R ≠ ∅
|
|
1040
|
+
* 3. L ⊆ R
|
|
1041
|
+
* 4. L ∩ R = ∅
|
|
1042
|
+
*/
|
|
1043
|
+
function syncRef(left, right, ...[options]) {
|
|
1044
|
+
const { flush = "sync", deep = false, immediate = true, direction = "both", transform = {} } = options || {};
|
|
1045
|
+
const watchers = [];
|
|
1046
|
+
const transformLTR = "ltr" in transform && transform.ltr || ((v) => v);
|
|
1047
|
+
const transformRTL = "rtl" in transform && transform.rtl || ((v) => v);
|
|
1048
|
+
if (direction === "both" || direction === "ltr") watchers.push(pausableWatch(left, (newValue) => {
|
|
1049
|
+
watchers.forEach((w) => w.pause());
|
|
1050
|
+
right.value = transformLTR(newValue);
|
|
1051
|
+
watchers.forEach((w) => w.resume());
|
|
1052
|
+
}, {
|
|
1053
|
+
flush,
|
|
1054
|
+
deep,
|
|
1055
|
+
immediate
|
|
1056
|
+
}));
|
|
1057
|
+
if (direction === "both" || direction === "rtl") watchers.push(pausableWatch(right, (newValue) => {
|
|
1058
|
+
watchers.forEach((w) => w.pause());
|
|
1059
|
+
left.value = transformRTL(newValue);
|
|
1060
|
+
watchers.forEach((w) => w.resume());
|
|
1061
|
+
}, {
|
|
1062
|
+
flush,
|
|
1063
|
+
deep,
|
|
1064
|
+
immediate
|
|
1065
|
+
}));
|
|
1066
|
+
const stop = () => {
|
|
1067
|
+
watchers.forEach((w) => w.stop());
|
|
1068
|
+
};
|
|
1069
|
+
return stop;
|
|
1070
|
+
}
|
|
1071
1071
|
|
|
1072
1072
|
//#endregion
|
|
1073
1073
|
//#region syncRefs/index.ts
|
|
1074
1074
|
/**
|
|
1075
|
-
* Keep target ref(s) in sync with the source ref
|
|
1076
|
-
*
|
|
1077
|
-
* @param source source ref
|
|
1078
|
-
* @param targets
|
|
1079
|
-
*/
|
|
1080
|
-
function syncRefs(source, targets, options = {}) {
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
}
|
|
1075
|
+
* Keep target ref(s) in sync with the source ref
|
|
1076
|
+
*
|
|
1077
|
+
* @param source source ref
|
|
1078
|
+
* @param targets
|
|
1079
|
+
*/
|
|
1080
|
+
function syncRefs(source, targets, options = {}) {
|
|
1081
|
+
const { flush = "sync", deep = false, immediate = true } = options;
|
|
1082
|
+
const targetsArray = toArray(targets);
|
|
1083
|
+
return (0, vue.watch)(source, (newValue) => targetsArray.forEach((target) => target.value = newValue), {
|
|
1084
|
+
flush,
|
|
1085
|
+
deep,
|
|
1086
|
+
immediate
|
|
1087
|
+
});
|
|
1088
|
+
}
|
|
1089
1089
|
|
|
1090
1090
|
//#endregion
|
|
1091
1091
|
//#region toRefs/index.ts
|
|
1092
1092
|
/**
|
|
1093
|
-
* Extended `toRefs` that also accepts refs of an object.
|
|
1094
|
-
*
|
|
1095
|
-
* @see https://vueuse.org/toRefs
|
|
1096
|
-
* @param objectRef A ref or normal object or array.
|
|
1097
|
-
* @param options Options
|
|
1098
|
-
*/
|
|
1099
|
-
function toRefs(objectRef, options = {}) {
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1093
|
+
* Extended `toRefs` that also accepts refs of an object.
|
|
1094
|
+
*
|
|
1095
|
+
* @see https://vueuse.org/toRefs
|
|
1096
|
+
* @param objectRef A ref or normal object or array.
|
|
1097
|
+
* @param options Options
|
|
1098
|
+
*/
|
|
1099
|
+
function toRefs(objectRef, options = {}) {
|
|
1100
|
+
if (!(0, vue.isRef)(objectRef)) return (0, vue.toRefs)(objectRef);
|
|
1101
|
+
const result = Array.isArray(objectRef.value) ? Array.from({ length: objectRef.value.length }) : {};
|
|
1102
|
+
for (const key in objectRef.value) result[key] = (0, vue.customRef)(() => ({
|
|
1103
|
+
get() {
|
|
1104
|
+
return objectRef.value[key];
|
|
1105
|
+
},
|
|
1106
|
+
set(v) {
|
|
1107
|
+
var _toValue;
|
|
1108
|
+
if ((_toValue = (0, vue.toValue)(options.replaceRef)) !== null && _toValue !== void 0 ? _toValue : true) if (Array.isArray(objectRef.value)) {
|
|
1109
|
+
const copy = [...objectRef.value];
|
|
1110
|
+
copy[key] = v;
|
|
1111
|
+
objectRef.value = copy;
|
|
1112
|
+
} else {
|
|
1113
|
+
const newObject = {
|
|
1114
|
+
...objectRef.value,
|
|
1115
|
+
[key]: v
|
|
1116
|
+
};
|
|
1117
|
+
Object.setPrototypeOf(newObject, Object.getPrototypeOf(objectRef.value));
|
|
1118
|
+
objectRef.value = newObject;
|
|
1119
|
+
}
|
|
1120
|
+
else objectRef.value[key] = v;
|
|
1119
1121
|
}
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
}
|
|
1123
|
-
return result;
|
|
1124
|
-
}
|
|
1122
|
+
}));
|
|
1123
|
+
return result;
|
|
1124
|
+
}
|
|
1125
1125
|
|
|
1126
1126
|
//#endregion
|
|
1127
1127
|
//#region tryOnBeforeMount/index.ts
|
|
1128
1128
|
/**
|
|
1129
|
-
* Call onBeforeMount() if it's inside a component lifecycle, if not, just call the function
|
|
1130
|
-
*
|
|
1131
|
-
* @param fn
|
|
1132
|
-
* @param sync if set to false, it will run in the nextTick() of Vue
|
|
1133
|
-
* @param target
|
|
1134
|
-
*/
|
|
1135
|
-
function tryOnBeforeMount(fn, sync = true, target) {
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
}
|
|
1129
|
+
* Call onBeforeMount() if it's inside a component lifecycle, if not, just call the function
|
|
1130
|
+
*
|
|
1131
|
+
* @param fn
|
|
1132
|
+
* @param sync if set to false, it will run in the nextTick() of Vue
|
|
1133
|
+
* @param target
|
|
1134
|
+
*/
|
|
1135
|
+
function tryOnBeforeMount(fn, sync = true, target) {
|
|
1136
|
+
if (getLifeCycleTarget(target)) (0, vue.onBeforeMount)(fn, target);
|
|
1137
|
+
else if (sync) fn();
|
|
1138
|
+
else (0, vue.nextTick)(fn);
|
|
1139
|
+
}
|
|
1140
1140
|
|
|
1141
1141
|
//#endregion
|
|
1142
1142
|
//#region tryOnBeforeUnmount/index.ts
|
|
1143
1143
|
/**
|
|
1144
|
-
* Call onBeforeUnmount() if it's inside a component lifecycle, if not, do nothing
|
|
1145
|
-
*
|
|
1146
|
-
* @param fn
|
|
1147
|
-
* @param target
|
|
1148
|
-
*/
|
|
1149
|
-
function tryOnBeforeUnmount(fn, target) {
|
|
1150
|
-
|
|
1151
|
-
}
|
|
1152
|
-
|
|
1153
|
-
//#endregion
|
|
1154
|
-
//#region tryOnMounted/index.ts
|
|
1155
|
-
/**
|
|
1156
|
-
* Call onMounted() if it's inside a component lifecycle, if not, just call the function
|
|
1157
|
-
*
|
|
1158
|
-
* @param fn
|
|
1159
|
-
* @param sync if set to false, it will run in the nextTick() of Vue
|
|
1160
|
-
* @param target
|
|
1161
|
-
*/
|
|
1162
|
-
function tryOnMounted(fn, sync = true, target) {
|
|
1163
|
-
if (getLifeCycleTarget(target)) (0, vue.onMounted)(fn, target);
|
|
1164
|
-
else if (sync) fn();
|
|
1165
|
-
else (0, vue.nextTick)(fn);
|
|
1166
|
-
}
|
|
1167
|
-
|
|
1168
|
-
//#endregion
|
|
1169
|
-
//#region tryOnUnmounted/index.ts
|
|
1170
|
-
/**
|
|
1171
|
-
* Call onUnmounted() if it's inside a component lifecycle, if not, do nothing
|
|
1172
|
-
*
|
|
1173
|
-
* @param fn
|
|
1174
|
-
* @param target
|
|
1175
|
-
*/
|
|
1176
|
-
function tryOnUnmounted(fn, target) {
|
|
1177
|
-
if (getLifeCycleTarget(target)) (0, vue.onUnmounted)(fn, target);
|
|
1178
|
-
}
|
|
1179
|
-
|
|
1180
|
-
//#endregion
|
|
1181
|
-
//#region until/index.ts
|
|
1182
|
-
function createUntil(r, isNot = false) {
|
|
1183
|
-
function toMatch(condition, { flush = "sync", deep = false, timeout, throwOnTimeout } = {}) {
|
|
1184
|
-
let stop = null;
|
|
1185
|
-
const promises = [new Promise((resolve) => {
|
|
1186
|
-
stop = (0, vue.watch)(r, (v) => {
|
|
1187
|
-
if (condition(v) !== isNot) {
|
|
1188
|
-
if (stop) stop();
|
|
1189
|
-
else (0, vue.nextTick)(() => stop === null || stop === void 0 ? void 0 : stop());
|
|
1190
|
-
resolve(v);
|
|
1191
|
-
}
|
|
1192
|
-
}, {
|
|
1193
|
-
flush,
|
|
1194
|
-
deep,
|
|
1195
|
-
immediate: true
|
|
1196
|
-
});
|
|
1197
|
-
})];
|
|
1198
|
-
if (timeout != null) promises.push(promiseTimeout(timeout, throwOnTimeout).then(() => (0, vue.toValue)(r)).finally(() => stop === null || stop === void 0 ? void 0 : stop()));
|
|
1199
|
-
return Promise.race(promises);
|
|
1200
|
-
}
|
|
1201
|
-
function toBe(value, options) {
|
|
1202
|
-
if (!(0, vue.isRef)(value)) return toMatch((v) => v === value, options);
|
|
1203
|
-
const { flush = "sync", deep = false, timeout, throwOnTimeout } = options !== null && options !== void 0 ? options : {};
|
|
1204
|
-
let stop = null;
|
|
1205
|
-
const promises = [new Promise((resolve) => {
|
|
1206
|
-
stop = (0, vue.watch)([r, value], ([v1, v2]) => {
|
|
1207
|
-
if (isNot !== (v1 === v2)) {
|
|
1208
|
-
if (stop) stop();
|
|
1209
|
-
else (0, vue.nextTick)(() => stop === null || stop === void 0 ? void 0 : stop());
|
|
1210
|
-
resolve(v1);
|
|
1211
|
-
}
|
|
1212
|
-
}, {
|
|
1213
|
-
flush,
|
|
1214
|
-
deep,
|
|
1215
|
-
immediate: true
|
|
1216
|
-
});
|
|
1217
|
-
})];
|
|
1218
|
-
if (timeout != null) promises.push(promiseTimeout(timeout, throwOnTimeout).then(() => (0, vue.toValue)(r)).finally(() => {
|
|
1219
|
-
stop === null || stop === void 0 || stop();
|
|
1220
|
-
return (0, vue.toValue)(r);
|
|
1221
|
-
}));
|
|
1222
|
-
return Promise.race(promises);
|
|
1223
|
-
}
|
|
1224
|
-
function toBeTruthy(options) {
|
|
1225
|
-
return toMatch((v) => Boolean(v), options);
|
|
1226
|
-
}
|
|
1227
|
-
function toBeNull(options) {
|
|
1228
|
-
return toBe(null, options);
|
|
1229
|
-
}
|
|
1230
|
-
function toBeUndefined(options) {
|
|
1231
|
-
return toBe(void 0, options);
|
|
1232
|
-
}
|
|
1233
|
-
function toBeNaN(options) {
|
|
1234
|
-
return toMatch(Number.isNaN, options);
|
|
1235
|
-
}
|
|
1236
|
-
function toContains(value, options) {
|
|
1237
|
-
return toMatch((v) => {
|
|
1238
|
-
const array = Array.from(v);
|
|
1239
|
-
return array.includes(value) || array.includes((0, vue.toValue)(value));
|
|
1240
|
-
}, options);
|
|
1144
|
+
* Call onBeforeUnmount() if it's inside a component lifecycle, if not, do nothing
|
|
1145
|
+
*
|
|
1146
|
+
* @param fn
|
|
1147
|
+
* @param target
|
|
1148
|
+
*/
|
|
1149
|
+
function tryOnBeforeUnmount(fn, target) {
|
|
1150
|
+
if (getLifeCycleTarget(target)) (0, vue.onBeforeUnmount)(fn, target);
|
|
1241
1151
|
}
|
|
1242
|
-
|
|
1243
|
-
|
|
1152
|
+
|
|
1153
|
+
//#endregion
|
|
1154
|
+
//#region tryOnMounted/index.ts
|
|
1155
|
+
/**
|
|
1156
|
+
* Call onMounted() if it's inside a component lifecycle, if not, just call the function
|
|
1157
|
+
*
|
|
1158
|
+
* @param fn
|
|
1159
|
+
* @param sync if set to false, it will run in the nextTick() of Vue
|
|
1160
|
+
* @param target
|
|
1161
|
+
*/
|
|
1162
|
+
function tryOnMounted(fn, sync = true, target) {
|
|
1163
|
+
if (getLifeCycleTarget(target)) (0, vue.onMounted)(fn, target);
|
|
1164
|
+
else if (sync) fn();
|
|
1165
|
+
else (0, vue.nextTick)(fn);
|
|
1244
1166
|
}
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1167
|
+
|
|
1168
|
+
//#endregion
|
|
1169
|
+
//#region tryOnUnmounted/index.ts
|
|
1170
|
+
/**
|
|
1171
|
+
* Call onUnmounted() if it's inside a component lifecycle, if not, do nothing
|
|
1172
|
+
*
|
|
1173
|
+
* @param fn
|
|
1174
|
+
* @param target
|
|
1175
|
+
*/
|
|
1176
|
+
function tryOnUnmounted(fn, target) {
|
|
1177
|
+
if (getLifeCycleTarget(target)) (0, vue.onUnmounted)(fn, target);
|
|
1251
1178
|
}
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1179
|
+
|
|
1180
|
+
//#endregion
|
|
1181
|
+
//#region until/index.ts
|
|
1182
|
+
function createUntil(r, isNot = false) {
|
|
1183
|
+
function toMatch(condition, { flush = "sync", deep = false, timeout, throwOnTimeout } = {}) {
|
|
1184
|
+
let stop = null;
|
|
1185
|
+
const promises = [new Promise((resolve) => {
|
|
1186
|
+
stop = (0, vue.watch)(r, (v) => {
|
|
1187
|
+
if (condition(v) !== isNot) {
|
|
1188
|
+
if (stop) stop();
|
|
1189
|
+
else (0, vue.nextTick)(() => stop === null || stop === void 0 ? void 0 : stop());
|
|
1190
|
+
resolve(v);
|
|
1191
|
+
}
|
|
1192
|
+
}, {
|
|
1193
|
+
flush,
|
|
1194
|
+
deep,
|
|
1195
|
+
immediate: true
|
|
1196
|
+
});
|
|
1197
|
+
})];
|
|
1198
|
+
if (timeout != null) promises.push(promiseTimeout(timeout, throwOnTimeout).then(() => (0, vue.toValue)(r)).finally(() => stop === null || stop === void 0 ? void 0 : stop()));
|
|
1199
|
+
return Promise.race(promises);
|
|
1259
1200
|
}
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1201
|
+
function toBe(value, options) {
|
|
1202
|
+
if (!(0, vue.isRef)(value)) return toMatch((v) => v === value, options);
|
|
1203
|
+
const { flush = "sync", deep = false, timeout, throwOnTimeout } = options !== null && options !== void 0 ? options : {};
|
|
1204
|
+
let stop = null;
|
|
1205
|
+
const promises = [new Promise((resolve) => {
|
|
1206
|
+
stop = (0, vue.watch)([r, value], ([v1, v2]) => {
|
|
1207
|
+
if (isNot !== (v1 === v2)) {
|
|
1208
|
+
if (stop) stop();
|
|
1209
|
+
else (0, vue.nextTick)(() => stop === null || stop === void 0 ? void 0 : stop());
|
|
1210
|
+
resolve(v1);
|
|
1211
|
+
}
|
|
1212
|
+
}, {
|
|
1213
|
+
flush,
|
|
1214
|
+
deep,
|
|
1215
|
+
immediate: true
|
|
1216
|
+
});
|
|
1217
|
+
})];
|
|
1218
|
+
if (timeout != null) promises.push(promiseTimeout(timeout, throwOnTimeout).then(() => (0, vue.toValue)(r)).finally(() => {
|
|
1219
|
+
stop === null || stop === void 0 || stop();
|
|
1220
|
+
return (0, vue.toValue)(r);
|
|
1221
|
+
}));
|
|
1222
|
+
return Promise.race(promises);
|
|
1272
1223
|
}
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1224
|
+
function toBeTruthy(options) {
|
|
1225
|
+
return toMatch((v) => Boolean(v), options);
|
|
1226
|
+
}
|
|
1227
|
+
function toBeNull(options) {
|
|
1228
|
+
return toBe(null, options);
|
|
1229
|
+
}
|
|
1230
|
+
function toBeUndefined(options) {
|
|
1231
|
+
return toBe(void 0, options);
|
|
1232
|
+
}
|
|
1233
|
+
function toBeNaN(options) {
|
|
1234
|
+
return toMatch(Number.isNaN, options);
|
|
1235
|
+
}
|
|
1236
|
+
function toContains(value, options) {
|
|
1237
|
+
return toMatch((v) => {
|
|
1238
|
+
const array = Array.from(v);
|
|
1239
|
+
return array.includes(value) || array.includes((0, vue.toValue)(value));
|
|
1240
|
+
}, options);
|
|
1241
|
+
}
|
|
1242
|
+
function changed(options) {
|
|
1243
|
+
return changedTimes(1, options);
|
|
1244
|
+
}
|
|
1245
|
+
function changedTimes(n = 1, options) {
|
|
1246
|
+
let count = -1;
|
|
1247
|
+
return toMatch(() => {
|
|
1248
|
+
count += 1;
|
|
1249
|
+
return count >= n;
|
|
1250
|
+
}, options);
|
|
1251
|
+
}
|
|
1252
|
+
if (Array.isArray((0, vue.toValue)(r))) return {
|
|
1253
|
+
toMatch,
|
|
1254
|
+
toContains,
|
|
1255
|
+
changed,
|
|
1256
|
+
changedTimes,
|
|
1257
|
+
get not() {
|
|
1258
|
+
return createUntil(r, !isNot);
|
|
1259
|
+
}
|
|
1260
|
+
};
|
|
1261
|
+
else return {
|
|
1262
|
+
toMatch,
|
|
1263
|
+
toBe,
|
|
1264
|
+
toBeTruthy,
|
|
1265
|
+
toBeNull,
|
|
1266
|
+
toBeNaN,
|
|
1267
|
+
toBeUndefined,
|
|
1268
|
+
changed,
|
|
1269
|
+
changedTimes,
|
|
1270
|
+
get not() {
|
|
1271
|
+
return createUntil(r, !isNot);
|
|
1272
|
+
}
|
|
1273
|
+
};
|
|
1274
|
+
}
|
|
1275
|
+
function until(r) {
|
|
1276
|
+
return createUntil(r);
|
|
1277
|
+
}
|
|
1278
1278
|
|
|
1279
1279
|
//#endregion
|
|
1280
1280
|
//#region useArrayDifference/index.ts
|
|
1281
|
-
function defaultComparator(value, othVal) {
|
|
1282
|
-
|
|
1283
|
-
}
|
|
1284
|
-
/**
|
|
1285
|
-
* Reactive get array difference of two array
|
|
1286
|
-
* @see https://vueuse.org/useArrayDifference
|
|
1287
|
-
* @returns - the difference of two array
|
|
1288
|
-
* @param args
|
|
1289
|
-
*
|
|
1290
|
-
* @__NO_SIDE_EFFECTS__
|
|
1291
|
-
*/
|
|
1292
|
-
function useArrayDifference(...args) {
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
}
|
|
1281
|
+
function defaultComparator(value, othVal) {
|
|
1282
|
+
return value === othVal;
|
|
1283
|
+
}
|
|
1284
|
+
/**
|
|
1285
|
+
* Reactive get array difference of two array
|
|
1286
|
+
* @see https://vueuse.org/useArrayDifference
|
|
1287
|
+
* @returns - the difference of two array
|
|
1288
|
+
* @param args
|
|
1289
|
+
*
|
|
1290
|
+
* @__NO_SIDE_EFFECTS__
|
|
1291
|
+
*/
|
|
1292
|
+
function useArrayDifference(...args) {
|
|
1293
|
+
var _args$, _args$2;
|
|
1294
|
+
const list = args[0];
|
|
1295
|
+
const values = args[1];
|
|
1296
|
+
let compareFn = (_args$ = args[2]) !== null && _args$ !== void 0 ? _args$ : defaultComparator;
|
|
1297
|
+
const { symmetric = false } = (_args$2 = args[3]) !== null && _args$2 !== void 0 ? _args$2 : {};
|
|
1298
|
+
if (typeof compareFn === "string") {
|
|
1299
|
+
const key = compareFn;
|
|
1300
|
+
compareFn = (value, othVal) => value[key] === othVal[key];
|
|
1301
|
+
}
|
|
1302
|
+
const diff1 = (0, vue.computed)(() => (0, vue.toValue)(list).filter((x) => (0, vue.toValue)(values).findIndex((y) => compareFn(x, y)) === -1));
|
|
1303
|
+
if (symmetric) {
|
|
1304
|
+
const diff2 = (0, vue.computed)(() => (0, vue.toValue)(values).filter((x) => (0, vue.toValue)(list).findIndex((y) => compareFn(x, y)) === -1));
|
|
1305
|
+
return (0, vue.computed)(() => symmetric ? [...(0, vue.toValue)(diff1), ...(0, vue.toValue)(diff2)] : (0, vue.toValue)(diff1));
|
|
1306
|
+
} else return diff1;
|
|
1307
|
+
}
|
|
1308
1308
|
|
|
1309
1309
|
//#endregion
|
|
1310
1310
|
//#region useArrayEvery/index.ts
|
|
1311
1311
|
/**
|
|
1312
|
-
* Reactive `Array.every`
|
|
1313
|
-
*
|
|
1314
|
-
* @see https://vueuse.org/useArrayEvery
|
|
1315
|
-
* @param list - the array was called upon.
|
|
1316
|
-
* @param fn - a function to test each element.
|
|
1317
|
-
*
|
|
1318
|
-
* @returns **true** if the `fn` function returns a **truthy** value for every element from the array. Otherwise, **false**.
|
|
1319
|
-
*
|
|
1320
|
-
* @__NO_SIDE_EFFECTS__
|
|
1321
|
-
*/
|
|
1322
|
-
function useArrayEvery(list, fn) {
|
|
1323
|
-
|
|
1324
|
-
}
|
|
1312
|
+
* Reactive `Array.every`
|
|
1313
|
+
*
|
|
1314
|
+
* @see https://vueuse.org/useArrayEvery
|
|
1315
|
+
* @param list - the array was called upon.
|
|
1316
|
+
* @param fn - a function to test each element.
|
|
1317
|
+
*
|
|
1318
|
+
* @returns **true** if the `fn` function returns a **truthy** value for every element from the array. Otherwise, **false**.
|
|
1319
|
+
*
|
|
1320
|
+
* @__NO_SIDE_EFFECTS__
|
|
1321
|
+
*/
|
|
1322
|
+
function useArrayEvery(list, fn) {
|
|
1323
|
+
return (0, vue.computed)(() => (0, vue.toValue)(list).every((element, index, array) => fn((0, vue.toValue)(element), index, array)));
|
|
1324
|
+
}
|
|
1325
1325
|
|
|
1326
1326
|
//#endregion
|
|
1327
1327
|
//#region useArrayFilter/index.ts
|
|
1328
1328
|
/**
|
|
1329
|
-
* Reactive `Array.filter`
|
|
1330
|
-
*
|
|
1331
|
-
* @see https://vueuse.org/useArrayFilter
|
|
1332
|
-
* @param list - the array was called upon.
|
|
1333
|
-
* @param fn - a function that is called for every element of the given `list`. Each time `fn` executes, the returned value is added to the new array.
|
|
1334
|
-
*
|
|
1335
|
-
* @returns a shallow copy of a portion of the given array, filtered down to just the elements from the given array that pass the test implemented by the provided function. If no elements pass the test, an empty array will be returned.
|
|
1336
|
-
*
|
|
1337
|
-
* @__NO_SIDE_EFFECTS__
|
|
1338
|
-
*/
|
|
1339
|
-
function useArrayFilter(list, fn) {
|
|
1340
|
-
|
|
1341
|
-
}
|
|
1329
|
+
* Reactive `Array.filter`
|
|
1330
|
+
*
|
|
1331
|
+
* @see https://vueuse.org/useArrayFilter
|
|
1332
|
+
* @param list - the array was called upon.
|
|
1333
|
+
* @param fn - a function that is called for every element of the given `list`. Each time `fn` executes, the returned value is added to the new array.
|
|
1334
|
+
*
|
|
1335
|
+
* @returns a shallow copy of a portion of the given array, filtered down to just the elements from the given array that pass the test implemented by the provided function. If no elements pass the test, an empty array will be returned.
|
|
1336
|
+
*
|
|
1337
|
+
* @__NO_SIDE_EFFECTS__
|
|
1338
|
+
*/
|
|
1339
|
+
function useArrayFilter(list, fn) {
|
|
1340
|
+
return (0, vue.computed)(() => (0, vue.toValue)(list).map((i) => (0, vue.toValue)(i)).filter(fn));
|
|
1341
|
+
}
|
|
1342
1342
|
|
|
1343
1343
|
//#endregion
|
|
1344
1344
|
//#region useArrayFind/index.ts
|
|
1345
1345
|
/**
|
|
1346
|
-
* Reactive `Array.find`
|
|
1347
|
-
*
|
|
1348
|
-
* @see https://vueuse.org/useArrayFind
|
|
1349
|
-
* @param list - the array was called upon.
|
|
1350
|
-
* @param fn - a function to test each element.
|
|
1351
|
-
*
|
|
1352
|
-
* @returns the first element in the array that satisfies the provided testing function. Otherwise, undefined is returned.
|
|
1353
|
-
*
|
|
1354
|
-
* @__NO_SIDE_EFFECTS__
|
|
1355
|
-
*/
|
|
1356
|
-
function useArrayFind(list, fn) {
|
|
1357
|
-
|
|
1358
|
-
}
|
|
1346
|
+
* Reactive `Array.find`
|
|
1347
|
+
*
|
|
1348
|
+
* @see https://vueuse.org/useArrayFind
|
|
1349
|
+
* @param list - the array was called upon.
|
|
1350
|
+
* @param fn - a function to test each element.
|
|
1351
|
+
*
|
|
1352
|
+
* @returns the first element in the array that satisfies the provided testing function. Otherwise, undefined is returned.
|
|
1353
|
+
*
|
|
1354
|
+
* @__NO_SIDE_EFFECTS__
|
|
1355
|
+
*/
|
|
1356
|
+
function useArrayFind(list, fn) {
|
|
1357
|
+
return (0, vue.computed)(() => (0, vue.toValue)((0, vue.toValue)(list).find((element, index, array) => fn((0, vue.toValue)(element), index, array))));
|
|
1358
|
+
}
|
|
1359
1359
|
|
|
1360
1360
|
//#endregion
|
|
1361
1361
|
//#region useArrayFindIndex/index.ts
|
|
1362
1362
|
/**
|
|
1363
|
-
* Reactive `Array.findIndex`
|
|
1364
|
-
*
|
|
1365
|
-
* @see https://vueuse.org/useArrayFindIndex
|
|
1366
|
-
* @param list - the array was called upon.
|
|
1367
|
-
* @param fn - a function to test each element.
|
|
1368
|
-
*
|
|
1369
|
-
* @returns the index of the first element in the array that passes the test. Otherwise, "-1".
|
|
1370
|
-
*
|
|
1371
|
-
* @__NO_SIDE_EFFECTS__
|
|
1372
|
-
*/
|
|
1373
|
-
function useArrayFindIndex(list, fn) {
|
|
1374
|
-
|
|
1375
|
-
}
|
|
1363
|
+
* Reactive `Array.findIndex`
|
|
1364
|
+
*
|
|
1365
|
+
* @see https://vueuse.org/useArrayFindIndex
|
|
1366
|
+
* @param list - the array was called upon.
|
|
1367
|
+
* @param fn - a function to test each element.
|
|
1368
|
+
*
|
|
1369
|
+
* @returns the index of the first element in the array that passes the test. Otherwise, "-1".
|
|
1370
|
+
*
|
|
1371
|
+
* @__NO_SIDE_EFFECTS__
|
|
1372
|
+
*/
|
|
1373
|
+
function useArrayFindIndex(list, fn) {
|
|
1374
|
+
return (0, vue.computed)(() => (0, vue.toValue)(list).findIndex((element, index, array) => fn((0, vue.toValue)(element), index, array)));
|
|
1375
|
+
}
|
|
1376
1376
|
|
|
1377
1377
|
//#endregion
|
|
1378
1378
|
//#region useArrayFindLast/index.ts
|
|
1379
|
-
function findLast(arr, cb) {
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
}
|
|
1383
|
-
/**
|
|
1384
|
-
* Reactive `Array.findLast`
|
|
1385
|
-
*
|
|
1386
|
-
* @see https://vueuse.org/useArrayFindLast
|
|
1387
|
-
* @param list - the array was called upon.
|
|
1388
|
-
* @param fn - a function to test each element.
|
|
1389
|
-
*
|
|
1390
|
-
* @returns the last element in the array that satisfies the provided testing function. Otherwise, undefined is returned.
|
|
1391
|
-
*
|
|
1392
|
-
* @__NO_SIDE_EFFECTS__
|
|
1393
|
-
*/
|
|
1394
|
-
function useArrayFindLast(list, fn) {
|
|
1395
|
-
|
|
1396
|
-
}
|
|
1379
|
+
function findLast(arr, cb) {
|
|
1380
|
+
let index = arr.length;
|
|
1381
|
+
while (index-- > 0) if (cb(arr[index], index, arr)) return arr[index];
|
|
1382
|
+
}
|
|
1383
|
+
/**
|
|
1384
|
+
* Reactive `Array.findLast`
|
|
1385
|
+
*
|
|
1386
|
+
* @see https://vueuse.org/useArrayFindLast
|
|
1387
|
+
* @param list - the array was called upon.
|
|
1388
|
+
* @param fn - a function to test each element.
|
|
1389
|
+
*
|
|
1390
|
+
* @returns the last element in the array that satisfies the provided testing function. Otherwise, undefined is returned.
|
|
1391
|
+
*
|
|
1392
|
+
* @__NO_SIDE_EFFECTS__
|
|
1393
|
+
*/
|
|
1394
|
+
function useArrayFindLast(list, fn) {
|
|
1395
|
+
return (0, vue.computed)(() => (0, vue.toValue)(!Array.prototype.findLast ? findLast((0, vue.toValue)(list), (element, index, array) => fn((0, vue.toValue)(element), index, array)) : (0, vue.toValue)(list).findLast((element, index, array) => fn((0, vue.toValue)(element), index, array))));
|
|
1396
|
+
}
|
|
1397
1397
|
|
|
1398
1398
|
//#endregion
|
|
1399
1399
|
//#region useArrayIncludes/index.ts
|
|
1400
|
-
function isArrayIncludesOptions(obj) {
|
|
1401
|
-
|
|
1402
|
-
}
|
|
1403
|
-
/**
|
|
1404
|
-
* Reactive `Array.includes`
|
|
1405
|
-
*
|
|
1406
|
-
* @see https://vueuse.org/useArrayIncludes
|
|
1407
|
-
*
|
|
1408
|
-
* @returns true if the `value` is found in the array. Otherwise, false.
|
|
1409
|
-
*
|
|
1410
|
-
* @__NO_SIDE_EFFECTS__
|
|
1411
|
-
*/
|
|
1412
|
-
function useArrayIncludes(...args) {
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
}
|
|
1400
|
+
function isArrayIncludesOptions(obj) {
|
|
1401
|
+
return isObject(obj) && containsProp(obj, "formIndex", "comparator");
|
|
1402
|
+
}
|
|
1403
|
+
/**
|
|
1404
|
+
* Reactive `Array.includes`
|
|
1405
|
+
*
|
|
1406
|
+
* @see https://vueuse.org/useArrayIncludes
|
|
1407
|
+
*
|
|
1408
|
+
* @returns true if the `value` is found in the array. Otherwise, false.
|
|
1409
|
+
*
|
|
1410
|
+
* @__NO_SIDE_EFFECTS__
|
|
1411
|
+
*/
|
|
1412
|
+
function useArrayIncludes(...args) {
|
|
1413
|
+
var _comparator;
|
|
1414
|
+
const list = args[0];
|
|
1415
|
+
const value = args[1];
|
|
1416
|
+
let comparator = args[2];
|
|
1417
|
+
let formIndex = 0;
|
|
1418
|
+
if (isArrayIncludesOptions(comparator)) {
|
|
1419
|
+
var _comparator$fromIndex;
|
|
1420
|
+
formIndex = (_comparator$fromIndex = comparator.fromIndex) !== null && _comparator$fromIndex !== void 0 ? _comparator$fromIndex : 0;
|
|
1421
|
+
comparator = comparator.comparator;
|
|
1422
|
+
}
|
|
1423
|
+
if (typeof comparator === "string") {
|
|
1424
|
+
const key = comparator;
|
|
1425
|
+
comparator = (element, value$1) => element[key] === (0, vue.toValue)(value$1);
|
|
1426
|
+
}
|
|
1427
|
+
comparator = (_comparator = comparator) !== null && _comparator !== void 0 ? _comparator : ((element, value$1) => element === (0, vue.toValue)(value$1));
|
|
1428
|
+
return (0, vue.computed)(() => (0, vue.toValue)(list).slice(formIndex).some((element, index, array) => comparator((0, vue.toValue)(element), (0, vue.toValue)(value), index, (0, vue.toValue)(array))));
|
|
1429
|
+
}
|
|
1430
1430
|
|
|
1431
1431
|
//#endregion
|
|
1432
1432
|
//#region useArrayJoin/index.ts
|
|
1433
1433
|
/**
|
|
1434
|
-
* Reactive `Array.join`
|
|
1435
|
-
*
|
|
1436
|
-
* @see https://vueuse.org/useArrayJoin
|
|
1437
|
-
* @param list - the array was called upon.
|
|
1438
|
-
* @param separator - a string to separate each pair of adjacent elements of the array. If omitted, the array elements are separated with a comma (",").
|
|
1439
|
-
*
|
|
1440
|
-
* @returns a string with all array elements joined. If arr.length is 0, the empty string is returned.
|
|
1441
|
-
*
|
|
1442
|
-
* @__NO_SIDE_EFFECTS__
|
|
1443
|
-
*/
|
|
1444
|
-
function useArrayJoin(list, separator) {
|
|
1445
|
-
|
|
1446
|
-
}
|
|
1434
|
+
* Reactive `Array.join`
|
|
1435
|
+
*
|
|
1436
|
+
* @see https://vueuse.org/useArrayJoin
|
|
1437
|
+
* @param list - the array was called upon.
|
|
1438
|
+
* @param separator - a string to separate each pair of adjacent elements of the array. If omitted, the array elements are separated with a comma (",").
|
|
1439
|
+
*
|
|
1440
|
+
* @returns a string with all array elements joined. If arr.length is 0, the empty string is returned.
|
|
1441
|
+
*
|
|
1442
|
+
* @__NO_SIDE_EFFECTS__
|
|
1443
|
+
*/
|
|
1444
|
+
function useArrayJoin(list, separator) {
|
|
1445
|
+
return (0, vue.computed)(() => (0, vue.toValue)(list).map((i) => (0, vue.toValue)(i)).join((0, vue.toValue)(separator)));
|
|
1446
|
+
}
|
|
1447
1447
|
|
|
1448
1448
|
//#endregion
|
|
1449
1449
|
//#region useArrayMap/index.ts
|
|
1450
1450
|
/**
|
|
1451
|
-
* Reactive `Array.map`
|
|
1452
|
-
*
|
|
1453
|
-
* @see https://vueuse.org/useArrayMap
|
|
1454
|
-
* @param list - the array was called upon.
|
|
1455
|
-
* @param fn - a function that is called for every element of the given `list`. Each time `fn` executes, the returned value is added to the new array.
|
|
1456
|
-
*
|
|
1457
|
-
* @returns a new array with each element being the result of the callback function.
|
|
1458
|
-
*
|
|
1459
|
-
* @__NO_SIDE_EFFECTS__
|
|
1460
|
-
*/
|
|
1461
|
-
function useArrayMap(list, fn) {
|
|
1462
|
-
|
|
1463
|
-
}
|
|
1451
|
+
* Reactive `Array.map`
|
|
1452
|
+
*
|
|
1453
|
+
* @see https://vueuse.org/useArrayMap
|
|
1454
|
+
* @param list - the array was called upon.
|
|
1455
|
+
* @param fn - a function that is called for every element of the given `list`. Each time `fn` executes, the returned value is added to the new array.
|
|
1456
|
+
*
|
|
1457
|
+
* @returns a new array with each element being the result of the callback function.
|
|
1458
|
+
*
|
|
1459
|
+
* @__NO_SIDE_EFFECTS__
|
|
1460
|
+
*/
|
|
1461
|
+
function useArrayMap(list, fn) {
|
|
1462
|
+
return (0, vue.computed)(() => (0, vue.toValue)(list).map((i) => (0, vue.toValue)(i)).map(fn));
|
|
1463
|
+
}
|
|
1464
1464
|
|
|
1465
1465
|
//#endregion
|
|
1466
1466
|
//#region useArrayReduce/index.ts
|
|
1467
1467
|
/**
|
|
1468
|
-
* Reactive `Array.reduce`
|
|
1469
|
-
*
|
|
1470
|
-
* @see https://vueuse.org/useArrayReduce
|
|
1471
|
-
* @param list - the array was called upon.
|
|
1472
|
-
* @param reducer - a "reducer" function.
|
|
1473
|
-
* @param args
|
|
1474
|
-
*
|
|
1475
|
-
* @returns the value that results from running the "reducer" callback function to completion over the entire array.
|
|
1476
|
-
*
|
|
1477
|
-
* @__NO_SIDE_EFFECTS__
|
|
1478
|
-
*/
|
|
1479
|
-
function useArrayReduce(list, reducer, ...args) {
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
}
|
|
1468
|
+
* Reactive `Array.reduce`
|
|
1469
|
+
*
|
|
1470
|
+
* @see https://vueuse.org/useArrayReduce
|
|
1471
|
+
* @param list - the array was called upon.
|
|
1472
|
+
* @param reducer - a "reducer" function.
|
|
1473
|
+
* @param args
|
|
1474
|
+
*
|
|
1475
|
+
* @returns the value that results from running the "reducer" callback function to completion over the entire array.
|
|
1476
|
+
*
|
|
1477
|
+
* @__NO_SIDE_EFFECTS__
|
|
1478
|
+
*/
|
|
1479
|
+
function useArrayReduce(list, reducer, ...args) {
|
|
1480
|
+
const reduceCallback = (sum, value, index) => reducer((0, vue.toValue)(sum), (0, vue.toValue)(value), index);
|
|
1481
|
+
return (0, vue.computed)(() => {
|
|
1482
|
+
const resolved = (0, vue.toValue)(list);
|
|
1483
|
+
return args.length ? resolved.reduce(reduceCallback, typeof args[0] === "function" ? (0, vue.toValue)(args[0]()) : (0, vue.toValue)(args[0])) : resolved.reduce(reduceCallback);
|
|
1484
|
+
});
|
|
1485
|
+
}
|
|
1486
1486
|
|
|
1487
1487
|
//#endregion
|
|
1488
1488
|
//#region useArraySome/index.ts
|
|
1489
1489
|
/**
|
|
1490
|
-
* Reactive `Array.some`
|
|
1491
|
-
*
|
|
1492
|
-
* @see https://vueuse.org/useArraySome
|
|
1493
|
-
* @param list - the array was called upon.
|
|
1494
|
-
* @param fn - a function to test each element.
|
|
1495
|
-
*
|
|
1496
|
-
* @returns **true** if the `fn` function returns a **truthy** value for any element from the array. Otherwise, **false**.
|
|
1497
|
-
*
|
|
1498
|
-
* @__NO_SIDE_EFFECTS__
|
|
1499
|
-
*/
|
|
1500
|
-
function useArraySome(list, fn) {
|
|
1501
|
-
|
|
1502
|
-
}
|
|
1490
|
+
* Reactive `Array.some`
|
|
1491
|
+
*
|
|
1492
|
+
* @see https://vueuse.org/useArraySome
|
|
1493
|
+
* @param list - the array was called upon.
|
|
1494
|
+
* @param fn - a function to test each element.
|
|
1495
|
+
*
|
|
1496
|
+
* @returns **true** if the `fn` function returns a **truthy** value for any element from the array. Otherwise, **false**.
|
|
1497
|
+
*
|
|
1498
|
+
* @__NO_SIDE_EFFECTS__
|
|
1499
|
+
*/
|
|
1500
|
+
function useArraySome(list, fn) {
|
|
1501
|
+
return (0, vue.computed)(() => (0, vue.toValue)(list).some((element, index, array) => fn((0, vue.toValue)(element), index, array)));
|
|
1502
|
+
}
|
|
1503
1503
|
|
|
1504
1504
|
//#endregion
|
|
1505
1505
|
//#region useArrayUnique/index.ts
|
|
1506
|
-
function uniq(array) {
|
|
1507
|
-
|
|
1508
|
-
}
|
|
1509
|
-
function uniqueElementsBy(array, fn) {
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
}
|
|
1515
|
-
/**
|
|
1516
|
-
* reactive unique array
|
|
1517
|
-
* @see https://vueuse.org/useArrayUnique
|
|
1518
|
-
* @param list - the array was called upon.
|
|
1519
|
-
* @param compareFn
|
|
1520
|
-
* @returns A computed ref that returns a unique array of items.
|
|
1521
|
-
*
|
|
1522
|
-
* @__NO_SIDE_EFFECTS__
|
|
1523
|
-
*/
|
|
1524
|
-
function useArrayUnique(list, compareFn) {
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
}
|
|
1506
|
+
function uniq(array) {
|
|
1507
|
+
return Array.from(new Set(array));
|
|
1508
|
+
}
|
|
1509
|
+
function uniqueElementsBy(array, fn) {
|
|
1510
|
+
return array.reduce((acc, v) => {
|
|
1511
|
+
if (!acc.some((x) => fn(v, x, array))) acc.push(v);
|
|
1512
|
+
return acc;
|
|
1513
|
+
}, []);
|
|
1514
|
+
}
|
|
1515
|
+
/**
|
|
1516
|
+
* reactive unique array
|
|
1517
|
+
* @see https://vueuse.org/useArrayUnique
|
|
1518
|
+
* @param list - the array was called upon.
|
|
1519
|
+
* @param compareFn
|
|
1520
|
+
* @returns A computed ref that returns a unique array of items.
|
|
1521
|
+
*
|
|
1522
|
+
* @__NO_SIDE_EFFECTS__
|
|
1523
|
+
*/
|
|
1524
|
+
function useArrayUnique(list, compareFn) {
|
|
1525
|
+
return (0, vue.computed)(() => {
|
|
1526
|
+
const resolvedList = (0, vue.toValue)(list).map((element) => (0, vue.toValue)(element));
|
|
1527
|
+
return compareFn ? uniqueElementsBy(resolvedList, compareFn) : uniq(resolvedList);
|
|
1528
|
+
});
|
|
1529
|
+
}
|
|
1530
1530
|
|
|
1531
1531
|
//#endregion
|
|
1532
1532
|
//#region useCounter/index.ts
|
|
1533
1533
|
/**
|
|
1534
|
-
* Basic counter with utility functions.
|
|
1535
|
-
*
|
|
1536
|
-
* @see https://vueuse.org/useCounter
|
|
1537
|
-
* @param [initialValue]
|
|
1538
|
-
* @param options
|
|
1539
|
-
*/
|
|
1540
|
-
function useCounter(initialValue = 0, options = {}) {
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
}
|
|
1534
|
+
* Basic counter with utility functions.
|
|
1535
|
+
*
|
|
1536
|
+
* @see https://vueuse.org/useCounter
|
|
1537
|
+
* @param [initialValue]
|
|
1538
|
+
* @param options
|
|
1539
|
+
*/
|
|
1540
|
+
function useCounter(initialValue = 0, options = {}) {
|
|
1541
|
+
let _initialValue = (0, vue.unref)(initialValue);
|
|
1542
|
+
const count = (0, vue.shallowRef)(initialValue);
|
|
1543
|
+
const { max = Number.POSITIVE_INFINITY, min = Number.NEGATIVE_INFINITY } = options;
|
|
1544
|
+
const inc = (delta = 1) => count.value = Math.max(Math.min(max, count.value + delta), min);
|
|
1545
|
+
const dec = (delta = 1) => count.value = Math.min(Math.max(min, count.value - delta), max);
|
|
1546
|
+
const get$1 = () => count.value;
|
|
1547
|
+
const set$1 = (val) => count.value = Math.max(min, Math.min(max, val));
|
|
1548
|
+
const reset = (val = _initialValue) => {
|
|
1549
|
+
_initialValue = val;
|
|
1550
|
+
return set$1(val);
|
|
1551
|
+
};
|
|
1552
|
+
return {
|
|
1553
|
+
count: (0, vue.shallowReadonly)(count),
|
|
1554
|
+
inc,
|
|
1555
|
+
dec,
|
|
1556
|
+
get: get$1,
|
|
1557
|
+
set: set$1,
|
|
1558
|
+
reset
|
|
1559
|
+
};
|
|
1560
|
+
}
|
|
1561
1561
|
|
|
1562
1562
|
//#endregion
|
|
1563
1563
|
//#region useDateFormat/index.ts
|
|
1564
|
-
const REGEX_PARSE = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[T\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/i;
|
|
1565
|
-
const REGEX_FORMAT = /[YMDHhms]o|\[([^\]]+)\]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a{1,2}|A{1,2}|m{1,2}|s{1,2}|Z{1,2}|z{1,4}|SSS/g;
|
|
1566
|
-
function defaultMeridiem(hours, minutes, isLowercase, hasPeriod) {
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
}
|
|
1571
|
-
function formatOrdinal(num) {
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
}
|
|
1581
|
-
function formatDate(date, formatStr, options = {}) {
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
}
|
|
1639
|
-
function normalizeDate(date) {
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1564
|
+
const REGEX_PARSE = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[T\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/i;
|
|
1565
|
+
const REGEX_FORMAT = /[YMDHhms]o|\[([^\]]+)\]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a{1,2}|A{1,2}|m{1,2}|s{1,2}|Z{1,2}|z{1,4}|SSS/g;
|
|
1566
|
+
function defaultMeridiem(hours, minutes, isLowercase, hasPeriod) {
|
|
1567
|
+
let m = hours < 12 ? "AM" : "PM";
|
|
1568
|
+
if (hasPeriod) m = m.split("").reduce((acc, curr) => acc += `${curr}.`, "");
|
|
1569
|
+
return isLowercase ? m.toLowerCase() : m;
|
|
1570
|
+
}
|
|
1571
|
+
function formatOrdinal(num) {
|
|
1572
|
+
const suffixes = [
|
|
1573
|
+
"th",
|
|
1574
|
+
"st",
|
|
1575
|
+
"nd",
|
|
1576
|
+
"rd"
|
|
1577
|
+
];
|
|
1578
|
+
const v = num % 100;
|
|
1579
|
+
return num + (suffixes[(v - 20) % 10] || suffixes[v] || suffixes[0]);
|
|
1580
|
+
}
|
|
1581
|
+
function formatDate(date, formatStr, options = {}) {
|
|
1582
|
+
var _options$customMeridi;
|
|
1583
|
+
const years = date.getFullYear();
|
|
1584
|
+
const month = date.getMonth();
|
|
1585
|
+
const days = date.getDate();
|
|
1586
|
+
const hours = date.getHours();
|
|
1587
|
+
const minutes = date.getMinutes();
|
|
1588
|
+
const seconds = date.getSeconds();
|
|
1589
|
+
const milliseconds = date.getMilliseconds();
|
|
1590
|
+
const day = date.getDay();
|
|
1591
|
+
const meridiem = (_options$customMeridi = options.customMeridiem) !== null && _options$customMeridi !== void 0 ? _options$customMeridi : defaultMeridiem;
|
|
1592
|
+
const stripTimeZone = (dateString) => {
|
|
1593
|
+
var _dateString$split$;
|
|
1594
|
+
return (_dateString$split$ = dateString.split(" ")[1]) !== null && _dateString$split$ !== void 0 ? _dateString$split$ : "";
|
|
1595
|
+
};
|
|
1596
|
+
const matches = {
|
|
1597
|
+
Yo: () => formatOrdinal(years),
|
|
1598
|
+
YY: () => String(years).slice(-2),
|
|
1599
|
+
YYYY: () => years,
|
|
1600
|
+
M: () => month + 1,
|
|
1601
|
+
Mo: () => formatOrdinal(month + 1),
|
|
1602
|
+
MM: () => `${month + 1}`.padStart(2, "0"),
|
|
1603
|
+
MMM: () => date.toLocaleDateString((0, vue.toValue)(options.locales), { month: "short" }),
|
|
1604
|
+
MMMM: () => date.toLocaleDateString((0, vue.toValue)(options.locales), { month: "long" }),
|
|
1605
|
+
D: () => String(days),
|
|
1606
|
+
Do: () => formatOrdinal(days),
|
|
1607
|
+
DD: () => `${days}`.padStart(2, "0"),
|
|
1608
|
+
H: () => String(hours),
|
|
1609
|
+
Ho: () => formatOrdinal(hours),
|
|
1610
|
+
HH: () => `${hours}`.padStart(2, "0"),
|
|
1611
|
+
h: () => `${hours % 12 || 12}`.padStart(1, "0"),
|
|
1612
|
+
ho: () => formatOrdinal(hours % 12 || 12),
|
|
1613
|
+
hh: () => `${hours % 12 || 12}`.padStart(2, "0"),
|
|
1614
|
+
m: () => String(minutes),
|
|
1615
|
+
mo: () => formatOrdinal(minutes),
|
|
1616
|
+
mm: () => `${minutes}`.padStart(2, "0"),
|
|
1617
|
+
s: () => String(seconds),
|
|
1618
|
+
so: () => formatOrdinal(seconds),
|
|
1619
|
+
ss: () => `${seconds}`.padStart(2, "0"),
|
|
1620
|
+
SSS: () => `${milliseconds}`.padStart(3, "0"),
|
|
1621
|
+
d: () => day,
|
|
1622
|
+
dd: () => date.toLocaleDateString((0, vue.toValue)(options.locales), { weekday: "narrow" }),
|
|
1623
|
+
ddd: () => date.toLocaleDateString((0, vue.toValue)(options.locales), { weekday: "short" }),
|
|
1624
|
+
dddd: () => date.toLocaleDateString((0, vue.toValue)(options.locales), { weekday: "long" }),
|
|
1625
|
+
A: () => meridiem(hours, minutes),
|
|
1626
|
+
AA: () => meridiem(hours, minutes, false, true),
|
|
1627
|
+
a: () => meridiem(hours, minutes, true),
|
|
1628
|
+
aa: () => meridiem(hours, minutes, true, true),
|
|
1629
|
+
z: () => stripTimeZone(date.toLocaleDateString((0, vue.toValue)(options.locales), { timeZoneName: "shortOffset" })),
|
|
1630
|
+
zz: () => stripTimeZone(date.toLocaleDateString((0, vue.toValue)(options.locales), { timeZoneName: "shortOffset" })),
|
|
1631
|
+
zzz: () => stripTimeZone(date.toLocaleDateString((0, vue.toValue)(options.locales), { timeZoneName: "shortOffset" })),
|
|
1632
|
+
zzzz: () => stripTimeZone(date.toLocaleDateString((0, vue.toValue)(options.locales), { timeZoneName: "longOffset" }))
|
|
1633
|
+
};
|
|
1634
|
+
return formatStr.replace(REGEX_FORMAT, (match, $1) => {
|
|
1635
|
+
var _ref, _matches$match;
|
|
1636
|
+
return (_ref = $1 !== null && $1 !== void 0 ? $1 : (_matches$match = matches[match]) === null || _matches$match === void 0 ? void 0 : _matches$match.call(matches)) !== null && _ref !== void 0 ? _ref : match;
|
|
1637
|
+
});
|
|
1638
|
+
}
|
|
1639
|
+
function normalizeDate(date) {
|
|
1640
|
+
if (date === null) return /* @__PURE__ */ new Date(NaN);
|
|
1641
|
+
if (date === void 0) return /* @__PURE__ */ new Date();
|
|
1642
|
+
if (date instanceof Date) return new Date(date);
|
|
1643
|
+
if (typeof date === "string" && !/Z$/i.test(date)) {
|
|
1644
|
+
const d = date.match(REGEX_PARSE);
|
|
1645
|
+
if (d) {
|
|
1646
|
+
const m = d[2] - 1 || 0;
|
|
1647
|
+
const ms = (d[7] || "0").substring(0, 3);
|
|
1648
|
+
return new Date(d[1], m, d[3] || 1, d[4] || 0, d[5] || 0, d[6] || 0, ms);
|
|
1649
|
+
}
|
|
1649
1650
|
}
|
|
1651
|
+
return new Date(date);
|
|
1652
|
+
}
|
|
1653
|
+
/**
|
|
1654
|
+
* Get the formatted date according to the string of tokens passed in.
|
|
1655
|
+
*
|
|
1656
|
+
* @see https://vueuse.org/useDateFormat
|
|
1657
|
+
* @param date - The date to format, can either be a `Date` object, a timestamp, or a string
|
|
1658
|
+
* @param formatStr - The combination of tokens to format the date
|
|
1659
|
+
* @param options - UseDateFormatOptions
|
|
1660
|
+
*
|
|
1661
|
+
* @__NO_SIDE_EFFECTS__
|
|
1662
|
+
*/
|
|
1663
|
+
function useDateFormat(date, formatStr = "HH:mm:ss", options = {}) {
|
|
1664
|
+
return (0, vue.computed)(() => formatDate(normalizeDate((0, vue.toValue)(date)), (0, vue.toValue)(formatStr), options));
|
|
1650
1665
|
}
|
|
1651
|
-
return new Date(date);
|
|
1652
|
-
}
|
|
1653
|
-
/**
|
|
1654
|
-
* Get the formatted date according to the string of tokens passed in.
|
|
1655
|
-
*
|
|
1656
|
-
* @see https://vueuse.org/useDateFormat
|
|
1657
|
-
* @param date - The date to format, can either be a `Date` object, a timestamp, or a string
|
|
1658
|
-
* @param formatStr - The combination of tokens to format the date
|
|
1659
|
-
* @param options - UseDateFormatOptions
|
|
1660
|
-
*
|
|
1661
|
-
* @__NO_SIDE_EFFECTS__
|
|
1662
|
-
*/
|
|
1663
|
-
function useDateFormat(date, formatStr = "HH:mm:ss", options = {}) {
|
|
1664
|
-
return (0, vue.computed)(() => formatDate(normalizeDate((0, vue.toValue)(date)), (0, vue.toValue)(formatStr), options));
|
|
1665
|
-
}
|
|
1666
1666
|
|
|
1667
1667
|
//#endregion
|
|
1668
1668
|
//#region useIntervalFn/index.ts
|
|
1669
1669
|
/**
|
|
1670
|
-
* Wrapper for `setInterval` with controls
|
|
1671
|
-
*
|
|
1672
|
-
* @see https://vueuse.org/useIntervalFn
|
|
1673
|
-
* @param cb
|
|
1674
|
-
* @param interval
|
|
1675
|
-
* @param options
|
|
1676
|
-
*/
|
|
1677
|
-
function useIntervalFn(cb, interval = 1e3, options = {}) {
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1670
|
+
* Wrapper for `setInterval` with controls
|
|
1671
|
+
*
|
|
1672
|
+
* @see https://vueuse.org/useIntervalFn
|
|
1673
|
+
* @param cb
|
|
1674
|
+
* @param interval
|
|
1675
|
+
* @param options
|
|
1676
|
+
*/
|
|
1677
|
+
function useIntervalFn(cb, interval = 1e3, options = {}) {
|
|
1678
|
+
const { immediate = true, immediateCallback = false } = options;
|
|
1679
|
+
let timer = null;
|
|
1680
|
+
const isActive = (0, vue.shallowRef)(false);
|
|
1681
|
+
function clean() {
|
|
1682
|
+
if (timer) {
|
|
1683
|
+
clearInterval(timer);
|
|
1684
|
+
timer = null;
|
|
1685
|
+
}
|
|
1685
1686
|
}
|
|
1687
|
+
function pause() {
|
|
1688
|
+
isActive.value = false;
|
|
1689
|
+
clean();
|
|
1690
|
+
}
|
|
1691
|
+
function resume() {
|
|
1692
|
+
const intervalValue = (0, vue.toValue)(interval);
|
|
1693
|
+
if (intervalValue <= 0) return;
|
|
1694
|
+
isActive.value = true;
|
|
1695
|
+
if (immediateCallback) cb();
|
|
1696
|
+
clean();
|
|
1697
|
+
if (isActive.value) timer = setInterval(cb, intervalValue);
|
|
1698
|
+
}
|
|
1699
|
+
if (immediate && isClient) resume();
|
|
1700
|
+
if ((0, vue.isRef)(interval) || typeof interval === "function") {
|
|
1701
|
+
const stopWatch = (0, vue.watch)(interval, () => {
|
|
1702
|
+
if (isActive.value && isClient) resume();
|
|
1703
|
+
});
|
|
1704
|
+
tryOnScopeDispose(stopWatch);
|
|
1705
|
+
}
|
|
1706
|
+
tryOnScopeDispose(pause);
|
|
1707
|
+
return {
|
|
1708
|
+
isActive: (0, vue.shallowReadonly)(isActive),
|
|
1709
|
+
pause,
|
|
1710
|
+
resume
|
|
1711
|
+
};
|
|
1686
1712
|
}
|
|
1687
|
-
function pause() {
|
|
1688
|
-
isActive.value = false;
|
|
1689
|
-
clean();
|
|
1690
|
-
}
|
|
1691
|
-
function resume() {
|
|
1692
|
-
const intervalValue = (0, vue.toValue)(interval);
|
|
1693
|
-
if (intervalValue <= 0) return;
|
|
1694
|
-
isActive.value = true;
|
|
1695
|
-
if (immediateCallback) cb();
|
|
1696
|
-
clean();
|
|
1697
|
-
if (isActive.value) timer = setInterval(cb, intervalValue);
|
|
1698
|
-
}
|
|
1699
|
-
if (immediate && isClient) resume();
|
|
1700
|
-
if ((0, vue.isRef)(interval) || typeof interval === "function") {
|
|
1701
|
-
const stopWatch = (0, vue.watch)(interval, () => {
|
|
1702
|
-
if (isActive.value && isClient) resume();
|
|
1703
|
-
});
|
|
1704
|
-
tryOnScopeDispose(stopWatch);
|
|
1705
|
-
}
|
|
1706
|
-
tryOnScopeDispose(pause);
|
|
1707
|
-
return {
|
|
1708
|
-
isActive: (0, vue.shallowReadonly)(isActive),
|
|
1709
|
-
pause,
|
|
1710
|
-
resume
|
|
1711
|
-
};
|
|
1712
|
-
}
|
|
1713
1713
|
|
|
1714
1714
|
//#endregion
|
|
1715
1715
|
//#region useInterval/index.ts
|
|
1716
|
-
function useInterval(interval = 1e3, options = {}) {
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
}
|
|
1716
|
+
function useInterval(interval = 1e3, options = {}) {
|
|
1717
|
+
const { controls: exposeControls = false, immediate = true, callback } = options;
|
|
1718
|
+
const counter = (0, vue.shallowRef)(0);
|
|
1719
|
+
const update = () => counter.value += 1;
|
|
1720
|
+
const reset = () => {
|
|
1721
|
+
counter.value = 0;
|
|
1722
|
+
};
|
|
1723
|
+
const controls = useIntervalFn(callback ? () => {
|
|
1724
|
+
update();
|
|
1725
|
+
callback(counter.value);
|
|
1726
|
+
} : update, interval, { immediate });
|
|
1727
|
+
if (exposeControls) return {
|
|
1728
|
+
counter: (0, vue.shallowReadonly)(counter),
|
|
1729
|
+
reset,
|
|
1730
|
+
...controls
|
|
1731
|
+
};
|
|
1732
|
+
else return (0, vue.shallowReadonly)(counter);
|
|
1733
|
+
}
|
|
1734
1734
|
|
|
1735
1735
|
//#endregion
|
|
1736
1736
|
//#region useLastChanged/index.ts
|
|
1737
|
-
function useLastChanged(source, options = {}) {
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
}
|
|
1737
|
+
function useLastChanged(source, options = {}) {
|
|
1738
|
+
var _options$initialValue;
|
|
1739
|
+
const ms = (0, vue.shallowRef)((_options$initialValue = options.initialValue) !== null && _options$initialValue !== void 0 ? _options$initialValue : null);
|
|
1740
|
+
(0, vue.watch)(source, () => ms.value = timestamp(), options);
|
|
1741
|
+
return (0, vue.shallowReadonly)(ms);
|
|
1742
|
+
}
|
|
1743
1743
|
|
|
1744
1744
|
//#endregion
|
|
1745
1745
|
//#region useTimeoutFn/index.ts
|
|
1746
1746
|
/**
|
|
1747
|
-
* Wrapper for `setTimeout` with controls.
|
|
1748
|
-
*
|
|
1749
|
-
* @param cb
|
|
1750
|
-
* @param interval
|
|
1751
|
-
* @param options
|
|
1752
|
-
*/
|
|
1753
|
-
function useTimeoutFn(cb, interval, options = {}) {
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1747
|
+
* Wrapper for `setTimeout` with controls.
|
|
1748
|
+
*
|
|
1749
|
+
* @param cb
|
|
1750
|
+
* @param interval
|
|
1751
|
+
* @param options
|
|
1752
|
+
*/
|
|
1753
|
+
function useTimeoutFn(cb, interval, options = {}) {
|
|
1754
|
+
const { immediate = true, immediateCallback = false } = options;
|
|
1755
|
+
const isPending = (0, vue.shallowRef)(false);
|
|
1756
|
+
let timer;
|
|
1757
|
+
function clear() {
|
|
1758
|
+
if (timer) {
|
|
1759
|
+
clearTimeout(timer);
|
|
1760
|
+
timer = void 0;
|
|
1761
|
+
}
|
|
1761
1762
|
}
|
|
1762
|
-
|
|
1763
|
-
function stop() {
|
|
1764
|
-
isPending.value = false;
|
|
1765
|
-
clear();
|
|
1766
|
-
}
|
|
1767
|
-
function start(...args) {
|
|
1768
|
-
if (immediateCallback) cb();
|
|
1769
|
-
clear();
|
|
1770
|
-
isPending.value = true;
|
|
1771
|
-
timer = setTimeout(() => {
|
|
1763
|
+
function stop() {
|
|
1772
1764
|
isPending.value = false;
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1765
|
+
clear();
|
|
1766
|
+
}
|
|
1767
|
+
function start(...args) {
|
|
1768
|
+
if (immediateCallback) cb();
|
|
1769
|
+
clear();
|
|
1770
|
+
isPending.value = true;
|
|
1771
|
+
timer = setTimeout(() => {
|
|
1772
|
+
isPending.value = false;
|
|
1773
|
+
timer = void 0;
|
|
1774
|
+
cb(...args);
|
|
1775
|
+
}, (0, vue.toValue)(interval));
|
|
1776
|
+
}
|
|
1777
|
+
if (immediate) {
|
|
1778
|
+
isPending.value = true;
|
|
1779
|
+
if (isClient) start();
|
|
1780
|
+
}
|
|
1781
|
+
tryOnScopeDispose(stop);
|
|
1782
|
+
return {
|
|
1783
|
+
isPending: (0, vue.shallowReadonly)(isPending),
|
|
1784
|
+
start,
|
|
1785
|
+
stop
|
|
1786
|
+
};
|
|
1780
1787
|
}
|
|
1781
|
-
tryOnScopeDispose(stop);
|
|
1782
|
-
return {
|
|
1783
|
-
isPending: (0, vue.shallowReadonly)(isPending),
|
|
1784
|
-
start,
|
|
1785
|
-
stop
|
|
1786
|
-
};
|
|
1787
|
-
}
|
|
1788
1788
|
|
|
1789
1789
|
//#endregion
|
|
1790
1790
|
//#region useTimeout/index.ts
|
|
1791
|
-
function useTimeout(interval = 1e3, options = {}) {
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
}
|
|
1791
|
+
function useTimeout(interval = 1e3, options = {}) {
|
|
1792
|
+
const { controls: exposeControls = false, callback } = options;
|
|
1793
|
+
const controls = useTimeoutFn(callback !== null && callback !== void 0 ? callback : noop, interval, options);
|
|
1794
|
+
const ready = (0, vue.computed)(() => !controls.isPending.value);
|
|
1795
|
+
if (exposeControls) return {
|
|
1796
|
+
ready,
|
|
1797
|
+
...controls
|
|
1798
|
+
};
|
|
1799
|
+
else return ready;
|
|
1800
|
+
}
|
|
1801
1801
|
|
|
1802
1802
|
//#endregion
|
|
1803
1803
|
//#region useToNumber/index.ts
|
|
1804
1804
|
/**
|
|
1805
|
-
* Reactively convert a string ref to number.
|
|
1806
|
-
*
|
|
1807
|
-
* @__NO_SIDE_EFFECTS__
|
|
1808
|
-
*/
|
|
1809
|
-
function useToNumber(value, options = {}) {
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
}
|
|
1805
|
+
* Reactively convert a string ref to number.
|
|
1806
|
+
*
|
|
1807
|
+
* @__NO_SIDE_EFFECTS__
|
|
1808
|
+
*/
|
|
1809
|
+
function useToNumber(value, options = {}) {
|
|
1810
|
+
const { method = "parseFloat", radix, nanToZero } = options;
|
|
1811
|
+
return (0, vue.computed)(() => {
|
|
1812
|
+
let resolved = (0, vue.toValue)(value);
|
|
1813
|
+
if (typeof method === "function") resolved = method(resolved);
|
|
1814
|
+
else if (typeof resolved === "string") resolved = Number[method](resolved, radix);
|
|
1815
|
+
if (nanToZero && Number.isNaN(resolved)) resolved = 0;
|
|
1816
|
+
return resolved;
|
|
1817
|
+
});
|
|
1818
|
+
}
|
|
1819
1819
|
|
|
1820
1820
|
//#endregion
|
|
1821
1821
|
//#region useToString/index.ts
|
|
1822
1822
|
/**
|
|
1823
|
-
* Reactively convert a ref to string.
|
|
1824
|
-
*
|
|
1825
|
-
* @see https://vueuse.org/useToString
|
|
1826
|
-
*
|
|
1827
|
-
* @__NO_SIDE_EFFECTS__
|
|
1828
|
-
*/
|
|
1829
|
-
function useToString(value) {
|
|
1830
|
-
|
|
1831
|
-
}
|
|
1823
|
+
* Reactively convert a ref to string.
|
|
1824
|
+
*
|
|
1825
|
+
* @see https://vueuse.org/useToString
|
|
1826
|
+
*
|
|
1827
|
+
* @__NO_SIDE_EFFECTS__
|
|
1828
|
+
*/
|
|
1829
|
+
function useToString(value) {
|
|
1830
|
+
return (0, vue.computed)(() => `${(0, vue.toValue)(value)}`);
|
|
1831
|
+
}
|
|
1832
1832
|
|
|
1833
1833
|
//#endregion
|
|
1834
1834
|
//#region useToggle/index.ts
|
|
1835
1835
|
/**
|
|
1836
|
-
* A boolean ref with a toggler
|
|
1837
|
-
*
|
|
1838
|
-
* @see https://vueuse.org/useToggle
|
|
1839
|
-
* @param [initialValue]
|
|
1840
|
-
* @param options
|
|
1841
|
-
*
|
|
1842
|
-
* @__NO_SIDE_EFFECTS__
|
|
1843
|
-
*/
|
|
1844
|
-
function useToggle(initialValue = false, options = {}) {
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1836
|
+
* A boolean ref with a toggler
|
|
1837
|
+
*
|
|
1838
|
+
* @see https://vueuse.org/useToggle
|
|
1839
|
+
* @param [initialValue]
|
|
1840
|
+
* @param options
|
|
1841
|
+
*
|
|
1842
|
+
* @__NO_SIDE_EFFECTS__
|
|
1843
|
+
*/
|
|
1844
|
+
function useToggle(initialValue = false, options = {}) {
|
|
1845
|
+
const { truthyValue = true, falsyValue = false } = options;
|
|
1846
|
+
const valueIsRef = (0, vue.isRef)(initialValue);
|
|
1847
|
+
const _value = (0, vue.shallowRef)(initialValue);
|
|
1848
|
+
function toggle(value) {
|
|
1849
|
+
if (arguments.length) {
|
|
1850
|
+
_value.value = value;
|
|
1851
|
+
return _value.value;
|
|
1852
|
+
} else {
|
|
1853
|
+
const truthy = (0, vue.toValue)(truthyValue);
|
|
1854
|
+
_value.value = _value.value === truthy ? (0, vue.toValue)(falsyValue) : truthy;
|
|
1855
|
+
return _value.value;
|
|
1856
|
+
}
|
|
1856
1857
|
}
|
|
1858
|
+
if (valueIsRef) return toggle;
|
|
1859
|
+
else return [_value, toggle];
|
|
1857
1860
|
}
|
|
1858
|
-
if (valueIsRef) return toggle;
|
|
1859
|
-
else return [_value, toggle];
|
|
1860
|
-
}
|
|
1861
1861
|
|
|
1862
1862
|
//#endregion
|
|
1863
1863
|
//#region watchArray/index.ts
|
|
1864
1864
|
/**
|
|
1865
|
-
* Watch for an array with additions and removals.
|
|
1866
|
-
*
|
|
1867
|
-
* @see https://vueuse.org/watchArray
|
|
1868
|
-
*/
|
|
1869
|
-
function watchArray(source, cb, options) {
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1865
|
+
* Watch for an array with additions and removals.
|
|
1866
|
+
*
|
|
1867
|
+
* @see https://vueuse.org/watchArray
|
|
1868
|
+
*/
|
|
1869
|
+
function watchArray(source, cb, options) {
|
|
1870
|
+
let oldList = (options === null || options === void 0 ? void 0 : options.immediate) ? [] : [...typeof source === "function" ? source() : Array.isArray(source) ? source : (0, vue.toValue)(source)];
|
|
1871
|
+
return (0, vue.watch)(source, (newList, _, onCleanup) => {
|
|
1872
|
+
const oldListRemains = Array.from({ length: oldList.length });
|
|
1873
|
+
const added = [];
|
|
1874
|
+
for (const obj of newList) {
|
|
1875
|
+
let found = false;
|
|
1876
|
+
for (let i = 0; i < oldList.length; i++) if (!oldListRemains[i] && obj === oldList[i]) {
|
|
1877
|
+
oldListRemains[i] = true;
|
|
1878
|
+
found = true;
|
|
1879
|
+
break;
|
|
1880
|
+
}
|
|
1881
|
+
if (!found) added.push(obj);
|
|
1880
1882
|
}
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
}, options);
|
|
1887
|
-
}
|
|
1883
|
+
const removed = oldList.filter((_$1, i) => !oldListRemains[i]);
|
|
1884
|
+
cb(newList, oldList, added, removed, onCleanup);
|
|
1885
|
+
oldList = [...newList];
|
|
1886
|
+
}, options);
|
|
1887
|
+
}
|
|
1888
1888
|
|
|
1889
1889
|
//#endregion
|
|
1890
1890
|
//#region watchAtMost/index.ts
|
|
1891
|
-
function watchAtMost(source, cb, options) {
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
}
|
|
1891
|
+
function watchAtMost(source, cb, options) {
|
|
1892
|
+
const { count,...watchOptions } = options;
|
|
1893
|
+
const current = (0, vue.shallowRef)(0);
|
|
1894
|
+
const { stop, resume, pause } = watchWithFilter(source, (...args) => {
|
|
1895
|
+
current.value += 1;
|
|
1896
|
+
if (current.value >= (0, vue.toValue)(count)) (0, vue.nextTick)(() => stop());
|
|
1897
|
+
cb(...args);
|
|
1898
|
+
}, watchOptions);
|
|
1899
|
+
return {
|
|
1900
|
+
count: current,
|
|
1901
|
+
stop,
|
|
1902
|
+
resume,
|
|
1903
|
+
pause
|
|
1904
|
+
};
|
|
1905
|
+
}
|
|
1906
1906
|
|
|
1907
1907
|
//#endregion
|
|
1908
1908
|
//#region watchDebounced/index.ts
|
|
1909
|
-
function watchDebounced(source, cb, options = {}) {
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
}
|
|
1916
|
-
/** @deprecated use `watchDebounced` instead */
|
|
1917
|
-
const debouncedWatch = watchDebounced;
|
|
1909
|
+
function watchDebounced(source, cb, options = {}) {
|
|
1910
|
+
const { debounce = 0, maxWait = void 0,...watchOptions } = options;
|
|
1911
|
+
return watchWithFilter(source, cb, {
|
|
1912
|
+
...watchOptions,
|
|
1913
|
+
eventFilter: debounceFilter(debounce, { maxWait })
|
|
1914
|
+
});
|
|
1915
|
+
}
|
|
1916
|
+
/** @deprecated use `watchDebounced` instead */
|
|
1917
|
+
const debouncedWatch = watchDebounced;
|
|
1918
1918
|
|
|
1919
1919
|
//#endregion
|
|
1920
1920
|
//#region watchDeep/index.ts
|
|
1921
1921
|
/**
|
|
1922
|
-
* Shorthand for watching value with {deep: true}
|
|
1923
|
-
*
|
|
1924
|
-
* @see https://vueuse.org/watchDeep
|
|
1925
|
-
*/
|
|
1926
|
-
function watchDeep(source, cb, options) {
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
}
|
|
1922
|
+
* Shorthand for watching value with {deep: true}
|
|
1923
|
+
*
|
|
1924
|
+
* @see https://vueuse.org/watchDeep
|
|
1925
|
+
*/
|
|
1926
|
+
function watchDeep(source, cb, options) {
|
|
1927
|
+
return (0, vue.watch)(source, cb, {
|
|
1928
|
+
...options,
|
|
1929
|
+
deep: true
|
|
1930
|
+
});
|
|
1931
|
+
}
|
|
1932
1932
|
|
|
1933
1933
|
//#endregion
|
|
1934
1934
|
//#region watchIgnorable/index.ts
|
|
1935
|
-
function watchIgnorable(source, cb, options = {}) {
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1935
|
+
function watchIgnorable(source, cb, options = {}) {
|
|
1936
|
+
const { eventFilter = bypassFilter,...watchOptions } = options;
|
|
1937
|
+
const filteredCb = createFilterWrapper(eventFilter, cb);
|
|
1938
|
+
let ignoreUpdates;
|
|
1939
|
+
let ignorePrevAsyncUpdates;
|
|
1940
|
+
let stop;
|
|
1941
|
+
if (watchOptions.flush === "sync") {
|
|
1942
|
+
let ignore = false;
|
|
1943
|
+
ignorePrevAsyncUpdates = () => {};
|
|
1944
|
+
ignoreUpdates = (updater) => {
|
|
1945
|
+
ignore = true;
|
|
1946
|
+
updater();
|
|
1947
|
+
ignore = false;
|
|
1948
|
+
};
|
|
1949
|
+
stop = (0, vue.watch)(source, (...args) => {
|
|
1950
|
+
if (!ignore) filteredCb(...args);
|
|
1951
|
+
}, watchOptions);
|
|
1952
|
+
} else {
|
|
1953
|
+
const disposables = [];
|
|
1954
|
+
let ignoreCounter = 0;
|
|
1955
|
+
let syncCounter = 0;
|
|
1956
|
+
ignorePrevAsyncUpdates = () => {
|
|
1957
|
+
ignoreCounter = syncCounter;
|
|
1958
|
+
};
|
|
1959
|
+
disposables.push((0, vue.watch)(source, () => {
|
|
1960
|
+
syncCounter++;
|
|
1961
|
+
}, {
|
|
1962
|
+
...watchOptions,
|
|
1963
|
+
flush: "sync"
|
|
1964
|
+
}));
|
|
1965
|
+
ignoreUpdates = (updater) => {
|
|
1966
|
+
const syncCounterPrev = syncCounter;
|
|
1967
|
+
updater();
|
|
1968
|
+
ignoreCounter += syncCounter - syncCounterPrev;
|
|
1969
|
+
};
|
|
1970
|
+
disposables.push((0, vue.watch)(source, (...args) => {
|
|
1971
|
+
const ignore = ignoreCounter > 0 && ignoreCounter === syncCounter;
|
|
1972
|
+
ignoreCounter = 0;
|
|
1973
|
+
syncCounter = 0;
|
|
1974
|
+
if (ignore) return;
|
|
1975
|
+
filteredCb(...args);
|
|
1976
|
+
}, watchOptions));
|
|
1977
|
+
stop = () => {
|
|
1978
|
+
disposables.forEach((fn) => fn());
|
|
1979
|
+
};
|
|
1980
|
+
}
|
|
1981
|
+
return {
|
|
1982
|
+
stop,
|
|
1983
|
+
ignoreUpdates,
|
|
1984
|
+
ignorePrevAsyncUpdates
|
|
1979
1985
|
};
|
|
1980
1986
|
}
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
ignoreUpdates,
|
|
1984
|
-
ignorePrevAsyncUpdates
|
|
1985
|
-
};
|
|
1986
|
-
}
|
|
1987
|
-
/** @deprecated use `watchIgnorable` instead */
|
|
1988
|
-
const ignorableWatch = watchIgnorable;
|
|
1987
|
+
/** @deprecated use `watchIgnorable` instead */
|
|
1988
|
+
const ignorableWatch = watchIgnorable;
|
|
1989
1989
|
|
|
1990
1990
|
//#endregion
|
|
1991
1991
|
//#region watchImmediate/index.ts
|
|
1992
1992
|
/**
|
|
1993
|
-
* Shorthand for watching value with {immediate: true}
|
|
1994
|
-
*
|
|
1995
|
-
* @see https://vueuse.org/watchImmediate
|
|
1996
|
-
*/
|
|
1997
|
-
function watchImmediate(source, cb, options) {
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
}
|
|
1993
|
+
* Shorthand for watching value with {immediate: true}
|
|
1994
|
+
*
|
|
1995
|
+
* @see https://vueuse.org/watchImmediate
|
|
1996
|
+
*/
|
|
1997
|
+
function watchImmediate(source, cb, options) {
|
|
1998
|
+
return (0, vue.watch)(source, cb, {
|
|
1999
|
+
...options,
|
|
2000
|
+
immediate: true
|
|
2001
|
+
});
|
|
2002
|
+
}
|
|
2003
2003
|
|
|
2004
2004
|
//#endregion
|
|
2005
2005
|
//#region watchOnce/index.ts
|
|
2006
2006
|
/**
|
|
2007
|
-
* Shorthand for watching value with { once: true }
|
|
2008
|
-
*
|
|
2009
|
-
* @see https://vueuse.org/watchOnce
|
|
2010
|
-
*/
|
|
2011
|
-
function watchOnce(source, cb, options) {
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
}
|
|
2007
|
+
* Shorthand for watching value with { once: true }
|
|
2008
|
+
*
|
|
2009
|
+
* @see https://vueuse.org/watchOnce
|
|
2010
|
+
*/
|
|
2011
|
+
function watchOnce(source, cb, options) {
|
|
2012
|
+
return (0, vue.watch)(source, cb, {
|
|
2013
|
+
...options,
|
|
2014
|
+
once: true
|
|
2015
|
+
});
|
|
2016
|
+
}
|
|
2017
2017
|
|
|
2018
2018
|
//#endregion
|
|
2019
2019
|
//#region watchThrottled/index.ts
|
|
2020
|
-
function watchThrottled(source, cb, options = {}) {
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
}
|
|
2027
|
-
/** @deprecated use `watchThrottled` instead */
|
|
2028
|
-
const throttledWatch = watchThrottled;
|
|
2020
|
+
function watchThrottled(source, cb, options = {}) {
|
|
2021
|
+
const { throttle = 0, trailing = true, leading = true,...watchOptions } = options;
|
|
2022
|
+
return watchWithFilter(source, cb, {
|
|
2023
|
+
...watchOptions,
|
|
2024
|
+
eventFilter: throttleFilter(throttle, trailing, leading)
|
|
2025
|
+
});
|
|
2026
|
+
}
|
|
2027
|
+
/** @deprecated use `watchThrottled` instead */
|
|
2028
|
+
const throttledWatch = watchThrottled;
|
|
2029
2029
|
|
|
2030
2030
|
//#endregion
|
|
2031
2031
|
//#region watchTriggerable/index.ts
|
|
2032
|
-
function watchTriggerable(source, cb, options = {}) {
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
}
|
|
2062
|
-
function getWatchSources(sources) {
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
}
|
|
2067
|
-
function getOldValue(source) {
|
|
2068
|
-
|
|
2069
|
-
}
|
|
2032
|
+
function watchTriggerable(source, cb, options = {}) {
|
|
2033
|
+
let cleanupFn;
|
|
2034
|
+
function onEffect() {
|
|
2035
|
+
if (!cleanupFn) return;
|
|
2036
|
+
const fn = cleanupFn;
|
|
2037
|
+
cleanupFn = void 0;
|
|
2038
|
+
fn();
|
|
2039
|
+
}
|
|
2040
|
+
/** Register the function `cleanupFn` */
|
|
2041
|
+
function onCleanup(callback) {
|
|
2042
|
+
cleanupFn = callback;
|
|
2043
|
+
}
|
|
2044
|
+
const _cb = (value, oldValue) => {
|
|
2045
|
+
onEffect();
|
|
2046
|
+
return cb(value, oldValue, onCleanup);
|
|
2047
|
+
};
|
|
2048
|
+
const res = watchIgnorable(source, _cb, options);
|
|
2049
|
+
const { ignoreUpdates } = res;
|
|
2050
|
+
const trigger = () => {
|
|
2051
|
+
let res$1;
|
|
2052
|
+
ignoreUpdates(() => {
|
|
2053
|
+
res$1 = _cb(getWatchSources(source), getOldValue(source));
|
|
2054
|
+
});
|
|
2055
|
+
return res$1;
|
|
2056
|
+
};
|
|
2057
|
+
return {
|
|
2058
|
+
...res,
|
|
2059
|
+
trigger
|
|
2060
|
+
};
|
|
2061
|
+
}
|
|
2062
|
+
function getWatchSources(sources) {
|
|
2063
|
+
if ((0, vue.isReactive)(sources)) return sources;
|
|
2064
|
+
if (Array.isArray(sources)) return sources.map((item) => (0, vue.toValue)(item));
|
|
2065
|
+
return (0, vue.toValue)(sources);
|
|
2066
|
+
}
|
|
2067
|
+
function getOldValue(source) {
|
|
2068
|
+
return Array.isArray(source) ? source.map(() => void 0) : void 0;
|
|
2069
|
+
}
|
|
2070
2070
|
|
|
2071
2071
|
//#endregion
|
|
2072
2072
|
//#region whenever/index.ts
|
|
2073
2073
|
/**
|
|
2074
|
-
* Shorthand for watching value to be truthy
|
|
2075
|
-
*
|
|
2076
|
-
* @see https://vueuse.org/whenever
|
|
2077
|
-
*/
|
|
2078
|
-
function whenever(source, cb, options) {
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
}
|
|
2074
|
+
* Shorthand for watching value to be truthy
|
|
2075
|
+
*
|
|
2076
|
+
* @see https://vueuse.org/whenever
|
|
2077
|
+
*/
|
|
2078
|
+
function whenever(source, cb, options) {
|
|
2079
|
+
const stop = (0, vue.watch)(source, (v, ov, onInvalidate) => {
|
|
2080
|
+
if (v) {
|
|
2081
|
+
if (options === null || options === void 0 ? void 0 : options.once) (0, vue.nextTick)(() => stop());
|
|
2082
|
+
cb(v, ov, onInvalidate);
|
|
2083
|
+
}
|
|
2084
|
+
}, {
|
|
2085
|
+
...options,
|
|
2086
|
+
once: false
|
|
2087
|
+
});
|
|
2088
|
+
return stop;
|
|
2089
|
+
}
|
|
2090
2090
|
|
|
2091
2091
|
//#endregion
|
|
2092
2092
|
exports.assert = assert;
|