@capytale/meta-player 0.4.0 → 0.4.1
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 +4 -13
- package/src/App.tsx +18 -1
- package/tsconfig.json +0 -1
- package/vite.config.ts +1 -7
- package/.eslintrc.json +0 -36
- package/src/setupTests.ts +0 -1
- package/src/utils/test-utils.tsx +0 -65
package/package.json
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capytale/meta-player",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "vite",
|
|
7
7
|
"start": "vite",
|
|
8
8
|
"build": "tsc && vite build",
|
|
9
9
|
"preview": "vite preview",
|
|
10
|
-
"test": "vitest run",
|
|
11
10
|
"format": "prettier --write .",
|
|
12
|
-
"lint": "eslint .",
|
|
13
|
-
"lint:fix": "eslint --fix .",
|
|
14
11
|
"type-check": "tsc --noEmit"
|
|
15
12
|
},
|
|
16
13
|
"overrides": {
|
|
@@ -19,7 +16,7 @@
|
|
|
19
16
|
}
|
|
20
17
|
},
|
|
21
18
|
"dependencies": {
|
|
22
|
-
"@capytale/activity.js": "^3.1.
|
|
19
|
+
"@capytale/activity.js": "^3.1.8",
|
|
23
20
|
"@capytale/capytale-anti-triche": "^0.2.1",
|
|
24
21
|
"@capytale/capytale-rich-text-editor": "^0.4.3",
|
|
25
22
|
"@reduxjs/toolkit": "^2.0.1",
|
|
@@ -39,20 +36,14 @@
|
|
|
39
36
|
"@testing-library/user-event": "^14.5.2",
|
|
40
37
|
"@types/react": "^18.3.8",
|
|
41
38
|
"@types/react-dom": "^18.3.0",
|
|
42
|
-
"@vitejs/plugin-react": "^4.3.
|
|
43
|
-
"eslint": "^8.56.0",
|
|
44
|
-
"eslint-config-prettier": "^9.1.0",
|
|
45
|
-
"eslint-config-react-app": "^7.0.1",
|
|
46
|
-
"eslint-plugin-prettier": "^5.1.3",
|
|
47
|
-
"eslint-plugin-react-hooks": "^4.6.2",
|
|
39
|
+
"@vitejs/plugin-react": "^4.3.4",
|
|
48
40
|
"jsdom": "^23.2.0",
|
|
49
41
|
"prettier": "^3.2.1",
|
|
50
42
|
"react": "^18.3.1",
|
|
51
43
|
"react-dom": "^18.3.1",
|
|
52
44
|
"sass": "^1.75.0",
|
|
53
45
|
"typescript": "^5.3.3",
|
|
54
|
-
"vite": "^
|
|
55
|
-
"vitest": "^1.2.0"
|
|
46
|
+
"vite": "^6.0.2"
|
|
56
47
|
},
|
|
57
48
|
"peerDependencies": {
|
|
58
49
|
"react": "^18.3.1",
|
package/src/App.tsx
CHANGED
|
@@ -13,15 +13,17 @@ import {
|
|
|
13
13
|
selectOrientation,
|
|
14
14
|
toggleIsPedagoVisible,
|
|
15
15
|
} from "./features/layout/layoutSlice";
|
|
16
|
-
import { FC, PropsWithChildren } from "react";
|
|
16
|
+
import { FC, KeyboardEvent, PropsWithChildren, useCallback } from "react";
|
|
17
17
|
import { Tooltip } from "primereact/tooltip";
|
|
18
18
|
import {
|
|
19
19
|
selectHasGradingOrComments,
|
|
20
20
|
selectHasInstructions,
|
|
21
|
+
selectIsDirty,
|
|
21
22
|
selectMode,
|
|
22
23
|
} from "./features/activityData/activityDataSlice";
|
|
23
24
|
import settings from "./settings";
|
|
24
25
|
import ReviewNavbar from "./features/navbar/ReviewNavbar";
|
|
26
|
+
import { useSave } from "./features/activityData/hooks";
|
|
25
27
|
|
|
26
28
|
type AppProps = PropsWithChildren<{}>;
|
|
27
29
|
|
|
@@ -35,6 +37,20 @@ const App: FC<AppProps> = (props) => {
|
|
|
35
37
|
const hasPedago = hasInstructions || hasGradingOrComments;
|
|
36
38
|
const dispatch = useAppDispatch();
|
|
37
39
|
const showPedago = hasPedago && isPedagoVisible;
|
|
40
|
+
const isDirty = useAppSelector(selectIsDirty);
|
|
41
|
+
const save = useSave();
|
|
42
|
+
|
|
43
|
+
const handleCtrlS = useCallback(
|
|
44
|
+
(e: KeyboardEvent<HTMLDivElement>) => {
|
|
45
|
+
if ((e.ctrlKey || e.metaKey) && e.key === "s") {
|
|
46
|
+
e.preventDefault();
|
|
47
|
+
if (isDirty) {
|
|
48
|
+
save();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
[isDirty, save],
|
|
53
|
+
);
|
|
38
54
|
|
|
39
55
|
return (
|
|
40
56
|
<div
|
|
@@ -43,6 +59,7 @@ const App: FC<AppProps> = (props) => {
|
|
|
43
59
|
isDark ? "dark-theme" : "light-theme",
|
|
44
60
|
isHorizontal ? "layout-horizontal" : "layout-vertical",
|
|
45
61
|
)}
|
|
62
|
+
onKeyDown={handleCtrlS}
|
|
46
63
|
>
|
|
47
64
|
<div>
|
|
48
65
|
<Navbar />
|
package/tsconfig.json
CHANGED
package/vite.config.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineConfig } from "
|
|
1
|
+
import { defineConfig } from "vite"
|
|
2
2
|
import react from "@vitejs/plugin-react"
|
|
3
3
|
|
|
4
4
|
// https://vitejs.dev/config/
|
|
@@ -8,10 +8,4 @@ export default defineConfig({
|
|
|
8
8
|
server: {
|
|
9
9
|
open: true,
|
|
10
10
|
},
|
|
11
|
-
test: {
|
|
12
|
-
globals: true,
|
|
13
|
-
environment: "jsdom",
|
|
14
|
-
setupFiles: "src/setupTests",
|
|
15
|
-
mockReset: true,
|
|
16
|
-
},
|
|
17
11
|
})
|
package/.eslintrc.json
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": [
|
|
3
|
-
"eslint:recommended",
|
|
4
|
-
"react-app",
|
|
5
|
-
"plugin:react/jsx-runtime",
|
|
6
|
-
"prettier",
|
|
7
|
-
"plugin:react-hooks/recommended"
|
|
8
|
-
],
|
|
9
|
-
"parser": "@typescript-eslint/parser",
|
|
10
|
-
"parserOptions": { "project": true, "tsconfigRootDir": "./" },
|
|
11
|
-
"plugins": ["@typescript-eslint"],
|
|
12
|
-
"root": true,
|
|
13
|
-
"ignorePatterns": ["dist"],
|
|
14
|
-
"rules": {
|
|
15
|
-
"@typescript-eslint/consistent-type-imports": [
|
|
16
|
-
2,
|
|
17
|
-
{ "fixStyle": "separate-type-imports" }
|
|
18
|
-
],
|
|
19
|
-
"@typescript-eslint/no-restricted-imports": [
|
|
20
|
-
2,
|
|
21
|
-
{
|
|
22
|
-
"paths": [
|
|
23
|
-
{
|
|
24
|
-
"name": "react-redux",
|
|
25
|
-
"importNames": ["useSelector", "useStore", "useDispatch"],
|
|
26
|
-
"message": "Please use pre-typed versions from `src/app/hooks.ts` instead."
|
|
27
|
-
}
|
|
28
|
-
]
|
|
29
|
-
}
|
|
30
|
-
]
|
|
31
|
-
},
|
|
32
|
-
"overrides": [
|
|
33
|
-
{ "files": ["*.{c,m,}{t,j}s", "*.{t,j}sx"] },
|
|
34
|
-
{ "files": ["*{test,spec}.{t,j}s?(x)"], "env": { "jest": true } }
|
|
35
|
-
]
|
|
36
|
-
}
|
package/src/setupTests.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "@testing-library/jest-dom/vitest"
|
package/src/utils/test-utils.tsx
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import type { RenderOptions } from "@testing-library/react"
|
|
2
|
-
import { render } from "@testing-library/react"
|
|
3
|
-
import userEvent from "@testing-library/user-event"
|
|
4
|
-
import type { PropsWithChildren, ReactElement } from "react"
|
|
5
|
-
import { Provider } from "react-redux"
|
|
6
|
-
import type { AppStore, RootState } from "../app/store"
|
|
7
|
-
import { makeStore } from "../app/store"
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* This type extends the default options for
|
|
11
|
-
* React Testing Library's render function. It allows for
|
|
12
|
-
* additional configuration such as specifying an initial Redux state and
|
|
13
|
-
* a custom store instance.
|
|
14
|
-
*/
|
|
15
|
-
interface ExtendedRenderOptions extends Omit<RenderOptions, "queries"> {
|
|
16
|
-
/**
|
|
17
|
-
* Defines a specific portion or the entire initial state for the Redux store.
|
|
18
|
-
* This is particularly useful for initializing the state in a
|
|
19
|
-
* controlled manner during testing, allowing components to be rendered
|
|
20
|
-
* with predetermined state conditions.
|
|
21
|
-
*/
|
|
22
|
-
preloadedState?: Partial<RootState>
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Allows the use of a specific Redux store instance instead of a
|
|
26
|
-
* default or global store. This flexibility is beneficial when
|
|
27
|
-
* testing components with unique store requirements or when isolating
|
|
28
|
-
* tests from a global store state. The custom store should be configured
|
|
29
|
-
* to match the structure and middleware of the store used by the application.
|
|
30
|
-
*
|
|
31
|
-
* @default makeStore(preloadedState)
|
|
32
|
-
*/
|
|
33
|
-
store?: AppStore
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Renders the given React element with Redux Provider and custom store.
|
|
38
|
-
* This function is useful for testing components that are connected to the Redux store.
|
|
39
|
-
*
|
|
40
|
-
* @param ui - The React component or element to render.
|
|
41
|
-
* @param extendedRenderOptions - Optional configuration options for rendering. This includes `preloadedState` for initial Redux state and `store` for a specific Redux store instance. Any additional properties are passed to React Testing Library's render function.
|
|
42
|
-
* @returns An object containing the Redux store used in the render, User event API for simulating user interactions in tests, and all of React Testing Library's query functions for testing the component.
|
|
43
|
-
*/
|
|
44
|
-
export const renderWithProviders = (
|
|
45
|
-
ui: ReactElement,
|
|
46
|
-
extendedRenderOptions: ExtendedRenderOptions = {},
|
|
47
|
-
) => {
|
|
48
|
-
const {
|
|
49
|
-
preloadedState = {},
|
|
50
|
-
// Automatically create a store instance if no store was passed in
|
|
51
|
-
store = makeStore(preloadedState),
|
|
52
|
-
...renderOptions
|
|
53
|
-
} = extendedRenderOptions
|
|
54
|
-
|
|
55
|
-
const Wrapper = ({ children }: PropsWithChildren) => (
|
|
56
|
-
<Provider store={store}>{children}</Provider>
|
|
57
|
-
)
|
|
58
|
-
|
|
59
|
-
// Return an object with the store and all of RTL's query functions
|
|
60
|
-
return {
|
|
61
|
-
store,
|
|
62
|
-
user: userEvent.setup(),
|
|
63
|
-
...render(ui, { wrapper: Wrapper, ...renderOptions }),
|
|
64
|
-
}
|
|
65
|
-
}
|