@olenbetong/synergi-course 2.0.0 → 2.1.0
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/es/chrome/CategoryHeader.css +28 -0
- package/es/completion/CourseCompletion.css +53 -0
- package/es/completion/CourseCompletion.d.ts +32 -0
- package/es/completion/CourseCompletion.js +60 -0
- package/es/document/cues.d.ts +51 -6
- package/es/document/cues.js +115 -14
- package/es/document/effects.d.ts +30 -0
- package/es/document/effects.js +74 -0
- package/es/document/schema.d.ts +924 -136
- package/es/document/schema.js +139 -5
- package/es/document/validate.d.ts +2 -1
- package/es/document/validate.js +73 -2
- package/es/index.d.ts +6 -2
- package/es/index.js +6 -2
- package/es/media/Media.css +16 -0
- package/es/media/icons.d.ts +1 -0
- package/es/media/icons.js +3 -0
- package/es/player/CoursePlayer.css +58 -0
- package/es/player/CoursePlayer.js +27 -13
- package/es/player/useFullScreen.d.ts +17 -0
- package/es/player/useFullScreen.js +83 -0
- package/es/player/useMediaQuery.d.ts +7 -0
- package/es/player/useMediaQuery.js +16 -0
- package/es/steps/Blocks.d.ts +20 -1
- package/es/steps/Blocks.js +103 -22
- package/es/steps/Markdown.d.ts +7 -1
- package/es/steps/Markdown.js +31 -4
- package/es/steps/RevealMotion.d.ts +29 -0
- package/es/steps/RevealMotion.js +55 -0
- package/es/steps/SlideStepView.d.ts +5 -3
- package/es/steps/SlideStepView.js +38 -15
- package/es/steps/StepBodyProps.d.ts +7 -1
- package/es/steps/StepView.css +328 -12
- package/es/steps/StepView.d.ts +8 -2
- package/es/steps/StepView.js +2 -2
- package/es/steps/motion.d.ts +59 -0
- package/es/steps/motion.js +136 -0
- package/es/transitions/Transitions.css +114 -0
- package/es/transitions/plan.d.ts +66 -0
- package/es/transitions/plan.js +185 -0
- package/es/transitions/playStepTransition.d.ts +23 -0
- package/es/transitions/playStepTransition.js +131 -0
- package/es/types.d.ts +3 -1
- package/package.json +4 -4
- package/src/chrome/CategoryHeader.css +28 -0
- package/src/completion/CourseCompletion.css +53 -0
- package/src/completion/CourseCompletion.test.tsx +45 -0
- package/src/completion/CourseCompletion.tsx +98 -0
- package/src/document/cues.ts +142 -13
- package/src/document/document.test.ts +1 -1
- package/src/document/effects.ts +105 -0
- package/src/document/reveal.test.ts +263 -0
- package/src/document/schema.ts +161 -5
- package/src/document/validate.ts +77 -3
- package/src/index.ts +35 -0
- package/src/media/Media.css +16 -0
- package/src/media/icons.tsx +8 -0
- package/src/player/CoursePlayer.css +58 -0
- package/src/player/CoursePlayer.test.tsx +70 -6
- package/src/player/CoursePlayer.tsx +68 -17
- package/src/player/fullScreen.test.tsx +70 -0
- package/src/player/useFullScreen.ts +91 -0
- package/src/player/useMediaQuery.ts +21 -0
- package/src/steps/Blocks.test.ts +34 -0
- package/src/steps/Blocks.tsx +166 -26
- package/src/steps/Markdown.test.tsx +43 -0
- package/src/steps/Markdown.tsx +42 -4
- package/src/steps/Presence.test.tsx +82 -0
- package/src/steps/RevealMotion.ts +66 -0
- package/src/steps/SlideStepView.tsx +67 -17
- package/src/steps/StepBodyProps.ts +7 -1
- package/src/steps/StepView.css +328 -12
- package/src/steps/StepView.test.tsx +41 -0
- package/src/steps/StepView.tsx +9 -1
- package/src/steps/motion.test.ts +98 -0
- package/src/steps/motion.ts +178 -0
- package/src/steps/visibility.test.ts +24 -0
- package/src/transitions/Transitions.css +114 -0
- package/src/transitions/plan.ts +258 -0
- package/src/transitions/playStepTransition.ts +162 -0
- package/src/transitions/transitions.test.ts +274 -0
- package/src/types.ts +3 -1
- package/es/Transitions.css +0 -55
- package/es/Transitions.d.ts +0 -10
- package/es/Transitions.js +0 -24
- package/src/Transitions.css +0 -55
- package/src/Transitions.ts +0 -35
package/src/index.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
export { CoursePlayer, type CoursePlayerProps } from "./player/CoursePlayer";
|
|
2
2
|
export { StepView, type StepViewProps } from "./steps/StepView";
|
|
3
|
+
export {
|
|
4
|
+
CourseCompletion,
|
|
5
|
+
type CourseCompletionProps,
|
|
6
|
+
hasCompletionText,
|
|
7
|
+
sanitizeCompletionHtml,
|
|
8
|
+
} from "./completion/CourseCompletion";
|
|
3
9
|
export { type CueClock, useCueClock } from "./media/useCueClock";
|
|
4
10
|
export {
|
|
5
11
|
elementHandle,
|
|
@@ -29,13 +35,28 @@ export {
|
|
|
29
35
|
getActiveCue,
|
|
30
36
|
getCueEnd,
|
|
31
37
|
getCues,
|
|
38
|
+
getRevealLeaders,
|
|
39
|
+
getRevealNavigation,
|
|
40
|
+
getRevealState,
|
|
32
41
|
getRevealSteps,
|
|
33
42
|
getStartedCueIds,
|
|
34
43
|
getTimedParts,
|
|
35
44
|
hasCueText,
|
|
45
|
+
hasTrigger,
|
|
46
|
+
isDue,
|
|
47
|
+
isNarratedSlide,
|
|
36
48
|
isVisible,
|
|
49
|
+
type RevealNavigation,
|
|
37
50
|
type RevealState,
|
|
38
51
|
} from "./document/cues";
|
|
52
|
+
export {
|
|
53
|
+
DEFAULT_EFFECT_DURATION,
|
|
54
|
+
effectTargets,
|
|
55
|
+
getActiveEffects,
|
|
56
|
+
getEffectBlocks,
|
|
57
|
+
getPartEffects,
|
|
58
|
+
type PartEffect,
|
|
59
|
+
} from "./document/effects";
|
|
39
60
|
export {
|
|
40
61
|
type Block,
|
|
41
62
|
blockSchema,
|
|
@@ -43,6 +64,8 @@ export {
|
|
|
43
64
|
type ColumnsBlock,
|
|
44
65
|
type ContentBlock,
|
|
45
66
|
type Cue,
|
|
67
|
+
type EffectBlock,
|
|
68
|
+
effectBlockSchema,
|
|
46
69
|
type ImageSize,
|
|
47
70
|
type Media,
|
|
48
71
|
type Narration,
|
|
@@ -51,9 +74,21 @@ export {
|
|
|
51
74
|
type SlideStep,
|
|
52
75
|
STEP_SCHEMA_VERSION,
|
|
53
76
|
type Step,
|
|
77
|
+
type StepTransition,
|
|
54
78
|
type StepType,
|
|
55
79
|
stepSchema,
|
|
80
|
+
transitionSchema,
|
|
56
81
|
type Timed,
|
|
57
82
|
type VideoStep,
|
|
58
83
|
} from "./document/schema";
|
|
59
84
|
export { getStepJsonSchema, type StepIssue, type StepValidation, validateStep } from "./document/validate";
|
|
85
|
+
export {
|
|
86
|
+
DEFAULT_TRANSITION_DURATION,
|
|
87
|
+
DEFAULT_TRANSITIONS,
|
|
88
|
+
getStepTransitions,
|
|
89
|
+
planStepTransition,
|
|
90
|
+
type TransitionDirection,
|
|
91
|
+
type TransitionPlan,
|
|
92
|
+
type TransitionStep,
|
|
93
|
+
} from "./transitions/plan";
|
|
94
|
+
export { playStepTransition, type StepTransitionOptions } from "./transitions/playStepTransition";
|
package/src/media/Media.css
CHANGED
|
@@ -94,3 +94,19 @@
|
|
|
94
94
|
height: 100%;
|
|
95
95
|
color: white;
|
|
96
96
|
}
|
|
97
|
+
|
|
98
|
+
/* A phone on its side: slimmer controls and smaller subtitles, so they cover less of the slide */
|
|
99
|
+
@media (orientation: landscape) and (max-height: 500px) {
|
|
100
|
+
.ob-course-media-controls {
|
|
101
|
+
padding-block: 0.125rem;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
.ob-course-subtitles {
|
|
105
|
+
inset-block-end: var(--ds-size-2, 0.5rem);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.ob-course-subtitles__text {
|
|
109
|
+
font-size: max(0.75rem, 3.6vh);
|
|
110
|
+
font-size: max(0.75rem, 3.6dvh);
|
|
111
|
+
}
|
|
112
|
+
}
|
package/src/media/icons.tsx
CHANGED
|
@@ -74,3 +74,11 @@ export function CloseIcon(props: IconProps) {
|
|
|
74
74
|
</Icon>
|
|
75
75
|
);
|
|
76
76
|
}
|
|
77
|
+
|
|
78
|
+
export function ExitFullscreenIcon(props: IconProps) {
|
|
79
|
+
return (
|
|
80
|
+
<Icon {...props}>
|
|
81
|
+
<path d="M8 4h2v6H4V8h4V4Zm6 0h2v4h4v2h-6V4ZM4 14h6v6H8v-4H4v-2Zm10 0h6v2h-4v4h-2v-6Z" />
|
|
82
|
+
</Icon>
|
|
83
|
+
);
|
|
84
|
+
}
|
|
@@ -155,3 +155,61 @@
|
|
|
155
155
|
height: 1.5em;
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
|
+
|
|
159
|
+
/*
|
|
160
|
+
* Full screen: the step fills the screen, with the buttons under it and a small button in the corner
|
|
161
|
+
* to leave. Native full screen puts the player on the whole screen itself; the immersive mode (Safari
|
|
162
|
+
* on iPhone, which only puts videos on the screen) lays it over the page.
|
|
163
|
+
*/
|
|
164
|
+
.ob-course-player {
|
|
165
|
+
position: relative;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
.ob-course-player.is-full-screen {
|
|
169
|
+
height: 100vh;
|
|
170
|
+
height: 100dvh;
|
|
171
|
+
padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
|
|
172
|
+
|
|
173
|
+
> .ob-course-player__header,
|
|
174
|
+
.ob-course-category-header {
|
|
175
|
+
display: none;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
.ob-course-player.is-immersive {
|
|
180
|
+
position: fixed;
|
|
181
|
+
inset: 0;
|
|
182
|
+
z-index: 2147483000;
|
|
183
|
+
overscroll-behavior: contain;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
.ob-course-player__leave-full-screen {
|
|
187
|
+
position: absolute;
|
|
188
|
+
top: max(var(--ds-size-2, 0.5rem), env(safe-area-inset-top));
|
|
189
|
+
right: max(var(--ds-size-2, 0.5rem), env(safe-area-inset-right));
|
|
190
|
+
z-index: 3;
|
|
191
|
+
opacity: 0.85;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/*
|
|
195
|
+
* A phone on its side has little height: the header and the buttons get slim (they also take the
|
|
196
|
+
* small size, set from the same query in CoursePlayer), so the slide keeps most of the screen.
|
|
197
|
+
*/
|
|
198
|
+
@media (orientation: landscape) and (max-height: 500px) {
|
|
199
|
+
.ob-course-player__header {
|
|
200
|
+
padding: 0.125rem max(var(--ds-size-3, 0.75rem), env(safe-area-inset-right)) 0.125rem
|
|
201
|
+
max(var(--ds-size-3, 0.75rem), env(safe-area-inset-left));
|
|
202
|
+
font-size: 0.875rem;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
.ob-course-player__controls {
|
|
206
|
+
gap: var(--ds-size-2, 0.5rem);
|
|
207
|
+
padding: 0.25rem max(var(--ds-size-3, 0.75rem), env(safe-area-inset-right))
|
|
208
|
+
max(0.25rem, env(safe-area-inset-bottom)) max(var(--ds-size-3, 0.75rem), env(safe-area-inset-left));
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
.ob-course-player__status {
|
|
212
|
+
font-size: 0.75rem;
|
|
213
|
+
line-height: 1.25;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
@@ -252,16 +252,84 @@ async function endMedia(selector: "audio" | "video") {
|
|
|
252
252
|
}
|
|
253
253
|
|
|
254
254
|
describe("narration the learner may skip", () => {
|
|
255
|
-
it("is done
|
|
255
|
+
it("is done at once: Next goes to the next step, and parts marked for Next show from the start", async () => {
|
|
256
256
|
let optional = {
|
|
257
257
|
...revealSlide,
|
|
258
258
|
narration: { media: { src: "/media/course/a.m4a" }, required: false },
|
|
259
259
|
} as Step;
|
|
260
260
|
renderPlayer({ steps: steps(optional, plainSlide), progress: adapter(() => 1) });
|
|
261
261
|
|
|
262
|
+
expect(part("one")).not.toHaveAttribute("aria-hidden");
|
|
263
|
+
expect(part("two")).not.toHaveAttribute("aria-hidden");
|
|
264
|
+
expect(next()).toBeEnabled();
|
|
262
265
|
await press(next());
|
|
266
|
+
expect(screen.getByText("The end")).toBeInTheDocument();
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
describe("a narrated slide", () => {
|
|
271
|
+
let narrated: Step = {
|
|
272
|
+
schemaVersion: 2,
|
|
273
|
+
type: "slide",
|
|
274
|
+
narration: {
|
|
275
|
+
media: { src: "/media/course/a.m4a" },
|
|
276
|
+
cues: [
|
|
277
|
+
{ id: "c1", start: 2 },
|
|
278
|
+
{ id: "c2", start: 5 },
|
|
279
|
+
],
|
|
280
|
+
},
|
|
281
|
+
blocks: [
|
|
282
|
+
{ id: "s1", type: "text", text: "One", hideAt: "c1" },
|
|
283
|
+
{ id: "s2", type: "text", text: "Two", reveal: "step", revealAt: "c1", hideAt: "c2" },
|
|
284
|
+
{ id: "with", type: "text", text: "With two", reveal: "with-previous" },
|
|
285
|
+
{ id: "dim", type: "effect", target: "s1", opacity: 0.5, revealAt: "c1" },
|
|
286
|
+
],
|
|
287
|
+
};
|
|
288
|
+
let shown = (id: string) => document.querySelector(`[data-part="${id}"]:not(.is-leaving, .is-pending)`) !== null;
|
|
289
|
+
let at = async (seconds: number) => {
|
|
290
|
+
let audio = document.querySelector("audio")!;
|
|
291
|
+
await act(async () => {
|
|
292
|
+
audio.currentTime = seconds;
|
|
293
|
+
fireEvent(audio, new Event("timeupdate"));
|
|
294
|
+
});
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
it("waits for the narration before Next goes on, and presses reveal nothing", async () => {
|
|
298
|
+
renderPlayer({ steps: steps(narrated, plainSlide), progress: adapter(() => 1) });
|
|
299
|
+
|
|
300
|
+
expect(next()).toBeDisabled();
|
|
301
|
+
expect(screen.getByText("Finish this part to continue.")).toBeInTheDocument();
|
|
263
302
|
await press(next());
|
|
303
|
+
expect([shown("s1"), shown("s2"), shown("with")]).toEqual([true, false, false]);
|
|
304
|
+
|
|
305
|
+
await endMedia("audio");
|
|
264
306
|
expect(next()).toBeEnabled();
|
|
307
|
+
await press(next());
|
|
308
|
+
expect(screen.getByText("The end")).toBeInTheDocument();
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
it("shows and hides the parts on their cues, with-previous parts and effects included", async () => {
|
|
312
|
+
renderPlayer({ steps: steps(narrated, plainSlide), mode: "preview" });
|
|
313
|
+
expect(shown("s1")).toBe(true);
|
|
314
|
+
expect(part("s1")).not.toHaveStyle({ filter: "opacity(0.5)" });
|
|
315
|
+
|
|
316
|
+
await at(3);
|
|
317
|
+
expect([shown("s1"), shown("s2"), shown("with")]).toEqual([false, true, true]);
|
|
318
|
+
await at(6);
|
|
319
|
+
expect([shown("s2"), shown("with")]).toEqual([false, true]);
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
it("goes straight to the other steps with Next and Back, and starts over at the start of the narration", async () => {
|
|
323
|
+
renderPlayer({ steps: steps(plainSlide, narrated, plainSlide), mode: "preview", initialIndex: 1 });
|
|
324
|
+
await at(3);
|
|
325
|
+
await press(back());
|
|
326
|
+
expect(screen.getByText("1 / 3")).toBeInTheDocument();
|
|
327
|
+
|
|
328
|
+
await press(next());
|
|
329
|
+
expect(screen.getByText("2 / 3")).toBeInTheDocument();
|
|
330
|
+
expect([shown("s1"), shown("s2")]).toEqual([true, false]);
|
|
331
|
+
await press(next());
|
|
332
|
+
expect(screen.getByText("3 / 3")).toBeInTheDocument();
|
|
265
333
|
});
|
|
266
334
|
});
|
|
267
335
|
|
|
@@ -381,14 +449,10 @@ describe("moving on by itself", () => {
|
|
|
381
449
|
expect(screen.getByText("2 / 2")).toBeInTheDocument();
|
|
382
450
|
});
|
|
383
451
|
|
|
384
|
-
it("
|
|
452
|
+
it("moves on when the narration ends, whatever the slide marks for Next: the narration shows its parts", async () => {
|
|
385
453
|
renderPlayer({ steps: steps(autoSlide, plainSlide), progress: adapter(() => 1) });
|
|
386
454
|
|
|
387
455
|
await endMedia("audio");
|
|
388
|
-
await press(next());
|
|
389
|
-
await press(next());
|
|
390
|
-
expect(screen.getByText("1 / 2")).toBeInTheDocument();
|
|
391
|
-
await press(next());
|
|
392
456
|
expect(screen.getByText("2 / 2")).toBeInTheDocument();
|
|
393
457
|
});
|
|
394
458
|
});
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
import clsx from "clsx";
|
|
1
2
|
import { Alert, Button } from "@digdir/designsystemet-react";
|
|
2
3
|
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
3
4
|
import { useSwipeable } from "react-swipeable";
|
|
4
5
|
import { ProgressBar } from "../chrome/ProgressBar";
|
|
5
|
-
import { getRevealSteps } from "../document/cues";
|
|
6
|
+
import { getRevealSteps, isNarratedSlide, type RevealNavigation } from "../document/cues";
|
|
6
7
|
import { getLocalizedString, localize } from "../i18n";
|
|
7
|
-
import { ArrowLeftIcon, ArrowRightIcon, CloseIcon } from "../media/icons";
|
|
8
|
+
import { ArrowLeftIcon, ArrowRightIcon, CloseIcon, ExitFullscreenIcon, FullscreenIcon } from "../media/icons";
|
|
8
9
|
import { StepBody, StepFrame } from "../steps/StepView";
|
|
9
|
-
import {
|
|
10
|
+
import { playStepTransition } from "../transitions/playStepTransition";
|
|
10
11
|
import type {
|
|
11
12
|
PlayerBranding,
|
|
12
13
|
PlayerCourse,
|
|
@@ -18,6 +19,8 @@ import type {
|
|
|
18
19
|
} from "../types";
|
|
19
20
|
import { LanguageMenu } from "./LanguageMenu";
|
|
20
21
|
import { StartScreen } from "./StartScreen";
|
|
22
|
+
import { useFullScreen } from "./useFullScreen";
|
|
23
|
+
import { COMPACT_QUERY, useMediaQuery } from "./useMediaQuery";
|
|
21
24
|
import { useNavigationKeys } from "./useNavigationKeys";
|
|
22
25
|
|
|
23
26
|
import "../steps/StepView.css";
|
|
@@ -50,7 +53,8 @@ export interface CoursePlayerProps {
|
|
|
50
53
|
}
|
|
51
54
|
|
|
52
55
|
function countReveals(step: PlayerStep | undefined) {
|
|
53
|
-
|
|
56
|
+
let document = step?.document;
|
|
57
|
+
return document?.type === "slide" ? getRevealSteps(document.blocks, isNarratedSlide(document)).length : 0;
|
|
54
58
|
}
|
|
55
59
|
|
|
56
60
|
function advancesByItself(step: PlayerStep | undefined) {
|
|
@@ -94,11 +98,21 @@ export function CoursePlayer({
|
|
|
94
98
|
let unlocked = preview ? lastIndex : Math.max(serverUnlocked, unlockedIndex);
|
|
95
99
|
let isLast = current === lastIndex;
|
|
96
100
|
let revealCount = countReveals(step);
|
|
97
|
-
let pendingReveal = stepsShown < revealCount;
|
|
98
101
|
|
|
99
|
-
|
|
102
|
+
// The main language is stored as no language, so a learner who is under way has chosen it
|
|
103
|
+
let underWay = initialIndex > 0 || unlockedIndex > 0;
|
|
104
|
+
let showStart = !preview && !languageChosen && !underWay && course.cultureId == null && course.languages.length > 1;
|
|
100
105
|
let stepKey = step ? `${step.slideId}:${course.cultureId ?? ""}` : "";
|
|
101
106
|
|
|
107
|
+
// Where Next and Back go within a slide, from the slide itself: it knows the narration's time
|
|
108
|
+
let [navigation, setNavigation] = useState<{ stepKey: string; navigation: RevealNavigation } | null>(null);
|
|
109
|
+
let onRevealNavigation = useCallback(
|
|
110
|
+
(reported: RevealNavigation) => setNavigation({ stepKey, navigation: reported }),
|
|
111
|
+
[stepKey],
|
|
112
|
+
);
|
|
113
|
+
let reveals = navigation?.stepKey === stepKey ? navigation.navigation : null;
|
|
114
|
+
let pendingReveal = reveals ? reveals.next !== null : stepsShown < revealCount;
|
|
115
|
+
|
|
102
116
|
// Steps below the frontier were done before, and can be walked through freely.
|
|
103
117
|
let gated = !preview && current >= unlocked;
|
|
104
118
|
let minDuration = gated ? (step?.minDuration ?? 0) : 0;
|
|
@@ -124,7 +138,7 @@ export function CoursePlayer({
|
|
|
124
138
|
let go = useCallback(
|
|
125
139
|
(target: number, direction: "forward" | "backward") => {
|
|
126
140
|
movedRef.current = true;
|
|
127
|
-
|
|
141
|
+
void playStepTransition(
|
|
128
142
|
() => {
|
|
129
143
|
setIndex(target);
|
|
130
144
|
setStepsShown(direction === "backward" ? countReveals(steps[target]) : 0);
|
|
@@ -135,10 +149,10 @@ export function CoursePlayer({
|
|
|
135
149
|
setShownAt(time);
|
|
136
150
|
setNow(time);
|
|
137
151
|
},
|
|
138
|
-
{ direction },
|
|
152
|
+
{ scope: stageRef.current, from: steps[current], to: steps[target], direction },
|
|
139
153
|
);
|
|
140
154
|
},
|
|
141
|
-
[steps],
|
|
155
|
+
[steps, current],
|
|
142
156
|
);
|
|
143
157
|
|
|
144
158
|
async function complete() {
|
|
@@ -184,7 +198,7 @@ export function CoursePlayer({
|
|
|
184
198
|
function next() {
|
|
185
199
|
if (busy || completed || showStart || !step) return;
|
|
186
200
|
if (pendingReveal) {
|
|
187
|
-
setStepsShown(
|
|
201
|
+
setStepsShown(reveals?.next ?? stepsShown + 1);
|
|
188
202
|
return;
|
|
189
203
|
}
|
|
190
204
|
if (!canLeave) return;
|
|
@@ -195,8 +209,8 @@ export function CoursePlayer({
|
|
|
195
209
|
|
|
196
210
|
function back() {
|
|
197
211
|
if (busy || showStart) return;
|
|
198
|
-
if (stepsShown > 0 && revealCount > 0) {
|
|
199
|
-
setStepsShown(
|
|
212
|
+
if (reveals ? reveals.previous !== null : stepsShown > 0 && revealCount > 0) {
|
|
213
|
+
setStepsShown(reveals?.previous ?? Math.min(stepsShown, revealCount) - 1);
|
|
200
214
|
return;
|
|
201
215
|
}
|
|
202
216
|
if (current > 0) go(current - 1, "backward");
|
|
@@ -253,19 +267,55 @@ export function CoursePlayer({
|
|
|
253
267
|
else if (!done) hint = getLocalizedString("Finish this part to continue.");
|
|
254
268
|
else if (remaining > 0) hint = localize`You can continue in ${remaining} seconds.`;
|
|
255
269
|
|
|
270
|
+
let fullScreen = useFullScreen(rootRef);
|
|
271
|
+
// On a phone on its side the header and the buttons take the small size, to leave the slide the height
|
|
272
|
+
let chromeSize = useMediaQuery(COMPACT_QUERY) ? "sm" : undefined;
|
|
273
|
+
let fullScreenLabel = fullScreen.active ? getLocalizedString("Leave full screen") : getLocalizedString("Full screen");
|
|
274
|
+
|
|
256
275
|
let nextLabel = isLast && !pendingReveal ? getLocalizedString("Complete") : getLocalizedString("Next");
|
|
257
276
|
|
|
258
277
|
return (
|
|
259
|
-
<div
|
|
260
|
-
|
|
278
|
+
<div
|
|
279
|
+
className={clsx(
|
|
280
|
+
"ob-course-player",
|
|
281
|
+
fullScreen.active && "is-full-screen",
|
|
282
|
+
fullScreen.immersive && "is-immersive",
|
|
283
|
+
)}
|
|
284
|
+
data-mode={mode}
|
|
285
|
+
ref={rootRef}
|
|
286
|
+
>
|
|
287
|
+
{fullScreen.active && (
|
|
288
|
+
<Button
|
|
289
|
+
variant="secondary"
|
|
290
|
+
data-size="sm"
|
|
291
|
+
icon
|
|
292
|
+
className="ob-course-player__leave-full-screen"
|
|
293
|
+
onClick={fullScreen.toggle}
|
|
294
|
+
aria-label={fullScreenLabel}
|
|
295
|
+
title={fullScreenLabel}
|
|
296
|
+
>
|
|
297
|
+
<ExitFullscreenIcon />
|
|
298
|
+
</Button>
|
|
299
|
+
)}
|
|
300
|
+
<header className="ob-course-player__header" data-size={chromeSize}>
|
|
261
301
|
<p className="ob-course-player__title">{course.title}</p>
|
|
262
302
|
{onCultureChange && course.languages.length > 1 && !showStart && (
|
|
263
303
|
<LanguageMenu
|
|
264
304
|
languages={course.languages}
|
|
265
|
-
cultureId={course.cultureId}
|
|
305
|
+
cultureId={course.cultureId ?? course.mainCultureId ?? null}
|
|
266
306
|
onChange={(cultureId) => onCultureChange(cultureId)}
|
|
267
307
|
/>
|
|
268
308
|
)}
|
|
309
|
+
<Button
|
|
310
|
+
variant="tertiary"
|
|
311
|
+
data-size="sm"
|
|
312
|
+
icon
|
|
313
|
+
onClick={fullScreen.toggle}
|
|
314
|
+
aria-label={fullScreenLabel}
|
|
315
|
+
title={fullScreenLabel}
|
|
316
|
+
>
|
|
317
|
+
<FullscreenIcon />
|
|
318
|
+
</Button>
|
|
269
319
|
{onExit && (
|
|
270
320
|
<Button
|
|
271
321
|
variant="tertiary"
|
|
@@ -308,14 +358,15 @@ export function CoursePlayer({
|
|
|
308
358
|
onSubtitlesChange={setSubtitles}
|
|
309
359
|
onDoneChange={setDone}
|
|
310
360
|
onMediaEnded={onMediaEnded}
|
|
361
|
+
onRevealNavigation={onRevealNavigation}
|
|
311
362
|
/>
|
|
312
363
|
</StepFrame>
|
|
313
364
|
</section>
|
|
314
|
-
<footer className="ob-course-player__controls">
|
|
365
|
+
<footer className="ob-course-player__controls" data-size={chromeSize}>
|
|
315
366
|
<Button
|
|
316
367
|
variant="secondary"
|
|
317
368
|
onClick={back}
|
|
318
|
-
disabled={busy || (current === 0 && stepsShown === 0)}
|
|
369
|
+
disabled={busy || (current === 0 && (reveals ? reveals.previous === null : stepsShown === 0))}
|
|
319
370
|
aria-label={getLocalizedString("Back")}
|
|
320
371
|
>
|
|
321
372
|
<ArrowLeftIcon />
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { act, render, screen } from "@testing-library/react";
|
|
2
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
import type { PlayerCourse, PlayerStep } from "../types";
|
|
4
|
+
import { CoursePlayer } from "./CoursePlayer";
|
|
5
|
+
import { fullScreenKind } from "./useFullScreen";
|
|
6
|
+
|
|
7
|
+
let course: PlayerCourse = { title: "Safety", cultureId: "nb-NO", languages: [{ cultureId: "nb-NO", name: "Norsk" }] };
|
|
8
|
+
let steps: PlayerStep[] = [
|
|
9
|
+
{
|
|
10
|
+
slideId: 1,
|
|
11
|
+
category: { title: "Intro" },
|
|
12
|
+
document: { schemaVersion: 2, type: "slide", blocks: [{ id: "h", type: "heading", text: "Hello" }] },
|
|
13
|
+
},
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
function renderPlayer() {
|
|
17
|
+
return render(<CoursePlayer course={course} steps={steps} resolveAsset={(src) => src} mode="preview" />);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
let player = () => document.querySelector<HTMLElement>(".ob-course-player")!;
|
|
21
|
+
|
|
22
|
+
describe("full screen", () => {
|
|
23
|
+
afterEach(() => {
|
|
24
|
+
vi.restoreAllMocks();
|
|
25
|
+
Reflect.deleteProperty(document, "fullscreenEnabled");
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("uses the browser's full screen where it has one, and the immersive mode where it does not", () => {
|
|
29
|
+
let doc = { fullscreenEnabled: true, documentElement: { requestFullscreen() {} } } as unknown as Document;
|
|
30
|
+
expect(fullScreenKind(doc)).toBe("native");
|
|
31
|
+
let webkit = { webkitFullscreenEnabled: true, documentElement: { webkitRequestFullscreen() {} } };
|
|
32
|
+
expect(fullScreenKind(webkit as unknown as Document)).toBe("native");
|
|
33
|
+
// Safari on iPhone: the API is there for videos only, so it is not enabled for other elements
|
|
34
|
+
let iphone = { fullscreenEnabled: false, documentElement: {} } as unknown as Document;
|
|
35
|
+
expect(fullScreenKind(iphone)).toBe("immersive");
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("lays the player over the page without the API, and leaves it with the corner button or Escape", async () => {
|
|
39
|
+
renderPlayer();
|
|
40
|
+
expect(player()).not.toHaveClass("is-full-screen");
|
|
41
|
+
|
|
42
|
+
await act(async () => screen.getByRole("button", { name: "Full screen" }).click());
|
|
43
|
+
expect(player()).toHaveClass("is-full-screen", "is-immersive");
|
|
44
|
+
expect(document.documentElement.style.overflow).toBe("hidden");
|
|
45
|
+
|
|
46
|
+
let leave = screen.getAllByRole("button", { name: "Leave full screen" });
|
|
47
|
+
expect(leave.some((button) => button.classList.contains("ob-course-player__leave-full-screen"))).toBe(true);
|
|
48
|
+
await act(async () => leave[0].click());
|
|
49
|
+
expect(player()).not.toHaveClass("is-full-screen");
|
|
50
|
+
expect(document.documentElement.style.overflow).toBe("");
|
|
51
|
+
|
|
52
|
+
await act(async () => screen.getByRole("button", { name: "Full screen" }).click());
|
|
53
|
+
await act(async () => {
|
|
54
|
+
document.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape" }));
|
|
55
|
+
});
|
|
56
|
+
expect(player()).not.toHaveClass("is-full-screen");
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("asks the browser for full screen on the player where it can", async () => {
|
|
60
|
+
Object.defineProperty(document, "fullscreenEnabled", { value: true, configurable: true });
|
|
61
|
+
let request = vi.fn(async () => {});
|
|
62
|
+
Object.defineProperty(HTMLElement.prototype, "requestFullscreen", { value: request, configurable: true });
|
|
63
|
+
renderPlayer();
|
|
64
|
+
|
|
65
|
+
await act(async () => screen.getByRole("button", { name: "Full screen" }).click());
|
|
66
|
+
expect(request).toHaveBeenCalledTimes(1);
|
|
67
|
+
expect(request.mock.contexts[0]).toBe(player());
|
|
68
|
+
Reflect.deleteProperty(HTMLElement.prototype, "requestFullscreen");
|
|
69
|
+
});
|
|
70
|
+
});
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { type RefObject, useCallback, useEffect, useState } from "react";
|
|
2
|
+
|
|
3
|
+
/** The prefixed names Safari and older WebKit browsers still use. */
|
|
4
|
+
type WebKitDocument = Document & {
|
|
5
|
+
webkitFullscreenEnabled?: boolean;
|
|
6
|
+
webkitFullscreenElement?: Element | null;
|
|
7
|
+
webkitExitFullscreen?: () => Promise<void> | void;
|
|
8
|
+
};
|
|
9
|
+
type WebKitElement = Element & { webkitRequestFullscreen?: () => Promise<void> | void };
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* How full screen is done here: `native` asks the browser to show the element on the whole screen
|
|
13
|
+
* (the Fullscreen API, prefixed or not); `immersive` lays the player over the whole page itself,
|
|
14
|
+
* for browsers that only put videos on the screen, such as Safari on iPhone.
|
|
15
|
+
*/
|
|
16
|
+
export function fullScreenKind(doc: Document = document): "native" | "immersive" {
|
|
17
|
+
let webkit = doc as WebKitDocument;
|
|
18
|
+
let element = doc.documentElement as WebKitElement;
|
|
19
|
+
let enabled = doc.fullscreenEnabled === true || webkit.webkitFullscreenEnabled === true;
|
|
20
|
+
let canRequest =
|
|
21
|
+
typeof element.requestFullscreen === "function" || typeof element.webkitRequestFullscreen === "function";
|
|
22
|
+
return enabled && canRequest ? "native" : "immersive";
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function fullscreenElement(doc: Document) {
|
|
26
|
+
return doc.fullscreenElement ?? (doc as WebKitDocument).webkitFullscreenElement ?? null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async function requestNative(element: Element) {
|
|
30
|
+
let target = element as WebKitElement;
|
|
31
|
+
if (typeof target.requestFullscreen === "function") await target.requestFullscreen();
|
|
32
|
+
else await target.webkitRequestFullscreen?.();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async function exitNative(doc: Document) {
|
|
36
|
+
let webkit = doc as WebKitDocument;
|
|
37
|
+
if (typeof doc.exitFullscreen === "function") await doc.exitFullscreen();
|
|
38
|
+
else await webkit.webkitExitFullscreen?.();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The player's full screen: one switch for the learner whichever way the browser does it. Native
|
|
43
|
+
* full screen follows the browser (Escape or the system's back gesture leave it); the immersive
|
|
44
|
+
* mode is left with the same button or Escape, and keeps the page behind it from scrolling.
|
|
45
|
+
*/
|
|
46
|
+
export function useFullScreen(root: RefObject<HTMLElement | null>) {
|
|
47
|
+
let [immersive, setImmersive] = useState(false);
|
|
48
|
+
let [native, setNative] = useState(false);
|
|
49
|
+
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
let sync = () => setNative(root.current != null && fullscreenElement(document) === root.current);
|
|
52
|
+
document.addEventListener("fullscreenchange", sync);
|
|
53
|
+
document.addEventListener("webkitfullscreenchange", sync);
|
|
54
|
+
return () => {
|
|
55
|
+
document.removeEventListener("fullscreenchange", sync);
|
|
56
|
+
document.removeEventListener("webkitfullscreenchange", sync);
|
|
57
|
+
};
|
|
58
|
+
}, [root]);
|
|
59
|
+
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
if (!immersive) return;
|
|
62
|
+
let page = document.documentElement;
|
|
63
|
+
let overflow = page.style.overflow;
|
|
64
|
+
page.style.overflow = "hidden";
|
|
65
|
+
let onKey = (event: KeyboardEvent) => {
|
|
66
|
+
if (event.key === "Escape") setImmersive(false);
|
|
67
|
+
};
|
|
68
|
+
document.addEventListener("keydown", onKey);
|
|
69
|
+
return () => {
|
|
70
|
+
page.style.overflow = overflow;
|
|
71
|
+
document.removeEventListener("keydown", onKey);
|
|
72
|
+
};
|
|
73
|
+
}, [immersive]);
|
|
74
|
+
|
|
75
|
+
let toggle = useCallback(() => {
|
|
76
|
+
let element = root.current;
|
|
77
|
+
if (!element) return;
|
|
78
|
+
if (native) {
|
|
79
|
+
exitNative(document).catch(() => {});
|
|
80
|
+
} else if (immersive) {
|
|
81
|
+
setImmersive(false);
|
|
82
|
+
} else if (fullScreenKind() === "native") {
|
|
83
|
+
// A refusal (no user gesture, a frame without permission) falls back to the immersive mode
|
|
84
|
+
requestNative(element).catch(() => setImmersive(true));
|
|
85
|
+
} else {
|
|
86
|
+
setImmersive(true);
|
|
87
|
+
}
|
|
88
|
+
}, [root, native, immersive]);
|
|
89
|
+
|
|
90
|
+
return { active: native || immersive, immersive, toggle };
|
|
91
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useSyncExternalStore } from "react";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A phone on its side: little height, so the player's chrome shrinks and the slide's text scales
|
|
5
|
+
* with the height. The stylesheet has the same query for what CSS can do alone.
|
|
6
|
+
*/
|
|
7
|
+
export const COMPACT_QUERY = "(orientation: landscape) and (max-height: 500px)";
|
|
8
|
+
|
|
9
|
+
/** Whether a media query matches, kept up to date. False where `matchMedia` is missing. */
|
|
10
|
+
export function useMediaQuery(query: string) {
|
|
11
|
+
return useSyncExternalStore(
|
|
12
|
+
(onChange) => {
|
|
13
|
+
if (typeof matchMedia !== "function") return () => {};
|
|
14
|
+
let list = matchMedia(query);
|
|
15
|
+
list.addEventListener?.("change", onChange);
|
|
16
|
+
return () => list.removeEventListener?.("change", onChange);
|
|
17
|
+
},
|
|
18
|
+
() => typeof matchMedia === "function" && matchMedia(query).matches,
|
|
19
|
+
() => false,
|
|
20
|
+
);
|
|
21
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { nestItems } from "./Blocks";
|
|
3
|
+
|
|
4
|
+
describe("nestItems", () => {
|
|
5
|
+
it("puts an indented item under the nearest item above it with a smaller indent", () => {
|
|
6
|
+
let tree = nestItems([
|
|
7
|
+
{ id: "a", text: "A" },
|
|
8
|
+
{ id: "a1", text: "A1", indent: 1 },
|
|
9
|
+
{ id: "a1x", text: "A1x", indent: 2 },
|
|
10
|
+
{ id: "a2", text: "A2", indent: 1 },
|
|
11
|
+
{ id: "b", text: "B" },
|
|
12
|
+
]);
|
|
13
|
+
let ids = (nodes: typeof tree): unknown => nodes.map((node) => [node.item.id, ids(node.children)]);
|
|
14
|
+
expect(ids(tree)).toEqual([
|
|
15
|
+
[
|
|
16
|
+
"a",
|
|
17
|
+
[
|
|
18
|
+
["a1", [["a1x", []]]],
|
|
19
|
+
["a2", []],
|
|
20
|
+
],
|
|
21
|
+
],
|
|
22
|
+
["b", []],
|
|
23
|
+
]);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("never nests an item deeper than one level under the item above it", () => {
|
|
27
|
+
let tree = nestItems([
|
|
28
|
+
{ id: "x", text: "X", indent: 2 },
|
|
29
|
+
{ id: "y", text: "Y", indent: 2 },
|
|
30
|
+
]);
|
|
31
|
+
expect(tree.map((node) => node.item.id)).toEqual(["x"]);
|
|
32
|
+
expect(tree[0].children.map((node) => node.item.id)).toEqual(["y"]);
|
|
33
|
+
});
|
|
34
|
+
});
|