@astl/editor 0.2.2 → 0.3.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 (45) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/dist/authoring.d.ts +50 -14
  3. package/dist/authoring.d.ts.map +1 -1
  4. package/dist/authoring.js +208 -18
  5. package/dist/authoring.js.map +1 -1
  6. package/dist/elements/help-form.d.ts.map +1 -1
  7. package/dist/elements/help-form.js +6 -3
  8. package/dist/elements/help-form.js.map +1 -1
  9. package/dist/elements/insert-menu.d.ts +8 -1
  10. package/dist/elements/insert-menu.d.ts.map +1 -1
  11. package/dist/elements/insert-menu.js +25 -3
  12. package/dist/elements/insert-menu.js.map +1 -1
  13. package/dist/elements/inspector.d.ts.map +1 -1
  14. package/dist/elements/inspector.js +67 -6
  15. package/dist/elements/inspector.js.map +1 -1
  16. package/dist/elements/picture-field.d.ts.map +1 -1
  17. package/dist/elements/picture-field.js +7 -3
  18. package/dist/elements/picture-field.js.map +1 -1
  19. package/dist/elements/styles.d.ts +10 -5
  20. package/dist/elements/styles.d.ts.map +1 -1
  21. package/dist/elements/styles.js +35 -8
  22. package/dist/elements/styles.js.map +1 -1
  23. package/dist/elements/toolbar.js +1 -1
  24. package/dist/index.d.ts +3 -3
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +1 -1
  27. package/dist/index.js.map +1 -1
  28. package/dist/inspect.d.ts +33 -3
  29. package/dist/inspect.d.ts.map +1 -1
  30. package/dist/inspect.js +2 -2
  31. package/dist/inspect.js.map +1 -1
  32. package/dist/messages/en.json +18 -0
  33. package/dist/messages/pl.json +18 -0
  34. package/package.json +5 -5
  35. package/src/authoring.ts +281 -30
  36. package/src/elements/help-form.ts +6 -3
  37. package/src/elements/insert-menu.ts +34 -3
  38. package/src/elements/inspector.ts +71 -7
  39. package/src/elements/picture-field.ts +7 -3
  40. package/src/elements/styles.ts +36 -8
  41. package/src/elements/toolbar.ts +1 -1
  42. package/src/index.ts +4 -1
  43. package/src/inspect.ts +33 -3
  44. package/src/messages/en.json +18 -0
  45. package/src/messages/pl.json +18 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,44 @@
1
1
  # @astl/editor
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - c85c3b9: A Check for several questions. `<astl-check id for label>` gives the questions it names (`for`: graded questions of its page, block ones too; without it, the inline questions of the run of text right above it) one Check, where practice checks one question at a time: one request for all of them, counted once, and they have no Check of their own; their hints, feedback and "Why?" stay theirs. Its row says how they came out ("2 of 3 correct"), read out, and the focus stays on its button. In a test, and where practice checks everything at once, it does not show. The questions of a run of text that no Check element has share an automatic Check after the last of them when there are two or more (three sentences with a gap each: one Check after the third); a question alone keeps its own. A heading starts a new run.
8
+
9
+ The protocol takes `CheckRequest.elements` (and `GradeOptions.elements`), at most one of `page`, `element` and `elements`, with the problem codes it had. Upgrade the server with the player or before it: a server before 0.3 grades the whole exercise for such a check, and a 0.3 player then takes only the results of the check's own questions. The engine warns with `CHECK_EMPTY`, `CHECK_TARGET_UNKNOWN`, `CHECK_TARGET_NOT_GRADED`, `CHECK_TARGET_OTHER_PAGE` and `CHECK_TARGET_TWICE`, and writes each check into the view with its questions resolved as opaque ids.
10
+
11
+ In the editor, "Elements" has "Check button": it goes after the block with the cursor with its `for` filled, drawn as the button with a tag ("3 questions") that marks its questions while selected, and a block of its own. Its card ticks the page's questions and sets the button's text; a question it checks says so in its card and goes there. An automatic Check shows where the player puts it, with "Make it a button". For hosts: `insertCheck(authoring, adapter)` for an insert menu of their own, `OutlinePage.checks` and `automatic`, `OutlineComponent.check`, block kind `check`, `InspectorModel.checkedBy`, the field `check-targets`, and from core `CHECK_TAG`, `checkFor`, `checkParts`, `planChecks`, `checkNodes` and `isCheckable`. Grading cases of the conformance fixtures take `elements`, and two gap fixtures show checks of several questions. The insert menu's Explanation icon is a ring again, not a black disc.
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies [c85c3b9]
16
+ - @astl/core@0.3.0
17
+ - @astl/engine@0.3.0
18
+ - @astl/player@0.3.0
19
+ - @astl/tokens@0.3.0
20
+
21
+ ## 0.2.3
22
+
23
+ ### Patch Changes
24
+
25
+ - 4498fa4: The card keeps its element while the author writes in it. Typing into an empty help field (the explanation, a feedback text, a new hint) with the cursor in the question's prompt closed the card at the first letter, and the rest of the word went into the page; the cross on a hint or on the explanation, and a table's "Add" and "Remove" in the card, closed it the same way. The TipTap adapter's `replaceElement` replaced the whole content of the block whenever a child came or went, which threw the cursor out of the block. It now changes only what changed (attributes in place, the children both versions share patched in place, only a child added or taken away replaced), so the cursor stays in the prompt, the card on its element and the field keeps its focus and caret, through undo and redo too. `EditorAdapter.replaceElement` says so: a cursor inside the element stays inside it.
26
+
27
+ The editor's focus ring is 2px wide and 1px out (`--astl-editor-focus-width`, `--astl-editor-focus-offset` on `<astl-editor>`), on all its controls (the toolbar and its menus, the card's fields and buttons, the sheet and the authoring controls on it), so it never reaches a field or a text beside it (the card's fields are 4px apart; the player's 3px ring, 2px out, reached 5px). A frame's tag draws its ring around its pill. The students' ring in the player is unchanged.
28
+
29
+ A hint's "Cost" label keeps its word whole on a phone and its select gives way, ending in an ellipsis: "Koszt" (Polish) broke into "Kosz" and "t" at 390 px. The card's other text still breaks anywhere when it must, so an author's long word or address never widens the card.
30
+
31
+ A table in the card (a crossword's words, say) shows a select's whole value: "Poziomo" was cut to "Pozior", and "Across" too at 1280 px. A select's cell starts from its natural width and a number's from 3.5rem, and a cell is never narrower than its label's longest word: when they don't fit, cells go on to the next line.
32
+
33
+ Every compact control is recognisable as a button at rest, without hover: an add action ("Add option", "Add prompt", "Add title", "Add a hint", a list's or a table's "Add", a picture field's "Add a zone") has a plus and the accent colour; any other text button ("Check this page", "Join with page 1", "Delete page", "Remove title", "Make it free", "Remove", the style targets, a picture's buttons) a 1px line in the outline colour, 3:1 at least in every theme; "In the text" also the selects' chevron, as it opens the style form; an icon alone keeps only its icon. "Add a hint" read as a label before. A page box's "Move to question" select has the same 1px line, height and corners (it had a 2px line), and a picture field's remove buttons are as wide as their words.
34
+
35
+ In a narrow page column a page head's button that wraps stays at the end, under the others, instead of under the page number.
36
+ - Updated dependencies [4498fa4]
37
+ - @astl/core@0.2.3
38
+ - @astl/engine@0.2.3
39
+ - @astl/player@0.2.3
40
+ - @astl/tokens@0.2.3
41
+
3
42
  ## 0.2.2
4
43
 
5
44
  ### Patch Changes
@@ -2,7 +2,7 @@
2
2
  * createAuthoring: the editor-independent logic of the authoring kit. Pure (no DOM), so hosts, agents and tests can
3
3
  * use it in any runtime; the web components and adapters are thin layers on top.
4
4
  */
5
- import { type AttemptPolicy, type EditorDescriptor, type EditorTemplate, type Engine, type Issue, type MessageCatalog, type MessageParams, type StyleTemplate, type UrlPolicy, type ValidationReport } from '@astl/core';
5
+ import { type AttemptPolicy, type EditorAdapter, type EditorDescriptor, type EditorTemplate, type Engine, type Issue, type MessageCatalog, type MessageParams, type StyleTemplate, type UrlPolicy, type ValidationReport } from '@astl/core';
6
6
  import { type LocalChecker } from '@astl/engine';
7
7
  import type { ElementEntry } from '@astl/player';
8
8
  import { type InspectorChange } from './edit.js';
@@ -111,6 +111,15 @@ export declare function pictureSize(value: unknown): number | undefined;
111
111
  * Every value is read once and escaped, and only the attributes of the content format are written.
112
112
  */
113
113
  export declare function pictureHtml(picture: PictureFields): string;
114
+ /**
115
+ * Inserts a Check element (`astl-check`) at the cursor, as the insert menu's "Check button" does, for a host's own menu
116
+ * (its label and line: the kit's messages `insert.check` and `insert.check.description`). It goes where
117
+ * `EditorAdapter.insert` puts a block, after the block the cursor is in, with a fresh id (`check-<n>`), and its `for`
118
+ * names the questions it takes there: the graded inline questions of the run of text right above it
119
+ * (`OutlineCheck.targets`), so moving text later does not change what it checks. The TipTap adapter selects it and
120
+ * makes the insert one undo step. Returns its source HTML.
121
+ */
122
+ export declare function insertCheck(authoring: Authoring, adapter: EditorAdapter): string;
114
123
  export interface OutlineComponent {
115
124
  readonly id: string | null;
116
125
  readonly tag: string;
@@ -118,33 +127,51 @@ export interface OutlineComponent {
118
127
  readonly label: string;
119
128
  /** Its `points` (default 1) when the type is graded, else null. */
120
129
  readonly points: number | null;
130
+ /**
131
+ * The source id of the Check element that checks it (`OutlinePage.checks`), or null. Where practice checks one
132
+ * question at a time, a question a Check element has gets no Check of its own.
133
+ */
134
+ readonly check: string | null;
121
135
  /** Issues located on this component or its children. */
122
136
  readonly errors: number;
123
137
  readonly warnings: number;
124
138
  }
125
139
  /**
126
- * One block of a page (`EditorBlockPlace`): a block component directly on the page, or the content between two of
127
- * them (paragraphs, headings, lists, quotes, pictures, with the inline components in their text).
140
+ * One block of a page (`EditorBlockPlace`): a block component directly on the page, a Check element (`astl-check`), or
141
+ * the content between two of them (paragraphs, headings, lists, quotes, pictures, with the inline components in their
142
+ * text).
128
143
  */
129
144
  export interface OutlineBlock {
130
- readonly kind: 'component' | 'text';
131
- /** The component's source id (null when it has none), or null for a text block. */
145
+ readonly kind: 'component' | 'text' | 'check';
146
+ /** The component's or the Check element's source id (null when it has none), or null for a text block. */
132
147
  readonly id: string | null;
133
- /** The component's tag, or null for a text block. */
148
+ /** The component's tag (`astl-check` for a Check element), or null for a text block. */
134
149
  readonly tag: string | null;
135
150
  /**
136
- * The block's type: the component's label, else `block.gap` ("Gap") for text that holds a graded component and
137
- * `block.text` ("Text") for the rest.
151
+ * The block's type: the component's label, `block.check` ("Check button") for a Check element, else `block.gap`
152
+ * ("Gap") for text that holds a graded component and `block.text` ("Text") for the rest.
138
153
  */
139
154
  readonly label: string;
140
155
  /** The sum of its components' points, or null when none of them is graded. */
141
156
  readonly points: number | null;
142
- /** Its component, or the components in its text, in document order. */
157
+ /** Its component, or the components in its text, in document order; none for a Check element. */
143
158
  readonly components: readonly OutlineComponent[];
144
- /** Issues located on its components. */
159
+ /** Issues located on its components, or on the Check element. */
145
160
  readonly errors: number;
146
161
  readonly warnings: number;
147
162
  }
163
+ /** A Check element of a page (`<astl-check>`): the questions it checks, as the engine and the player take them. */
164
+ export interface OutlineCheck {
165
+ /** Its source id, or null when it has none. */
166
+ readonly id: string | null;
167
+ /** Its `label`, the text of its button, or null without one (the button says "Check"). */
168
+ readonly label: string | null;
169
+ /**
170
+ * The source ids of the graded questions it checks, in order (`planChecks`): those its `for` names on its page, else
171
+ * the graded inline questions of the run of text right above it; none that a Check element before it has.
172
+ */
173
+ readonly targets: readonly string[];
174
+ }
148
175
  export interface OutlinePage {
149
176
  /** null for the implicit page of a document without pages. */
150
177
  readonly id: string | null;
@@ -160,6 +187,14 @@ export interface OutlinePage {
160
187
  readonly components: readonly OutlineComponent[];
161
188
  /** Its content as blocks, in order. */
162
189
  readonly blocks: readonly OutlineBlock[];
190
+ /** Its Check elements, in reading order (in its layouts' columns too). */
191
+ readonly checks: readonly OutlineCheck[];
192
+ /**
193
+ * Its automatic Checks, where practice checks one question at a time: the source ids of the graded questions of each
194
+ * run of text that no Check element has, when there are two or more, in order. The player puts one Check after the
195
+ * last of them that checks them at once; a question alone keeps its own.
196
+ */
197
+ readonly automatic: readonly (readonly string[])[];
163
198
  /** The sum of its blocks' points, or null when nothing on it is graded. */
164
199
  readonly points: number | null;
165
200
  }
@@ -253,9 +288,10 @@ export interface Authoring {
253
288
  */
254
289
  withCompanion(tag: string, source: string, id?: string): string | null;
255
290
  /**
256
- * The inspector model of one component element (source HTML), or null for elements it does not know. With the
257
- * whole document (`source`), fields offer what other elements hold (the words of the bank a drop takes its words
258
- * from); without it they show the attribute's own control.
291
+ * The inspector model of one component element (source HTML), or of a Check element (`astl-check`: its button's text
292
+ * and a `check-targets` field), or null for elements it does not know. With the whole document (`source`), fields
293
+ * offer what other elements hold (the words of the bank a drop takes its words from, the questions of a check's page)
294
+ * and a question a Check element checks says which (`checkedBy`); without it they show the attribute's own control.
259
295
  */
260
296
  inspect(elementHtml: string, source?: string): InspectorModel | null;
261
297
  /**
@@ -275,7 +311,7 @@ export interface Authoring {
275
311
  * `page: false`, without its page ("Question 2").
276
312
  */
277
313
  describe(issue: Issue, source?: string, options?: DescribeOptions): string;
278
- /** `source` with fresh ids on pages and components that lack one (or have an empty one). */
314
+ /** `source` with fresh ids on pages, components and Check elements that lack one (or have an empty one). */
279
315
  assignIds(source: string): string;
280
316
  /** Pages, their blocks and components, points and issue counts. */
281
317
  outline(source: string): Outline;
@@ -1 +1 @@
1
- {"version":3,"file":"authoring.d.ts","sourceRoot":"","sources":["../src/authoring.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EACL,KAAK,aAAa,EAMlB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EAGnB,KAAK,MAAM,EAEX,KAAK,KAAK,EAIV,KAAK,cAAc,EACnB,KAAK,aAAa,EAQlB,KAAK,aAAa,EAElB,KAAK,SAAS,EACd,KAAK,gBAAgB,EACtB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAkB,KAAK,YAAY,EAA2B,MAAM,cAAc,CAAC;AAC1F,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,KAAK,eAAe,EAAiB,MAAM,WAAW,CAAC;AAChE,OAAO,EAAE,KAAK,cAAc,EAA4D,MAAM,cAAc,CAAC;AAe7G,OAAO,EAAiC,KAAK,UAAU,EAAE,KAAK,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAE1G,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,wGAAwG;IACxG,QAAQ,CAAC,WAAW,EAAE,SAAS,gBAAgB,EAAE,CAAC;IAClD,2DAA2D;IAC3D,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,YAAY,EAAE,CAAC;IAC5C,8DAA8D;IAC9D,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,2EAA2E;IAC3E,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,cAAc,EAAE,CAAC;IAC9C;;;;OAIG;IACH,QAAQ,CAA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G,MAAM,CAAC;IAC7D,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,gBAAgB,CAAC;IAC3C;;;;;;OAMG;IACH,QAAQ,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,MAAM,CAAC;IAC3E,4GAA4G;IAC5G,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IAClC,mEAAmE;IACnE,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;IACjC;;;;;OAKG;IACH,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACpE;;;OAGG;IACH,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;CAC3E;AAuDD,wBAAgB,eAAe,CAAC,OAAO,EAAE,gBAAgB,GAAG,SAAS,CA6nBpE"}
package/dist/authoring.js CHANGED
@@ -2,11 +2,11 @@
2
2
  * createAuthoring: the editor-independent logic of the authoring kit. Pure (no DOM), so hosts, agents and tests can
3
3
  * use it in any runtime; the web components and adapters are thin layers on top.
4
4
  */
5
- import { COLUMN_TAG, COLUMNS_TAG, createI18n, DOC_TAG, ENGINE_NAMESPACE, element, isElement, isSafeUrl, isSourceId, PAGE_CHECK_ATTRIBUTE, PAGE_TAG, SCORING_ATTRIBUTES, STYLE_TAG, STYLE_TEMPLATE_ATTRIBUTE, strictUrlPolicy, } from '@astl/core';
5
+ import { CHECK_FOR_ATTRIBUTE, CHECK_LABEL_ATTRIBUTE, CHECK_TAG, COLUMN_TAG, COLUMNS_TAG, checkFor, checkNodes, checkParts, createI18n, DOC_TAG, ENGINE_NAMESPACE, element, isCheckable, isElement, isSafeUrl, isSourceId, PAGE_CHECK_ATTRIBUTE, PAGE_TAG, planChecks, SCORING_ATTRIBUTES, STYLE_TAG, STYLE_TEMPLATE_ATTRIBUTE, strictUrlPolicy, } from '@astl/core';
6
6
  import { cleanStyle, isStyleName } from '@astl/core/declarations';
7
7
  import { engineMessages, localChecker, parseHtml } from '@astl/engine';
8
8
  import { updateElement } from './edit.js';
9
- import { inspectorModel, styleTemplateField } from './inspect.js';
9
+ import { inspectorModel, styleTemplateField, } from './inspect.js';
10
10
  import { EDITOR_NAMESPACE, editorMessages } from './messages.js';
11
11
  import { setPageCheckSource } from './pages.js';
12
12
  import { applyEdits, attributeValue, elementTree, escapeHtml, scanElements, scanRanges, tokenize, usedIds, } from './scan.js';
@@ -83,6 +83,37 @@ export function pictureHtml(picture) {
83
83
  const caption = String(picture.caption ?? '').trim();
84
84
  return caption === '' ? img : `<figure>${img}<figcaption>${escapeHtml(caption)}</figcaption></figure>`;
85
85
  }
86
+ /**
87
+ * Inserts a Check element (`astl-check`) at the cursor, as the insert menu's "Check button" does, for a host's own menu
88
+ * (its label and line: the kit's messages `insert.check` and `insert.check.description`). It goes where
89
+ * `EditorAdapter.insert` puts a block, after the block the cursor is in, with a fresh id (`check-<n>`), and its `for`
90
+ * names the questions it takes there: the graded inline questions of the run of text right above it
91
+ * (`OutlineCheck.targets`), so moving text later does not change what it checks. The TipTap adapter selects it and
92
+ * makes the insert one undo step. Returns its source HTML.
93
+ */
94
+ export function insertCheck(authoring, adapter) {
95
+ const used = usedIds(adapter.getSource());
96
+ let n = 1;
97
+ while (used.has(`check-${n}`))
98
+ n++;
99
+ const id = `check-${n}`;
100
+ let html = `<${CHECK_TAG} id="${id}"></${CHECK_TAG}>`;
101
+ adapter.insert(html);
102
+ const targets = authoring
103
+ .outline(adapter.getSource())
104
+ .pages.flatMap((page) => page.checks)
105
+ .find((check) => check.id === id)?.targets;
106
+ const current = adapter.getElement(id);
107
+ if (current !== null && targets !== undefined && targets.length > 0) {
108
+ html = authoring.update(current, {
109
+ kind: 'attribute',
110
+ name: CHECK_FOR_ATTRIBUTE,
111
+ value: targets.join(' '),
112
+ });
113
+ adapter.replaceElement(id, html);
114
+ }
115
+ return html;
116
+ }
86
117
  /** 128 random bits as hex: mixed into every preview, so preview ids never match published views. */
87
118
  function sessionSalt() {
88
119
  const bytes = crypto.getRandomValues(new Uint8Array(16));
@@ -203,22 +234,73 @@ export function createAuthoring(options) {
203
234
  const n = Object.hasOwn(node.attrs, 'points') ? Number(node.attrs.points) : Number.NaN;
204
235
  return Number.isFinite(n) && n > 0 ? n : DEFAULT_POINTS;
205
236
  };
237
+ /** An element's own id, or null without one (or with an empty one). */
238
+ const ownId = (node) => Object.hasOwn(node.attrs, 'id') && node.attrs.id !== '' ? (node.attrs.id ?? null) : null;
239
+ /**
240
+ * The Check elements of a page's content (or a document's without pages), each with its questions, as the engine
241
+ * resolves them (`planChecks`): a `for` keeps the graded questions of the page it names. And the automatic ones: the
242
+ * questions of each run of text that none has, two or more.
243
+ */
244
+ const checksOf = (content) => {
245
+ const questions = new Set();
246
+ const collect = (nodes) => {
247
+ for (const node of nodes) {
248
+ if (node.type !== 'element')
249
+ continue;
250
+ const manifest = registered.get(node.tag);
251
+ const id = ownId(node);
252
+ if (manifest === undefined)
253
+ collect(node.children);
254
+ else if (isCheckable(manifest) && id !== null)
255
+ questions.add(id);
256
+ }
257
+ };
258
+ collect(content);
259
+ const tree = {
260
+ tag: (node) => (node.type === 'element' ? node.tag : null),
261
+ children: (node) => (node.type === 'element' ? node.children : []),
262
+ component: (node) => {
263
+ const manifest = node.type === 'element' ? registered.get(node.tag) : undefined;
264
+ if (manifest === undefined || node.type !== 'element')
265
+ return null;
266
+ return { id: ownId(node), graded: isCheckable(manifest), block: manifest.display === 'block' };
267
+ },
268
+ checkFor: (node) => node.type === 'element' && Object.hasOwn(node.attrs, CHECK_FOR_ATTRIBUTE)
269
+ ? checkFor(node.attrs[CHECK_FOR_ATTRIBUTE]).filter((id) => questions.has(id))
270
+ : null,
271
+ };
272
+ const { targets, uncovered } = planChecks(checkParts(content, tree));
273
+ const checks = checkNodes(content, tree).map((node, k) => {
274
+ const attrs = node.type === 'element' ? node.attrs : {};
275
+ return {
276
+ id: node.type === 'element' ? ownId(node) : null,
277
+ label: Object.hasOwn(attrs, CHECK_LABEL_ATTRIBUTE) ? (attrs[CHECK_LABEL_ATTRIBUTE] ?? null) : null,
278
+ targets: targets[k] ?? [],
279
+ };
280
+ });
281
+ return { checks, automatic: uncovered.filter((run) => run.length > 1) };
282
+ };
283
+ /** The last outline: an inspector asks for it on every render, for the same source. */
284
+ let outlined = null;
206
285
  const outline = (source) => {
286
+ if (outlined?.source === source)
287
+ return outlined.outline;
207
288
  const { issues } = engine.validate(source);
208
289
  const idOf = (node) => (Object.hasOwn(node.attrs, 'id') ? (node.attrs.id ?? null) : null);
209
- const entry = (node) => {
290
+ const entry = (node, checkOf) => {
210
291
  const id = idOf(node);
211
292
  const counts = count(issues, (i) => id !== null && i.at.element === id);
212
- return { id, tag: node.tag, label: labelOf(node.tag), points: pointsOf(node), ...counts };
293
+ const check = (id === null ? undefined : checkOf.get(id)) ?? null;
294
+ return { id, tag: node.tag, label: labelOf(node.tag), points: pointsOf(node), check, ...counts };
213
295
  };
214
- const components = (nodes, out = []) => {
296
+ const components = (nodes, checkOf, out = []) => {
215
297
  for (const node of nodes) {
216
298
  if (node.type !== 'element')
217
299
  continue;
218
300
  if (registered.has(node.tag))
219
- out.push(entry(node));
301
+ out.push(entry(node, checkOf));
220
302
  else
221
- components(node.children, out);
303
+ components(node.children, checkOf, out);
222
304
  }
223
305
  return out;
224
306
  };
@@ -236,12 +318,12 @@ export function createAuthoring(options) {
236
318
  ...count(issues, (i) => i.at.element !== null && ids.has(i.at.element)),
237
319
  };
238
320
  };
239
- const blocks = (content) => {
321
+ const blocks = (content, checkOf) => {
240
322
  const out = [];
241
323
  let run = [];
242
324
  const flush = () => {
243
325
  if (run.some((n) => n.type === 'element' || n.value.trim() !== ''))
244
- out.push(block('text', null, components(run)));
326
+ out.push(block('text', null, components(run, checkOf)));
245
327
  run = [];
246
328
  };
247
329
  for (const node of content) {
@@ -250,12 +332,25 @@ export function createAuthoring(options) {
250
332
  flush();
251
333
  for (const column of node.children) {
252
334
  if (isElement(column, COLUMN_TAG))
253
- out.push(...blocks(column.children));
335
+ out.push(...blocks(column.children, checkOf));
254
336
  }
255
337
  }
338
+ else if (node.type === 'element' && node.tag === CHECK_TAG) {
339
+ flush();
340
+ const id = idOf(node);
341
+ out.push({
342
+ kind: 'check',
343
+ id,
344
+ tag: CHECK_TAG,
345
+ label: t(EDITOR_NAMESPACE, 'block.check'),
346
+ points: null,
347
+ components: [],
348
+ ...count(issues, (i) => id !== null && i.at.element === id),
349
+ });
350
+ }
256
351
  else if (node.type === 'element' && registered.get(node.tag)?.display === 'block') {
257
352
  flush();
258
- out.push(block('component', node, [entry(node)]));
353
+ out.push(block('component', node, [entry(node, checkOf)]));
259
354
  }
260
355
  else {
261
356
  run.push(node);
@@ -265,14 +360,23 @@ export function createAuthoring(options) {
265
360
  return out;
266
361
  };
267
362
  const page = (id, label, content, check = false) => {
268
- const list = blocks(content);
363
+ const { checks, automatic } = checksOf(content);
364
+ const checkOf = new Map();
365
+ for (const one of checks) {
366
+ if (one.id !== null)
367
+ for (const target of one.targets)
368
+ checkOf.set(target, one.id);
369
+ }
370
+ const list = blocks(content, checkOf);
269
371
  return {
270
372
  id,
271
373
  label,
272
374
  check,
273
375
  ...count(issues, (i) => id === null ? i.at.page === null && i.at.tag !== null && i.at.tag !== DOC_TAG : i.at.page === id),
274
- components: components(content),
376
+ components: components(content, checkOf),
275
377
  blocks: list,
378
+ checks,
379
+ automatic,
276
380
  points: sum(list.map((b) => b.points)),
277
381
  };
278
382
  };
@@ -303,7 +407,9 @@ export function createAuthoring(options) {
303
407
  else {
304
408
  pages.push(page(null, null, content));
305
409
  }
306
- return { pages, ...count(issues, () => true), points: sum(pages.map((p) => p.points)) };
410
+ const result = { pages, ...count(issues, () => true), points: sum(pages.map((p) => p.points)) };
411
+ outlined = { source, outline: result };
412
+ return result;
307
413
  };
308
414
  let named = null;
309
415
  const namesIn = (source) => {
@@ -347,7 +453,9 @@ export function createAuthoring(options) {
347
453
  text = false;
348
454
  continue;
349
455
  }
350
- if (node.type === 'element' && registered.get(node.tag)?.display === 'block') {
456
+ // A Check element is a block of its own, as in `outline`.
457
+ if (node.type === 'element' &&
458
+ (node.tag === CHECK_TAG || registered.get(node.tag)?.display === 'block')) {
351
459
  block++;
352
460
  text = false;
353
461
  set(node, block, page);
@@ -381,9 +489,11 @@ export function createAuthoring(options) {
381
489
  for (const { tag, id, range } of scanRanges(source)) {
382
490
  if (id !== null && id.trim() !== '')
383
491
  continue;
384
- if (tag !== PAGE_TAG && !registered.has(tag))
492
+ if (tag !== PAGE_TAG && tag !== CHECK_TAG && !registered.has(tag))
385
493
  continue;
386
- const prefix = tag === PAGE_TAG ? 'page' : (byTag.get(tag)?.idPrefix ?? tag.replace(/^astl-/, ''));
494
+ const prefix = tag === PAGE_TAG || tag === CHECK_TAG
495
+ ? tag.replace(/^astl-/, '')
496
+ : (byTag.get(tag)?.idPrefix ?? tag.replace(/^astl-/, ''));
387
497
  const fresh = freshId(isSourceId(`${prefix}-1`) ? prefix : 'item', used);
388
498
  used.add(fresh);
389
499
  const written = range.startTag.attributes.find((a) => a.name === 'id');
@@ -435,6 +545,81 @@ export function createAuthoring(options) {
435
545
  // A starter can hold more components (gaps and their word bank): those it writes without an id get fresh ones.
436
546
  return linkCompanions(withIds(html, used), source, used);
437
547
  }
548
+ /** How a Check element of a page is named: its label in quotes, else by its number among the page's ("Check button 2"). */
549
+ const checkName = (checks, id) => {
550
+ const index = checks.findIndex((check) => check.id === id);
551
+ const label = checks[index]?.label?.trim() ?? '';
552
+ return label === ''
553
+ ? t(EDITOR_NAMESPACE, 'check.name', { n: index + 1 })
554
+ : t(EDITOR_NAMESPACE, 'check.named', { label });
555
+ };
556
+ /**
557
+ * The inspector model of a Check element: its button's text, and which questions of its page it checks, each named
558
+ * as authors know it ("Gap 2"); a question another Check element has says which. Without the document, the questions
559
+ * its `for` names, by id.
560
+ */
561
+ const inspectCheck = (el, source) => {
562
+ const id = ownId(el);
563
+ const text = (key, params) => t(EDITOR_NAMESPACE, key, params);
564
+ const page = source === undefined || id === null
565
+ ? undefined
566
+ : outline(source).pages.find((p) => p.checks.some((check) => check.id === id));
567
+ const names = page === undefined || source === undefined ? null : namesIn(source);
568
+ const own = page?.checks.find((check) => check.id === id)?.targets ?? checkFor(el.attrs[CHECK_FOR_ATTRIBUTE]);
569
+ const targets = page === undefined
570
+ ? own.map((target) => ({ id: target, label: target, checked: true, other: null }))
571
+ : page.components.flatMap((component) => {
572
+ const manifest = manifestOf(component.tag);
573
+ if (component.id === null || manifest === null || !isCheckable(manifest))
574
+ return [];
575
+ const n = names?.get(component.id)?.n;
576
+ const by = component.check;
577
+ return [
578
+ {
579
+ id: component.id,
580
+ label: n === undefined ? component.label : text('check.target', { type: component.label, n }),
581
+ checked: own.includes(component.id),
582
+ other: by !== null && by !== id ? checkName(page.checks, by) : null,
583
+ },
584
+ ];
585
+ });
586
+ return {
587
+ tag: CHECK_TAG,
588
+ id,
589
+ label: text('block.check'),
590
+ icon: 'check',
591
+ fields: [
592
+ {
593
+ kind: 'attribute',
594
+ control: 'text',
595
+ name: CHECK_LABEL_ATTRIBUTE,
596
+ label: text('check.labelField'),
597
+ help: text('check.labelHelp'),
598
+ value: Object.hasOwn(el.attrs, CHECK_LABEL_ATTRIBUTE)
599
+ ? (el.attrs[CHECK_LABEL_ATTRIBUTE] ?? '')
600
+ : '',
601
+ required: false,
602
+ accept: null,
603
+ },
604
+ {
605
+ kind: 'check-targets',
606
+ name: CHECK_FOR_ATTRIBUTE,
607
+ label: text('check.targets'),
608
+ help: text('check.targetsHelp'),
609
+ targets,
610
+ },
611
+ ],
612
+ };
613
+ };
614
+ /** The Check element that checks the question `id` in `source`, with its name, or null. */
615
+ const checkedBy = (source, id) => {
616
+ for (const page of outline(source).pages) {
617
+ const by = page.components.find((component) => component.id === id)?.check ?? null;
618
+ if (by !== null)
619
+ return { id: by, name: checkName(page.checks, by) };
620
+ }
621
+ return null;
622
+ };
438
623
  return {
439
624
  engine,
440
625
  locale,
@@ -498,6 +683,8 @@ export function createAuthoring(options) {
498
683
  const el = firstElement(parseHtml(elementHtml));
499
684
  if (el === null)
500
685
  return null;
686
+ if (el.tag === CHECK_TAG)
687
+ return inspectCheck(el, source);
501
688
  const manifest = manifestOf(el.tag);
502
689
  if (manifest === null)
503
690
  return null;
@@ -509,7 +696,10 @@ export function createAuthoring(options) {
509
696
  const at = scanElements(source).find((e) => e.id === id);
510
697
  return at === undefined ? null : firstElement(parseHtml(source.slice(at.start, at.end)));
511
698
  };
512
- return inspectorModel(el, manifest, byTag.get(el.tag) ?? null, textsFor(manifest), templates, find);
699
+ const model = inspectorModel(el, manifest, byTag.get(el.tag) ?? null, textsFor(manifest), templates, find);
700
+ const id = ownId(el);
701
+ const by = source === undefined || id === null || !isCheckable(manifest) ? null : checkedBy(source, id);
702
+ return by === null ? model : { ...model, checkedBy: by };
513
703
  },
514
704
  inspectDocument(source) {
515
705
  // The scanner, as `update` uses it: the document is the first start tag (and no full parse per keystroke).