@olenbetong/synergi-course 2.1.0 → 2.2.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.
Files changed (47) hide show
  1. package/es/document/cues.d.ts +1 -1
  2. package/es/document/cues.js +3 -1
  3. package/es/document/effects.d.ts +3 -3
  4. package/es/document/effects.js +3 -1
  5. package/es/document/schema.d.ts +1778 -190
  6. package/es/document/schema.js +35 -2
  7. package/es/document/validate.js +14 -18
  8. package/es/index.d.ts +3 -2
  9. package/es/index.js +1 -1
  10. package/es/player/CoursePlayer.css +18 -0
  11. package/es/player/CoursePlayer.js +3 -2
  12. package/es/player/PlayerBars.d.ts +32 -0
  13. package/es/player/PlayerBars.js +14 -0
  14. package/es/steps/Blocks.d.ts +24 -3
  15. package/es/steps/Blocks.js +14 -7
  16. package/es/steps/Markdown.js +1 -1
  17. package/es/steps/QuizStepView.d.ts +2 -1
  18. package/es/steps/QuizStepView.js +20 -10
  19. package/es/steps/SlideStepView.d.ts +1 -1
  20. package/es/steps/SlideStepView.js +14 -4
  21. package/es/steps/StepBodyProps.d.ts +9 -0
  22. package/es/steps/StepView.css +65 -7
  23. package/es/steps/StepView.d.ts +29 -3
  24. package/es/steps/StepView.js +21 -5
  25. package/es/types.d.ts +13 -2
  26. package/package.json +1 -1
  27. package/src/document/box.test.ts +234 -0
  28. package/src/document/cues.ts +2 -1
  29. package/src/document/effects.ts +4 -3
  30. package/src/document/schema.ts +44 -2
  31. package/src/document/validate.ts +15 -19
  32. package/src/index.ts +11 -1
  33. package/src/player/CoursePlayer.css +18 -0
  34. package/src/player/CoursePlayer.tsx +38 -58
  35. package/src/player/PlayerBars.tsx +106 -0
  36. package/src/steps/Blocks.tsx +55 -8
  37. package/src/steps/Box.test.tsx +95 -0
  38. package/src/steps/Markdown.test.tsx +3 -0
  39. package/src/steps/Markdown.tsx +1 -1
  40. package/src/steps/QuizStepView.test.tsx +79 -0
  41. package/src/steps/QuizStepView.tsx +34 -12
  42. package/src/steps/SlideStepView.tsx +15 -3
  43. package/src/steps/StepBodyProps.ts +9 -0
  44. package/src/steps/StepView.css +65 -7
  45. package/src/steps/StepView.test.tsx +116 -0
  46. package/src/steps/StepView.tsx +100 -19
  47. package/src/types.ts +13 -2
@@ -14,6 +14,15 @@ let text = string();
14
14
  */
15
15
  let source = pipe(string(), minLength(1));
16
16
  let seconds = pipe(number(), minValue(0));
17
+ /** The colour scales a box, a callout or a framed canvas text can take. `brand` is the company theme's own. */
18
+ export const TONES = ["neutral", "info", "success", "warning", "danger", "brand"];
19
+ /** The colour of a surface. Default `neutral`. */
20
+ let tone = optional(picklist(TONES));
21
+ /**
22
+ * `bordered` (the default): a tinted surface with a frame and a coloured edge. `filled`: a solid
23
+ * surface in the tone's colour, with the text in its contrast colour.
24
+ */
25
+ let surfaceVariant = optional(picklist(["bordered", "filled"]));
17
26
  /**
18
27
  * A stretch of narration or video: what is said, and when. The text is also the subtitle. A cue
19
28
  * without text is a marker: something on the slide can show or go away at it, but no subtitle is
@@ -132,7 +141,8 @@ export const calloutBlockSchema = strictObject({
132
141
  /** Markdown. */
133
142
  text,
134
143
  /** The colour of the box. Default `neutral`. */
135
- tone: optional(picklist(["neutral", "info", "success", "warning", "danger"])),
144
+ tone,
145
+ variant: surfaceVariant,
136
146
  ...timing,
137
147
  });
138
148
  /** A link that plays a video in a dialog on top of the slide. */
@@ -162,6 +172,27 @@ export const effectBlockSchema = strictObject({
162
172
  /** Milliseconds the change takes, 50 to 3000. Default 300. `delay` holds it back after it is due. */
163
173
  duration: milliseconds.duration,
164
174
  });
175
+ /** Every block that can stand inside a box. A box holds no box, callout, columns or canvas. */
176
+ export const boxContentSchema = variant("type", [
177
+ headingBlockSchema,
178
+ textBlockSchema,
179
+ listBlockSchema,
180
+ imageBlockSchema,
181
+ quoteBlockSchema,
182
+ videoLinkBlockSchema,
183
+ effectBlockSchema,
184
+ ]);
185
+ /** A coloured box around other blocks, e.g. a heading and a list of steps. */
186
+ export const boxBlockSchema = strictObject({
187
+ id,
188
+ type: literal("box"),
189
+ /** The colour of the box. Default `neutral`. */
190
+ tone,
191
+ variant: surfaceVariant,
192
+ /** Headings, texts, lists, images, quotes and video links, and effects. No box, callout, columns or canvas. */
193
+ blocks: array(boxContentSchema),
194
+ ...timing,
195
+ });
165
196
  /** Every block that can stand inside a column. Columns do not nest. */
166
197
  export const contentBlockSchema = variant("type", [
167
198
  headingBlockSchema,
@@ -170,6 +201,7 @@ export const contentBlockSchema = variant("type", [
170
201
  imageBlockSchema,
171
202
  quoteBlockSchema,
172
203
  calloutBlockSchema,
204
+ boxBlockSchema,
173
205
  videoLinkBlockSchema,
174
206
  effectBlockSchema,
175
207
  ]);
@@ -204,7 +236,7 @@ export const canvasTextSchema = strictObject({
204
236
  /** `solid`: on a white surface that covers what is under it. `frame`: the same with a coloured frame. */
205
237
  surface: optional(picklist(["none", "solid", "frame"])),
206
238
  /** The colour of the frame. Default `neutral`. */
207
- tone: optional(picklist(["neutral", "info", "success", "warning", "danger"])),
239
+ tone,
208
240
  /** The text size, as a factor of the canvas's normal size. Default 1. */
209
241
  size: optional(pipe(number(), minValue(0.1))),
210
242
  ...canvasPlace,
@@ -239,6 +271,7 @@ export const blockSchema = variant("type", [
239
271
  imageBlockSchema,
240
272
  quoteBlockSchema,
241
273
  calloutBlockSchema,
274
+ boxBlockSchema,
242
275
  videoLinkBlockSchema,
243
276
  effectBlockSchema,
244
277
  columnsBlockSchema,
@@ -135,32 +135,28 @@ function* mediaOf(step) {
135
135
  }
136
136
  }
137
137
  }
138
- /** Every timed part of a slide with its path. Columns are walked too, and they have ids of their own. */
139
- function* walk(step) {
140
- for (let [index, block] of step.blocks.entries()) {
141
- let path = `blocks.${index}`;
138
+ /**
139
+ * Every timed part of a slide with its path. Columns and boxes are walked too, a box in a column
140
+ * included, and columns have ids of their own.
141
+ */
142
+ function walk(step) {
143
+ return walkBlocks(step.blocks, "blocks");
144
+ }
145
+ function* walkBlocks(blocks, basePath) {
146
+ for (let [index, block] of blocks.entries()) {
147
+ let path = `${basePath}.${index}`;
142
148
  yield { part: block, path };
143
- if (block.type === "list") {
144
- for (let [itemIndex, item] of block.items.entries())
145
- yield { part: item, path: `${path}.items.${itemIndex}` };
146
- }
147
- if (block.type === "canvas") {
149
+ if (block.type === "list" || block.type === "canvas") {
148
150
  for (let [itemIndex, item] of block.items.entries())
149
151
  yield { part: item, path: `${path}.items.${itemIndex}` };
150
152
  }
153
+ if (block.type === "box")
154
+ yield* walkBlocks(block.blocks, `${path}.blocks`);
151
155
  if (block.type === "columns") {
152
156
  for (let [columnIndex, column] of block.columns.entries()) {
153
157
  let columnPath = `${path}.columns.${columnIndex}`;
154
158
  yield { part: { id: column.id }, path: columnPath };
155
- for (let [childIndex, child] of column.blocks.entries()) {
156
- let childPath = `${columnPath}.blocks.${childIndex}`;
157
- yield { part: child, path: childPath };
158
- if (child.type === "list") {
159
- for (let [itemIndex, item] of child.items.entries()) {
160
- yield { part: item, path: `${childPath}.items.${itemIndex}` };
161
- }
162
- }
163
- }
159
+ yield* walkBlocks(column.blocks, `${columnPath}.blocks`);
164
160
  }
165
161
  }
166
162
  }
package/es/index.d.ts CHANGED
@@ -1,12 +1,13 @@
1
1
  export { CoursePlayer, type CoursePlayerProps } from "./player/CoursePlayer";
2
- export { StepView, type StepViewProps } from "./steps/StepView";
2
+ export { type SampleChrome, StepView, type StepViewProps } from "./steps/StepView";
3
+ export type { InsertContainer, InsertPlace } from "./steps/Blocks";
3
4
  export { CourseCompletion, type CourseCompletionProps, hasCompletionText, sanitizeCompletionHtml, } from "./completion/CourseCompletion";
4
5
  export { type CueClock, useCueClock } from "./media/useCueClock";
5
6
  export { elementHandle, isVimeoAddress, type MediaHandle, type MediaListener, type MediaTrim, vimeoHandle, } from "./media/mediaHandle";
6
7
  export type { PlayerBranding, PlayerCategory, PlayerCourse, PlayerLanguage, PlayerMode, PlayerStep, ProgressAdapter, QuizAdapter, QuizAnswerResult, QuizAttempt, QuizOption, QuizQuestion, QuizResult, ResolveAsset, } from "./types";
7
8
  export { getActiveCue, getCueEnd, getCues, getRevealLeaders, getRevealNavigation, getRevealState, getRevealSteps, getStartedCueIds, getTimedParts, hasCueText, hasTrigger, isDue, isNarratedSlide, isVisible, type RevealNavigation, type RevealState, } from "./document/cues";
8
9
  export { DEFAULT_EFFECT_DURATION, effectTargets, getActiveEffects, getEffectBlocks, getPartEffects, type PartEffect, } from "./document/effects";
9
- export { type Block, blockSchema, type CalloutBlock, type ColumnsBlock, type ContentBlock, type Cue, type EffectBlock, effectBlockSchema, type ImageSize, type Media, type Narration, type PdfStep, type QuizStep, type SlideStep, STEP_SCHEMA_VERSION, type Step, type StepTransition, type StepType, stepSchema, transitionSchema, type Timed, type VideoStep, } from "./document/schema";
10
+ export { type Block, blockSchema, type BoxBlock, type BoxContentBlock, boxBlockSchema, boxContentSchema, type CalloutBlock, calloutBlockSchema, type ColumnsBlock, type ContentBlock, contentBlockSchema, type Cue, type EffectBlock, effectBlockSchema, type ImageSize, type Media, type Narration, type PdfStep, type QuizStep, type SlideStep, STEP_SCHEMA_VERSION, type Step, type StepTransition, type StepType, stepSchema, type SurfaceVariant, TONES, type Tone, transitionSchema, type Timed, type VideoStep, } from "./document/schema";
10
11
  export { getStepJsonSchema, type StepIssue, type StepValidation, validateStep } from "./document/validate";
11
12
  export { DEFAULT_TRANSITION_DURATION, DEFAULT_TRANSITIONS, getStepTransitions, planStepTransition, type TransitionDirection, type TransitionPlan, type TransitionStep, } from "./transitions/plan";
12
13
  export { playStepTransition, type StepTransitionOptions } from "./transitions/playStepTransition";
package/es/index.js CHANGED
@@ -5,7 +5,7 @@ export { useCueClock } from "./media/useCueClock";
5
5
  export { elementHandle, isVimeoAddress, vimeoHandle, } from "./media/mediaHandle";
6
6
  export { getActiveCue, getCueEnd, getCues, getRevealLeaders, getRevealNavigation, getRevealState, getRevealSteps, getStartedCueIds, getTimedParts, hasCueText, hasTrigger, isDue, isNarratedSlide, isVisible, } from "./document/cues";
7
7
  export { DEFAULT_EFFECT_DURATION, effectTargets, getActiveEffects, getEffectBlocks, getPartEffects, } from "./document/effects";
8
- export { blockSchema, effectBlockSchema, STEP_SCHEMA_VERSION, stepSchema, transitionSchema, } from "./document/schema";
8
+ export { blockSchema, boxBlockSchema, boxContentSchema, calloutBlockSchema, contentBlockSchema, effectBlockSchema, STEP_SCHEMA_VERSION, stepSchema, TONES, transitionSchema, } from "./document/schema";
9
9
  export { getStepJsonSchema, validateStep } from "./document/validate";
10
10
  export { DEFAULT_TRANSITION_DURATION, DEFAULT_TRANSITIONS, getStepTransitions, planStepTransition, } from "./transitions/plan";
11
11
  export { playStepTransition } from "./transitions/playStepTransition";
@@ -213,3 +213,21 @@
213
213
  line-height: 1.25;
214
214
  }
215
215
  }
216
+
217
+ /* The same slim chrome in an editor's preview of a phone on its side, which the media query cannot see. */
218
+ .ob-course-player.is-compact {
219
+ > .ob-course-player__header {
220
+ padding: 0.125rem var(--ds-size-3, 0.75rem);
221
+ font-size: 0.875rem;
222
+ }
223
+
224
+ > .ob-course-player__controls {
225
+ gap: var(--ds-size-2, 0.5rem);
226
+ padding: 0.25rem var(--ds-size-3, 0.75rem);
227
+ }
228
+
229
+ .ob-course-player__status {
230
+ font-size: 0.75rem;
231
+ line-height: 1.25;
232
+ }
233
+ }
@@ -6,10 +6,11 @@ import { useSwipeable } from "react-swipeable";
6
6
  import { ProgressBar } from "../chrome/ProgressBar";
7
7
  import { getRevealSteps, isNarratedSlide } from "../document/cues";
8
8
  import { getLocalizedString, localize } from "../i18n";
9
- import { ArrowLeftIcon, ArrowRightIcon, CloseIcon, ExitFullscreenIcon, FullscreenIcon } from "../media/icons";
9
+ import { CloseIcon, ExitFullscreenIcon } from "../media/icons";
10
10
  import { StepBody, StepFrame } from "../steps/StepView";
11
11
  import { playStepTransition } from "../transitions/playStepTransition";
12
12
  import { LanguageMenu } from "./LanguageMenu";
13
+ import { PlayerControls, PlayerHeader } from "./PlayerBars";
13
14
  import { StartScreen } from "./StartScreen";
14
15
  import { useFullScreen } from "./useFullScreen";
15
16
  import { COMPACT_QUERY, useMediaQuery } from "./useMediaQuery";
@@ -209,5 +210,5 @@ export function CoursePlayer({ course, steps, initialIndex = 0, unlockedIndex =
209
210
  let chromeSize = useMediaQuery(COMPACT_QUERY) ? "sm" : undefined;
210
211
  let fullScreenLabel = fullScreen.active ? getLocalizedString("Leave full screen") : getLocalizedString("Full screen");
211
212
  let nextLabel = isLast && !pendingReveal ? getLocalizedString("Complete") : getLocalizedString("Next");
212
- return (_jsxs("div", { className: clsx("ob-course-player", fullScreen.active && "is-full-screen", fullScreen.immersive && "is-immersive"), "data-mode": mode, ref: rootRef, children: [fullScreen.active && (_jsx(Button, { variant: "secondary", "data-size": "sm", icon: true, className: "ob-course-player__leave-full-screen", onClick: fullScreen.toggle, "aria-label": fullScreenLabel, title: fullScreenLabel, children: _jsx(ExitFullscreenIcon, {}) })), _jsxs("header", { className: "ob-course-player__header", "data-size": chromeSize, children: [_jsx("p", { className: "ob-course-player__title", children: course.title }), onCultureChange && course.languages.length > 1 && !showStart && (_jsx(LanguageMenu, { languages: course.languages, cultureId: course.cultureId ?? course.mainCultureId ?? null, onChange: (cultureId) => onCultureChange(cultureId) })), _jsx(Button, { variant: "tertiary", "data-size": "sm", icon: true, onClick: fullScreen.toggle, "aria-label": fullScreenLabel, title: fullScreenLabel, children: _jsx(FullscreenIcon, {}) }), onExit && (_jsx(Button, { variant: "tertiary", "data-size": "sm", icon: true, onClick: onExit, "aria-label": getLocalizedString("Close the course"), title: getLocalizedString("Close the course"), children: _jsx(CloseIcon, {}) }))] }), _jsx(ProgressBar, { length: steps.length, currentIndex: showStart ? -1 : current }), showStart ? (_jsx(StartScreen, { course: course, onChoose: chooseLanguage })) : !step ? (_jsx("div", { className: "ob-course-player__empty", children: _jsx(Alert, { "data-color": "info", children: getLocalizedString("This course has no content yet.") }) })) : (_jsxs(_Fragment, { children: [_jsx("section", { className: "ob-course-step", ref: setStage, tabIndex: -1, "aria-label": localize `Step ${current + 1} of ${steps.length}`, onMouseDown: onSwipeMouseDown, children: _jsx(StepFrame, { category: step.category, branding: branding, children: _jsx(StepBody, { step: step.document, slideId: step.slideId, mode: mode, resolveAsset: resolveAsset, quiz: quiz, stepsShown: stepsShown, subtitles: subtitles, onSubtitlesChange: setSubtitles, onDoneChange: setDone, onMediaEnded: onMediaEnded, onRevealNavigation: onRevealNavigation }, `${step.slideId}:${course.cultureId ?? ""}`) }) }), _jsxs("footer", { className: "ob-course-player__controls", "data-size": chromeSize, children: [_jsxs(Button, { variant: "secondary", onClick: back, disabled: busy || (current === 0 && (reveals ? reveals.previous === null : stepsShown === 0)), "aria-label": getLocalizedString("Back"), children: [_jsx(ArrowLeftIcon, {}), _jsx("span", { className: "ob-course-player__button-text", children: getLocalizedString("Back") })] }), _jsxs("div", { className: "ob-course-player__status", children: [_jsxs("span", { className: "ob-course-player__count", children: [current + 1, " / ", steps.length] }), _jsxs("span", { className: "ob-course-player__note", children: [_jsx("span", { role: "status", className: "ob-course-player__message", children: message }), hint && _jsx("span", { className: "ob-course-player__hint", children: hint })] })] }), _jsxs(Button, { onClick: next, loading: busy, disabled: busy || completed || (!pendingReveal && !canLeave), "aria-label": nextLabel, children: [_jsx("span", { className: "ob-course-player__button-text", children: nextLabel }), !(isLast && !pendingReveal) && _jsx(ArrowRightIcon, {})] })] })] }))] }));
213
+ return (_jsxs("div", { className: clsx("ob-course-player", fullScreen.active && "is-full-screen", fullScreen.immersive && "is-immersive"), "data-mode": mode, ref: rootRef, children: [fullScreen.active && (_jsx(Button, { variant: "secondary", "data-size": "sm", icon: true, className: "ob-course-player__leave-full-screen", onClick: fullScreen.toggle, "aria-label": fullScreenLabel, title: fullScreenLabel, children: _jsx(ExitFullscreenIcon, {}) })), _jsx(PlayerHeader, { title: course.title, size: chromeSize, fullScreenLabel: fullScreenLabel, onFullScreen: fullScreen.toggle, end: onExit && (_jsx(Button, { variant: "tertiary", "data-size": "sm", icon: true, onClick: onExit, "aria-label": getLocalizedString("Close the course"), title: getLocalizedString("Close the course"), children: _jsx(CloseIcon, {}) })), children: onCultureChange && course.languages.length > 1 && !showStart && (_jsx(LanguageMenu, { languages: course.languages, cultureId: course.cultureId ?? course.mainCultureId ?? null, onChange: (cultureId) => onCultureChange(cultureId) })) }), _jsx(ProgressBar, { length: steps.length, currentIndex: showStart ? -1 : current }), showStart ? (_jsx(StartScreen, { course: course, onChoose: chooseLanguage })) : !step ? (_jsx("div", { className: "ob-course-player__empty", children: _jsx(Alert, { "data-color": "info", children: getLocalizedString("This course has no content yet.") }) })) : (_jsxs(_Fragment, { children: [_jsx("section", { className: "ob-course-step", ref: setStage, tabIndex: -1, "aria-label": localize `Step ${current + 1} of ${steps.length}`, onMouseDown: onSwipeMouseDown, children: _jsx(StepFrame, { category: step.category, branding: branding, children: _jsx(StepBody, { step: step.document, slideId: step.slideId, mode: mode, resolveAsset: resolveAsset, quiz: quiz, stepsShown: stepsShown, subtitles: subtitles, onSubtitlesChange: setSubtitles, onDoneChange: setDone, onMediaEnded: onMediaEnded, onRevealNavigation: onRevealNavigation }, `${step.slideId}:${course.cultureId ?? ""}`) }) }), _jsx(PlayerControls, { size: chromeSize, position: current + 1, count: steps.length, message: message, hint: hint, backDisabled: busy || (current === 0 && (reveals ? reveals.previous === null : stepsShown === 0)), nextDisabled: busy || completed || (!pendingReveal && !canLeave), busy: busy, nextLabel: nextLabel, nextArrow: !(isLast && !pendingReveal), onBack: back, onNext: next })] }))] }));
213
214
  }
@@ -0,0 +1,32 @@
1
+ import type { ReactNode } from "react";
2
+ export declare function PlayerHeader({ title, size, fullScreenLabel, onFullScreen, children, end, inert, }: {
3
+ title: string;
4
+ /** Drawn but not operable, and hidden from screen readers: a preview's sample. */
5
+ inert?: boolean;
6
+ /** `sm` on a phone on its side, to leave the step the height. */
7
+ size?: "sm";
8
+ fullScreenLabel: string;
9
+ onFullScreen?(): void;
10
+ /** Buttons between the title and the full screen button, such as the language menu. */
11
+ children?: ReactNode;
12
+ /** After the full screen button, such as closing the course. */
13
+ end?: ReactNode;
14
+ }): import("react").JSX.Element;
15
+ export declare function PlayerControls({ size, position, count, message, hint, backDisabled, nextDisabled, busy, nextLabel, nextArrow, onBack, onNext, inert, }: {
16
+ size?: "sm";
17
+ /** Drawn but not operable, and hidden from screen readers: a preview's sample. */
18
+ inert?: boolean;
19
+ /** The step shown, from 1. */
20
+ position: number;
21
+ count: number;
22
+ message?: string | null;
23
+ hint?: string | null;
24
+ backDisabled?: boolean;
25
+ nextDisabled?: boolean;
26
+ busy?: boolean;
27
+ nextLabel: string;
28
+ /** The arrow on Next; left out on Complete. */
29
+ nextArrow: boolean;
30
+ onBack?(): void;
31
+ onNext?(): void;
32
+ }): import("react").JSX.Element;
@@ -0,0 +1,14 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Button } from "@digdir/designsystemet-react";
3
+ import { getLocalizedString } from "../i18n";
4
+ import { ArrowLeftIcon, ArrowRightIcon, FullscreenIcon } from "../media/icons";
5
+ /*
6
+ * The player's header and buttons, apart from the player, so an editor's preview draws the same
7
+ * bars around a step as the learner gets, and the step is left exactly the room it has there.
8
+ */
9
+ export function PlayerHeader({ title, size, fullScreenLabel, onFullScreen, children, end, inert, }) {
10
+ return (_jsxs("header", { className: "ob-course-player__header", "data-size": size, inert: inert, "aria-hidden": inert || undefined, children: [_jsx("p", { className: "ob-course-player__title", children: title }), children, _jsx(Button, { variant: "tertiary", "data-size": "sm", icon: true, onClick: onFullScreen, "aria-label": fullScreenLabel, title: fullScreenLabel, children: _jsx(FullscreenIcon, {}) }), end] }));
11
+ }
12
+ export function PlayerControls({ size, position, count, message, hint, backDisabled, nextDisabled, busy, nextLabel, nextArrow, onBack, onNext, inert, }) {
13
+ return (_jsxs("footer", { className: "ob-course-player__controls", "data-size": size, inert: inert, "aria-hidden": inert || undefined, children: [_jsxs(Button, { variant: "secondary", onClick: onBack, disabled: backDisabled, "aria-label": getLocalizedString("Back"), children: [_jsx(ArrowLeftIcon, {}), _jsx("span", { className: "ob-course-player__button-text", children: getLocalizedString("Back") })] }), _jsxs("div", { className: "ob-course-player__status", children: [_jsxs("span", { className: "ob-course-player__count", children: [position, " / ", count] }), _jsxs("span", { className: "ob-course-player__note", children: [_jsx("span", { role: "status", className: "ob-course-player__message", children: message }), hint && _jsx("span", { className: "ob-course-player__hint", children: hint })] })] }), _jsxs(Button, { onClick: onNext, loading: busy, disabled: nextDisabled, "aria-label": nextLabel, children: [_jsx("span", { className: "ob-course-player__button-text", children: nextLabel }), nextArrow && _jsx(ArrowRightIcon, {})] })] }));
14
+ }
@@ -1,7 +1,7 @@
1
1
  import type React from "react";
2
2
  import { type RevealState } from "../document/cues";
3
3
  import type { PartEffect } from "../document/effects";
4
- import type { Block, ContentBlock, ListItem, Timed } from "../document/schema";
4
+ import type { Block, BoxContentBlock, ContentBlock, ListItem, Timed } from "../document/schema";
5
5
  import type { ResolveAsset } from "../types";
6
6
  export interface BlocksContext {
7
7
  reveal: RevealState;
@@ -12,10 +12,31 @@ export interface BlocksContext {
12
12
  effects?: ReadonlyMap<string, PartEffect>;
13
13
  /** The learner prefers reduced motion: parts change at once. */
14
14
  calm?: boolean;
15
+ /** For an editor: every part is drawn whatever its timing, marked `is-unrevealed` when it would wait. */
16
+ revealAll?: boolean;
17
+ /** For an editor: drawn at each place a block can be added, before every shown block and at the end. */
18
+ renderInsert?(place: InsertPlace): React.ReactNode;
15
19
  }
16
- export declare function Blocks({ blocks, context }: {
17
- blocks: Array<Block | ContentBlock>;
20
+ /** Where blocks stand: on the slide, in a column or in a box. */
21
+ export type InsertContainer = {
22
+ kind: "slide";
23
+ } | {
24
+ kind: "column";
25
+ id: string;
26
+ } | {
27
+ kind: "box";
28
+ id: string;
29
+ };
30
+ /** A place a block can be added: in a container, before the block at `index` (or at the end). */
31
+ export type InsertPlace = {
32
+ container: InsertContainer;
33
+ index: number;
34
+ };
35
+ export declare function Blocks({ blocks, context, container, }: {
36
+ blocks: Array<Block | ContentBlock | BoxContentBlock>;
18
37
  context: BlocksContext;
38
+ /** Where the blocks stand, for an editor's places to add one. */
39
+ container?: InsertContainer;
19
40
  }): React.JSX.Element;
20
41
  type Visibility = "shown" | "pending" | "gone";
21
42
  /**
@@ -1,7 +1,7 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Button, Dialog } from "@digdir/designsystemet-react";
3
3
  import clsx from "clsx";
4
- import { useState } from "react";
4
+ import { Fragment, useState } from "react";
5
5
  import { isVisible } from "../document/cues";
6
6
  import { getLocalizedString } from "../i18n";
7
7
  import { PlayIcon } from "../media/icons";
@@ -9,8 +9,9 @@ import { VideoPlayer } from "../media/VideoPlayer";
9
9
  import { Markdown } from "./Markdown";
10
10
  import { aspectRatio, partStyle } from "./motion";
11
11
  import { usePresence } from "./RevealMotion";
12
- export function Blocks({ blocks, context }) {
13
- return (_jsx(_Fragment, { children: blocks.map((block) => (_jsx(BlockView, { block: block, context: context }, block.id))) }));
12
+ export function Blocks({ blocks, context, container, }) {
13
+ let insert = container && context.renderInsert ? context.renderInsert : null;
14
+ return (_jsxs(_Fragment, { children: [blocks.map((block, index) => (_jsxs(Fragment, { children: [insert && container && block.type !== "effect" && (_jsx("div", { className: "ob-course-insert", children: insert({ container, index }) })), _jsx(BlockView, { block: block, context: context })] }, block.id))), insert && container && _jsx("div", { className: "ob-course-insert", children: insert({ container, index: blocks.length }) })] }));
14
15
  }
15
16
  /**
16
17
  * A part that has not been revealed yet keeps its place, so the slide does not jump when it
@@ -25,12 +26,16 @@ export function getVisibility(part, reveal) {
25
26
  function lookClasses(block) {
26
27
  return clsx(block.caps && "ob-course-look--caps", block.shadow && "ob-course-look--shadow");
27
28
  }
29
+ /** A callout and a box share one surface, coloured by `data-color` and drawn by its variant. */
30
+ function surfaceClasses(className, block) {
31
+ return clsx(className, "ob-course-surface", `ob-course-surface--${block.variant ?? "bordered"}`);
32
+ }
28
33
  /**
29
34
  * How a part is drawn now, or null when it is not in the page. A part that goes away fades out
30
35
  * first (`leaving`); the slide lifts it out of the flow meanwhile.
31
36
  */
32
37
  function usePart(part, context) {
33
- let visibility = getVisibility(part, context.reveal);
38
+ let visibility = context.revealAll ? "shown" : getVisibility(part, context.reveal);
34
39
  let presence = usePresence(visibility !== "gone", context.calm ?? false);
35
40
  let inPage = presence !== "absent";
36
41
  /*
@@ -53,7 +58,7 @@ function usePart(part, context) {
53
58
  function partProps(part, shown, className, context, canvasAspect) {
54
59
  let hidden = shown.state !== "shown";
55
60
  return {
56
- className: clsx(className, shown.state === "pending" && "is-pending", shown.state === "leaving" && "is-leaving", shown.entering && "is-entering"),
61
+ className: clsx(className, shown.state === "pending" && "is-pending", shown.state === "leaving" && "is-leaving", shown.entering && "is-entering", context.revealAll && !isVisible(part, context.reveal) && "is-unrevealed"),
57
62
  "data-part": part.id,
58
63
  "aria-hidden": hidden || undefined,
59
64
  inert: hidden || undefined,
@@ -82,13 +87,15 @@ function BlockView({ block, context }) {
82
87
  case "quote":
83
88
  return (_jsxs("figure", { ...props, children: [_jsx("blockquote", { children: _jsx(Markdown, { children: block.text }) }), block.cite && _jsx("figcaption", { children: block.cite })] }));
84
89
  case "callout":
85
- return (_jsx("div", { ...props, "data-color": block.tone ?? "neutral", children: _jsx(Markdown, { children: block.text }) }));
90
+ return (_jsx("div", { ...props, className: surfaceClasses(props.className, block), "data-color": block.tone ?? "neutral", children: _jsx(Markdown, { children: block.text }) }));
91
+ case "box":
92
+ return (_jsx("div", { ...props, className: surfaceClasses(props.className, block), "data-color": block.tone ?? "neutral", children: _jsx(Blocks, { blocks: block.blocks, context: context, container: { kind: "box", id: block.id } }) }));
86
93
  case "video-link":
87
94
  return (_jsx("div", { ...props, children: _jsx(VideoLink, { block: block, context: context }) }));
88
95
  case "canvas":
89
96
  return (_jsx("div", { ...props, children: _jsx("div", { className: "ob-course-canvas", "data-color-scheme": "light", style: { aspectRatio: block.aspect ?? "16 / 9" }, children: block.items.map((item) => (_jsx(CanvasItemView, { item: item, aspect: aspectRatio(block.aspect), context: context }, item.id))) }) }));
90
97
  case "columns":
91
- return (_jsx("div", { ...props, children: block.columns.map((column) => (_jsx("div", { className: "ob-course-column", "data-part": column.id, style: partStyle({ effect: context.effects?.get(column.id), state: "shown" }), children: _jsx(Blocks, { blocks: column.blocks, context: context }) }, column.id))) }));
98
+ return (_jsx("div", { ...props, children: block.columns.map((column) => (_jsx("div", { className: "ob-course-column", "data-part": column.id, style: partStyle({ effect: context.effects?.get(column.id), state: "shown" }), children: _jsx(Blocks, { blocks: column.blocks, context: context, container: { kind: "column", id: column.id } }) }, column.id))) }));
92
99
  }
93
100
  }
94
101
  /** The flat items as a tree: an indented item belongs to the nearest item above it with a smaller indent. */
@@ -6,7 +6,7 @@ const MARKDOWN_TAGS = new Set("p strong em del a ul ol li blockquote code pre br
6
6
  /** The tags a text may use for what Markdown has no syntax for. They take no attributes. */
7
7
  export const TEXT_TAGS = new Set(["big", "small", "u", "sup", "sub", "mark"]);
8
8
  /** The colours a `<span data-color>` may name; they come from the theme. */
9
- export const TEXT_TONES = new Set(["info", "success", "warning", "danger"]);
9
+ export const TEXT_TONES = new Set(["info", "success", "warning", "danger", "brand"]);
10
10
  const OPTIONS = {
11
11
  forceBlock: true,
12
12
  // A single paragraph is otherwise returned bare, without the element that carries the class
@@ -4,7 +4,8 @@ import type { StepBodyProps } from "./StepBodyProps";
4
4
  import "./QuizStepView.css";
5
5
  /**
6
6
  * A quiz, one question at a time with feedback after each answer, graded by the server.
7
- * Done when an attempt has passed.
7
+ * Done when an attempt has passed. With `retryUntilCorrect` a wrong answer only says so and the
8
+ * learner answers the same question again; the next question comes after the right answer.
8
9
  */
9
10
  export declare function QuizStepView({ step, slideId, quiz, mode, resolveAsset, subtitles, onSubtitlesChange, onDoneChange, }: StepBodyProps & {
10
11
  step: QuizStep;
@@ -8,7 +8,8 @@ import { Markdown } from "./Markdown";
8
8
  import "./QuizStepView.css";
9
9
  /**
10
10
  * A quiz, one question at a time with feedback after each answer, graded by the server.
11
- * Done when an attempt has passed.
11
+ * Done when an attempt has passed. With `retryUntilCorrect` a wrong answer only says so and the
12
+ * learner answers the same question again; the next question comes after the right answer.
12
13
  */
13
14
  export function QuizStepView({ step, slideId, quiz, mode, resolveAsset, subtitles, onSubtitlesChange, onDoneChange, }) {
14
15
  let [phase, setPhase] = useState({ name: "intro" });
@@ -76,11 +77,23 @@ export function QuizStepView({ step, slideId, quiz, mode, resolveAsset, subtitle
76
77
  let question = attempt.questions[index];
77
78
  let nextIndex = attempt.questions.findIndex((candidate, at) => at > index && !candidate.answered);
78
79
  let isLast = nextIndex === -1;
79
- let answered = feedback != null;
80
+ let retry = attempt.retryUntilCorrect === true;
81
+ // A wrong answer in a retry quiz leaves the question open for another answer.
82
+ let answered = feedback != null && (feedback.correct || !retry);
83
+ let tryAgain = feedback != null && !answered;
80
84
  let inputName = `ob-course-quiz-${slideId}-${question.questionId}`;
81
85
  let answer = () => run(async () => {
82
86
  setFeedback(await quiz.answer(slideId, attempt.attemptId, question.questionId, selected));
83
87
  });
88
+ let toggle = (optionId, checked) => {
89
+ // Changing the answer after "try again" clears the old verdict, so it is not read as being about the new choice.
90
+ if (tryAgain)
91
+ setFeedback(null);
92
+ if (!question.multiple)
93
+ setSelected([optionId]);
94
+ else
95
+ setSelected((current) => (checked ? [...current, optionId] : current.filter((id) => id !== optionId)));
96
+ };
84
97
  let next = () => {
85
98
  if (!isLast) {
86
99
  setSelected([]);
@@ -93,12 +106,6 @@ export function QuizStepView({ step, slideId, quiz, mode, resolveAsset, subtitle
93
106
  setPhase({ name: "result", attempt, result });
94
107
  });
95
108
  };
96
- let toggle = (optionId, checked) => {
97
- if (!question.multiple)
98
- setSelected([optionId]);
99
- else
100
- setSelected((current) => (checked ? [...current, optionId] : current.filter((id) => id !== optionId)));
101
- };
102
109
  return (_jsxs("div", { className: "ob-course-form-step ob-course-quiz", children: [_jsx(Paragraph, { "data-size": "sm", className: "ob-course-hint", children: localize `Question ${index + 1} of ${attempt.questions.length}` }), _jsxs(Fieldset, { disabled: answered || busy, children: [_jsx(Fieldset.Legend, { children: _jsx(Heading, { level: 2, "data-size": "sm", ref: focusRef, tabIndex: -1, className: "ob-course-quiz__question", children: question.text }) }), question.multiple && (_jsx(Fieldset.Description, { children: getLocalizedString("Choose every answer that is right.") })), question.options.map((option) => {
103
110
  let props = {
104
111
  label: option.text,
@@ -108,10 +115,13 @@ export function QuizStepView({ step, slideId, quiz, mode, resolveAsset, subtitle
108
115
  onChange: (event) => toggle(option.optionId, event.currentTarget.checked),
109
116
  };
110
117
  return question.multiple ? (_jsx(Checkbox, { ...props }, option.optionId)) : (_jsx(Radio, { ...props }, option.optionId));
111
- })] }), feedback && (_jsxs(Alert, { "data-color": feedback.correct ? "success" : "danger", className: "ob-course-quiz__feedback", children: [_jsx(Heading, { level: 3, "data-size": "2xs", children: feedback.correct ? getLocalizedString("Correct") : getLocalizedString("Not correct") }), feedback.explanation && _jsx(Markdown, { children: feedback.explanation })] })), error, _jsx("div", { children: answered ? (_jsx(Button, { onClick: next, loading: busy, disabled: busy, children: isLast ? getLocalizedString("See the result") : getLocalizedString("Next question") })) : (_jsx(Button, { onClick: answer, loading: busy, disabled: busy || selected.length === 0, children: getLocalizedString("Answer") })) })] }));
118
+ })] }), tryAgain ? (_jsx(Alert, { "data-color": "danger", className: "ob-course-quiz__feedback", children: _jsx(Heading, { level: 3, "data-size": "2xs", children: getLocalizedString("Not correct. Try again.") }) })) : (feedback && (_jsxs(Alert, { "data-color": feedback.correct ? "success" : "danger", className: "ob-course-quiz__feedback", children: [_jsx(Heading, { level: 3, "data-size": "2xs", children: feedback.correct ? getLocalizedString("Correct") : getLocalizedString("Not correct") }), feedback.explanation && _jsx(Markdown, { children: feedback.explanation })] }))), error, _jsx("div", { children: answered ? (_jsx(Button, { onClick: next, loading: busy, disabled: busy, children: isLast ? getLocalizedString("See the result") : getLocalizedString("Next question") })) : (_jsx(Button, { onClick: answer, loading: busy, disabled: busy || selected.length === 0, children: getLocalizedString("Answer") })) })] }));
112
119
  }
113
120
  let { result } = phase;
114
- return (_jsxs("div", { className: "ob-course-form-step ob-course-quiz", children: [step.heading && _jsx(Paragraph, { className: "ob-course-hint", children: step.heading }), _jsx(Heading, { level: 2, "data-size": "md", ref: focusRef, tabIndex: -1, children: passed ? getLocalizedString("You passed the quiz") : getLocalizedString("You did not pass the quiz") }), result ? (_jsxs(_Fragment, { children: [_jsx(Paragraph, { className: "ob-course-quiz__score", children: localize `You answered ${result.correctCount} of ${result.questionCount} questions correctly (${Math.round(result.percent)} %).` }), _jsx(Paragraph, { children: result.passPercent == null
121
+ let retryResult = result != null && (result.retryUntilCorrect ?? phase.attempt.retryUntilCorrect) === true;
122
+ return (_jsxs("div", { className: "ob-course-form-step ob-course-quiz", children: [step.heading && _jsx(Paragraph, { className: "ob-course-hint", children: step.heading }), _jsx(Heading, { level: 2, "data-size": "md", ref: focusRef, tabIndex: -1, children: passed ? getLocalizedString("You passed the quiz") : getLocalizedString("You did not pass the quiz") }), retryResult ? (_jsx(Paragraph, { children: passed
123
+ ? getLocalizedString("You answered every question correctly.")
124
+ : getLocalizedString("Answer every question correctly to pass.") })) : result ? (_jsxs(_Fragment, { children: [_jsx(Paragraph, { className: "ob-course-quiz__score", children: localize `You answered ${result.correctCount} of ${result.questionCount} questions correctly (${Math.round(result.percent)} %).` }), _jsx(Paragraph, { children: result.passPercent == null
115
125
  ? getLocalizedString("Every answer must be correct to pass.")
116
126
  : localize `You need ${result.passPercent} % correct answers to pass.` }), result.missedRequired.length > 0 && (_jsx(Alert, { "data-color": "warning", children: result.missedRequired.length === 1
117
127
  ? getLocalizedString("One of the questions that must be answered correctly was wrong.")
@@ -6,6 +6,6 @@ import type { StepBodyProps } from "./StepBodyProps";
6
6
  * steps. Without, Next shows the parts that wait for it, and the slide is done when no press would
7
7
  * show anything more. The slide reports where Next and Back go with `onRevealNavigation`.
8
8
  */
9
- export declare function SlideStepView({ step, mode, resolveAsset, stepsShown, subtitles, onSubtitlesChange, onDoneChange, onMediaEnded, onRevealNavigation, }: StepBodyProps & {
9
+ export declare function SlideStepView({ step, mode, resolveAsset, stepsShown, subtitles, onSubtitlesChange, onDoneChange, onMediaEnded, onRevealNavigation, revealAll, renderInsert, }: StepBodyProps & {
10
10
  step: SlideStep;
11
11
  }): import("react").JSX.Element;
@@ -13,7 +13,7 @@ import { prefersCalm, RevealMotion } from "./RevealMotion";
13
13
  * steps. Without, Next shows the parts that wait for it, and the slide is done when no press would
14
14
  * show anything more. The slide reports where Next and Back go with `onRevealNavigation`.
15
15
  */
16
- export function SlideStepView({ step, mode, resolveAsset, stepsShown, subtitles, onSubtitlesChange, onDoneChange, onMediaEnded, onRevealNavigation, }) {
16
+ export function SlideStepView({ step, mode, resolveAsset, stepsShown, subtitles, onSubtitlesChange, onDoneChange, onMediaEnded, onRevealNavigation, revealAll = false, renderInsert, }) {
17
17
  let narration = step.narration;
18
18
  // On a narrated slide only the narration shows and hides parts; Next goes to the next step
19
19
  let narrated = narration != null;
@@ -49,17 +49,27 @@ export function SlideStepView({ step, mode, resolveAsset, stepsShown, subtitles,
49
49
  let [effectsSeen, setEffectsSeen] = useState({ key: activeKey, active, previous: active });
50
50
  if (effectsSeen.key !== activeKey)
51
51
  setEffectsSeen({ key: activeKey, active, previous: effectsSeen.active });
52
- let effects = getPartEffects(step.blocks, reveal, effectsSeen.previous);
52
+ // An editor that draws every part shows them where they are laid out, not moved by an effect
53
+ let effects = revealAll ? undefined : getPartEffects(step.blocks, reveal, effectsSeen.previous);
53
54
  let calm = prefersCalm();
54
55
  let signature = getTimedParts(step.blocks)
55
56
  .map((part) => `${part.id}:${getVisibility(part, reveal)}`)
56
57
  .join("|");
57
- let context = { reveal, resolveAsset, subtitles, onSubtitlesChange, effects, calm };
58
+ let context = {
59
+ reveal,
60
+ resolveAsset,
61
+ subtitles,
62
+ onSubtitlesChange,
63
+ effects,
64
+ calm,
65
+ revealAll,
66
+ renderInsert,
67
+ };
58
68
  let background = step.background ? resolveAsset(step.background) : undefined;
59
69
  // A banner shows the image as a band of its own instead of behind the whole slide
60
70
  let banner = step.layout === "banner" && background ? background : undefined;
61
71
  if (banner)
62
72
  background = undefined;
63
- let content = (_jsx("div", { className: "ob-course-slide__content", children: _jsx(Blocks, { blocks: step.blocks, context: context }) }));
73
+ let content = (_jsx("div", { className: "ob-course-slide__content", children: _jsx(Blocks, { blocks: step.blocks, context: context, container: { kind: "slide" } }) }));
64
74
  return (_jsxs("div", { ref: rootRef, className: clsx("ob-course-slide", `ob-course-slide--${step.layout ?? "default"}`, step.width && `ob-course-slide--${step.width}`, background && "ob-course-slide--background", background && step.panel === false && "ob-course-slide--bare"), children: [_jsx(RevealMotion, { root: rootRef, signature: signature, source: step.blocks, calm: calm }), background && (_jsx("div", { className: "ob-course-slide__background", style: { backgroundImage: `url("${background}")` } })), banner ? (_jsx("div", { className: "ob-course-banner", children: _jsxs("div", { className: "ob-course-banner__stage", children: [_jsx("img", { className: "ob-course-banner__image", src: banner, alt: "" }), content] }) })) : (content), narration && (_jsx(NarrationPlayer, { className: "ob-course-slide__narration", narration: narration, clock: state.clock, setAudio: state.setAudio, resolveAsset: resolveAsset, subtitles: subtitles, onSubtitlesChange: onSubtitlesChange })), _jsx(Subtitles, { cue: subtitles ? clock.activeCue : undefined })] }));
65
75
  }
@@ -1,4 +1,6 @@
1
+ import type { ReactNode } from "react";
1
2
  import type { RevealNavigation } from "../document/cues";
3
+ import type { InsertPlace } from "./Blocks";
2
4
  import type { PlayerMode, QuizAdapter, ResolveAsset } from "../types";
3
5
  /** What the player hands every step type. */
4
6
  export interface StepBodyProps {
@@ -19,4 +21,11 @@ export interface StepBodyProps {
19
21
  onMediaEnded?(): void;
20
22
  /** A slide reports where Next and Back go from here, and the presses that show something. */
21
23
  onRevealNavigation?(navigation: RevealNavigation): void;
24
+ /**
25
+ * For an editor: every part of a slide is drawn, whatever its timing, so each can be reached,
26
+ * and the effects are left off. A part that would not be shown yet carries `is-unrevealed`.
27
+ */
28
+ revealAll?: boolean;
29
+ /** For an editor: a node drawn at each place on a slide where a block can be added. */
30
+ renderInsert?(place: InsertPlace): ReactNode;
22
31
  }