@propknot/shared-ui 1.0.5 → 1.0.6
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/index.js +19 -1
- package/dist/index.mjs +19 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1545,15 +1545,33 @@ var CustomThemeProvider = ({ children }) => {
|
|
|
1545
1545
|
const [currentTheme, setCurrentTheme] = (0, import_react3.useState)("light");
|
|
1546
1546
|
const [loading, setLoading] = (0, import_react3.useState)(false);
|
|
1547
1547
|
const { user, companyBranding } = useAuth();
|
|
1548
|
+
const isEmbedded = new URLSearchParams(window.location.search).get("embedded") === "true";
|
|
1548
1549
|
const canModifyTheme = Boolean(user && (user.role === "admin" || user.role === "owner" || user.role === "property_manager" || user.role === "maintenance"));
|
|
1549
1550
|
(0, import_react3.useEffect)(() => {
|
|
1551
|
+
if (!isEmbedded) return;
|
|
1552
|
+
const handleMessage = (event) => {
|
|
1553
|
+
if (!event.origin.startsWith("http://localhost:")) return;
|
|
1554
|
+
const { type, theme } = event.data;
|
|
1555
|
+
if (type === "THEME_CHANGE" && theme && ["light", "dark"].includes(theme)) {
|
|
1556
|
+
console.log("Embedded app received theme change:", theme);
|
|
1557
|
+
setCurrentTheme(theme);
|
|
1558
|
+
}
|
|
1559
|
+
};
|
|
1560
|
+
window.addEventListener("message", handleMessage);
|
|
1561
|
+
if (window.parent !== window) {
|
|
1562
|
+
window.parent.postMessage({ type: "REQUEST_THEME" }, "*");
|
|
1563
|
+
}
|
|
1564
|
+
return () => window.removeEventListener("message", handleMessage);
|
|
1565
|
+
}, [isEmbedded]);
|
|
1566
|
+
(0, import_react3.useEffect)(() => {
|
|
1567
|
+
if (isEmbedded) return;
|
|
1550
1568
|
if (user && canModifyTheme) {
|
|
1551
1569
|
const themeToUse = user.themePreference || "light";
|
|
1552
1570
|
setCurrentTheme(themeToUse);
|
|
1553
1571
|
} else {
|
|
1554
1572
|
setCurrentTheme("light");
|
|
1555
1573
|
}
|
|
1556
|
-
}, [user, canModifyTheme]);
|
|
1574
|
+
}, [user, canModifyTheme, isEmbedded]);
|
|
1557
1575
|
const toggleTheme = async () => {
|
|
1558
1576
|
if (!canModifyTheme) return;
|
|
1559
1577
|
const newTheme = currentTheme === "light" ? "dark" : "light";
|
package/dist/index.mjs
CHANGED
|
@@ -1481,15 +1481,33 @@ var CustomThemeProvider = ({ children }) => {
|
|
|
1481
1481
|
const [currentTheme, setCurrentTheme] = useState3("light");
|
|
1482
1482
|
const [loading, setLoading] = useState3(false);
|
|
1483
1483
|
const { user, companyBranding } = useAuth();
|
|
1484
|
+
const isEmbedded = new URLSearchParams(window.location.search).get("embedded") === "true";
|
|
1484
1485
|
const canModifyTheme = Boolean(user && (user.role === "admin" || user.role === "owner" || user.role === "property_manager" || user.role === "maintenance"));
|
|
1485
1486
|
useEffect2(() => {
|
|
1487
|
+
if (!isEmbedded) return;
|
|
1488
|
+
const handleMessage = (event) => {
|
|
1489
|
+
if (!event.origin.startsWith("http://localhost:")) return;
|
|
1490
|
+
const { type, theme } = event.data;
|
|
1491
|
+
if (type === "THEME_CHANGE" && theme && ["light", "dark"].includes(theme)) {
|
|
1492
|
+
console.log("Embedded app received theme change:", theme);
|
|
1493
|
+
setCurrentTheme(theme);
|
|
1494
|
+
}
|
|
1495
|
+
};
|
|
1496
|
+
window.addEventListener("message", handleMessage);
|
|
1497
|
+
if (window.parent !== window) {
|
|
1498
|
+
window.parent.postMessage({ type: "REQUEST_THEME" }, "*");
|
|
1499
|
+
}
|
|
1500
|
+
return () => window.removeEventListener("message", handleMessage);
|
|
1501
|
+
}, [isEmbedded]);
|
|
1502
|
+
useEffect2(() => {
|
|
1503
|
+
if (isEmbedded) return;
|
|
1486
1504
|
if (user && canModifyTheme) {
|
|
1487
1505
|
const themeToUse = user.themePreference || "light";
|
|
1488
1506
|
setCurrentTheme(themeToUse);
|
|
1489
1507
|
} else {
|
|
1490
1508
|
setCurrentTheme("light");
|
|
1491
1509
|
}
|
|
1492
|
-
}, [user, canModifyTheme]);
|
|
1510
|
+
}, [user, canModifyTheme, isEmbedded]);
|
|
1493
1511
|
const toggleTheme = async () => {
|
|
1494
1512
|
if (!canModifyTheme) return;
|
|
1495
1513
|
const newTheme = currentTheme === "light" ? "dark" : "light";
|