@anas_hameed/edly-saas-widget 0.2.55 → 0.2.56
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.
|
@@ -7,30 +7,45 @@ exports.DiscussionSidebarWidget = void 0;
|
|
|
7
7
|
var _react = require("react");
|
|
8
8
|
const COURSE_PAGE_PATTERN = /\/learning\/(course|preview\/course)\/[^/]+\/[^/]+/;
|
|
9
9
|
const DISCUSSIONS_IFRAME_SELECTOR = 'iframe[src*="inContextSidebar"]';
|
|
10
|
+
const OUTLINE_TOGGLE_SELECTOR = '.outline-sidebar-toggle-btn';
|
|
10
11
|
const DiscussionSidebarWidget = () => {
|
|
11
12
|
(0, _react.useEffect)(() => {
|
|
12
13
|
if (!COURSE_PAGE_PATTERN.test(window.location.pathname)) {
|
|
13
14
|
return undefined;
|
|
14
15
|
}
|
|
15
16
|
let rafId;
|
|
16
|
-
|
|
17
|
+
let lastHandledPath = null;
|
|
18
|
+
const switchToOutline = () => {
|
|
19
|
+
const currentPath = window.location.pathname;
|
|
20
|
+
if (currentPath === lastHandledPath) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
17
23
|
cancelAnimationFrame(rafId);
|
|
18
24
|
rafId = requestAnimationFrame(() => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
25
|
+
const outlineToggle = document.querySelector(OUTLINE_TOGGLE_SELECTOR);
|
|
26
|
+
if (outlineToggle) {
|
|
27
|
+
outlineToggle.click();
|
|
28
|
+
} else {
|
|
29
|
+
// Mobile or outline unavailable — just close discussions
|
|
30
|
+
window.postMessage({
|
|
31
|
+
type: 'learning.events.sidebar.close'
|
|
32
|
+
}, window.location.origin);
|
|
33
|
+
}
|
|
34
|
+
lastHandledPath = currentPath;
|
|
22
35
|
});
|
|
23
36
|
};
|
|
24
37
|
if (document.querySelector(DISCUSSIONS_IFRAME_SELECTOR)) {
|
|
25
|
-
|
|
38
|
+
switchToOutline();
|
|
26
39
|
}
|
|
27
40
|
|
|
28
41
|
// Stay alive across client-side navigations (next/prev unit).
|
|
29
|
-
// SidebarContextProvider resets
|
|
30
|
-
//
|
|
42
|
+
// SidebarContextProvider resets currentSidebar to discussions on each
|
|
43
|
+
// unitId change — observer catches the iframe reappearing and switches
|
|
44
|
+
// back to outline. lastHandledPath prevents interfering when the user
|
|
45
|
+
// manually opens discussions on the same page.
|
|
31
46
|
const observer = new MutationObserver(() => {
|
|
32
47
|
if (document.querySelector(DISCUSSIONS_IFRAME_SELECTOR)) {
|
|
33
|
-
|
|
48
|
+
switchToOutline();
|
|
34
49
|
}
|
|
35
50
|
});
|
|
36
51
|
observer.observe(document.body, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_react","require","COURSE_PAGE_PATTERN","DISCUSSIONS_IFRAME_SELECTOR","DiscussionSidebarWidget","useEffect","test","window","location","pathname","undefined","rafId","
|
|
1
|
+
{"version":3,"file":"index.js","names":["_react","require","COURSE_PAGE_PATTERN","DISCUSSIONS_IFRAME_SELECTOR","OUTLINE_TOGGLE_SELECTOR","DiscussionSidebarWidget","useEffect","test","window","location","pathname","undefined","rafId","lastHandledPath","switchToOutline","currentPath","cancelAnimationFrame","requestAnimationFrame","outlineToggle","document","querySelector","click","postMessage","type","origin","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\"]';\nconst OUTLINE_TOGGLE_SELECTOR = '.outline-sidebar-toggle-btn';\n\nconst DiscussionSidebarWidget = () => {\n useEffect(() => {\n if (!COURSE_PAGE_PATTERN.test(window.location.pathname)) { return undefined; }\n\n let rafId;\n let lastHandledPath = null;\n\n const switchToOutline = () => {\n const currentPath = window.location.pathname;\n if (currentPath === lastHandledPath) { return; }\n\n cancelAnimationFrame(rafId);\n rafId = requestAnimationFrame(() => {\n const outlineToggle = document.querySelector(OUTLINE_TOGGLE_SELECTOR);\n if (outlineToggle) {\n outlineToggle.click();\n } else {\n // Mobile or outline unavailable — just close discussions\n window.postMessage({ type: 'learning.events.sidebar.close' }, window.location.origin);\n }\n lastHandledPath = currentPath;\n });\n };\n\n if (document.querySelector(DISCUSSIONS_IFRAME_SELECTOR)) {\n switchToOutline();\n }\n\n // Stay alive across client-side navigations (next/prev unit).\n // SidebarContextProvider resets currentSidebar to discussions on each\n // unitId change — observer catches the iframe reappearing and switches\n // back to outline. lastHandledPath prevents interfering when the user\n // manually opens discussions on the same page.\n const observer = new MutationObserver(() => {\n if (document.querySelector(DISCUSSIONS_IFRAME_SELECTOR)) {\n switchToOutline();\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;AACrE,MAAMC,uBAAuB,GAAG,6BAA6B;AAE7D,MAAMC,uBAAuB,GAAGA,CAAA,KAAM;EACpC,IAAAC,gBAAS,EAAC,MAAM;IACd,IAAI,CAACJ,mBAAmB,CAACK,IAAI,CAACC,MAAM,CAACC,QAAQ,CAACC,QAAQ,CAAC,EAAE;MAAE,OAAOC,SAAS;IAAE;IAE7E,IAAIC,KAAK;IACT,IAAIC,eAAe,GAAG,IAAI;IAE1B,MAAMC,eAAe,GAAGA,CAAA,KAAM;MAC5B,MAAMC,WAAW,GAAGP,MAAM,CAACC,QAAQ,CAACC,QAAQ;MAC5C,IAAIK,WAAW,KAAKF,eAAe,EAAE;QAAE;MAAQ;MAE/CG,oBAAoB,CAACJ,KAAK,CAAC;MAC3BA,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