@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
@@ -38,6 +38,14 @@
38
38
 
39
39
  /* Blocks */
40
40
 
41
+ /*
42
+ * An editor's place to add a block (`renderInsert`): the node it draws is laid out as a block would
43
+ * be. The rules for a slide's first heading skip it, so a title looks the same while it is edited.
44
+ */
45
+ .ob-course-insert {
46
+ display: contents;
47
+ }
48
+
41
49
  .ob-course-slide {
42
50
  flex: 1;
43
51
  display: flex;
@@ -116,7 +124,7 @@
116
124
  }
117
125
 
118
126
  /* The first heading is the title whatever its level, in the company's colour. */
119
- .ob-course-slide__content > .ob-course-block--heading:first-child {
127
+ .ob-course-slide__content > .ob-course-block--heading:nth-child(1 of :not(.ob-course-insert)) {
120
128
  font-size: clamp(2em, 1.2em + 4cqi, 3.6em);
121
129
  color: var(--ds-color-brand-text-default);
122
130
  }
@@ -148,7 +156,7 @@
148
156
  box-shadow: none;
149
157
  text-shadow: 0 2px 12px rgb(0 0 0 / 0.6);
150
158
 
151
- > .ob-course-block--heading:first-child {
159
+ > .ob-course-block--heading:nth-child(1 of :not(.ob-course-insert)) {
152
160
  color: inherit;
153
161
  }
154
162
  }
@@ -212,7 +220,7 @@
212
220
  text-align: center;
213
221
  text-shadow: 0.05em 0.05em rgb(0 0 0 / 0.5);
214
222
 
215
- > .ob-course-block--heading:first-child {
223
+ > .ob-course-block--heading:nth-child(1 of :not(.ob-course-insert)) {
216
224
  font-size: clamp(2em, 1.2em + 4cqi, 3.6em);
217
225
  }
218
226
 
@@ -284,6 +292,7 @@
284
292
  .ob-course-block--list,
285
293
  .ob-course-block--quote,
286
294
  .ob-course-block--callout,
295
+ .ob-course-block--box,
287
296
  .ob-course-block--video-link,
288
297
  .ob-course-list-item
289
298
  ) {
@@ -297,6 +306,7 @@
297
306
  .ob-course-block--list,
298
307
  .ob-course-block--quote,
299
308
  .ob-course-block--callout,
309
+ .ob-course-block--box,
300
310
  .ob-course-block--video-link,
301
311
  .ob-course-list-item
302
312
  ) {
@@ -463,8 +473,11 @@
463
473
  object-fit: contain;
464
474
  }
465
475
 
466
- /* `data-color` picks the Designsystemet colour scale the tokens below resolve to. */
467
- .ob-course-block--callout {
476
+ /*
477
+ * A callout or a box. `data-color` picks the Designsystemet colour scale the tokens below resolve
478
+ * to; every theme maps `brand` to its own scale the way it maps the severity colours.
479
+ */
480
+ .ob-course-surface {
468
481
  padding: 0.9em 1.1em;
469
482
  border: var(--ds-border-width-default, 1px) solid var(--ds-color-border-subtle);
470
483
  border-inline-start: 0.35em solid var(--ds-color-base-default);
@@ -478,6 +491,51 @@
478
491
  }
479
492
  }
480
493
 
494
+ /*
495
+ * The tone's base colour with its contrast colour on it, the pair the theme guarantees can be read.
496
+ * What has a colour of its own inside takes the contrast colour instead, since its own would vanish
497
+ * on a surface of the same scale.
498
+ */
499
+ .ob-course-surface--filled {
500
+ border-color: var(--ds-color-base-default);
501
+ background: var(--ds-color-base-default);
502
+ color: var(--ds-color-base-contrast-default);
503
+ /* A title page's shadow is for words on a picture, not on a solid colour */
504
+ text-shadow: none;
505
+
506
+ .ob-course-tone {
507
+ color: inherit;
508
+ font-weight: 600;
509
+ }
510
+
511
+ .ob-course-block--quote blockquote {
512
+ border-inline-start-color: currentColor;
513
+ }
514
+
515
+ figcaption,
516
+ .ob-course-block--quote figcaption,
517
+ .ob-course-block--image figcaption {
518
+ color: var(--ds-color-base-contrast-subtle);
519
+ }
520
+
521
+ /* The video link's outlined button would be the surface's colour on itself */
522
+ .ob-course-block--video-link .ds-button {
523
+ --dsc-button-background: var(--ds-color-surface-default);
524
+ --dsc-button-background--hover: var(--ds-color-surface-hover);
525
+ --dsc-button-background--active: var(--ds-color-surface-active);
526
+ --dsc-button-border-color: transparent;
527
+ --dsc-button-color: var(--ds-color-text-default);
528
+ }
529
+ }
530
+
531
+ /* The parts of a box stand like the parts of a column, and reveal the same way. */
532
+ .ob-course-block--box {
533
+ display: flex;
534
+ flex-direction: column;
535
+ gap: 0.9em;
536
+ min-width: 0;
537
+ }
538
+
481
539
  .ob-course-block--quote {
482
540
  blockquote {
483
541
  margin: 0;
@@ -677,8 +735,8 @@
677
735
  gap: 0.6em;
678
736
  }
679
737
 
680
- .ob-course-slide--title .ob-course-slide__content > .ob-course-block--heading:first-child,
681
- .ob-course-banner .ob-course-slide__content > .ob-course-block--heading:first-child {
738
+ .ob-course-slide--title .ob-course-slide__content > .ob-course-block--heading:nth-child(1 of :not(.ob-course-insert)),
739
+ .ob-course-banner .ob-course-slide__content > .ob-course-block--heading:nth-child(1 of :not(.ob-course-insert)) {
682
740
  font-size: clamp(1.5em, 1em + 3cqi, 2.4em);
683
741
  }
684
742
 
@@ -1,9 +1,10 @@
1
1
  import { type ReactNode } from "react";
2
2
  import type { RevealNavigation } from "../document/cues";
3
3
  import type { Step } from "../document/schema";
4
- import type { PlayerBranding, PlayerCategory, PlayerMode, QuizAdapter, ResolveAsset } from "../types";
4
+ import type { PlayerBranding, PlayerCategory, PlayerLanguage, PlayerMode, QuizAdapter, ResolveAsset } from "../types";
5
5
  import type { StepBodyProps } from "./StepBodyProps";
6
6
  import "./StepView.css";
7
+ import "../player/CoursePlayer.css";
7
8
  /** Picks the view for a step's type. A missing document is shown as not available, and counts as done. */
8
9
  export declare function StepBody({ step, ...props }: StepBodyProps & {
9
10
  step: Step | null;
@@ -39,6 +40,31 @@ export interface StepViewProps {
39
40
  * four product logos; given without a logo, the company's name.
40
41
  */
41
42
  branding?: PlayerBranding | null;
43
+ /**
44
+ * For an editor: draws every part of a slide whatever its timing, without effects, and marks the
45
+ * parts that would not be shown yet with `is-unrevealed`. Off (the default) it is the player.
46
+ */
47
+ revealAll?: boolean;
48
+ /** For an editor: a node drawn at each place on a slide where a block can be added. */
49
+ renderInsert?: StepBodyProps["renderInsert"];
50
+ /**
51
+ * For an editor: the player's header, progress bar and buttons around the step, as a learner has
52
+ * them, so the step gets the room it has in the player. They are drawn but cannot be used.
53
+ */
54
+ courseChrome?: SampleChrome | null;
55
+ }
56
+ /** What the player's chrome shows around a previewed step. */
57
+ export interface SampleChrome {
58
+ /** The course's title, in the header. */
59
+ title: string;
60
+ /** The step's place in the course, from 1. */
61
+ position: number;
62
+ count: number;
63
+ /** The course's languages: the header has the language menu when there are several. */
64
+ languages?: PlayerLanguage[];
65
+ cultureId?: string | null;
66
+ /** The slim chrome of a phone on its side. */
67
+ compact?: boolean;
42
68
  }
43
- /** One step on its own, without the course chrome: for previewing a step while it is edited. */
44
- export declare function StepView({ step, resolveAsset, mode, quiz, slideId, stepsShown, category, branding, onRevealNavigation, }: StepViewProps): import("react").JSX.Element;
69
+ /** One step on its own, for previewing a step while it is edited, with or without the player's chrome. */
70
+ export declare function StepView({ step, resolveAsset, mode, quiz, slideId, stepsShown, category, branding, onRevealNavigation, revealAll, renderInsert, courseChrome, }: StepViewProps): import("react").JSX.Element;
@@ -1,13 +1,19 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Alert } from "@digdir/designsystemet-react";
2
+ import { Alert, Button } from "@digdir/designsystemet-react";
3
+ import clsx from "clsx";
3
4
  import { useLayoutEffect, useState } from "react";
4
5
  import { CategoryHeader } from "../chrome/CategoryHeader";
5
- import { getLocalizedString } from "../i18n";
6
+ import { ProgressBar } from "../chrome/ProgressBar";
7
+ import { getLocalizedString, localize } from "../i18n";
8
+ import { CloseIcon } from "../media/icons";
9
+ import { LanguageMenu } from "../player/LanguageMenu";
10
+ import { PlayerControls, PlayerHeader } from "../player/PlayerBars";
6
11
  import { PdfStepView } from "./PdfStepView";
7
12
  import { QuizStepView } from "./QuizStepView";
8
13
  import { SlideStepView } from "./SlideStepView";
9
14
  import { VideoStepView } from "./VideoStepView";
10
15
  import "./StepView.css";
16
+ import "../player/CoursePlayer.css";
11
17
  /** Picks the view for a step's type. A missing document is shown as not available, and counts as done. */
12
18
  export function StepBody({ step, ...props }) {
13
19
  if (!step)
@@ -36,9 +42,19 @@ function MissingStep({ onDoneChange }) {
36
42
  export function StepFrame({ category, branding, children, }) {
37
43
  return (_jsxs(_Fragment, { children: [category && _jsx(CategoryHeader, { ...category, branding: branding }), _jsx("div", { className: "ob-course-step__body", children: children })] }));
38
44
  }
39
- /** One step on its own, without the course chrome: for previewing a step while it is edited. */
40
- export function StepView({ step, resolveAsset, mode = "preview", quiz, slideId = 0, stepsShown, category, branding, onRevealNavigation, }) {
45
+ /** One step on its own, for previewing a step while it is edited, with or without the player's chrome. */
46
+ export function StepView({ step, resolveAsset, mode = "preview", quiz, slideId = 0, stepsShown, category, branding, onRevealNavigation, revealAll, renderInsert, courseChrome, }) {
41
47
  let [subtitles, setSubtitles] = useState(true);
42
- return (_jsx("div", { className: "ob-course-step ob-course-step--standalone", children: _jsx(StepFrame, { category: category, branding: branding, children: _jsx(StepBody, { step: step, slideId: slideId, mode: mode, resolveAsset: resolveAsset, quiz: quiz, stepsShown: stepsShown ?? Number.POSITIVE_INFINITY, subtitles: subtitles, onSubtitlesChange: setSubtitles, onDoneChange: ignore, onRevealNavigation: onRevealNavigation }) }) }));
48
+ let frame = (_jsx(StepFrame, { category: category, branding: branding, children: _jsx(StepBody, { step: step, slideId: slideId, mode: mode, resolveAsset: resolveAsset, quiz: quiz, stepsShown: stepsShown ?? Number.POSITIVE_INFINITY, subtitles: subtitles, onSubtitlesChange: setSubtitles, onDoneChange: ignore, onRevealNavigation: onRevealNavigation, revealAll: revealAll, renderInsert: renderInsert }) }));
49
+ if (!courseChrome)
50
+ return _jsx("div", { className: "ob-course-step ob-course-step--standalone", children: frame });
51
+ return _jsx(SampleChromeView, { chrome: courseChrome, children: frame });
52
+ }
53
+ /** The player's own bars around a step, inert: a tester sees them but cannot move through the course. */
54
+ function SampleChromeView({ chrome, children }) {
55
+ let { title, position, count, languages = [], cultureId = null, compact = false } = chrome;
56
+ let size = compact ? "sm" : undefined;
57
+ let last = position >= count;
58
+ return (_jsxs("div", { className: clsx("ob-course-player", compact && "is-compact"), "data-mode": "preview", children: [_jsx(PlayerHeader, { title: title, size: size, fullScreenLabel: getLocalizedString("Full screen"), inert: true, end: _jsx(Button, { variant: "tertiary", "data-size": "sm", icon: true, "aria-label": getLocalizedString("Close the course"), title: getLocalizedString("Close the course"), children: _jsx(CloseIcon, {}) }), children: languages.length > 1 && _jsx(LanguageMenu, { languages: languages, cultureId: cultureId, onChange: ignore }) }), _jsx(ProgressBar, { length: count, currentIndex: position - 1 }), _jsx("section", { className: "ob-course-step", "aria-label": localize `Step ${position} of ${count}`, children: children }), _jsx(PlayerControls, { size: size, position: position, count: count, backDisabled: position <= 1, nextLabel: last ? getLocalizedString("Complete") : getLocalizedString("Next"), nextArrow: !last, inert: true })] }));
43
59
  }
44
60
  function ignore() { }
package/es/types.d.ts CHANGED
@@ -64,7 +64,10 @@ export interface QuizQuestion {
64
64
  text: string;
65
65
  /** Several options may be right: shown as checkboxes instead of radio buttons. */
66
66
  multiple: boolean;
67
- /** Already answered in this attempt. Set when an open attempt is resumed; the quiz continues at the first question without it. */
67
+ /**
68
+ * Already answered in this attempt. Set when an open attempt is resumed; the quiz continues at the first question
69
+ * without it. With `retryUntilCorrect`, only a correct answer counts, so a question last answered wrong is asked again.
70
+ */
68
71
  answered?: boolean;
69
72
  options: QuizOption[];
70
73
  }
@@ -72,13 +75,19 @@ export interface QuizAttempt {
72
75
  attemptId: string;
73
76
  /** Percent of correct answers needed to pass. `null` means every answer must be correct. */
74
77
  passPercent: number | null;
78
+ /**
79
+ * Each question must be answered correctly before the next one: a wrong answer only says so, and the learner
80
+ * answers the same question again. The attempt passes once every question is right; `passPercent` is not used.
81
+ */
82
+ retryUntilCorrect?: boolean;
75
83
  questions: QuizQuestion[];
76
84
  /** The learner has passed this quiz before; the player shows it as passed without asking again. */
77
85
  alreadyPassed?: boolean;
78
86
  }
79
87
  export interface QuizAnswerResult {
80
88
  correct: boolean;
81
- explanation?: string;
89
+ /** Left out after a wrong answer when the quiz has `retryUntilCorrect`; the player then never shows one. */
90
+ explanation?: string | null;
82
91
  }
83
92
  export interface QuizResult {
84
93
  passed: boolean;
@@ -86,6 +95,8 @@ export interface QuizResult {
86
95
  correctCount: number;
87
96
  questionCount: number;
88
97
  passPercent: number | null;
98
+ /** The quiz had to be answered correctly question by question, so a passed attempt is every question right. */
99
+ retryUntilCorrect?: boolean;
89
100
  /** The ids of the must-be-correct questions that were answered wrong. */
90
101
  missedRequired: string[];
91
102
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@olenbetong/synergi-course",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "description": "Course player: steps described as content, shown responsively",
5
5
  "type": "module",
6
6
  "exports": {
@@ -0,0 +1,234 @@
1
+ import { safeParse } from "valibot";
2
+ import { describe, expect, it } from "vitest";
3
+ import {
4
+ getRevealLeaders,
5
+ getRevealNavigation,
6
+ getRevealSteps,
7
+ getTimedParts,
8
+ isVisible,
9
+ type RevealState,
10
+ } from "./cues";
11
+ import { getEffectBlocks, getPartEffects } from "./effects";
12
+ import { type Block, type BoxBlock, blockSchema, boxBlockSchema, contentBlockSchema, type SlideStep } from "./schema";
13
+ import { validateStep } from "./validate";
14
+
15
+ function issuesOf(input: unknown) {
16
+ let result = validateStep(input);
17
+ return result.ok ? [] : result.issues;
18
+ }
19
+
20
+ function stateOf(blocks: Block[], stepsShown: number, ...cues: string[]): RevealState {
21
+ return {
22
+ stepsShown,
23
+ revealSteps: getRevealSteps(blocks),
24
+ startedCues: new Set(cues),
25
+ leaders: getRevealLeaders(blocks),
26
+ };
27
+ }
28
+
29
+ function shownIds(blocks: Block[], state: RevealState) {
30
+ return getTimedParts(blocks)
31
+ .filter((part) => isVisible(part, state))
32
+ .map((part) => part.id);
33
+ }
34
+
35
+ let steps: Block = {
36
+ id: "box",
37
+ type: "box",
38
+ tone: "brand",
39
+ variant: "filled",
40
+ blocks: [
41
+ { id: "h", type: "heading", text: "Slik gjør du", level: 2 },
42
+ {
43
+ id: "l",
44
+ type: "list",
45
+ ordered: true,
46
+ items: [
47
+ { id: "i1", text: "Ta på hjelm", reveal: "step" },
48
+ { id: "i2", text: "Sjekk stroppen", reveal: "step" },
49
+ ],
50
+ },
51
+ ],
52
+ };
53
+
54
+ let slide = (blocks: Block[], cues?: string[]): SlideStep => ({
55
+ schemaVersion: 2,
56
+ type: "slide",
57
+ ...(cues && { narration: { media: { src: "/media/course/a.m4a" }, cues: cues.map((id, start) => ({ id, start })) } }),
58
+ blocks,
59
+ });
60
+
61
+ describe("the box schema", () => {
62
+ it("accepts a box with a heading and a list, in every tone and variant", () => {
63
+ expect(safeParse(boxBlockSchema, steps).success).toBe(true);
64
+ for (let tone of ["neutral", "info", "success", "warning", "danger", "brand"]) {
65
+ for (let variant of ["bordered", "filled", undefined]) {
66
+ expect(safeParse(blockSchema, { id: "b", type: "box", tone, variant, blocks: [] }).success).toBe(true);
67
+ }
68
+ }
69
+ });
70
+
71
+ it("stands at the top level and in a column", () => {
72
+ expect(issuesOf(slide([steps]))).toEqual([]);
73
+ expect(safeParse(contentBlockSchema, steps).success).toBe(true);
74
+ let inColumn = {
75
+ id: "cols",
76
+ type: "columns",
77
+ columns: [
78
+ { id: "a", blocks: [steps] },
79
+ { id: "b", blocks: [] },
80
+ ],
81
+ };
82
+ expect(issuesOf(slide([inColumn as Block]))).toEqual([]);
83
+ });
84
+
85
+ it("holds no box, callout, columns or canvas", () => {
86
+ let nested = [
87
+ { id: "inner", type: "box", blocks: [] },
88
+ { id: "inner", type: "callout", text: "Nei" },
89
+ {
90
+ id: "inner",
91
+ type: "columns",
92
+ columns: [
93
+ { id: "a", blocks: [] },
94
+ { id: "b", blocks: [] },
95
+ ],
96
+ },
97
+ { id: "inner", type: "canvas", items: [] },
98
+ ];
99
+ for (let child of nested) {
100
+ let result = safeParse(boxBlockSchema, { id: "box", type: "box", blocks: [child] });
101
+ expect(result.success, child.type).toBe(false);
102
+ }
103
+ });
104
+
105
+ it("refuses an unknown variant or tone", () => {
106
+ expect(issuesOf(slide([{ ...steps, variant: "dotted" } as never])).map((issue) => issue.path)).toEqual([
107
+ "blocks.0.variant",
108
+ ]);
109
+ expect(issuesOf(slide([{ ...steps, tone: "purple" } as never])).map((issue) => issue.path)).toEqual([
110
+ "blocks.0.tone",
111
+ ]);
112
+ });
113
+
114
+ it("gives a callout a variant and the brand tone, and a canvas text the brand tone", () => {
115
+ let blocks = [
116
+ { id: "c", type: "callout", text: "Husk", tone: "brand", variant: "filled" },
117
+ { id: "k", type: "canvas", items: [{ id: "t", type: "text", text: "Hei", surface: "frame", tone: "brand" }] },
118
+ ];
119
+ expect(issuesOf(slide(blocks as Block[]))).toEqual([]);
120
+ });
121
+ });
122
+
123
+ describe("revealing the parts of a box", () => {
124
+ it("walks a box in document order, its list items included", () => {
125
+ let blocks: Block[] = [{ id: "top", type: "text", text: "Før", reveal: "step" }, steps];
126
+ expect(getTimedParts(blocks).map((part) => part.id)).toEqual(["top", "box", "h", "l", "i1", "i2"]);
127
+ expect(getRevealSteps(blocks)).toEqual(["top", "i1", "i2"]);
128
+ expect(shownIds(blocks, stateOf(blocks, 1))).toEqual(["top", "box", "h", "l"]);
129
+ expect(shownIds(blocks, stateOf(blocks, 2))).toEqual(["top", "box", "h", "l", "i1"]);
130
+ expect(getRevealNavigation(blocks, 0, new Set()).presses).toBe(3);
131
+ });
132
+
133
+ it("walks a box in a column", () => {
134
+ let blocks: Block[] = [
135
+ {
136
+ id: "cols",
137
+ type: "columns",
138
+ columns: [
139
+ { id: "a", blocks: [steps] },
140
+ { id: "b", blocks: [{ id: "t", type: "text", text: "Etter", reveal: "step" }] },
141
+ ],
142
+ },
143
+ ];
144
+ expect(getRevealSteps(blocks)).toEqual(["i1", "i2", "t"]);
145
+ expect(shownIds(blocks, stateOf(blocks, 1))).toEqual(["cols", "box", "h", "l", "i1"]);
146
+ });
147
+
148
+ it("lets a part in a box follow its cues, go with the part above it, and go away", () => {
149
+ let blocks: Block[] = [
150
+ {
151
+ id: "box",
152
+ type: "box",
153
+ revealAt: "c1",
154
+ blocks: [
155
+ { id: "a", type: "text", text: "A", reveal: "with-previous" },
156
+ { id: "b", type: "text", text: "B", revealAt: "c2", hideAt: "c3" },
157
+ ],
158
+ },
159
+ ];
160
+ expect(shownIds(blocks, stateOf(blocks, 0))).toEqual([]);
161
+ expect(shownIds(blocks, stateOf(blocks, 0, "c1"))).toEqual(["box", "a"]);
162
+ expect(shownIds(blocks, stateOf(blocks, 0, "c1", "c2"))).toEqual(["box", "a", "b"]);
163
+ expect(shownIds(blocks, stateOf(blocks, 0, "c1", "c2", "c3"))).toEqual(["box", "a"]);
164
+ });
165
+
166
+ it("finds the effects in a box, in a column too, and what they act on", () => {
167
+ let blocks: Block[] = [
168
+ { id: "t", type: "text", text: "T" },
169
+ {
170
+ id: "cols",
171
+ type: "columns",
172
+ columns: [
173
+ {
174
+ id: "a",
175
+ blocks: [{ id: "box", type: "box", blocks: [{ id: "e", type: "effect", target: "t", move: { x: 1 } }] }],
176
+ },
177
+ { id: "b", blocks: [] },
178
+ ],
179
+ },
180
+ ];
181
+ expect(getEffectBlocks(blocks).map((effect) => effect.id)).toEqual(["e"]);
182
+ expect(getPartEffects(blocks, stateOf(blocks, 0)).get("t")?.x).toBe(1);
183
+ });
184
+ });
185
+
186
+ describe("validating a box", () => {
187
+ it("checks the ids, cues, delays and effect targets of its parts, in a column too", () => {
188
+ let box = (id: string): BoxBlock => ({
189
+ id,
190
+ type: "box",
191
+ blocks: [
192
+ { id: "h", type: "heading", text: "Overskrift", revealAt: "nope" },
193
+ { id: `${id}-t`, type: "text", text: "Tekst", delay: 100 },
194
+ { id: `${id}-e`, type: "effect", target: "missing" },
195
+ { id: `${id}-v`, type: "video-link", label: "Se", media: { src: "/m.mp4", start: 5, end: 2 } },
196
+ ],
197
+ });
198
+ let issues = issuesOf(
199
+ slide(
200
+ [
201
+ box("b1"),
202
+ {
203
+ id: "cols",
204
+ type: "columns",
205
+ columns: [
206
+ { id: "a", blocks: [box("b2")] },
207
+ { id: "b", blocks: [] },
208
+ ],
209
+ },
210
+ ],
211
+ ["c1"],
212
+ ),
213
+ );
214
+ expect(issues.map((issue) => issue.path).sort()).toEqual(
215
+ [
216
+ "blocks.0.blocks.0.revealAt",
217
+ "blocks.0.blocks.1.delay",
218
+ "blocks.0.blocks.2.target",
219
+ "blocks.0.blocks.3.media.end",
220
+ "blocks.1.columns.0.blocks.0.blocks.0.id",
221
+ "blocks.1.columns.0.blocks.0.blocks.0.revealAt",
222
+ "blocks.1.columns.0.blocks.0.blocks.1.delay",
223
+ "blocks.1.columns.0.blocks.0.blocks.2.target",
224
+ "blocks.1.columns.0.blocks.0.blocks.3.media.end",
225
+ ].sort(),
226
+ );
227
+ });
228
+
229
+ it("lets an effect and a transition target a part in a box", () => {
230
+ let step = slide([steps, { id: "e", type: "effect", target: ["h", "i1"], scale: 2 }]);
231
+ step.transitions = [{ on: "enter", effect: "fade", target: "i2" }];
232
+ expect(issuesOf(step)).toEqual([]);
233
+ });
234
+ });
@@ -34,7 +34,7 @@ export function getStartedCueIds(cues: Cue[], time: number): Set<string> {
34
34
  return started;
35
35
  }
36
36
 
37
- /** Every block, list item and canvas item of a slide in document order, columns flattened. */
37
+ /** Every block, list item and canvas item of a slide in document order, columns and boxes flattened. */
38
38
  export function getTimedParts(blocks: Block[]): Timed[] {
39
39
  let parts: Timed[] = [];
40
40
 
@@ -45,6 +45,7 @@ export function getTimedParts(blocks: Block[]): Timed[] {
45
45
  if (block.type === "columns") {
46
46
  for (let column of block.columns) column.blocks.forEach(add);
47
47
  }
48
+ if (block.type === "box") block.blocks.forEach(add);
48
49
  }
49
50
 
50
51
  blocks.forEach(add);
@@ -1,5 +1,5 @@
1
1
  import { isVisible, type RevealState } from "./cues";
2
- import type { Block, ContentBlock, EffectBlock } from "./schema";
2
+ import type { Block, BoxContentBlock, ContentBlock, EffectBlock } from "./schema";
3
3
 
4
4
  export const DEFAULT_EFFECT_DURATION = 300;
5
5
 
@@ -16,14 +16,15 @@ export interface PartEffect {
16
16
  duration: number;
17
17
  }
18
18
 
19
- /** Every effect block of a slide in document order, those in columns included. */
20
- export function getEffectBlocks(blocks: Array<Block | ContentBlock>): EffectBlock[] {
19
+ /** Every effect block of a slide in document order, those in columns and boxes included. */
20
+ export function getEffectBlocks(blocks: Array<Block | ContentBlock | BoxContentBlock>): EffectBlock[] {
21
21
  let effects: EffectBlock[] = [];
22
22
  for (let block of blocks) {
23
23
  if (block.type === "effect") effects.push(block);
24
24
  if (block.type === "columns") {
25
25
  for (let column of block.columns) effects.push(...getEffectBlocks(column.blocks));
26
26
  }
27
+ if (block.type === "box") effects.push(...getEffectBlocks(block.blocks));
27
28
  }
28
29
  return effects;
29
30
  }
@@ -37,6 +37,18 @@ let source = pipe(string(), minLength(1));
37
37
 
38
38
  let seconds = pipe(number(), minValue(0));
39
39
 
40
+ /** The colour scales a box, a callout or a framed canvas text can take. `brand` is the company theme's own. */
41
+ export const TONES = ["neutral", "info", "success", "warning", "danger", "brand"] as const;
42
+
43
+ /** The colour of a surface. Default `neutral`. */
44
+ let tone = optional(picklist(TONES));
45
+
46
+ /**
47
+ * `bordered` (the default): a tinted surface with a frame and a coloured edge. `filled`: a solid
48
+ * surface in the tone's colour, with the text in its contrast colour.
49
+ */
50
+ let surfaceVariant = optional(picklist(["bordered", "filled"]));
51
+
40
52
  /**
41
53
  * A stretch of narration or video: what is said, and when. The text is also the subtitle. A cue
42
54
  * without text is a marker: something on the slide can show or go away at it, but no subtitle is
@@ -167,7 +179,8 @@ export const calloutBlockSchema = strictObject({
167
179
  /** Markdown. */
168
180
  text,
169
181
  /** The colour of the box. Default `neutral`. */
170
- tone: optional(picklist(["neutral", "info", "success", "warning", "danger"])),
182
+ tone,
183
+ variant: surfaceVariant,
171
184
  ...timing,
172
185
  });
173
186
 
@@ -200,6 +213,29 @@ export const effectBlockSchema = strictObject({
200
213
  duration: milliseconds.duration,
201
214
  });
202
215
 
216
+ /** Every block that can stand inside a box. A box holds no box, callout, columns or canvas. */
217
+ export const boxContentSchema = variant("type", [
218
+ headingBlockSchema,
219
+ textBlockSchema,
220
+ listBlockSchema,
221
+ imageBlockSchema,
222
+ quoteBlockSchema,
223
+ videoLinkBlockSchema,
224
+ effectBlockSchema,
225
+ ]);
226
+
227
+ /** A coloured box around other blocks, e.g. a heading and a list of steps. */
228
+ export const boxBlockSchema = strictObject({
229
+ id,
230
+ type: literal("box"),
231
+ /** The colour of the box. Default `neutral`. */
232
+ tone,
233
+ variant: surfaceVariant,
234
+ /** Headings, texts, lists, images, quotes and video links, and effects. No box, callout, columns or canvas. */
235
+ blocks: array(boxContentSchema),
236
+ ...timing,
237
+ });
238
+
203
239
  /** Every block that can stand inside a column. Columns do not nest. */
204
240
  export const contentBlockSchema = variant("type", [
205
241
  headingBlockSchema,
@@ -208,6 +244,7 @@ export const contentBlockSchema = variant("type", [
208
244
  imageBlockSchema,
209
245
  quoteBlockSchema,
210
246
  calloutBlockSchema,
247
+ boxBlockSchema,
211
248
  videoLinkBlockSchema,
212
249
  effectBlockSchema,
213
250
  ]);
@@ -246,7 +283,7 @@ export const canvasTextSchema = strictObject({
246
283
  /** `solid`: on a white surface that covers what is under it. `frame`: the same with a coloured frame. */
247
284
  surface: optional(picklist(["none", "solid", "frame"])),
248
285
  /** The colour of the frame. Default `neutral`. */
249
- tone: optional(picklist(["neutral", "info", "success", "warning", "danger"])),
286
+ tone,
250
287
  /** The text size, as a factor of the canvas's normal size. Default 1. */
251
288
  size: optional(pipe(number(), minValue(0.1))),
252
289
  ...canvasPlace,
@@ -284,6 +321,7 @@ export const blockSchema = variant("type", [
284
321
  imageBlockSchema,
285
322
  quoteBlockSchema,
286
323
  calloutBlockSchema,
324
+ boxBlockSchema,
287
325
  videoLinkBlockSchema,
288
326
  effectBlockSchema,
289
327
  columnsBlockSchema,
@@ -393,7 +431,11 @@ export type Cue = InferOutput<typeof cueSchema>;
393
431
  export type StepTransition = InferOutput<typeof transitionSchema>;
394
432
  export type Media = InferOutput<typeof mediaSchema>;
395
433
  export type Narration = InferOutput<typeof narrationSchema>;
434
+ export type Tone = (typeof TONES)[number];
435
+ export type SurfaceVariant = NonNullable<InferOutput<typeof calloutBlockSchema>["variant"]>;
396
436
  export type CalloutBlock = InferOutput<typeof calloutBlockSchema>;
437
+ export type BoxBlock = InferOutput<typeof boxBlockSchema>;
438
+ export type BoxContentBlock = InferOutput<typeof boxContentSchema>;
397
439
  export type EffectBlock = InferOutput<typeof effectBlockSchema>;
398
440
  export type ImageSize = NonNullable<InferOutput<typeof imageBlockSchema>["size"]>;
399
441
  export type ListItem = InferOutput<typeof listItemSchema>;