@astl/engine 0.5.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +50 -0
- package/dist/analyse.d.ts.map +1 -1
- package/dist/analyse.js +458 -21
- package/dist/analyse.js.map +1 -1
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +7 -4
- package/dist/compile.js.map +1 -1
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +16 -2
- package/dist/engine.js.map +1 -1
- package/dist/guard.d.ts.map +1 -1
- package/dist/guard.js +5 -2
- package/dist/guard.js.map +1 -1
- package/dist/messages/en.json +4 -0
- package/dist/messages/pl.json +4 -0
- package/package.json +2 -2
- package/src/analyse.ts +512 -23
- package/src/compile.ts +8 -3
- package/src/engine.ts +23 -1
- package/src/guard.ts +6 -1
- package/src/messages/en.json +4 -0
- package/src/messages/pl.json +4 -0
package/src/compile.ts
CHANGED
|
@@ -31,6 +31,8 @@ import {
|
|
|
31
31
|
type ScoringGroup,
|
|
32
32
|
type SlotKind,
|
|
33
33
|
STYLE_TEMPLATE_ATTRIBUTE,
|
|
34
|
+
TABLE_TAG,
|
|
35
|
+
TASK_TAG,
|
|
34
36
|
type UrlPolicy,
|
|
35
37
|
} from '@astl/core';
|
|
36
38
|
import type { ComponentRecord, DocRecord, HelpRecord } from './analyse.js';
|
|
@@ -158,6 +160,9 @@ export async function compileDocument(doc: DocRecord, setup: CompileSetup): Prom
|
|
|
158
160
|
const viewNode = (node: Node): Node => {
|
|
159
161
|
if (node.type === 'text') return node;
|
|
160
162
|
const rec = doc.components.get(node);
|
|
163
|
+
// A task's own Check is a Check element at its end, as one written there would be.
|
|
164
|
+
if (rec === undefined && node.tag === TASK_TAG)
|
|
165
|
+
return element(node.tag, node.attrs, [...viewNodes(node.children), ...viewCheck(node)]);
|
|
161
166
|
if (rec === undefined) return element(node.tag, node.attrs, viewNodes(node.children));
|
|
162
167
|
const ctx = contextOf(rec);
|
|
163
168
|
const view = rec.definition.toView(rec.element, ctx);
|
|
@@ -201,8 +206,8 @@ export async function compileDocument(doc: DocRecord, setup: CompileSetup): Prom
|
|
|
201
206
|
const open: string[] = [];
|
|
202
207
|
for (const rec of doc.components.values()) {
|
|
203
208
|
const manifest = rec.definition.manifest;
|
|
204
|
-
// Ungraded types without slot kinds (flash cards, media) have nothing to answer.
|
|
205
|
-
if (manifest.slotKinds.length === 0) continue;
|
|
209
|
+
// Ungraded types without slot kinds (flash cards, media) have nothing to answer; an example is answered already.
|
|
210
|
+
if (manifest.slotKinds.length === 0 || rec.definition.example?.(rec.element)) continue;
|
|
206
211
|
const ctx = contextOf(rec);
|
|
207
212
|
const page = pageIds[rec.page] as string;
|
|
208
213
|
const groupId = ctx.opaque();
|
|
@@ -295,7 +300,7 @@ export async function compileDocument(doc: DocRecord, setup: CompileSetup): Prom
|
|
|
295
300
|
}
|
|
296
301
|
|
|
297
302
|
const isBlock = (node: Node): boolean =>
|
|
298
|
-
isElement(node) && (BLOCK_TAGS.has(node.tag) || node.tag === FIGURE_TAG);
|
|
303
|
+
isElement(node) && (BLOCK_TAGS.has(node.tag) || node.tag === FIGURE_TAG || node.tag === TABLE_TAG);
|
|
299
304
|
|
|
300
305
|
/**
|
|
301
306
|
* The HTML of help content as a browser rebuilds it, like the view's (see the end of `compileDocument`). Blocks lose
|
package/src/engine.ts
CHANGED
|
@@ -4,6 +4,10 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import {
|
|
6
6
|
allAttributes,
|
|
7
|
+
BADGE_TAG,
|
|
8
|
+
BOX_LABEL_TAG,
|
|
9
|
+
BOX_TAG,
|
|
10
|
+
BOX_TITLE_TAG,
|
|
7
11
|
CLASS_ATTRIBUTE,
|
|
8
12
|
COLUMN_TAG,
|
|
9
13
|
COLUMNS_TAG,
|
|
@@ -21,6 +25,7 @@ import {
|
|
|
21
25
|
type EngineOptions,
|
|
22
26
|
HELP_ATTRIBUTES,
|
|
23
27
|
HELP_TAGS,
|
|
28
|
+
INSTRUCTION_TAG,
|
|
24
29
|
isSafeUrl,
|
|
25
30
|
isStyleTemplate,
|
|
26
31
|
type NormalisationProfile,
|
|
@@ -30,7 +35,10 @@ import {
|
|
|
30
35
|
STYLE_TAG,
|
|
31
36
|
STYLE_TEMPLATE_NAME,
|
|
32
37
|
type StyleTemplate,
|
|
38
|
+
SUBTASK_TAG,
|
|
33
39
|
strictUrlPolicy,
|
|
40
|
+
TASK_LABEL_TAG,
|
|
41
|
+
TASK_TAG,
|
|
34
42
|
} from '@astl/core';
|
|
35
43
|
import { parseStyleColor } from '@astl/core/declarations';
|
|
36
44
|
import { analyse } from './analyse.js';
|
|
@@ -44,7 +52,21 @@ const MIN_SECRET_BYTES = 16;
|
|
|
44
52
|
const NAME_PATTERN = /^[a-z][a-z0-9-]*$/;
|
|
45
53
|
const KEBAB = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
46
54
|
/** Elements of the format itself, which no component can be. A child can share a tag: inside its host it wins. */
|
|
47
|
-
const FORMAT_TAGS: ReadonlySet<string> = new Set([
|
|
55
|
+
const FORMAT_TAGS: ReadonlySet<string> = new Set([
|
|
56
|
+
DOC_TAG,
|
|
57
|
+
PAGE_TAG,
|
|
58
|
+
STYLE_TAG,
|
|
59
|
+
COLUMNS_TAG,
|
|
60
|
+
COLUMN_TAG,
|
|
61
|
+
BADGE_TAG,
|
|
62
|
+
BOX_TAG,
|
|
63
|
+
BOX_TITLE_TAG,
|
|
64
|
+
BOX_LABEL_TAG,
|
|
65
|
+
TASK_TAG,
|
|
66
|
+
INSTRUCTION_TAG,
|
|
67
|
+
TASK_LABEL_TAG,
|
|
68
|
+
SUBTASK_TAG,
|
|
69
|
+
]);
|
|
48
70
|
|
|
49
71
|
function checkManifest(manifest: ComponentManifest, slotKinds: ReadonlyMap<string, SlotKind>): void {
|
|
50
72
|
const tag = manifest.tag;
|
package/src/guard.ts
CHANGED
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
isOpaqueId,
|
|
18
18
|
LANGUAGE_TAG_PATTERN,
|
|
19
19
|
type Node,
|
|
20
|
+
TABLE_TAGS,
|
|
20
21
|
TAG_ATTRIBUTES,
|
|
21
22
|
URL_ATTRIBUTES,
|
|
22
23
|
type UrlPolicy,
|
|
@@ -141,7 +142,11 @@ function contentProblem(
|
|
|
141
142
|
continue;
|
|
142
143
|
}
|
|
143
144
|
const inline = INLINE_TAGS.has(node.tag) || node.tag === BADGE_TAG;
|
|
144
|
-
const block =
|
|
145
|
+
const block =
|
|
146
|
+
BLOCK_TAGS.has(node.tag) ||
|
|
147
|
+
node.tag === FIGURE_TAG ||
|
|
148
|
+
node.tag === CAPTION_TAG ||
|
|
149
|
+
TABLE_TAGS.has(node.tag);
|
|
145
150
|
if (!inline && !(blocks && block)) return `writes <${node.tag}>`;
|
|
146
151
|
if (node.tag === BADGE_TAG && node.children.some((child) => child.type !== 'text'))
|
|
147
152
|
return `writes an element in <${BADGE_TAG}>`;
|
package/src/messages/en.json
CHANGED
|
@@ -40,6 +40,10 @@
|
|
|
40
40
|
"STYLE_LOW_CONTRAST": "The text of element {tag} is hard to read on its background: contrast {ratio}:1, at least {min}:1 is recommended.",
|
|
41
41
|
"COLUMNS_INVALID": "Element {tag} is not a valid layout: <astl-columns> goes directly on a page and holds 2 to 4 <astl-column> elements, with nothing else between them, and layouts do not nest.",
|
|
42
42
|
"BADGE_TOO_LONG": "This badge holds more than {max} characters: keep a badge to a number or a word or two, and write longer text beside it.",
|
|
43
|
+
"BOX_NESTED": "A frame cannot stand inside another frame: put it after the frame, or use a heading inside it.",
|
|
44
|
+
"TASK_NESTED": "A task cannot stand inside another task: put it after the task, or make it a sub-task (astl-subtask).",
|
|
45
|
+
"TABLE_INVALID": "A table holds a caption (<caption>, optional, first), then rows (<tr>) in a head (<thead>) and bodies (<tbody>), and each row cells (<th>, <td>) that cover the same columns as the other rows; a span (colspan, rowspan) stays within the rows of its part.",
|
|
46
|
+
"TABLE_TOO_LARGE": "A table has at most {maxColumns} columns and {maxRows} rows; this one has {columns} columns and {rows} rows.",
|
|
43
47
|
"HELP_UNGRADED": "Element <{tag}> works only inside a graded interaction or on a page with one. Move it there: for now it is left out.",
|
|
44
48
|
"HELP_EMPTY": "Element <{tag}> is empty, so it is left out. Write its text or remove it.",
|
|
45
49
|
"PAGE_HELP_UNCHECKED": "Page {page}{titled, select, yes { (“{title}”)} other {}} has help for students but no Check of its own: turn on “Check this page”. Until then the player adds that Check by itself.",
|
package/src/messages/pl.json
CHANGED
|
@@ -40,6 +40,10 @@
|
|
|
40
40
|
"STYLE_LOW_CONTRAST": "Tekst elementu {tag} jest trudny do odczytania na swoim tle: kontrast {ratio}:1, zalecane co najmniej {min}:1.",
|
|
41
41
|
"COLUMNS_INVALID": "Element {tag} nie tworzy poprawnego układu: <astl-columns> stoi bezpośrednio na stronie i zawiera od 2 do 4 elementów <astl-column>, bez niczego między nimi, a układów nie można zagnieżdżać.",
|
|
42
42
|
"BADGE_TOO_LONG": "Ten znaczek ma więcej niż {max} znaków: w znaczku zostaw liczbę albo słowo lub dwa, a dłuższy tekst napisz obok.",
|
|
43
|
+
"BOX_NESTED": "Ramki nie można wstawić do innej ramki: postaw ją za ramką albo użyj w niej nagłówka.",
|
|
44
|
+
"TASK_NESTED": "Zadania nie można wstawić do innego zadania: postaw je za zadaniem albo zrób z niego podpunkt (astl-subtask).",
|
|
45
|
+
"TABLE_INVALID": "Tabela zawiera podpis (<caption>, opcjonalny, na początku), potem wiersze (<tr>) w nagłówku (<thead>) i treści (<tbody>), a każdy wiersz komórki (<th>, <td>) zajmujące te same kolumny co inne wiersze; scalenie (colspan, rowspan) nie wychodzi poza wiersze swojej części.",
|
|
46
|
+
"TABLE_TOO_LARGE": "Tabela ma najwyżej {maxColumns} kolumn i {maxRows} wierszy; ta ma kolumn: {columns}, wierszy: {rows}.",
|
|
43
47
|
"HELP_UNGRADED": "Element <{tag}> działa tylko w ocenianym zadaniu albo na stronie z takim zadaniem. Przenieś go tam: na razie jest pominięty.",
|
|
44
48
|
"HELP_EMPTY": "Element <{tag}> jest pusty, więc jest pominięty. Wpisz jego treść albo go usuń.",
|
|
45
49
|
"PAGE_HELP_UNCHECKED": "Strona {page}{titled, select, yes { („{title}”)} other {}} ma pomoc dla uczniów, ale nie ma własnego sprawdzania: włącz „Sprawdź tę stronę”. Do tego czasu odtwarzacz sam dodaje to sprawdzanie.",
|