bits-ui 1.0.0-next.83 → 1.0.0-next.85
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/bits/pin-input/pin-input.svelte.js +9 -25
- package/dist/bits/pin-input/usePasswordManager.svelte.js +0 -15
- package/dist/bits/range-calendar/range-calendar.svelte.js +6 -12
- package/dist/bits/utilities/dismissible-layer/use-dismissable-layer.svelte.js +4 -1
- package/dist/internal/dom.d.ts +6 -0
- package/dist/internal/dom.js +10 -0
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Previous } from "runed";
|
|
1
|
+
import { Previous, watch } from "runed";
|
|
2
2
|
import { untrack } from "svelte";
|
|
3
3
|
import { box, useRefById } from "svelte-toolbelt";
|
|
4
4
|
import { usePasswordManagerBadge } from "./usePasswordManager.svelte.js";
|
|
@@ -130,9 +130,7 @@ class PinInputRootState {
|
|
|
130
130
|
};
|
|
131
131
|
});
|
|
132
132
|
});
|
|
133
|
-
|
|
134
|
-
this.value.current;
|
|
135
|
-
this.#inputRef.current;
|
|
133
|
+
watch([() => this.value.current, () => this.#inputRef.current], () => {
|
|
136
134
|
syncTimeouts(() => {
|
|
137
135
|
const input = this.#inputRef.current;
|
|
138
136
|
if (!input)
|
|
@@ -324,35 +322,21 @@ class PinInputRootState {
|
|
|
324
322
|
};
|
|
325
323
|
onpaste = (e) => {
|
|
326
324
|
const input = this.#inputRef.current;
|
|
327
|
-
if (!
|
|
328
|
-
if (!e.clipboardData || !input)
|
|
329
|
-
return;
|
|
330
|
-
const content = e.clipboardData.getData("text/plain");
|
|
331
|
-
const sanitizedContent = this.#onPaste?.current?.(content) ?? content;
|
|
332
|
-
if (sanitizedContent.length > 0 &&
|
|
333
|
-
this.#regexPattern &&
|
|
334
|
-
!this.#regexPattern.test(sanitizedContent)) {
|
|
335
|
-
e.preventDefault();
|
|
336
|
-
return;
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
if (!this.#initialLoad.isIOS || !e.clipboardData || !input)
|
|
325
|
+
if (!input)
|
|
340
326
|
return;
|
|
341
|
-
|
|
342
|
-
e.preventDefault();
|
|
343
|
-
const sanitizedContent = this.#onPaste?.current?.(content) ?? content;
|
|
344
|
-
if (sanitizedContent.length > 0 &&
|
|
345
|
-
this.#regexPattern &&
|
|
346
|
-
!this.#regexPattern.test(sanitizedContent)) {
|
|
327
|
+
if (!this.#onPaste?.current && (!this.#initialLoad.isIOS || !e.clipboardData || !input)) {
|
|
347
328
|
return;
|
|
348
329
|
}
|
|
330
|
+
const _content = e.clipboardData?.getData("text/plain") ?? "";
|
|
331
|
+
const content = this.#onPaste?.current ? this.#onPaste.current(_content) : _content;
|
|
332
|
+
e.preventDefault();
|
|
349
333
|
const start = input.selectionStart === null ? undefined : input.selectionStart;
|
|
350
334
|
const end = input.selectionEnd === null ? undefined : input.selectionEnd;
|
|
351
335
|
const isReplacing = start !== end;
|
|
352
336
|
const initNewVal = this.value.current;
|
|
353
337
|
const newValueUncapped = isReplacing
|
|
354
|
-
? initNewVal.slice(0, start) +
|
|
355
|
-
: initNewVal.slice(0, start) +
|
|
338
|
+
? initNewVal.slice(0, start) + content + initNewVal.slice(end)
|
|
339
|
+
: initNewVal.slice(0, start) + content + initNewVal.slice(start);
|
|
356
340
|
const newValue = newValueUncapped.slice(0, this.#maxLength.current);
|
|
357
341
|
if (newValue.length > 0 && this.#regexPattern && !this.#regexPattern.test(newValue)) {
|
|
358
342
|
return;
|
|
@@ -8,10 +8,6 @@ const PASSWORD_MANAGER_SELECTORS = [
|
|
|
8
8
|
'[style$="2147483647 !important;"]', // Bitwarden
|
|
9
9
|
].join(",");
|
|
10
10
|
export function usePasswordManagerBadge({ containerRef, inputRef, pushPasswordManagerStrategy, isFocused, }) {
|
|
11
|
-
let pwmMetadata = $state({
|
|
12
|
-
done: false,
|
|
13
|
-
refocused: false,
|
|
14
|
-
});
|
|
15
11
|
let hasPwmBadge = $state(false);
|
|
16
12
|
let hasPwmBadgeSpace = $state(false);
|
|
17
13
|
let done = $state(false);
|
|
@@ -47,17 +43,6 @@ export function usePasswordManagerBadge({ containerRef, inputRef, pushPasswordMa
|
|
|
47
43
|
}
|
|
48
44
|
hasPwmBadge = true;
|
|
49
45
|
done = true;
|
|
50
|
-
// for specific PWMs the input has to be re-focused
|
|
51
|
-
// to trigger a reposition of the badge
|
|
52
|
-
if (!pwmMetadata.refocused && document.activeElement === input) {
|
|
53
|
-
const selections = [input.selectionStart ?? 0, input.selectionEnd ?? 0];
|
|
54
|
-
input.blur();
|
|
55
|
-
input.focus();
|
|
56
|
-
input.focus();
|
|
57
|
-
// recover the previous selection
|
|
58
|
-
input.setSelectionRange(selections[0], selections[1]);
|
|
59
|
-
pwmMetadata.refocused = true;
|
|
60
|
-
}
|
|
61
46
|
}
|
|
62
47
|
$effect(() => {
|
|
63
48
|
const container = containerRef.current;
|
|
@@ -37,7 +37,7 @@ export class RangeCalendarRootState {
|
|
|
37
37
|
formatter;
|
|
38
38
|
accessibleHeadingId = useId();
|
|
39
39
|
focusedValue = $state(undefined);
|
|
40
|
-
lastPressedDateValue =
|
|
40
|
+
lastPressedDateValue = undefined;
|
|
41
41
|
constructor(props) {
|
|
42
42
|
this.value = props.value;
|
|
43
43
|
this.placeholder = props.placeholder;
|
|
@@ -309,19 +309,13 @@ export class RangeCalendarRootState {
|
|
|
309
309
|
const isStartBeforeFocused = isBefore(this.startValue.current, this.focusedValue);
|
|
310
310
|
const start = isStartBeforeFocused ? this.startValue.current : this.focusedValue;
|
|
311
311
|
const end = isStartBeforeFocused ? this.focusedValue : this.startValue.current;
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
end,
|
|
316
|
-
};
|
|
312
|
+
const range = { start, end };
|
|
313
|
+
if (isSameDay(start.add({ days: 1 }), end) || isSameDay(start, end)) {
|
|
314
|
+
return range;
|
|
317
315
|
}
|
|
318
316
|
const isValid = areAllDaysBetweenValid(start, end, this.isDateUnavailable, this.isDateDisabled);
|
|
319
|
-
if (isValid)
|
|
320
|
-
return
|
|
321
|
-
start,
|
|
322
|
-
end,
|
|
323
|
-
};
|
|
324
|
-
}
|
|
317
|
+
if (isValid)
|
|
318
|
+
return range;
|
|
325
319
|
return null;
|
|
326
320
|
});
|
|
327
321
|
shiftFocus(node, add) {
|
|
@@ -7,6 +7,7 @@ import { debounce } from "../../../internal/debounce.js";
|
|
|
7
7
|
import { noop } from "../../../internal/noop.js";
|
|
8
8
|
import { getOwnerDocument, isOrContainsTarget } from "../../../internal/elements.js";
|
|
9
9
|
import { isElement } from "../../../internal/is.js";
|
|
10
|
+
import { isClickTrulyOutside } from "../../../internal/dom.js";
|
|
10
11
|
globalThis.bitsDismissableLayers ??= new Map();
|
|
11
12
|
export class DismissibleLayerState {
|
|
12
13
|
#interactOutsideProp;
|
|
@@ -200,7 +201,9 @@ function isValidEvent(e, node) {
|
|
|
200
201
|
if (!isElement(target))
|
|
201
202
|
return false;
|
|
202
203
|
const ownerDocument = getOwnerDocument(target);
|
|
203
|
-
const isValid = ownerDocument.documentElement.contains(target) &&
|
|
204
|
+
const isValid = ownerDocument.documentElement.contains(target) &&
|
|
205
|
+
!isOrContainsTarget(node, target) &&
|
|
206
|
+
isClickTrulyOutside(e, node);
|
|
204
207
|
return isValid;
|
|
205
208
|
}
|
|
206
209
|
function createWrappedEvent(e) {
|
package/dist/internal/dom.d.ts
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
1
|
export declare function getFirstNonCommentChild(element: HTMLElement | null): ChildNode | null;
|
|
2
|
+
/**
|
|
3
|
+
* Determines if the click event truly occurred outside the content node.
|
|
4
|
+
* This was added to handle password managers and other elements that may be injected
|
|
5
|
+
* into the DOM but visually appear inside the content.
|
|
6
|
+
*/
|
|
7
|
+
export declare function isClickTrulyOutside(event: PointerEvent, contentNode: HTMLElement): boolean;
|
package/dist/internal/dom.js
CHANGED
|
@@ -8,3 +8,13 @@ export function getFirstNonCommentChild(element) {
|
|
|
8
8
|
}
|
|
9
9
|
return null;
|
|
10
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Determines if the click event truly occurred outside the content node.
|
|
13
|
+
* This was added to handle password managers and other elements that may be injected
|
|
14
|
+
* into the DOM but visually appear inside the content.
|
|
15
|
+
*/
|
|
16
|
+
export function isClickTrulyOutside(event, contentNode) {
|
|
17
|
+
const { clientX, clientY } = event;
|
|
18
|
+
const rect = contentNode.getBoundingClientRect();
|
|
19
|
+
return (clientX < rect.left || clientX > rect.right || clientY < rect.top || clientY > rect.bottom);
|
|
20
|
+
}
|