unscren
This commit is contained in:
parent
2f7f89e8b2
commit
f358a959bf
@ -21,12 +21,10 @@ import ViewPublicationPage from "./ViewPublicationPage/ViewPublicationPage";
|
|||||||
import { HelmetProvider } from "react-helmet-async";
|
import { HelmetProvider } from "react-helmet-async";
|
||||||
|
|
||||||
import "moment/dist/locale/ru";
|
import "moment/dist/locale/ru";
|
||||||
|
import unscreen from "@/ui_kit/unscreen";
|
||||||
moment.locale("ru");
|
moment.locale("ru");
|
||||||
const localeText = ruRU.components.MuiLocalizationProvider.defaultProps.localeText;
|
const localeText = ruRU.components.MuiLocalizationProvider.defaultProps.localeText;
|
||||||
|
|
||||||
console.log(localeText);
|
|
||||||
console.log(moment);
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
quizSettings?: QuizSettings;
|
quizSettings?: QuizSettings;
|
||||||
quizId: string;
|
quizId: string;
|
||||||
@ -128,8 +126,17 @@ function QuizAnswererInner({
|
|||||||
</QuizViewContext.Provider>
|
</QuizViewContext.Provider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function QuizAnswerer(props: Props) {
|
export default function QuizAnswerer(props: Props) {
|
||||||
|
useEffect(() => {
|
||||||
|
const root = document.getElementById("root");
|
||||||
|
const overlay = document.getElementById("hideoverlay");
|
||||||
|
|
||||||
|
if (root !== null && overlay !== null && props.quizSettings?.settings.cfg?.isUnSc) {
|
||||||
|
overlay.style.cssText =
|
||||||
|
"position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: black; z-index:999; opacity: 0;";
|
||||||
|
unscreen(overlay, root);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
return (
|
return (
|
||||||
<HelmetProvider>
|
<HelmetProvider>
|
||||||
<LocalizationProvider
|
<LocalizationProvider
|
||||||
@ -142,6 +149,7 @@ export default function QuizAnswerer(props: Props) {
|
|||||||
preventDuplicate={true}
|
preventDuplicate={true}
|
||||||
style={{ backgroundColor: lightTheme.palette.brightPurple.main }}
|
style={{ backgroundColor: lightTheme.palette.brightPurple.main }}
|
||||||
>
|
>
|
||||||
|
<div id="hideoverlay" />
|
||||||
<QuizAnswererInner {...props} />
|
<QuizAnswererInner {...props} />
|
||||||
</SnackbarProvider>
|
</SnackbarProvider>
|
||||||
</ThemeProvider>
|
</ThemeProvider>
|
||||||
|
@ -183,6 +183,7 @@ export const ResultForm = ({ resultQuestion }: ResultFormProps) => {
|
|||||||
display: "flex",
|
display: "flex",
|
||||||
justifyContent: "center",
|
justifyContent: "center",
|
||||||
}}
|
}}
|
||||||
|
onClick={(event) => event.preventDefault()}
|
||||||
>
|
>
|
||||||
<img
|
<img
|
||||||
alt="resultImage"
|
alt="resultImage"
|
||||||
|
@ -87,6 +87,7 @@ const StandartLayout = ({ alignType, quizHeaderBlock, quizMainBlock, backgroundB
|
|||||||
justifyContent: "center",
|
justifyContent: "center",
|
||||||
"& > img": { width: "100%", borderRadius: "12px" },
|
"& > img": { width: "100%", borderRadius: "12px" },
|
||||||
}}
|
}}
|
||||||
|
onClick={(event) => event.preventDefault()}
|
||||||
>
|
>
|
||||||
{backgroundBlock}
|
{backgroundBlock}
|
||||||
</Box>
|
</Box>
|
||||||
@ -204,6 +205,7 @@ const CenteredLayout = ({ quizHeaderBlock, quizMainBlock, backgroundBlock }: Lay
|
|||||||
justifyContent: "center",
|
justifyContent: "center",
|
||||||
"& > img": { width: "100%", borderRadius: "12px" },
|
"& > img": { width: "100%", borderRadius: "12px" },
|
||||||
}}
|
}}
|
||||||
|
onClick={(event) => event.preventDefault()}
|
||||||
>
|
>
|
||||||
{backgroundBlock}
|
{backgroundBlock}
|
||||||
</Box>
|
</Box>
|
||||||
|
@ -73,6 +73,7 @@ const StandartMobileLayout = ({ quizHeaderBlock, quizMainBlock, backgroundBlock
|
|||||||
borderRadius: "12px",
|
borderRadius: "12px",
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
|
onClick={(event) => event.preventDefault()}
|
||||||
>
|
>
|
||||||
{backgroundBlock}
|
{backgroundBlock}
|
||||||
</Box>
|
</Box>
|
||||||
@ -154,6 +155,7 @@ const ExpandedMobileLayout = ({ quizHeaderBlock, quizMainBlock, backgroundBlock
|
|||||||
minHeight: "100%",
|
minHeight: "100%",
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
|
onClick={(event) => event.preventDefault()}
|
||||||
>
|
>
|
||||||
{backgroundBlock}
|
{backgroundBlock}
|
||||||
</Box>
|
</Box>
|
||||||
@ -205,6 +207,7 @@ const CenteredMobileLayout = ({ quizHeaderBlock, quizMainBlock, backgroundBlock
|
|||||||
overflow: "hidden",
|
overflow: "hidden",
|
||||||
"& > img": { width: "100%", borderRadius: "12px" },
|
"& > img": { width: "100%", borderRadius: "12px" },
|
||||||
}}
|
}}
|
||||||
|
onClick={(event) => event.preventDefault()}
|
||||||
>
|
>
|
||||||
{backgroundBlock}
|
{backgroundBlock}
|
||||||
</Box>
|
</Box>
|
||||||
|
@ -105,6 +105,7 @@ export const StartPageViewPublication = () => {
|
|||||||
? "center"
|
? "center"
|
||||||
: undefined,
|
: undefined,
|
||||||
}}
|
}}
|
||||||
|
onClick={(event) => event.preventDefault()}
|
||||||
>
|
>
|
||||||
{settings.cfg.startpage.logo && (
|
{settings.cfg.startpage.logo && (
|
||||||
<img
|
<img
|
||||||
@ -220,6 +221,7 @@ export const StartPageViewPublication = () => {
|
|||||||
|
|
||||||
color: settings.cfg.startpageType === "expanded" ? "white" : "black",
|
color: settings.cfg.startpageType === "expanded" ? "white" : "black",
|
||||||
}}
|
}}
|
||||||
|
onClick={(event) => event.preventDefault()}
|
||||||
>
|
>
|
||||||
<QuizPreviewLayoutByType
|
<QuizPreviewLayoutByType
|
||||||
quizHeaderBlock={quizHeaderBlock}
|
quizHeaderBlock={quizHeaderBlock}
|
||||||
|
@ -28,7 +28,11 @@ export const File = ({ currentQuestion }: FileProps) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Box>
|
<Box>
|
||||||
<Typography variant="h5" color={theme.palette.text.primary} sx={{ wordBreak: "break-word" }}>
|
<Typography
|
||||||
|
variant="h5"
|
||||||
|
color={theme.palette.text.primary}
|
||||||
|
sx={{ wordBreak: "break-word" }}
|
||||||
|
>
|
||||||
{currentQuestion.title}
|
{currentQuestion.title}
|
||||||
</Typography>
|
</Typography>
|
||||||
<Box
|
<Box
|
||||||
@ -39,9 +43,13 @@ export const File = ({ currentQuestion }: FileProps) => {
|
|||||||
marginTop: "20px",
|
marginTop: "20px",
|
||||||
maxWidth: answer?.split("|")[0] ? "640px" : "600px",
|
maxWidth: answer?.split("|")[0] ? "640px" : "600px",
|
||||||
}}
|
}}
|
||||||
|
onClick={(event) => event.preventDefault()}
|
||||||
>
|
>
|
||||||
{answer?.split("|")[0] ? (
|
{answer?.split("|")[0] ? (
|
||||||
<UploadedFile currentQuestion={currentQuestion} setIsSending={setIsSending} />
|
<UploadedFile
|
||||||
|
currentQuestion={currentQuestion}
|
||||||
|
setIsSending={setIsSending}
|
||||||
|
/>
|
||||||
) : (
|
) : (
|
||||||
<UploadFile
|
<UploadFile
|
||||||
currentQuestion={currentQuestion}
|
currentQuestion={currentQuestion}
|
||||||
@ -51,7 +59,11 @@ export const File = ({ currentQuestion }: FileProps) => {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{answer && currentQuestion.content.type === "picture" && (
|
{answer && currentQuestion.content.type === "picture" && (
|
||||||
<img src={answer.split("|")[1]} style={{ marginTop: "15px", maxWidth: "300px", maxHeight: "300px" }} alt="" />
|
<img
|
||||||
|
src={answer.split("|")[1]}
|
||||||
|
style={{ marginTop: "15px", maxWidth: "300px", maxHeight: "300px" }}
|
||||||
|
alt=""
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
{answer && currentQuestion.content.type === "video" && (
|
{answer && currentQuestion.content.type === "video" && (
|
||||||
<video
|
<video
|
||||||
@ -65,7 +77,10 @@ export const File = ({ currentQuestion }: FileProps) => {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
<Modal open={modalWarningType !== null} onClose={() => setModalWarningType(null)}>
|
<Modal
|
||||||
|
open={modalWarningType !== null}
|
||||||
|
onClose={() => setModalWarningType(null)}
|
||||||
|
>
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
position: "absolute",
|
position: "absolute",
|
||||||
|
@ -6,7 +6,7 @@ import { useQuizViewStore } from "@stores/quizView";
|
|||||||
import RadioCheck from "@ui_kit/RadioCheck";
|
import RadioCheck from "@ui_kit/RadioCheck";
|
||||||
import RadioIcon from "@ui_kit/RadioIcon";
|
import RadioIcon from "@ui_kit/RadioIcon";
|
||||||
import { quizThemes } from "@utils/themes/Publication/themePublication";
|
import { quizThemes } from "@utils/themes/Publication/themePublication";
|
||||||
import { useMemo, type MouseEvent } from "react";
|
import { useMemo, type MouseEvent, useRef, useEffect } from "react";
|
||||||
import { useRootContainerSize } from "@contexts/RootContainerWidthContext";
|
import { useRootContainerSize } from "@contexts/RootContainerWidthContext";
|
||||||
|
|
||||||
type ImagesProps = {
|
type ImagesProps = {
|
||||||
@ -99,6 +99,9 @@ export const ImageVariant = ({
|
|||||||
const isMobile = useRootContainerSize() < 450;
|
const isMobile = useRootContainerSize() < 450;
|
||||||
const isTablet = useRootContainerSize() < 850;
|
const isTablet = useRootContainerSize() < 850;
|
||||||
|
|
||||||
|
const canvasRef = useRef<HTMLCanvasElement | null>(null);
|
||||||
|
const containerCanvasRef = useRef<HTMLDivElement | null>(null);
|
||||||
|
|
||||||
const onVariantClick = async (event: MouseEvent<HTMLDivElement>) => {
|
const onVariantClick = async (event: MouseEvent<HTMLDivElement>) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
@ -130,6 +133,23 @@ export const ImageVariant = ({
|
|||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (canvasRef.current !== null) {
|
||||||
|
const canvas = canvasRef.current;
|
||||||
|
const ctx = canvas.getContext("2d");
|
||||||
|
if (ctx !== null) {
|
||||||
|
const img = new Image();
|
||||||
|
img.src = choiceImgUrl;
|
||||||
|
|
||||||
|
img.onload = () => {
|
||||||
|
canvas.width = img.width;
|
||||||
|
canvas.height = img.height;
|
||||||
|
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
@ -151,9 +171,8 @@ export const ImageVariant = ({
|
|||||||
<Box sx={{ display: "flex", alignItems: "center", gap: "10px" }}>
|
<Box sx={{ display: "flex", alignItems: "center", gap: "10px" }}>
|
||||||
<Box sx={{ width: "100%", height: "300px" }}>
|
<Box sx={{ width: "100%", height: "300px" }}>
|
||||||
{variant.extendedText && (
|
{variant.extendedText && (
|
||||||
<img
|
<canvas
|
||||||
src={choiceImgUrl}
|
ref={canvasRef}
|
||||||
alt=""
|
|
||||||
style={{
|
style={{
|
||||||
display: "block",
|
display: "block",
|
||||||
width: "100%",
|
width: "100%",
|
||||||
@ -162,6 +181,18 @@ export const ImageVariant = ({
|
|||||||
borderRadius: "12px 12px 0 0",
|
borderRadius: "12px 12px 0 0",
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
// <img
|
||||||
|
// src={choiceImgUrl}
|
||||||
|
// alt=""
|
||||||
|
// style={{
|
||||||
|
// display: "block",
|
||||||
|
// width: "100%",
|
||||||
|
// height: "100%",
|
||||||
|
// objectFit: "cover",
|
||||||
|
// borderRadius: "12px 12px 0 0",
|
||||||
|
// }}
|
||||||
|
// />
|
||||||
)}
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
|
@ -21,7 +21,10 @@ export const Page = ({ currentQuestion }: PageProps) => {
|
|||||||
>
|
>
|
||||||
{currentQuestion.title}
|
{currentQuestion.title}
|
||||||
</Typography>
|
</Typography>
|
||||||
<Typography color={theme.palette.text.primary} sx={{ wordBreak: "break-word" }}>
|
<Typography
|
||||||
|
color={theme.palette.text.primary}
|
||||||
|
sx={{ wordBreak: "break-word" }}
|
||||||
|
>
|
||||||
{currentQuestion.content.text}
|
{currentQuestion.content.text}
|
||||||
</Typography>
|
</Typography>
|
||||||
<Box
|
<Box
|
||||||
@ -40,6 +43,7 @@ export const Page = ({ currentQuestion }: PageProps) => {
|
|||||||
border: "1px solid #9A9AAF",
|
border: "1px solid #9A9AAF",
|
||||||
overflow: "hidden",
|
overflow: "hidden",
|
||||||
}}
|
}}
|
||||||
|
onClick={(event) => event.preventDefault()}
|
||||||
>
|
>
|
||||||
<img
|
<img
|
||||||
key={currentQuestion.id}
|
key={currentQuestion.id}
|
||||||
|
@ -79,6 +79,7 @@ export const TextNormal = ({ currentQuestion, answer }: TextNormalProps) => {
|
|||||||
height: "300px",
|
height: "300px",
|
||||||
margin: "15px",
|
margin: "15px",
|
||||||
}}
|
}}
|
||||||
|
onClick={(event) => event.preventDefault()}
|
||||||
>
|
>
|
||||||
<img
|
<img
|
||||||
key={currentQuestion.id}
|
key={currentQuestion.id}
|
||||||
|
@ -81,7 +81,10 @@ export const TextSpecial = ({ currentQuestion, answer, stepNumber }: TextSpecial
|
|||||||
{currentQuestion.title}
|
{currentQuestion.title}
|
||||||
</Typography>
|
</Typography>
|
||||||
{isHorizontal && currentQuestion.content.back && currentQuestion.content.back !== " " && (
|
{isHorizontal && currentQuestion.content.back && currentQuestion.content.back !== " " && (
|
||||||
<Box sx={{ margin: "30px", width: "50vw", maxHeight: "550px" }}>
|
<Box
|
||||||
|
sx={{ margin: "30px", width: "50vw", maxHeight: "550px" }}
|
||||||
|
onClick={(event) => event.preventDefault()}
|
||||||
|
>
|
||||||
<img
|
<img
|
||||||
key={currentQuestion.id}
|
key={currentQuestion.id}
|
||||||
src={currentQuestion.content.back}
|
src={currentQuestion.content.back}
|
||||||
@ -119,7 +122,10 @@ export const TextSpecial = ({ currentQuestion, answer, stepNumber }: TextSpecial
|
|||||||
}
|
}
|
||||||
</Box>
|
</Box>
|
||||||
{!isHorizontal && currentQuestion.content.back && currentQuestion.content.back !== " " && (
|
{!isHorizontal && currentQuestion.content.back && currentQuestion.content.back !== " " && (
|
||||||
<Box sx={{ margin: "15px", width: "40vw" }}>
|
<Box
|
||||||
|
sx={{ margin: "15px", width: "40vw" }}
|
||||||
|
onClick={(event) => event.preventDefault()}
|
||||||
|
>
|
||||||
<img
|
<img
|
||||||
key={currentQuestion.id}
|
key={currentQuestion.id}
|
||||||
src={currentQuestion.content.back}
|
src={currentQuestion.content.back}
|
||||||
|
@ -105,7 +105,10 @@ export const Variant = ({ currentQuestion }: VariantProps) => {
|
|||||||
</Box>
|
</Box>
|
||||||
</Group>
|
</Group>
|
||||||
{choiceImgUrlQuestion && choiceImgUrlQuestion !== " " && choiceImgUrlQuestion !== null && (
|
{choiceImgUrlQuestion && choiceImgUrlQuestion !== " " && choiceImgUrlQuestion !== null && (
|
||||||
<Box sx={{ maxWidth: "400px", width: "100%", height: "300px" }}>
|
<Box
|
||||||
|
sx={{ maxWidth: "400px", width: "100%", height: "300px" }}
|
||||||
|
onClick={(event) => event.preventDefault()}
|
||||||
|
>
|
||||||
<img
|
<img
|
||||||
key={currentQuestion.id}
|
key={currentQuestion.id}
|
||||||
src={choiceImgUrlQuestion}
|
src={choiceImgUrlQuestion}
|
||||||
|
@ -134,6 +134,7 @@ export const Varimg = ({ currentQuestion }: VarimgProps) => {
|
|||||||
color: theme.palette.text.primary,
|
color: theme.palette.text.primary,
|
||||||
textAlign: "center",
|
textAlign: "center",
|
||||||
}}
|
}}
|
||||||
|
onClick={(event) => event.preventDefault()}
|
||||||
>
|
>
|
||||||
{answer ? (
|
{answer ? (
|
||||||
choiceImgUrlAnswer ? (
|
choiceImgUrlAnswer ? (
|
||||||
|
@ -61,6 +61,7 @@ export type QuizSettings = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export interface QuizConfig {
|
export interface QuizConfig {
|
||||||
|
isUnSc?: boolean;
|
||||||
spec: undefined | true;
|
spec: undefined | true;
|
||||||
type: QuizType;
|
type: QuizType;
|
||||||
noStartPage: boolean;
|
noStartPage: boolean;
|
||||||
|
78
lib/ui_kit/unscreen.ts
Normal file
78
lib/ui_kit/unscreen.ts
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
function addOverlay(overlay: HTMLElement) {
|
||||||
|
// const overlay = document.getElementById('overlay');
|
||||||
|
overlay.style.opacity = "1"; // Затемнено
|
||||||
|
overlay.style.pointerEvents = "auto"; // Включить клики
|
||||||
|
}
|
||||||
|
function removeOverlay(overlay: HTMLElement) {
|
||||||
|
overlay.style.opacity = "0"; // Вернуть в исходное состояние
|
||||||
|
overlay.style.pointerEvents = "none"; // Игнорировать клики
|
||||||
|
}
|
||||||
|
function addRemoveOverlayTimer(overlay: HTMLElement, time = 1000) {
|
||||||
|
addOverlay(overlay);
|
||||||
|
setTimeout(() => {
|
||||||
|
removeOverlay(overlay);
|
||||||
|
}, time); // 1 секунда затемнения
|
||||||
|
}
|
||||||
|
|
||||||
|
// Флаги для отслеживания состояния
|
||||||
|
let isMouseInside = true;
|
||||||
|
let isWindowFocused = true;
|
||||||
|
|
||||||
|
export default function unscreen(overlay: HTMLElement, root: HTMLElement) {
|
||||||
|
let focusTimeout: NodeJS.Timeout | undefined;
|
||||||
|
// Проверка состояния и выполнение нужного действия
|
||||||
|
function checkFocusAndMouse() {
|
||||||
|
if (!isWindowFocused || !isMouseInside) {
|
||||||
|
// ИЛИ
|
||||||
|
addOverlay(overlay);
|
||||||
|
} else if (isWindowFocused && isMouseInside) {
|
||||||
|
// И
|
||||||
|
removeOverlay(overlay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Добавляем обработчики событий
|
||||||
|
window.addEventListener("blur", () => {
|
||||||
|
console.log("blur");
|
||||||
|
isWindowFocused = false;
|
||||||
|
checkFocusAndMouse(); // Проверяем состояние
|
||||||
|
}); // Когда окно теряет фокус
|
||||||
|
|
||||||
|
window.addEventListener("focus", () => {
|
||||||
|
isWindowFocused = true;
|
||||||
|
checkFocusAndMouse(); // Проверяем состояние
|
||||||
|
}); // Когда окно получает фокус
|
||||||
|
|
||||||
|
window.addEventListener("mouseleave", () => {
|
||||||
|
console.log("mouseleave");
|
||||||
|
isMouseInside = false;
|
||||||
|
checkFocusAndMouse(); // Проверяем состояние
|
||||||
|
}); // Когда мышка покидает окно
|
||||||
|
|
||||||
|
window.addEventListener("mouseenter", () => {
|
||||||
|
console.log("mouseenter");
|
||||||
|
isMouseInside = true;
|
||||||
|
checkFocusAndMouse(); // Проверяем состояние
|
||||||
|
}); // Когда мышка возвращается в окно
|
||||||
|
|
||||||
|
root.addEventListener("contextmenu", (event) => event.preventDefault());
|
||||||
|
|
||||||
|
window.addEventListener("keydown", function (event) {
|
||||||
|
event.preventDefault();
|
||||||
|
if (event.key === "PrintScreen" || (event.ctrlKey && event.key === "p")) {
|
||||||
|
addRemoveOverlayTimer(overlay);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Проверка для мобильных устройств
|
||||||
|
root.addEventListener("touchstart", function (event) {
|
||||||
|
// Пример: если есть более чем один жест
|
||||||
|
if (event.touches.length > 1) {
|
||||||
|
addRemoveOverlayTimer(overlay);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
window.addEventListener("beforeprint", function () {
|
||||||
|
addRemoveOverlayTimer(overlay);
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user