@povio/ui 3.2.4-rc.1 → 3.2.4-rc.2

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.
@@ -8,7 +8,7 @@ import { DateTimeUtils } from "../../../../utils/date-time.utils.js";
8
8
  import { DateField } from "./DateField.js";
9
9
  import { datePickerInputContentRowDefinition } from "./datePickerInput.cva.js";
10
10
  import { renderDatePickerTodayIcon } from "./datePickerTodayIcon.js";
11
- import { usePreserveExternalFocusOnUnmount } from "./usePreserveExternalFocusOnUnmount.js";
11
+ import { useFirefoxDateSegmentSelectionGuard } from "./useFirefoxDateSegmentSelectionGuard.js";
12
12
  import { InputClear } from "../../shared/InputClear.js";
13
13
  import { c } from "react/compiler-runtime";
14
14
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
@@ -59,7 +59,7 @@ var DatePickerInput = (t0) => {
59
59
  const dateFieldRef = useRef(null);
60
60
  const endDateFieldRef = useRef(null);
61
61
  const containerRef = useRef(null);
62
- usePreserveExternalFocusOnUnmount(containerRef);
62
+ useFirefoxDateSegmentSelectionGuard(containerRef);
63
63
  const t8 = isValueControlled ? fieldValue ?? null : fieldProps.value ?? null;
64
64
  let t9;
65
65
  if ($[4] !== autoFixYear || $[5] !== fieldProps || $[6] !== t8) {
@@ -4,7 +4,7 @@ import { UIConfig } from "../../../../config/uiConfig.context.js";
4
4
  import { InlineIconButton } from "../../../buttons/InlineIconButton/InlineIconButton.js";
5
5
  import { FormFieldLabel } from "../../FormField/FormFieldLabel.js";
6
6
  import { inputBaseDefinition, inputSizeDefinition } from "../../shared/input.cva.js";
7
- import { usePreserveExternalFocusOnUnmount } from "./usePreserveExternalFocusOnUnmount.js";
7
+ import { useFirefoxDateSegmentSelectionGuard } from "./useFirefoxDateSegmentSelectionGuard.js";
8
8
  import { InputClear } from "../../shared/InputClear.js";
9
9
  import { TimeField } from "./TimeField.js";
10
10
  import { c } from "react/compiler-runtime";
@@ -37,7 +37,7 @@ var TimePickerInput = (t0) => {
37
37
  const { focusWithinProps } = useFocusWithin(t2);
38
38
  const { isFocusVisible } = useFocusVisible();
39
39
  const containerRef = useRef(null);
40
- usePreserveExternalFocusOnUnmount(containerRef);
40
+ useFirefoxDateSegmentSelectionGuard(containerRef);
41
41
  const hidePlaceholder = as === "floating" && !state.value && !isFocused;
42
42
  let t3;
43
43
  if ($[3] !== state.segments) {
@@ -0,0 +1,2 @@
1
+ import { RefObject } from 'react';
2
+ export declare const useFirefoxDateSegmentSelectionGuard: (containerRef: RefObject<HTMLElement | null>) => void;
@@ -0,0 +1,33 @@
1
+ import { c } from "react/compiler-runtime";
2
+ import { useLayoutEffect } from "react";
3
+ import { isFirefox } from "@react-aria/utils";
4
+ //#region src/components/inputs/DateTime/shared/useFirefoxDateSegmentSelectionGuard.ts
5
+ var isEditableElement = (element) => element instanceof HTMLElement && (element.matches("input, textarea") || element.isContentEditable);
6
+ var useFirefoxDateSegmentSelectionGuard = (containerRef) => {
7
+ const $ = c(3);
8
+ let t0;
9
+ let t1;
10
+ if ($[0] !== containerRef) {
11
+ t0 = () => {
12
+ const container = containerRef.current;
13
+ if (!container || !isFirefox()) return;
14
+ const onSelectionChange = (event) => {
15
+ const activeElement = document.activeElement;
16
+ const selection = window.getSelection();
17
+ if (isEditableElement(activeElement) && !container.contains(activeElement) && selection?.anchorNode && container.contains(selection.anchorNode)) event.stopImmediatePropagation();
18
+ };
19
+ document.addEventListener("selectionchange", onSelectionChange, true);
20
+ return () => document.removeEventListener("selectionchange", onSelectionChange, true);
21
+ };
22
+ t1 = [containerRef];
23
+ $[0] = containerRef;
24
+ $[1] = t0;
25
+ $[2] = t1;
26
+ } else {
27
+ t0 = $[1];
28
+ t1 = $[2];
29
+ }
30
+ useLayoutEffect(t0, t1);
31
+ };
32
+ //#endregion
33
+ export { useFirefoxDateSegmentSelectionGuard };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@povio/ui",
3
- "version": "3.2.4-rc.1",
3
+ "version": "3.2.4-rc.2",
4
4
  "type": "module",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,2 +0,0 @@
1
- import { RefObject } from 'react';
2
- export declare const usePreserveExternalFocusOnUnmount: (containerRef: RefObject<HTMLElement | null>) => void;
@@ -1,32 +0,0 @@
1
- import { c } from "react/compiler-runtime";
2
- import { useLayoutEffect } from "react";
3
- //#region src/components/inputs/DateTime/shared/usePreserveExternalFocusOnUnmount.ts
4
- var usePreserveExternalFocusOnUnmount = (containerRef) => {
5
- const $ = c(3);
6
- let t0;
7
- let t1;
8
- if ($[0] !== containerRef) {
9
- t0 = () => {
10
- const container = containerRef.current;
11
- return () => {
12
- const activeElement = document.activeElement;
13
- if (!(activeElement instanceof HTMLElement) || activeElement === document.body || container?.contains(activeElement)) return;
14
- requestAnimationFrame(() => {
15
- const nextActiveElement = document.activeElement;
16
- const dateInputReclaimedFocus = Boolean(nextActiveElement instanceof HTMLElement && nextActiveElement.closest("[data-datetime-input]"));
17
- if (activeElement.isConnected && (nextActiveElement === document.body || dateInputReclaimedFocus) && nextActiveElement !== activeElement) activeElement.focus({ preventScroll: true });
18
- });
19
- };
20
- };
21
- t1 = [containerRef];
22
- $[0] = containerRef;
23
- $[1] = t0;
24
- $[2] = t1;
25
- } else {
26
- t0 = $[1];
27
- t1 = $[2];
28
- }
29
- useLayoutEffect(t0, t1);
30
- };
31
- //#endregion
32
- export { usePreserveExternalFocusOnUnmount };