@cuemath/leap 3.1.12-as1 → 3.1.12-as3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,48 +1,50 @@
|
|
1
|
-
import { jsxs as
|
2
|
-
import { memo as
|
3
|
-
import
|
4
|
-
import
|
5
|
-
import { lockScroll as
|
6
|
-
const
|
7
|
-
const [o,
|
8
|
-
(
|
9
|
-
const
|
10
|
-
if (!
|
11
|
-
throw new Error(`Modal with name "${
|
12
|
-
if (
|
1
|
+
import { jsxs as b, jsx as x } from "react/jsx-runtime";
|
2
|
+
import { memo as y, useState as l, useCallback as v, useMemo as I, useEffect as w } from "react";
|
3
|
+
import S from "./modal.js";
|
4
|
+
import h from "./modal-context.js";
|
5
|
+
import { lockScroll as D, unlockScroll as T } from "./modal-helpers.js";
|
6
|
+
const $ = 500, g = y(({ children: M, modals: d, isUserAuthenticated: t }) => {
|
7
|
+
const [o, f] = l(null), [m, p] = l(void 0), [n, a] = l(!1), [r, k] = l(void 0), u = v(
|
8
|
+
(e, i, C) => {
|
9
|
+
const c = d.find((E) => E.name === e);
|
10
|
+
if (!c)
|
11
|
+
throw new Error(`Modal with name "${e}" not found`);
|
12
|
+
if (c.isPrivate && !t)
|
13
13
|
throw new Error(
|
14
|
-
`Access violation: Modal "${
|
14
|
+
`Access violation: Modal "${e}" is private and user is not authenticated`
|
15
15
|
);
|
16
|
-
|
16
|
+
k(C), a(!1), f(c), p(i), D();
|
17
17
|
},
|
18
18
|
[t, d]
|
19
|
-
),
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
), s = v(() => {
|
20
|
+
const { onCloseModal: e } = r || {};
|
21
|
+
a(!0), T(), setTimeout(() => {
|
22
|
+
e == null || e(), f(null), a(!1);
|
23
|
+
}, $);
|
24
|
+
}, [r]), P = I(
|
24
25
|
() => ({
|
25
26
|
modal: o,
|
26
|
-
modalParams:
|
27
|
-
openModal:
|
28
|
-
closeModal:
|
29
|
-
isClosing:
|
27
|
+
modalParams: m,
|
28
|
+
openModal: u,
|
29
|
+
closeModal: s,
|
30
|
+
isClosing: n,
|
31
|
+
callbacks: r
|
30
32
|
}),
|
31
|
-
[o,
|
33
|
+
[o, m, u, s, n, r]
|
32
34
|
);
|
33
|
-
return
|
34
|
-
!t && (o != null && o.isPrivate) &&
|
35
|
-
}, [t, o,
|
36
|
-
const
|
37
|
-
|
35
|
+
return w(() => {
|
36
|
+
!t && (o != null && o.isPrivate) && s();
|
37
|
+
}, [t, o, s]), w(() => {
|
38
|
+
const e = (i) => {
|
39
|
+
i.key === "Escape" && (o == null ? void 0 : o.isDismissable) !== !1 && !n && s();
|
38
40
|
};
|
39
|
-
return window.addEventListener("keydown",
|
40
|
-
}, [o,
|
41
|
-
|
42
|
-
o && /* @__PURE__ */
|
41
|
+
return window.addEventListener("keydown", e), () => window.removeEventListener("keydown", e);
|
42
|
+
}, [o, s, n]), /* @__PURE__ */ b(h.Provider, { value: P, children: [
|
43
|
+
M,
|
44
|
+
o && /* @__PURE__ */ x(S, { modal: o, isClosing: n, onClose: s })
|
43
45
|
] });
|
44
|
-
}),
|
46
|
+
}), K = g;
|
45
47
|
export {
|
46
|
-
|
48
|
+
K as default
|
47
49
|
};
|
48
50
|
//# sourceMappingURL=modal-provider.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"modal-provider.js","sources":["../../../../src/features/ui/modals/modal-provider.tsx"],"sourcesContent":["import type { IModal, IModalContext, IModalProviderProps } from './modal-types';\nimport type { FC } from 'react';\n\nimport { memo, useCallback, useEffect, useMemo, useState } from 'react';\n\nimport Modal from './modal';\nimport ModalContext from './modal-context';\nimport { lockScroll, unlockScroll } from './modal-helpers';\n\nconst ANIMATION_DURATION_MS = 500; // Match the animation duration in modal.tsx\n\n/**\n * Provider component that manages modal state and provides modal context to child components\n */\nconst ModalProvider: FC<IModalProviderProps> = memo(({ children, modals, isUserAuthenticated }) => {\n const [modal, setModal] = useState<IModal | null>(null);\n const [modalParams, setModalParams] = useState<Record<string, unknown> | undefined>(undefined);\n const [isClosing, setIsClosing] = useState(false);\n
|
1
|
+
{"version":3,"file":"modal-provider.js","sources":["../../../../src/features/ui/modals/modal-provider.tsx"],"sourcesContent":["import type { IModal, IModalCallbacks, IModalContext, IModalProviderProps } from './modal-types';\nimport type { FC } from 'react';\n\nimport { memo, useCallback, useEffect, useMemo, useState } from 'react';\n\nimport Modal from './modal';\nimport ModalContext from './modal-context';\nimport { lockScroll, unlockScroll } from './modal-helpers';\n\nconst ANIMATION_DURATION_MS = 500; // Match the animation duration in modal.tsx\n\n/**\n * Provider component that manages modal state and provides modal context to child components\n */\nconst ModalProvider: FC<IModalProviderProps> = memo(({ children, modals, isUserAuthenticated }) => {\n const [modal, setModal] = useState<IModal | null>(null);\n const [modalParams, setModalParams] = useState<Record<string, unknown> | undefined>(undefined);\n const [isClosing, setIsClosing] = useState(false);\n const [callbacks, setCallbacks] = useState<IModalCallbacks | undefined>(undefined);\n /**\n * Opens a modal by name with optional parameters\n * Handles authentication check for private modals\n */\n const openModal = useCallback<IModalContext['openModal']>(\n (modalName, newModalParams, callback) => {\n const newModal = modals.find(m => m.name === modalName);\n\n if (!newModal) {\n throw new Error(`Modal with name \"${modalName}\" not found`);\n }\n\n if (newModal.isPrivate && !isUserAuthenticated) {\n throw new Error(\n `Access violation: Modal \"${modalName}\" is private and user is not authenticated`,\n );\n }\n\n setCallbacks(callback);\n setIsClosing(false);\n setModal(newModal);\n setModalParams(newModalParams as unknown as Record<string, unknown> | undefined);\n lockScroll(); // Lock scroll while preserving scrollbar width\n },\n [isUserAuthenticated, modals],\n );\n\n const closeModal = useCallback(() => {\n const { onCloseModal } = callbacks || {};\n\n setIsClosing(true);\n // Wait for the animation to complete before removing the modal\n unlockScroll();\n setTimeout(() => {\n onCloseModal?.();\n setModal(null);\n setIsClosing(false);\n }, ANIMATION_DURATION_MS);\n }, [callbacks]);\n\n const modalContent = useMemo<IModalContext>(\n () => ({\n modal,\n modalParams,\n openModal,\n closeModal,\n isClosing,\n callbacks,\n }),\n [modal, modalParams, openModal, closeModal, isClosing, callbacks],\n );\n\n useEffect(() => {\n if (!isUserAuthenticated && modal?.isPrivate) {\n // If the modal is private and user is not authenticated, close it\n closeModal();\n }\n }, [isUserAuthenticated, modal, closeModal]);\n\n // Handle ESC key\n useEffect(() => {\n const handleKeyDown = (e: KeyboardEvent) => {\n if (e.key === 'Escape' && modal?.isDismissable !== false && !isClosing) {\n closeModal();\n }\n };\n\n window.addEventListener('keydown', handleKeyDown);\n\n return () => window.removeEventListener('keydown', handleKeyDown);\n }, [modal, closeModal, isClosing]);\n\n return (\n <ModalContext.Provider value={modalContent}>\n {children}\n {modal && <Modal modal={modal} isClosing={isClosing} onClose={closeModal} />}\n </ModalContext.Provider>\n );\n});\n\nexport default ModalProvider;\n"],"names":["ANIMATION_DURATION_MS","ModalProvider","memo","children","modals","isUserAuthenticated","modal","setModal","useState","modalParams","setModalParams","isClosing","setIsClosing","callbacks","setCallbacks","openModal","useCallback","modalName","newModalParams","callback","newModal","m","lockScroll","closeModal","onCloseModal","unlockScroll","modalContent","useMemo","useEffect","handleKeyDown","e","jsxs","ModalContext","jsx","Modal","ModalProvider$1"],"mappings":";;;;;AASA,MAAMA,IAAwB,KAKxBC,IAAyCC,EAAK,CAAC,EAAE,UAAAC,GAAU,QAAAC,GAAQ,qBAAAC,QAA0B;AACjG,QAAM,CAACC,GAAOC,CAAQ,IAAIC,EAAwB,IAAI,GAChD,CAACC,GAAaC,CAAc,IAAIF,EAA8C,MAAS,GACvF,CAACG,GAAWC,CAAY,IAAIJ,EAAS,EAAK,GAC1C,CAACK,GAAWC,CAAY,IAAIN,EAAsC,MAAS,GAK3EO,IAAYC;AAAA,IAChB,CAACC,GAAWC,GAAgBC,MAAa;AACvC,YAAMC,IAAWhB,EAAO,KAAK,CAAKiB,MAAAA,EAAE,SAASJ,CAAS;AAEtD,UAAI,CAACG;AACH,cAAM,IAAI,MAAM,oBA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AAA2B,EAAAC,GAAA,EAAM,OAAA5B,GAAc,WAAAK,GAAsB,SAASY,GAAY;AAAA,EAC5E,EAAA,CAAA;AAEJ,CAAC,GAEDY,IAAelC;"}
|
@@ -1,9 +1,9 @@
|
|
1
|
-
import { useContext as
|
2
|
-
import
|
3
|
-
const
|
4
|
-
const { openModal: o, closeModal: t, isClosing: s } =
|
5
|
-
return { openModal: o, closeModal: t, isClosing: s };
|
6
|
-
}, c =
|
1
|
+
import { useContext as n } from "react";
|
2
|
+
import l from "./modal-context.js";
|
3
|
+
const a = () => {
|
4
|
+
const { openModal: o, closeModal: t, isClosing: s, modal: e } = n(l);
|
5
|
+
return { openModal: o, closeModal: t, isClosing: s, modal: e };
|
6
|
+
}, c = a;
|
7
7
|
export {
|
8
8
|
c as default
|
9
9
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-modal-actions.js","sources":["../../../../src/features/ui/modals/use-modal-actions.ts"],"sourcesContent":["import type { IUseModalActions } from './modal-types';\n\nimport { useContext } from 'react';\n\nimport ModalContext from './modal-context';\n\nconst useModalActions: IUseModalActions = () => {\n const { openModal, closeModal, isClosing } = useContext(ModalContext);\n\n return { openModal, closeModal, isClosing };\n};\n\nexport default useModalActions;\n"],"names":["useModalActions","openModal","closeModal","isClosing","useContext","ModalContext","useModalActions$1"],"mappings":";;AAMA,MAAMA,IAAoC,MAAM;AAC9C,QAAM,EAAE,WAAAC,GAAW,YAAAC,GAAY,WAAAC,
|
1
|
+
{"version":3,"file":"use-modal-actions.js","sources":["../../../../src/features/ui/modals/use-modal-actions.ts"],"sourcesContent":["import type { IUseModalActions } from './modal-types';\n\nimport { useContext } from 'react';\n\nimport ModalContext from './modal-context';\n\nconst useModalActions: IUseModalActions = () => {\n const { openModal, closeModal, isClosing, modal } = useContext(ModalContext);\n\n return { openModal, closeModal, isClosing, modal };\n};\n\nexport default useModalActions;\n"],"names":["useModalActions","openModal","closeModal","isClosing","modal","useContext","ModalContext","useModalActions$1"],"mappings":";;AAMA,MAAMA,IAAoC,MAAM;AAC9C,QAAM,EAAE,WAAAC,GAAW,YAAAC,GAAY,WAAAC,GAAW,OAAAC,MAAUC,EAAWC,CAAY;AAE3E,SAAO,EAAE,WAAAL,GAAW,YAAAC,GAAY,WAAAC,GAAW,OAAAC,EAAM;AACnD,GAEAG,IAAeP;"}
|
package/dist/index.d.ts
CHANGED
@@ -2368,6 +2368,11 @@ export declare interface IModal {
|
|
2368
2368
|
modalWidth: string;
|
2369
2369
|
}
|
2370
2370
|
|
2371
|
+
declare interface IModalCallbacks {
|
2372
|
+
/** Callback when the modal is closed */
|
2373
|
+
onCloseModal?: () => void;
|
2374
|
+
}
|
2375
|
+
|
2371
2376
|
/**
|
2372
2377
|
* Context for managing modals throughout the application
|
2373
2378
|
*/
|
@@ -2377,7 +2382,7 @@ declare interface IModalContext {
|
|
2377
2382
|
/** Parameters passed to the modal when opened */
|
2378
2383
|
modalParams?: Record<string, unknown>;
|
2379
2384
|
/** Opens a modal by name with optional parameters */
|
2380
|
-
openModal: <T = undefined>(name: string, params?: T) => void;
|
2385
|
+
openModal: <T = undefined>(name: string, params?: T, callbacks?: IModalCallbacks) => void;
|
2381
2386
|
/** Closes the currently open modal */
|
2382
2387
|
closeModal: () => void;
|
2383
2388
|
/** Whether the modal is in the process of closing (for animation) */
|
@@ -3595,7 +3600,7 @@ declare interface IUseIsTabBlocked {
|
|
3595
3600
|
}
|
3596
3601
|
|
3597
3602
|
declare interface IUseModalActions {
|
3598
|
-
(): Pick<IModalContext, 'openModal' | 'closeModal' | 'isClosing'>;
|
3603
|
+
(): Pick<IModalContext, 'openModal' | 'closeModal' | 'isClosing' | 'modal'>;
|
3599
3604
|
}
|
3600
3605
|
|
3601
3606
|
declare interface IUseModalParams {
|