@capytale/meta-player 0.0.3 → 0.1.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 +1 -1
- package/src/App.tsx +12 -15
- package/src/MetaPlayer.tsx +1 -12
- package/src/app/store.ts +2 -0
- package/src/app.module.scss +1 -0
- package/src/demo.tsx +10 -8
- package/src/external/prime.ts +5 -0
- package/src/features/activityData/IsDirtySetter.tsx +0 -6
- package/src/features/activityData/MetaPlayerOptionsSetter.tsx +41 -0
- package/src/features/activityData/hooks.ts +9 -0
- package/src/features/activityJS/Saver.tsx +0 -1
- package/src/features/activitySettings/ActivitySettingsSetter.tsx +26 -0
- package/src/features/activitySettings/activitySettingsSlice.ts +43 -0
- package/src/features/activitySettings/hooks.ts +6 -0
- package/src/features/activitySettings/index.tsx +32 -0
- package/src/features/activitySettings/style.module.scss +4 -0
- package/src/features/activitySettings/types.ts +88 -0
- package/src/features/activitySettings/ui.tsx +393 -0
- package/src/features/navbar/ActivityMenu.tsx +30 -2
- package/src/features/navbar/CapytaleMenu.tsx +142 -124
- package/src/features/navbar/GradingNav.tsx +0 -1
- package/src/features/navbar/SidebarContent.tsx +38 -11
- package/src/features/navbar/style.module.scss +5 -14
- package/src/features/pedago/index.tsx +0 -2
- package/src/index.css +49 -0
- package/src/utils/equality.ts +32 -0
- package/src/features/activityData/OptionSetter.tsx +0 -35
package/package.json
CHANGED
package/src/App.tsx
CHANGED
|
@@ -94,21 +94,18 @@ const App: FC<AppProps> = (props) => {
|
|
|
94
94
|
mouseTrack={!isHorizontal}
|
|
95
95
|
/>
|
|
96
96
|
</div>
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
>
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
<div id="meta-player-content">{props.children}</div>
|
|
110
|
-
</SplitterPanel>
|
|
111
|
-
</Splitter>
|
|
97
|
+
<Splitter
|
|
98
|
+
className={styles.appPedagoSplitter}
|
|
99
|
+
layout={isHorizontal ? "vertical" : "horizontal"}
|
|
100
|
+
>
|
|
101
|
+
<SplitterPanel minSize={15} size={30} className={styles.pedagoPanel}>
|
|
102
|
+
<Pedago key="pedago" />
|
|
103
|
+
</SplitterPanel>
|
|
104
|
+
<SplitterPanel minSize={40} size={70}>
|
|
105
|
+
<div id="meta-player-content-cover"></div>
|
|
106
|
+
<div id="meta-player-content">{props.children}</div>
|
|
107
|
+
</SplitterPanel>
|
|
108
|
+
</Splitter>
|
|
112
109
|
</div>
|
|
113
110
|
</div>
|
|
114
111
|
);
|
package/src/MetaPlayer.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { PropsWithChildren
|
|
1
|
+
import React, { PropsWithChildren } from "react";
|
|
2
2
|
|
|
3
3
|
import { Provider } from "react-redux";
|
|
4
4
|
|
|
@@ -12,30 +12,19 @@ import ThemeSwitcher from "./features/theming/ThemeSwitcher";
|
|
|
12
12
|
import { ActivityJSProvider } from "./features/activityJS/ActivityJSProvider";
|
|
13
13
|
import { LoadOptions } from "./features/activityJS/hooks";
|
|
14
14
|
import { ErrorBoundary } from "./utils/ErrorBoundary";
|
|
15
|
-
import {
|
|
16
|
-
MetaPlayerOptions,
|
|
17
|
-
defaultMetaPlayerOptions,
|
|
18
|
-
} from "./features/activityData/metaPlayerOptions";
|
|
19
|
-
import OptionSetter from "./features/activityData/OptionSetter";
|
|
20
15
|
import Saver from "./features/activityJS/Saver";
|
|
21
16
|
|
|
22
17
|
type MetaPlayerProps = PropsWithChildren<{
|
|
23
18
|
activityJSOptions?: LoadOptions;
|
|
24
|
-
options?: Partial<MetaPlayerOptions>;
|
|
25
19
|
}>;
|
|
26
20
|
|
|
27
21
|
const MetaPlayer: React.FC<MetaPlayerProps> = (props) => {
|
|
28
22
|
const primeSettings: Partial<APIOptions> = {
|
|
29
23
|
ripple: true,
|
|
30
24
|
};
|
|
31
|
-
const options = useMemo(
|
|
32
|
-
() => ({ ...defaultMetaPlayerOptions, ...props.options }),
|
|
33
|
-
[props.options],
|
|
34
|
-
);
|
|
35
25
|
return (
|
|
36
26
|
<PrimeReactProvider value={primeSettings}>
|
|
37
27
|
<Provider store={store}>
|
|
38
|
-
<OptionSetter options={options} />
|
|
39
28
|
<ThemeSwitcher />
|
|
40
29
|
<ErrorBoundary fallback={<div>Une erreur est survenue</div>}>
|
|
41
30
|
<ActivityJSProvider options={props.activityJSOptions}>
|
package/src/app/store.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { layoutSlice } from "../features/layout/layoutSlice";
|
|
|
6
6
|
import { activityDataSlice } from "../features/activityData/activityDataSlice";
|
|
7
7
|
import { navbarSlice } from "../features/navbar/navbarSlice";
|
|
8
8
|
import { saverSlice } from "../features/activityJS/saverSlice";
|
|
9
|
+
import { activitySettingsSlice } from "../features/activitySettings/activitySettingsSlice";
|
|
9
10
|
|
|
10
11
|
// `combineSlices` automatically combines the reducers using
|
|
11
12
|
// their `reducerPath`s, therefore we no longer need to call `combineReducers`.
|
|
@@ -15,6 +16,7 @@ const rootReducer = combineSlices(
|
|
|
15
16
|
layoutSlice,
|
|
16
17
|
navbarSlice,
|
|
17
18
|
saverSlice,
|
|
19
|
+
activitySettingsSlice,
|
|
18
20
|
);
|
|
19
21
|
// Infer the `RootState` type from the root reducer
|
|
20
22
|
export type RootState = ReturnType<typeof rootReducer>;
|
package/src/app.module.scss
CHANGED
package/src/demo.tsx
CHANGED
|
@@ -6,6 +6,7 @@ import { ActivityQuickActionsSetter } from "./features/navbar/ActivityQuickActio
|
|
|
6
6
|
import { ActivitySidebarActionsSetter } from "./features/navbar/ActivitySidebarActions";
|
|
7
7
|
// import { useActivityJS } from "./features/activityJS/ActivityJSProvider";
|
|
8
8
|
import BeforeSaveAction from "./features/activityJS/BeforeSaveAction";
|
|
9
|
+
import MetaPlayerOptionsSetter from "./features/activityData/MetaPlayerOptionsSetter";
|
|
9
10
|
|
|
10
11
|
const DemoActivity: FC = () => {
|
|
11
12
|
// const activityJs = useActivityJS();
|
|
@@ -62,14 +63,15 @@ if (container) {
|
|
|
62
63
|
|
|
63
64
|
root.render(
|
|
64
65
|
<React.StrictMode>
|
|
65
|
-
<MetaPlayer
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
66
|
+
<MetaPlayer>
|
|
67
|
+
<MetaPlayerOptionsSetter
|
|
68
|
+
options={{
|
|
69
|
+
hasInstructions: true,
|
|
70
|
+
pedagoLayout: "default-horizontal",
|
|
71
|
+
supportsLightTheme: true,
|
|
72
|
+
supportsDarkTheme: true,
|
|
73
|
+
}}
|
|
74
|
+
/>
|
|
73
75
|
<DemoActivity />
|
|
74
76
|
</MetaPlayer>
|
|
75
77
|
</React.StrictMode>,
|
|
@@ -14,10 +14,4 @@ const IsDirtySetter: FC<IsDirtySetterProps> = (props) => {
|
|
|
14
14
|
return null;
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
const notifyIsDirty = (isDirty: boolean = true) => {
|
|
18
|
-
const dispatch = useAppDispatch();
|
|
19
|
-
dispatch(setIsPlayerDirty(isDirty));
|
|
20
|
-
};
|
|
21
|
-
|
|
22
17
|
export default IsDirtySetter;
|
|
23
|
-
export { notifyIsDirty };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { FC, useEffect } from "react";
|
|
2
|
+
import { useAppDispatch } from "../../app/hooks";
|
|
3
|
+
import { setPlayerSettings } from "./activityDataSlice";
|
|
4
|
+
import { setLayout } from "../layout/layoutSlice";
|
|
5
|
+
import { setAutoSwitch, switchToTheme } from "../theming/themingSlice";
|
|
6
|
+
import {
|
|
7
|
+
defaultMetaPlayerOptions,
|
|
8
|
+
MetaPlayerOptions,
|
|
9
|
+
} from "./metaPlayerOptions";
|
|
10
|
+
|
|
11
|
+
type MetaPlayerOptionsSetterProps = {
|
|
12
|
+
options: Partial<MetaPlayerOptions>;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const MetaPlayerOptionsSetter: FC<MetaPlayerOptionsSetterProps> = (props) => {
|
|
16
|
+
const dispatch = useAppDispatch();
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
const options = { ...defaultMetaPlayerOptions, ...props.options };
|
|
19
|
+
if (!options.supportsLightTheme && !options.supportsDarkTheme) {
|
|
20
|
+
throw new Error("At least one theme must be supported");
|
|
21
|
+
}
|
|
22
|
+
dispatch(setPlayerSettings(options));
|
|
23
|
+
dispatch(
|
|
24
|
+
setLayout(
|
|
25
|
+
options.pedagoLayout === "horizontal" ||
|
|
26
|
+
options.pedagoLayout === "default-horizontal"
|
|
27
|
+
? "horizontal"
|
|
28
|
+
: "vertical",
|
|
29
|
+
),
|
|
30
|
+
);
|
|
31
|
+
if (options.supportsDarkTheme && options.supportsLightTheme) {
|
|
32
|
+
dispatch(setAutoSwitch(true));
|
|
33
|
+
} else {
|
|
34
|
+
dispatch(setAutoSwitch(false));
|
|
35
|
+
dispatch(switchToTheme(options.supportsLightTheme ? "light" : "dark"));
|
|
36
|
+
}
|
|
37
|
+
}, [dispatch, props.options]);
|
|
38
|
+
return null;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export default MetaPlayerOptionsSetter;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { useAppDispatch } from "../../app/hooks";
|
|
2
|
+
import { setIsPlayerDirty } from "./activityDataSlice";
|
|
3
|
+
|
|
4
|
+
const useNotifyIsDirty = (isDirty: boolean = true) => {
|
|
5
|
+
const dispatch = useAppDispatch();
|
|
6
|
+
return () => dispatch(setIsPlayerDirty(isDirty));
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export { useNotifyIsDirty };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { FC, useEffect, useRef } from "react";
|
|
2
|
+
import { useAppDispatch } from "../../app/hooks";
|
|
3
|
+
import { ActivitySettings } from "./types";
|
|
4
|
+
import { setSettings } from "./activitySettingsSlice";
|
|
5
|
+
import { deepEqual } from "../../utils/equality";
|
|
6
|
+
|
|
7
|
+
type ActivitySettingsSetterProps = {
|
|
8
|
+
settings: ActivitySettings;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const ActivitySettingsSetter: FC<ActivitySettingsSetterProps> = ({
|
|
12
|
+
settings,
|
|
13
|
+
}) => {
|
|
14
|
+
const oldSettings = useRef<ActivitySettings | null>(null);
|
|
15
|
+
const dispatch = useAppDispatch();
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
if (deepEqual(oldSettings.current, settings)) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
oldSettings.current = settings;
|
|
21
|
+
dispatch(setSettings(settings));
|
|
22
|
+
}, [dispatch, settings]);
|
|
23
|
+
return null;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export default ActivitySettingsSetter;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { PayloadAction } from "@reduxjs/toolkit";
|
|
2
|
+
import { createAppSlice } from "../../app/createAppSlice";
|
|
3
|
+
import { ActivitySettings } from "./types";
|
|
4
|
+
|
|
5
|
+
// If you are not using async thunks you can use the standalone `createSlice`.
|
|
6
|
+
export const activitySettingsSlice = createAppSlice({
|
|
7
|
+
name: "activitySettings",
|
|
8
|
+
// `createSlice` will infer the state type from the `initialState` argument
|
|
9
|
+
initialState: {
|
|
10
|
+
settings: undefined as ActivitySettings | undefined,
|
|
11
|
+
},
|
|
12
|
+
// The `reducers` field lets us define reducers and generate associated actions
|
|
13
|
+
reducers: (create) => ({
|
|
14
|
+
setSettings: create.reducer(
|
|
15
|
+
(state, action: PayloadAction<ActivitySettings | undefined>) => {
|
|
16
|
+
state.settings = action.payload;
|
|
17
|
+
},
|
|
18
|
+
),
|
|
19
|
+
updateSettings: create.reducer(
|
|
20
|
+
(
|
|
21
|
+
state,
|
|
22
|
+
action: PayloadAction<
|
|
23
|
+
(
|
|
24
|
+
oldSettings: ActivitySettings | undefined,
|
|
25
|
+
) => ActivitySettings | undefined
|
|
26
|
+
>,
|
|
27
|
+
) => {
|
|
28
|
+
state.settings = action.payload(state.settings);
|
|
29
|
+
},
|
|
30
|
+
),
|
|
31
|
+
}),
|
|
32
|
+
// You can define your selectors here. These selectors receive the slice
|
|
33
|
+
// state as their first argument.
|
|
34
|
+
selectors: {
|
|
35
|
+
selectSettings: (data) => data.settings,
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// Action creators are generated for each case reducer function.
|
|
40
|
+
export const { setSettings, updateSettings } = activitySettingsSlice.actions;
|
|
41
|
+
|
|
42
|
+
// Selectors returned by `slice.selectors` take the root state as their first argument.
|
|
43
|
+
export const { selectSettings } = activitySettingsSlice.selectors;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Fieldset } from "primereact/fieldset";
|
|
2
|
+
import { useActivitySettings } from "./hooks";
|
|
3
|
+
import {
|
|
4
|
+
ActivitySettingsFormDisplay,
|
|
5
|
+
ActivitySettingsOptionsDisplay,
|
|
6
|
+
} from "./ui";
|
|
7
|
+
|
|
8
|
+
type ActivitySettingsDisplayProps = {};
|
|
9
|
+
|
|
10
|
+
export function ActivitySettingsDisplay({}: ActivitySettingsDisplayProps) {
|
|
11
|
+
const settings = useActivitySettings();
|
|
12
|
+
if (!settings) return null;
|
|
13
|
+
return (
|
|
14
|
+
<div>
|
|
15
|
+
{Object.keys(settings).map((id) => {
|
|
16
|
+
const section = settings[id];
|
|
17
|
+
return (
|
|
18
|
+
<Fieldset key={id} legend={section.title} className="sidebarFieldset">
|
|
19
|
+
{section.type === "form" ? (
|
|
20
|
+
<ActivitySettingsFormDisplay form={section} sectionId={id} />
|
|
21
|
+
) : (
|
|
22
|
+
<ActivitySettingsOptionsDisplay
|
|
23
|
+
options={section}
|
|
24
|
+
sectionId={id}
|
|
25
|
+
/>
|
|
26
|
+
)}
|
|
27
|
+
</Fieldset>
|
|
28
|
+
);
|
|
29
|
+
})}
|
|
30
|
+
</div>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
export type ActivitySettingsSelect = {
|
|
2
|
+
type: "select";
|
|
3
|
+
options: {
|
|
4
|
+
label: string;
|
|
5
|
+
name: string;
|
|
6
|
+
}[];
|
|
7
|
+
selectedOptionName: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export type ActivitySettingsRange = {
|
|
11
|
+
type: "range";
|
|
12
|
+
min: number;
|
|
13
|
+
max: number;
|
|
14
|
+
step?: number;
|
|
15
|
+
value: number;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type ActivitySettingsTextArea = {
|
|
19
|
+
type: "textarea";
|
|
20
|
+
value: string;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type ActivitySettingsOption = {
|
|
24
|
+
type: "checkbox" | "switch";
|
|
25
|
+
value: boolean;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type ActivitySettingsInput = {
|
|
29
|
+
type: "input";
|
|
30
|
+
inputType:
|
|
31
|
+
| "color"
|
|
32
|
+
| "date"
|
|
33
|
+
| "datetime-local"
|
|
34
|
+
| "email"
|
|
35
|
+
| "month"
|
|
36
|
+
| "number"
|
|
37
|
+
| "password"
|
|
38
|
+
| "search"
|
|
39
|
+
| "tel"
|
|
40
|
+
| "text"
|
|
41
|
+
| "time"
|
|
42
|
+
| "url"
|
|
43
|
+
| "week";
|
|
44
|
+
value: string | number;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export type ActivitySettingsFormSection = {
|
|
48
|
+
type: "form";
|
|
49
|
+
fields: {
|
|
50
|
+
[name: string]: (
|
|
51
|
+
| ActivitySettingsRange
|
|
52
|
+
| ActivitySettingsInput
|
|
53
|
+
| ActivitySettingsTextArea
|
|
54
|
+
| ActivitySettingsOption
|
|
55
|
+
| ActivitySettingsSelect
|
|
56
|
+
) & {
|
|
57
|
+
label: string;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export type ActivitySettingsMultipleOptionsSection = {
|
|
63
|
+
type: "checkboxes" | "switches";
|
|
64
|
+
options: {
|
|
65
|
+
label: string;
|
|
66
|
+
name: string;
|
|
67
|
+
}[];
|
|
68
|
+
selectedOptionNames: string[];
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export type ActivitySettingsRadioOptionsSection = {
|
|
72
|
+
type: "radio";
|
|
73
|
+
options: {
|
|
74
|
+
label: string;
|
|
75
|
+
name: string;
|
|
76
|
+
}[];
|
|
77
|
+
selectedOptionName: string | null;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export type ActivitySettingsSection = (
|
|
81
|
+
| ActivitySettingsMultipleOptionsSection
|
|
82
|
+
| ActivitySettingsRadioOptionsSection
|
|
83
|
+
| ActivitySettingsFormSection
|
|
84
|
+
) & {
|
|
85
|
+
title: string;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export type ActivitySettings = { [id: string]: ActivitySettingsSection };
|