@mantine-vue/hooks 3.5.0 → 3.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/index.cjs +52 -35
- package/cjs/index.cjs.map +1 -1
- package/esm/index.mjs +52 -35
- package/esm/index.mjs.map +1 -1
- package/lib/use-click-outside/use-click-outside.d.ts +1 -1
- package/package.json +1 -1
package/esm/index.mjs
CHANGED
|
@@ -117,9 +117,10 @@ function useDebouncedCallback(callback, waitOrOptions) {
|
|
|
117
117
|
}
|
|
118
118
|
//#endregion
|
|
119
119
|
//#region src/use-click-outside/use-click-outside.ts
|
|
120
|
-
function useClickOutside(callback, events = ["mousedown", "touchstart"], nodes, enabled = true) {
|
|
120
|
+
function useClickOutside(callback, events = ["mousedown", "touchstart"], nodes, enabled = true, capture = false) {
|
|
121
121
|
const element = ref(null);
|
|
122
122
|
let activeEvents = [];
|
|
123
|
+
let activeCapture = false;
|
|
123
124
|
const listener = (event) => {
|
|
124
125
|
const target = event.target;
|
|
125
126
|
if (!target || !document.body.contains(target) && target.tagName !== "HTML") return;
|
|
@@ -130,17 +131,22 @@ function useClickOutside(callback, events = ["mousedown", "touchstart"], nodes,
|
|
|
130
131
|
} else if (element.value && !path.includes(element.value)) callback(event);
|
|
131
132
|
};
|
|
132
133
|
const cleanup = () => {
|
|
133
|
-
activeEvents.forEach((event) => document.removeEventListener(event, listener));
|
|
134
|
+
activeEvents.forEach((event) => document.removeEventListener(event, listener, activeCapture));
|
|
134
135
|
activeEvents = [];
|
|
135
136
|
};
|
|
136
137
|
const bind = () => {
|
|
137
138
|
cleanup();
|
|
138
139
|
if (!toValue(enabled)) return;
|
|
139
140
|
activeEvents = toValue(events) || ["mousedown", "touchstart"];
|
|
140
|
-
|
|
141
|
+
activeCapture = toValue(capture);
|
|
142
|
+
activeEvents.forEach((event) => document.addEventListener(event, listener, activeCapture));
|
|
141
143
|
};
|
|
142
144
|
onMounted(bind);
|
|
143
|
-
watch([
|
|
145
|
+
watch([
|
|
146
|
+
() => toValue(events)?.join(","),
|
|
147
|
+
() => toValue(enabled),
|
|
148
|
+
() => toValue(capture)
|
|
149
|
+
], bind);
|
|
144
150
|
onBeforeUnmount(cleanup);
|
|
145
151
|
return element;
|
|
146
152
|
}
|
|
@@ -184,7 +190,11 @@ function useClipboard({ timeout = 2e3 } = {}) {
|
|
|
184
190
|
//#region src/use-media-query/use-media-query.ts
|
|
185
191
|
function getInitialMediaQueryValue(query, initialValue) {
|
|
186
192
|
if (typeof initialValue === "boolean") return initialValue;
|
|
187
|
-
if (typeof window !== "undefined" && typeof window.matchMedia === "function")
|
|
193
|
+
if (typeof window !== "undefined" && typeof window.matchMedia === "function") try {
|
|
194
|
+
return window.matchMedia(query).matches;
|
|
195
|
+
} catch {
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
188
198
|
return false;
|
|
189
199
|
}
|
|
190
200
|
function useMediaQuery(query, initialValue = false, options = { getInitialValueInEffect: true }) {
|
|
@@ -254,6 +264,10 @@ function useDebouncedState(initialValue, wait, options = {}) {
|
|
|
254
264
|
if (options.leading && !leadingCalled) {
|
|
255
265
|
value.value = next;
|
|
256
266
|
leadingCalled = true;
|
|
267
|
+
clear();
|
|
268
|
+
timeout = setTimeout(() => {
|
|
269
|
+
leadingCalled = false;
|
|
270
|
+
}, wait);
|
|
257
271
|
} else {
|
|
258
272
|
clear();
|
|
259
273
|
timeout = setTimeout(() => {
|
|
@@ -1025,7 +1039,7 @@ function usePagination({ total, siblings = 1, boundaries = 1, page, initialPage,
|
|
|
1025
1039
|
const leftSiblingIndex = Math.max(active.value - siblings, start.value + boundaries - 1);
|
|
1026
1040
|
const rightSiblingIndex = Math.min(active.value + siblings, end.value - boundaries);
|
|
1027
1041
|
const shouldShowLeftDots = leftSiblingIndex > start.value + boundaries + 1;
|
|
1028
|
-
const shouldShowRightDots = rightSiblingIndex < end.value - boundaries;
|
|
1042
|
+
const shouldShowRightDots = rightSiblingIndex < end.value - (boundaries + 1);
|
|
1029
1043
|
if (!shouldShowLeftDots && shouldShowRightDots) {
|
|
1030
1044
|
const leftItemCount = siblings * 2 + boundaries + 2;
|
|
1031
1045
|
return [
|
|
@@ -1431,8 +1445,8 @@ function useIntersection(options) {
|
|
|
1431
1445
|
entry.value = null;
|
|
1432
1446
|
return;
|
|
1433
1447
|
}
|
|
1434
|
-
observer = new IntersectionObserver((
|
|
1435
|
-
entry.value =
|
|
1448
|
+
observer = new IntersectionObserver((entries) => {
|
|
1449
|
+
entry.value = entries[entries.length - 1];
|
|
1436
1450
|
}, options);
|
|
1437
1451
|
observer.observe(node);
|
|
1438
1452
|
}, { immediate: true });
|
|
@@ -1535,12 +1549,10 @@ function getHotkeyMatcher(hotkey, usePhysicalKeys) {
|
|
|
1535
1549
|
}
|
|
1536
1550
|
function getHotkeyHandler(hotkeys) {
|
|
1537
1551
|
return (event) => {
|
|
1538
|
-
hotkeys.forEach(([hotkey, handler, options
|
|
1539
|
-
preventDefault
|
|
1540
|
-
usePhysicalKeys
|
|
1541
|
-
|
|
1542
|
-
if (getHotkeyMatcher(hotkey, options.usePhysicalKeys)(event)) {
|
|
1543
|
-
if (options.preventDefault) event.preventDefault();
|
|
1552
|
+
hotkeys.forEach(([hotkey, handler, options]) => {
|
|
1553
|
+
const { preventDefault = true, usePhysicalKeys = false } = options || {};
|
|
1554
|
+
if (getHotkeyMatcher(hotkey, usePhysicalKeys)(event)) {
|
|
1555
|
+
if (preventDefault) event.preventDefault();
|
|
1544
1556
|
handler(event);
|
|
1545
1557
|
}
|
|
1546
1558
|
});
|
|
@@ -1571,16 +1583,14 @@ function useHotkeys(hotkeys, tagsToIgnore = [
|
|
|
1571
1583
|
"select"
|
|
1572
1584
|
], triggerOnContentEditable = false) {
|
|
1573
1585
|
const handleKeydown = (event) => {
|
|
1574
|
-
toValue(hotkeys).forEach(([hotkey, handler, options
|
|
1575
|
-
preventDefault
|
|
1576
|
-
usePhysicalKeys
|
|
1577
|
-
}]) => {
|
|
1578
|
-
if (getHotkeyMatcher(hotkey, options.usePhysicalKeys)(event) && shouldFireEvent(event, toValue(tagsToIgnore) ?? [
|
|
1586
|
+
toValue(hotkeys).forEach(([hotkey, handler, options]) => {
|
|
1587
|
+
const { preventDefault = true, usePhysicalKeys = false } = options || {};
|
|
1588
|
+
if (getHotkeyMatcher(hotkey, usePhysicalKeys)(event) && shouldFireEvent(event, toValue(tagsToIgnore) ?? [
|
|
1579
1589
|
"input",
|
|
1580
1590
|
"textarea",
|
|
1581
1591
|
"select"
|
|
1582
1592
|
], toValue(triggerOnContentEditable))) {
|
|
1583
|
-
if (
|
|
1593
|
+
if (preventDefault) event.preventDefault();
|
|
1584
1594
|
handler(event);
|
|
1585
1595
|
}
|
|
1586
1596
|
});
|
|
@@ -2278,7 +2288,13 @@ function useThrottledCallbackWithClearTimeout(callback, wait) {
|
|
|
2278
2288
|
let latestOutArgs = null;
|
|
2279
2289
|
let active = true;
|
|
2280
2290
|
let timeoutId = -1;
|
|
2281
|
-
const clear = () =>
|
|
2291
|
+
const clear = () => {
|
|
2292
|
+
window.clearTimeout(timeoutId);
|
|
2293
|
+
timeoutId = -1;
|
|
2294
|
+
active = true;
|
|
2295
|
+
latestInArgs = null;
|
|
2296
|
+
latestOutArgs = null;
|
|
2297
|
+
};
|
|
2282
2298
|
const callThrottledCallback = (...args) => {
|
|
2283
2299
|
callback(...args);
|
|
2284
2300
|
latestInArgs = args;
|
|
@@ -3300,7 +3316,7 @@ function findPrevTokenIndex(slots, from) {
|
|
|
3300
3316
|
for (let i = from; i >= 0; i--) if (slots[i].type === "token") return i;
|
|
3301
3317
|
return -1;
|
|
3302
3318
|
}
|
|
3303
|
-
function processInput(inputValue, slots, _slotCharOption) {
|
|
3319
|
+
function processInput(inputValue, slots, _slotCharOption, transform) {
|
|
3304
3320
|
let result = "";
|
|
3305
3321
|
let inputIndex = 0;
|
|
3306
3322
|
for (let slotIndex = 0; slotIndex < slots.length && inputIndex <= inputValue.length; slotIndex++) {
|
|
@@ -3312,7 +3328,7 @@ function processInput(inputValue, slots, _slotCharOption) {
|
|
|
3312
3328
|
}
|
|
3313
3329
|
if (inputIndex >= inputValue.length) break;
|
|
3314
3330
|
while (inputIndex < inputValue.length) {
|
|
3315
|
-
const ch = inputValue[inputIndex];
|
|
3331
|
+
const ch = transform ? transform(inputValue[inputIndex]) : inputValue[inputIndex];
|
|
3316
3332
|
inputIndex++;
|
|
3317
3333
|
if (slot.pattern.test(ch)) {
|
|
3318
3334
|
result += ch;
|
|
@@ -3434,8 +3450,8 @@ function useMask(options) {
|
|
|
3434
3450
|
const initializeInputValue = (inputNode) => {
|
|
3435
3451
|
if (!inputNode.value) return false;
|
|
3436
3452
|
const isOwnValue = inputNode.value === display;
|
|
3437
|
-
const
|
|
3438
|
-
const
|
|
3453
|
+
const { slots: initialSlots, slotChar: initialSlotChar, transform } = getResolvedOptions(options, "");
|
|
3454
|
+
const parse = (slots, slotChar) => isOwnValue ? applyMaskToRaw(rawInternal, slots, slotChar, options.transform) : processInput(inputNode.value, slots, slotChar, transform);
|
|
3439
3455
|
const { slots: resolvedSlots, slotChar } = getResolvedOptions(options, extractRaw(parse(initialSlots, initialSlotChar), initialSlots));
|
|
3440
3456
|
const reprocessed = parse(resolvedSlots, slotChar);
|
|
3441
3457
|
const newRaw = extractRaw(reprocessed, resolvedSlots);
|
|
@@ -3780,6 +3796,13 @@ function findLastEnabled(total, isItemDisabled) {
|
|
|
3780
3796
|
for (let i = total - 1; i >= 0; i -= 1) if (!isItemDisabled(i)) return i;
|
|
3781
3797
|
return 0;
|
|
3782
3798
|
}
|
|
3799
|
+
function findEnabledInRow(row, startCol, step, columns, total, isItemDisabled) {
|
|
3800
|
+
for (let col = startCol; col >= 0 && col < columns; col += step) {
|
|
3801
|
+
const candidate = row * columns + col;
|
|
3802
|
+
if (candidate < total && !isItemDisabled(candidate)) return candidate;
|
|
3803
|
+
}
|
|
3804
|
+
return null;
|
|
3805
|
+
}
|
|
3783
3806
|
var defaultIsItemDisabled = () => false;
|
|
3784
3807
|
function useRovingIndex(input) {
|
|
3785
3808
|
const { total, orientation = "horizontal", loop = true, dir = "ltr", activateOnFocus = false, columns, focusedIndex, initialIndex, onFocusChange, isItemDisabled = defaultIsItemDisabled } = input;
|
|
@@ -3818,19 +3841,13 @@ function useRovingIndex(input) {
|
|
|
3818
3841
|
const isRtl = dir === "rtl";
|
|
3819
3842
|
switch (event.key) {
|
|
3820
3843
|
case "ArrowRight": {
|
|
3821
|
-
const
|
|
3822
|
-
|
|
3823
|
-
const candidate = row * cols + targetCol;
|
|
3824
|
-
if (!isItemDisabled(candidate)) nextIndex = candidate;
|
|
3825
|
-
}
|
|
3844
|
+
const step = isRtl ? -1 : 1;
|
|
3845
|
+
nextIndex = findEnabledInRow(row, col + step, step, cols, total_, isItemDisabled);
|
|
3826
3846
|
break;
|
|
3827
3847
|
}
|
|
3828
3848
|
case "ArrowLeft": {
|
|
3829
|
-
const
|
|
3830
|
-
|
|
3831
|
-
const candidate = row * cols + targetCol;
|
|
3832
|
-
if (!isItemDisabled(candidate)) nextIndex = candidate;
|
|
3833
|
-
}
|
|
3849
|
+
const step = isRtl ? 1 : -1;
|
|
3850
|
+
nextIndex = findEnabledInRow(row, col + step, step, cols, total_, isItemDisabled);
|
|
3834
3851
|
break;
|
|
3835
3852
|
}
|
|
3836
3853
|
case "ArrowDown":
|