@cuemath/leap 3.2.11 → 3.2.12
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,21 +1,21 @@
|
|
1
|
-
import { jsx as
|
2
|
-
import { memo as
|
1
|
+
import { jsx as L } from "react/jsx-runtime";
|
2
|
+
import { memo as M, useRef as y, useCallback as R, useEffect as m } from "react";
|
3
3
|
import g from "../hooks/use-learnosity-append.js";
|
4
|
-
import { LearnosityQuestionContainer as
|
5
|
-
const
|
4
|
+
import { LearnosityQuestionContainer as O } from "./worksheet-question-styled.js";
|
5
|
+
const Q = ["numberline", "imageclozeassociationV2"], $ = M(
|
6
6
|
({
|
7
|
-
signedRequest:
|
7
|
+
signedRequest: v,
|
8
8
|
appended: o,
|
9
9
|
canRender: I,
|
10
10
|
canForceAppend: a,
|
11
11
|
question: t,
|
12
12
|
response: s,
|
13
|
-
learnosity:
|
14
|
-
isConceptIntro:
|
13
|
+
learnosity: _,
|
14
|
+
isConceptIntro: A,
|
15
15
|
simState: c,
|
16
|
-
onMediaStateChange:
|
16
|
+
onMediaStateChange: w
|
17
17
|
}) => {
|
18
|
-
const l =
|
18
|
+
const l = y(null), n = y(s), { forceAppend: p } = g(v), d = R(
|
19
19
|
(e) => {
|
20
20
|
const { source: r, data: i } = e, { type: u } = i ?? {};
|
21
21
|
u === "SIM_IS_READY" ? r.postMessage(
|
@@ -27,10 +27,10 @@ const N = R(
|
|
27
27
|
}
|
28
28
|
},
|
29
29
|
"*"
|
30
|
-
) : u === "SIM_STATE_UPDATE" &&
|
30
|
+
) : u === "SIM_STATE_UPDATE" && w(t, "SIMULATION", e.data.payload);
|
31
31
|
},
|
32
|
-
[a, c,
|
33
|
-
),
|
32
|
+
[a, c, w, t]
|
33
|
+
), E = R(
|
34
34
|
(e) => {
|
35
35
|
window.requestAnimationFrame(() => {
|
36
36
|
var i, u, T;
|
@@ -40,20 +40,20 @@ const N = R(
|
|
40
40
|
}), (T = l.current) == null || T.append(r), p({
|
41
41
|
question: t,
|
42
42
|
response: e,
|
43
|
-
removeOldElements: t.type
|
43
|
+
removeOldElements: Q.includes(t.type) ? "before" : "after",
|
44
44
|
callback: (f) => {
|
45
|
-
f || (n.current && n.current !== e ?
|
45
|
+
f || (n.current && n.current !== e ? E(n.current) : n.current = void 0);
|
46
46
|
}
|
47
47
|
});
|
48
48
|
});
|
49
49
|
},
|
50
50
|
[p, t]
|
51
|
-
),
|
51
|
+
), S = y(!1);
|
52
52
|
return m(() => {
|
53
53
|
let e;
|
54
|
-
return I && (
|
54
|
+
return I && (S.current || (e = window.requestAnimationFrame(() => {
|
55
55
|
const r = n.current ?? s;
|
56
|
-
|
56
|
+
S.current = !0, _.appendQuestion({
|
57
57
|
questions: [t],
|
58
58
|
...r ? {
|
59
59
|
responses: {
|
@@ -67,7 +67,7 @@ const N = R(
|
|
67
67
|
}))), () => {
|
68
68
|
e && window.cancelAnimationFrame(e);
|
69
69
|
};
|
70
|
-
}, [I,
|
70
|
+
}, [I, _, t, s]), m(() => {
|
71
71
|
var e;
|
72
72
|
return o && (n.current = void 0, (e = l.current) != null && e.querySelector("iframe") && window.addEventListener("message", d)), () => {
|
73
73
|
window.removeEventListener("message", d);
|
@@ -85,19 +85,19 @@ const N = R(
|
|
85
85
|
));
|
86
86
|
}
|
87
87
|
}, [o, a, c]), m(() => {
|
88
|
-
o && s && a && s !== n.current && (n.current ? n.current = s : (n.current = s,
|
89
|
-
}, [o, a, s,
|
90
|
-
|
88
|
+
o && s && a && s !== n.current && (n.current ? n.current = s : (n.current = s, E(s)));
|
89
|
+
}, [o, a, s, E]), /* @__PURE__ */ L(
|
90
|
+
O,
|
91
91
|
{
|
92
92
|
ref: l,
|
93
|
-
$isConceptIntro:
|
93
|
+
$isConceptIntro: A,
|
94
94
|
$isTeacher: a,
|
95
|
-
children: /* @__PURE__ */
|
95
|
+
children: /* @__PURE__ */ L("div", { className: `learnosity-response question-${t.response_id}` })
|
96
96
|
}
|
97
97
|
);
|
98
98
|
}
|
99
99
|
);
|
100
100
|
export {
|
101
|
-
|
101
|
+
$ as default
|
102
102
|
};
|
103
103
|
//# sourceMappingURL=learnosity-question.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"learnosity-question.js","sources":["../../../../../src/features/worksheet/worksheet/worksheet-question/learnosity-question.tsx"],"sourcesContent":["import type { ILearnosityQuestionResponse } from '../worksheet-types';\nimport type { ILearnosityQuestionProps } from './worksheet-question-types';\nimport type { FC } from 'react';\n\nimport { memo, useCallback, useEffect, useRef } from 'react';\n\nimport useLearnosityAppend from '../hooks/use-learnosity-append';\nimport * as Styled from './worksheet-question-styled';\n\nconst LearnosityQuestion: FC<ILearnosityQuestionProps> = memo(\n ({\n signedRequest,\n appended,\n canRender,\n canForceAppend,\n question,\n response,\n learnosity,\n isConceptIntro,\n simState,\n onMediaStateChange,\n }) => {\n const containerElementRef = useRef<HTMLDivElement>(null);\n const latestQuestionResponseRef = useRef<ILearnosityQuestionResponse | undefined>(response);\n const { forceAppend } = useLearnosityAppend(signedRequest);\n\n const handleSimIframeMessage = useCallback(\n (event: MessageEvent) => {\n const { source, data } = event;\n const { type } = data ?? ({} as { type: string });\n\n if (type === 'SIM_IS_READY') {\n (source as Window).postMessage(\n {\n type: 'SIMULATION_CONFIG',\n payload: {\n userRole: canForceAppend ? 'teacher' : 'student',\n simulationState: simState,\n },\n },\n '*',\n );\n } else if (type === 'SIM_STATE_UPDATE') {\n onMediaStateChange(question, 'SIMULATION', event.data.payload);\n }\n },\n [canForceAppend, simState, onMediaStateChange, question],\n );\n\n const updateResponse = useCallback(\n (newResponse: ILearnosityQuestionResponse) => {\n window.requestAnimationFrame(() => {\n const questionElement = document.createElement('div');\n\n questionElement.classList.add('learnosity-response');\n questionElement.classList.add(`question-${question.response_id}`);\n // Drawing questions looks for already appended path elements with id, if present it will not append the path, to overcome this issue we are adding temp to the id\n containerElementRef.current?.children[0]\n ?.querySelectorAll('.lrn_drawing svg path')\n .forEach(path => {\n path.id = `${path.id} + temp`;\n });\n\n containerElementRef.current?.append(questionElement);\n forceAppend({\n question,\n response: newResponse,\n removeOldElements: question.type
|
1
|
+
{"version":3,"file":"learnosity-question.js","sources":["../../../../../src/features/worksheet/worksheet/worksheet-question/learnosity-question.tsx"],"sourcesContent":["import type { ILearnosityQuestionResponse } from '../worksheet-types';\nimport type { ILearnosityQuestionProps } from './worksheet-question-types';\nimport type { FC } from 'react';\n\nimport { memo, useCallback, useEffect, useRef } from 'react';\n\nimport useLearnosityAppend from '../hooks/use-learnosity-append';\nimport * as Styled from './worksheet-question-styled';\n\nconst REMOVE_BEFORE_QUESTIONS = ['numberline', 'imageclozeassociationV2'];\n\nconst LearnosityQuestion: FC<ILearnosityQuestionProps> = memo(\n ({\n signedRequest,\n appended,\n canRender,\n canForceAppend,\n question,\n response,\n learnosity,\n isConceptIntro,\n simState,\n onMediaStateChange,\n }) => {\n const containerElementRef = useRef<HTMLDivElement>(null);\n const latestQuestionResponseRef = useRef<ILearnosityQuestionResponse | undefined>(response);\n const { forceAppend } = useLearnosityAppend(signedRequest);\n\n const handleSimIframeMessage = useCallback(\n (event: MessageEvent) => {\n const { source, data } = event;\n const { type } = data ?? ({} as { type: string });\n\n if (type === 'SIM_IS_READY') {\n (source as Window).postMessage(\n {\n type: 'SIMULATION_CONFIG',\n payload: {\n userRole: canForceAppend ? 'teacher' : 'student',\n simulationState: simState,\n },\n },\n '*',\n );\n } else if (type === 'SIM_STATE_UPDATE') {\n onMediaStateChange(question, 'SIMULATION', event.data.payload);\n }\n },\n [canForceAppend, simState, onMediaStateChange, question],\n );\n\n const updateResponse = useCallback(\n (newResponse: ILearnosityQuestionResponse) => {\n window.requestAnimationFrame(() => {\n const questionElement = document.createElement('div');\n\n questionElement.classList.add('learnosity-response');\n questionElement.classList.add(`question-${question.response_id}`);\n // Drawing questions looks for already appended path elements with id, if present it will not append the path, to overcome this issue we are adding temp to the id\n containerElementRef.current?.children[0]\n ?.querySelectorAll('.lrn_drawing svg path')\n .forEach(path => {\n path.id = `${path.id} + temp`;\n });\n\n containerElementRef.current?.append(questionElement);\n forceAppend({\n question,\n response: newResponse,\n removeOldElements: REMOVE_BEFORE_QUESTIONS.includes(question.type) ? 'before' : 'after',\n callback: error => {\n if (error) return;\n\n if (\n latestQuestionResponseRef.current &&\n latestQuestionResponseRef.current !== newResponse\n )\n updateResponse(latestQuestionResponseRef.current);\n else latestQuestionResponseRef.current = undefined;\n },\n });\n });\n },\n [forceAppend, question],\n );\n\n const appendQuestionCalledRef = useRef(false);\n\n useEffect(() => {\n let requestId: number;\n\n if (canRender) {\n if (!appendQuestionCalledRef.current) {\n requestId = window.requestAnimationFrame(() => {\n const appenndableResponse = latestQuestionResponseRef.current ?? response;\n\n appendQuestionCalledRef.current = true;\n learnosity.appendQuestion({\n questions: [question],\n ...(appenndableResponse\n ? {\n responses: {\n [question.response_id]: {\n // Learnosity is mutating the response object, so we need to clone it\n ...appenndableResponse,\n },\n },\n }\n : {}),\n });\n });\n }\n }\n\n return () => {\n if (requestId) window.cancelAnimationFrame(requestId);\n };\n }, [canRender, learnosity, question, response]);\n\n useEffect(() => {\n if (appended) {\n latestQuestionResponseRef.current = undefined;\n\n if (containerElementRef.current?.querySelector('iframe')) {\n window.addEventListener('message', handleSimIframeMessage);\n }\n }\n\n return () => {\n window.removeEventListener('message', handleSimIframeMessage);\n };\n }, [appended, handleSimIframeMessage]);\n\n useEffect(() => {\n if (simState && appended) {\n const simIframe = containerElementRef.current?.querySelector('iframe');\n\n if (simIframe) {\n simIframe.contentWindow?.postMessage(\n {\n type: 'SIM_STATE_UPDATE',\n payload: simState,\n },\n '*',\n );\n }\n }\n }, [appended, canForceAppend, simState]);\n\n useEffect(() => {\n if (appended && response && canForceAppend) {\n if (response !== latestQuestionResponseRef.current) {\n if (!latestQuestionResponseRef.current) {\n latestQuestionResponseRef.current = response;\n updateResponse(response);\n } else {\n latestQuestionResponseRef.current = response;\n }\n }\n }\n }, [appended, canForceAppend, response, updateResponse]);\n\n return (\n <Styled.LearnosityQuestionContainer\n ref={containerElementRef}\n $isConceptIntro={isConceptIntro}\n $isTeacher={canForceAppend}\n >\n <div className={`learnosity-response question-${question.response_id}`} />\n </Styled.LearnosityQuestionContainer>\n );\n },\n);\n\nexport default LearnosityQuestion;\n"],"names":["REMOVE_BEFORE_QUESTIONS","LearnosityQuestion","memo","signedRequest","appended","canRender","canForceAppend","question","response","learnosity","isConceptIntro","simState","onMediaStateChange","containerElementRef","useRef","latestQuestionResponseRef","forceAppend","useLearnosityAppend","handleSimIframeMessage","useCallback","event","source","data","type","updateResponse","newResponse","questionElement","_b","_a","path","_c","error","appendQuestionCalledRef","useEffect","requestId","appenndableResponse","simIframe","jsx","Styled.LearnosityQuestionContainer"],"mappings":";;;;AASA,MAAMA,IAA0B,CAAC,cAAc,yBAAyB,GAElEC,IAAmDC;AAAA,EACvD,CAAC;AAAA,IACC,eAAAC;AAAA,IACA,UAAAC;AAAA,IACA,WAAAC;AAAA,IACA,gBAAAC;AAAA,IACA,UAAAC;AAAA,IACA,UAAAC;AAAA,IACA,YAAAC;AAAA,IACA,gBAAAC;AAAA,IACA,UAAAC;AAAA,IACA,oBAAAC;AAAA,EAAA,MACI;AACE,UAAAC,IAAsBC,EAAuB,IAAI,GACjDC,IAA4BD,EAAgDN,CAAQ,GACpF,EAAE,aAAAQ,EAAA,IAAgBC,EAAoBd,CAAa,GAEnDe,IAAyBC;AAAA,MAC7B,CAACC,MAAwB;AACjB,cAAA,EAAE,QAAAC,GAAQ,MAAAC,EAAS,IAAAF,GACnB,EAAE,MAAAG,EAAA,IAASD,KAAS;AAE1B,QAAIC,MAAS,iBACVF,EAAkB;AAAA,UACjB;AAAA,YACE,MAAM;AAAA,YACN,SAAS;AAAA,cACP,UAAUf,IAAiB,YAAY;AAAA,cACvC,iBAAiBK;AAAA,YACnB;AAAA,UACF;AAAA,UACA;AAAA,QAAA,IAEOY,MAAS,sBAClBX,EAAmBL,GAAU,cAAca,EAAM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