@capytale/meta-player 0.3.15 → 0.3.16

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capytale/meta-player",
3
- "version": "0.3.15",
3
+ "version": "0.3.16",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite",
@@ -19,7 +19,7 @@
19
19
  }
20
20
  },
21
21
  "dependencies": {
22
- "@capytale/activity.js": "^3.1.6",
22
+ "@capytale/activity.js": "^3.1.7",
23
23
  "@capytale/capytale-anti-triche": "^0.2.1",
24
24
  "@capytale/capytale-rich-text-editor": "^0.4.3",
25
25
  "@reduxjs/toolkit": "^2.0.1",
@@ -32,6 +32,7 @@ import {
32
32
  } from "./features/activityData/activityDataSlice";
33
33
 
34
34
  import { initialState as layoutInitialState } from "./features/layout/layoutSlice";
35
+ import ExitWarning from "./features/activityData/ExitWarning";
35
36
 
36
37
  type AntiCheatOptions = {
37
38
  preserveDom: boolean;
@@ -81,6 +82,7 @@ const MetaPlayer: FC<MetaPlayerProps> = (props) => {
81
82
  <PrimeReactProvider value={primeSettings}>
82
83
  <Provider store={store}>
83
84
  <ThemeSwitcher />
85
+ <ExitWarning />
84
86
  <ErrorBoundary fallback={<div>Une erreur est survenue</div>}>
85
87
  <ActivityJSProvider options={props.activityJSOptions}>
86
88
  <Saver />
@@ -0,0 +1,26 @@
1
+ import { FC, useEffect } from "react";
2
+ import { useAppSelector } from "../../app/hooks";
3
+ import { selectIsDirty } from "./activityDataSlice";
4
+
5
+ const ExitWarning: FC = () => {
6
+ const isDirty = useAppSelector(selectIsDirty);
7
+
8
+ useEffect(() => {
9
+ const handleBeforeUnload = (e: BeforeUnloadEvent) => {
10
+ if (isDirty) {
11
+ e.preventDefault();
12
+ e.returnValue = true;
13
+ }
14
+ };
15
+
16
+ window.addEventListener("beforeunload", handleBeforeUnload);
17
+
18
+ return () => {
19
+ window.removeEventListener("beforeunload", handleBeforeUnload);
20
+ };
21
+ }, [isDirty]);
22
+
23
+ return null;
24
+ };
25
+
26
+ export default ExitWarning;