@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.
- package/CHANGELOG.md +39 -0
- package/dist/authoring.d.ts +50 -14
- package/dist/authoring.d.ts.map +1 -1
- package/dist/authoring.js +208 -18
- package/dist/authoring.js.map +1 -1
- package/dist/elements/help-form.d.ts.map +1 -1
- package/dist/elements/help-form.js +6 -3
- package/dist/elements/help-form.js.map +1 -1
- package/dist/elements/insert-menu.d.ts +8 -1
- package/dist/elements/insert-menu.d.ts.map +1 -1
- package/dist/elements/insert-menu.js +25 -3
- package/dist/elements/insert-menu.js.map +1 -1
- package/dist/elements/inspector.d.ts.map +1 -1
- package/dist/elements/inspector.js +67 -6
- package/dist/elements/inspector.js.map +1 -1
- package/dist/elements/picture-field.d.ts.map +1 -1
- package/dist/elements/picture-field.js +7 -3
- package/dist/elements/picture-field.js.map +1 -1
- package/dist/elements/styles.d.ts +10 -5
- package/dist/elements/styles.d.ts.map +1 -1
- package/dist/elements/styles.js +35 -8
- package/dist/elements/styles.js.map +1 -1
- package/dist/elements/toolbar.js +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/inspect.d.ts +33 -3
- package/dist/inspect.d.ts.map +1 -1
- package/dist/inspect.js +2 -2
- package/dist/inspect.js.map +1 -1
- package/dist/messages/en.json +18 -0
- package/dist/messages/pl.json +18 -0
- package/package.json +5 -5
- package/src/authoring.ts +281 -30
- package/src/elements/help-form.ts +6 -3
- package/src/elements/insert-menu.ts +34 -3
- package/src/elements/inspector.ts +71 -7
- package/src/elements/picture-field.ts +7 -3
- package/src/elements/styles.ts +36 -8
- package/src/elements/toolbar.ts +1 -1
- package/src/index.ts +4 -1
- package/src/inspect.ts +33 -3
- package/src/messages/en.json +18 -0
- package/src/messages/pl.json +18 -0
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 {
|
|
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,
|
|
233
|
-
* them (paragraphs, headings, lists, quotes, pictures, with the inline components in their
|
|
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,
|
|
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
|
|
366
|
-
*
|
|
367
|
-
*
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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 = (
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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 =
|
|
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,85 @@ 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 named
|
|
961
|
+
* as authors know it ("Gap 2"); a question another Check element has says which. Without the document, the questions
|
|
962
|
+
* 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 names = page === undefined || source === undefined ? null : namesIn(source);
|
|
972
|
+
const own =
|
|
973
|
+
page?.checks.find((check) => check.id === id)?.targets ?? checkFor(el.attrs[CHECK_FOR_ATTRIBUTE]);
|
|
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 (component.id === null || manifest === null || !isCheckable(manifest)) return [];
|
|
980
|
+
const n = names?.get(component.id)?.n;
|
|
981
|
+
const by = component.check;
|
|
982
|
+
return [
|
|
983
|
+
{
|
|
984
|
+
id: component.id,
|
|
985
|
+
label: n === undefined ? component.label : text('check.target', { type: component.label, n }),
|
|
986
|
+
checked: own.includes(component.id),
|
|
987
|
+
other: by !== null && by !== id ? checkName(page.checks, by) : null,
|
|
988
|
+
},
|
|
989
|
+
];
|
|
990
|
+
});
|
|
991
|
+
return {
|
|
992
|
+
tag: CHECK_TAG,
|
|
993
|
+
id,
|
|
994
|
+
label: text('block.check'),
|
|
995
|
+
icon: 'check',
|
|
996
|
+
fields: [
|
|
997
|
+
{
|
|
998
|
+
kind: 'attribute',
|
|
999
|
+
control: 'text',
|
|
1000
|
+
name: CHECK_LABEL_ATTRIBUTE,
|
|
1001
|
+
label: text('check.labelField'),
|
|
1002
|
+
help: text('check.labelHelp'),
|
|
1003
|
+
value: Object.hasOwn(el.attrs, CHECK_LABEL_ATTRIBUTE)
|
|
1004
|
+
? (el.attrs[CHECK_LABEL_ATTRIBUTE] ?? '')
|
|
1005
|
+
: '',
|
|
1006
|
+
required: false,
|
|
1007
|
+
accept: null,
|
|
1008
|
+
},
|
|
1009
|
+
{
|
|
1010
|
+
kind: 'check-targets',
|
|
1011
|
+
name: CHECK_FOR_ATTRIBUTE,
|
|
1012
|
+
label: text('check.targets'),
|
|
1013
|
+
help: text('check.targetsHelp'),
|
|
1014
|
+
targets,
|
|
1015
|
+
},
|
|
1016
|
+
],
|
|
1017
|
+
};
|
|
1018
|
+
};
|
|
1019
|
+
|
|
1020
|
+
/** The Check element that checks the question `id` in `source`, with its name, or null. */
|
|
1021
|
+
const checkedBy = (source: string, id: string): { readonly id: string; readonly name: string } | null => {
|
|
1022
|
+
for (const page of outline(source).pages) {
|
|
1023
|
+
const by = page.components.find((component) => component.id === id)?.check ?? null;
|
|
1024
|
+
if (by !== null) return { id: by, name: checkName(page.checks, by) };
|
|
1025
|
+
}
|
|
1026
|
+
return null;
|
|
1027
|
+
};
|
|
1028
|
+
|
|
789
1029
|
return {
|
|
790
1030
|
engine,
|
|
791
1031
|
locale,
|
|
@@ -852,6 +1092,7 @@ export function createAuthoring(options: AuthoringOptions): Authoring {
|
|
|
852
1092
|
inspect(elementHtml, source) {
|
|
853
1093
|
const el = firstElement(parseHtml(elementHtml));
|
|
854
1094
|
if (el === null) return null;
|
|
1095
|
+
if (el.tag === CHECK_TAG) return inspectCheck(el, source);
|
|
855
1096
|
const manifest = manifestOf(el.tag);
|
|
856
1097
|
if (manifest === null) return null;
|
|
857
1098
|
const templates = templateOptions('component', el.tag);
|
|
@@ -861,7 +1102,17 @@ export function createAuthoring(options: AuthoringOptions): Authoring {
|
|
|
861
1102
|
const at = scanElements(source).find((e) => e.id === id);
|
|
862
1103
|
return at === undefined ? null : firstElement(parseHtml(source.slice(at.start, at.end)));
|
|
863
1104
|
};
|
|
864
|
-
|
|
1105
|
+
const model = inspectorModel(
|
|
1106
|
+
el,
|
|
1107
|
+
manifest,
|
|
1108
|
+
byTag.get(el.tag) ?? null,
|
|
1109
|
+
textsFor(manifest),
|
|
1110
|
+
templates,
|
|
1111
|
+
find,
|
|
1112
|
+
);
|
|
1113
|
+
const id = ownId(el);
|
|
1114
|
+
const by = source === undefined || id === null || !isCheckable(manifest) ? null : checkedBy(source, id);
|
|
1115
|
+
return by === null ? model : { ...model, checkedBy: by };
|
|
865
1116
|
},
|
|
866
1117
|
inspectDocument(source) {
|
|
867
1118
|
// The scanner, as `update` uses it: the document is the first start tag (and no full parse per keystroke).
|
|
@@ -28,7 +28,7 @@ import { EDITOR_NAMESPACE } from '../messages.js';
|
|
|
28
28
|
import { elementTree } from '../scan.js';
|
|
29
29
|
import { AuthoringElement } from './base.js';
|
|
30
30
|
import type { HelpPart } from './style-load.js';
|
|
31
|
-
import { compactButtons, kitStyles } from './styles.js';
|
|
31
|
+
import { addIcon, compactButtons, kitStyles } from './styles.js';
|
|
32
32
|
|
|
33
33
|
const helpMessages: readonly MessageCatalog[] = [
|
|
34
34
|
{ namespace: EDITOR_NAMESPACE, locale: 'en', messages: en },
|
|
@@ -117,6 +117,8 @@ export class AstlHelpForm extends AuthoringElement {
|
|
|
117
117
|
inline: { type: Boolean },
|
|
118
118
|
};
|
|
119
119
|
|
|
120
|
+
// A label beside a select keeps its word whole and the select gives way (it ellipsizes): the card's text may break
|
|
121
|
+
// anywhere, for an author's long word or address, which let "Koszt" shrink into "Kosz" and "t" on a phone.
|
|
120
122
|
static override styles: CSSResultGroup = [
|
|
121
123
|
kitStyles,
|
|
122
124
|
compactButtons,
|
|
@@ -241,6 +243,7 @@ export class AstlHelpForm extends AuthoringElement {
|
|
|
241
243
|
min-inline-size: 0;
|
|
242
244
|
max-inline-size: 100%;
|
|
243
245
|
font-weight: 400;
|
|
246
|
+
overflow-wrap: break-word;
|
|
244
247
|
}
|
|
245
248
|
.cost select {
|
|
246
249
|
inline-size: auto;
|
|
@@ -628,8 +631,8 @@ export class AstlHelpForm extends AuthoringElement {
|
|
|
628
631
|
: html`<ol>${Array.from({ length: rows }, (_, i) => this.#hint(help, i, points))}</ol>`
|
|
629
632
|
}
|
|
630
633
|
<div class="row">
|
|
631
|
-
<button type="button" data-help="add-hint" part="help-add" @click=${() => this.#addHint(help)}>
|
|
632
|
-
${this.t('help.addHint')}
|
|
634
|
+
<button type="button" data-help="add-hint" data-add part="help-add" @click=${() => this.#addHint(help)}>
|
|
635
|
+
${addIcon}${this.t('help.addHint')}
|
|
633
636
|
</button>
|
|
634
637
|
</div>
|
|
635
638
|
</fieldset>
|
|
@@ -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
|
-
|
|
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,
|
|
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(
|