bits-ui 1.0.0-next.84 → 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.
@@ -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
- $effect(() => {
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 (!this.#initialLoad.isIOS) {
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
- const content = e.clipboardData.getData("text/plain");
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) + sanitizedContent + initNewVal.slice(end)
355
- : initNewVal.slice(0, start) + sanitizedContent + initNewVal.slice(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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bits-ui",
3
- "version": "1.0.0-next.84",
3
+ "version": "1.0.0-next.85",
4
4
  "license": "MIT",
5
5
  "repository": "github:huntabyte/bits-ui",
6
6
  "funding": "https://github.com/sponsors/huntabyte",