@adsgency_npm/adsgency-ads-ui 0.1.0-alpha.19 → 0.1.0-alpha.20

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/index.cjs CHANGED
@@ -1924,6 +1924,73 @@ function useNestedDismissableLayerCoordinator() {
1924
1924
  ]
1925
1925
  );
1926
1926
  }
1927
+ function useNestedDismissableLayerParent({
1928
+ onEscapeKeyDown,
1929
+ onFocusOutside,
1930
+ onPointerDownOutside
1931
+ } = {}) {
1932
+ const coordinator = useNestedDismissableLayerCoordinator();
1933
+ const shieldNextFocusOutsideRef = React19.useRef(false);
1934
+ const handlePointerDownOutside = React19.useCallback(
1935
+ (event) => {
1936
+ onPointerDownOutside?.(event);
1937
+ if (event.defaultPrevented) return;
1938
+ const hasActiveNestedLayer = coordinator.hasActiveNestedLayer();
1939
+ const shouldShieldParent = hasActiveNestedLayer || coordinator.hadActiveNestedLayerAtPointerDown();
1940
+ if (!shouldShieldParent) {
1941
+ shieldNextFocusOutsideRef.current = false;
1942
+ return;
1943
+ }
1944
+ shieldNextFocusOutsideRef.current = true;
1945
+ if (hasActiveNestedLayer) {
1946
+ coordinator.dismissTopNestedLayer();
1947
+ }
1948
+ event.preventDefault();
1949
+ },
1950
+ [coordinator, onPointerDownOutside]
1951
+ );
1952
+ const handleFocusOutside = React19.useCallback(
1953
+ (event) => {
1954
+ onFocusOutside?.(event);
1955
+ if (event.defaultPrevented) return;
1956
+ const followsShieldedPointer = shieldNextFocusOutsideRef.current;
1957
+ shieldNextFocusOutsideRef.current = false;
1958
+ if (followsShieldedPointer) {
1959
+ event.preventDefault();
1960
+ return;
1961
+ }
1962
+ if (!coordinator.hasActiveNestedLayer()) return;
1963
+ coordinator.dismissTopNestedLayer();
1964
+ event.preventDefault();
1965
+ },
1966
+ [coordinator, onFocusOutside]
1967
+ );
1968
+ const handleEscapeKeyDown = React19.useCallback(
1969
+ (event) => {
1970
+ onEscapeKeyDown?.(event);
1971
+ if (event.defaultPrevented || !coordinator.hasActiveNestedLayer()) {
1972
+ return;
1973
+ }
1974
+ coordinator.dismissTopNestedLayer();
1975
+ event.preventDefault();
1976
+ },
1977
+ [coordinator, onEscapeKeyDown]
1978
+ );
1979
+ return React19.useMemo(
1980
+ () => ({
1981
+ coordinator,
1982
+ onEscapeKeyDown: handleEscapeKeyDown,
1983
+ onFocusOutside: handleFocusOutside,
1984
+ onPointerDownOutside: handlePointerDownOutside
1985
+ }),
1986
+ [
1987
+ coordinator,
1988
+ handleEscapeKeyDown,
1989
+ handleFocusOutside,
1990
+ handlePointerDownOutside
1991
+ ]
1992
+ );
1993
+ }
1927
1994
  function NestedDismissableLayerProvider({
1928
1995
  children,
1929
1996
  coordinator
@@ -1953,55 +2020,12 @@ var PopoverContentImpl = React20.forwardRef(
1953
2020
  sideOffset = 4,
1954
2021
  ...props
1955
2022
  }, ref) => {
1956
- const coordinator = useNestedDismissableLayerCoordinator();
1957
- const shieldNextFocusOutsideRef = React20.useRef(false);
1958
- const handlePointerDownOutside = React20.useCallback(
1959
- (event) => {
1960
- onPointerDownOutside?.(event);
1961
- if (event.defaultPrevented) return;
1962
- const hasActiveNestedLayer = coordinator.hasActiveNestedLayer();
1963
- const shouldShieldParent = hasActiveNestedLayer || coordinator.hadActiveNestedLayerAtPointerDown();
1964
- if (!shouldShieldParent) {
1965
- shieldNextFocusOutsideRef.current = false;
1966
- return;
1967
- }
1968
- shieldNextFocusOutsideRef.current = true;
1969
- if (hasActiveNestedLayer) {
1970
- coordinator.dismissTopNestedLayer();
1971
- }
1972
- event.preventDefault();
1973
- },
1974
- [coordinator, onPointerDownOutside]
1975
- );
1976
- const handleFocusOutside = React20.useCallback(
1977
- (event) => {
1978
- onFocusOutside?.(event);
1979
- if (event.defaultPrevented) return;
1980
- const followsShieldedPointer = shieldNextFocusOutsideRef.current;
1981
- shieldNextFocusOutsideRef.current = false;
1982
- if (followsShieldedPointer) {
1983
- event.preventDefault();
1984
- return;
1985
- }
1986
- const hasActiveNestedLayer = coordinator.hasActiveNestedLayer();
1987
- if (!hasActiveNestedLayer) return;
1988
- coordinator.dismissTopNestedLayer();
1989
- event.preventDefault();
1990
- },
1991
- [coordinator, onFocusOutside]
1992
- );
1993
- const handleEscapeKeyDown = React20.useCallback(
1994
- (event) => {
1995
- onEscapeKeyDown?.(event);
1996
- if (event.defaultPrevented || !coordinator.hasActiveNestedLayer()) {
1997
- return;
1998
- }
1999
- coordinator.dismissTopNestedLayer();
2000
- event.preventDefault();
2001
- },
2002
- [coordinator, onEscapeKeyDown]
2003
- );
2004
- return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(NestedDismissableLayerProvider, { coordinator, children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
2023
+ const parentLayer = useNestedDismissableLayerParent({
2024
+ onEscapeKeyDown,
2025
+ onFocusOutside,
2026
+ onPointerDownOutside
2027
+ });
2028
+ return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(NestedDismissableLayerProvider, { coordinator: parentLayer.coordinator, children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
2005
2029
  PopoverPrimitive.Content,
2006
2030
  {
2007
2031
  ref,
@@ -2011,9 +2035,9 @@ var PopoverContentImpl = React20.forwardRef(
2011
2035
  "z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-popover-content-transform-origin]",
2012
2036
  className
2013
2037
  ),
2014
- onEscapeKeyDown: handleEscapeKeyDown,
2015
- onFocusOutside: handleFocusOutside,
2016
- onPointerDownOutside: handlePointerDownOutside,
2038
+ onEscapeKeyDown: parentLayer.onEscapeKeyDown,
2039
+ onFocusOutside: parentLayer.onFocusOutside,
2040
+ onPointerDownOutside: parentLayer.onPointerDownOutside,
2017
2041
  ...props
2018
2042
  }
2019
2043
  ) });
@@ -6605,8 +6629,22 @@ var DialogBody = React60.forwardRef(
6605
6629
  );
6606
6630
  DialogBody.displayName = "DialogBody";
6607
6631
  var DialogContent = React60.forwardRef(
6608
- ({ children, className, closeLabel, hideCloseButton = false, ...props }, ref) => {
6632
+ ({
6633
+ children,
6634
+ className,
6635
+ closeLabel,
6636
+ hideCloseButton = false,
6637
+ onEscapeKeyDown,
6638
+ onFocusOutside,
6639
+ onPointerDownOutside,
6640
+ ...props
6641
+ }, ref) => {
6609
6642
  const { messages } = useAdsI18n();
6643
+ const parentLayer = useNestedDismissableLayerParent({
6644
+ onEscapeKeyDown,
6645
+ onFocusOutside,
6646
+ onPointerDownOutside
6647
+ });
6610
6648
  const resolvedCloseLabel = closeLabel ?? messages.dialog.close;
6611
6649
  const childNodes = flattenDialogChildren(children);
6612
6650
  const headerIndex = childNodes.findIndex(
@@ -6635,21 +6673,19 @@ var DialogContent = React60.forwardRef(
6635
6673
  }
6636
6674
  }
6637
6675
  const footerNode = footerIndex >= 0 && footerIndex !== headerIndex ? childNodes[footerIndex] : null;
6638
- const bodyNodes = childNodes.filter(
6639
- (child, index) => {
6640
- if (index === headerIndex || index === footerIndex) {
6641
- return false;
6642
- }
6643
- return !generatedHeaderNodes.includes(child);
6676
+ const bodyNodes = childNodes.filter((child, index) => {
6677
+ if (index === headerIndex || index === footerIndex) {
6678
+ return false;
6644
6679
  }
6645
- );
6680
+ return !generatedHeaderNodes.includes(child);
6681
+ });
6646
6682
  const explicitBodyNodes = bodyNodes.filter(
6647
6683
  (child) => isDialogSlotElement(child, DialogBody)
6648
6684
  );
6649
6685
  const looseBodyNodes = bodyNodes.filter(
6650
6686
  (child) => !isDialogSlotElement(child, DialogBody)
6651
6687
  );
6652
- return /* @__PURE__ */ (0, import_jsx_runtime66.jsxs)(DialogPortal, { children: [
6688
+ return /* @__PURE__ */ (0, import_jsx_runtime66.jsx)(NestedDismissableLayerProvider, { coordinator: parentLayer.coordinator, children: /* @__PURE__ */ (0, import_jsx_runtime66.jsxs)(DialogPortal, { children: [
6653
6689
  /* @__PURE__ */ (0, import_jsx_runtime66.jsx)(DialogOverlay, {}),
6654
6690
  /* @__PURE__ */ (0, import_jsx_runtime66.jsxs)(
6655
6691
  DialogPrimitive.Content,
@@ -6660,6 +6696,9 @@ var DialogContent = React60.forwardRef(
6660
6696
  adsTextColorClassName.card,
6661
6697
  className
6662
6698
  ),
6699
+ onEscapeKeyDown: parentLayer.onEscapeKeyDown,
6700
+ onFocusOutside: parentLayer.onFocusOutside,
6701
+ onPointerDownOutside: parentLayer.onPointerDownOutside,
6663
6702
  ref,
6664
6703
  ...props,
6665
6704
  children: [
@@ -6682,7 +6721,7 @@ var DialogContent = React60.forwardRef(
6682
6721
  ]
6683
6722
  }
6684
6723
  )
6685
- ] });
6724
+ ] }) });
6686
6725
  }
6687
6726
  );
6688
6727
  DialogContent.displayName = "DialogContent";