@cuemath/leap 2.9.7-rj-3 → 2.9.7-rj-5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/features/journey/use-journey/journey-context-provider.js +50 -42
- package/dist/features/journey/use-journey/journey-context-provider.js.map +1 -1
- package/dist/features/journey/use-journey/journey-styled.js +1 -0
- package/dist/features/journey/use-journey/journey-styled.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/package.json +1 -1
@@ -1,75 +1,75 @@
|
|
1
|
-
import { jsxs as
|
2
|
-
import { createContext as
|
3
|
-
import { Coachmark as
|
4
|
-
import { usePostUserJourney as
|
5
|
-
import { Overlay as
|
6
|
-
const
|
7
|
-
const [x,
|
8
|
-
(e, r) => {
|
9
|
-
if (
|
1
|
+
import { jsxs as q, jsx as w } from "react/jsx-runtime";
|
2
|
+
import { createContext as D, useState as J, useRef as k, useCallback as y, useMemo as L, useEffect as R } from "react";
|
3
|
+
import { Coachmark as N } from "../comps/coachmark/coachmark.js";
|
4
|
+
import { usePostUserJourney as B, useGetUserJourney as M } from "../user-journey-api/user-journey-api.js";
|
5
|
+
import { Overlay as z } from "./journey-styled.js";
|
6
|
+
const G = D(null), Q = ({ children: T, appId: c, userId: o }) => {
|
7
|
+
const [x, g] = J(null), [a, i] = J([]), [b, O] = J(!1), [f, p] = J(!1), m = k(-1), t = k(), d = k([]), { post: v } = B(), { data: C = null, get: _ } = M(), A = y(
|
8
|
+
(e, r, s = !0) => {
|
9
|
+
if (a.length > 0) {
|
10
10
|
console.error(
|
11
11
|
`setJourney: Other Journey is already active, Current Journey: ${t.current}, New Journey Request: ${e}`
|
12
12
|
);
|
13
13
|
return;
|
14
14
|
}
|
15
|
-
|
15
|
+
p(!0), O(s), t.current = e, m.current = -1, i([...r]);
|
16
16
|
},
|
17
|
-
[
|
18
|
-
), u =
|
17
|
+
[a.length]
|
18
|
+
), u = y(() => {
|
19
19
|
d.current.forEach((e) => {
|
20
20
|
clearTimeout(e);
|
21
|
-
}), d.current = [], t.current = void 0, m.current = -1,
|
22
|
-
}, []), $ =
|
21
|
+
}), d.current = [], t.current = void 0, m.current = -1, i([]), p(!1);
|
22
|
+
}, []), $ = y(
|
23
23
|
(e) => {
|
24
|
-
u(),
|
25
|
-
app_id:
|
24
|
+
u(), g((r) => r && !r.includes(e) ? [...r, e] : r), v({
|
25
|
+
app_id: c,
|
26
26
|
user_id: o,
|
27
27
|
journey_id: e,
|
28
28
|
journey_status: "COMPLETED"
|
29
29
|
});
|
30
30
|
},
|
31
|
-
[
|
32
|
-
), E =
|
31
|
+
[c, u, v, o]
|
32
|
+
), E = y((e, r) => {
|
33
33
|
if (!t.current || e !== t.current) {
|
34
34
|
console.error(
|
35
35
|
t.current ? `A Journey is already active, Current Journey: ${t.current}, New Journey Request: ${e}` : "addCoachmark was called before setJourney and Journey ID is undefined"
|
36
36
|
);
|
37
37
|
return;
|
38
38
|
}
|
39
|
-
|
40
|
-
}, []), P =
|
41
|
-
(e, r = !1,
|
39
|
+
i((s) => [...s, r]);
|
40
|
+
}, []), P = y(
|
41
|
+
(e, r = !1, s = 0) => {
|
42
42
|
if (!t.current || e !== t.current) {
|
43
43
|
console.error(
|
44
44
|
t.current ? "nextCoachmark was called before setJourney" : `A Journey is already active, Current Journey: ${t.current}, New Journey Request: ${e}`
|
45
45
|
);
|
46
46
|
return;
|
47
47
|
}
|
48
|
-
|
48
|
+
s !== 0 && i((n) => n.map((l) => ({ ...l, isActive: !1 })));
|
49
49
|
const j = setTimeout(() => {
|
50
50
|
clearTimeout(j);
|
51
51
|
const n = m.current + 1;
|
52
|
-
|
53
|
-
if (n >=
|
52
|
+
i((l) => {
|
53
|
+
if (n >= l.length || l.length === 0)
|
54
54
|
return u(), [];
|
55
55
|
m.current = n;
|
56
|
-
const
|
57
|
-
return
|
56
|
+
const h = [...l];
|
57
|
+
return h[n].isActive = !0, n > 0 && (h[n - 1].isActive = r), h;
|
58
58
|
});
|
59
|
-
},
|
59
|
+
}, s);
|
60
60
|
d.current.push(j);
|
61
61
|
},
|
62
62
|
[u]
|
63
|
-
),
|
63
|
+
), U = L(
|
64
64
|
() => ({
|
65
65
|
nextCoachmark: P,
|
66
66
|
setJourney: A,
|
67
67
|
addCoachmark: E,
|
68
68
|
clearJourney: u,
|
69
69
|
endJourney: $,
|
70
|
-
coachmarks:
|
70
|
+
coachmarks: a,
|
71
71
|
userCompletedJourneyIds: x,
|
72
|
-
isJourneyActive:
|
72
|
+
isJourneyActive: f
|
73
73
|
}),
|
74
74
|
[
|
75
75
|
P,
|
@@ -77,29 +77,37 @@ const z = U(null), H = ({ children: T, appId: s, userId: o }) => {
|
|
77
77
|
E,
|
78
78
|
u,
|
79
79
|
$,
|
80
|
-
|
80
|
+
a,
|
81
81
|
x,
|
82
|
-
|
82
|
+
f
|
83
83
|
]
|
84
84
|
);
|
85
85
|
return R(() => {
|
86
|
-
|
87
|
-
app_id:
|
86
|
+
c && o && _(o, {
|
87
|
+
app_id: c,
|
88
88
|
user_id: o,
|
89
89
|
journey_status: "COMPLETED"
|
90
90
|
});
|
91
|
-
}, [
|
92
|
-
if (
|
93
|
-
const e =
|
94
|
-
|
91
|
+
}, [c, _, o]), R(() => {
|
92
|
+
if (C) {
|
93
|
+
const e = C.map((r) => r.journey_id);
|
94
|
+
g(e);
|
95
95
|
}
|
96
|
-
}, [
|
97
|
-
|
96
|
+
}, [C]), /* @__PURE__ */ q(G.Provider, { value: U, children: [
|
97
|
+
f && /* @__PURE__ */ w(
|
98
|
+
z,
|
99
|
+
{
|
100
|
+
about: "journey-overlay",
|
101
|
+
"data-testid": t.current,
|
102
|
+
isBlockingJourney: b,
|
103
|
+
children: a.map((e, r) => /* @__PURE__ */ w(N, { coachmark: e }, `coachmark-${r}`))
|
104
|
+
}
|
105
|
+
),
|
98
106
|
T
|
99
107
|
] });
|
100
108
|
};
|
101
109
|
export {
|
102
|
-
|
103
|
-
|
110
|
+
G as JourneyContext,
|
111
|
+
Q as JourneyProvider
|
104
112
|
};
|
105
113
|
//# sourceMappingURL=journey-context-provider.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"journey-context-provider.js","sources":["../../../../src/features/journey/use-journey/journey-context-provider.tsx"],"sourcesContent":["/* eslint-disable no-console */\nimport type { TJourneyId } from '../journey-id/journey-id-types';\nimport type {\n ICoachmarkProps,\n IJourneyContext,\n IJourneyProviderProps,\n} from './journey-context-types';\nimport type { FC } from 'react';\n\nimport { createContext, useCallback, useEffect, useMemo, useRef, useState } from 'react';\n\nimport { Coachmark } from '../comps/coachmark/coachmark';\nimport { useGetUserJourney, usePostUserJourney } from '../user-journey-api/user-journey-api';\nimport * as S from './journey-styled';\n\nexport const JourneyContext = createContext<IJourneyContext | null>(null);\n\nexport const JourneyProvider: FC<IJourneyProviderProps> = ({ children, appId, userId }) => {\n const [userCompletedJourneyIds, setUserCompletedJourneyIds] = useState<TJourneyId[] | null>(null);\n const [coachmarkList, setCoachmarkList] = useState<ICoachmarkProps[]>([]);\n const [isJourneyActive, setIsJourneyActive] = useState(false);\n const currentIndex = useRef(-1);\n const currentJourneyId = useRef<TJourneyId | undefined>();\n const timerRefs = useRef<ReturnType<typeof setTimeout>[]>([]);\n\n const { post: postJourneyCompletion } = usePostUserJourney();\n const { data: userCompletedJourneys = null, get: getJourneyProgress } = useGetUserJourney();\n\n const setJourney = useCallback(\n (id: TJourneyId, coachmarks: ICoachmarkProps[]) => {\n if (coachmarkList.length > 0) {\n console.error(\n `setJourney: Other Journey is already active, Current Journey: ${currentJourneyId.current}, New Journey Request: ${id}`,\n );\n\n return;\n }\n setIsJourneyActive(true);\n currentJourneyId.current = id;\n currentIndex.current = -1;\n setCoachmarkList([...coachmarks]);\n },\n [coachmarkList.length],\n );\n\n const clearJourney = useCallback(() => {\n // Clear all timers\n timerRefs.current.forEach(timer => {\n clearTimeout(timer);\n });\n timerRefs.current = [];\n currentJourneyId.current = undefined;\n currentIndex.current = -1;\n setCoachmarkList([]);\n setIsJourneyActive(false);\n }, []);\n\n const endJourney = useCallback(\n (journeyId: TJourneyId) => {\n clearJourney();\n setUserCompletedJourneyIds(prev => {\n if (prev && !prev.includes(journeyId)) {\n return [...prev, journeyId];\n }\n\n return prev;\n });\n // fire the API (doesn’t block the UI)\n postJourneyCompletion({\n app_id: appId,\n user_id: userId,\n journey_id: journeyId,\n journey_status: 'COMPLETED',\n });\n },\n [appId, clearJourney, postJourneyCompletion, userId],\n );\n\n const addCoachmark = useCallback((id: TJourneyId, coachmark: ICoachmarkProps) => {\n if (!currentJourneyId.current || id !== currentJourneyId.current) {\n console.error(\n currentJourneyId.current\n ? `A Journey is already active, Current Journey: ${currentJourneyId.current}, New Journey Request: ${id}`\n : `addCoachmark was called before setJourney and Journey ID is undefined`,\n );\n\n return;\n }\n\n setCoachmarkList(prev => [...prev, coachmark]);\n }, []);\n\n const nextCoachmark = useCallback(\n (id: TJourneyId, keepPrevActive: boolean = false, delayInMs: number = 0) => {\n if (!currentJourneyId.current || id !== currentJourneyId.current) {\n console.error(\n currentJourneyId.current\n ? `nextCoachmark was called before setJourney`\n : `A Journey is already active, Current Journey: ${currentJourneyId.current}, New Journey Request: ${id}`,\n );\n\n return;\n }\n\n if (delayInMs !== 0) {\n // If delay is not 0, we will hide all them coachmarks and reveal only after the delay\n setCoachmarkList(prevList => {\n return prevList.map((item: ICoachmarkProps) => {\n return { ...item, isActive: false };\n });\n });\n }\n\n const timer = setTimeout(() => {\n clearTimeout(timer);\n const currIndex = currentIndex.current + 1;\n\n setCoachmarkList(prevList => {\n // Finish onboarding\n if (currIndex >= prevList.length || prevList.length === 0) {\n clearJourney();\n\n return [];\n }\n\n currentIndex.current = currIndex;\n const updatedCoachmarkList = [...prevList];\n\n (updatedCoachmarkList[currIndex] as ICoachmarkProps).isActive = true;\n\n if (currIndex > 0) {\n (updatedCoachmarkList[currIndex - 1] as ICoachmarkProps).isActive = keepPrevActive;\n }\n\n return updatedCoachmarkList;\n });\n }, delayInMs);\n\n timerRefs.current.push(timer);\n },\n [clearJourney],\n );\n\n const memoizedContextValue: IJourneyContext = useMemo(\n () => ({\n nextCoachmark,\n setJourney,\n addCoachmark,\n clearJourney,\n endJourney,\n coachmarks: coachmarkList,\n userCompletedJourneyIds,\n isJourneyActive,\n }),\n [\n nextCoachmark,\n setJourney,\n addCoachmark,\n clearJourney,\n endJourney,\n coachmarkList,\n userCompletedJourneyIds,\n isJourneyActive,\n ],\n );\n\n // Get the initial state of incompleteJourneys\n useEffect(() => {\n if (appId && userId) {\n getJourneyProgress(userId, {\n app_id: appId,\n user_id: userId,\n journey_status: 'COMPLETED',\n });\n }\n }, [appId, getJourneyProgress, userId]);\n\n // Set the data to context state initially\n useEffect(() => {\n if (userCompletedJourneys) {\n const completedUserJourneysIds = userCompletedJourneys.map(journey => journey.journey_id);\n\n setUserCompletedJourneyIds(completedUserJourneysIds);\n }\n }, [userCompletedJourneys]);\n\n return (\n <JourneyContext.Provider value={memoizedContextValue}>\n {isJourneyActive && (\n <S.Overlay about=\"journey-overlay\" data-testid={currentJourneyId.current}>\n {coachmarkList.map((coachmark, index) => (\n <Coachmark key={`coachmark-${index}`} coachmark={coachmark} />\n ))}\n </S.Overlay>\n )}\n {children}\n </JourneyContext.Provider>\n );\n};\n"],"names":["JourneyContext","createContext","JourneyProvider","children","appId","userId","userCompletedJourneyIds","setUserCompletedJourneyIds","useState","coachmarkList","setCoachmarkList","isJourneyActive","setIsJourneyActive","currentIndex","useRef","currentJourneyId","timerRefs","postJourneyCompletion","usePostUserJourney","userCompletedJourneys","getJourneyProgress","useGetUserJourney","setJourney","useCallback","id","coachmarks","clearJourney","timer","endJourney","journeyId","prev","addCoachmark","coachmark","nextCoachmark","keepPrevActive","delayInMs","prevList","item","currIndex","updatedCoachmarkList","memoizedContextValue","useMemo","useEffect","completedUserJourneysIds","journey","jsxs","jsx","S.Overlay","index","Coachmark"],"mappings":";;;;;AAea,MAAAA,IAAiBC,EAAsC,IAAI,GAE3DC,IAA6C,CAAC,EAAE,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CC;AAAA,IAC5C,OAAO;AAAA,MACL,eAAAR;AAAA,MACA,YAAAX;AAAA,MACA,cAAAS;AAAA,MACA,cAAAL;AAAA,MACA,YAAAE;AAAA,MACA,YAAYnB;AAAA,MACZ,yBAAAH;AAAA,MACA,iBAAAK;AAAA,IAAA;AAAA,IAEF;AAAA,MACEsB;AAAA,MACAX;AAAA,MACAS;AAAA,MACAL;AAAA,MACAE;AAAA,MACAnB;AAAA,MACAH;AAAA,MACAK;AAAA,IACF;AAAA,EAAA;AAIF,SAAA+B,EAAU,MAAM;AACd,IAAItC,KAASC,KACXe,EAAmBf,GAAQ;AAAA,MACzB,QAAQD;AAAA,MACR,SAASC;AAAA,MACT,gBAAgB;AAAA,IAAA,CACjB;AAAA,EAEF,GAAA,CAACD,GAAOgB,GAAoBf,CAAM,CAAC,GAGtCqC,EAAU,MAAM;AACd,QAAIvB,GAAuB;AACzB,YAAMwB,IAA2BxB,EAAsB,IAAI,CAAAyB,MAAWA,EAAQ,UAAU;AAExF,MAAArC,EAA2BoC,CAAwB;AAAA,IACrD;AAAA,EAAA,GACC,CAACxB,CAAqB,CAAC,GAGvB,gBAAA0B,EAAA7C,EAAe,UAAf,EAAwB,OAAOwC,GAC7B,UAAA;AAAA,IACC7B,KAAA,gBAAAmC,EAACC,GAAA,EAAU,OAAM,mBAAkB,eAAahC,EAAiB,SAC9D,UAAAN,EAAc,IAAI,CAACuB,GAAWgB,MAC5B,gBAAAF,EAAAG,GAAA,EAAqC,WAAAjB,KAAtB,aAAagB,CAAK,EAA0B,CAC7D,EACH,CAAA;AAAA,IAED7C;AAAA,EACH,EAAA,CAAA;AAEJ;"}
|
1
|
+
{"version":3,"file":"journey-context-provider.js","sources":["../../../../src/features/journey/use-journey/journey-context-provider.tsx"],"sourcesContent":["/* eslint-disable no-console */\nimport type { TJourneyId } from '../journey-id/journey-id-types';\nimport type {\n ICoachmarkProps,\n IJourneyContext,\n IJourneyProviderProps,\n} from './journey-context-types';\nimport type { FC } from 'react';\n\nimport { createContext, useCallback, useEffect, useMemo, useRef, useState } from 'react';\n\nimport { Coachmark } from '../comps/coachmark/coachmark';\nimport { useGetUserJourney, usePostUserJourney } from '../user-journey-api/user-journey-api';\nimport * as S from './journey-styled';\n\nexport const JourneyContext = createContext<IJourneyContext | null>(null);\n\nexport const JourneyProvider: FC<IJourneyProviderProps> = ({ children, appId, userId }) => {\n const [userCompletedJourneyIds, setUserCompletedJourneyIds] = useState<TJourneyId[] | null>(null);\n const [coachmarkList, setCoachmarkList] = useState<ICoachmarkProps[]>([]);\n const [isBlockingJourney, setIsBlockingJourney] = useState(false);\n const [isJourneyActive, setIsJourneyActive] = useState(false);\n const currentIndex = useRef(-1);\n const currentJourneyId = useRef<TJourneyId | undefined>();\n const timerRefs = useRef<ReturnType<typeof setTimeout>[]>([]);\n\n const { post: postJourneyCompletion } = usePostUserJourney();\n const { data: userCompletedJourneys = null, get: getJourneyProgress } = useGetUserJourney();\n\n const setJourney = useCallback(\n (id: TJourneyId, coachmarks: ICoachmarkProps[], blockingJourney: boolean = true) => {\n if (coachmarkList.length > 0) {\n console.error(\n `setJourney: Other Journey is already active, Current Journey: ${currentJourneyId.current}, New Journey Request: ${id}`,\n );\n\n return;\n }\n setIsJourneyActive(true);\n setIsBlockingJourney(blockingJourney);\n currentJourneyId.current = id;\n currentIndex.current = -1;\n setCoachmarkList([...coachmarks]);\n },\n [coachmarkList.length],\n );\n\n const clearJourney = useCallback(() => {\n // Clear all timers\n timerRefs.current.forEach(timer => {\n clearTimeout(timer);\n });\n timerRefs.current = [];\n currentJourneyId.current = undefined;\n currentIndex.current = -1;\n setCoachmarkList([]);\n setIsJourneyActive(false);\n }, []);\n\n const endJourney = useCallback(\n (journeyId: TJourneyId) => {\n clearJourney();\n setUserCompletedJourneyIds(prev => {\n if (prev && !prev.includes(journeyId)) {\n return [...prev, journeyId];\n }\n\n return prev;\n });\n // fire the API (doesn’t block the UI)\n postJourneyCompletion({\n app_id: appId,\n user_id: userId,\n journey_id: journeyId,\n journey_status: 'COMPLETED',\n });\n },\n [appId, clearJourney, postJourneyCompletion, userId],\n );\n\n const addCoachmark = useCallback((id: TJourneyId, coachmark: ICoachmarkProps) => {\n if (!currentJourneyId.current || id !== currentJourneyId.current) {\n console.error(\n currentJourneyId.current\n ? `A Journey is already active, Current Journey: ${currentJourneyId.current}, New Journey Request: ${id}`\n : `addCoachmark was called before setJourney and Journey ID is undefined`,\n );\n\n return;\n }\n\n setCoachmarkList(prev => [...prev, coachmark]);\n }, []);\n\n const nextCoachmark = useCallback(\n (id: TJourneyId, keepPrevActive: boolean = false, delayInMs: number = 0) => {\n if (!currentJourneyId.current || id !== currentJourneyId.current) {\n console.error(\n currentJourneyId.current\n ? `nextCoachmark was called before setJourney`\n : `A Journey is already active, Current Journey: ${currentJourneyId.current}, New Journey Request: ${id}`,\n );\n\n return;\n }\n\n if (delayInMs !== 0) {\n // If delay is not 0, we will hide all them coachmarks and reveal only after the delay\n setCoachmarkList(prevList => {\n return prevList.map((item: ICoachmarkProps) => {\n return { ...item, isActive: false };\n });\n });\n }\n\n const timer = setTimeout(() => {\n clearTimeout(timer);\n const currIndex = currentIndex.current + 1;\n\n setCoachmarkList(prevList => {\n // Finish onboarding\n if (currIndex >= prevList.length || prevList.length === 0) {\n clearJourney();\n\n return [];\n }\n\n currentIndex.current = currIndex;\n const updatedCoachmarkList = [...prevList];\n\n (updatedCoachmarkList[currIndex] as ICoachmarkProps).isActive = true;\n\n if (currIndex > 0) {\n (updatedCoachmarkList[currIndex - 1] as ICoachmarkProps).isActive = keepPrevActive;\n }\n\n return updatedCoachmarkList;\n });\n }, delayInMs);\n\n timerRefs.current.push(timer);\n },\n [clearJourney],\n );\n\n const memoizedContextValue: IJourneyContext = useMemo(\n () => ({\n nextCoachmark,\n setJourney,\n addCoachmark,\n clearJourney,\n endJourney,\n coachmarks: coachmarkList,\n userCompletedJourneyIds,\n isJourneyActive,\n }),\n [\n nextCoachmark,\n setJourney,\n addCoachmark,\n clearJourney,\n endJourney,\n coachmarkList,\n userCompletedJourneyIds,\n isJourneyActive,\n ],\n );\n\n // Get the initial state of incompleteJourneys\n useEffect(() => {\n if (appId && userId) {\n getJourneyProgress(userId, {\n app_id: appId,\n user_id: userId,\n journey_status: 'COMPLETED',\n });\n }\n }, [appId, getJourneyProgress, userId]);\n\n // Set the data to context state initially\n useEffect(() => {\n if (userCompletedJourneys) {\n const completedUserJourneysIds = userCompletedJourneys.map(journey => journey.journey_id);\n\n setUserCompletedJourneyIds(completedUserJourneysIds);\n }\n }, [userCompletedJourneys]);\n\n return (\n <JourneyContext.Provider value={memoizedContextValue}>\n {isJourneyActive && (\n <S.Overlay\n about=\"journey-overlay\"\n data-testid={currentJourneyId.current}\n isBlockingJourney={isBlockingJourney}\n >\n {coachmarkList.map((coachmark, index) => (\n <Coachmark key={`coachmark-${index}`} coachmark={coachmark} />\n ))}\n </S.Overlay>\n )}\n {children}\n </JourneyContext.Provider>\n );\n};\n"],"names":["JourneyContext","createContext","JourneyProvider","children","appId","userId","userCompletedJourneyIds","setUserCompletedJourneyIds","useState","coachmarkList","setCoachmarkList","isBlockingJourney","setIsBlockingJourney","isJourneyActive","setIsJourneyActive","currentIndex","useRef","currentJourneyId","timerRefs","postJourneyCompletion","usePostUserJourney","userCompletedJourneys","getJourneyProgress","useGetUserJourney","setJourney","useCallback","id","coachmarks","blockingJourney","clearJourney","timer","endJourney","journeyId","prev","addCoachmark","coachmark","nextCoachmark","keepPrevActive","delayInMs","prevList","item","currIndex","updatedCoachmarkList","memoizedContextValue","useMemo","useEffect","completedUserJourneysIds","journey","jsxs","jsx","S.Overlay","index","Coachmark"],"mappings":";;;;;AAea,MAAAA,IAAiBC,EAAsC,IAAI,GAE3DC,IAA6C,CAAC,EAAE,UAAAC,GAAU,OAAAC,GAAO,QAAAC,QAAa;AACzF,QAAM,CAACC,GAAyBC,CAA0B,IAAIC,EAA8B,IAAI,GAC1F,CAACC,GAAeC,CAAgB,IAAIF,EAA4B,CAAE,CAA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AZ;AAAA,MACA,cAAAU;AAAA,MACA,cAAAL;AAAA,MACA,YAAAE;AAAA,MACA,YAAYtB;AAAA,MACZ,yBAAAH;AAAA,MACA,iBAAAO;AAAA,IAAA;AAAA,IAEF;AAAA,MACEuB;AAAA,MACAZ;AAAA,MACAU;AAAA,MACAL;AAAA,MACAE;AAAA,MACAtB;AAAA,MACAH;AAAA,MACAO;AAAA,IACF;AAAA,EAAA;AAIF,SAAAgC,EAAU,MAAM;AACd,IAAIzC,KAASC,KACXiB,EAAmBjB,GAAQ;AAAA,MACzB,QAAQD;AAAA,MACR,SAASC;AAAA,MACT,gBAAgB;AAAA,IAAA,CACjB;AAAA,EAEF,GAAA,CAACD,GAAOkB,GAAoBjB,CAAM,CAAC,GAGtCwC,EAAU,MAAM;AACd,QAAIxB,GAAuB;AACzB,YAAMyB,IAA2BzB,EAAsB,IAAI,CAAA0B,MAAWA,EAAQ,UAAU;AAExF,MAAAxC,EAA2BuC,CAAwB;AAAA,IACrD;AAAA,EAAA,GACC,CAACzB,CAAqB,CAAC,GAGvB,gBAAA2B,EAAAhD,EAAe,UAAf,EAAwB,OAAO2C,GAC7B,UAAA;AAAA,IACC9B,KAAA,gBAAAoC;AAAA,MAACC;AAAAA,MAAA;AAAA,QACC,OAAM;AAAA,QACN,eAAajC,EAAiB;AAAA,QAC9B,mBAAAN;AAAA,QAEC,UAAAF,EAAc,IAAI,CAAC0B,GAAWgB,MAC5B,gBAAAF,EAAAG,GAAA,EAAqC,WAAAjB,EAAtB,GAAA,aAAagB,CAAK,EAA0B,CAC7D;AAAA,MAAA;AAAA,IACH;AAAA,IAEDhD;AAAA,EACH,EAAA,CAAA;AAEJ;"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"journey-styled.js","sources":["../../../../src/features/journey/use-journey/journey-styled.tsx"],"sourcesContent":["import styled from 'styled-components';\n\nexport const Overlay = styled.div
|
1
|
+
{"version":3,"file":"journey-styled.js","sources":["../../../../src/features/journey/use-journey/journey-styled.tsx"],"sourcesContent":["import styled from 'styled-components';\n\nexport const Overlay = styled.div<{ isBlockingJourney: boolean }>`\n position: fixed;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n pointer-events: ${({ isBlockingJourney }) => (isBlockingJourney ? 'auto' : 'none')};\n z-index: ${({ theme }) => theme.zIndex.JOURNEY_OVERLAY};\n`;\n"],"names":["Overlay","styled","isBlockingJourney","theme"],"mappings":";AAEO,MAAMA,IAAUC,EAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAMV,CAAC,EAAE,mBAAAC,EAAA,MAAyBA,IAAoB,SAAS,MAAO;AAAA,aACvE,CAAC,EAAE,OAAAC,EAAA,MAAYA,EAAM,OAAO,eAAe;AAAA;"}
|
package/dist/index.d.ts
CHANGED
@@ -1297,8 +1297,9 @@ export declare interface IJourneyContext {
|
|
1297
1297
|
* Sets a journey with a list of coachmarks.
|
1298
1298
|
* @param id - The journey identifier.
|
1299
1299
|
* @param coachmark - The array of coachmarks to be used in this journey.
|
1300
|
+
* @param blockingJourney - If `true`, the journey will block user interaction with the app.
|
1300
1301
|
*/
|
1301
|
-
setJourney: (id: TJourneyId, coachmark: ICoachmarkProps[]) => void;
|
1302
|
+
setJourney: (id: TJourneyId, coachmark: ICoachmarkProps[], blockingJourney?: boolean) => void;
|
1302
1303
|
/**
|
1303
1304
|
* Clears the current journey, removing all coachmarks.
|
1304
1305
|
* Should be called inside useEffect to ensure cleanup.
|