@simplybusiness/mobius 4.4.0 → 4.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.4.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 5d126f3: Move @swc/cli from dependencies to devDependencies
8
+
9
+ ## 4.4.1
10
+
11
+ ### Patch Changes
12
+
13
+ - 10a1de9: Fix `<Drawer>` closing transition occasionally not firing
14
+
3
15
  ## 4.4.0
4
16
 
5
17
  ### Minor Changes
@@ -82,20 +82,26 @@ const Drawer = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
82
82
  event.preventDefault();
83
83
  event.stopPropagation();
84
84
  }
85
+ // Name the callback function, so we can add and remove event listener
86
+ const transitionCallback = (e)=>{
87
+ // Close drawer only if the transition is on the dialog element
88
+ // As it can be on a child element (ie `<Button>` inside the drawer)
89
+ if (e.target === modalRef.current) {
90
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
91
+ doClose();
92
+ }
93
+ };
85
94
  const doClose = ()=>{
86
- var _modalRef_current;
95
+ var _modalRef_current, _modalRef_current1;
87
96
  (_modalRef_current = modalRef.current) === null || _modalRef_current === void 0 ? void 0 : _modalRef_current.close();
88
97
  onClose === null || onClose === void 0 ? void 0 : onClose();
98
+ (_modalRef_current1 = modalRef.current) === null || _modalRef_current1 === void 0 ? void 0 : _modalRef_current1.removeEventListener("transitionend", transitionCallback);
89
99
  };
90
100
  // Delay close to allow backdrop exit transition
91
101
  if (hasDialogSupport) {
92
102
  var _modalRef_current, _modalRef_current1;
93
103
  (_modalRef_current = modalRef.current) === null || _modalRef_current === void 0 ? void 0 : _modalRef_current.classList.remove(TRANSITION_CLASS_NAME);
94
- (_modalRef_current1 = modalRef.current) === null || _modalRef_current1 === void 0 ? void 0 : _modalRef_current1.addEventListener("transitionend", ()=>{
95
- doClose();
96
- }, {
97
- once: true
98
- });
104
+ (_modalRef_current1 = modalRef.current) === null || _modalRef_current1 === void 0 ? void 0 : _modalRef_current1.addEventListener("transitionend", transitionCallback);
99
105
  } else {
100
106
  doClose();
101
107
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/Drawer/Drawer.tsx"],"sourcesContent":["\"use client\";\n\nimport classNames from \"classnames/dedupe\";\nimport {\n Children,\n Ref,\n SyntheticEvent,\n cloneElement,\n forwardRef,\n isValidElement,\n useCallback,\n useEffect,\n useRef,\n} from \"react\";\nimport { useBodyScrollLock } from \"../../hooks/useBodyScrollLock\";\nimport { supportsDialog } from \"../../utils/polyfill-tests\";\nimport { VisuallyHidden } from \"../VisuallyHidden\";\nimport { DrawerProps } from \"./types\";\nimport { mergeRefs } from \"../../utils\";\n\nexport type DialogElementType = HTMLDialogElement;\nexport type DialogRef = Ref<DialogElementType>;\n\nconst TRANSITION_CLASS_NAME = \"--transition\";\n\nconst Drawer = forwardRef((props: DrawerProps, ref: DialogRef) => {\n const {\n isOpen,\n className,\n closeLabel,\n direction,\n announce = \"Drawer opened on screen\",\n onOpen,\n onClose,\n children,\n } = props;\n const hasOpened = useRef<boolean>(false);\n const modalRef = useRef<HTMLDialogElement | null>(null);\n const hasDialogSupport = supportsDialog();\n\n // Fire onOpen once\n if (onOpen && !hasOpened.current) {\n onOpen();\n hasOpened.current = true;\n }\n\n useBodyScrollLock({ enabled: isOpen });\n\n // Add close handler, to enable closing transitions\n const handleClose = useCallback(\n (event?: SyntheticEvent<HTMLElement, Event>) => {\n if (event) {\n event.preventDefault();\n event.stopPropagation();\n }\n\n const doClose = () => {\n modalRef.current?.close();\n onClose?.();\n };\n\n // Delay close to allow backdrop exit transition\n if (hasDialogSupport) {\n modalRef.current?.classList.remove(TRANSITION_CLASS_NAME);\n modalRef.current?.addEventListener(\n \"transitionend\",\n () => {\n doClose();\n },\n { once: true },\n );\n } else {\n doClose();\n }\n },\n [onClose, hasDialogSupport],\n );\n\n const modalClasses = classNames(\n \"mobius\",\n \"mobius/Drawer\",\n `--${direction}`,\n className,\n {\n \"--should-transition\": hasDialogSupport,\n },\n );\n\n // Add polyfill for HTML Dialog in old browsers\n useEffect(() => {\n async function toggleModal() {\n if (\n !hasDialogSupport &&\n typeof window !== \"undefined\" &&\n modalRef.current !== null\n ) {\n // eslint-disable-next-line import/no-extraneous-dependencies\n const { default: dialogPolyfill } = await import(\"dialog-polyfill\");\n try {\n dialogPolyfill.registerDialog(modalRef.current);\n } catch (error) {\n // In iOS 15 <= 15.2 this intermittently fails with\n // TypeError: null is not an object (evaluating 'element.showModal')\n // Checking showModal presence through hasOwnProperty is falsy natively, truthy with polyfill 🤷🏼‍♂️\n console.error(\"Failed to load dialog-polyfill\", error);\n }\n }\n\n if (isOpen && !modalRef.current?.open) {\n modalRef.current?.showModal();\n modalRef.current?.classList.add(TRANSITION_CLASS_NAME);\n onOpen?.();\n } else if (!isOpen && modalRef.current?.open) {\n handleClose();\n }\n }\n\n toggleModal();\n }, [isOpen, onOpen, handleClose, hasDialogSupport]);\n\n return (\n <dialog\n ref={mergeRefs([modalRef, ref])}\n onCancel={handleClose}\n className={modalClasses}\n aria-describedby=\"screen-reader-announce\"\n >\n <VisuallyHidden>\n <div id=\"screen-reader-announce\">{announce}</div>\n </VisuallyHidden>\n {Children.map(children, child => {\n if (isValidElement(child)) {\n return cloneElement(child, {\n onClose: handleClose,\n closeLabel,\n } as any);\n }\n\n return child;\n })}\n </dialog>\n );\n});\n\nDrawer.displayName = \"Drawer\";\nexport { Drawer };\n"],"names":["Drawer","TRANSITION_CLASS_NAME","forwardRef","props","ref","isOpen","className","closeLabel","direction","announce","onOpen","onClose","children","hasOpened","useRef","modalRef","hasDialogSupport","supportsDialog","current","useBodyScrollLock","enabled","handleClose","useCallback","event","preventDefault","stopPropagation","doClose","close","classList","remove","addEventListener","once","modalClasses","classNames","useEffect","toggleModal","window","default","dialogPolyfill","registerDialog","error","console","open","showModal","add","dialog","mergeRefs","onCancel","aria-describedby","VisuallyHidden","div","id","Children","map","child","isValidElement","cloneElement","displayName"],"mappings":"AAAA;;;;;+BAiJSA;;;eAAAA;;;;+DA/Ic;uBAWhB;mCAC2B;+BACH;gCACA;uBAEL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAK1B,MAAMC,wBAAwB;AAE9B,MAAMD,uBAASE,IAAAA,iBAAU,EAAC,CAACC,OAAoBC;IAC7C,MAAM,EACJC,MAAM,EACNC,SAAS,EACTC,UAAU,EACVC,SAAS,EACTC,WAAW,yBAAyB,EACpCC,MAAM,EACNC,OAAO,EACPC,QAAQ,EACT,GAAGT;IACJ,MAAMU,YAAYC,IAAAA,aAAM,EAAU;IAClC,MAAMC,WAAWD,IAAAA,aAAM,EAA2B;IAClD,MAAME,mBAAmBC,IAAAA,6BAAc;IAEvC,mBAAmB;IACnB,IAAIP,UAAU,CAACG,UAAUK,OAAO,EAAE;QAChCR;QACAG,UAAUK,OAAO,GAAG;IACtB;IAEAC,IAAAA,oCAAiB,EAAC;QAAEC,SAASf;IAAO;IAEpC,mDAAmD;IACnD,MAAMgB,cAAcC,IAAAA,kBAAW,EAC7B,CAACC;QACC,IAAIA,OAAO;YACTA,MAAMC,cAAc;YACpBD,MAAME,eAAe;QACvB;QAEA,MAAMC,UAAU;gBACdX;aAAAA,oBAAAA,SAASG,OAAO,cAAhBH,wCAAAA,kBAAkBY,KAAK;YACvBhB,oBAAAA,8BAAAA;QACF;QAEA,gDAAgD;QAChD,IAAIK,kBAAkB;gBACpBD,mBACAA;aADAA,oBAAAA,SAASG,OAAO,cAAhBH,wCAAAA,kBAAkBa,SAAS,CAACC,MAAM,CAAC5B;aACnCc,qBAAAA,SAASG,OAAO,cAAhBH,yCAAAA,mBAAkBe,gBAAgB,CAChC,iBACA;gBACEJ;YACF,GACA;gBAAEK,MAAM;YAAK;QAEjB,OAAO;YACLL;QACF;IACF,GACA;QAACf;QAASK;KAAiB;IAG7B,MAAMgB,eAAeC,I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oBACzB,qBAAOE,IAAAA,mBAAY,EAACF,OAAO;wBACzB3C,SAASU;wBACTd;oBACF;gBACF;gBAEA,OAAO+C;YACT;;;AAGN;AAEAtD,OAAOyD,WAAW,GAAG"}
1
+ {"version":3,"sources":["../../../../src/components/Drawer/Drawer.tsx"],"sourcesContent":["\"use client\";\n\nimport classNames from \"classnames/dedupe\";\nimport {\n Children,\n Ref,\n SyntheticEvent,\n cloneElement,\n forwardRef,\n isValidElement,\n useCallback,\n useEffect,\n useRef,\n} from \"react\";\nimport { useBodyScrollLock } from \"../../hooks/useBodyScrollLock\";\nimport { supportsDialog } from \"../../utils/polyfill-tests\";\nimport { VisuallyHidden } from \"../VisuallyHidden\";\nimport { DrawerProps } from \"./types\";\nimport { mergeRefs } from \"../../utils\";\n\nexport type DialogElementType = HTMLDialogElement;\nexport type DialogRef = Ref<DialogElementType>;\n\nconst TRANSITION_CLASS_NAME = \"--transition\";\n\nconst Drawer = forwardRef((props: DrawerProps, ref: DialogRef) => {\n const {\n isOpen,\n className,\n closeLabel,\n direction,\n announce = \"Drawer opened on screen\",\n onOpen,\n onClose,\n children,\n } = props;\n const hasOpened = useRef<boolean>(false);\n const modalRef = useRef<HTMLDialogElement | null>(null);\n const hasDialogSupport = supportsDialog();\n\n // Fire onOpen once\n if (onOpen && !hasOpened.current) {\n onOpen();\n hasOpened.current = true;\n }\n\n useBodyScrollLock({ enabled: isOpen });\n\n // Add close handler, to enable closing transitions\n const handleClose = useCallback(\n (event?: SyntheticEvent<HTMLElement, Event>) => {\n if (event) {\n event.preventDefault();\n event.stopPropagation();\n }\n\n // Name the callback function, so we can add and remove event listener\n const transitionCallback = (e: Event) => {\n // Close drawer only if the transition is on the dialog element\n // As it can be on a child element (ie `<Button>` inside the drawer)\n if (e.target === modalRef.current) {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n doClose();\n }\n };\n\n const doClose = () => {\n modalRef.current?.close();\n onClose?.();\n modalRef.current?.removeEventListener(\n \"transitionend\",\n transitionCallback,\n );\n };\n\n // Delay close to allow backdrop exit transition\n if (hasDialogSupport) {\n modalRef.current?.classList.remove(TRANSITION_CLASS_NAME);\n modalRef.current?.addEventListener(\"transitionend\", transitionCallback);\n } else {\n doClose();\n }\n },\n [onClose, hasDialogSupport],\n );\n\n const modalClasses = classNames(\n \"mobius\",\n \"mobius/Drawer\",\n `--${direction}`,\n className,\n {\n \"--should-transition\": hasDialogSupport,\n },\n );\n\n // Add polyfill for HTML Dialog in old browsers\n useEffect(() => {\n async function toggleModal() {\n if (\n !hasDialogSupport &&\n typeof window !== \"undefined\" &&\n modalRef.current !== null\n ) {\n // eslint-disable-next-line import/no-extraneous-dependencies\n const { default: dialogPolyfill } = await import(\"dialog-polyfill\");\n try {\n dialogPolyfill.registerDialog(modalRef.current);\n } catch (error) {\n // In iOS 15 <= 15.2 this intermittently fails with\n // TypeError: null is not an object (evaluating 'element.showModal')\n // Checking showModal presence through hasOwnProperty is falsy natively, truthy with polyfill 🤷🏼‍♂️\n console.error(\"Failed to load dialog-polyfill\", error);\n }\n }\n\n if (isOpen && !modalRef.current?.open) {\n modalRef.current?.showModal();\n modalRef.current?.classList.add(TRANSITION_CLASS_NAME);\n onOpen?.();\n } else if (!isOpen && modalRef.current?.open) {\n handleClose();\n }\n }\n\n toggleModal();\n }, [isOpen, onOpen, handleClose, hasDialogSupport]);\n\n return (\n <dialog\n ref={mergeRefs([modalRef, ref])}\n onCancel={handleClose}\n className={modalClasses}\n aria-describedby=\"screen-reader-announce\"\n >\n <VisuallyHidden>\n <div id=\"screen-reader-announce\">{announce}</div>\n </VisuallyHidden>\n {Children.map(children, child => {\n if (isValidElement(child)) {\n return cloneElement(child, {\n onClose: handleClose,\n closeLabel,\n } as any);\n }\n\n return child;\n })}\n </dialog>\n );\n});\n\nDrawer.displayName = \"Drawer\";\nexport { Drawer };\n"],"names":["Drawer","TRANSITION_CLASS_NAME","forwardRef","props","ref","isOpen","className","closeLabel","direction","announce","onOpen","onClose","children","hasOpened","useRef","modalRef","hasDialogSupport","supportsDialog","current","useBodyScrollLock","enabled","handleClose","useCallback","event","preventDefault","stopPropagation","transitionCallback","e","target","doClose","close","removeEventListener","classList","remove","addEventListener","modalClasses","classNames","useEffect","toggleModal","window","default","dialogPolyfill","registerDialog","error","console","open","showModal","add","dialog","mergeRefs","onCancel","aria-describedby","VisuallyHidden","div","id","Children","map","child","isValidElement","cloneElement","displayName"],"mappings":"AAAA;;;;;+BAyJSA;;;eAAAA;;;;+DAvJc;uBAWhB;mCAC2B;+BACH;gCACA;uBAEL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAK1B,MAAMC,wBAAwB;AAE9B,MAAMD,uBAASE,IAAAA,iBAAU,EAAC,CAACC,OAAoBC;IAC7C,MAAM,EACJC,MAAM,EACNC,SAAS,EACTC,UAAU,EACVC,SAAS,EACTC,WAAW,yBAAyB,EACpCC,MAAM,EACNC,OAAO,EACPC,QAAQ,EACT,GAAGT;IACJ,MAAMU,YAAYC,IAAAA,aAAM,EAAU;IAClC,MAAMC,WAAWD,IAAAA,aAAM,EAA2B;IAClD,MAAME,mBAAmBC,IAAAA,6BAAc;IAEvC,mBAAmB;IACnB,IAAIP,UAAU,CAACG,UAAUK,OAAO,EAAE;QAChCR;QACAG,UAAUK,OAAO,GAAG;IACtB;IAEAC,IAAAA,oCAAiB,EAAC;QAAEC,SAASf;IAAO;IAEpC,mDAAmD;IACnD,MAAMgB,cAAcC,IAAAA,kBAAW,EAC7B,CAACC;QACC,IAAIA,OAAO;YACTA,MAAMC,cAAc;YACpBD,MAAME,eAAe;QACvB;QAEA,sEAAsE;QACtE,MAAMC,qBAAqB,CAACC;YAC1B,+DAA+D;YAC/D,oEAAoE;YACpE,IAAIA,EAAEC,MAAM,KAAKb,SAASG,OAAO,EAAE;gBACjC,mEAAmE;gBACnEW;YACF;QACF;QAEA,MAAMA,UAAU;gBACdd,mBAEAA;aAFAA,oBAAAA,SAASG,OAAO,cAAhBH,wC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ASG,OAAO,cAAhBH,yCAAAA,mBAAkB8B,IAAI,GAAE;gBAC5CxB;YACF;QACF;QAEAiB;IACF,GAAG;QAACjC;QAAQK;QAAQW;QAAaL;KAAiB;IAElD,qBACE,sBAACgC;QACC5C,KAAK6C,IAAAA,gBAAS,EAAC;YAAClC;YAAUX;SAAI;QAC9B8C,UAAU7B;QACVf,WAAW6B;QACXgB,oBAAiB;;0BAEjB,qBAACC,8BAAc;0BACb,cAAA,qBAACC;oBAAIC,IAAG;8BAA0B7C;;;YAEnC8C,eAAQ,CAACC,GAAG,CAAC5C,UAAU6C,CAAAA;gBACtB,kBAAIC,IAAAA,qBAAc,EAACD,QAAQ;oBACzB,qBAAOE,IAAAA,mBAAY,EAACF,OAAO;wBACzB9C,SAASU;wBACTd;oBACF;gBACF;gBAEA,OAAOkD;YACT;;;AAGN;AAEAzD,OAAO4D,WAAW,GAAG"}
@@ -90,20 +90,26 @@ const Modal = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
90
90
  event.preventDefault();
91
91
  event.stopPropagation();
92
92
  }
93
+ // Name the callback function, so we can add and remove event listener
94
+ const transitionCallback = (e)=>{
95
+ // Close modal only if the transition is on the dialog element
96
+ // As it can be on a child element (ie `<Button>` inside the drawer)
97
+ if (e.target === modalRef.current) {
98
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
99
+ doClose();
100
+ }
101
+ };
93
102
  const doClose = ()=>{
94
- var _modalRef_current;
103
+ var _modalRef_current, _modalRef_current1;
95
104
  (_modalRef_current = modalRef.current) === null || _modalRef_current === void 0 ? void 0 : _modalRef_current.close();
96
105
  onClose === null || onClose === void 0 ? void 0 : onClose();
106
+ (_modalRef_current1 = modalRef.current) === null || _modalRef_current1 === void 0 ? void 0 : _modalRef_current1.removeEventListener("transitionend", transitionCallback);
97
107
  };
98
108
  // Delay close to allow backdrop exit transition
99
109
  if (hasDialogSupport && animation) {
100
110
  var _modalRef_current, _modalRef_current1;
101
111
  (_modalRef_current = modalRef.current) === null || _modalRef_current === void 0 ? void 0 : _modalRef_current.classList.remove(TRANSITION_CLASS_NAME);
102
- (_modalRef_current1 = modalRef.current) === null || _modalRef_current1 === void 0 ? void 0 : _modalRef_current1.addEventListener("transitionend", ()=>{
103
- doClose();
104
- }, {
105
- once: true
106
- });
112
+ (_modalRef_current1 = modalRef.current) === null || _modalRef_current1 === void 0 ? void 0 : _modalRef_current1.addEventListener("transitionend", transitionCallback);
107
113
  } else {
108
114
  doClose();
109
115
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/Modal/Modal.tsx"],"sourcesContent":["\"use client\";\n\nimport classNames from \"classnames/dedupe\";\nimport {\n Children,\n Ref,\n SyntheticEvent,\n cloneElement,\n forwardRef,\n isValidElement,\n useCallback,\n useEffect,\n useRef,\n} from \"react\";\nimport { useBodyScrollLock } from \"../../hooks/useBodyScrollLock\";\nimport { supportsDialog } from \"../../utils/polyfill-tests\";\nimport { ModalProps } from \"./types\";\nimport { mergeRefs } from \"../../utils\";\n\nexport type ModalElementType = HTMLDialogElement;\nexport type ModalRef = Ref<ModalElementType>;\n\nconst TRANSITION_CLASS_NAME = \"--transition\";\n\nconst Modal = forwardRef((props: ModalProps, ref: ModalRef) => {\n const {\n isOpen,\n onClose,\n onOpen,\n children,\n className,\n closeLabel,\n isFullScreen,\n animation,\n // Deprecated props below\n size,\n appElement,\n preventCloseOnEsc,\n shouldFocusAfterRender,\n parentSelector,\n } = props;\n const hasWarnedAboutMissingLabels = useRef<boolean>(false);\n // Handle deprecated props\n if (!hasWarnedAboutMissingLabels.current) {\n if (\n size ||\n appElement ||\n preventCloseOnEsc ||\n shouldFocusAfterRender ||\n parentSelector\n ) {\n console.warn(\n `Deprecation warning: Mobius Modal no longer supports the following props: size, appElement, preventCloseOnEsc, shouldFocusAfterRender and parentSelector.`,\n );\n hasWarnedAboutMissingLabels.current = true;\n }\n }\n\n const hasOpened = useRef<boolean>(false);\n const modalRef = useRef<HTMLDialogElement | null>(null);\n const hasDialogSupport = supportsDialog();\n\n // Fire onOpen once\n if (onOpen && !hasOpened.current) {\n onOpen();\n hasOpened.current = true;\n }\n\n useBodyScrollLock({ enabled: isOpen });\n\n // Add close handler, to enable closing animations\n const handleClose = useCallback(\n (event?: SyntheticEvent<HTMLElement, Event>) => {\n if (event) {\n event.preventDefault();\n event.stopPropagation();\n }\n\n const doClose = () => {\n modalRef.current?.close();\n onClose?.();\n };\n\n // Delay close to allow backdrop exit transition\n if (hasDialogSupport && animation) {\n modalRef.current?.classList.remove(TRANSITION_CLASS_NAME);\n modalRef.current?.addEventListener(\n \"transitionend\",\n () => {\n doClose();\n },\n { once: true },\n );\n } else {\n doClose();\n }\n },\n [onClose, hasDialogSupport, animation],\n );\n\n const modalClasses = classNames(\n \"mobius\",\n \"mobius/Modal\",\n {\n \"--no-dialog-support\": !hasDialogSupport, // This class is used to correctly position modal in x/y middle on iOS <= 15.2\n \"--should-transition\": hasDialogSupport && animation,\n \"--slide-up\": animation === \"slideUp\",\n \"--fade\": animation === \"fade\",\n \"--is-fullscreen\": isFullScreen,\n },\n className,\n );\n\n // Add polyfill for HTML Dialog in old browsers\n useEffect(() => {\n async function toggleModal() {\n if (\n !hasDialogSupport &&\n typeof window !== \"undefined\" &&\n modalRef.current !== null\n ) {\n // eslint-disable-next-line import/no-extraneous-dependencies\n const { default: dialogPolyfill } = await import(\"dialog-polyfill\");\n\n try {\n dialogPolyfill.registerDialog(modalRef.current);\n } catch (error) {\n // In iOS 15 <= 15.2 this intermittently fails with\n // TypeError: null is not an object (evaluating 'element.showModal')\n // Checking showModal presence through hasOwnProperty is falsy natively, truthy with polyfill 🤷🏼‍♂️\n console.error(\"Failed to load dialog-polyfill\", error);\n }\n }\n\n if (isOpen && !modalRef.current?.open) {\n modalRef.current?.showModal();\n modalRef.current?.classList.add(TRANSITION_CLASS_NAME);\n onOpen?.();\n } else if (!isOpen && modalRef.current?.open) {\n handleClose();\n }\n }\n\n toggleModal();\n }, [isOpen, onOpen, handleClose, hasDialogSupport]);\n\n return (\n <dialog\n ref={mergeRefs([modalRef, ref])}\n onCancel={handleClose}\n className={modalClasses}\n >\n {Children.map(children, child => {\n if (isValidElement(child)) {\n return cloneElement(child, {\n onClose: handleClose,\n closeLabel,\n } as any);\n }\n\n return child;\n })}\n </dialog>\n );\n});\n\nModal.displayName = \"Modal\";\nexport { Modal };\n"],"names":["Modal","TRANSITION_CLASS_NAME","forwardRef","props","ref","isOpen","onClose","onOpen","children","className","closeLabel","isFullScreen","animation","size","appElement","preventCloseOnEsc","shouldFocusAfterRender","parentSelector","hasWarnedAboutMissingLabels","useRef","current","console","warn","hasOpened","modalRef","hasDialogSupport","supportsDialog","useBodyScrollLock","enabled","handleClose","useCallback","event","preventDefault","stopPropagation","doClose","close","classList","remove","addEventListener","once","modalClasses","classNames","useEffect","toggleModal","window","default","dialogPolyfill","registerDialog","error","open","showModal","add","dialog","mergeRefs","onCancel","Children","map","child","isValidElement","cloneElement","displayName"],"mappings":"AAAA;;;;;+BAuKSA;;;eAAAA;;;;+DArKc;uBAWhB;mCAC2B;+BACH;uBAEL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAK1B,MAAMC,wBAAwB;AAE9B,MAAMD,sBAAQE,IAAAA,iBAAU,EAAC,CAACC,OAAmBC;IAC3C,MAAM,EACJC,MAAM,EACNC,OAAO,EACPC,MAAM,EACNC,QAAQ,EACRC,SAAS,EACTC,UAAU,EACVC,YAAY,EACZC,SAAS,EACT,yBAAyB;IACzBC,IAAI,EACJC,UAAU,EACVC,iBAAiB,EACjBC,sBAAsB,EACtBC,cAAc,EACf,GAAGd;IACJ,MAAMe,8BAA8BC,IAAAA,aAAM,EAAU;IACpD,0BAA0B;IAC1B,IAAI,CAACD,4BAA4BE,OAAO,EAAE;QACxC,IACEP,QACAC,cACAC,qBACAC,0BACAC,gBACA;YACAI,QAAQC,IAAI,CACV,CAAC,yJAAyJ,CAAC;YAE7JJ,4BAA4BE,OAAO,GAAG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AAA,QAAO;gBAEjD,IAAI;oBACFA,eAAeC,cAAc,CAACvB,SAASJ,OAAO;gBAChD,EAAE,OAAO4B,OAAO;oBACd,mDAAmD;oBACnD,oEAAoE;oBACpE,qGAAqG;oBACrG3B,QAAQ2B,KAAK,CAAC,kCAAkCA;gBAClD;YACF;YAEA,IAAI3C,UAAU,GAACmB,oBAAAA,SAASJ,OAAO,cAAhBI,wCAAAA,kBAAkByB,IAAI,GAAE;oBACrCzB,oBACAA;iBADAA,qBAAAA,SAASJ,OAAO,cAAhBI,yCAAAA,mBAAkB0B,SAAS;iBAC3B1B,qBAAAA,SAASJ,OAAO,cAAhBI,yCAAAA,mBAAkBY,SAAS,CAACe,GAAG,CAAClD;gBAChCM,mBAAAA,6BAAAA;YACF,OAAO,IAAI,CAACF,YAAUmB,qBAAAA,SAASJ,OAAO,cAAhBI,yCAAAA,mBAAkByB,IAAI,GAAE;gBAC5CpB;YACF;QACF;QAEAc;IACF,GAAG;QAACtC;QAAQE;QAAQsB;QAAaJ;KAAiB;IAElD,qBACE,qBAAC2B;QACChD,KAAKiD,IAAAA,gBAAS,EAAC;YAAC7B;YAAUpB;SAAI;QAC9BkD,UAAUzB;QACVpB,WAAW+B;kBAEVe,eAAQ,CAACC,GAAG,CAAChD,UAAUiD,CAAAA;YACtB,kBAAIC,IAAAA,qBAAc,EAACD,QAAQ;gBACzB,qBAAOE,IAAAA,mBAAY,EAACF,OAAO;oBACzBnD,SAASuB;oBACTnB;gBACF;YACF;YAEA,OAAO+C;QACT;;AAGN;AAEAzD,MAAM4D,WAAW,GAAG"}
1
+ {"version":3,"sources":["../../../../src/components/Modal/Modal.tsx"],"sourcesContent":["\"use client\";\n\nimport classNames from \"classnames/dedupe\";\nimport {\n Children,\n Ref,\n SyntheticEvent,\n cloneElement,\n forwardRef,\n isValidElement,\n useCallback,\n useEffect,\n useRef,\n} from \"react\";\nimport { useBodyScrollLock } from \"../../hooks/useBodyScrollLock\";\nimport { supportsDialog } from \"../../utils/polyfill-tests\";\nimport { ModalProps } from \"./types\";\nimport { mergeRefs } from \"../../utils\";\n\nexport type ModalElementType = HTMLDialogElement;\nexport type ModalRef = Ref<ModalElementType>;\n\nconst TRANSITION_CLASS_NAME = \"--transition\";\n\nconst Modal = forwardRef((props: ModalProps, ref: ModalRef) => {\n const {\n isOpen,\n onClose,\n onOpen,\n children,\n className,\n closeLabel,\n isFullScreen,\n animation,\n // Deprecated props below\n size,\n appElement,\n preventCloseOnEsc,\n shouldFocusAfterRender,\n parentSelector,\n } = props;\n const hasWarnedAboutMissingLabels = useRef<boolean>(false);\n // Handle deprecated props\n if (!hasWarnedAboutMissingLabels.current) {\n if (\n size ||\n appElement ||\n preventCloseOnEsc ||\n shouldFocusAfterRender ||\n parentSelector\n ) {\n console.warn(\n `Deprecation warning: Mobius Modal no longer supports the following props: size, appElement, preventCloseOnEsc, shouldFocusAfterRender and parentSelector.`,\n );\n hasWarnedAboutMissingLabels.current = true;\n }\n }\n\n const hasOpened = useRef<boolean>(false);\n const modalRef = useRef<HTMLDialogElement | null>(null);\n const hasDialogSupport = supportsDialog();\n\n // Fire onOpen once\n if (onOpen && !hasOpened.current) {\n onOpen();\n hasOpened.current = true;\n }\n\n useBodyScrollLock({ enabled: isOpen });\n\n // Add close handler, to enable closing animations\n const handleClose = useCallback(\n (event?: SyntheticEvent<HTMLElement, Event>) => {\n if (event) {\n event.preventDefault();\n event.stopPropagation();\n }\n\n // Name the callback function, so we can add and remove event listener\n const transitionCallback = (e: Event) => {\n // Close modal only if the transition is on the dialog element\n // As it can be on a child element (ie `<Button>` inside the drawer)\n if (e.target === modalRef.current) {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n doClose();\n }\n };\n\n const doClose = () => {\n modalRef.current?.close();\n onClose?.();\n modalRef.current?.removeEventListener(\n \"transitionend\",\n transitionCallback,\n );\n };\n\n // Delay close to allow backdrop exit transition\n if (hasDialogSupport && animation) {\n modalRef.current?.classList.remove(TRANSITION_CLASS_NAME);\n modalRef.current?.addEventListener(\"transitionend\", transitionCallback);\n } else {\n doClose();\n }\n },\n [onClose, hasDialogSupport, animation],\n );\n\n const modalClasses = classNames(\n \"mobius\",\n \"mobius/Modal\",\n {\n \"--no-dialog-support\": !hasDialogSupport, // This class is used to correctly position modal in x/y middle on iOS <= 15.2\n \"--should-transition\": hasDialogSupport && animation,\n \"--slide-up\": animation === \"slideUp\",\n \"--fade\": animation === \"fade\",\n \"--is-fullscreen\": isFullScreen,\n },\n className,\n );\n\n // Add polyfill for HTML Dialog in old browsers\n useEffect(() => {\n async function toggleModal() {\n if (\n !hasDialogSupport &&\n typeof window !== \"undefined\" &&\n modalRef.current !== null\n ) {\n // eslint-disable-next-line import/no-extraneous-dependencies\n const { default: dialogPolyfill } = await import(\"dialog-polyfill\");\n\n try {\n dialogPolyfill.registerDialog(modalRef.current);\n } catch (error) {\n // In iOS 15 <= 15.2 this intermittently fails with\n // TypeError: null is not an object (evaluating 'element.showModal')\n // Checking showModal presence through hasOwnProperty is falsy natively, truthy with polyfill 🤷🏼‍♂️\n console.error(\"Failed to load dialog-polyfill\", error);\n }\n }\n\n if (isOpen && !modalRef.current?.open) {\n modalRef.current?.showModal();\n modalRef.current?.classList.add(TRANSITION_CLASS_NAME);\n onOpen?.();\n } else if (!isOpen && modalRef.current?.open) {\n handleClose();\n }\n }\n\n toggleModal();\n }, [isOpen, onOpen, handleClose, hasDialogSupport]);\n\n return (\n <dialog\n ref={mergeRefs([modalRef, ref])}\n onCancel={handleClose}\n className={modalClasses}\n >\n {Children.map(children, child => {\n if (isValidElement(child)) {\n return cloneElement(child, {\n onClose: handleClose,\n closeLabel,\n } as any);\n }\n\n return child;\n })}\n </dialog>\n );\n});\n\nModal.displayName = \"Modal\";\nexport { Modal };\n"],"names":["Modal","TRANSITION_CLASS_NAME","forwardRef","props","ref","isOpen","onClose","onOpen","children","className","closeLabel","isFullScreen","animation","size","appElement","preventCloseOnEsc","shouldFocusAfterRender","parentSelector","hasWarnedAboutMissingLabels","useRef","current","console","warn","hasOpened","modalRef","hasDialogSupport","supportsDialog","useBodyScrollLock","enabled","handleClose","useCallback","event","preventDefault","stopPropagation","transitionCallback","e","target","doClose","close","removeEventListener","classList","remove","addEventListener","modalClasses","classNames","useEffect","toggleModal","window","default","dialogPolyfill","registerDialog","error","open","showModal","add","dialog","mergeRefs","onCancel","Children","map","child","isValidElement","cloneElement","displayName"],"mappings":"AAAA;;;;;+BA+KSA;;;eAAAA;;;;+DA7Kc;uBAWhB;mCAC2B;+BACH;uBAEL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAK1B,MAAMC,wBAAwB;AAE9B,MAAMD,sBAAQE,IAAAA,iBAAU,EAAC,CAACC,OAAmBC;IAC3C,MAAM,EACJC,MAAM,EACNC,OAAO,EACPC,MAAM,EACNC,QAAQ,EACRC,SAAS,EACTC,UAAU,EACVC,YAAY,EACZC,SAAS,EACT,yBAAyB;IACzBC,IAAI,EACJC,UAAU,EACVC,iBAAiB,EACjBC,sBAAsB,EACtBC,cAAc,EACf,GAAGd;IACJ,MAAMe,8BAA8BC,IAAAA,aAAM,EAAU;IACpD,0BAA0B;IAC1B,IAAI,CAACD,4BAA4BE,OAAO,EAAE;QACxC,IACEP,QACAC,cACAC,qBACAC,0BACAC,gBACA;YACAI,QAAQC,IAAI,CACV,CAAC,yJAAyJ,CAAC;YAE7JJ,4BAA4BE,OAAO,GAAG;QACxC;IACF;IAEA,MAAMG,YAAYJ,IAAAA,aAAM,EAAU;IAClC,MAAMK,WAAWL,IAAAA,aAAM,EAA2B;IAClD,MAAMM,mBAAmBC,IAAAA,6BAAc;IAEvC,mBAAmB;IACnB,IAAInB,UAAU,CAACgB,UAAUH,OAAO,EAAE;QAChCb;QACAgB,UAAUH,OAAO,GAAG;IACtB;IAEAO,IAAAA,oCAAiB,EAAC;QAAEC,SAASvB;IAAO;IAEpC,kDAAkD;IAClD,MAAMwB,cAAcC,IAAAA,kBAAW,EAC7B,CAACC;QACC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