@capytale/meta-player 0.0.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.
Files changed (66) hide show
  1. package/.eslintrc.json +35 -0
  2. package/.prettierrc.json +4 -0
  3. package/README.md +27 -0
  4. package/index.html +15 -0
  5. package/package.json +48 -0
  6. package/public/themes/lara-dark-blue/fonts/Inter-italic.var.woff2 +0 -0
  7. package/public/themes/lara-dark-blue/fonts/Inter-roman.var.woff2 +0 -0
  8. package/public/themes/lara-dark-blue/theme.css +7015 -0
  9. package/public/themes/lara-light-blue/fonts/Inter-italic.var.woff2 +0 -0
  10. package/public/themes/lara-light-blue/fonts/Inter-roman.var.woff2 +0 -0
  11. package/public/themes/lara-light-blue/theme.css +7005 -0
  12. package/src/App.tsx +116 -0
  13. package/src/AppRedux.css +39 -0
  14. package/src/MetaPlayer.tsx +51 -0
  15. package/src/app/createAppSlice.ts +6 -0
  16. package/src/app/hooks.ts +12 -0
  17. package/src/app/store.ts +46 -0
  18. package/src/app.module.scss +56 -0
  19. package/src/demo.tsx +81 -0
  20. package/src/features/activityData/IsDirtySetter.tsx +17 -0
  21. package/src/features/activityData/OptionSetter.tsx +35 -0
  22. package/src/features/activityData/activityDataSlice.ts +250 -0
  23. package/src/features/activityData/metaPlayerOptions.ts +17 -0
  24. package/src/features/activityJS/ActivityJSProvider.tsx +110 -0
  25. package/src/features/activityJS/AfterSaveAction.tsx +23 -0
  26. package/src/features/activityJS/BeforeSaveAction.tsx +23 -0
  27. package/src/features/activityJS/Saver.tsx +147 -0
  28. package/src/features/activityJS/hooks.ts +93 -0
  29. package/src/features/activityJS/saverSlice.ts +58 -0
  30. package/src/features/layout/layoutSlice.ts +76 -0
  31. package/src/features/navbar/ActivityInfo.tsx +41 -0
  32. package/src/features/navbar/ActivityMenu.tsx +56 -0
  33. package/src/features/navbar/ActivityQuickActions.tsx +52 -0
  34. package/src/features/navbar/ActivitySidebarActions.tsx +52 -0
  35. package/src/features/navbar/CapytaleMenu.tsx +183 -0
  36. package/src/features/navbar/GradingNav.tsx +120 -0
  37. package/src/features/navbar/ReviewNavbar.tsx +18 -0
  38. package/src/features/navbar/SidebarContent.tsx +125 -0
  39. package/src/features/navbar/index.tsx +33 -0
  40. package/src/features/navbar/navbarSlice.ts +51 -0
  41. package/src/features/navbar/student-utils.ts +11 -0
  42. package/src/features/navbar/style.module.scss +162 -0
  43. package/src/features/pedago/AnswerSheetEditor.tsx +65 -0
  44. package/src/features/pedago/InstructionsEditor.tsx +82 -0
  45. package/src/features/pedago/index.tsx +219 -0
  46. package/src/features/pedago/style.module.scss +104 -0
  47. package/src/features/theming/ThemeSwitcher.tsx +51 -0
  48. package/src/features/theming/themingSlice.ts +93 -0
  49. package/src/hooks/index.ts +8 -0
  50. package/src/index.css +30 -0
  51. package/src/index.tsx +6 -0
  52. package/src/logo.svg +1 -0
  53. package/src/my_json_data.js +4146 -0
  54. package/src/settings.ts +6 -0
  55. package/src/setupTests.ts +1 -0
  56. package/src/utils/ErrorBoundary.tsx +41 -0
  57. package/src/utils/PopupButton.tsx +135 -0
  58. package/src/utils/activity.ts +8 -0
  59. package/src/utils/breakpoints.ts +5 -0
  60. package/src/utils/clipboard.ts +11 -0
  61. package/src/utils/test-utils.tsx +65 -0
  62. package/src/utils/useFullscreen.ts +65 -0
  63. package/src/vite-env.d.ts +1 -0
  64. package/tsconfig.json +27 -0
  65. package/tsconfig.node.json +9 -0
  66. package/vite.config.ts +17 -0
@@ -0,0 +1,6 @@
1
+ const settings = {
2
+ STATEMENT_MAX_SIZE: 2000000, // 2 MB
3
+ TOOLTIP_SHOW_DELAY: 500,
4
+ };
5
+
6
+ export default settings;
@@ -0,0 +1 @@
1
+ import "@testing-library/jest-dom/vitest"
@@ -0,0 +1,41 @@
1
+ import { Component, ErrorInfo, PropsWithChildren, ReactNode } from "react";
2
+
3
+ type ErrorBoundaryProps = PropsWithChildren<{
4
+ fallback: ReactNode;
5
+ }>;
6
+ type ErrorBoundaryState = {
7
+ hasError: boolean;
8
+ };
9
+
10
+ export class ErrorBoundary extends Component<
11
+ ErrorBoundaryProps,
12
+ ErrorBoundaryState
13
+ > {
14
+ constructor(props: ErrorBoundaryProps) {
15
+ super(props);
16
+ this.state = { hasError: false };
17
+ }
18
+
19
+ static getDerivedStateFromError(_error: Error) {
20
+ // Update state so the next render will show the fallback UI.
21
+ return { hasError: true };
22
+ }
23
+
24
+ componentDidCatch(error: Error, info: ErrorInfo) {
25
+ // Example "componentStack":
26
+ // in ComponentThatThrows (created by App)
27
+ // in ErrorBoundary (created by App)
28
+ // in div (created by App)
29
+ // in App
30
+ console.error(error, info.componentStack);
31
+ }
32
+
33
+ render() {
34
+ if (this.state.hasError) {
35
+ // You can render any custom fallback UI
36
+ return this.props.fallback;
37
+ }
38
+
39
+ return this.props.children;
40
+ }
41
+ }
@@ -0,0 +1,135 @@
1
+ import { Button, ButtonProps } from "primereact/button";
2
+ import { MenuItem } from "primereact/menuitem";
3
+ import { TieredMenu } from "primereact/tieredmenu";
4
+ import { useMountEffect } from "primereact/hooks";
5
+ import {
6
+ IconType,
7
+ ObjectUtils,
8
+ UniqueComponentId,
9
+ classNames,
10
+ } from "primereact/utils";
11
+ import {
12
+ CSSProperties,
13
+ KeyboardEventHandler,
14
+ MouseEventHandler,
15
+ ReactNode,
16
+ useRef,
17
+ useState,
18
+ } from "react";
19
+ import { Tooltip } from "primereact/tooltip";
20
+ import { TooltipOptions } from "primereact/tooltip/tooltipoptions";
21
+
22
+ type PopupButtonProps = {
23
+ id?: string;
24
+ icon?: IconType<ButtonProps>;
25
+ buttonClassName?: string;
26
+ disabled?: boolean;
27
+ buttonProps?: ButtonProps;
28
+ size?: "small" | "large";
29
+ severity?: "secondary" | "success" | "info" | "warning" | "danger" | "help";
30
+ outlined?: boolean;
31
+ text?: boolean;
32
+ raised?: boolean;
33
+ unstyled?: boolean;
34
+ onButtonKeydown?: KeyboardEventHandler<HTMLButtonElement>;
35
+ model?: MenuItem[];
36
+ appendTo?: HTMLElement | "self" | (() => HTMLElement) | null;
37
+ tooltip?: ReactNode;
38
+ menuStyle?: CSSProperties;
39
+ autoZIndex?: boolean;
40
+ baseZIndex?: number;
41
+ menuClassName?: string;
42
+ tooltipOptions?: TooltipOptions;
43
+ };
44
+
45
+ const PopupButton: React.FC<PopupButtonProps> = ({
46
+ id,
47
+ icon,
48
+ buttonClassName,
49
+ disabled,
50
+ buttonProps,
51
+ size,
52
+ severity,
53
+ outlined,
54
+ text,
55
+ raised,
56
+ unstyled,
57
+ onButtonKeydown,
58
+ model,
59
+ appendTo,
60
+ tooltip,
61
+ menuStyle,
62
+ autoZIndex,
63
+ baseZIndex,
64
+ menuClassName,
65
+ tooltipOptions,
66
+ ...props
67
+ }: PopupButtonProps) => {
68
+ const [idState, setIdState] = useState(id);
69
+ useMountEffect(() => {
70
+ if (!idState) {
71
+ setIdState(UniqueComponentId());
72
+ }
73
+ });
74
+
75
+ const [overlayVisibleState, _setOverlayVisibleState] =
76
+ useState<boolean>(false);
77
+ const menuRef = useRef(null);
78
+ const elementRef = useRef(null);
79
+
80
+ const hasTooltip = ObjectUtils.isNotEmpty(tooltip);
81
+
82
+ const onDropdownButtonClick: MouseEventHandler<HTMLButtonElement> = (
83
+ event,
84
+ ) => {
85
+ menuRef && (menuRef.current as any)?.toggle(event);
86
+ };
87
+
88
+ const menuId = idState + "_overlay";
89
+
90
+ return (
91
+ <>
92
+ <div {...props}>
93
+ <Button
94
+ type="button"
95
+ className={classNames(buttonClassName)}
96
+ icon={icon}
97
+ onClick={onDropdownButtonClick}
98
+ disabled={disabled}
99
+ aria-expanded={overlayVisibleState}
100
+ aria-haspopup="true"
101
+ aria-controls={menuId}
102
+ {...buttonProps}
103
+ size={size}
104
+ severity={severity}
105
+ outlined={outlined}
106
+ text={text}
107
+ raised={raised}
108
+ onKeyDown={onButtonKeydown}
109
+ unstyled={unstyled}
110
+ />
111
+ <TieredMenu
112
+ ref={menuRef}
113
+ popup={true}
114
+ unstyled={unstyled}
115
+ model={model}
116
+ appendTo={appendTo}
117
+ id={menuId}
118
+ style={menuStyle}
119
+ autoZIndex={autoZIndex}
120
+ baseZIndex={baseZIndex}
121
+ className={menuClassName}
122
+ />
123
+ </div>
124
+ {hasTooltip && (
125
+ <Tooltip
126
+ target={elementRef}
127
+ content={tooltip}
128
+ {...tooltipOptions}
129
+ />
130
+ )}
131
+ </>
132
+ );
133
+ };
134
+
135
+ export default PopupButton;
@@ -0,0 +1,8 @@
1
+ export function getIdFromUrl() {
2
+ const params = new URLSearchParams(window.location.search);
3
+ const id = params.get("id");
4
+ if (id !== null) {
5
+ return parseInt(id, 10);
6
+ }
7
+ return null;
8
+ }
@@ -0,0 +1,5 @@
1
+ export const SM = 576;
2
+ export const MD = 768;
3
+ export const ML = 850;
4
+ export const LG = 992;
5
+ export const XL = 1200;
@@ -0,0 +1,11 @@
1
+ export async function copyToClipboard(
2
+ text: string,
3
+ callback?: (success: boolean, error?: any) => any,
4
+ ) {
5
+ try {
6
+ await navigator.clipboard.writeText(text);
7
+ callback?.(true);
8
+ } catch (err) {
9
+ callback?.(false, err);
10
+ }
11
+ }
@@ -0,0 +1,65 @@
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
+ }
@@ -0,0 +1,65 @@
1
+ // From https://github.com/streamich/react-use/blob/master/src/useFullscreen.ts
2
+ // Modified to use <body> instead of react ref
3
+
4
+ import { useState, useEffect, useLayoutEffect } from "react";
5
+ import screenfull from "screenfull";
6
+
7
+ const noop = () => {};
8
+ const isBrowser = typeof window !== "undefined";
9
+
10
+ const useIsomorphicLayoutEffect = isBrowser ? useLayoutEffect : useEffect;
11
+
12
+ export interface FullScreenOptions {
13
+ onClose?: (error?: Error) => void;
14
+ }
15
+
16
+ const useFullscreen = (
17
+ enabled: boolean,
18
+ onClose: (error?: Error) => void = noop,
19
+ ): boolean => {
20
+ const [isFullscreen, setIsFullscreen] = useState(enabled);
21
+
22
+ useIsomorphicLayoutEffect(() => {
23
+ if (!enabled) {
24
+ return;
25
+ }
26
+
27
+ const onChange = () => {
28
+ if (screenfull.isEnabled) {
29
+ const isScreenfullFullscreen = screenfull.isFullscreen;
30
+ setIsFullscreen(isScreenfullFullscreen);
31
+ if (!isScreenfullFullscreen) {
32
+ onClose();
33
+ }
34
+ }
35
+ };
36
+
37
+ if (screenfull.isEnabled) {
38
+ try {
39
+ screenfull.request(window.document.body);
40
+ setIsFullscreen(true);
41
+ } catch (error) {
42
+ onClose(error as Error | undefined);
43
+ setIsFullscreen(false);
44
+ }
45
+ screenfull.on("change", onChange);
46
+ } else {
47
+ onClose();
48
+ setIsFullscreen(false);
49
+ }
50
+
51
+ return () => {
52
+ setIsFullscreen(false);
53
+ if (screenfull.isEnabled) {
54
+ try {
55
+ screenfull.off("change", onChange);
56
+ screenfull.exit();
57
+ } catch {}
58
+ }
59
+ };
60
+ }, [enabled]);
61
+
62
+ return isFullscreen;
63
+ };
64
+
65
+ export default useFullscreen;
@@ -0,0 +1 @@
1
+ /// <reference types="vite/client" />
package/tsconfig.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "useDefineForClassFields": true,
5
+ "lib": ["DOM", "DOM.Iterable", "ESNext"],
6
+ "allowJs": false,
7
+ "skipLibCheck": true,
8
+ "esModuleInterop": false,
9
+ "allowSyntheticDefaultImports": true,
10
+ "module": "ESNext",
11
+ "moduleResolution": "bundler",
12
+ "resolveJsonModule": true,
13
+ "isolatedModules": true,
14
+ "noEmit": true,
15
+ "jsx": "react-jsx",
16
+ "types": ["vitest/globals"],
17
+
18
+ /* Linting */
19
+ "strict": true,
20
+ "noUnusedLocals": true,
21
+ "noUnusedParameters": true,
22
+ "noFallthroughCasesInSwitch": true,
23
+ },
24
+ "references": [{ "path": "./tsconfig.node.json" }],
25
+
26
+ "include": ["src/**/*"],
27
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "compilerOptions": {
3
+ "composite": true,
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "allowSyntheticDefaultImports": true
7
+ },
8
+ "include": ["vite.config.ts"]
9
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,17 @@
1
+ import { defineConfig } from "vitest/config"
2
+ import react from "@vitejs/plugin-react"
3
+
4
+ // https://vitejs.dev/config/
5
+ export default defineConfig({
6
+ base: "./",
7
+ plugins: [react()],
8
+ server: {
9
+ open: true,
10
+ },
11
+ test: {
12
+ globals: true,
13
+ environment: "jsdom",
14
+ setupFiles: "src/setupTests",
15
+ mockReset: true,
16
+ },
17
+ })