@activecollab/components 2.0.528 → 2.0.530

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.
Files changed (39) hide show
  1. package/dist/cjs/components/ConfirmDialog/ConfirmDialog.js +1 -1
  2. package/dist/cjs/components/ConfirmDialog/ConfirmDialog.js.map +1 -1
  3. package/dist/cjs/components/GlobalPortal/GlobalPortal.js +10 -4
  4. package/dist/cjs/components/GlobalPortal/GlobalPortal.js.map +1 -1
  5. package/dist/cjs/components/ModalRoot/ModalRoot.js +5 -4
  6. package/dist/cjs/components/ModalRoot/ModalRoot.js.map +1 -1
  7. package/dist/cjs/components/ModalRoot/modalRootStack.js +21 -13
  8. package/dist/cjs/components/ModalRoot/modalRootStack.js.map +1 -1
  9. package/dist/cjs/components/ModalRoot/useModalStackHost.js +43 -5
  10. package/dist/cjs/components/ModalRoot/useModalStackHost.js.map +1 -1
  11. package/dist/cjs/components/Window/Window.js +9 -1
  12. package/dist/cjs/components/Window/Window.js.map +1 -1
  13. package/dist/esm/components/ConfirmDialog/ConfirmDialog.d.ts +1 -1
  14. package/dist/esm/components/ConfirmDialog/ConfirmDialog.d.ts.map +1 -1
  15. package/dist/esm/components/ConfirmDialog/ConfirmDialog.js +1 -1
  16. package/dist/esm/components/ConfirmDialog/ConfirmDialog.js.map +1 -1
  17. package/dist/esm/components/GlobalPortal/GlobalPortal.d.ts +6 -4
  18. package/dist/esm/components/GlobalPortal/GlobalPortal.d.ts.map +1 -1
  19. package/dist/esm/components/GlobalPortal/GlobalPortal.js +9 -4
  20. package/dist/esm/components/GlobalPortal/GlobalPortal.js.map +1 -1
  21. package/dist/esm/components/ModalRoot/ModalRoot.d.ts.map +1 -1
  22. package/dist/esm/components/ModalRoot/ModalRoot.js +5 -4
  23. package/dist/esm/components/ModalRoot/ModalRoot.js.map +1 -1
  24. package/dist/esm/components/ModalRoot/modalRootStack.d.ts +8 -4
  25. package/dist/esm/components/ModalRoot/modalRootStack.d.ts.map +1 -1
  26. package/dist/esm/components/ModalRoot/modalRootStack.js +15 -11
  27. package/dist/esm/components/ModalRoot/modalRootStack.js.map +1 -1
  28. package/dist/esm/components/ModalRoot/useModalStackHost.d.ts +4 -2
  29. package/dist/esm/components/ModalRoot/useModalStackHost.d.ts.map +1 -1
  30. package/dist/esm/components/ModalRoot/useModalStackHost.js +36 -5
  31. package/dist/esm/components/ModalRoot/useModalStackHost.js.map +1 -1
  32. package/dist/esm/components/Window/Window.d.ts.map +1 -1
  33. package/dist/esm/components/Window/Window.js +9 -1
  34. package/dist/esm/components/Window/Window.js.map +1 -1
  35. package/dist/index.js +86 -27
  36. package/dist/index.js.map +1 -1
  37. package/dist/index.min.js +1 -1
  38. package/dist/index.min.js.map +1 -1
  39. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"ConfirmDialog.d.ts","sourceRoot":"","sources":["../../../../src/components/ConfirmDialog/ConfirmDialog.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAuD,MAAM,OAAO,CAAC;AAQ5E,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAK9C,MAAM,WAAW,kBAAkB;IACjC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAChC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oFAAoF;IACpF,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,eAAO,MAAM,aAAa,2FAiHzB,CAAC"}
1
+ {"version":3,"file":"ConfirmDialog.d.ts","sourceRoot":"","sources":["../../../../src/components/ConfirmDialog/ConfirmDialog.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAuD,MAAM,OAAO,CAAC;AAQ5E,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAK9C,MAAM,WAAW,kBAAkB;IACjC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAChC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oHAAoH;IACpH,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,eAAO,MAAM,aAAa,2FAiHzB,CAAC"}
@@ -28,7 +28,7 @@ export const ConfirmDialog = /*#__PURE__*/forwardRef((_ref, ref) => {
28
28
  size = _ref.size,
29
29
  height = _ref.height,
30
30
  _ref$native = _ref.native,
31
- native = _ref$native === void 0 ? false : _ref$native;
31
+ native = _ref$native === void 0 ? true : _ref$native;
32
32
  const _useState = useState(false),
33
33
  confirmed = _useState[0],
34
34
  setConfirmed = _useState[1];
@@ -1 +1 @@
1
- {"version":3,"file":"ConfirmDialog.js","names":["React","forwardRef","useCallback","useEffect","useState","classnames","Button","Checkbox","Dialog","StyledConfirmation","Body2","CONFIRMATION_CHECKBOX_ID","ConfirmDialog","_ref","ref","_ref$open","open","onCancel","onConfirm","className","_ref$dialogTitle","dialogTitle","_ref$dialogContent","dialogContent","_ref$confirmBtnText","confirmBtnText","_ref$cancelBtnText","cancelBtnText","_ref$shouldShowCancel","shouldShowCancelButton","_ref$isLoading","isLoading","confirmationLabel","size","height","_ref$native","native","_useState","confirmed","setConfirmed","isConfirmBlocked","Boolean","handleToggleConfirmed","event","target","checked","handleKeyDown","key","preventDefault","window","addEventListener","removeEventListener","createElement","onClose","disableCloseOnEsc","role","undefined","Title","ContentDivider","Content","lineHeight","color","whitespace","id","onChange","disabled","htmlFor","Actions","variant","onClick","type","displayName"],"sources":["../../../../src/components/ConfirmDialog/ConfirmDialog.tsx"],"sourcesContent":["import React, { forwardRef, useCallback, useEffect, useState } from \"react\";\n\nimport classnames from \"classnames\";\n\nimport { Button } from \"../Button/Button\";\nimport { Checkbox } from \"../Checkbox\";\nimport { Dialog } from \"../Dialog\";\nimport { StyledConfirmation } from \"./Styles\";\nimport { DialogSize } from \"../Dialog/Styles\";\nimport { Body2 } from \"../Typography/Variants/Body2\";\n\nconst CONFIRMATION_CHECKBOX_ID = \"confirm-dialog-confirmation\";\n\nexport interface ConfirmDialogProps {\n open?: boolean;\n onCancel?: () => void;\n onConfirm?: () => void;\n className?: string;\n dialogTitle?: string;\n dialogContent?: React.ReactNode;\n confirmBtnText?: string;\n cancelBtnText?: string;\n shouldShowCancelButton?: boolean;\n isLoading?: boolean;\n confirmationLabel?: string;\n size?: DialogSize;\n height?: string;\n /** Opens as a native modal alert dialog. Temporary opt-in, like Dialog's native. */\n native?: boolean;\n}\n\nexport const ConfirmDialog = forwardRef<HTMLDivElement, ConfirmDialogProps>(\n (\n {\n open = false,\n onCancel,\n onConfirm,\n className,\n dialogTitle = \"Discard changes?\",\n dialogContent = \"All unsaved changes will be lost.\",\n confirmBtnText = \"OK\",\n cancelBtnText = \"Cancel\",\n shouldShowCancelButton = true,\n isLoading = false,\n confirmationLabel,\n size,\n height,\n native = false,\n },\n ref\n ) => {\n const [confirmed, setConfirmed] = useState(false);\n const isConfirmBlocked = Boolean(confirmationLabel) && !confirmed;\n\n const handleToggleConfirmed = useCallback(\n (event: React.ChangeEvent<HTMLInputElement>) =>\n setConfirmed(event.target.checked),\n []\n );\n\n useEffect(() => {\n if (!open) {\n setConfirmed(false);\n }\n }, [open]);\n\n useEffect(() => {\n const handleKeyDown = (event: KeyboardEvent) => {\n if (\n event.key === \"Enter\" &&\n onConfirm &&\n !isConfirmBlocked &&\n !isLoading\n ) {\n event.preventDefault();\n onConfirm();\n }\n };\n\n if (open) {\n window.addEventListener(\"keydown\", handleKeyDown);\n }\n\n return () => {\n window.removeEventListener(\"keydown\", handleKeyDown);\n };\n }, [open, onConfirm, isConfirmBlocked, isLoading]);\n\n return (\n <Dialog\n ref={ref}\n open={open}\n onClose={onCancel}\n className={classnames(\"c-confirm-dialog\", className)}\n disableCloseOnEsc={isLoading}\n size={size}\n height={height}\n native={native}\n role={native ? \"alertdialog\" : undefined}\n >\n <Dialog.Title>{dialogTitle}</Dialog.Title>\n <Dialog.ContentDivider />\n <Dialog.Content>\n <Body2 lineHeight=\"loose\" color=\"secondary\" whitespace=\"pre-line\">\n {dialogContent}\n </Body2>\n {confirmationLabel ? (\n <StyledConfirmation className=\"c-confirm-dialog--confirmation\">\n <Checkbox\n id={CONFIRMATION_CHECKBOX_ID}\n checked={confirmed}\n onChange={handleToggleConfirmed}\n disabled={isLoading}\n />\n <label htmlFor={CONFIRMATION_CHECKBOX_ID}>\n <Body2 color=\"secondary\">{confirmationLabel}</Body2>\n </label>\n </StyledConfirmation>\n ) : null}\n </Dialog.Content>\n <Dialog.ContentDivider />\n <Dialog.Actions>\n <Button\n variant=\"primary\"\n onClick={onConfirm}\n disabled={isLoading || isConfirmBlocked}\n >\n {confirmBtnText}\n </Button>\n {shouldShowCancelButton ? (\n <Button\n variant=\"secondary\"\n data-action=\"cancel\"\n onClick={onCancel}\n type=\"button\"\n disabled={isLoading}\n >\n {cancelBtnText}\n </Button>\n ) : null}\n </Dialog.Actions>\n </Dialog>\n );\n }\n);\n\nConfirmDialog.displayName = \"ConfirmDialog\";\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,UAAU,EAAEC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAE3E,OAAOC,UAAU,MAAM,YAAY;AAEnC,SAASC,MAAM,QAAQ,kBAAkB;AACzC,SAASC,QAAQ,QAAQ,aAAa;AACtC,SAASC,MAAM,QAAQ,WAAW;AAClC,SAASC,kBAAkB,QAAQ,UAAU;AAE7C,SAASC,KAAK,QAAQ,8BAA8B;AAEpD,MAAMC,wBAAwB,GAAG,6BAA6B;AAoB9D,OAAO,MAAMC,aAAa,gBAAGX,UAAU,CACrC,CAAAY,IAAA,EAiBEC,GAAG,KACA;EAAA,IAAAC,SAAA,GAAAF,IAAA,CAhBDG,IAAI;IAAJA,IAAI,GAAAD,SAAA,cAAG,KAAK,GAAAA,SAAA;IACZE,QAAQ,GAAAJ,IAAA,CAARI,QAAQ;IACRC,SAAS,GAAAL,IAAA,CAATK,SAAS;IACTC,SAAS,GAAAN,IAAA,CAATM,SAAS;IAAAC,gBAAA,GAAAP,IAAA,CACTQ,WAAW;IAAXA,WAAW,GAAAD,gBAAA,cAAG,kBAAkB,GAAAA,gBAAA;IAAAE,kBAAA,GAAAT,IAAA,CAChCU,aAAa;IAAbA,aAAa,GAAAD,kBAAA,cAAG,mCAAmC,GAAAA,kBAAA;IAAAE,mBAAA,GAAAX,IAAA,CACnDY,cAAc;IAAdA,cAAc,GAAAD,mBAAA,cAAG,IAAI,GAAAA,mBAAA;IAAAE,kBAAA,GAAAb,IAAA,CACrBc,aAAa;IAAbA,aAAa,GAAAD,kBAAA,cAAG,QAAQ,GAAAA,kBAAA;IAAAE,qBAAA,GAAAf,IAAA,CACxBgB,sBAAsB;IAAtBA,sBAAsB,GAAAD,qBAAA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C5C,MAAM,CAACkD,cAAc,MAAE,CAAC,eACzB1D,KAAA,CAAAoD,aAAA,CAAC5C,MAAM,CAAC2D,OAAO,qBACbnE,KAAA,CAAAoD,aAAA,CAAC9C,MAAM;IACL8D,OAAO,EAAC,SAAS;IACjBC,OAAO,EAAEnD,SAAU;IACnB+C,QAAQ,EAAElC,SAAS,IAAIS;EAAiB,GAEvCf,cACK,CAAC,EACRI,sBAAsB,gBACrB7B,KAAA,CAAAoD,aAAA,CAAC9C,MAAM;IACL8D,OAAO,EAAC,WAAW;IACnB,eAAY,QAAQ;IACpBC,OAAO,EAAEpD,QAAS;IAClBqD,IAAI,EAAC,QAAQ;IACbL,QAAQ,EAAElC;EAAU,GAEnBJ,aACK,CAAC,GACP,IACU,CACV,CAAC;AAEb,CACF,CAAC;AAEDf,aAAa,CAAC2D,WAAW,GAAG,eAAe","ignoreList":[]}
1
+ {"version":3,"file":"ConfirmDialog.js","names":["React","forwardRef","useCallback","useEffect","useState","classnames","Button","Checkbox","Dialog","StyledConfirmation","Body2","CONFIRMATION_CHECKBOX_ID","ConfirmDialog","_ref","ref","_ref$open","open","onCancel","onConfirm","className","_ref$dialogTitle","dialogTitle","_ref$dialogContent","dialogContent","_ref$confirmBtnText","confirmBtnText","_ref$cancelBtnText","cancelBtnText","_ref$shouldShowCancel","shouldShowCancelButton","_ref$isLoading","isLoading","confirmationLabel","size","height","_ref$native","native","_useState","confirmed","setConfirmed","isConfirmBlocked","Boolean","handleToggleConfirmed","event","target","checked","handleKeyDown","key","preventDefault","window","addEventListener","removeEventListener","createElement","onClose","disableCloseOnEsc","role","undefined","Title","ContentDivider","Content","lineHeight","color","whitespace","id","onChange","disabled","htmlFor","Actions","variant","onClick","type","displayName"],"sources":["../../../../src/components/ConfirmDialog/ConfirmDialog.tsx"],"sourcesContent":["import React, { forwardRef, useCallback, useEffect, useState } from \"react\";\n\nimport classnames from \"classnames\";\n\nimport { Button } from \"../Button/Button\";\nimport { Checkbox } from \"../Checkbox\";\nimport { Dialog } from \"../Dialog\";\nimport { StyledConfirmation } from \"./Styles\";\nimport { DialogSize } from \"../Dialog/Styles\";\nimport { Body2 } from \"../Typography/Variants/Body2\";\n\nconst CONFIRMATION_CHECKBOX_ID = \"confirm-dialog-confirmation\";\n\nexport interface ConfirmDialogProps {\n open?: boolean;\n onCancel?: () => void;\n onConfirm?: () => void;\n className?: string;\n dialogTitle?: string;\n dialogContent?: React.ReactNode;\n confirmBtnText?: string;\n cancelBtnText?: string;\n shouldShowCancelButton?: boolean;\n isLoading?: boolean;\n confirmationLabel?: string;\n size?: DialogSize;\n height?: string;\n /** Opens as a native modal alert dialog, the default. false keeps the legacy dialog until every screen is moved. */\n native?: boolean;\n}\n\nexport const ConfirmDialog = forwardRef<HTMLDivElement, ConfirmDialogProps>(\n (\n {\n open = false,\n onCancel,\n onConfirm,\n className,\n dialogTitle = \"Discard changes?\",\n dialogContent = \"All unsaved changes will be lost.\",\n confirmBtnText = \"OK\",\n cancelBtnText = \"Cancel\",\n shouldShowCancelButton = true,\n isLoading = false,\n confirmationLabel,\n size,\n height,\n native = true,\n },\n ref\n ) => {\n const [confirmed, setConfirmed] = useState(false);\n const isConfirmBlocked = Boolean(confirmationLabel) && !confirmed;\n\n const handleToggleConfirmed = useCallback(\n (event: React.ChangeEvent<HTMLInputElement>) =>\n setConfirmed(event.target.checked),\n []\n );\n\n useEffect(() => {\n if (!open) {\n setConfirmed(false);\n }\n }, [open]);\n\n useEffect(() => {\n const handleKeyDown = (event: KeyboardEvent) => {\n if (\n event.key === \"Enter\" &&\n onConfirm &&\n !isConfirmBlocked &&\n !isLoading\n ) {\n event.preventDefault();\n onConfirm();\n }\n };\n\n if (open) {\n window.addEventListener(\"keydown\", handleKeyDown);\n }\n\n return () => {\n window.removeEventListener(\"keydown\", handleKeyDown);\n };\n }, [open, onConfirm, isConfirmBlocked, isLoading]);\n\n return (\n <Dialog\n ref={ref}\n open={open}\n onClose={onCancel}\n className={classnames(\"c-confirm-dialog\", className)}\n disableCloseOnEsc={isLoading}\n size={size}\n height={height}\n native={native}\n role={native ? \"alertdialog\" : undefined}\n >\n <Dialog.Title>{dialogTitle}</Dialog.Title>\n <Dialog.ContentDivider />\n <Dialog.Content>\n <Body2 lineHeight=\"loose\" color=\"secondary\" whitespace=\"pre-line\">\n {dialogContent}\n </Body2>\n {confirmationLabel ? (\n <StyledConfirmation className=\"c-confirm-dialog--confirmation\">\n <Checkbox\n id={CONFIRMATION_CHECKBOX_ID}\n checked={confirmed}\n onChange={handleToggleConfirmed}\n disabled={isLoading}\n />\n <label htmlFor={CONFIRMATION_CHECKBOX_ID}>\n <Body2 color=\"secondary\">{confirmationLabel}</Body2>\n </label>\n </StyledConfirmation>\n ) : null}\n </Dialog.Content>\n <Dialog.ContentDivider />\n <Dialog.Actions>\n <Button\n variant=\"primary\"\n onClick={onConfirm}\n disabled={isLoading || isConfirmBlocked}\n >\n {confirmBtnText}\n </Button>\n {shouldShowCancelButton ? (\n <Button\n variant=\"secondary\"\n data-action=\"cancel\"\n onClick={onCancel}\n type=\"button\"\n disabled={isLoading}\n >\n {cancelBtnText}\n </Button>\n ) : null}\n </Dialog.Actions>\n </Dialog>\n );\n }\n);\n\nConfirmDialog.displayName = \"ConfirmDialog\";\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,UAAU,EAAEC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAE3E,OAAOC,UAAU,MAAM,YAAY;AAEnC,SAASC,MAAM,QAAQ,kBAAkB;AACzC,SAASC,QAAQ,QAAQ,aAAa;AACtC,SAASC,MAAM,QAAQ,WAAW;AAClC,SAASC,kBAAkB,QAAQ,UAAU;AAE7C,SAASC,KAAK,QAAQ,8BAA8B;AAEpD,MAAMC,wBAAwB,GAAG,6BAA6B;AAoB9D,OAAO,MAAMC,aAAa,gBAAGX,UAAU,CACrC,CAAAY,IAAA,EAiBEC,GAAG,KACA;EAAA,IAAAC,SAAA,GAAAF,IAAA,CAhBDG,IAA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WithChildren } from "react";
2
2
  /**
3
- * Renders content that must stay above every modal, such as toasts. Everything outside an open native modal is inert,
4
- * so the content follows the top open modal into its overlay root and comes back to document.body once none is open.
3
+ * Renders content that must stay above every modal, such as toasts, a chat or a feedback prompt. Everything outside
4
+ * an open native modal is inert, so the content follows the top open modal into its overlay root and comes back to
5
+ * document.body once none is open.
5
6
  * The host node moves instead of the content being portalled again, so the content never remounts on the way.
7
+ * Portals from the content, such as a menu or a tooltip, render into the host too, so they move along with it.
6
8
  * The host is attached in a layout effect after the content mounts, so content that measures itself on mount reads
7
9
  * no size there, and a transition that runs while the host moves restarts.
8
10
  */
9
11
  export declare const GlobalPortal: {
10
- ({ children }: PropsWithChildren): import("react").ReactPortal;
12
+ ({ children }: PropsWithChildren): React.ReactPortal;
11
13
  displayName: string;
12
14
  };
13
15
  //# sourceMappingURL=GlobalPortal.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"GlobalPortal.d.ts","sourceRoot":"","sources":["../../../../src/components/GlobalPortal/GlobalPortal.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAY,MAAM,OAAO,CAAC;AAYpD;;;;;;GAMG;AACH,eAAO,MAAM,YAAY;mBAAkB,iBAAiB;;CAM3D,CAAC"}
1
+ {"version":3,"file":"GlobalPortal.d.ts","sourceRoot":"","sources":["../../../../src/components/GlobalPortal/GlobalPortal.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,iBAAiB,EAAY,MAAM,OAAO,CAAC;AAa3D;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY;mBAAkB,iBAAiB;;CAS3D,CAAC"}
@@ -1,5 +1,6 @@
1
- import { useState } from "react";
1
+ import React, { useState } from "react";
2
2
  import ReactDOM from "react-dom";
3
+ import { PortalContainerProvider } from "../../helpers";
3
4
  import { useModalStackHost } from "../ModalRoot/useModalStackHost";
4
5
  const createHost = () => {
5
6
  const host = document.createElement("div");
@@ -8,9 +9,11 @@ const createHost = () => {
8
9
  };
9
10
 
10
11
  /**
11
- * Renders content that must stay above every modal, such as toasts. Everything outside an open native modal is inert,
12
- * so the content follows the top open modal into its overlay root and comes back to document.body once none is open.
12
+ * Renders content that must stay above every modal, such as toasts, a chat or a feedback prompt. Everything outside
13
+ * an open native modal is inert, so the content follows the top open modal into its overlay root and comes back to
14
+ * document.body once none is open.
13
15
  * The host node moves instead of the content being portalled again, so the content never remounts on the way.
16
+ * Portals from the content, such as a menu or a tooltip, render into the host too, so they move along with it.
14
17
  * The host is attached in a layout effect after the content mounts, so content that measures itself on mount reads
15
18
  * no size there, and a transition that runs while the host moves restarts.
16
19
  */
@@ -19,7 +22,9 @@ export const GlobalPortal = _ref => {
19
22
  const _useState = useState(createHost),
20
23
  host = _useState[0];
21
24
  useModalStackHost(host);
22
- return /*#__PURE__*/ReactDOM.createPortal(children, host);
25
+ return /*#__PURE__*/ReactDOM.createPortal(/*#__PURE__*/React.createElement(PortalContainerProvider, {
26
+ value: host
27
+ }, children), host);
23
28
  };
24
29
  GlobalPortal.displayName = "GlobalPortal";
25
30
  //# sourceMappingURL=GlobalPortal.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"GlobalPortal.js","names":["useState","ReactDOM","useModalStackHost","createHost","host","document","createElement","className","GlobalPortal","_ref","children","_useState","createPortal","displayName"],"sources":["../../../../src/components/GlobalPortal/GlobalPortal.tsx"],"sourcesContent":["import { PropsWithChildren, useState } from \"react\";\nimport ReactDOM from \"react-dom\";\n\nimport { useModalStackHost } from \"../ModalRoot/useModalStackHost\";\n\nconst createHost = () => {\n const host = document.createElement(\"div\");\n host.className = \"c-global-portal\";\n\n return host;\n};\n\n/**\n * Renders content that must stay above every modal, such as toasts. Everything outside an open native modal is inert,\n * so the content follows the top open modal into its overlay root and comes back to document.body once none is open.\n * The host node moves instead of the content being portalled again, so the content never remounts on the way.\n * The host is attached in a layout effect after the content mounts, so content that measures itself on mount reads\n * no size there, and a transition that runs while the host moves restarts.\n */\nexport const GlobalPortal = ({ children }: PropsWithChildren) => {\n const [host] = useState(createHost);\n\n useModalStackHost(host);\n\n return ReactDOM.createPortal(children, host);\n};\n\nGlobalPortal.displayName = \"GlobalPortal\";\n"],"mappings":"AAAA,SAA4BA,QAAQ,QAAQ,OAAO;AACnD,OAAOC,QAAQ,MAAM,WAAW;AAEhC,SAASC,iBAAiB,QAAQ,gCAAgC;AAElE,MAAMC,UAAU,GAAGA,CAAA,KAAM;EACvB,MAAMC,IAAI,GAAGC,QAAQ,CAACC,aAAa,CAAC,KAAK,CAAC;EAC1CF,IAAI,CAACG,SAAS,GAAG,iBAAiB;EAElC,OAAOH,IAAI;AACb,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMI,YAAY,GAAGC,IAAA,IAAqC;EAAA,IAAlCC,QAAQ,GAAAD,IAAA,CAARC,QAAQ;EACrC,MAAAC,SAAA,GAAeX,QAAQ,CAACG,UAAU,CAAC;IAA5BC,IAAI,GAAAO,SAAA;EAEXT,iBAAiB,CAACE,IAAI,CAAC;EAEvB,oBAAOH,QAAQ,CAACW,YAAY,CAACF,QAAQ,EAAEN,IAAI,CAAC;AAC9C,CAAC;AAEDI,YAAY,CAACK,WAAW,GAAG,cAAc","ignoreList":[]}
1
+ {"version":3,"file":"GlobalPortal.js","names":["React","useState","ReactDOM","PortalContainerProvider","useModalStackHost","createHost","host","document","createElement","className","GlobalPortal","_ref","children","_useState","createPortal","value","displayName"],"sources":["../../../../src/components/GlobalPortal/GlobalPortal.tsx"],"sourcesContent":["import React, { PropsWithChildren, useState } from \"react\";\nimport ReactDOM from \"react-dom\";\n\nimport { PortalContainerProvider } from \"../../helpers\";\nimport { useModalStackHost } from \"../ModalRoot/useModalStackHost\";\n\nconst createHost = () => {\n const host = document.createElement(\"div\");\n host.className = \"c-global-portal\";\n\n return host;\n};\n\n/**\n * Renders content that must stay above every modal, such as toasts, a chat or a feedback prompt. Everything outside\n * an open native modal is inert, so the content follows the top open modal into its overlay root and comes back to\n * document.body once none is open.\n * The host node moves instead of the content being portalled again, so the content never remounts on the way.\n * Portals from the content, such as a menu or a tooltip, render into the host too, so they move along with it.\n * The host is attached in a layout effect after the content mounts, so content that measures itself on mount reads\n * no size there, and a transition that runs while the host moves restarts.\n */\nexport const GlobalPortal = ({ children }: PropsWithChildren) => {\n const [host] = useState(createHost);\n\n useModalStackHost(host);\n\n return ReactDOM.createPortal(\n <PortalContainerProvider value={host}>{children}</PortalContainerProvider>,\n host\n );\n};\n\nGlobalPortal.displayName = \"GlobalPortal\";\n"],"mappings":"AAAA,OAAOA,KAAK,IAAuBC,QAAQ,QAAQ,OAAO;AAC1D,OAAOC,QAAQ,MAAM,WAAW;AAEhC,SAASC,uBAAuB,QAAQ,eAAe;AACvD,SAASC,iBAAiB,QAAQ,gCAAgC;AAElE,MAAMC,UAAU,GAAGA,CAAA,KAAM;EACvB,MAAMC,IAAI,GAAGC,QAAQ,CAACC,aAAa,CAAC,KAAK,CAAC;EAC1CF,IAAI,CAACG,SAAS,GAAG,iBAAiB;EAElC,OAAOH,IAAI;AACb,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMI,YAAY,GAAGC,IAAA,IAAqC;EAAA,IAAlCC,QAAQ,GAAAD,IAAA,CAARC,QAAQ;EACrC,MAAAC,SAAA,GAAeZ,QAAQ,CAACI,UAAU,CAAC;IAA5BC,IAAI,GAAAO,SAAA;EAEXT,iBAAiB,CAACE,IAAI,CAAC;EAEvB,oBAAOJ,QAAQ,CAACY,YAAY,cAC1Bd,KAAA,CAAAQ,aAAA,CAACL,uBAAuB;IAACY,KAAK,EAAET;EAAK,GAAEM,QAAkC,CAAC,EAC1EN,IACF,CAAC;AACH,CAAC;AAEDI,YAAY,CAACM,WAAW,GAAG,cAAc","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"ModalRoot.d.ts","sourceRoot":"","sources":["../../../../src/components/ModalRoot/ModalRoot.tsx"],"names":[],"mappings":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C;IACZ,QAAQ,EAAE,MAAM,IAAI,CAAC;CACtB;AAED,MAAM,WAAW,cACf,SAAQ,IAAI,CACV,cAAc,CAAC,iBAAiB,CAAC,EACjC,UAAU,GAAG,MAAM,GAAG,SAAS,GAAG,UAAU,CAC7C;IACD,IAAI,EAAE,OAAO,CAAC;IACd,qEAAqE;IACrE,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,sBAAsB,KAAK,IAAI,CAAC;IAC1D,6HAA6H;IAC7H,gBAAgB,CAAC,EAAE,CACjB,MAAM,EAAE,sBAAsB,EAC9B,KAAK,CAAC,EAAE,UAAU,CAAC,iBAAiB,CAAC,KAClC,IAAI,CAAC;IACV,2DAA2D;IAC3D,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,iHAAiH;IACjH,QAAQ,EAAE,SAAS,GAAG,CAAC,CAAC,UAAU,EAAE,mBAAmB,KAAK,SAAS,CAAC,CAAC;CACxE;AAED,eAAO,MAAM,SAAS,0FA0RrB,CAAC"}
@@ -63,17 +63,18 @@ export const ModalRoot = /*#__PURE__*/forwardRef((_ref, ref) => {
63
63
  }, [onClose]);
64
64
 
65
65
  // The entry joins the stack with every showModal, so an owner that opens the dialog again from onClose, on the
66
- // same node, gets it back.
66
+ // same node, gets it back. It joins after showModal, so content that moves into the overlay root lands where it
67
+ // is rendered and can get its scroll positions back.
67
68
  useLayoutEffect(() => {
68
69
  if (!open || !dialog) {
69
70
  return;
70
71
  }
71
- if (stackIdRef.current === undefined) {
72
- stackIdRef.current = pushModalRoot(overlayRootRef.current);
73
- }
74
72
  if (!dialog.open) {
75
73
  dialog.showModal();
76
74
  }
75
+ if (stackIdRef.current === undefined) {
76
+ stackIdRef.current = pushModalRoot(overlayRootRef.current);
77
+ }
77
78
  }, [open, dialog]);
78
79
 
79
80
  // A layout effect, so the entry leaves the stack before an unmount removes the dialog and its overlay root.
@@ -1 +1 @@
1
- {"version":3,"file":"ModalRoot.js","names":["React","forwardRef","useCallback","useEffect","useLayoutEffect","useRef","useState","RemoveScroll","classnames","isTopModalRoot","popModalRoot","pushModalRoot","StyledModalRoot","Portal","PortalContainerProvider","useForkRef","ModalRoot","_ref","ref","open","onRequestClose","onDismissBlocked","onClose","_ref$disableCloseOnEs","disableCloseOnEsc","_ref$disableBackgroun","disableBackgroundClick","_ref$disableScrollLoc","disableScrollLock","children","className","onPointerDown","onClick","onKeyDown","rest","_objectWithoutPropertiesLoose","_excluded","_useState","mounted","setMounted","_useState2","dialog","setDialog","dialogRef","setDialogNode","node","current","handleRef","hasTransition","openRef","pressStartedOnBackdrop","stackIdRef","overlayRootRef","getOverlayRoot","finishClose","_dialogRef$current","undefined","close","showModal","dismissRef","reason","event","blocked","handleKeyDown","_overlayRootRef$curre","_overlayRootRef$curre2","stackId","defaultPrevented","key","target","document","body","querySelector","preventDefault","contains","addEventListener","removeEventListener","handleCancel","_overlayRootRef$curre3","activeElement","handleNativeClose","handlePointerDown","currentTarget","handleClick","_overlayRootRef$curre4","stopPropagation","handleExited","createElement","forwardProps","enabled","noIsolation","_extends","value","in","onExited","displayName"],"sources":["../../../../src/components/ModalRoot/ModalRoot.tsx"],"sourcesContent":["import React, {\n forwardRef,\n HTMLAttributes,\n KeyboardEvent as ReactKeyboardEvent,\n MouseEvent,\n PointerEvent,\n ReactNode,\n useCallback,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n} from \"react\";\nimport { RemoveScroll } from \"react-remove-scroll\";\n\nimport classnames from \"classnames\";\n\nimport { isTopModalRoot, popModalRoot, pushModalRoot } from \"./modalRootStack\";\nimport { StyledModalRoot } from \"./Styles\";\nimport { Portal, PortalContainerProvider } from \"../../helpers\";\nimport useForkRef from \"../../utils/useForkRef\";\n\nexport type ModalRootDismissReason = \"escape\" | \"backdrop\";\n\nexport interface ModalRootTransition {\n in: boolean;\n onExited: () => void;\n}\n\nexport interface ModalRootProps\n extends Omit<\n HTMLAttributes<HTMLDialogElement>,\n \"children\" | \"open\" | \"onClose\" | \"onCancel\"\n > {\n open: boolean;\n /** Escape or a backdrop click asks the owner to set open to false */\n onRequestClose?: (reason: ModalRootDismissReason) => void;\n /** Escape or a backdrop click that disableCloseOnEsc or disableBackgroundClick blocked; a backdrop click passes its event */\n onDismissBlocked?: (\n reason: ModalRootDismissReason,\n event?: MouseEvent<HTMLDialogElement>\n ) => void;\n /** The exit transition is done and the dialog is closed */\n onClose?: () => void;\n disableCloseOnEsc?: boolean;\n disableBackgroundClick?: boolean;\n disableScrollLock?: boolean;\n /** A function gets the transition state, and the dialog closes when it calls onExited. A node closes at once. */\n children: ReactNode | ((transition: ModalRootTransition) => ReactNode);\n}\n\nexport const ModalRoot = forwardRef<HTMLDialogElement, ModalRootProps>(\n (\n {\n open,\n onRequestClose,\n onDismissBlocked,\n onClose,\n disableCloseOnEsc = false,\n disableBackgroundClick = false,\n disableScrollLock = false,\n children,\n className,\n onPointerDown,\n onClick,\n onKeyDown,\n ...rest\n },\n ref\n ) => {\n const [mounted, setMounted] = useState(open);\n // Inside another root the dialog mounts a render after its first one, once the outer overlay root exists,\n // so opening, the stack and the listeners wait for the node instead of the first commit.\n const [dialog, setDialog] = useState<HTMLDialogElement | null>(null);\n const dialogRef = useRef<HTMLDialogElement | null>(null);\n const setDialogNode = useCallback((node: HTMLDialogElement | null) => {\n dialogRef.current = node;\n setDialog(node);\n }, []);\n const handleRef = useForkRef(setDialogNode, ref);\n const hasTransition = typeof children === \"function\";\n const openRef = useRef(open);\n const pressStartedOnBackdrop = useRef(false);\n const stackIdRef = useRef<number>();\n const overlayRootRef = useRef<HTMLDivElement>(null);\n // Menus and pickers opened inside portal here, into the top layer with the dialog, not under it.\n const getOverlayRoot = useCallback(\n () => overlayRootRef.current as HTMLElement,\n []\n );\n\n openRef.current = open;\n\n if (open && !mounted) {\n setMounted(true);\n }\n\n const finishClose = useCallback(() => {\n // Content that sits in the overlay root moves out before the dialog hides it.\n if (stackIdRef.current !== undefined) {\n popModalRoot(stackIdRef.current);\n stackIdRef.current = undefined;\n }\n dialogRef.current?.close();\n setMounted(false);\n onClose?.();\n }, [onClose]);\n\n // The entry joins the stack with every showModal, so an owner that opens the dialog again from onClose, on the\n // same node, gets it back.\n useLayoutEffect(() => {\n if (!open || !dialog) {\n return;\n }\n\n if (stackIdRef.current === undefined) {\n stackIdRef.current = pushModalRoot(overlayRootRef.current);\n }\n\n if (!dialog.open) {\n dialog.showModal();\n }\n }, [open, dialog]);\n\n // A layout effect, so the entry leaves the stack before an unmount removes the dialog and its overlay root.\n useLayoutEffect(\n () => () => {\n if (stackIdRef.current !== undefined) {\n popModalRoot(stackIdRef.current);\n stackIdRef.current = undefined;\n }\n },\n [dialog]\n );\n\n useLayoutEffect(() => {\n if (!open && mounted && !hasTransition) {\n finishClose();\n }\n }, [open, mounted, hasTransition, finishClose]);\n\n const dismissRef =\n useRef<\n (\n reason: ModalRootDismissReason,\n event?: MouseEvent<HTMLDialogElement>\n ) => void\n >();\n\n dismissRef.current = (reason, event) => {\n const blocked =\n reason === \"escape\" ? disableCloseOnEsc : disableBackgroundClick;\n\n if (blocked) {\n onDismissBlocked?.(reason, event);\n } else {\n onRequestClose?.(reason);\n }\n };\n\n // A prevented Escape keydown starts no close request, and the browser stops honouring a prevented cancel\n // after a while, so Escape is caught here and the cancel event only covers the other close requests.\n useEffect(() => {\n if (!dialog) {\n return undefined;\n }\n\n const handleKeyDown = (event: KeyboardEvent) => {\n const stackId = stackIdRef.current;\n\n if (\n stackId === undefined ||\n !isTopModalRoot(stackId) ||\n event.defaultPrevented ||\n (event.key !== \"Escape\" && event.key !== \"Esc\")\n ) {\n return;\n }\n\n // A menu inside closes on an Escape that reaches the body, from a listener that runs after this one.\n if (\n event.target === document.body &&\n overlayRootRef.current?.querySelector(\".c-window\")\n ) {\n return;\n }\n\n event.preventDefault();\n\n // A sheet, a menu or the chat in the overlay root is a layer above the dialog. An Escape it did not take\n // still belongs to it, so the dialog only stops the browser from closing itself.\n if (overlayRootRef.current?.contains(event.target as Node)) {\n return;\n }\n\n if (openRef.current) {\n dismissRef.current?.(\"escape\");\n }\n };\n\n document.addEventListener(\"keydown\", handleKeyDown);\n\n return () => document.removeEventListener(\"keydown\", handleKeyDown);\n }, [dialog]);\n\n useEffect(() => {\n if (!dialog) {\n return undefined;\n }\n\n const handleCancel = (event: Event) => {\n event.preventDefault();\n\n // A layer in the overlay root may stop its Escape before the document sees it, so the cancel that follows\n // would close the dialog under the layer. While the focus is in that layer, the close request is its own.\n if (overlayRootRef.current?.contains(document.activeElement)) {\n return;\n }\n\n if (openRef.current) {\n dismissRef.current?.(\"escape\");\n }\n };\n\n const handleNativeClose = () => {\n if (openRef.current && !dialog.open) {\n dialog.showModal();\n }\n };\n\n dialog.addEventListener(\"cancel\", handleCancel);\n dialog.addEventListener(\"close\", handleNativeClose);\n\n return () => {\n dialog.removeEventListener(\"cancel\", handleCancel);\n dialog.removeEventListener(\"close\", handleNativeClose);\n };\n }, [dialog]);\n\n const handlePointerDown = useCallback(\n (event: PointerEvent<HTMLDialogElement>) => {\n pressStartedOnBackdrop.current = event.target === event.currentTarget;\n onPointerDown?.(event);\n },\n [onPointerDown]\n );\n\n // The dialog covers the viewport and its content sits inside it, so a click on the dialog itself is a\n // click on the backdrop. A press that started on the content and ended outside it is a text selection.\n const handleClick = useCallback(\n (event: MouseEvent<HTMLDialogElement>) => {\n if (\n event.target === event.currentTarget &&\n pressStartedOnBackdrop.current &&\n openRef.current\n ) {\n dismissRef.current?.(\"backdrop\", event);\n }\n pressStartedOnBackdrop.current = false;\n onClick?.(event);\n },\n [onClick]\n );\n\n // React events from a portal bubble through the React tree, so an Escape from the content would reach an\n // ancestor's handler, like an older Sheet's, before the document listener. The dialog takes it here first.\n const handleKeyDown = useCallback(\n (event: ReactKeyboardEvent<HTMLDialogElement>) => {\n onKeyDown?.(event);\n\n if (\n event.defaultPrevented ||\n (event.key !== \"Escape\" && event.key !== \"Esc\") ||\n stackIdRef.current === undefined ||\n !isTopModalRoot(stackIdRef.current)\n ) {\n return;\n }\n\n event.preventDefault();\n event.stopPropagation();\n\n // An Escape a layer in the overlay root did not take stops here too, so it does not close the sheet that\n // opened this dialog, but it leaves the dialog open.\n if (overlayRootRef.current?.contains(event.target as Node)) {\n return;\n }\n\n if (openRef.current) {\n dismissRef.current?.(\"escape\");\n }\n },\n [onKeyDown]\n );\n\n const handleExited = useCallback(() => {\n if (!open) {\n finishClose();\n }\n }, [open, finishClose]);\n\n if (!mounted) {\n return null;\n }\n\n return (\n <Portal>\n <RemoveScroll\n forwardProps\n ref={handleRef}\n enabled={!disableScrollLock}\n noIsolation\n >\n <StyledModalRoot\n {...rest}\n className={classnames(\"c-modal-root\", className)}\n data-state={open ? \"open\" : \"closing\"}\n onPointerDown={handlePointerDown}\n onClick={handleClick}\n onKeyDown={handleKeyDown}\n >\n <PortalContainerProvider value={getOverlayRoot}>\n {typeof children === \"function\"\n ? children({ in: open, onExited: handleExited })\n : children}\n </PortalContainerProvider>\n <div ref={overlayRootRef} className=\"c-modal-root__overlays\" />\n </StyledModalRoot>\n </RemoveScroll>\n </Portal>\n );\n }\n);\n\nModalRoot.displayName = \"ModalRoot\";\n"],"mappings":";;;AAAA,OAAOA,KAAK,IACVC,UAAU,EAMVC,WAAW,EACXC,SAAS,EACTC,eAAe,EACfC,MAAM,EACNC,QAAQ,QACH,OAAO;AACd,SAASC,YAAY,QAAQ,qBAAqB;AAElD,OAAOC,UAAU,MAAM,YAAY;AAEnC,SAASC,cAAc,EAAEC,YAAY,EAAEC,aAAa,QAAQ,kBAAkB;AAC9E,SAASC,eAAe,QAAQ,UAAU;AAC1C,SAASC,MAAM,EAAEC,uBAAuB,QAAQ,eAAe;AAC/D,OAAOC,UAAU,MAAM,wBAAwB;AA+B/C,OAAO,MAAMC,SAAS,gBAAGf,UAAU,CACjC,CAAAgB,IAAA,EAgB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AEvC;EAAe,GAC5C,OAAOxB,QAAQ,KAAK,UAAU,GAC3BA,QAAQ,CAAC;IAAEgE,EAAE,EAAE1E,IAAI;IAAE2E,QAAQ,EAAER;EAAa,CAAC,CAAC,GAC9CzD,QACmB,CAAC,eAC1B7B,KAAA,CAAAuF,aAAA;IAAKrE,GAAG,EAAEkC,cAAe;IAACtB,SAAS,EAAC;EAAwB,CAAE,CAC/C,CACL,CACR,CAAC;AAEb,CACF,CAAC;AAEDd,SAAS,CAAC+E,WAAW,GAAG,WAAW","ignoreList":[]}
1
+ {"version":3,"file":"ModalRoot.js","names":["React","forwardRef","useCallback","useEffect","useLayoutEffect","useRef","useState","RemoveScroll","classnames","isTopModalRoot","popModalRoot","pushModalRoot","StyledModalRoot","Portal","PortalContainerProvider","useForkRef","ModalRoot","_ref","ref","open","onRequestClose","onDismissBlocked","onClose","_ref$disableCloseOnEs","disableCloseOnEsc","_ref$disableBackgroun","disableBackgroundClick","_ref$disableScrollLoc","disableScrollLock","children","className","onPointerDown","onClick","onKeyDown","rest","_objectWithoutPropertiesLoose","_excluded","_useState","mounted","setMounted","_useState2","dialog","setDialog","dialogRef","setDialogNode","node","current","handleRef","hasTransition","openRef","pressStartedOnBackdrop","stackIdRef","overlayRootRef","getOverlayRoot","finishClose","_dialogRef$current","undefined","close","showModal","dismissRef","reason","event","blocked","handleKeyDown","_overlayRootRef$curre","_overlayRootRef$curre2","stackId","defaultPrevented","key","target","document","body","querySelector","preventDefault","contains","addEventListener","removeEventListener","handleCancel","_overlayRootRef$curre3","activeElement","handleNativeClose","handlePointerDown","currentTarget","handleClick","_overlayRootRef$curre4","stopPropagation","handleExited","createElement","forwardProps","enabled","noIsolation","_extends","value","in","onExited","displayName"],"sources":["../../../../src/components/ModalRoot/ModalRoot.tsx"],"sourcesContent":["import React, {\n forwardRef,\n HTMLAttributes,\n KeyboardEvent as ReactKeyboardEvent,\n MouseEvent,\n PointerEvent,\n ReactNode,\n useCallback,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n} from \"react\";\nimport { RemoveScroll } from \"react-remove-scroll\";\n\nimport classnames from \"classnames\";\n\nimport { isTopModalRoot, popModalRoot, pushModalRoot } from \"./modalRootStack\";\nimport { StyledModalRoot } from \"./Styles\";\nimport { Portal, PortalContainerProvider } from \"../../helpers\";\nimport useForkRef from \"../../utils/useForkRef\";\n\nexport type ModalRootDismissReason = \"escape\" | \"backdrop\";\n\nexport interface ModalRootTransition {\n in: boolean;\n onExited: () => void;\n}\n\nexport interface ModalRootProps\n extends Omit<\n HTMLAttributes<HTMLDialogElement>,\n \"children\" | \"open\" | \"onClose\" | \"onCancel\"\n > {\n open: boolean;\n /** Escape or a backdrop click asks the owner to set open to false */\n onRequestClose?: (reason: ModalRootDismissReason) => void;\n /** Escape or a backdrop click that disableCloseOnEsc or disableBackgroundClick blocked; a backdrop click passes its event */\n onDismissBlocked?: (\n reason: ModalRootDismissReason,\n event?: MouseEvent<HTMLDialogElement>\n ) => void;\n /** The exit transition is done and the dialog is closed */\n onClose?: () => void;\n disableCloseOnEsc?: boolean;\n disableBackgroundClick?: boolean;\n disableScrollLock?: boolean;\n /** A function gets the transition state, and the dialog closes when it calls onExited. A node closes at once. */\n children: ReactNode | ((transition: ModalRootTransition) => ReactNode);\n}\n\nexport const ModalRoot = forwardRef<HTMLDialogElement, ModalRootProps>(\n (\n {\n open,\n onRequestClose,\n onDismissBlocked,\n onClose,\n disableCloseOnEsc = false,\n disableBackgroundClick = false,\n disableScrollLock = false,\n children,\n className,\n onPointerDown,\n onClick,\n onKeyDown,\n ...rest\n },\n ref\n ) => {\n const [mounted, setMounted] = useState(open);\n // Inside another root the dialog mounts a render after its first one, once the outer overlay root exists,\n // so opening, the stack and the listeners wait for the node instead of the first commit.\n const [dialog, setDialog] = useState<HTMLDialogElement | null>(null);\n const dialogRef = useRef<HTMLDialogElement | null>(null);\n const setDialogNode = useCallback((node: HTMLDialogElement | null) => {\n dialogRef.current = node;\n setDialog(node);\n }, []);\n const handleRef = useForkRef(setDialogNode, ref);\n const hasTransition = typeof children === \"function\";\n const openRef = useRef(open);\n const pressStartedOnBackdrop = useRef(false);\n const stackIdRef = useRef<number>();\n const overlayRootRef = useRef<HTMLDivElement>(null);\n // Menus and pickers opened inside portal here, into the top layer with the dialog, not under it.\n const getOverlayRoot = useCallback(\n () => overlayRootRef.current as HTMLElement,\n []\n );\n\n openRef.current = open;\n\n if (open && !mounted) {\n setMounted(true);\n }\n\n const finishClose = useCallback(() => {\n // Content that sits in the overlay root moves out before the dialog hides it.\n if (stackIdRef.current !== undefined) {\n popModalRoot(stackIdRef.current);\n stackIdRef.current = undefined;\n }\n dialogRef.current?.close();\n setMounted(false);\n onClose?.();\n }, [onClose]);\n\n // The entry joins the stack with every showModal, so an owner that opens the dialog again from onClose, on the\n // same node, gets it back. It joins after showModal, so content that moves into the overlay root lands where it\n // is rendered and can get its scroll positions back.\n useLayoutEffect(() => {\n if (!open || !dialog) {\n return;\n }\n\n if (!dialog.open) {\n dialog.showModal();\n }\n\n if (stackIdRef.current === undefined) {\n stackIdRef.current = pushModalRoot(overlayRootRef.current);\n }\n }, [open, dialog]);\n\n // A layout effect, so the entry leaves the stack before an unmount removes the dialog and its overlay root.\n useLayoutEffect(\n () => () => {\n if (stackIdRef.current !== undefined) {\n popModalRoot(stackIdRef.current);\n stackIdRef.current = undefined;\n }\n },\n [dialog]\n );\n\n useLayoutEffect(() => {\n if (!open && mounted && !hasTransition) {\n finishClose();\n }\n }, [open, mounted, hasTransition, finishClose]);\n\n const dismissRef =\n useRef<\n (\n reason: ModalRootDismissReason,\n event?: MouseEvent<HTMLDialogElement>\n ) => void\n >();\n\n dismissRef.current = (reason, event) => {\n const blocked =\n reason === \"escape\" ? disableCloseOnEsc : disableBackgroundClick;\n\n if (blocked) {\n onDismissBlocked?.(reason, event);\n } else {\n onRequestClose?.(reason);\n }\n };\n\n // A prevented Escape keydown starts no close request, and the browser stops honouring a prevented cancel\n // after a while, so Escape is caught here and the cancel event only covers the other close requests.\n useEffect(() => {\n if (!dialog) {\n return undefined;\n }\n\n const handleKeyDown = (event: KeyboardEvent) => {\n const stackId = stackIdRef.current;\n\n if (\n stackId === undefined ||\n !isTopModalRoot(stackId) ||\n event.defaultPrevented ||\n (event.key !== \"Escape\" && event.key !== \"Esc\")\n ) {\n return;\n }\n\n // A menu inside closes on an Escape that reaches the body, from a listener that runs after this one.\n if (\n event.target === document.body &&\n overlayRootRef.current?.querySelector(\".c-window\")\n ) {\n return;\n }\n\n event.preventDefault();\n\n // A sheet, a menu or the chat in the overlay root is a layer above the dialog. An Escape it did not take\n // still belongs to it, so the dialog only stops the browser from closing itself.\n if (overlayRootRef.current?.contains(event.target as Node)) {\n return;\n }\n\n if (openRef.current) {\n dismissRef.current?.(\"escape\");\n }\n };\n\n document.addEventListener(\"keydown\", handleKeyDown);\n\n return () => document.removeEventListener(\"keydown\", handleKeyDown);\n }, [dialog]);\n\n useEffect(() => {\n if (!dialog) {\n return undefined;\n }\n\n const handleCancel = (event: Event) => {\n event.preventDefault();\n\n // A layer in the overlay root may stop its Escape before the document sees it, so the cancel that follows\n // would close the dialog under the layer. While the focus is in that layer, the close request is its own.\n if (overlayRootRef.current?.contains(document.activeElement)) {\n return;\n }\n\n if (openRef.current) {\n dismissRef.current?.(\"escape\");\n }\n };\n\n const handleNativeClose = () => {\n if (openRef.current && !dialog.open) {\n dialog.showModal();\n }\n };\n\n dialog.addEventListener(\"cancel\", handleCancel);\n dialog.addEventListener(\"close\", handleNativeClose);\n\n return () => {\n dialog.removeEventListener(\"cancel\", handleCancel);\n dialog.removeEventListener(\"close\", handleNativeClose);\n };\n }, [dialog]);\n\n const handlePointerDown = useCallback(\n (event: PointerEvent<HTMLDialogElement>) => {\n pressStartedOnBackdrop.current = event.target === event.currentTarget;\n onPointerDown?.(event);\n },\n [onPointerDown]\n );\n\n // The dialog covers the viewport and its content sits inside it, so a click on the dialog itself is a\n // click on the backdrop. A press that started on the content and ended outside it is a text selection.\n const handleClick = useCallback(\n (event: MouseEvent<HTMLDialogElement>) => {\n if (\n event.target === event.currentTarget &&\n pressStartedOnBackdrop.current &&\n openRef.current\n ) {\n dismissRef.current?.(\"backdrop\", event);\n }\n pressStartedOnBackdrop.current = false;\n onClick?.(event);\n },\n [onClick]\n );\n\n // React events from a portal bubble through the React tree, so an Escape from the content would reach an\n // ancestor's handler, like an older Sheet's, before the document listener. The dialog takes it here first.\n const handleKeyDown = useCallback(\n (event: ReactKeyboardEvent<HTMLDialogElement>) => {\n onKeyDown?.(event);\n\n if (\n event.defaultPrevented ||\n (event.key !== \"Escape\" && event.key !== \"Esc\") ||\n stackIdRef.current === undefined ||\n !isTopModalRoot(stackIdRef.current)\n ) {\n return;\n }\n\n event.preventDefault();\n event.stopPropagation();\n\n // An Escape a layer in the overlay root did not take stops here too, so it does not close the sheet that\n // opened this dialog, but it leaves the dialog open.\n if (overlayRootRef.current?.contains(event.target as Node)) {\n return;\n }\n\n if (openRef.current) {\n dismissRef.current?.(\"escape\");\n }\n },\n [onKeyDown]\n );\n\n const handleExited = useCallback(() => {\n if (!open) {\n finishClose();\n }\n }, [open, finishClose]);\n\n if (!mounted) {\n return null;\n }\n\n return (\n <Portal>\n <RemoveScroll\n forwardProps\n ref={handleRef}\n enabled={!disableScrollLock}\n noIsolation\n >\n <StyledModalRoot\n {...rest}\n className={classnames(\"c-modal-root\", className)}\n data-state={open ? \"open\" : \"closing\"}\n onPointerDown={handlePointerDown}\n onClick={handleClick}\n onKeyDown={handleKeyDown}\n >\n <PortalContainerProvider value={getOverlayRoot}>\n {typeof children === \"function\"\n ? children({ in: open, onExited: handleExited })\n : children}\n </PortalContainerProvider>\n <div ref={overlayRootRef} className=\"c-modal-root__overlays\" />\n </StyledModalRoot>\n </RemoveScroll>\n </Portal>\n );\n }\n);\n\nModalRoot.displayName = \"ModalRoot\";\n"],"mappings":";;;AAAA,OAAOA,KAAK,IACVC,UAAU,EAMVC,WAAW,EACXC,SAAS,EACTC,eAAe,EACfC,MAAM,E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AW;EAAA,gBAEX1F,KAAA,CAAAuF,aAAA,CAAC3E,eAAe,EAAA+E,QAAA,KACVzD,IAAI;IACRJ,SAAS,EAAEtB,UAAU,CAAC,cAAc,EAAEsB,SAAS,CAAE;IACjD,cAAYX,IAAI,GAAG,MAAM,GAAG,SAAU;IACtCY,aAAa,EAAEkD,iBAAkB;IACjCjD,OAAO,EAAEmD,WAAY;IACrBlD,SAAS,EAAE8B;EAAc,iBAEzB/D,KAAA,CAAAuF,aAAA,CAACzE,uBAAuB;IAAC8E,KAAK,EAAEvC;EAAe,GAC5C,OAAOxB,QAAQ,KAAK,UAAU,GAC3BA,QAAQ,CAAC;IAAEgE,EAAE,EAAE1E,IAAI;IAAE2E,QAAQ,EAAER;EAAa,CAAC,CAAC,GAC9CzD,QACmB,CAAC,eAC1B7B,KAAA,CAAAuF,aAAA;IAAKrE,GAAG,EAAEkC,cAAe;IAACtB,SAAS,EAAC;EAAwB,CAAE,CAC/C,CACL,CACR,CAAC;AAEb,CACF,CAAC;AAEDd,SAAS,CAAC+E,WAAW,GAAG,WAAW","ignoreList":[]}
@@ -2,12 +2,16 @@ type Listener = () => void;
2
2
  export declare const pushModalRoot: (overlayRoot: HTMLElement | null) => number;
3
3
  export declare const popModalRoot: (id: number) => void;
4
4
  export declare const isTopModalRoot: (id: number) => boolean;
5
- /** The overlay root of the top open modal root, where content that must stay above every modal goes. */
6
- export declare const getTopModalOverlayRoot: () => HTMLElement | null;
5
+ /**
6
+ * The overlay root of the top open modal root, where content that must stay above every modal goes. A modal root
7
+ * whose overlay root sits inside outside, one opened from that content, is skipped, since content cannot move into
8
+ * itself.
9
+ */
10
+ export declare const getTopModalOverlayRoot: (outside?: Node) => HTMLElement | null;
7
11
  /** The id of the top open modal root, or undefined when none is open. */
8
12
  export declare const getTopModalRootId: () => number | undefined;
9
- /** The overlay root of the top modal root among those opened no later than the given one. */
10
- export declare const getModalOverlayRootUpTo: (id: number) => HTMLElement | null;
13
+ /** The overlay root of the top modal root among those opened no later than the given one, skipping as above. */
14
+ export declare const getModalOverlayRootUpTo: (id: number, outside?: Node) => HTMLElement | null;
11
15
  export declare const subscribeToModalRoots: (listener: Listener) => (() => void);
12
16
  export {};
13
17
  //# sourceMappingURL=modalRootStack.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"modalRootStack.d.ts","sourceRoot":"","sources":["../../../../src/components/ModalRoot/modalRootStack.ts"],"names":[],"mappings":"AAAA,KAAK,QAAQ,GAAG,MAAM,IAAI,CAAC;AAc3B,eAAO,MAAM,aAAa,GAAI,aAAa,WAAW,GAAG,IAAI,KAAG,MAM/D,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,IAAI,MAAM,KAAG,IAOzC,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,IAAI,MAAM,KAAG,OACR,CAAC;AAErC,wGAAwG;AACxG,eAAO,MAAM,sBAAsB,QAAO,WAAW,GAAG,IACV,CAAC;AAE/C,yEAAyE;AACzE,eAAO,MAAM,iBAAiB,QAAO,MAAM,GAAG,SACjB,CAAC;AAE9B,6FAA6F;AAC7F,eAAO,MAAM,uBAAuB,GAAI,IAAI,MAAM,KAAG,WAAW,GAAG,IAIlE,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAAI,UAAU,QAAQ,KAAG,CAAC,MAAM,IAAI,CAMrE,CAAC"}
1
+ {"version":3,"file":"modalRootStack.d.ts","sourceRoot":"","sources":["../../../../src/components/ModalRoot/modalRootStack.ts"],"names":[],"mappings":"AAAA,KAAK,QAAQ,GAAG,MAAM,IAAI,CAAC;AAc3B,eAAO,MAAM,aAAa,GAAI,aAAa,WAAW,GAAG,IAAI,KAAG,MAM/D,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,IAAI,MAAM,KAAG,IAOzC,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,IAAI,MAAM,KAAG,OACR,CAAC;AAKrC;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,GAAI,UAAU,IAAI,KAAG,WAAW,GAAG,IACS,CAAC;AAEhF,yEAAyE;AACzE,eAAO,MAAM,iBAAiB,QAAO,MAAM,GAAG,SACjB,CAAC;AAE9B,gHAAgH;AAChH,eAAO,MAAM,uBAAuB,GAClC,IAAI,MAAM,EACV,UAAU,IAAI,KACb,WAAW,GAAG,IAEQ,CAAC;AAE1B,eAAO,MAAM,qBAAqB,GAAI,UAAU,QAAQ,KAAG,CAAC,MAAM,IAAI,CAMrE,CAAC"}
@@ -22,24 +22,28 @@ export const isTopModalRoot = id => {
22
22
  var _stack;
23
23
  return ((_stack = stack[stack.length - 1]) == null ? void 0 : _stack.id) === id;
24
24
  };
25
+ const isInside = (entry, outside) => !!outside && !!entry.overlayRoot && outside.contains(entry.overlayRoot);
25
26
 
26
- /** The overlay root of the top open modal root, where content that must stay above every modal goes. */
27
- export const getTopModalOverlayRoot = () => {
28
- var _stack$overlayRoot, _stack2;
29
- return (_stack$overlayRoot = (_stack2 = stack[stack.length - 1]) == null ? void 0 : _stack2.overlayRoot) != null ? _stack$overlayRoot : null;
27
+ /**
28
+ * The overlay root of the top open modal root, where content that must stay above every modal goes. A modal root
29
+ * whose overlay root sits inside outside, one opened from that content, is skipped, since content cannot move into
30
+ * itself.
31
+ */
32
+ export const getTopModalOverlayRoot = outside => {
33
+ var _stack$filter$pop$ove, _stack$filter$pop;
34
+ return (_stack$filter$pop$ove = (_stack$filter$pop = stack.filter(entry => !isInside(entry, outside)).pop()) == null ? void 0 : _stack$filter$pop.overlayRoot) != null ? _stack$filter$pop$ove : null;
30
35
  };
31
36
 
32
37
  /** The id of the top open modal root, or undefined when none is open. */
33
38
  export const getTopModalRootId = () => {
34
- var _stack3;
35
- return (_stack3 = stack[stack.length - 1]) == null ? void 0 : _stack3.id;
39
+ var _stack2;
40
+ return (_stack2 = stack[stack.length - 1]) == null ? void 0 : _stack2.id;
36
41
  };
37
42
 
38
- /** The overlay root of the top modal root among those opened no later than the given one. */
39
- export const getModalOverlayRootUpTo = id => {
40
- var _entries$overlayRoot, _entries;
41
- const entries = stack.filter(entry => entry.id <= id);
42
- return (_entries$overlayRoot = (_entries = entries[entries.length - 1]) == null ? void 0 : _entries.overlayRoot) != null ? _entries$overlayRoot : null;
43
+ /** The overlay root of the top modal root among those opened no later than the given one, skipping as above. */
44
+ export const getModalOverlayRootUpTo = (id, outside) => {
45
+ var _stack$filter$pop$ove2, _stack$filter$pop2;
46
+ return (_stack$filter$pop$ove2 = (_stack$filter$pop2 = stack.filter(entry => entry.id <= id && !isInside(entry, outside)).pop()) == null ? void 0 : _stack$filter$pop2.overlayRoot) != null ? _stack$filter$pop$ove2 : null;
43
47
  };
44
48
  export const subscribeToModalRoots = listener => {
45
49
  listeners.add(listener);
@@ -1 +1 @@
1
- {"version":3,"file":"modalRootStack.js","names":["listeners","Set","stack","lastId","notify","forEach","listener","pushModalRoot","overlayRoot","id","popModalRoot","some","entry","filter","isTopModalRoot","_stack","length","getTopModalOverlayRoot","_stack$overlayRoot","_stack2","getTopModalRootId","_stack3","getModalOverlayRootUpTo","_entries$overlayRoot","_entries","entries","subscribeToModalRoots","add","delete"],"sources":["../../../../src/components/ModalRoot/modalRootStack.ts"],"sourcesContent":["type Listener = () => void;\n\ninterface Entry {\n id: number;\n overlayRoot: HTMLElement | null;\n}\n\nconst listeners = new Set<Listener>();\n\nlet stack: Entry[] = [];\nlet lastId = 0;\n\nconst notify = (): void => listeners.forEach((listener) => listener());\n\nexport const pushModalRoot = (overlayRoot: HTMLElement | null): number => {\n lastId += 1;\n stack = [...stack, { id: lastId, overlayRoot }];\n notify();\n\n return lastId;\n};\n\nexport const popModalRoot = (id: number): void => {\n if (!stack.some((entry) => entry.id === id)) {\n return;\n }\n\n stack = stack.filter((entry) => entry.id !== id);\n notify();\n};\n\nexport const isTopModalRoot = (id: number): boolean =>\n stack[stack.length - 1]?.id === id;\n\n/** The overlay root of the top open modal root, where content that must stay above every modal goes. */\nexport const getTopModalOverlayRoot = (): HTMLElement | null =>\n stack[stack.length - 1]?.overlayRoot ?? null;\n\n/** The id of the top open modal root, or undefined when none is open. */\nexport const getTopModalRootId = (): number | undefined =>\n stack[stack.length - 1]?.id;\n\n/** The overlay root of the top modal root among those opened no later than the given one. */\nexport const getModalOverlayRootUpTo = (id: number): HTMLElement | null => {\n const entries = stack.filter((entry) => entry.id <= id);\n\n return entries[entries.length - 1]?.overlayRoot ?? null;\n};\n\nexport const subscribeToModalRoots = (listener: Listener): (() => void) => {\n listeners.add(listener);\n\n return (): void => {\n listeners.delete(listener);\n };\n};\n"],"mappings":"AAOA,MAAMA,SAAS,GAAG,IAAIC,GAAG,CAAW,CAAC;AAErC,IAAIC,KAAc,GAAG,EAAE;AACvB,IAAIC,MAAM,GAAG,CAAC;AAEd,MAAMC,MAAM,GAAGA,CAAA,KAAYJ,SAAS,CAACK,OAAO,CAAEC,QAAQ,IAAKA,QAAQ,CAAC,CAAC,CAAC;AAEtE,OAAO,MAAMC,aAAa,GAAIC,WAA+B,IAAa;EACxEL,MAAM,IAAI,CAAC;EACXD,KAAK,GAAG,CAAC,GAAGA,KAAK,EAAE;IAAEO,EAAE,EAAEN,MAAM;IAAEK;EAAY,CAAC,CAAC;EAC/CJ,MAAM,CAAC,CAAC;EAER,OAAOD,MAAM;AACf,CAAC;AAED,OAAO,MAAMO,YAAY,GAAID,EAAU,IAAW;EAChD,IAAI,CAACP,KAAK,CAACS,IAAI,CAAEC,KAAK,IAAKA,KAAK,CAACH,EAAE,KAAKA,EAAE,CAAC,EAAE;IAC3C;EACF;EAEAP,KAAK,GAAGA,KAAK,CAACW,MAAM,CAAED,KAAK,IAAKA,KAAK,CAACH,EAAE,KAAKA,EAAE,CAAC;EAChDL,MAAM,CAAC,CAAC;AACV,CAAC;AAED,OAAO,MAAMU,cAAc,GAAIL,EAAU;EAAA,IAAAM,MAAA;EAAA,OACvC,EAAAA,MAAA,GAAAb,KAAK,CAACA,KAAK,CAACc,MAAM,GAAG,CAAC,CAAC,qBAAvBD,MAAA,CAAyBN,EAAE,MAAKA,EAAE;AAAA;;AAEpC;AACA,OAAO,MAAMQ,sBAAsB,GAAGA,CAAA;EAAA,IAAAC,kBAAA,EAAAC,OAAA;EAAA,QAAAD,kBAAA,IAAAC,OAAA,GACpCjB,KAAK,CAACA,KAAK,CAACc,MAAM,GAAG,CAAC,CAAC,qBAAvBG,OAAA,CAAyBX,WAAW,YAAAU,kBAAA,GAAI,IAAI;AAAA;;AAE9C;AACA,OAAO,MAAME,iBAAiB,GAAGA,CAAA;EAAA,IAAAC,OAAA;EAAA,QAAAA,OAAA,GAC/BnB,KAAK,CAACA,KAAK,CAACc,MAAM,GAAG,CAAC,CAAC,qBAAvBK,OAAA,CAAyBZ,EAAE;AAAA;;AAE7B;AACA,OAAO,MAAMa,uBAAuB,GAAIb,EAAU,IAAyB;EAAA,IAAAc,oBAAA,EAAAC,QAAA;EACzE,MAAMC,OAAO,GAAGvB,KAAK,CAACW,MAAM,CAAED,KAAK,IAAKA,KAAK,CAACH,EAAE,IAAIA,EAAE,CAAC;EAEvD,QAAAc,oBAAA,IAAAC,QAAA,GAAOC,OAAO,CAACA,OAAO,CAACT,MAAM,GAAG,CAAC,CAAC,qBAA3BQ,QAAA,CAA6BhB,WAAW,YAAAe,oBAAA,GAAI,IAAI;AACzD,CAAC;AAED,OAAO,MAAMG,qBAAqB,GAAIpB,QAAkB,IAAmB;EACzEN,SAAS,CAAC2B,GAAG,CAACrB,QAAQ,CAAC;EAEvB,OAAO,MAAY;IACjBN,SAAS,CAAC4B,MAAM,CAACtB,QAAQ,CAAC;EAC5B,CAAC;AACH,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"modalRootStack.js","names":["listeners","Set","stack","lastId","notify","forEach","listener","pushModalRoot","overlayRoot","id","popModalRoot","some","entry","filter","isTopModalRoot","_stack","length","isInside","outside","contains","getTopModalOverlayRoot","_stack$filter$pop$ove","_stack$filter$pop","pop","getTopModalRootId","_stack2","getModalOverlayRootUpTo","_stack$filter$pop$ove2","_stack$filter$pop2","subscribeToModalRoots","add","delete"],"sources":["../../../../src/components/ModalRoot/modalRootStack.ts"],"sourcesContent":["type Listener = () => void;\n\ninterface Entry {\n id: number;\n overlayRoot: HTMLElement | null;\n}\n\nconst listeners = new Set<Listener>();\n\nlet stack: Entry[] = [];\nlet lastId = 0;\n\nconst notify = (): void => listeners.forEach((listener) => listener());\n\nexport const pushModalRoot = (overlayRoot: HTMLElement | null): number => {\n lastId += 1;\n stack = [...stack, { id: lastId, overlayRoot }];\n notify();\n\n return lastId;\n};\n\nexport const popModalRoot = (id: number): void => {\n if (!stack.some((entry) => entry.id === id)) {\n return;\n }\n\n stack = stack.filter((entry) => entry.id !== id);\n notify();\n};\n\nexport const isTopModalRoot = (id: number): boolean =>\n stack[stack.length - 1]?.id === id;\n\nconst isInside = (entry: Entry, outside?: Node) =>\n !!outside && !!entry.overlayRoot && outside.contains(entry.overlayRoot);\n\n/**\n * The overlay root of the top open modal root, where content that must stay above every modal goes. A modal root\n * whose overlay root sits inside outside, one opened from that content, is skipped, since content cannot move into\n * itself.\n */\nexport const getTopModalOverlayRoot = (outside?: Node): HTMLElement | null =>\n stack.filter((entry) => !isInside(entry, outside)).pop()?.overlayRoot ?? null;\n\n/** The id of the top open modal root, or undefined when none is open. */\nexport const getTopModalRootId = (): number | undefined =>\n stack[stack.length - 1]?.id;\n\n/** The overlay root of the top modal root among those opened no later than the given one, skipping as above. */\nexport const getModalOverlayRootUpTo = (\n id: number,\n outside?: Node\n): HTMLElement | null =>\n stack.filter((entry) => entry.id <= id && !isInside(entry, outside)).pop()\n ?.overlayRoot ?? null;\n\nexport const subscribeToModalRoots = (listener: Listener): (() => void) => {\n listeners.add(listener);\n\n return (): void => {\n listeners.delete(listener);\n };\n};\n"],"mappings":"AAOA,MAAMA,SAAS,GAAG,IAAIC,GAAG,CAAW,CAAC;AAErC,IAAIC,KAAc,GAAG,EAAE;AACvB,IAAIC,MAAM,GAAG,CAAC;AAEd,MAAMC,MAAM,GAAGA,CAAA,KAAYJ,SAAS,CAACK,OAAO,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;AAAA;;AAE/E;AACA,OAAO,MAAMG,iBAAiB,GAAGA,CAAA;EAAA,IAAAC,OAAA;EAAA,QAAAA,OAAA,GAC/BvB,KAAK,CAACA,KAAK,CAACc,MAAM,GAAG,CAAC,CAAC,qBAAvBS,OAAA,CAAyBhB,EAAE;AAAA;;AAE7B;AACA,OAAO,MAAMiB,uBAAuB,GAAGA,CACrCjB,EAAU,EACVS,OAAc;EAAA,IAAAS,sBAAA,EAAAC,kBAAA;EAAA,QAAAD,sBAAA,IAAAC,kBAAA,GAEd1B,KAAK,CAACW,MAAM,CAAED,KAAK,IAAKA,KAAK,CAACH,EAAE,IAAIA,EAAE,IAAI,CAACQ,QAAQ,CAACL,KAAK,EAAEM,OAAO,CAAC,CAAC,CAACK,GAAG,CAAC,CAAC,qBAA1EK,kBAAA,CACIpB,WAAW,YAAAmB,sBAAA,GAAI,IAAI;AAAA;AAEzB,OAAO,MAAME,qBAAqB,GAAIvB,QAAkB,IAAmB;EACzEN,SAAS,CAAC8B,GAAG,CAACxB,QAAQ,CAAC;EAEvB,OAAO,MAAY;IACjBN,SAAS,CAAC+B,MAAM,CAACzB,QAAQ,CAAC;EAC5B,CAAC;AACH,CAAC","ignoreList":[]}
@@ -1,7 +1,9 @@
1
1
  /**
2
2
  * Keeps a host node in the overlay root of the top open modal, or of the top one opened no later than
3
- * upToModalRootId, and in document.body while there is none. The node moves as modals open and close, so content
4
- * portalled into it never remounts, and it leaves the page on unmount or when the host changes. Returns whether the
3
+ * upToModalRootId, and in document.body while there is none. A modal opened from the content of the host is not
4
+ * counted, since its overlay root is inside the host. The node moves as modals open and close, so content
5
+ * portalled into it never remounts and keeps its scroll positions and focus, and it leaves the page on unmount or
6
+ * when the host changes. Returns whether the
5
7
  * host is in the page, which it is from a layout effect after the first render with it.
6
8
  */
7
9
  export declare const useModalStackHost: (host: HTMLElement | null, upToModalRootId?: number) => boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"useModalStackHost.d.ts","sourceRoot":"","sources":["../../../../src/components/ModalRoot/useModalStackHost.ts"],"names":[],"mappings":"AAQA;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAC5B,MAAM,WAAW,GAAG,IAAI,EACxB,kBAAkB,MAAM,KACvB,OA+BF,CAAC"}
1
+ {"version":3,"file":"useModalStackHost.d.ts","sourceRoot":"","sources":["../../../../src/components/ModalRoot/useModalStackHost.ts"],"names":[],"mappings":"AA8CA;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,GAC5B,MAAM,WAAW,GAAG,IAAI,EACxB,kBAAkB,MAAM,KACvB,OA+BF,CAAC"}
@@ -1,10 +1,41 @@
1
1
  import { useLayoutEffect, useState } from "react";
2
2
  import { getModalOverlayRootUpTo, getTopModalOverlayRoot, subscribeToModalRoots } from "./modalRootStack";
3
+ const getScrollPositions = host => Array.from(host.querySelectorAll("*")).filter(element => element.scrollTop || element.scrollLeft).map(element => ({
4
+ element,
5
+ top: element.scrollTop,
6
+ left: element.scrollLeft
7
+ }));
8
+
9
+ /**
10
+ * moveBefore keeps the state of the moved content. appendChild resets the scroll positions inside the host and drops
11
+ * the focus, so without moveBefore they are put back after the move.
12
+ */
13
+ const moveHost = (host, target) => {
14
+ if (host.isConnected && target.moveBefore) {
15
+ target.moveBefore(host, null);
16
+ return;
17
+ }
18
+ const scrollPositions = host.isConnected ? getScrollPositions(host) : [];
19
+ const focused = host.contains(document.activeElement) ? document.activeElement : null;
20
+ target.appendChild(host);
21
+ scrollPositions.forEach(_ref => {
22
+ let element = _ref.element,
23
+ top = _ref.top,
24
+ left = _ref.left;
25
+ element.scrollTop = top;
26
+ element.scrollLeft = left;
27
+ });
28
+ focused == null || focused.focus({
29
+ preventScroll: true
30
+ });
31
+ };
3
32
 
4
33
  /**
5
34
  * Keeps a host node in the overlay root of the top open modal, or of the top one opened no later than
6
- * upToModalRootId, and in document.body while there is none. The node moves as modals open and close, so content
7
- * portalled into it never remounts, and it leaves the page on unmount or when the host changes. Returns whether the
35
+ * upToModalRootId, and in document.body while there is none. A modal opened from the content of the host is not
36
+ * counted, since its overlay root is inside the host. The node moves as modals open and close, so content
37
+ * portalled into it never remounts and keeps its scroll positions and focus, and it leaves the page on unmount or
38
+ * when the host changes. Returns whether the
8
39
  * host is in the page, which it is from a layout effect after the first render with it.
9
40
  */
10
41
  export const useModalStackHost = (host, upToModalRootId) => {
@@ -16,10 +47,10 @@ export const useModalStackHost = (host, upToModalRootId) => {
16
47
  return undefined;
17
48
  }
18
49
  const place = () => {
19
- var _ref;
20
- const target = (_ref = upToModalRootId === undefined ? getTopModalOverlayRoot() : getModalOverlayRootUpTo(upToModalRootId)) != null ? _ref : document.body;
50
+ var _ref2;
51
+ const target = (_ref2 = upToModalRootId === undefined ? getTopModalOverlayRoot(host) : getModalOverlayRootUpTo(upToModalRootId, host)) != null ? _ref2 : document.body;
21
52
  if (host.parentElement !== target) {
22
- target.appendChild(host);
53
+ moveHost(host, target);
23
54
  }
24
55
  };
25
56
  place();
@@ -1 +1 @@
1
- {"version":3,"file":"useModalStackHost.js","names":["useLayoutEffect","useState","getModalOverlayRootUpTo","getTopModalOverlayRoot","subscribeToModalRoots","useModalStackHost","host","upToModalRootId","_useState","placedHost","setPlacedHost","undefined","place","_ref","target","document","body","parentElement","appendChild","unsubscribe","remove"],"sources":["../../../../src/components/ModalRoot/useModalStackHost.ts"],"sourcesContent":["import { useLayoutEffect, useState } from \"react\";\n\nimport {\n getModalOverlayRootUpTo,\n getTopModalOverlayRoot,\n subscribeToModalRoots,\n} from \"./modalRootStack\";\n\n/**\n * Keeps a host node in the overlay root of the top open modal, or of the top one opened no later than\n * upToModalRootId, and in document.body while there is none. The node moves as modals open and close, so content\n * portalled into it never remounts, and it leaves the page on unmount or when the host changes. Returns whether the\n * host is in the page, which it is from a layout effect after the first render with it.\n */\nexport const useModalStackHost = (\n host: HTMLElement | null,\n upToModalRootId?: number\n): boolean => {\n const [placedHost, setPlacedHost] = useState<HTMLElement | null>(null);\n\n useLayoutEffect(() => {\n if (!host) {\n return undefined;\n }\n\n const place = () => {\n const target =\n (upToModalRootId === undefined\n ? getTopModalOverlayRoot()\n : getModalOverlayRootUpTo(upToModalRootId)) ?? document.body;\n\n if (host.parentElement !== target) {\n target.appendChild(host);\n }\n };\n\n place();\n setPlacedHost(host);\n\n const unsubscribe = subscribeToModalRoots(place);\n\n return () => {\n unsubscribe();\n host.remove();\n };\n }, [host, upToModalRootId]);\n\n return host !== null && placedHost === host;\n};\n"],"mappings":"AAAA,SAASA,eAAe,EAAEC,QAAQ,QAAQ,OAAO;AAEjD,SACEC,uBAAuB,EACvBC,sBAAsB,EACtBC,qBAAqB,QAChB,kBAAkB;;AAEzB;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,iBAAiB,GAAGA,CAC/BC,IAAwB,EACxBC,eAAwB,KACZ;EACZ,MAAAC,SAAA,GAAoCP,QAAQ,CAAqB,IAAI,CAAC;IAA/DQ,UAAU,GAAAD,SAAA;IAAEE,aAAa,GAAAF,SAAA;EAEhCR,eAAe,CAAC,MAAM;IACpB,IAAI,CAACM,IAAI,EAAE;MACT,OAAOK,SAAS;IAClB;IAEA,MAAMC,KAAK,GAAGA,CAAA,KAAM;MAAA,IAAAC,IAAA;MAClB,MAAMC,MAAM,IAAAD,IAAA,GACTN,eAAe,KAAKI,SAAS,GAC1BR,sBAAsB,CAAC,CAAC,GACxBD,uBAAuB,CAACK,eAAe,CAAC,YAAAM,IAAA,GAAKE,QAAQ,CAACC,IAAI;MAEhE,IAAIV,IAAI,CAACW,aAAa,KAAKH,MAAM,EAAE;QACjCA,MAAM,CAACI,WAAW,CAACZ,IAAI,CAAC;MAC1B;IACF,CAAC;IAEDM,KAAK,CAAC,CAAC;IACPF,aAAa,CAACJ,IAAI,CAAC;IAEnB,MAAMa,WAAW,GAAGf,qBAAqB,CAACQ,KAAK,CAAC;IAEhD,OAAO,MAAM;MACXO,WAAW,CAAC,CAAC;MACbb,IAAI,CAACc,MAAM,CAAC,CAAC;IACf,CAAC;EACH,CAAC,EAAE,CAACd,IAAI,EAAEC,eAAe,CAAC,CAAC;EAE3B,OAAOD,IAAI,KAAK,IAAI,IAAIG,UAAU,KAAKH,IAAI;AAC7C,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"useModalStackHost.js","names":["useLayoutEffect","useState","getModalOverlayRootUpTo","getTopModalOverlayRoot","subscribeToModalRoots","getScrollPositions","host","Array","from","querySelectorAll","filter","element","scrollTop","scrollLeft","map","top","left","moveHost","target","isConnected","moveBefore","scrollPositions","focused","contains","document","activeElement","appendChild","forEach","_ref","focus","preventScroll","useModalStackHost","upToModalRootId","_useState","placedHost","setPlacedHost","undefined","place","_ref2","body","parentElement","unsubscribe","remove"],"sources":["../../../../src/components/ModalRoot/useModalStackHost.ts"],"sourcesContent":["import { useLayoutEffect, useState } from \"react\";\n\nimport {\n getModalOverlayRootUpTo,\n getTopModalOverlayRoot,\n subscribeToModalRoots,\n} from \"./modalRootStack\";\n\ntype MovableParent = HTMLElement & {\n moveBefore?: (node: Node, child: Node | null) => void;\n};\n\nconst getScrollPositions = (host: HTMLElement) =>\n Array.from(host.querySelectorAll<HTMLElement>(\"*\"))\n .filter((element) => element.scrollTop || element.scrollLeft)\n .map((element) => ({\n element,\n top: element.scrollTop,\n left: element.scrollLeft,\n }));\n\n/**\n * moveBefore keeps the state of the moved content. appendChild resets the scroll positions inside the host and drops\n * the focus, so without moveBefore they are put back after the move.\n */\nconst moveHost = (host: HTMLElement, target: MovableParent) => {\n if (host.isConnected && target.moveBefore) {\n target.moveBefore(host, null);\n\n return;\n }\n\n const scrollPositions = host.isConnected ? getScrollPositions(host) : [];\n const focused = host.contains(document.activeElement)\n ? (document.activeElement as HTMLElement)\n : null;\n\n target.appendChild(host);\n\n scrollPositions.forEach(({ element, top, left }) => {\n element.scrollTop = top;\n element.scrollLeft = left;\n });\n focused?.focus({ preventScroll: true });\n};\n\n/**\n * Keeps a host node in the overlay root of the top open modal, or of the top one opened no later than\n * upToModalRootId, and in document.body while there is none. A modal opened from the content of the host is not\n * counted, since its overlay root is inside the host. The node moves as modals open and close, so content\n * portalled into it never remounts and keeps its scroll positions and focus, and it leaves the page on unmount or\n * when the host changes. Returns whether the\n * host is in the page, which it is from a layout effect after the first render with it.\n */\nexport const useModalStackHost = (\n host: HTMLElement | null,\n upToModalRootId?: number\n): boolean => {\n const [placedHost, setPlacedHost] = useState<HTMLElement | null>(null);\n\n useLayoutEffect(() => {\n if (!host) {\n return undefined;\n }\n\n const place = () => {\n const target =\n (upToModalRootId === undefined\n ? getTopModalOverlayRoot(host)\n : getModalOverlayRootUpTo(upToModalRootId, host)) ?? document.body;\n\n if (host.parentElement !== target) {\n moveHost(host, target);\n }\n };\n\n place();\n setPlacedHost(host);\n\n const unsubscribe = subscribeToModalRoots(place);\n\n return () => {\n unsubscribe();\n host.remove();\n };\n }, [host, upToModalRootId]);\n\n return host !== null && placedHost === host;\n};\n"],"mappings":"AAAA,SAASA,eAAe,EAAEC,QAAQ,QAAQ,OAAO;AAEjD,SACEC,uBAAuB,EACvBC,sBAAsB,EACtBC,qBAAqB,QAChB,kBAAkB;AAMzB,MAAMC,kBAAkB,GAAIC,IAAiB,IAC3CC,KAAK,CAACC,IAAI,CAACF,IAAI,CAACG,gBAAgB,CAAc,GAAG,CAAC,CAAC,CAChDC,MAAM,CAAEC,OAAO,IAAKA,OAAO,CAACC,SAAS,IAAID,OAAO,CAACE,UAAU,CAAC,CAC5DC,GAAG,CAAEH,OAAO,KAAM;EACjBA,OAAO;EACPI,GAAG,EAAEJ,OAAO,CAACC,SAAS;EACtBI,IAAI,EAAEL,OAAO,CAACE;AAChB,CAAC,CAAC,CAAC;;AAEP;AACA;AACA;AACA;AACA,MAAMI,QAAQ,GAAGA,CAACX,IAAiB,EAAEY,MAAqB,KAAK;EAC7D,IAAIZ,IAAI,CAACa,WAAW,IAAID,MAAM,CAACE,UAAU,EAAE;IACzCF,MAAM,CAACE,UAAU,CAACd,IAAI,EAAE,IAAI,CAAC;IAE7B;EACF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ACjCD,QAAQ,CAACX,IAAI,EAAEY,MAAM,CAAC;MACxB;IACF,CAAC;IAEDmB,KAAK,CAAC,CAAC;IACPF,aAAa,CAAC7B,IAAI,CAAC;IAEnB,MAAMmC,WAAW,GAAGrC,qBAAqB,CAACiC,KAAK,CAAC;IAEhD,OAAO,MAAM;MACXI,WAAW,CAAC,CAAC;MACbnC,IAAI,CAACoC,MAAM,CAAC,CAAC;IACf,CAAC;EACH,CAAC,EAAE,CAACpC,IAAI,EAAE0B,eAAe,CAAC,CAAC;EAE3B,OAAO1B,IAAI,KAAK,IAAI,IAAI4B,UAAU,KAAK5B,IAAI;AAC7C,CAAC","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"Window.d.ts","sourceRoot":"","sources":["../../../../src/components/Window/Window.tsx"],"names":[],"mappings":"AAAA,OAAO,KAMN,MAAM,OAAO,CAAC;AAWf,MAAM,WAAW,OAAO;IACtB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,gEAAgE;IAChE,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,mFAAmF;IACnF,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAID,eAAO,MAAM,MAAM,kMA0GlB,CAAC"}
1
+ {"version":3,"file":"Window.d.ts","sourceRoot":"","sources":["../../../../src/components/Window/Window.tsx"],"names":[],"mappings":"AAAA,OAAO,KAMN,MAAM,OAAO,CAAC;AAWf,MAAM,WAAW,OAAO;IACtB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,gEAAgE;IAChE,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,mFAAmF;IACnF,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAID,eAAO,MAAM,MAAM,kMAmHlB,CAAC"}
@@ -64,13 +64,21 @@ export const Window = /*#__PURE__*/forwardRef((_ref, ref) => {
64
64
  document.addEventListener("keydown", handleBodyKeyDown);
65
65
  return () => document.removeEventListener("keydown", handleBodyKeyDown);
66
66
  }, [disableCloseOnEsc, onClose]);
67
+
68
+ // A native modal dialog this window is not inside sits above it in the top layer and leaves it inert, such as a
69
+ // confirmation rendered outside the window's React tree. Focus in that dialog is the dialog's, so the lock lets it be.
70
+ const isFocusForLock = useCallback(node => {
71
+ const modalDialog = node.closest("dialog[open]");
72
+ return !modalDialog || modalDialog.contains(innerRef.current);
73
+ }, []);
67
74
  const handleClick = useCallback(event => {
68
75
  event == null || event.stopPropagation();
69
76
  typeof onClick === "function" && onClick(event);
70
77
  }, [onClick]);
71
78
  return /*#__PURE__*/React.createElement(Portal, null, /*#__PURE__*/React.createElement(FocusLock, {
72
79
  returnFocus: disableReturnFocus ? false : returnFocus,
73
- disabled: disableFocusLock
80
+ disabled: disableFocusLock,
81
+ whiteList: isFocusForLock
74
82
  }, /*#__PURE__*/React.createElement(RemoveScroll, {
75
83
  forwardProps: true,
76
84
  ref: handleRef,
@@ -1 +1 @@
1
- {"version":3,"file":"Window.js","names":["React","useCallback","useEffect","useRef","forwardRef","FocusLock","RemoveScroll","classnames","StyledWindow","Portal","useLayerContext","getTopLayer","layers","useForkRef","returnFocus","preventScroll","Window","_ref","ref","children","onClose","className","style","onKeyDown","_ref$disableFocusLock","disableFocusLock","_ref$disableScrollLoc","disableScrollLock","_ref$disableCloseOnEs","disableCloseOnEsc","_ref$disableReturnFoc","disableReturnFocus","_ref$isolateScroll","isolateScroll","onClick","rest","_objectWithoutPropertiesLoose","_excluded","innerRef","handleRef","_useLayerContext","_useLayerContext$zInd","zIndex","skyscraper","handleKeyDown","event","defaultPrevented","key","preventDefault","stopPropagation","undefined","handleBodyKeyDown","isTopWindow","current","target","document","body","addEventListener","removeEventListener","handleClick","createElement","disabled","forwardProps","enabled","noIsolation","_extends","tabIndex","displayName"],"sources":["../../../../src/components/Window/Window.tsx"],"sourcesContent":["import React, {\n useCallback,\n useEffect,\n useRef,\n forwardRef,\n KeyboardEvent,\n} from \"react\";\nimport FocusLock from \"react-focus-lock\";\nimport { RemoveScroll } from \"react-remove-scroll\";\n\nimport classnames from \"classnames\";\n\nimport { StyledWindow } from \"./Style\";\nimport { Portal, useLayerContext } from \"../../helpers\";\nimport { getTopLayer, layers } from \"../../utils\";\nimport useForkRef from \"../../utils/useForkRef\";\n\nexport interface IWindow {\n onClose?: () => void;\n disableFocusLock?: boolean;\n disableScrollLock?: boolean;\n disableCloseOnEsc?: boolean;\n /** Leave the focus where it is when the focus lock turns off */\n disableReturnFocus?: boolean;\n /** With the scroll lock on, also stop the scroll that starts outside the window */\n isolateScroll?: boolean;\n}\n\nconst returnFocus = { preventScroll: true };\n\nexport const Window = forwardRef<\n HTMLDivElement,\n IWindow & Omit<React.ComponentPropsWithoutRef<\"div\">, keyof IWindow>\n>(\n (\n {\n children,\n onClose,\n className,\n style,\n onKeyDown,\n disableFocusLock = false,\n disableScrollLock = false,\n disableCloseOnEsc = false,\n disableReturnFocus = false,\n isolateScroll = false,\n onClick,\n ...rest\n },\n ref\n ) => {\n const innerRef = useRef<HTMLDivElement>(null);\n const handleRef = useForkRef(innerRef, ref);\n const { zIndex = layers.skyscraper } = useLayerContext();\n\n const handleKeyDown = useCallback(\n (event: KeyboardEvent<HTMLDivElement>) => {\n if (\n !event.defaultPrevented &&\n (event.key === \"Esc\" || event.key === \"Escape\") &&\n !disableCloseOnEsc\n ) {\n event.preventDefault();\n event.stopPropagation();\n if (onClose) {\n onClose();\n }\n }\n if (typeof onKeyDown === \"function\") {\n onKeyDown(event);\n }\n },\n [disableCloseOnEsc, onClose, onKeyDown]\n );\n\n // Focus that falls to the body, when the focused node unmounts, sends no key to the window.\n useEffect(() => {\n if (disableCloseOnEsc || !onClose) {\n return undefined;\n }\n\n const handleBodyKeyDown = (event: globalThis.KeyboardEvent) => {\n // A window or a native modal dialog opened above this one takes the Escape.\n const isTopWindow = getTopLayer() === innerRef.current;\n\n if (\n event.target === document.body &&\n !event.defaultPrevented &&\n (event.key === \"Esc\" || event.key === \"Escape\") &&\n isTopWindow\n ) {\n event.preventDefault();\n onClose();\n }\n };\n\n document.addEventListener(\"keydown\", handleBodyKeyDown);\n\n return () => document.removeEventListener(\"keydown\", handleBodyKeyDown);\n }, [disableCloseOnEsc, onClose]);\n\n const handleClick = useCallback(\n (event) => {\n event?.stopPropagation();\n typeof onClick === \"function\" && onClick(event);\n },\n [onClick]\n );\n\n return (\n <Portal>\n <FocusLock\n returnFocus={disableReturnFocus ? false : returnFocus}\n disabled={disableFocusLock}\n >\n <RemoveScroll\n forwardProps\n ref={handleRef}\n enabled={!disableScrollLock}\n noIsolation={!isolateScroll}\n >\n <StyledWindow\n {...rest}\n style={{ zIndex, ...style }}\n onKeyDown={handleKeyDown}\n tabIndex={0}\n className={classnames(\"c-window\", className)}\n onClick={handleClick}\n >\n {children}\n </StyledWindow>\n </RemoveScroll>\n </FocusLock>\n </Portal>\n );\n }\n);\n\nWindow.displayName = \"Window\";\n"],"mappings":";;;AAAA,OAAOA,KAAK,IACVC,WAAW,EACXC,SAAS,EACTC,MAAM,EACNC,UAAU,QAEL,OAAO;AACd,OAAOC,SAAS,MAAM,kBAAkB;AACxC,SAASC,YAAY,QAAQ,qBAAqB;AAElD,OAAOC,UAAU,MAAM,YAAY;AAEnC,SAASC,YAAY,QAAQ,SAAS;AACtC,SAASC,MAAM,EAAEC,eAAe,QAAQ,eAAe;AACvD,SAASC,WAAW,EAAEC,MAAM,QAAQ,aAAa;AACjD,OAAOC,UAAU,MAAM,wBAAwB;AAa/C,MAAMC,WAAW,GAAG;EAAEC,aAAa,EAAE;AAAK,CAAC;AAE3C,OAAO,MAAMC,MAAM,gBAAGZ,UAAU,CAI9B,CAAA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ACjD,CAAC,EACD,CAACX,OAAO,CACV,CAAC;EAED,oBACElC,KAAA,CAAA4D,aAAA,CAACnD,MAAM,qBACLT,KAAA,CAAA4D,aAAA,CAACvD,SAAS;IACRS,WAAW,EAAEiB,kBAAkB,GAAG,KAAK,GAAGjB,WAAY;IACtD+C,QAAQ,EAAEpC;EAAiB,gBAE3BzB,KAAA,CAAA4D,aAAA,CAACtD,YAAY;IACXwD,YAAY;IACZ5C,GAAG,EAAEqB,SAAU;IACfwB,OAAO,EAAE,CAACpC,iBAAkB;IAC5BqC,WAAW,EAAE,CAAC/B;EAAc,gBAE5BjC,KAAA,CAAA4D,aAAA,CAACpD,YAAY,EAAAyD,QAAA,KACP9B,IAAI;IACRb,KAAK,EAAA2C,QAAA;MAAIvB;IAAM,GAAKpB,KAAK,CAAG;IAC5BC,SAAS,EAAEqB,aAAc;IACzBsB,QAAQ,EAAE,CAAE;IACZ7C,SAAS,EAAEd,UAAU,CAAC,UAAU,EAAEc,SAAS,CAAE;IAC7Ca,OAAO,EAAEyB;EAAY,IAEpBxC,QACW,CACF,CACL,CACL,CAAC;AAEb,CACF,CAAC;AAEDH,MAAM,CAACmD,WAAW,GAAG,QAAQ","ignoreList":[]}
1
+ {"version":3,"file":"Window.js","names":["React","useCallback","useEffect","useRef","forwardRef","FocusLock","RemoveScroll","classnames","StyledWindow","Portal","useLayerContext","getTopLayer","layers","useForkRef","returnFocus","preventScroll","Window","_ref","ref","children","onClose","className","style","onKeyDown","_ref$disableFocusLock","disableFocusLock","_ref$disableScrollLoc","disableScrollLock","_ref$disableCloseOnEs","disableCloseOnEsc","_ref$disableReturnFoc","disableReturnFocus","_ref$isolateScroll","isolateScroll","onClick","rest","_objectWithoutPropertiesLoose","_excluded","innerRef","handleRef","_useLayerContext","_useLayerContext$zInd","zIndex","skyscraper","handleKeyDown","event","defaultPrevented","key","preventDefault","stopPropagation","undefined","handleBodyKeyDown","isTopWindow","current","target","document","body","addEventListener","removeEventListener","isFocusForLock","node","modalDialog","closest","contains","handleClick","createElement","disabled","whiteList","forwardProps","enabled","noIsolation","_extends","tabIndex","displayName"],"sources":["../../../../src/components/Window/Window.tsx"],"sourcesContent":["import React, {\n useCallback,\n useEffect,\n useRef,\n forwardRef,\n KeyboardEvent,\n} from \"react\";\nimport FocusLock from \"react-focus-lock\";\nimport { RemoveScroll } from \"react-remove-scroll\";\n\nimport classnames from \"classnames\";\n\nimport { StyledWindow } from \"./Style\";\nimport { Portal, useLayerContext } from \"../../helpers\";\nimport { getTopLayer, layers } from \"../../utils\";\nimport useForkRef from \"../../utils/useForkRef\";\n\nexport interface IWindow {\n onClose?: () => void;\n disableFocusLock?: boolean;\n disableScrollLock?: boolean;\n disableCloseOnEsc?: boolean;\n /** Leave the focus where it is when the focus lock turns off */\n disableReturnFocus?: boolean;\n /** With the scroll lock on, also stop the scroll that starts outside the window */\n isolateScroll?: boolean;\n}\n\nconst returnFocus = { preventScroll: true };\n\nexport const Window = forwardRef<\n HTMLDivElement,\n IWindow & Omit<React.ComponentPropsWithoutRef<\"div\">, keyof IWindow>\n>(\n (\n {\n children,\n onClose,\n className,\n style,\n onKeyDown,\n disableFocusLock = false,\n disableScrollLock = false,\n disableCloseOnEsc = false,\n disableReturnFocus = false,\n isolateScroll = false,\n onClick,\n ...rest\n },\n ref\n ) => {\n const innerRef = useRef<HTMLDivElement>(null);\n const handleRef = useForkRef(innerRef, ref);\n const { zIndex = layers.skyscraper } = useLayerContext();\n\n const handleKeyDown = useCallback(\n (event: KeyboardEvent<HTMLDivElement>) => {\n if (\n !event.defaultPrevented &&\n (event.key === \"Esc\" || event.key === \"Escape\") &&\n !disableCloseOnEsc\n ) {\n event.preventDefault();\n event.stopPropagation();\n if (onClose) {\n onClose();\n }\n }\n if (typeof onKeyDown === \"function\") {\n onKeyDown(event);\n }\n },\n [disableCloseOnEsc, onClose, onKeyDown]\n );\n\n // Focus that falls to the body, when the focused node unmounts, sends no key to the window.\n useEffect(() => {\n if (disableCloseOnEsc || !onClose) {\n return undefined;\n }\n\n const handleBodyKeyDown = (event: globalThis.KeyboardEvent) => {\n // A window or a native modal dialog opened above this one takes the Escape.\n const isTopWindow = getTopLayer() === innerRef.current;\n\n if (\n event.target === document.body &&\n !event.defaultPrevented &&\n (event.key === \"Esc\" || event.key === \"Escape\") &&\n isTopWindow\n ) {\n event.preventDefault();\n onClose();\n }\n };\n\n document.addEventListener(\"keydown\", handleBodyKeyDown);\n\n return () => document.removeEventListener(\"keydown\", handleBodyKeyDown);\n }, [disableCloseOnEsc, onClose]);\n\n // A native modal dialog this window is not inside sits above it in the top layer and leaves it inert, such as a\n // confirmation rendered outside the window's React tree. Focus in that dialog is the dialog's, so the lock lets it be.\n const isFocusForLock = useCallback((node: HTMLElement) => {\n const modalDialog = node.closest(\"dialog[open]\");\n\n return !modalDialog || modalDialog.contains(innerRef.current);\n }, []);\n\n const handleClick = useCallback(\n (event) => {\n event?.stopPropagation();\n typeof onClick === \"function\" && onClick(event);\n },\n [onClick]\n );\n\n return (\n <Portal>\n <FocusLock\n returnFocus={disableReturnFocus ? false : returnFocus}\n disabled={disableFocusLock}\n whiteList={isFocusForLock}\n >\n <RemoveScroll\n forwardProps\n ref={handleRef}\n enabled={!disableScrollLock}\n noIsolation={!isolateScroll}\n >\n <StyledWindow\n {...rest}\n style={{ zIndex, ...style }}\n onKeyDown={handleKeyDown}\n tabIndex={0}\n className={classnames(\"c-window\", className)}\n onClick={handleClick}\n >\n {children}\n </StyledWindow>\n </RemoveScroll>\n </FocusLock>\n </Portal>\n );\n }\n);\n\nWindow.displayName = \"Window\";\n"],"mappings":";;;AAAA,OAAOA,KAAK,IACVC,WAAW,EACXC,SAAS,EACTC,MAAM,EACNC,UAAU,QAEL,OAAO;AACd,OAAOC,SAAS,MAAM,kBAAkB;AACxC,SAASC,YAAY,QAAQ,qBAAqB;AAElD,OAAOC,UAAU,MAAM,YAAY;AAEnC,SAASC,YAAY,QAAQ,SAAS;AACtC,SAASC,MAAM,EAAEC,eAAe,QAAQ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