@astl/engine 0.6.0 → 0.8.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 +54 -0
- package/dist/analyse.d.ts.map +1 -1
- package/dist/analyse.js +224 -15
- package/dist/analyse.js.map +1 -1
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +4 -4
- package/dist/compile.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 +2 -0
- package/dist/messages/pl.json +2 -0
- package/package.json +2 -2
- package/src/analyse.ts +253 -17
- package/src/compile.ts +4 -3
- package/src/guard.ts +6 -1
- package/src/messages/en.json +2 -0
- package/src/messages/pl.json +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,59 @@
|
|
|
1
1
|
# @astl/engine
|
|
2
2
|
|
|
3
|
+
## 0.8.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 33d162e: Questions in table cells: a data cell (`td`) may hold one block component, a choice, true or false or a long answer
|
|
8
|
+
standing in the cell, with text before it, and rich blocks (paragraphs, lists) beside inline content. A second one in
|
|
9
|
+
a cell, or one in a header cell or deeper in a cell, is `PLACEMENT_INVALID`; a header cell keeps inline content only.
|
|
10
|
+
The player gives a question in a cell the width it works at (10em at least), its row as tall as it is, and a table
|
|
11
|
+
that cannot fit even wrapped tight now gets at most a third more room than that tightest layout (a table of short
|
|
12
|
+
cells still unwraps whole), so sentences stay readable beside their questions. The TipTap surface keeps a question in
|
|
13
|
+
its cell (loose text before it goes in a paragraph), one at most.
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Updated dependencies [10b5c29]
|
|
18
|
+
- @astl/core@0.8.0
|
|
19
|
+
|
|
20
|
+
## 0.7.0
|
|
21
|
+
|
|
22
|
+
### Minor Changes
|
|
23
|
+
|
|
24
|
+
- 8ae6707: Tables in rich text: `table`, `caption`, `thead`, `tbody`, `tr`, `th` (`scope`, `colspan`, `rowspan`) and `td`
|
|
25
|
+
(`colspan`, `rowspan`), a block wherever a figure may be. Cells and the caption hold inline content, inline components
|
|
26
|
+
among it, which keep their ids and slots as anywhere. The source is read as a browser reads it; what stays broken is
|
|
27
|
+
`TABLE_INVALID` (parts out of order or missing, rows that cover different columns, a span past its rows), more than
|
|
28
|
+
12 columns or 50 rows `TABLE_TOO_LARGE`. The style allow-list adds `border-collapse` and `border-spacing`; tag rules
|
|
29
|
+
and named styles reach every part.
|
|
30
|
+
|
|
31
|
+
The player draws a table as wide as its column, its head tinted and its row headers lighter (lines only in high
|
|
32
|
+
contrast), in a box of its own that scrolls sideways when the table is too wide, never the page: at its content
|
|
33
|
+
width when it cannot fit wrapped tight, with fading edges where there is more to see, the box then a stop of the
|
|
34
|
+
keyboard named by the caption ("Table" otherwise). Fields in cells (a gap, a select, a drop) keep their size and
|
|
35
|
+
their words whole instead of being squeezed: inline components read `--astl-inline-line`, `--astl-inline-wrap`,
|
|
36
|
+
`--astl-inline-hyphens` and `--astl-inline-min`, which a cell sets. The TipTap surface keeps tables, their cells
|
|
37
|
+
written in place, a wide one scrolling in its box; tools to change a table's shape come with the table's editing.
|
|
38
|
+
- 0f89c80: Worked examples: a gap, a long answer or a select with `example` (public) is answered already, so students see what
|
|
39
|
+
to do before they start. A gap and a long answer show its text, a select the option whose id it holds as chosen;
|
|
40
|
+
written in by hand (the new tokens `--astl-font-hand`, a system cursive stack, and `--astl-example-ink`, in every
|
|
41
|
+
theme and built-in look), read-only and never a stop of the keyboard. A gap with boxes shows a letter in each box, a
|
|
42
|
+
long answer its box with its paper. Screen readers read "Example: ..." ("Przykład: ..."); the part is `example`.
|
|
43
|
+
|
|
44
|
+
An example has no slot: it is not graded, adds nothing to the maximum score, is left out of the player's numbers and
|
|
45
|
+
of what counts as unanswered, and needs no answer. A gap's `answer` is no longer required by its manifest: a gap
|
|
46
|
+
without one reports `GAP_ANSWER_MISSING` instead of `ATTRIBUTE_REQUIRED`. New issues: `GAP_EXAMPLE_WITH_ANSWER` and
|
|
47
|
+
`SELECT_EXAMPLE_WITH_CORRECT` (warnings, the example wins), `SELECT_EXAMPLE_UNKNOWN` (an error). The kit offers
|
|
48
|
+
"Example" ("Przykład") for all three, a select's from its own options: an attribute field's `options` without `from`
|
|
49
|
+
lists the element's own children.
|
|
50
|
+
|
|
51
|
+
### Patch Changes
|
|
52
|
+
|
|
53
|
+
- Updated dependencies [8ae6707]
|
|
54
|
+
- Updated dependencies [0f89c80]
|
|
55
|
+
- @astl/core@0.7.0
|
|
56
|
+
|
|
3
57
|
## 0.6.0
|
|
4
58
|
|
|
5
59
|
### Minor Changes
|
package/dist/analyse.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analyse.d.ts","sourceRoot":"","sources":["../src/analyse.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAwBL,KAAK,mBAAmB,EAMxB,KAAK,SAAS,EAId,KAAK,OAAO,EAEZ,KAAK,WAAW,EAOhB,KAAK,eAAe,EAEpB,KAAK,YAAY,EAKjB,KAAK,KAAK,
|
|
1
|
+
{"version":3,"file":"analyse.d.ts","sourceRoot":"","sources":["../src/analyse.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAwBL,KAAK,mBAAmB,EAMxB,KAAK,SAAS,EAId,KAAK,OAAO,EAEZ,KAAK,WAAW,EAOhB,KAAK,eAAe,EAEpB,KAAK,YAAY,EAKjB,KAAK,KAAK,EAiBV,KAAK,IAAI,EACT,KAAK,oBAAoB,EAWzB,KAAK,aAAa,EAoBlB,KAAK,SAAS,EACf,MAAM,YAAY,CAAC;AA0DpB,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,UAAU,EAAE,mBAAmB,CAAC;IACzC,qDAAqD;IACrD,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;IAC9B,QAAQ,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package/dist/analyse.js
CHANGED
|
@@ -2,20 +2,23 @@
|
|
|
2
2
|
* One pass over a source that sanitises it and validates it against the registered manifests. `validate` and
|
|
3
3
|
* `compile` share it: compile only runs on an error-free analysis and works on the sanitised tree it returns.
|
|
4
4
|
*/
|
|
5
|
-
import { allAttributes, BADGE_ATTRIBUTES, BADGE_FILLS, BADGE_SHAPES, BADGE_TAG, BLOCK_TAGS, BOX_ICONS, BOX_LABEL_TAG, BOX_TAG, BOX_TITLE_PLACES, BOX_TITLE_TAG, BOX_VARIANTS, CAPTION_TAG, CHECK_ATTRIBUTES, CHECK_FOR_ATTRIBUTE, CHECK_TAG, CLASS_ATTRIBUTE, COLUMN_TAG, COLUMNS_TAG, CONTENT_ATTRIBUTES, checkFor, checkNodes, checkParts, DEFAULT_DOC_KIND, DOC_ATTRIBUTES, DOC_KINDS, DOC_TAG, directionOf, ENGINE_NAMESPACE, EngineIssue, EXPLANATION_TAG, element, FEEDBACK_TAG, FEEDBACK_VARIANTS, FIGURE_TAG, HELP_TAGS, HINT_TAG, INLINE_TAGS, INSTRUCTION_TAG, isCheckable, isElement, isSourceId, LANGUAGE_TAG_PATTERN, MAX_ATTRIBUTES_PER_ELEMENT, MAX_BADGE_LENGTH, MAX_BADGE_PALETTE, MAX_COLUMNS, MAX_NESTING_DEPTH, MAX_SOURCE_LENGTH, MAX_TASK_LABELS, MAX_TASK_LEVEL, MIN_COLUMNS, PAGE_ATTRIBUTES, PAGE_CHECK_ATTRIBUTE, PAGE_TAG, planChecks, REMOVED_WITH_CONTENT, RULE_TAG, STYLE_TAG, STYLE_TEMPLATE_ATTRIBUTE, SUBTASK_LEVELS, SUBTASK_TAG, SUPPORTED_FORMATS, TAG_ATTRIBUTES, TASK_LABEL_ICONS, TASK_LABEL_TAG, TASK_NUMBERING_ATTRIBUTE, TASK_NUMBERINGS, TASK_TAG, URL_ATTRIBUTES, } from '@astl/core';
|
|
5
|
+
import { allAttributes, BADGE_ATTRIBUTES, BADGE_FILLS, BADGE_SHAPES, BADGE_TAG, BLOCK_TAGS, BOX_ICONS, BOX_LABEL_TAG, BOX_TAG, BOX_TITLE_PLACES, BOX_TITLE_TAG, BOX_VARIANTS, CAPTION_TAG, CHECK_ATTRIBUTES, CHECK_FOR_ATTRIBUTE, CHECK_TAG, CLASS_ATTRIBUTE, COLUMN_TAG, COLUMNS_TAG, CONTENT_ATTRIBUTES, checkFor, checkNodes, checkParts, DEFAULT_DOC_KIND, DOC_ATTRIBUTES, DOC_KINDS, DOC_TAG, directionOf, ENGINE_NAMESPACE, EngineIssue, EXPLANATION_TAG, element, FEEDBACK_TAG, FEEDBACK_VARIANTS, FIGURE_TAG, HELP_TAGS, HINT_TAG, INLINE_TAGS, INSTRUCTION_TAG, isCheckable, isElement, isSourceId, LANGUAGE_TAG_PATTERN, MAX_ATTRIBUTES_PER_ELEMENT, MAX_BADGE_LENGTH, MAX_BADGE_PALETTE, MAX_COLUMNS, MAX_NESTING_DEPTH, MAX_SOURCE_LENGTH, MAX_TABLE_COLUMNS, MAX_TABLE_ROWS, MAX_TASK_LABELS, MAX_TASK_LEVEL, MIN_COLUMNS, PAGE_ATTRIBUTES, PAGE_CHECK_ATTRIBUTE, PAGE_TAG, planChecks, REMOVED_WITH_CONTENT, RULE_TAG, STYLE_TAG, STYLE_TEMPLATE_ATTRIBUTE, SUBTASK_LEVELS, SUBTASK_TAG, SUPPORTED_FORMATS, TABLE_BODY_TAG, TABLE_CAPTION_TAG, TABLE_CELL_TAG, TABLE_HEAD_TAG, TABLE_HEADER_CELL_TAG, TABLE_ROW_TAG, TABLE_SCOPES, TABLE_TAG, TABLE_TAGS, TAG_ATTRIBUTES, TASK_LABEL_ICONS, TASK_LABEL_TAG, TASK_NUMBERING_ATTRIBUTE, TASK_NUMBERINGS, TASK_TAG, URL_ATTRIBUTES, } from '@astl/core';
|
|
6
6
|
import { cleanStyle, isStyleName, MAX_INLINED_STYLES, MAX_STYLE_LENGTH, MAX_STYLE_RULES, mergeStyles, overStyleColor, parseStyleColor, styleContrast, styleText, } from '@astl/core/declarations';
|
|
7
7
|
import { appendText, isHtmlWhitespace, parseSource } from './html.js';
|
|
8
8
|
import { isBooleanValue, parseDecimalValue, parseIntegerValue } from './kit/attributes.js';
|
|
9
9
|
import { mostAttributes } from './limits.js';
|
|
10
10
|
import { round6 } from './round.js';
|
|
11
11
|
/**
|
|
12
|
-
* Where inline components may sit: text-holding blocks, captions and inline formatting, never inside a
|
|
13
|
-
* rule, a line break or a picture holds nothing).
|
|
12
|
+
* Where inline components may sit: text-holding blocks, captions, table cells and inline formatting, never inside a
|
|
13
|
+
* link (and a rule, a line break or a picture holds nothing).
|
|
14
14
|
*/
|
|
15
15
|
const TEXT_PARENTS = new Set([
|
|
16
16
|
...[...BLOCK_TAGS].filter((t) => t !== 'ul' && t !== 'ol' && t !== RULE_TAG),
|
|
17
17
|
...[...INLINE_TAGS].filter((t) => t !== 'a' && t !== 'br' && t !== 'img'),
|
|
18
18
|
CAPTION_TAG,
|
|
19
|
+
TABLE_CAPTION_TAG,
|
|
20
|
+
TABLE_HEADER_CELL_TAG,
|
|
21
|
+
TABLE_CELL_TAG,
|
|
19
22
|
]);
|
|
20
23
|
const DIRECTIONS = new Set(['ltr', 'rtl', 'auto']);
|
|
21
24
|
/** The attributes of `<astl-style>`. */
|
|
@@ -36,6 +39,7 @@ const RULE_TARGETS = new Set([
|
|
|
36
39
|
INSTRUCTION_TAG,
|
|
37
40
|
TASK_LABEL_TAG,
|
|
38
41
|
SUBTASK_TAG,
|
|
42
|
+
...TABLE_TAGS,
|
|
39
43
|
]);
|
|
40
44
|
/** The contrast WCAG asks of normal text (AA); large text may have less, and then the warning is only stricter. */
|
|
41
45
|
const MIN_CONTRAST = 4.5;
|
|
@@ -46,6 +50,61 @@ const noHelp = () => ({ hints: [], explanation: null, feedback: {}, where: [] })
|
|
|
46
50
|
const helpRecord = (parts) => parts.where.length === 0
|
|
47
51
|
? null
|
|
48
52
|
: { hints: parts.hints, explanation: parts.explanation, feedback: parts.feedback };
|
|
53
|
+
/** A cell's `colspan` or `rowspan`: 1 when absent, 0 when it is no whole number from 1 to `max`. */
|
|
54
|
+
function tableSpan(value, max) {
|
|
55
|
+
if (value === undefined)
|
|
56
|
+
return 1;
|
|
57
|
+
const n = parseIntegerValue(value);
|
|
58
|
+
return n !== null && n >= 1 && n <= max ? n : 0;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The columns a table's rows cover, row by row as HTML lays them out: a cell takes the first column no span from a row
|
|
62
|
+
* above holds, and as many as its `colspan`; its `rowspan` holds them in the rows below, within its part (a head, a
|
|
63
|
+
* body, the rows standing directly in the table).
|
|
64
|
+
*/
|
|
65
|
+
class TableGrid {
|
|
66
|
+
rows = 0;
|
|
67
|
+
/** The table's columns: the most any row covers. */
|
|
68
|
+
columns = 0;
|
|
69
|
+
/** What the first row covered: every other row must cover as much. */
|
|
70
|
+
#width = null;
|
|
71
|
+
/** Per column, how many more rows a span from above holds it. */
|
|
72
|
+
#held = [];
|
|
73
|
+
/** A new part: spans never cross into it. */
|
|
74
|
+
start() {
|
|
75
|
+
this.#held = [];
|
|
76
|
+
}
|
|
77
|
+
/** The end of a part: whether a span reached past its last row. */
|
|
78
|
+
end() {
|
|
79
|
+
const past = this.#held.some((n) => n > 0);
|
|
80
|
+
this.#held = [];
|
|
81
|
+
return past;
|
|
82
|
+
}
|
|
83
|
+
/** One row of cells (`[colspan, rowspan]`, 0 for an invalid span, counted as 1): whether it fits the table. */
|
|
84
|
+
row(cells) {
|
|
85
|
+
this.rows++;
|
|
86
|
+
const above = this.#held.map((n) => n > 0);
|
|
87
|
+
const held = this.#held.map((n) => Math.max(0, n - 1));
|
|
88
|
+
let fits = true;
|
|
89
|
+
let at = 0;
|
|
90
|
+
for (const [colspan, rowspan] of cells) {
|
|
91
|
+
while (above[at])
|
|
92
|
+
at++;
|
|
93
|
+
for (let column = at; column < at + Math.max(1, colspan); column++) {
|
|
94
|
+
// A cell running into a column a span from above holds.
|
|
95
|
+
if (above[column])
|
|
96
|
+
fits = false;
|
|
97
|
+
held[column] = Math.max(held[column] ?? 0, Math.max(1, rowspan) - 1);
|
|
98
|
+
}
|
|
99
|
+
at += Math.max(1, colspan);
|
|
100
|
+
}
|
|
101
|
+
this.#held = Array.from({ length: Math.max(held.length, at) }, (_, i) => held[i] ?? 0);
|
|
102
|
+
const width = Math.max(at, above.lastIndexOf(true) + 1);
|
|
103
|
+
this.columns = Math.max(this.columns, width);
|
|
104
|
+
this.#width ??= width;
|
|
105
|
+
return fits && width === this.#width;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
49
108
|
function own(attrs, name) {
|
|
50
109
|
return Object.hasOwn(attrs, name) ? attrs[name] : undefined;
|
|
51
110
|
}
|
|
@@ -88,7 +147,9 @@ function placementAllowed(display, scope) {
|
|
|
88
147
|
scope.parent === COLUMN_TAG ||
|
|
89
148
|
scope.parent === BOX_TAG ||
|
|
90
149
|
scope.parent === TASK_TAG ||
|
|
91
|
-
scope.parent === SUBTASK_TAG
|
|
150
|
+
scope.parent === SUBTASK_TAG ||
|
|
151
|
+
// One in a table's data cell (visitComponent counts them).
|
|
152
|
+
scope.parent === TABLE_CELL_TAG);
|
|
92
153
|
}
|
|
93
154
|
function outOfRange(value, spec) {
|
|
94
155
|
return (spec.min !== undefined && value < spec.min) || (spec.max !== undefined && value > spec.max);
|
|
@@ -386,7 +447,8 @@ class Analyser {
|
|
|
386
447
|
const record = this.components.get(node);
|
|
387
448
|
return {
|
|
388
449
|
id: record?.sourceId ?? null,
|
|
389
|
-
|
|
450
|
+
// An example is answered already: nothing for a Check.
|
|
451
|
+
graded: isCheckable(definition.manifest) && definition.example?.(node) !== true,
|
|
390
452
|
block: definition.manifest.display === 'block',
|
|
391
453
|
};
|
|
392
454
|
},
|
|
@@ -664,6 +726,16 @@ class Analyser {
|
|
|
664
726
|
// A figure is a block: in a prompt or an option it is unwrapped like the other blocks, below.
|
|
665
727
|
if (tag === FIGURE_TAG && scope.mode === 'flow')
|
|
666
728
|
return [this.visitFigure(el, scope, place, where)];
|
|
729
|
+
if (tag === TABLE_TAG) {
|
|
730
|
+
return scope.mode === 'flow'
|
|
731
|
+
? [this.visitTable(el, scope, place, where)]
|
|
732
|
+
: this.unwrapTable(el, scope, place, where);
|
|
733
|
+
}
|
|
734
|
+
// A part of a table out of its table (a cell outside a row): its content stays, to be validated.
|
|
735
|
+
if (TABLE_TAGS.has(tag)) {
|
|
736
|
+
this.add(EngineIssue.TABLE_INVALID, {}, where);
|
|
737
|
+
return this.visitNodes(el, scope, place.path);
|
|
738
|
+
}
|
|
667
739
|
if (tag.includes('-')) {
|
|
668
740
|
const host = scope.host;
|
|
669
741
|
const spec = host?.manifest.children.find((c) => c.tag === tag);
|
|
@@ -1059,6 +1131,13 @@ class Analyser {
|
|
|
1059
1131
|
else if ((name === 'width' || name === 'height') && !((parseIntegerValue(value) ?? 0) > 0)) {
|
|
1060
1132
|
this.invalid(el.tag, name, value, 'integer', [], where);
|
|
1061
1133
|
}
|
|
1134
|
+
else if ((name === 'colspan' || name === 'rowspan') &&
|
|
1135
|
+
tableSpan(value, name === 'colspan' ? MAX_TABLE_COLUMNS : MAX_TABLE_ROWS) === 0) {
|
|
1136
|
+
this.invalid(el.tag, name, value, 'integer', [], where);
|
|
1137
|
+
}
|
|
1138
|
+
else if (name === 'scope' && !TABLE_SCOPES.includes(value)) {
|
|
1139
|
+
this.invalid(el.tag, name, value, 'enum', TABLE_SCOPES, where);
|
|
1140
|
+
}
|
|
1062
1141
|
else {
|
|
1063
1142
|
attrs[name] = value;
|
|
1064
1143
|
}
|
|
@@ -1078,16 +1157,8 @@ class Analyser {
|
|
|
1078
1157
|
* and at most one caption. A caption holds rich inline text, which may hold inline components like any text.
|
|
1079
1158
|
*/
|
|
1080
1159
|
visitFigure(el, scope, place, where) {
|
|
1081
|
-
if (scope
|
|
1082
|
-
scope.parent !== DOC_TAG &&
|
|
1083
|
-
scope.parent !== COLUMN_TAG &&
|
|
1084
|
-
scope.parent !== BOX_TAG &&
|
|
1085
|
-
scope.parent !== TASK_TAG &&
|
|
1086
|
-
scope.parent !== SUBTASK_TAG &&
|
|
1087
|
-
scope.parent !== scope.host?.manifest.tag &&
|
|
1088
|
-
!HELP_TAGS.has(scope.parent)) {
|
|
1160
|
+
if (!this.blockPlace(scope))
|
|
1089
1161
|
this.add(EngineIssue.PLACEMENT_INVALID, { tag: el.tag }, where);
|
|
1090
|
-
}
|
|
1091
1162
|
const attrs = this.richAttributes(el, where, scope);
|
|
1092
1163
|
const inner = { ...scope, ...this.below(attrs, scope), parent: FIGURE_TAG };
|
|
1093
1164
|
let pictures = 0;
|
|
@@ -1112,6 +1183,138 @@ class Analyser {
|
|
|
1112
1183
|
this.add(EngineIssue.FIGURE_INVALID, {}, where);
|
|
1113
1184
|
return element(FIGURE_TAG, attrs, children);
|
|
1114
1185
|
}
|
|
1186
|
+
/** Where a figure or a table may stand: directly in a page, the document, a column, a frame, a task, a rich block or help. */
|
|
1187
|
+
blockPlace(scope) {
|
|
1188
|
+
return (scope.parent === PAGE_TAG ||
|
|
1189
|
+
scope.parent === DOC_TAG ||
|
|
1190
|
+
scope.parent === COLUMN_TAG ||
|
|
1191
|
+
scope.parent === BOX_TAG ||
|
|
1192
|
+
scope.parent === TASK_TAG ||
|
|
1193
|
+
scope.parent === SUBTASK_TAG ||
|
|
1194
|
+
scope.parent === scope.host?.manifest.tag ||
|
|
1195
|
+
HELP_TAGS.has(scope.parent));
|
|
1196
|
+
}
|
|
1197
|
+
/**
|
|
1198
|
+
* A table, where a figure may stand. Its caption (first, once) holds rich inline text; then a head (once, before the
|
|
1199
|
+
* bodies) and bodies of rows, or rows directly in it (one body until the next part); a row holds header and data
|
|
1200
|
+
* cells, whose content is rich inline text with inline components in it. A part out of its place, text between
|
|
1201
|
+
* rows or cells, rows that cover different columns, a span past the rows of its part or no rows at all are
|
|
1202
|
+
* TABLE_INVALID, reported at the part; more than MAX_TABLE_COLUMNS columns or MAX_TABLE_ROWS rows TABLE_TOO_LARGE.
|
|
1203
|
+
*/
|
|
1204
|
+
visitTable(el, scope, place, where) {
|
|
1205
|
+
if (!this.blockPlace(scope))
|
|
1206
|
+
this.add(EngineIssue.PLACEMENT_INVALID, { tag: el.tag }, where);
|
|
1207
|
+
const attrs = this.richAttributes(el, where, scope);
|
|
1208
|
+
const inner = { ...scope, ...this.below(attrs, scope), parent: TABLE_TAG };
|
|
1209
|
+
const grid = new TableGrid();
|
|
1210
|
+
// What came last: the order is caption, head, bodies (and rows of their own).
|
|
1211
|
+
const seen = { last: 'start' };
|
|
1212
|
+
const children = this.visitNodes(el, inner, place.path, (child, childPlace) => {
|
|
1213
|
+
const at = this.where(inner, childPlace, child.tag);
|
|
1214
|
+
if (child.tag === TABLE_CAPTION_TAG && seen.last === 'start') {
|
|
1215
|
+
seen.last = 'caption';
|
|
1216
|
+
const caption = this.richAttributes(child, at, inner);
|
|
1217
|
+
const text = {
|
|
1218
|
+
...inner,
|
|
1219
|
+
...this.below(caption, inner),
|
|
1220
|
+
parent: TABLE_CAPTION_TAG,
|
|
1221
|
+
mode: 'inline',
|
|
1222
|
+
};
|
|
1223
|
+
return [element(TABLE_CAPTION_TAG, caption, this.visitNodes(child, text, childPlace.path))];
|
|
1224
|
+
}
|
|
1225
|
+
if (child.tag === TABLE_HEAD_TAG && (seen.last === 'start' || seen.last === 'caption')) {
|
|
1226
|
+
seen.last = 'head';
|
|
1227
|
+
return [this.visitTableSection(child, inner, childPlace, at, grid)];
|
|
1228
|
+
}
|
|
1229
|
+
if (child.tag === TABLE_BODY_TAG) {
|
|
1230
|
+
if (seen.last === 'rows')
|
|
1231
|
+
this.endTableSection(grid, where);
|
|
1232
|
+
seen.last = 'body';
|
|
1233
|
+
return [this.visitTableSection(child, inner, childPlace, at, grid)];
|
|
1234
|
+
}
|
|
1235
|
+
if (child.tag === TABLE_ROW_TAG) {
|
|
1236
|
+
if (seen.last !== 'rows')
|
|
1237
|
+
grid.start();
|
|
1238
|
+
seen.last = 'rows';
|
|
1239
|
+
return [this.visitTableRow(child, inner, childPlace, at, grid)];
|
|
1240
|
+
}
|
|
1241
|
+
this.add(EngineIssue.TABLE_INVALID, {}, at);
|
|
1242
|
+
return [];
|
|
1243
|
+
});
|
|
1244
|
+
if (seen.last === 'rows')
|
|
1245
|
+
this.endTableSection(grid, where);
|
|
1246
|
+
if (children.some((n) => n.type === 'text' && !isHtmlWhitespace(n.value)) || grid.rows === 0) {
|
|
1247
|
+
this.add(EngineIssue.TABLE_INVALID, {}, where);
|
|
1248
|
+
}
|
|
1249
|
+
if (grid.columns > MAX_TABLE_COLUMNS || grid.rows > MAX_TABLE_ROWS) {
|
|
1250
|
+
const params = {
|
|
1251
|
+
columns: grid.columns,
|
|
1252
|
+
rows: grid.rows,
|
|
1253
|
+
maxColumns: MAX_TABLE_COLUMNS,
|
|
1254
|
+
maxRows: MAX_TABLE_ROWS,
|
|
1255
|
+
};
|
|
1256
|
+
this.add(EngineIssue.TABLE_TOO_LARGE, params, where);
|
|
1257
|
+
}
|
|
1258
|
+
return element(TABLE_TAG, attrs, children);
|
|
1259
|
+
}
|
|
1260
|
+
/** A head or a body: rows only, its spans ending with it. */
|
|
1261
|
+
visitTableSection(el, scope, place, where, grid) {
|
|
1262
|
+
const attrs = this.richAttributes(el, where, scope);
|
|
1263
|
+
const inner = { ...scope, ...this.below(attrs, scope), parent: el.tag };
|
|
1264
|
+
grid.start();
|
|
1265
|
+
const children = this.visitNodes(el, inner, place.path, (child, childPlace) => {
|
|
1266
|
+
const at = this.where(inner, childPlace, child.tag);
|
|
1267
|
+
if (child.tag === TABLE_ROW_TAG)
|
|
1268
|
+
return [this.visitTableRow(child, inner, childPlace, at, grid)];
|
|
1269
|
+
this.add(EngineIssue.TABLE_INVALID, {}, at);
|
|
1270
|
+
return [];
|
|
1271
|
+
});
|
|
1272
|
+
if (children.some((n) => n.type === 'text' && !isHtmlWhitespace(n.value))) {
|
|
1273
|
+
this.add(EngineIssue.TABLE_INVALID, {}, where);
|
|
1274
|
+
}
|
|
1275
|
+
this.endTableSection(grid, where);
|
|
1276
|
+
return element(el.tag, attrs, children);
|
|
1277
|
+
}
|
|
1278
|
+
/** A span that reaches past the last row of its part. */
|
|
1279
|
+
endTableSection(grid, where) {
|
|
1280
|
+
if (grid.end())
|
|
1281
|
+
this.add(EngineIssue.TABLE_INVALID, {}, where);
|
|
1282
|
+
}
|
|
1283
|
+
/** A row: cells only, covering the columns of the rows before it. */
|
|
1284
|
+
visitTableRow(el, scope, place, where, grid) {
|
|
1285
|
+
const attrs = this.richAttributes(el, where, scope);
|
|
1286
|
+
const inner = { ...scope, ...this.below(attrs, scope), parent: TABLE_ROW_TAG };
|
|
1287
|
+
const spans = [];
|
|
1288
|
+
const children = this.visitNodes(el, inner, place.path, (child, childPlace) => {
|
|
1289
|
+
const at = this.where(inner, childPlace, child.tag);
|
|
1290
|
+
if (child.tag !== TABLE_HEADER_CELL_TAG && child.tag !== TABLE_CELL_TAG) {
|
|
1291
|
+
this.add(EngineIssue.TABLE_INVALID, {}, at);
|
|
1292
|
+
return [];
|
|
1293
|
+
}
|
|
1294
|
+
const cell = this.richAttributes(child, at, inner);
|
|
1295
|
+
spans.push([tableSpan(cell.colspan, MAX_TABLE_COLUMNS), tableSpan(cell.rowspan, MAX_TABLE_ROWS)]);
|
|
1296
|
+
// A header cell holds inline content; a data cell rich blocks too, and one block component.
|
|
1297
|
+
const content = child.tag === TABLE_CELL_TAG
|
|
1298
|
+
? { ...inner, ...this.below(cell, inner), parent: child.tag, mode: 'flow', cell: { blocks: 0 } }
|
|
1299
|
+
: { ...inner, ...this.below(cell, inner), parent: child.tag, mode: 'inline' };
|
|
1300
|
+
return [element(child.tag, cell, this.visitNodes(child, content, childPlace.path))];
|
|
1301
|
+
});
|
|
1302
|
+
if (children.some((n) => n.type === 'text' && !isHtmlWhitespace(n.value)) || !grid.row(spans)) {
|
|
1303
|
+
this.add(EngineIssue.TABLE_INVALID, {}, where);
|
|
1304
|
+
}
|
|
1305
|
+
return element(TABLE_ROW_TAG, attrs, children);
|
|
1306
|
+
}
|
|
1307
|
+
/**
|
|
1308
|
+
* A table in a prompt, an option or a card, where blocks are unwrapped: its parts go, the text of its caption and
|
|
1309
|
+
* cells stays, a space between them.
|
|
1310
|
+
*/
|
|
1311
|
+
unwrapTable(el, scope, place, where) {
|
|
1312
|
+
this.add(EngineIssue.ELEMENT_REMOVED, { tag: el.tag }, where, 'warning');
|
|
1313
|
+
const unwrap = (child, childPlace) => TABLE_TAGS.has(child.tag)
|
|
1314
|
+
? [{ type: 'text', value: ' ' }, ...this.visitNodes(child, scope, childPlace.path, unwrap)]
|
|
1315
|
+
: null;
|
|
1316
|
+
return this.visitNodes(el, scope, place.path, unwrap);
|
|
1317
|
+
}
|
|
1115
1318
|
visitPage(el, index, place, base) {
|
|
1116
1319
|
const id = own(el.attrs, 'id');
|
|
1117
1320
|
const where = {
|
|
@@ -1164,10 +1367,16 @@ class Analyser {
|
|
|
1164
1367
|
const id = own(raw.attrs, 'id');
|
|
1165
1368
|
const where = { order: place.order, page: scope.page, element: id ?? null, tag, path: place.path };
|
|
1166
1369
|
this.componentCount++;
|
|
1167
|
-
if (manifest.graded)
|
|
1370
|
+
if (manifest.graded && definition.example?.(raw) !== true)
|
|
1168
1371
|
this.gradedPages.add(scope.pageIndex);
|
|
1169
1372
|
if (!placementAllowed(manifest.display, scope))
|
|
1170
1373
|
this.add(EngineIssue.PLACEMENT_INVALID, { tag }, where);
|
|
1374
|
+
else if (manifest.display === 'block' && scope.parent === TABLE_CELL_TAG && scope.cell !== undefined) {
|
|
1375
|
+
// A second block component in one cell.
|
|
1376
|
+
scope.cell.blocks++;
|
|
1377
|
+
if (scope.cell.blocks > 1)
|
|
1378
|
+
this.add(EngineIssue.PLACEMENT_INVALID, { tag }, where);
|
|
1379
|
+
}
|
|
1171
1380
|
const el = this.upgrade(raw, definition, where);
|
|
1172
1381
|
const specs = allAttributes(manifest);
|
|
1173
1382
|
const attrs = {};
|