@astl/editor 0.2.3 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/dist/authoring.d.ts +50 -14
- package/dist/authoring.d.ts.map +1 -1
- package/dist/authoring.js +211 -18
- package/dist/authoring.js.map +1 -1
- package/dist/elements/color-control.d.ts +4 -1
- package/dist/elements/color-control.d.ts.map +1 -1
- package/dist/elements/color-control.js +6 -2
- package/dist/elements/color-control.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 +68 -4
- package/dist/elements/inspector.js.map +1 -1
- package/dist/elements/issues.d.ts.map +1 -1
- package/dist/elements/issues.js +11 -3
- package/dist/elements/issues.js.map +1 -1
- package/dist/elements/picture-dialog.d.ts +1 -0
- package/dist/elements/picture-dialog.d.ts.map +1 -1
- package/dist/elements/picture-dialog.js +16 -3
- package/dist/elements/picture-dialog.js.map +1 -1
- package/dist/elements/preview.d.ts.map +1 -1
- package/dist/elements/preview.js +11 -2
- package/dist/elements/preview.js.map +1 -1
- package/dist/elements/style-popups.js +3 -3
- package/dist/elements/styles.d.ts +36 -1
- package/dist/elements/styles.d.ts.map +1 -1
- package/dist/elements/styles.js +97 -1
- package/dist/elements/styles.js.map +1 -1
- package/dist/elements/toolbar.d.ts.map +1 -1
- package/dist/elements/toolbar.js +40 -16
- package/dist/elements/toolbar.js.map +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 +283 -30
- package/src/elements/color-control.ts +6 -2
- package/src/elements/insert-menu.ts +34 -3
- package/src/elements/inspector.ts +80 -5
- package/src/elements/issues.ts +11 -3
- package/src/elements/picture-dialog.ts +17 -3
- package/src/elements/preview.ts +11 -2
- package/src/elements/style-popups.ts +3 -3
- package/src/elements/styles.ts +111 -1
- package/src/elements/toolbar.ts +42 -16
- 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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
1
1
|
# @astl/editor
|
|
2
2
|
|
|
3
|
+
## 0.3.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 83f0eed: A Check element's card numbers each question among those of its type on its page, in page order ("Gap 1" to "Gap 4", "Closed question 1"), block questions too, which it named by their block ("Closed question 4" on a page with one).
|
|
8
|
+
|
|
9
|
+
The editor's popups (the style, font, size, colour, alignment and spacing menus, the link form, "Elements", "Templates" and "Layout") and the picture dialog stay inside the viewport: no wider or taller than it (they scroll inside), moved along to fit, and above their button where they fit only there. This holds on a page that enlarges its text with `zoom`, where they ran past the right edge (a 390 px phone at 125%), and when the viewport changes while one is open. The colour swatches stay four a row and narrow where the popup has less room.
|
|
10
|
+
- 8026e49: A narrow player gives the exercise more of its width. It sizes its spacing from its own width, in the page's root font size, so it follows larger text, by zoom or by font size. At 18rem and under the space around its card is halved and the card's sides go from 1.5rem to 0.75rem; at 12rem and under the card reaches the player's sides with 0.25rem inside them. The cards of `<astl-preview>`, `<astl-inspector>` and `<astl-issues>` do the same from their width (0.5rem at 20rem and under, 0.25rem at their sides at 13rem and under), so the cards of a narrow column switch together. A closed question on a 390 px phone with 200% text was about one letter wide and its options could not be pressed; now its words stay whole and its options take a press. A phone of 360 px or more at 100% text, and wider screens, keep the spacing they had. The player and the cards measure their width rather than being size containers, so in any layout (a block, a flex or grid item, an inline-block) they take the width they had; in a box that sizes to its content, one that narrow because its content is narrow takes the smaller padding too.
|
|
11
|
+
|
|
12
|
+
On the editor's surface, a frame's add buttons ("Add option", "Add prompt") wrap their words where one alone is wider than its row: in Polish at 320 px with 200% text, "Dodaj odpowiedź" ran past the frame and the page scrolled sideways. A page's "Remove title" goes under its title where the two do not fit side by side, rather than past the screen.
|
|
13
|
+
- Updated dependencies [8026e49]
|
|
14
|
+
- @astl/player@0.3.1
|
|
15
|
+
- @astl/core@0.3.1
|
|
16
|
+
- @astl/engine@0.3.1
|
|
17
|
+
- @astl/tokens@0.3.1
|
|
18
|
+
|
|
19
|
+
## 0.3.0
|
|
20
|
+
|
|
21
|
+
### Minor Changes
|
|
22
|
+
|
|
23
|
+
- 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.
|
|
24
|
+
|
|
25
|
+
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.
|
|
26
|
+
|
|
27
|
+
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.
|
|
28
|
+
|
|
29
|
+
### Patch Changes
|
|
30
|
+
|
|
31
|
+
- Updated dependencies [c85c3b9]
|
|
32
|
+
- @astl/core@0.3.0
|
|
33
|
+
- @astl/engine@0.3.0
|
|
34
|
+
- @astl/player@0.3.0
|
|
35
|
+
- @astl/tokens@0.3.0
|
|
36
|
+
|
|
3
37
|
## 0.2.3
|
|
4
38
|
|
|
5
39
|
### Patch Changes
|
package/dist/authoring.d.ts
CHANGED
|
@@ -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,
|
|
127
|
-
* them (paragraphs, headings, lists, quotes, pictures, with the inline components in their
|
|
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,
|
|
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
|
|
257
|
-
*
|
|
258
|
-
*
|
|
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
|
|
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;
|
package/dist/authoring.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authoring.d.ts","sourceRoot":"","sources":["../src/authoring.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EACL,KAAK,aAAa,
|
|
1
|
+
{"version":3,"file":"authoring.d.ts","sourceRoot":"","sources":["../src/authoring.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EACL,KAAK,aAAa,EAalB,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EAGnB,KAAK,MAAM,EAEX,KAAK,KAAK,EAKV,KAAK,cAAc,EACnB,KAAK,aAAa,EASlB,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,EAEL,KAAK,cAAc,EAIpB,MAAM,cAAc,CAAC;AAetB,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,CAAC,YAAY,CAAC,EAAE,MAAM,OAAO,CAAC,SAAS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EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,GAAG,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,CA+nBpE"}
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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,84 @@ 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 by its
|
|
558
|
+
* number among the questions of its type on the page, in page order ("Gap 2", "Closed question 1"); a question
|
|
559
|
+
* another Check element has says which. Without the document, the questions 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 own = page?.checks.find((check) => check.id === id)?.targets ?? checkFor(el.attrs[CHECK_FOR_ATTRIBUTE]);
|
|
568
|
+
const seen = new Map();
|
|
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 (manifest === null || !isCheckable(manifest))
|
|
574
|
+
return [];
|
|
575
|
+
const n = (seen.get(component.tag) ?? 0) + 1;
|
|
576
|
+
seen.set(component.tag, n);
|
|
577
|
+
if (component.id === null)
|
|
578
|
+
return [];
|
|
579
|
+
const by = component.check;
|
|
580
|
+
return [
|
|
581
|
+
{
|
|
582
|
+
id: component.id,
|
|
583
|
+
label: text('check.target', { type: component.label, n }),
|
|
584
|
+
checked: own.includes(component.id),
|
|
585
|
+
other: by !== null && by !== id ? checkName(page.checks, by) : null,
|
|
586
|
+
},
|
|
587
|
+
];
|
|
588
|
+
});
|
|
589
|
+
return {
|
|
590
|
+
tag: CHECK_TAG,
|
|
591
|
+
id,
|
|
592
|
+
label: text('block.check'),
|
|
593
|
+
icon: 'check',
|
|
594
|
+
fields: [
|
|
595
|
+
{
|
|
596
|
+
kind: 'attribute',
|
|
597
|
+
control: 'text',
|
|
598
|
+
name: CHECK_LABEL_ATTRIBUTE,
|
|
599
|
+
label: text('check.labelField'),
|
|
600
|
+
help: text('check.labelHelp'),
|
|
601
|
+
value: Object.hasOwn(el.attrs, CHECK_LABEL_ATTRIBUTE)
|
|
602
|
+
? (el.attrs[CHECK_LABEL_ATTRIBUTE] ?? '')
|
|
603
|
+
: '',
|
|
604
|
+
required: false,
|
|
605
|
+
accept: null,
|
|
606
|
+
},
|
|
607
|
+
{
|
|
608
|
+
kind: 'check-targets',
|
|
609
|
+
name: CHECK_FOR_ATTRIBUTE,
|
|
610
|
+
label: text('check.targets'),
|
|
611
|
+
help: text('check.targetsHelp'),
|
|
612
|
+
targets,
|
|
613
|
+
},
|
|
614
|
+
],
|
|
615
|
+
};
|
|
616
|
+
};
|
|
617
|
+
/** The Check element that checks the question `id` in `source`, with its name, or null. */
|
|
618
|
+
const checkedBy = (source, id) => {
|
|
619
|
+
for (const page of outline(source).pages) {
|
|
620
|
+
const by = page.components.find((component) => component.id === id)?.check ?? null;
|
|
621
|
+
if (by !== null)
|
|
622
|
+
return { id: by, name: checkName(page.checks, by) };
|
|
623
|
+
}
|
|
624
|
+
return null;
|
|
625
|
+
};
|
|
438
626
|
return {
|
|
439
627
|
engine,
|
|
440
628
|
locale,
|
|
@@ -498,6 +686,8 @@ export function createAuthoring(options) {
|
|
|
498
686
|
const el = firstElement(parseHtml(elementHtml));
|
|
499
687
|
if (el === null)
|
|
500
688
|
return null;
|
|
689
|
+
if (el.tag === CHECK_TAG)
|
|
690
|
+
return inspectCheck(el, source);
|
|
501
691
|
const manifest = manifestOf(el.tag);
|
|
502
692
|
if (manifest === null)
|
|
503
693
|
return null;
|
|
@@ -509,7 +699,10 @@ export function createAuthoring(options) {
|
|
|
509
699
|
const at = scanElements(source).find((e) => e.id === id);
|
|
510
700
|
return at === undefined ? null : firstElement(parseHtml(source.slice(at.start, at.end)));
|
|
511
701
|
};
|
|
512
|
-
|
|
702
|
+
const model = inspectorModel(el, manifest, byTag.get(el.tag) ?? null, textsFor(manifest), templates, find);
|
|
703
|
+
const id = ownId(el);
|
|
704
|
+
const by = source === undefined || id === null || !isCheckable(manifest) ? null : checkedBy(source, id);
|
|
705
|
+
return by === null ? model : { ...model, checkedBy: by };
|
|
513
706
|
},
|
|
514
707
|
inspectDocument(source) {
|
|
515
708
|
// The scanner, as `update` uses it: the document is the first start tag (and no full parse per keystroke).
|