@anas_hameed/edly-saas-widget 0.2.53 → 0.2.55
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.
|
@@ -5,35 +5,42 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.DiscussionSidebarWidget = void 0;
|
|
7
7
|
var _react = require("react");
|
|
8
|
+
const COURSE_PAGE_PATTERN = /\/learning\/(course|preview\/course)\/[^/]+\/[^/]+/;
|
|
9
|
+
const DISCUSSIONS_IFRAME_SELECTOR = 'iframe[src*="inContextSidebar"]';
|
|
8
10
|
const DiscussionSidebarWidget = () => {
|
|
9
11
|
(0, _react.useEffect)(() => {
|
|
10
|
-
|
|
11
|
-
if (!isCoursePage) {
|
|
12
|
+
if (!COURSE_PAGE_PATTERN.test(window.location.pathname)) {
|
|
12
13
|
return undefined;
|
|
13
14
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
let rafId;
|
|
16
|
+
const closeDiscussions = () => {
|
|
17
|
+
cancelAnimationFrame(rafId);
|
|
18
|
+
rafId = requestAnimationFrame(() => {
|
|
17
19
|
window.postMessage({
|
|
18
20
|
type: 'learning.events.sidebar.close'
|
|
19
21
|
}, window.location.origin);
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
return false;
|
|
22
|
+
});
|
|
23
23
|
};
|
|
24
|
-
if (
|
|
25
|
-
|
|
24
|
+
if (document.querySelector(DISCUSSIONS_IFRAME_SELECTOR)) {
|
|
25
|
+
closeDiscussions();
|
|
26
26
|
}
|
|
27
|
+
|
|
28
|
+
// Stay alive across client-side navigations (next/prev unit).
|
|
29
|
+
// SidebarContextProvider resets hideDiscussionbar on each unitId change,
|
|
30
|
+
// re-mounting the iframe — observer catches it and closes again.
|
|
27
31
|
const observer = new MutationObserver(() => {
|
|
28
|
-
if (
|
|
29
|
-
|
|
32
|
+
if (document.querySelector(DISCUSSIONS_IFRAME_SELECTOR)) {
|
|
33
|
+
closeDiscussions();
|
|
30
34
|
}
|
|
31
35
|
});
|
|
32
36
|
observer.observe(document.body, {
|
|
33
37
|
childList: true,
|
|
34
38
|
subtree: true
|
|
35
39
|
});
|
|
36
|
-
return () =>
|
|
40
|
+
return () => {
|
|
41
|
+
observer.disconnect();
|
|
42
|
+
cancelAnimationFrame(rafId);
|
|
43
|
+
};
|
|
37
44
|
}, []);
|
|
38
45
|
return null;
|
|
39
46
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_react","require","
|
|
1
|
+
{"version":3,"file":"index.js","names":["_react","require","COURSE_PAGE_PATTERN","DISCUSSIONS_IFRAME_SELECTOR","DiscussionSidebarWidget","useEffect","test","window","location","pathname","undefined","rafId","closeDiscussions","cancelAnimationFrame","requestAnimationFrame","postMessage","type","origin","document","querySelector","observer","MutationObserver","observe","body","childList","subtree","disconnect","exports"],"sources":["../../src/DiscussionSidebarWidget/index.jsx"],"sourcesContent":["import { useEffect } from 'react';\n\nconst COURSE_PAGE_PATTERN = /\\/learning\\/(course|preview\\/course)\\/[^/]+\\/[^/]+/;\nconst DISCUSSIONS_IFRAME_SELECTOR = 'iframe[src*=\"inContextSidebar\"]';\n\nconst DiscussionSidebarWidget = () => {\n useEffect(() => {\n if (!COURSE_PAGE_PATTERN.test(window.location.pathname)) { return undefined; }\n\n let rafId;\n\n const closeDiscussions = () => {\n cancelAnimationFrame(rafId);\n rafId = requestAnimationFrame(() => {\n window.postMessage({ type: 'learning.events.sidebar.close' }, window.location.origin);\n });\n };\n\n if (document.querySelector(DISCUSSIONS_IFRAME_SELECTOR)) {\n closeDiscussions();\n }\n\n // Stay alive across client-side navigations (next/prev unit).\n // SidebarContextProvider resets hideDiscussionbar on each unitId change,\n // re-mounting the iframe — observer catches it and closes again.\n const observer = new MutationObserver(() => {\n if (document.querySelector(DISCUSSIONS_IFRAME_SELECTOR)) {\n closeDiscussions();\n }\n });\n\n observer.observe(document.body, { childList: true, subtree: true });\n\n return () => {\n observer.disconnect();\n cancelAnimationFrame(rafId);\n };\n }, []);\n\n return null;\n};\n\nexport { DiscussionSidebarWidget };\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,MAAMC,mBAAmB,GAAG,oDAAoD;AAChF,MAAMC,2BAA2B,GAAG,iCAAiC;AAErE,MAAMC,uBAAuB,GAAGA,CAAA,KAAM;EACpC,IAAAC,gBAAS,EAAC,MAAM;IACd,IAAI,CAACH,mBAAmB,CAACI,IAAI,CAACC,MAAM,CAACC,QAAQ,CAACC,QAAQ,CAAC,EAAE;MAAE,OAAOC,SAAS;IAAE;IAE7E,IAAIC,KAAK;IAET,MAAMC,gBAAgB,GAAGA,CAAA,KAAM;MAC7BC,oBAAoB,CAACF,KAAK,CAAC;MAC3BA,KAAK,GAAGG,qBAAqB,CAAC,MAAM;QAClCP,MAAM,CAACQ,WAAW,CAAC;UAAEC,IAAI,EAAE;QAAgC,CAAC,EAAET,MAAM,CAACC,QAAQ,CAACS,MAAM,CAAC;MACvF,CAAC,CAAC;IACJ,CAAC;IAED,IAAIC,QAAQ,CAACC,aAAa,CAAChB,2BAA2B,CAAC,EAAE;MACvDS,gBAAgB,CAAC,CAAC;IACpB;;IAEA;IACA;IACA;IACA,MAAMQ,QAAQ,GAAG,IAAIC,gBAAgB,CAAC,MAAM;MAC1C,IAAIH,QAAQ,CAACC,aAAa,CAAChB,2BAA2B,CAAC,EAAE;QACvDS,gBAAgB,CAAC,CAAC;MACpB;IACF,CAAC,CAAC;IAEFQ,QAAQ,CAACE,OAAO,CAACJ,QAAQ,CAACK,IAAI,EAAE;MAAEC,SAAS,EAAE,IAAI;MAAEC,OAAO,EAAE;IAAK,CAAC,CAAC;IAEnE,OAAO,MAAM;MACXL,QAAQ,CAACM,UAAU,CAAC,CAAC;MACrBb,oBAAoB,CAACF,KAAK,CAAC;IAC7B,CAAC;EACH,CAAC,EAAE,EAAE,CAAC;EAEN,OAAO,IAAI;AACb,CAAC;AAACgB,OAAA,CAAAvB,uBAAA,GAAAA,uBAAA","ignoreList":[]}
|