@astl/editor 0.2.3 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/dist/authoring.d.ts +50 -14
  3. package/dist/authoring.d.ts.map +1 -1
  4. package/dist/authoring.js +211 -18
  5. package/dist/authoring.js.map +1 -1
  6. package/dist/elements/color-control.d.ts +4 -1
  7. package/dist/elements/color-control.d.ts.map +1 -1
  8. package/dist/elements/color-control.js +6 -2
  9. package/dist/elements/color-control.js.map +1 -1
  10. package/dist/elements/insert-menu.d.ts +8 -1
  11. package/dist/elements/insert-menu.d.ts.map +1 -1
  12. package/dist/elements/insert-menu.js +25 -3
  13. package/dist/elements/insert-menu.js.map +1 -1
  14. package/dist/elements/inspector.d.ts.map +1 -1
  15. package/dist/elements/inspector.js +68 -4
  16. package/dist/elements/inspector.js.map +1 -1
  17. package/dist/elements/issues.d.ts.map +1 -1
  18. package/dist/elements/issues.js +11 -3
  19. package/dist/elements/issues.js.map +1 -1
  20. package/dist/elements/picture-dialog.d.ts +1 -0
  21. package/dist/elements/picture-dialog.d.ts.map +1 -1
  22. package/dist/elements/picture-dialog.js +16 -3
  23. package/dist/elements/picture-dialog.js.map +1 -1
  24. package/dist/elements/preview.d.ts.map +1 -1
  25. package/dist/elements/preview.js +11 -2
  26. package/dist/elements/preview.js.map +1 -1
  27. package/dist/elements/style-popups.js +3 -3
  28. package/dist/elements/styles.d.ts +36 -1
  29. package/dist/elements/styles.d.ts.map +1 -1
  30. package/dist/elements/styles.js +97 -1
  31. package/dist/elements/styles.js.map +1 -1
  32. package/dist/elements/toolbar.d.ts.map +1 -1
  33. package/dist/elements/toolbar.js +40 -16
  34. package/dist/elements/toolbar.js.map +1 -1
  35. package/dist/index.d.ts +3 -3
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +1 -1
  38. package/dist/index.js.map +1 -1
  39. package/dist/inspect.d.ts +33 -3
  40. package/dist/inspect.d.ts.map +1 -1
  41. package/dist/inspect.js +2 -2
  42. package/dist/inspect.js.map +1 -1
  43. package/dist/messages/en.json +18 -0
  44. package/dist/messages/pl.json +18 -0
  45. package/package.json +5 -5
  46. package/src/authoring.ts +283 -30
  47. package/src/elements/color-control.ts +6 -2
  48. package/src/elements/insert-menu.ts +34 -3
  49. package/src/elements/inspector.ts +80 -5
  50. package/src/elements/issues.ts +11 -3
  51. package/src/elements/picture-dialog.ts +17 -3
  52. package/src/elements/preview.ts +11 -2
  53. package/src/elements/style-popups.ts +3 -3
  54. package/src/elements/styles.ts +111 -1
  55. package/src/elements/toolbar.ts +42 -16
  56. package/src/index.ts +4 -1
  57. package/src/inspect.ts +33 -3
  58. package/src/messages/en.json +18 -0
  59. package/src/messages/pl.json +18 -0
@@ -13,6 +13,8 @@
13
13
  "insert.explanation.description": "Dlaczego odpowiedź jest dobra, widoczne po sprawdzeniu",
14
14
  "insert.feedback": "Informacja zwrotna",
15
15
  "insert.feedback.description": "Tekst zależny od wyniku, widoczny po sprawdzeniu",
16
+ "insert.check": "Przycisk Sprawdź",
17
+ "insert.check.description": "Jeden przycisk Sprawdź dla pytań z tekstu nad nim",
16
18
  "insert.text": "Tekst",
17
19
  "insert.text.description": "Akapit po tym bloku",
18
20
  "insert.noMatch": "Nic nie pasuje do „{query}”.",
@@ -40,6 +42,7 @@
40
42
  "toolbar.search": "Szukaj",
41
43
  "block.text": "Tekst",
42
44
  "block.gap": "Luka",
45
+ "block.check": "Przycisk Sprawdź",
43
46
  "issue.onPage": "{n} na stronie {page}",
44
47
  "picture.title": "Dodaj obrazek",
45
48
  "picture.editTitle": "Edytuj obrazek",
@@ -117,6 +120,21 @@
117
120
  "inspector.uploaded": "Wgrano.",
118
121
  "inspector.uploadFailed": "Nie udało się wgrać pliku. Spróbuj ponownie albo wpisz jego adres.",
119
122
  "inspector.uploadBlocked": "Wgrywanie zwróciło adres, na który nie pozwala polityka adresów.",
123
+ "check.labelField": "Tekst przycisku",
124
+ "check.labelHelp": "Puste: „Sprawdź”.",
125
+ "check.targets": "Pytania, które sprawdza",
126
+ "check.targetsHelp": "Pytania z tej strony. Zaznaczone nie mają własnego przycisku Sprawdź.",
127
+ "check.noQuestions": "Na tej stronie nie ma jeszcze pytań.",
128
+ "check.target": "{type} {n}",
129
+ "check.name": "przycisk Sprawdź {n}",
130
+ "check.named": "„{label}”",
131
+ "check.checkedBy": "Sprawdzane przez {check}",
132
+ "check.count": "{n, plural, one {# pytanie} few {# pytania} many {# pytań} other {# pytania}}",
133
+ "check.button": "Sprawdź",
134
+ "check.none": "Brak pytań",
135
+ "check.auto": "automatyczny · {n, plural, one {# pytanie} few {# pytania} many {# pytań} other {# pytania}}",
136
+ "check.make": "Zrób z niego przycisk",
137
+ "check.makeHelp": "Gdy ćwiczenie sprawdza po jednym pytaniu, te pytania mają wspólny przycisk Sprawdź. Jako przycisk możesz wybrać pytania i ustawić jego tekst.",
120
138
  "issues.title": "Problemy",
121
139
  "issues.errors": "{count, plural, one {# błąd} few {# błędy} many {# błędów} other {# błędu}}",
122
140
  "issues.warnings": "{count, plural, one {# ostrzeżenie} few {# ostrzeżenia} many {# ostrzeżeń} other {# ostrzeżenia}}",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astl/editor",
3
- "version": "0.2.3",
3
+ "version": "0.3.1",
4
4
  "description": "Editor-agnostic authoring kit: templates, ids, inspector, issues, insert menu and preview over an EditorAdapter. Bring any WYSIWYG editor.",
5
5
  "keywords": [
6
6
  "astrolabe",
@@ -48,10 +48,10 @@
48
48
  "access": "public"
49
49
  },
50
50
  "dependencies": {
51
- "@astl/core": "0.2.3",
52
- "@astl/engine": "0.2.3",
53
- "@astl/player": "0.2.3",
54
- "@astl/tokens": "0.2.3",
51
+ "@astl/core": "0.3.1",
52
+ "@astl/engine": "0.3.1",
53
+ "@astl/player": "0.3.1",
54
+ "@astl/tokens": "0.3.1",
55
55
  "lit": "3.3.3"
56
56
  }
57
57
  }
package/src/authoring.ts CHANGED
@@ -4,11 +4,19 @@
4
4
  */
5
5
  import {
6
6
  type AttemptPolicy,
7
+ CHECK_FOR_ATTRIBUTE,
8
+ CHECK_LABEL_ATTRIBUTE,
9
+ CHECK_TAG,
10
+ type CheckTree,
7
11
  COLUMN_TAG,
8
12
  COLUMNS_TAG,
9
13
  type ComponentManifest,
14
+ checkFor,
15
+ checkNodes,
16
+ checkParts,
10
17
  createI18n,
11
18
  DOC_TAG,
19
+ type EditorAdapter,
12
20
  type EditorDescriptor,
13
21
  type EditorTemplate,
14
22
  type ElementNode,
@@ -16,6 +24,7 @@ import {
16
24
  type Engine,
17
25
  element,
18
26
  type Issue,
27
+ isCheckable,
19
28
  isElement,
20
29
  isSafeUrl,
21
30
  isSourceId,
@@ -24,6 +33,7 @@ import {
24
33
  type Node,
25
34
  PAGE_CHECK_ATTRIBUTE,
26
35
  PAGE_TAG,
36
+ planChecks,
27
37
  SCORING_ATTRIBUTES,
28
38
  STYLE_TAG,
29
39
  STYLE_TEMPLATE_ATTRIBUTE,
@@ -37,7 +47,13 @@ import { cleanStyle, isStyleName } from '@astl/core/declarations';
37
47
  import { engineMessages, type LocalChecker, localChecker, parseHtml } from '@astl/engine';
38
48
  import type { ElementEntry } from '@astl/player';
39
49
  import { type InspectorChange, updateElement } from './edit.js';
40
- import { type InspectorModel, type InspectorOption, inspectorModel, styleTemplateField } from './inspect.js';
50
+ import {
51
+ type CheckTargetModel,
52
+ type InspectorModel,
53
+ type InspectorOption,
54
+ inspectorModel,
55
+ styleTemplateField,
56
+ } from './inspect.js';
41
57
  import { EDITOR_NAMESPACE, editorMessages } from './messages.js';
42
58
  import { setPageCheckSource } from './pages.js';
43
59
  import {
@@ -216,6 +232,37 @@ export function pictureHtml(picture: PictureFields): string {
216
232
  return caption === '' ? img : `<figure>${img}<figcaption>${escapeHtml(caption)}</figcaption></figure>`;
217
233
  }
218
234
 
235
+ /**
236
+ * Inserts a Check element (`astl-check`) at the cursor, as the insert menu's "Check button" does, for a host's own menu
237
+ * (its label and line: the kit's messages `insert.check` and `insert.check.description`). It goes where
238
+ * `EditorAdapter.insert` puts a block, after the block the cursor is in, with a fresh id (`check-<n>`), and its `for`
239
+ * names the questions it takes there: the graded inline questions of the run of text right above it
240
+ * (`OutlineCheck.targets`), so moving text later does not change what it checks. The TipTap adapter selects it and
241
+ * makes the insert one undo step. Returns its source HTML.
242
+ */
243
+ export function insertCheck(authoring: Authoring, adapter: EditorAdapter): string {
244
+ const used = usedIds(adapter.getSource());
245
+ let n = 1;
246
+ while (used.has(`check-${n}`)) n++;
247
+ const id = `check-${n}`;
248
+ let html = `<${CHECK_TAG} id="${id}"></${CHECK_TAG}>`;
249
+ adapter.insert(html);
250
+ const targets = authoring
251
+ .outline(adapter.getSource())
252
+ .pages.flatMap((page) => page.checks)
253
+ .find((check) => check.id === id)?.targets;
254
+ const current = adapter.getElement(id);
255
+ if (current !== null && targets !== undefined && targets.length > 0) {
256
+ html = authoring.update(current, {
257
+ kind: 'attribute',
258
+ name: CHECK_FOR_ATTRIBUTE,
259
+ value: targets.join(' '),
260
+ });
261
+ adapter.replaceElement(id, html);
262
+ }
263
+ return html;
264
+ }
265
+
219
266
  export interface OutlineComponent {
220
267
  readonly id: string | null;
221
268
  readonly tag: string;
@@ -223,35 +270,54 @@ export interface OutlineComponent {
223
270
  readonly label: string;
224
271
  /** Its `points` (default 1) when the type is graded, else null. */
225
272
  readonly points: number | null;
273
+ /**
274
+ * The source id of the Check element that checks it (`OutlinePage.checks`), or null. Where practice checks one
275
+ * question at a time, a question a Check element has gets no Check of its own.
276
+ */
277
+ readonly check: string | null;
226
278
  /** Issues located on this component or its children. */
227
279
  readonly errors: number;
228
280
  readonly warnings: number;
229
281
  }
230
282
 
231
283
  /**
232
- * One block of a page (`EditorBlockPlace`): a block component directly on the page, or the content between two of
233
- * them (paragraphs, headings, lists, quotes, pictures, with the inline components in their text).
284
+ * One block of a page (`EditorBlockPlace`): a block component directly on the page, a Check element (`astl-check`), or
285
+ * the content between two of them (paragraphs, headings, lists, quotes, pictures, with the inline components in their
286
+ * text).
234
287
  */
235
288
  export interface OutlineBlock {
236
- readonly kind: 'component' | 'text';
237
- /** The component's source id (null when it has none), or null for a text block. */
289
+ readonly kind: 'component' | 'text' | 'check';
290
+ /** The component's or the Check element's source id (null when it has none), or null for a text block. */
238
291
  readonly id: string | null;
239
- /** The component's tag, or null for a text block. */
292
+ /** The component's tag (`astl-check` for a Check element), or null for a text block. */
240
293
  readonly tag: string | null;
241
294
  /**
242
- * The block's type: the component's label, else `block.gap` ("Gap") for text that holds a graded component and
243
- * `block.text` ("Text") for the rest.
295
+ * The block's type: the component's label, `block.check` ("Check button") for a Check element, else `block.gap`
296
+ * ("Gap") for text that holds a graded component and `block.text` ("Text") for the rest.
244
297
  */
245
298
  readonly label: string;
246
299
  /** The sum of its components' points, or null when none of them is graded. */
247
300
  readonly points: number | null;
248
- /** Its component, or the components in its text, in document order. */
301
+ /** Its component, or the components in its text, in document order; none for a Check element. */
249
302
  readonly components: readonly OutlineComponent[];
250
- /** Issues located on its components. */
303
+ /** Issues located on its components, or on the Check element. */
251
304
  readonly errors: number;
252
305
  readonly warnings: number;
253
306
  }
254
307
 
308
+ /** A Check element of a page (`<astl-check>`): the questions it checks, as the engine and the player take them. */
309
+ export interface OutlineCheck {
310
+ /** Its source id, or null when it has none. */
311
+ readonly id: string | null;
312
+ /** Its `label`, the text of its button, or null without one (the button says "Check"). */
313
+ readonly label: string | null;
314
+ /**
315
+ * The source ids of the graded questions it checks, in order (`planChecks`): those its `for` names on its page, else
316
+ * the graded inline questions of the run of text right above it; none that a Check element before it has.
317
+ */
318
+ readonly targets: readonly string[];
319
+ }
320
+
255
321
  export interface OutlinePage {
256
322
  /** null for the implicit page of a document without pages. */
257
323
  readonly id: string | null;
@@ -267,6 +333,14 @@ export interface OutlinePage {
267
333
  readonly components: readonly OutlineComponent[];
268
334
  /** Its content as blocks, in order. */
269
335
  readonly blocks: readonly OutlineBlock[];
336
+ /** Its Check elements, in reading order (in its layouts' columns too). */
337
+ readonly checks: readonly OutlineCheck[];
338
+ /**
339
+ * Its automatic Checks, where practice checks one question at a time: the source ids of the graded questions of each
340
+ * run of text that no Check element has, when there are two or more, in order. The player puts one Check after the
341
+ * last of them that checks them at once; a question alone keeps its own.
342
+ */
343
+ readonly automatic: readonly (readonly string[])[];
270
344
  /** The sum of its blocks' points, or null when nothing on it is graded. */
271
345
  readonly points: number | null;
272
346
  }
@@ -362,9 +436,10 @@ export interface Authoring {
362
436
  */
363
437
  withCompanion(tag: string, source: string, id?: string): string | null;
364
438
  /**
365
- * The inspector model of one component element (source HTML), or null for elements it does not know. With the
366
- * whole document (`source`), fields offer what other elements hold (the words of the bank a drop takes its words
367
- * from); without it they show the attribute's own control.
439
+ * The inspector model of one component element (source HTML), or of a Check element (`astl-check`: its button's text
440
+ * and a `check-targets` field), or null for elements it does not know. With the whole document (`source`), fields
441
+ * offer what other elements hold (the words of the bank a drop takes its words from, the questions of a check's page)
442
+ * and a question a Check element checks says which (`checkedBy`); without it they show the attribute's own control.
368
443
  */
369
444
  inspect(elementHtml: string, source?: string): InspectorModel | null;
370
445
  /**
@@ -384,7 +459,7 @@ export interface Authoring {
384
459
  * `page: false`, without its page ("Question 2").
385
460
  */
386
461
  describe(issue: Issue, source?: string, options?: DescribeOptions): string;
387
- /** `source` with fresh ids on pages and components that lack one (or have an empty one). */
462
+ /** `source` with fresh ids on pages, components and Check elements that lack one (or have an empty one). */
388
463
  assignIds(source: string): string;
389
464
  /** Pages, their blocks and components, points and issue counts. */
390
465
  outline(source: string): Outline;
@@ -543,19 +618,77 @@ export function createAuthoring(options: AuthoringOptions): Authoring {
543
618
  return Number.isFinite(n) && n > 0 ? n : DEFAULT_POINTS;
544
619
  };
545
620
 
621
+ /** An element's own id, or null without one (or with an empty one). */
622
+ const ownId = (node: ElementNode): string | null =>
623
+ Object.hasOwn(node.attrs, 'id') && node.attrs.id !== '' ? (node.attrs.id ?? null) : null;
624
+
625
+ /**
626
+ * The Check elements of a page's content (or a document's without pages), each with its questions, as the engine
627
+ * resolves them (`planChecks`): a `for` keeps the graded questions of the page it names. And the automatic ones: the
628
+ * questions of each run of text that none has, two or more.
629
+ */
630
+ const checksOf = (
631
+ content: readonly Node[],
632
+ ): { readonly checks: OutlineCheck[]; readonly automatic: (readonly string[])[] } => {
633
+ const questions = new Set<string>();
634
+ const collect = (nodes: readonly Node[]): void => {
635
+ for (const node of nodes) {
636
+ if (node.type !== 'element') continue;
637
+ const manifest = registered.get(node.tag);
638
+ const id = ownId(node);
639
+ if (manifest === undefined) collect(node.children);
640
+ else if (isCheckable(manifest) && id !== null) questions.add(id);
641
+ }
642
+ };
643
+ collect(content);
644
+ const tree: CheckTree<Node> = {
645
+ tag: (node) => (node.type === 'element' ? node.tag : null),
646
+ children: (node) => (node.type === 'element' ? node.children : []),
647
+ component: (node) => {
648
+ const manifest = node.type === 'element' ? registered.get(node.tag) : undefined;
649
+ if (manifest === undefined || node.type !== 'element') return null;
650
+ return { id: ownId(node), graded: isCheckable(manifest), block: manifest.display === 'block' };
651
+ },
652
+ checkFor: (node) =>
653
+ node.type === 'element' && Object.hasOwn(node.attrs, CHECK_FOR_ATTRIBUTE)
654
+ ? checkFor(node.attrs[CHECK_FOR_ATTRIBUTE]).filter((id) => questions.has(id))
655
+ : null,
656
+ };
657
+ const { targets, uncovered } = planChecks(checkParts(content, tree));
658
+ const checks = checkNodes(content, tree).map((node, k) => {
659
+ const attrs = node.type === 'element' ? node.attrs : {};
660
+ return {
661
+ id: node.type === 'element' ? ownId(node) : null,
662
+ label: Object.hasOwn(attrs, CHECK_LABEL_ATTRIBUTE) ? (attrs[CHECK_LABEL_ATTRIBUTE] ?? null) : null,
663
+ targets: targets[k] ?? [],
664
+ };
665
+ });
666
+ return { checks, automatic: uncovered.filter((run) => run.length > 1) };
667
+ };
668
+
669
+ /** The last outline: an inspector asks for it on every render, for the same source. */
670
+ let outlined: { readonly source: string; readonly outline: Outline } | null = null;
546
671
  const outline = (source: string): Outline => {
672
+ if (outlined?.source === source) return outlined.outline;
547
673
  const { issues } = engine.validate(source);
548
674
  const idOf = (node: ElementNode) => (Object.hasOwn(node.attrs, 'id') ? (node.attrs.id ?? null) : null);
549
- const entry = (node: ElementNode): OutlineComponent => {
675
+ /** The Check element of the page that checks a question, by the question's id. */
676
+ type CheckOf = ReadonlyMap<string, string>;
677
+ const entry = (node: ElementNode, checkOf: CheckOf): OutlineComponent => {
550
678
  const id = idOf(node);
551
679
  const counts = count(issues, (i) => id !== null && i.at.element === id);
552
- return { id, tag: node.tag, label: labelOf(node.tag), points: pointsOf(node), ...counts };
680
+ const check = (id === null ? undefined : checkOf.get(id)) ?? null;
681
+ return { id, tag: node.tag, label: labelOf(node.tag), points: pointsOf(node), check, ...counts };
553
682
  };
554
- const components = (nodes: readonly Node[], out: OutlineComponent[] = []): OutlineComponent[] => {
683
+ const components = (
684
+ nodes: readonly Node[],
685
+ checkOf: CheckOf,
686
+ out: OutlineComponent[] = [],
687
+ ): OutlineComponent[] => {
555
688
  for (const node of nodes) {
556
689
  if (node.type !== 'element') continue;
557
- if (registered.has(node.tag)) out.push(entry(node));
558
- else components(node.children, out);
690
+ if (registered.has(node.tag)) out.push(entry(node, checkOf));
691
+ else components(node.children, checkOf, out);
559
692
  }
560
693
  return out;
561
694
  };
@@ -578,12 +711,12 @@ export function createAuthoring(options: AuthoringOptions): Authoring {
578
711
  ...count(issues, (i) => i.at.element !== null && ids.has(i.at.element)),
579
712
  };
580
713
  };
581
- const blocks = (content: readonly Node[]): OutlineBlock[] => {
714
+ const blocks = (content: readonly Node[], checkOf: CheckOf): OutlineBlock[] => {
582
715
  const out: OutlineBlock[] = [];
583
716
  let run: Node[] = [];
584
717
  const flush = () => {
585
718
  if (run.some((n) => n.type === 'element' || n.value.trim() !== ''))
586
- out.push(block('text', null, components(run)));
719
+ out.push(block('text', null, components(run, checkOf)));
587
720
  run = [];
588
721
  };
589
722
  for (const node of content) {
@@ -591,11 +724,23 @@ export function createAuthoring(options: AuthoringOptions): Authoring {
591
724
  // In reading order, as the surface numbers them: a layout is no block, what is in its columns is.
592
725
  flush();
593
726
  for (const column of node.children) {
594
- if (isElement(column, COLUMN_TAG)) out.push(...blocks(column.children));
727
+ if (isElement(column, COLUMN_TAG)) out.push(...blocks(column.children, checkOf));
595
728
  }
729
+ } else if (node.type === 'element' && node.tag === CHECK_TAG) {
730
+ flush();
731
+ const id = idOf(node);
732
+ out.push({
733
+ kind: 'check',
734
+ id,
735
+ tag: CHECK_TAG,
736
+ label: t(EDITOR_NAMESPACE, 'block.check'),
737
+ points: null,
738
+ components: [],
739
+ ...count(issues, (i) => id !== null && i.at.element === id),
740
+ });
596
741
  } else if (node.type === 'element' && registered.get(node.tag)?.display === 'block') {
597
742
  flush();
598
- out.push(block('component', node, [entry(node)]));
743
+ out.push(block('component', node, [entry(node, checkOf)]));
599
744
  } else {
600
745
  run.push(node);
601
746
  }
@@ -609,7 +754,12 @@ export function createAuthoring(options: AuthoringOptions): Authoring {
609
754
  content: readonly Node[],
610
755
  check = false,
611
756
  ): OutlinePage => {
612
- const list = blocks(content);
757
+ const { checks, automatic } = checksOf(content);
758
+ const checkOf = new Map<string, string>();
759
+ for (const one of checks) {
760
+ if (one.id !== null) for (const target of one.targets) checkOf.set(target, one.id);
761
+ }
762
+ const list = blocks(content, checkOf);
613
763
  return {
614
764
  id,
615
765
  label,
@@ -617,8 +767,10 @@ export function createAuthoring(options: AuthoringOptions): Authoring {
617
767
  ...count(issues, (i) =>
618
768
  id === null ? i.at.page === null && i.at.tag !== null && i.at.tag !== DOC_TAG : i.at.page === id,
619
769
  ),
620
- components: components(content),
770
+ components: components(content, checkOf),
621
771
  blocks: list,
772
+ checks,
773
+ automatic,
622
774
  points: sum(list.map((b) => b.points)),
623
775
  };
624
776
  };
@@ -649,7 +801,9 @@ export function createAuthoring(options: AuthoringOptions): Authoring {
649
801
  } else {
650
802
  pages.push(page(null, null, content));
651
803
  }
652
- return { pages, ...count(issues, () => true), points: sum(pages.map((p) => p.points)) };
804
+ const result = { pages, ...count(issues, () => true), points: sum(pages.map((p) => p.points)) };
805
+ outlined = { source, outline: result };
806
+ return result;
653
807
  };
654
808
 
655
809
  /**
@@ -699,7 +853,11 @@ export function createAuthoring(options: AuthoringOptions): Authoring {
699
853
  text = false;
700
854
  continue;
701
855
  }
702
- if (node.type === 'element' && registered.get(node.tag)?.display === 'block') {
856
+ // A Check element is a block of its own, as in `outline`.
857
+ if (
858
+ node.type === 'element' &&
859
+ (node.tag === CHECK_TAG || registered.get(node.tag)?.display === 'block')
860
+ ) {
703
861
  block++;
704
862
  text = false;
705
863
  set(node, block, page);
@@ -732,8 +890,11 @@ export function createAuthoring(options: AuthoringOptions): Authoring {
732
890
  const edits: Edit[] = [];
733
891
  for (const { tag, id, range } of scanRanges(source)) {
734
892
  if (id !== null && id.trim() !== '') continue;
735
- if (tag !== PAGE_TAG && !registered.has(tag)) continue;
736
- const prefix = tag === PAGE_TAG ? 'page' : (byTag.get(tag)?.idPrefix ?? tag.replace(/^astl-/, ''));
893
+ if (tag !== PAGE_TAG && tag !== CHECK_TAG && !registered.has(tag)) continue;
894
+ const prefix =
895
+ tag === PAGE_TAG || tag === CHECK_TAG
896
+ ? tag.replace(/^astl-/, '')
897
+ : (byTag.get(tag)?.idPrefix ?? tag.replace(/^astl-/, ''));
737
898
  const fresh = freshId(isSourceId(`${prefix}-1`) ? prefix : 'item', used);
738
899
  used.add(fresh);
739
900
  const written = range.startTag.attributes.find((a) => a.name === 'id');
@@ -786,6 +947,87 @@ export function createAuthoring(options: AuthoringOptions): Authoring {
786
947
  return linkCompanions(withIds(html, used), source, used);
787
948
  }
788
949
 
950
+ /** How a Check element of a page is named: its label in quotes, else by its number among the page's ("Check button 2"). */
951
+ const checkName = (checks: readonly OutlineCheck[], id: string): string => {
952
+ const index = checks.findIndex((check) => check.id === id);
953
+ const label = checks[index]?.label?.trim() ?? '';
954
+ return label === ''
955
+ ? t(EDITOR_NAMESPACE, 'check.name', { n: index + 1 })
956
+ : t(EDITOR_NAMESPACE, 'check.named', { label });
957
+ };
958
+
959
+ /**
960
+ * The inspector model of a Check element: its button's text, and which questions of its page it checks, each by its
961
+ * number among the questions of its type on the page, in page order ("Gap 2", "Closed question 1"); a question
962
+ * another Check element has says which. Without the document, the questions its `for` names, by id.
963
+ */
964
+ const inspectCheck = (el: ElementNode, source: string | undefined): InspectorModel => {
965
+ const id = ownId(el);
966
+ const text = (key: string, params?: MessageParams) => t(EDITOR_NAMESPACE, key, params);
967
+ const page =
968
+ source === undefined || id === null
969
+ ? undefined
970
+ : outline(source).pages.find((p) => p.checks.some((check) => check.id === id));
971
+ const own =
972
+ page?.checks.find((check) => check.id === id)?.targets ?? checkFor(el.attrs[CHECK_FOR_ATTRIBUTE]);
973
+ const seen = new Map<string, number>();
974
+ const targets =
975
+ page === undefined
976
+ ? own.map((target): CheckTargetModel => ({ id: target, label: target, checked: true, other: null }))
977
+ : page.components.flatMap((component): CheckTargetModel[] => {
978
+ const manifest = manifestOf(component.tag);
979
+ if (manifest === null || !isCheckable(manifest)) return [];
980
+ const n = (seen.get(component.tag) ?? 0) + 1;
981
+ seen.set(component.tag, n);
982
+ if (component.id === null) return [];
983
+ const by = component.check;
984
+ return [
985
+ {
986
+ id: component.id,
987
+ label: text('check.target', { type: component.label, n }),
988
+ checked: own.includes(component.id),
989
+ other: by !== null && by !== id ? checkName(page.checks, by) : null,
990
+ },
991
+ ];
992
+ });
993
+ return {
994
+ tag: CHECK_TAG,
995
+ id,
996
+ label: text('block.check'),
997
+ icon: 'check',
998
+ fields: [
999
+ {
1000
+ kind: 'attribute',
1001
+ control: 'text',
1002
+ name: CHECK_LABEL_ATTRIBUTE,
1003
+ label: text('check.labelField'),
1004
+ help: text('check.labelHelp'),
1005
+ value: Object.hasOwn(el.attrs, CHECK_LABEL_ATTRIBUTE)
1006
+ ? (el.attrs[CHECK_LABEL_ATTRIBUTE] ?? '')
1007
+ : '',
1008
+ required: false,
1009
+ accept: null,
1010
+ },
1011
+ {
1012
+ kind: 'check-targets',
1013
+ name: CHECK_FOR_ATTRIBUTE,
1014
+ label: text('check.targets'),
1015
+ help: text('check.targetsHelp'),
1016
+ targets,
1017
+ },
1018
+ ],
1019
+ };
1020
+ };
1021
+
1022
+ /** The Check element that checks the question `id` in `source`, with its name, or null. */
1023
+ const checkedBy = (source: string, id: string): { readonly id: string; readonly name: string } | null => {
1024
+ for (const page of outline(source).pages) {
1025
+ const by = page.components.find((component) => component.id === id)?.check ?? null;
1026
+ if (by !== null) return { id: by, name: checkName(page.checks, by) };
1027
+ }
1028
+ return null;
1029
+ };
1030
+
789
1031
  return {
790
1032
  engine,
791
1033
  locale,
@@ -852,6 +1094,7 @@ export function createAuthoring(options: AuthoringOptions): Authoring {
852
1094
  inspect(elementHtml, source) {
853
1095
  const el = firstElement(parseHtml(elementHtml));
854
1096
  if (el === null) return null;
1097
+ if (el.tag === CHECK_TAG) return inspectCheck(el, source);
855
1098
  const manifest = manifestOf(el.tag);
856
1099
  if (manifest === null) return null;
857
1100
  const templates = templateOptions('component', el.tag);
@@ -861,7 +1104,17 @@ export function createAuthoring(options: AuthoringOptions): Authoring {
861
1104
  const at = scanElements(source).find((e) => e.id === id);
862
1105
  return at === undefined ? null : firstElement(parseHtml(source.slice(at.start, at.end)));
863
1106
  };
864
- return inspectorModel(el, manifest, byTag.get(el.tag) ?? null, textsFor(manifest), templates, find);
1107
+ const model = inspectorModel(
1108
+ el,
1109
+ manifest,
1110
+ byTag.get(el.tag) ?? null,
1111
+ textsFor(manifest),
1112
+ templates,
1113
+ find,
1114
+ );
1115
+ const id = ownId(el);
1116
+ const by = source === undefined || id === null || !isCheckable(manifest) ? null : checkedBy(source, id);
1117
+ return by === null ? model : { ...model, checkedBy: by };
865
1118
  },
866
1119
  inspectDocument(source) {
867
1120
  // The scanner, as `update` uses it: the document is the first start tag (and no full parse per keystroke).
@@ -4,17 +4,21 @@ import { PALETTE_SIZE } from '../style-model.js';
4
4
 
5
5
  const PALETTE = Array.from({ length: PALETTE_SIZE }, (_, i) => i + 1);
6
6
 
7
- /** The theme's colours first, each its own token: an author's colour that follows the theme by itself. */
7
+ /**
8
+ * The theme's colours first, each its own token: an author's colour that follows the theme by itself. The swatches go
9
+ * four a row, narrower than a target only where the popup has less room (a phone with larger text).
10
+ */
8
11
  export const colorStyles: CSSResult = css`
9
12
  .swatches {
10
13
  display: grid;
11
- grid-template-columns: repeat(4, minmax(var(--astl-target-min), 1fr));
14
+ grid-template-columns: repeat(4, minmax(0, 1fr));
12
15
  gap: var(--astl-space-1);
13
16
  max-inline-size: 16rem;
14
17
  }
15
18
  button.swatch {
16
19
  position: relative;
17
20
  justify-content: center;
21
+ min-inline-size: 0;
18
22
  padding: 0;
19
23
  border-color: var(--astl-outline);
20
24
  forced-color-adjust: none;
@@ -10,7 +10,7 @@ import {
10
10
  svg,
11
11
  type TemplateResult,
12
12
  } from 'lit';
13
- import { type Authoring, type PictureFields, pictureHtml } from '../authoring.js';
13
+ import { type Authoring, insertCheck, type PictureFields, pictureHtml } from '../authoring.js';
14
14
  import { scanElements } from '../scan.js';
15
15
  import { LAYOUTS, type LayoutName, layoutHtml } from '../style-model.js';
16
16
  import { AuthoringElement } from './base.js';
@@ -51,8 +51,11 @@ export const TYPE_GLYPHS: ReadonlyMap<string, SVGTemplateResult> = new Map([
51
51
  'help-hint',
52
52
  svg`<path d="M7.5 15.5h5M8.5 18h3M10 2.5a5 5 0 0 0-3 9c.6.5 1 1.2 1 2v.5h4v-.5c0-.8.4-1.5 1-2a5 5 0 0 0-3-9z"/>`,
53
53
  ],
54
- ['help-explanation', svg`<circle cx="10" cy="10" r="7.5"/><path d="M10 9v5m0-7.5v.5"/>`],
54
+ // A ring as a path: the menus fill a glyph's <circle> (the dots of list-checks), which drew a black disc here.
55
+ ['help-explanation', svg`<path d="M10 2.5a7.5 7.5 0 1 1 0 15a7.5 7.5 0 1 1 0-15zM10 9v5m0-7.5v.5"/>`],
55
56
  ['help-feedback', svg`<path d="M3.5 4.5h13v9h-7l-4 3v-3h-2z"/>`],
57
+ // A Check element: a button with a tick.
58
+ ['check', svg`<rect x="2.5" y="5" width="15" height="10" rx="2"/><path d="M7 10.2l2 2 4-4.2"/>`],
56
59
  ]);
57
60
 
58
61
  /** What "Hint", "Explanation" and "Feedback" add (`addHelp`). */
@@ -109,7 +112,8 @@ function withPicture(
109
112
  /**
110
113
  * `<astl-insert-menu>`: what authors can add, in named groups (`groups`): "Components" (each type with its default
111
114
  * template), "Exercises" (the types' named starters, when any) and "Content" ("Picture", which asks for the picture in a
112
- * dialog, and "Page break" when the editor can split pages, `EditorAdapter.splitPage`). Each entry shows its icon, its
115
+ * dialog, the help for students, "Check button", one Check for the questions above it, and "Page break" when the editor
116
+ * can split pages, `EditorAdapter.splitPage`). Each entry shows its icon, its
113
117
  * name and a one-line description, which together name its button; a press inserts at the cursor. The descriptions of
114
118
  * types with `menuMessages` load when the menu is first shown (inside a popover: when that opens).
115
119
  */
@@ -317,6 +321,19 @@ export class AstlInsertMenu extends AuthoringElement {
317
321
  return added;
318
322
  }
319
323
 
324
+ /**
325
+ * Inserts a Check element (`astl-check`) at the cursor (`insertCheck`): after the block the cursor is in, its `for`
326
+ * the questions of the run of text right above it, selected; its card lists its page's questions to tick. Returns
327
+ * its HTML, or null without an editor.
328
+ */
329
+ addCheck(): string | null {
330
+ const { authoring, adapter } = this;
331
+ if (authoring === null || adapter === null) return null;
332
+ const html = insertCheck(authoring, adapter);
333
+ this.#inserted(html);
334
+ return html;
335
+ }
336
+
320
337
  /** Inserts a page break at the cursor (`EditorAdapter.splitPage`): the new page's id, or null. */
321
338
  insertPageBreak(): string | null {
322
339
  const id = this.adapter?.splitPage?.() ?? null;
@@ -438,6 +455,20 @@ export class AstlInsertMenu extends AuthoringElement {
438
455
  );
439
456
  }
440
457
  }
458
+ if (shows('content')) {
459
+ content.push(
460
+ this.#button(
461
+ 'block',
462
+ 'check',
463
+ this.t('insert.check'),
464
+ this.t('insert.check.description'),
465
+ { content: 'check' },
466
+ () => {
467
+ this.addCheck();
468
+ },
469
+ ),
470
+ );
471
+ }
441
472
  if (shows('content') && this.adapter?.splitPage !== undefined) {
442
473
  content.push(
443
474
  this.#button(