@varlet/use 2.20.2 → 2.20.3-alpha.1703057787821
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/lib/index.cjs +483 -0
- package/lib/index.d.cts +89 -0
- package/package.json +13 -4
package/lib/index.cjs
ADDED
|
@@ -0,0 +1,483 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __spreadValues = (a, b) => {
|
|
10
|
+
for (var prop in b || (b = {}))
|
|
11
|
+
if (__hasOwnProp.call(b, prop))
|
|
12
|
+
__defNormalProp(a, prop, b[prop]);
|
|
13
|
+
if (__getOwnPropSymbols)
|
|
14
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
+
if (__propIsEnum.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
}
|
|
18
|
+
return a;
|
|
19
|
+
};
|
|
20
|
+
var __objRest = (source, exclude) => {
|
|
21
|
+
var target = {};
|
|
22
|
+
for (var prop in source)
|
|
23
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
+
target[prop] = source[prop];
|
|
25
|
+
if (source != null && __getOwnPropSymbols)
|
|
26
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
31
|
+
};
|
|
32
|
+
var __export = (target, all) => {
|
|
33
|
+
for (var name in all)
|
|
34
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
35
|
+
};
|
|
36
|
+
var __copyProps = (to, from, except, desc) => {
|
|
37
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
38
|
+
for (let key of __getOwnPropNames(from))
|
|
39
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
40
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
41
|
+
}
|
|
42
|
+
return to;
|
|
43
|
+
};
|
|
44
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
45
|
+
|
|
46
|
+
// src/index.ts
|
|
47
|
+
var src_exports = {};
|
|
48
|
+
__export(src_exports, {
|
|
49
|
+
keyInProvides: () => keyInProvides,
|
|
50
|
+
onSmartMounted: () => onSmartMounted,
|
|
51
|
+
onSmartUnmounted: () => onSmartUnmounted,
|
|
52
|
+
onWindowResize: () => onWindowResize,
|
|
53
|
+
useChildren: () => useChildren,
|
|
54
|
+
useClickOutside: () => useClickOutside,
|
|
55
|
+
useEventListener: () => useEventListener,
|
|
56
|
+
useId: () => useId,
|
|
57
|
+
useInitialized: () => useInitialized,
|
|
58
|
+
useParent: () => useParent,
|
|
59
|
+
useTouch: () => useTouch,
|
|
60
|
+
useVModel: () => useVModel,
|
|
61
|
+
useWindowSize: () => useWindowSize
|
|
62
|
+
});
|
|
63
|
+
module.exports = __toCommonJS(src_exports);
|
|
64
|
+
|
|
65
|
+
// src/useEventListener.ts
|
|
66
|
+
var import_shared = require("@varlet/shared");
|
|
67
|
+
var import_vue2 = require("vue");
|
|
68
|
+
|
|
69
|
+
// src/onSmartMounted.ts
|
|
70
|
+
var import_vue = require("vue");
|
|
71
|
+
function onSmartMounted(hook) {
|
|
72
|
+
let isMounted = false;
|
|
73
|
+
(0, import_vue.onMounted)(() => {
|
|
74
|
+
hook();
|
|
75
|
+
(0, import_vue.nextTick)(() => {
|
|
76
|
+
isMounted = true;
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
(0, import_vue.onActivated)(() => {
|
|
80
|
+
if (!isMounted) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
hook();
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// src/useEventListener.ts
|
|
88
|
+
function useEventListener(target, type, listener, options = {}) {
|
|
89
|
+
if (!(0, import_shared.inBrowser)()) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const { passive = false, capture = false } = options;
|
|
93
|
+
let listening = false;
|
|
94
|
+
let cleaned = false;
|
|
95
|
+
const getElement = (target2) => (0, import_shared.isFunction)(target2) ? target2() : (0, import_vue2.unref)(target2);
|
|
96
|
+
const add = (target2) => {
|
|
97
|
+
if (listening || cleaned) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const element = getElement(target2);
|
|
101
|
+
if (element) {
|
|
102
|
+
element.addEventListener(type, listener, {
|
|
103
|
+
passive,
|
|
104
|
+
capture
|
|
105
|
+
});
|
|
106
|
+
listening = true;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
const remove = (target2) => {
|
|
110
|
+
if (!listening || cleaned) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const element = getElement(target2);
|
|
114
|
+
if (element) {
|
|
115
|
+
element.removeEventListener(type, listener, {
|
|
116
|
+
capture
|
|
117
|
+
});
|
|
118
|
+
listening = false;
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
let watchStopHandle;
|
|
122
|
+
if ((0, import_vue2.isRef)(target)) {
|
|
123
|
+
watchStopHandle = (0, import_vue2.watch)(
|
|
124
|
+
() => target.value,
|
|
125
|
+
(newValue, oldValue) => {
|
|
126
|
+
remove(oldValue);
|
|
127
|
+
add(newValue);
|
|
128
|
+
}
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
const cleanup = () => {
|
|
132
|
+
watchStopHandle == null ? void 0 : watchStopHandle();
|
|
133
|
+
remove(target);
|
|
134
|
+
cleaned = true;
|
|
135
|
+
};
|
|
136
|
+
onSmartMounted(() => {
|
|
137
|
+
add(target);
|
|
138
|
+
});
|
|
139
|
+
(0, import_vue2.onBeforeUnmount)(() => {
|
|
140
|
+
remove(target);
|
|
141
|
+
});
|
|
142
|
+
(0, import_vue2.onDeactivated)(() => {
|
|
143
|
+
remove(target);
|
|
144
|
+
});
|
|
145
|
+
return cleanup;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// src/useClickOutside.ts
|
|
149
|
+
var import_shared2 = require("@varlet/shared");
|
|
150
|
+
var import_vue3 = require("vue");
|
|
151
|
+
function useClickOutside(target, type, listener) {
|
|
152
|
+
if (!(0, import_shared2.inBrowser)()) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
const handler = (event) => {
|
|
156
|
+
const element = (0, import_shared2.isFunction)(target) ? target() : (0, import_vue3.unref)(target);
|
|
157
|
+
if (element && !element.contains(event.target)) {
|
|
158
|
+
listener(event);
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
useEventListener(document, type, handler);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// src/onSmartUnmounted.ts
|
|
165
|
+
var import_vue4 = require("vue");
|
|
166
|
+
function onSmartUnmounted(hook) {
|
|
167
|
+
(0, import_vue4.onUnmounted)(() => {
|
|
168
|
+
hook();
|
|
169
|
+
});
|
|
170
|
+
(0, import_vue4.onDeactivated)(() => {
|
|
171
|
+
hook();
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// src/useParent.ts
|
|
176
|
+
var import_vue5 = require("vue");
|
|
177
|
+
function keyInProvides(key) {
|
|
178
|
+
const instance = (0, import_vue5.getCurrentInstance)();
|
|
179
|
+
return key in instance.provides;
|
|
180
|
+
}
|
|
181
|
+
function useParent(key) {
|
|
182
|
+
if (!keyInProvides(key)) {
|
|
183
|
+
return {
|
|
184
|
+
index: null,
|
|
185
|
+
parentProvider: null,
|
|
186
|
+
bindParent: null
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
const provider = (0, import_vue5.inject)(key);
|
|
190
|
+
const _a = provider, { childInstances, collect, clear } = _a, parentProvider = __objRest(_a, ["childInstances", "collect", "clear"]);
|
|
191
|
+
const childInstance = (0, import_vue5.getCurrentInstance)();
|
|
192
|
+
const index = (0, import_vue5.computed)(() => childInstances.indexOf(childInstance));
|
|
193
|
+
const bindParent = (childProvider) => {
|
|
194
|
+
(0, import_vue5.onMounted)(() => {
|
|
195
|
+
(0, import_vue5.nextTick)().then(() => {
|
|
196
|
+
collect(childInstance, childProvider);
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
(0, import_vue5.onBeforeUnmount)(() => {
|
|
200
|
+
(0, import_vue5.nextTick)().then(() => {
|
|
201
|
+
clear(childInstance, childProvider);
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
};
|
|
205
|
+
return {
|
|
206
|
+
index,
|
|
207
|
+
parentProvider,
|
|
208
|
+
bindParent
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// src/useChildren.ts
|
|
213
|
+
var import_shared3 = require("@varlet/shared");
|
|
214
|
+
var import_vue6 = require("vue");
|
|
215
|
+
function flatVNodes(subTree) {
|
|
216
|
+
const vNodes = [];
|
|
217
|
+
const flat = (subTree2) => {
|
|
218
|
+
if (subTree2 == null ? void 0 : subTree2.component) {
|
|
219
|
+
flat(subTree2 == null ? void 0 : subTree2.component.subTree);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
if (Array.isArray(subTree2 == null ? void 0 : subTree2.children)) {
|
|
223
|
+
subTree2.children.forEach((child) => {
|
|
224
|
+
if ((0, import_vue6.isVNode)(child)) {
|
|
225
|
+
vNodes.push(child);
|
|
226
|
+
flat(child);
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
flat(subTree);
|
|
232
|
+
return vNodes;
|
|
233
|
+
}
|
|
234
|
+
function useChildren(key) {
|
|
235
|
+
const parentInstance = (0, import_vue6.getCurrentInstance)();
|
|
236
|
+
const childInstances = (0, import_vue6.reactive)([]);
|
|
237
|
+
const childProviders = [];
|
|
238
|
+
const length = (0, import_vue6.computed)(() => childInstances.length);
|
|
239
|
+
const sortInstances = () => {
|
|
240
|
+
const vNodes = flatVNodes(parentInstance.subTree);
|
|
241
|
+
childInstances.sort((a, b) => vNodes.indexOf(a.vnode) - vNodes.indexOf(b.vnode));
|
|
242
|
+
};
|
|
243
|
+
const collect = (childInstance, childProvider) => {
|
|
244
|
+
childInstances.push(childInstance);
|
|
245
|
+
childProviders.push(childProvider);
|
|
246
|
+
sortInstances();
|
|
247
|
+
};
|
|
248
|
+
const clear = (childInstance, childProvider) => {
|
|
249
|
+
(0, import_shared3.removeItem)(childInstances, childInstance);
|
|
250
|
+
(0, import_shared3.removeItem)(childProviders, childProvider);
|
|
251
|
+
};
|
|
252
|
+
const bindChildren = (parentProvider) => {
|
|
253
|
+
(0, import_vue6.provide)(key, __spreadValues({
|
|
254
|
+
childInstances,
|
|
255
|
+
collect,
|
|
256
|
+
clear
|
|
257
|
+
}, parentProvider));
|
|
258
|
+
};
|
|
259
|
+
return {
|
|
260
|
+
length,
|
|
261
|
+
childProviders,
|
|
262
|
+
bindChildren
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// src/onWindowResize.ts
|
|
267
|
+
function onWindowResize(listener) {
|
|
268
|
+
useEventListener(() => window, "resize", listener, { passive: true });
|
|
269
|
+
useEventListener(() => window, "orientationchange", listener, { passive: true });
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// src/useInitialized.ts
|
|
273
|
+
var import_vue7 = require("vue");
|
|
274
|
+
function useInitialized(source, value) {
|
|
275
|
+
const initialized = (0, import_vue7.ref)(false);
|
|
276
|
+
(0, import_vue7.watch)(
|
|
277
|
+
source,
|
|
278
|
+
(newValue) => {
|
|
279
|
+
if (value === newValue) {
|
|
280
|
+
initialized.value = true;
|
|
281
|
+
}
|
|
282
|
+
},
|
|
283
|
+
{ immediate: true }
|
|
284
|
+
);
|
|
285
|
+
return initialized;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// src/useTouch.ts
|
|
289
|
+
var import_vue8 = require("vue");
|
|
290
|
+
var import_shared4 = require("@varlet/shared");
|
|
291
|
+
function getDirection(x, y) {
|
|
292
|
+
if (x > y) {
|
|
293
|
+
return "horizontal";
|
|
294
|
+
}
|
|
295
|
+
if (y > x) {
|
|
296
|
+
return "vertical";
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
function useTouch() {
|
|
300
|
+
const startX = (0, import_vue8.ref)(0);
|
|
301
|
+
const startY = (0, import_vue8.ref)(0);
|
|
302
|
+
const deltaX = (0, import_vue8.ref)(0);
|
|
303
|
+
const deltaY = (0, import_vue8.ref)(0);
|
|
304
|
+
const offsetX = (0, import_vue8.ref)(0);
|
|
305
|
+
const offsetY = (0, import_vue8.ref)(0);
|
|
306
|
+
const prevX = (0, import_vue8.ref)(0);
|
|
307
|
+
const prevY = (0, import_vue8.ref)(0);
|
|
308
|
+
const moveX = (0, import_vue8.ref)(0);
|
|
309
|
+
const moveY = (0, import_vue8.ref)(0);
|
|
310
|
+
const direction = (0, import_vue8.ref)();
|
|
311
|
+
const touching = (0, import_vue8.ref)(false);
|
|
312
|
+
const dragging = (0, import_vue8.ref)(false);
|
|
313
|
+
const startTime = (0, import_vue8.ref)(0);
|
|
314
|
+
const distance = (0, import_vue8.ref)(0);
|
|
315
|
+
let draggingAnimationFrame = null;
|
|
316
|
+
const resetTouch = () => {
|
|
317
|
+
startX.value = 0;
|
|
318
|
+
startY.value = 0;
|
|
319
|
+
deltaX.value = 0;
|
|
320
|
+
deltaY.value = 0;
|
|
321
|
+
offsetX.value = 0;
|
|
322
|
+
offsetY.value = 0;
|
|
323
|
+
prevX.value = 0;
|
|
324
|
+
prevY.value = 0;
|
|
325
|
+
moveX.value = 0;
|
|
326
|
+
moveY.value = 0;
|
|
327
|
+
direction.value = void 0;
|
|
328
|
+
touching.value = false;
|
|
329
|
+
dragging.value = false;
|
|
330
|
+
startTime.value = 0;
|
|
331
|
+
distance.value = 0;
|
|
332
|
+
};
|
|
333
|
+
const startTouch = (event) => {
|
|
334
|
+
resetTouch();
|
|
335
|
+
const { clientX: x, clientY: y } = event.touches[0];
|
|
336
|
+
startX.value = x;
|
|
337
|
+
startY.value = y;
|
|
338
|
+
prevX.value = x;
|
|
339
|
+
prevY.value = y;
|
|
340
|
+
touching.value = true;
|
|
341
|
+
startTime.value = performance.now();
|
|
342
|
+
dragging.value = false;
|
|
343
|
+
if (draggingAnimationFrame) {
|
|
344
|
+
window.cancelAnimationFrame(draggingAnimationFrame);
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
const moveTouch = (event) => {
|
|
348
|
+
const { clientX: x, clientY: y } = event.touches[0];
|
|
349
|
+
dragging.value = true;
|
|
350
|
+
deltaX.value = x - startX.value;
|
|
351
|
+
deltaY.value = y - startY.value;
|
|
352
|
+
offsetX.value = Math.abs(deltaX.value);
|
|
353
|
+
offsetY.value = Math.abs(deltaY.value);
|
|
354
|
+
distance.value = Math.sqrt(offsetX.value ** 2 + offsetY.value ** 2);
|
|
355
|
+
moveX.value = x - prevX.value;
|
|
356
|
+
moveY.value = y - prevY.value;
|
|
357
|
+
if (!direction.value) {
|
|
358
|
+
direction.value = getDirection(offsetX.value, offsetY.value);
|
|
359
|
+
}
|
|
360
|
+
prevX.value = x;
|
|
361
|
+
prevY.value = y;
|
|
362
|
+
};
|
|
363
|
+
const endTouch = () => {
|
|
364
|
+
touching.value = false;
|
|
365
|
+
draggingAnimationFrame = window.requestAnimationFrame(() => {
|
|
366
|
+
dragging.value = false;
|
|
367
|
+
});
|
|
368
|
+
};
|
|
369
|
+
const isReachTop = (element) => {
|
|
370
|
+
const scrollTop = (0, import_shared4.getScrollTop)(element);
|
|
371
|
+
return scrollTop === 0 && deltaY.value > 0;
|
|
372
|
+
};
|
|
373
|
+
const isReachBottom = (element, offset = 1) => {
|
|
374
|
+
const { scrollHeight, clientHeight, scrollTop } = element;
|
|
375
|
+
const offsetBottom = Math.abs(scrollHeight - scrollTop - clientHeight);
|
|
376
|
+
return deltaY.value < 0 && offsetBottom <= offset;
|
|
377
|
+
};
|
|
378
|
+
return {
|
|
379
|
+
startX,
|
|
380
|
+
startY,
|
|
381
|
+
deltaX,
|
|
382
|
+
deltaY,
|
|
383
|
+
offsetX,
|
|
384
|
+
offsetY,
|
|
385
|
+
prevX,
|
|
386
|
+
prevY,
|
|
387
|
+
moveX,
|
|
388
|
+
moveY,
|
|
389
|
+
direction,
|
|
390
|
+
touching,
|
|
391
|
+
dragging,
|
|
392
|
+
startTime,
|
|
393
|
+
distance,
|
|
394
|
+
resetTouch,
|
|
395
|
+
startTouch,
|
|
396
|
+
moveTouch,
|
|
397
|
+
endTouch,
|
|
398
|
+
isReachTop,
|
|
399
|
+
isReachBottom
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
// src/useId.ts
|
|
404
|
+
var import_vue9 = require("vue");
|
|
405
|
+
var import_shared5 = require("@varlet/shared");
|
|
406
|
+
function useId() {
|
|
407
|
+
const id = (0, import_vue9.ref)();
|
|
408
|
+
const instance = (0, import_vue9.getCurrentInstance)();
|
|
409
|
+
const name = (0, import_shared5.kebabCase)(instance.type.name);
|
|
410
|
+
id.value = process.env.NODE_ENV === "test" ? `${name}-mock-id` : `${name}-${instance.uid}`;
|
|
411
|
+
return id;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
// src/useWindowSize.ts
|
|
415
|
+
var import_shared6 = require("@varlet/shared");
|
|
416
|
+
var import_vue10 = require("vue");
|
|
417
|
+
function useWindowSize(options = {}) {
|
|
418
|
+
const { initialWidth = 0, initialHeight = 0 } = options;
|
|
419
|
+
const width = (0, import_vue10.ref)(initialWidth);
|
|
420
|
+
const height = (0, import_vue10.ref)(initialHeight);
|
|
421
|
+
const update = () => {
|
|
422
|
+
if (!(0, import_shared6.inBrowser)()) {
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
width.value = window.innerWidth;
|
|
426
|
+
height.value = window.innerHeight;
|
|
427
|
+
};
|
|
428
|
+
onSmartMounted(update);
|
|
429
|
+
onWindowResize(update);
|
|
430
|
+
return {
|
|
431
|
+
width,
|
|
432
|
+
height
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
// src/useVModel.ts
|
|
437
|
+
var import_shared7 = require("@varlet/shared");
|
|
438
|
+
var import_vue11 = require("vue");
|
|
439
|
+
function useVModel(props, key, options = {}) {
|
|
440
|
+
const { passive = true, eventName, defaultValue, emit } = options;
|
|
441
|
+
const event = eventName != null ? eventName : `onUpdate:${key.toString()}`;
|
|
442
|
+
const getValue = () => props[key] != null ? props[key] : defaultValue;
|
|
443
|
+
if (!passive) {
|
|
444
|
+
return (0, import_vue11.computed)({
|
|
445
|
+
get() {
|
|
446
|
+
return getValue();
|
|
447
|
+
},
|
|
448
|
+
set(value) {
|
|
449
|
+
emit ? emit(event, value) : (0, import_shared7.call)(props[event], value);
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
const proxy = (0, import_vue11.ref)(getValue());
|
|
454
|
+
(0, import_vue11.watch)(
|
|
455
|
+
() => props[key],
|
|
456
|
+
() => {
|
|
457
|
+
proxy.value = getValue();
|
|
458
|
+
}
|
|
459
|
+
);
|
|
460
|
+
(0, import_vue11.watch)(
|
|
461
|
+
() => proxy.value,
|
|
462
|
+
(newValue) => {
|
|
463
|
+
emit ? emit(event, newValue) : (0, import_shared7.call)(props[event], newValue);
|
|
464
|
+
}
|
|
465
|
+
);
|
|
466
|
+
return proxy;
|
|
467
|
+
}
|
|
468
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
469
|
+
0 && (module.exports = {
|
|
470
|
+
keyInProvides,
|
|
471
|
+
onSmartMounted,
|
|
472
|
+
onSmartUnmounted,
|
|
473
|
+
onWindowResize,
|
|
474
|
+
useChildren,
|
|
475
|
+
useClickOutside,
|
|
476
|
+
useEventListener,
|
|
477
|
+
useId,
|
|
478
|
+
useInitialized,
|
|
479
|
+
useParent,
|
|
480
|
+
useTouch,
|
|
481
|
+
useVModel,
|
|
482
|
+
useWindowSize
|
|
483
|
+
});
|
package/lib/index.d.cts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import * as vue from 'vue';
|
|
2
|
+
import { Ref, ComponentInternalInstance, ComputedRef, WatchSource, WritableComputedRef } from 'vue';
|
|
3
|
+
|
|
4
|
+
type UseEventListenerTarget = EventTarget | Ref<EventTarget | undefined | null> | (() => EventTarget);
|
|
5
|
+
interface UseEventListenerOptions {
|
|
6
|
+
capture?: boolean;
|
|
7
|
+
passive?: boolean;
|
|
8
|
+
}
|
|
9
|
+
declare function useEventListener<T extends keyof DocumentEventMap>(target: UseEventListenerTarget, type: T, listener: (event: DocumentEventMap[T]) => void, options?: UseEventListenerOptions): () => void;
|
|
10
|
+
declare function useEventListener(target: UseEventListenerTarget, type: string, listener: EventListener, options?: UseEventListenerOptions): () => void;
|
|
11
|
+
|
|
12
|
+
type UseClickOutsideTarget = Element | Ref<Element | undefined | null> | (() => Element);
|
|
13
|
+
declare function useClickOutside(target: UseClickOutsideTarget, type: string, listener: EventListener): void;
|
|
14
|
+
|
|
15
|
+
declare function onSmartMounted(hook: () => void): void;
|
|
16
|
+
|
|
17
|
+
declare function onSmartUnmounted(hook: () => void): void;
|
|
18
|
+
|
|
19
|
+
interface UseChildrenBaseProvider<C> {
|
|
20
|
+
childInstances: ComponentInternalInstance[];
|
|
21
|
+
collect(instance: ComponentInternalInstance, childProvider: C): void;
|
|
22
|
+
clear(instance: ComponentInternalInstance, childProvider: C): void;
|
|
23
|
+
}
|
|
24
|
+
declare function useChildren<P, C>(key: symbol | string): {
|
|
25
|
+
length: ComputedRef<number>;
|
|
26
|
+
childProviders: C[];
|
|
27
|
+
bindChildren: (parentProvider: P) => void;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
declare function keyInProvides(key: symbol | string): boolean;
|
|
31
|
+
declare function useParent<P, C>(key: symbol | string): {
|
|
32
|
+
index: null;
|
|
33
|
+
parentProvider: null;
|
|
34
|
+
bindParent: null;
|
|
35
|
+
} | {
|
|
36
|
+
index: ComputedRef<number>;
|
|
37
|
+
parentProvider: Omit<P & UseChildrenBaseProvider<C>, "childInstances" | "collect" | "clear">;
|
|
38
|
+
bindParent: (childProvider: C) => void;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
declare function onWindowResize(listener: EventListener): void;
|
|
42
|
+
|
|
43
|
+
declare function useInitialized<T>(source: WatchSource<T>, value: T): vue.Ref<boolean>;
|
|
44
|
+
|
|
45
|
+
type TouchDirection = 'horizontal' | 'vertical';
|
|
46
|
+
declare function useTouch(): {
|
|
47
|
+
startX: vue.Ref<number>;
|
|
48
|
+
startY: vue.Ref<number>;
|
|
49
|
+
deltaX: vue.Ref<number>;
|
|
50
|
+
deltaY: vue.Ref<number>;
|
|
51
|
+
offsetX: vue.Ref<number>;
|
|
52
|
+
offsetY: vue.Ref<number>;
|
|
53
|
+
prevX: vue.Ref<number>;
|
|
54
|
+
prevY: vue.Ref<number>;
|
|
55
|
+
moveX: vue.Ref<number>;
|
|
56
|
+
moveY: vue.Ref<number>;
|
|
57
|
+
direction: vue.Ref<TouchDirection | undefined>;
|
|
58
|
+
touching: vue.Ref<boolean>;
|
|
59
|
+
dragging: vue.Ref<boolean>;
|
|
60
|
+
startTime: vue.Ref<number>;
|
|
61
|
+
distance: vue.Ref<number>;
|
|
62
|
+
resetTouch: () => void;
|
|
63
|
+
startTouch: (event: TouchEvent) => void;
|
|
64
|
+
moveTouch: (event: TouchEvent) => void;
|
|
65
|
+
endTouch: () => void;
|
|
66
|
+
isReachTop: (element: Element | Window) => boolean;
|
|
67
|
+
isReachBottom: (element: Element, offset?: number) => boolean;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
declare function useId(): vue.Ref<string | undefined>;
|
|
71
|
+
|
|
72
|
+
interface UseWindowSizeOptions {
|
|
73
|
+
initialWidth?: number;
|
|
74
|
+
initialHeight?: number;
|
|
75
|
+
}
|
|
76
|
+
declare function useWindowSize(options?: UseWindowSizeOptions): {
|
|
77
|
+
width: vue.Ref<number>;
|
|
78
|
+
height: vue.Ref<number>;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
interface UseVModelOptions<P, K extends keyof P> {
|
|
82
|
+
passive?: boolean;
|
|
83
|
+
eventName?: string;
|
|
84
|
+
defaultValue?: P[K];
|
|
85
|
+
emit?: (event: string, value: P[K]) => void;
|
|
86
|
+
}
|
|
87
|
+
declare function useVModel<P extends Record<string, any>, K extends keyof P>(props: P, key: K, options?: UseVModelOptions<P, K>): WritableComputedRef<P[K]> | Ref<P[K]>;
|
|
88
|
+
|
|
89
|
+
export { TouchDirection, UseChildrenBaseProvider, UseClickOutsideTarget, UseEventListenerOptions, UseEventListenerTarget, UseVModelOptions, UseWindowSizeOptions, keyInProvides, onSmartMounted, onSmartUnmounted, onWindowResize, useChildren, useClickOutside, useEventListener, useId, useInitialized, useParent, useTouch, useVModel, useWindowSize };
|
package/package.json
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@varlet/use",
|
|
3
|
-
"version": "2.20.
|
|
3
|
+
"version": "2.20.3-alpha.1703057787821",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"main": "lib/index.
|
|
5
|
+
"main": "lib/index.cjs",
|
|
6
6
|
"module": "lib/index.js",
|
|
7
|
+
"types": "lib/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./lib/index.js",
|
|
11
|
+
"require": "./lib/index.cjs",
|
|
12
|
+
"types": "./lib/index.d.ts"
|
|
13
|
+
},
|
|
14
|
+
"./*": "./*"
|
|
15
|
+
},
|
|
7
16
|
"description": "composable utils of varlet",
|
|
8
17
|
"keywords": [
|
|
9
18
|
"composable",
|
|
@@ -24,7 +33,7 @@
|
|
|
24
33
|
"url": "https://github.com/varletjs/varlet/issues"
|
|
25
34
|
},
|
|
26
35
|
"dependencies": {
|
|
27
|
-
"@varlet/shared": "2.20.
|
|
36
|
+
"@varlet/shared": "2.20.3-alpha.1703057787821"
|
|
28
37
|
},
|
|
29
38
|
"devDependencies": {
|
|
30
39
|
"@types/node": "^18.7.18",
|
|
@@ -37,6 +46,6 @@
|
|
|
37
46
|
},
|
|
38
47
|
"scripts": {
|
|
39
48
|
"dev": "tsup src/index.ts --format esm --out-dir=lib --watch --dts",
|
|
40
|
-
"build": "tsup src/index.ts --format esm --out-dir=lib --dts --clean"
|
|
49
|
+
"build": "tsup src/index.ts --format esm,cjs --out-dir=lib --dts --clean"
|
|
41
50
|
}
|
|
42
51
|
}
|