@astl/core 0.0.0 → 0.1.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/LICENSE +202 -0
- package/README.md +38 -0
- package/dist/answers.d.ts +29 -0
- package/dist/answers.d.ts.map +1 -0
- package/dist/answers.js +40 -0
- package/dist/answers.js.map +1 -0
- package/dist/ast.d.ts +25 -0
- package/dist/ast.d.ts.map +1 -0
- package/dist/ast.js +27 -0
- package/dist/ast.js.map +1 -0
- package/dist/authoring.d.ts +451 -0
- package/dist/authoring.d.ts.map +1 -0
- package/dist/authoring.js +2 -0
- package/dist/authoring.js.map +1 -0
- package/dist/checker.d.ts +78 -0
- package/dist/checker.d.ts.map +1 -0
- package/dist/checker.js +10 -0
- package/dist/checker.js.map +1 -0
- package/dist/compiled.d.ts +94 -0
- package/dist/compiled.d.ts.map +1 -0
- package/dist/compiled.js +16 -0
- package/dist/compiled.js.map +1 -0
- package/dist/content.d.ts +72 -0
- package/dist/content.d.ts.map +1 -0
- package/dist/content.js +128 -0
- package/dist/content.js.map +1 -0
- package/dist/declarations.d.ts +52 -0
- package/dist/declarations.d.ts.map +1 -0
- package/dist/declarations.js +358 -0
- package/dist/declarations.js.map +1 -0
- package/dist/definition.d.ts +106 -0
- package/dist/definition.d.ts.map +1 -0
- package/dist/definition.js +2 -0
- package/dist/definition.js.map +1 -0
- package/dist/engine.d.ts +95 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +2 -0
- package/dist/engine.js.map +1 -0
- package/dist/format.d.ts +29 -0
- package/dist/format.d.ts.map +1 -0
- package/dist/format.js +55 -0
- package/dist/format.js.map +1 -0
- package/dist/help.d.ts +38 -0
- package/dist/help.d.ts.map +1 -0
- package/dist/help.js +22 -0
- package/dist/help.js.map +1 -0
- package/dist/i18n/check.d.ts +11 -0
- package/dist/i18n/check.d.ts.map +1 -0
- package/dist/i18n/check.js +64 -0
- package/dist/i18n/check.js.map +1 -0
- package/dist/i18n/format.d.ts +40 -0
- package/dist/i18n/format.d.ts.map +1 -0
- package/dist/i18n/format.js +280 -0
- package/dist/i18n/format.js.map +1 -0
- package/dist/i18n/i18n.d.ts +14 -0
- package/dist/i18n/i18n.d.ts.map +1 -0
- package/dist/i18n/i18n.js +82 -0
- package/dist/i18n/i18n.js.map +1 -0
- package/dist/i18n/types.d.ts +31 -0
- package/dist/i18n/types.d.ts.map +1 -0
- package/dist/i18n/types.js +7 -0
- package/dist/i18n/types.js.map +1 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/issues.d.ts +98 -0
- package/dist/issues.d.ts.map +1 -0
- package/dist/issues.js +74 -0
- package/dist/issues.js.map +1 -0
- package/dist/json.d.ts +7 -0
- package/dist/json.d.ts.map +1 -0
- package/dist/json.js +2 -0
- package/dist/json.js.map +1 -0
- package/dist/manifest.d.ts +135 -0
- package/dist/manifest.d.ts.map +1 -0
- package/dist/manifest.js +63 -0
- package/dist/manifest.js.map +1 -0
- package/dist/player.d.ts +129 -0
- package/dist/player.d.ts.map +1 -0
- package/dist/player.js +18 -0
- package/dist/player.js.map +1 -0
- package/dist/policy.d.ts +53 -0
- package/dist/policy.d.ts.map +1 -0
- package/dist/policy.js +55 -0
- package/dist/policy.js.map +1 -0
- package/dist/protocol.d.ts +54 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +51 -0
- package/dist/protocol.js.map +1 -0
- package/dist/result.d.ts +44 -0
- package/dist/result.d.ts.map +1 -0
- package/dist/result.js +5 -0
- package/dist/result.js.map +1 -0
- package/dist/scoring.d.ts +27 -0
- package/dist/scoring.d.ts.map +1 -0
- package/dist/scoring.js +6 -0
- package/dist/scoring.js.map +1 -0
- package/dist/slots.d.ts +47 -0
- package/dist/slots.d.ts.map +1 -0
- package/dist/slots.js +9 -0
- package/dist/slots.js.map +1 -0
- package/dist/snapshot.d.ts +23 -0
- package/dist/snapshot.d.ts.map +1 -0
- package/dist/snapshot.js +22 -0
- package/dist/snapshot.js.map +1 -0
- package/dist/style.d.ts +51 -0
- package/dist/style.d.ts.map +1 -0
- package/dist/style.js +36 -0
- package/dist/style.js.map +1 -0
- package/package.json +40 -4
- package/src/answers.ts +52 -0
- package/src/ast.ts +49 -0
- package/src/authoring.ts +475 -0
- package/src/checker.ts +91 -0
- package/src/compiled.ts +115 -0
- package/src/content.ts +156 -0
- package/src/declarations.ts +427 -0
- package/src/definition.ts +104 -0
- package/src/engine.ts +98 -0
- package/src/format.ts +67 -0
- package/src/help.ts +41 -0
- package/src/i18n/check.ts +67 -0
- package/src/i18n/format.ts +318 -0
- package/src/i18n/i18n.ts +92 -0
- package/src/i18n/types.ts +35 -0
- package/src/index.ts +201 -0
- package/src/issues.ts +107 -0
- package/src/json.ts +6 -0
- package/src/manifest.ts +193 -0
- package/src/player.ts +145 -0
- package/src/policy.ts +117 -0
- package/src/protocol.ts +65 -0
- package/src/result.ts +53 -0
- package/src/scoring.ts +31 -0
- package/src/slots.ts +57 -0
- package/src/snapshot.ts +40 -0
- package/src/style.ts +89 -0
|
@@ -0,0 +1,451 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authoring contracts, independent of any WYSIWYG editor. These contracts and the authoring kit (`@astl/editor`)
|
|
3
|
+
* need no editor engine; `@astl/editor-tiptap` brings TipTap as the default, and any other editor (ProseMirror,
|
|
4
|
+
* CKEditor, Lexical, a plain textarea) plugs in by implementing EditorAdapter. The kit builds inspectors, insert
|
|
5
|
+
* menus, issue lists and previews on top of this contract.
|
|
6
|
+
*/
|
|
7
|
+
import type { MessageCatalog } from './i18n/types.js';
|
|
8
|
+
import type { ComponentManifest } from './manifest.js';
|
|
9
|
+
/**
|
|
10
|
+
* How authors create and edit one component type. Plain data, so it can also feed agent tools and docs.
|
|
11
|
+
* Message keys are looked up in the manifest's `messages` namespace.
|
|
12
|
+
*/
|
|
13
|
+
export interface EditorDescriptor {
|
|
14
|
+
readonly manifest: ComponentManifest;
|
|
15
|
+
/** Catalogs of the manifest's namespace (labels, help texts, template texts). */
|
|
16
|
+
readonly messages?: readonly MessageCatalog[];
|
|
17
|
+
/** Message key of the menu label, e.g. `editor.label`. */
|
|
18
|
+
readonly label: string;
|
|
19
|
+
/** Message key of a one-line description for insert menus. */
|
|
20
|
+
readonly description: string;
|
|
21
|
+
/** Icon name in the host's icon set (Phosphor names recommended), e.g. `text-t`. */
|
|
22
|
+
readonly icon: string;
|
|
23
|
+
/** Prefix for generated ids: `gap` gives `gap-1`, `gap-2`, ... */
|
|
24
|
+
readonly idPrefix: string;
|
|
25
|
+
/**
|
|
26
|
+
* Source HTML that insert menus add. Placeholders: `{{id}}` = a fresh unique id, `{{t:key}}` = a message from the
|
|
27
|
+
* manifest's namespace in the author's UI locale (escaped), `{{selection}}` = the text the author selected (escaped,
|
|
28
|
+
* `''` without one), which the snippet then replaces. Local child ids (option ids) stay as written.
|
|
29
|
+
*/
|
|
30
|
+
readonly template: string;
|
|
31
|
+
/**
|
|
32
|
+
* Named starters: whole exercises with sample content, listed apart from the default `template` (which stays what
|
|
33
|
+
* the type's own entry inserts).
|
|
34
|
+
*/
|
|
35
|
+
readonly templates?: readonly EditorTemplate[];
|
|
36
|
+
/** Inspector fields. Absent = derived from the manifest by the authoring kit. */
|
|
37
|
+
readonly fields?: readonly InspectorField[];
|
|
38
|
+
/**
|
|
39
|
+
* The element this type works with, such as the word bank of a gap: an insert writes into an empty `attribute` the
|
|
40
|
+
* id of the first `tag` element of the inserted template (a starter that brings one), else of the new element's
|
|
41
|
+
* page (pages play one at a time), and adds that tag's template at the end of the page when it has none.
|
|
42
|
+
*/
|
|
43
|
+
readonly companion?: {
|
|
44
|
+
readonly tag: string;
|
|
45
|
+
readonly attribute: string;
|
|
46
|
+
};
|
|
47
|
+
/** A command on the author's selection, for a type that holds rich content (`content: 'flow'`). */
|
|
48
|
+
readonly wrap?: EditorWrap;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Wraps the selected words in an inline child (`Mark word`): the editor puts each selected word in a new `child`
|
|
52
|
+
* element (a fresh local id, `attributes` as given) and the blocks around them in an element of this type when they
|
|
53
|
+
* are in none (with a fresh id, joined to one right before or after); on words already in the child it removes the
|
|
54
|
+
* child, keeping the text. Editors offer it as a button labelled `label` (`EditorAdapter.wrap`).
|
|
55
|
+
*/
|
|
56
|
+
export interface EditorWrap {
|
|
57
|
+
/** Message key of the button label. */
|
|
58
|
+
readonly label: string;
|
|
59
|
+
/** The inline child tag, one of the manifest's children. */
|
|
60
|
+
readonly child: string;
|
|
61
|
+
/** Attributes of a new child besides its id, e.g. `{ correct: '' }` for a boolean. */
|
|
62
|
+
readonly attributes?: Readonly<Record<string, string>>;
|
|
63
|
+
}
|
|
64
|
+
/** A named starter of a type, inserted like its default template. */
|
|
65
|
+
export interface EditorTemplate {
|
|
66
|
+
/** Kebab-case, unique among the descriptor's templates, e.g. `two-gaps`. */
|
|
67
|
+
readonly id: string;
|
|
68
|
+
/** Message key of the menu label. */
|
|
69
|
+
readonly label: string;
|
|
70
|
+
/** Message key of a one-line description. */
|
|
71
|
+
readonly description?: string;
|
|
72
|
+
/** Icon name; default: the descriptor's. */
|
|
73
|
+
readonly icon?: string;
|
|
74
|
+
/**
|
|
75
|
+
* Source HTML with the placeholders of `EditorDescriptor.template` (one `{{id}}`, texts as `{{t:key}}`). Other
|
|
76
|
+
* components in it (the gaps of a word bank) are written without an id: each insert gives them fresh ones.
|
|
77
|
+
*/
|
|
78
|
+
readonly template: string;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* One inspector control:
|
|
82
|
+
* - `attribute`: an attribute of the element (control picked from the AttributeSpec type);
|
|
83
|
+
* - `text-list`: repeated private text children (e.g. accepted alternatives `<astl-alt>`);
|
|
84
|
+
* - `child-flag`: a boolean attribute on each child of a tag, listed by the child's text (e.g. which options are
|
|
85
|
+
* correct); its label and help messages get `count` (children) and `checked` (children with the flag);
|
|
86
|
+
* - `child-text`: a free-text attribute on each child of a tag, listed by the child's text (e.g. the word each clue
|
|
87
|
+
* hides); an empty value removes the attribute;
|
|
88
|
+
* - `child-choice`: one value of an attribute on each child of a tag, listed by the child's text: one of the
|
|
89
|
+
* attribute's enum values (e.g. whether each statement is true or false), or with `options`, the id of a child of
|
|
90
|
+
* another tag (e.g. the category of each card).
|
|
91
|
+
* - `child-table`: the children of a tag as rows, each listed by its text, with a control for each of `columns` (by
|
|
92
|
+
* the attribute's type: text, number or a select of its enum values) and a button that removes it; a button adds a
|
|
93
|
+
* row, a child with a fresh local id and a first value for each required attribute (e.g. a crossword's words).
|
|
94
|
+
* - `picture-regions`: zones on the element's picture, one child of `tag` each, drawn with a pointer or typed in
|
|
95
|
+
* number fields. A zone has `id` (local), `shape` (`rect`, `circle` or `polygon`), `x` and `y` (rect: its top-left
|
|
96
|
+
* corner; circle: its centre), `width` and `height` (rect), `r` (circle, a share of the width), `points`
|
|
97
|
+
* (polygon: `x,y x,y ...`) and an optional `label`. Every coordinate is a percentage of the picture, which never
|
|
98
|
+
* mirrors: x of its width from the left edge, y of its height from the top.
|
|
99
|
+
* - `picture-points`: pins on the picture, one child of `tag` each: `id`, `x` and `y` (percent) and `label`.
|
|
100
|
+
* Both show the picture of the element's `url` attribute `src`, which they set by upload or address.
|
|
101
|
+
* Rich content (prompts, option texts) is edited in the WYSIWYG itself. The children of a tag are found anywhere in
|
|
102
|
+
* the element, so the inline children of a type with rich content (`content: 'flow'`) are listed too.
|
|
103
|
+
*/
|
|
104
|
+
export type InspectorField = {
|
|
105
|
+
readonly kind: 'attribute';
|
|
106
|
+
/** Attribute name, e.g. `answer`. */
|
|
107
|
+
readonly name: string;
|
|
108
|
+
/** Message key of the label. */
|
|
109
|
+
readonly label: string;
|
|
110
|
+
/** Message key of help text, optional. */
|
|
111
|
+
readonly help?: string;
|
|
112
|
+
/**
|
|
113
|
+
* A `url` attribute: the files an author may upload for it with the host's `uploadAsset` (a file input's
|
|
114
|
+
* `accept`, e.g. `video/mp4,video/webm`). Absent, or without an upload, the address is typed.
|
|
115
|
+
*/
|
|
116
|
+
readonly accept?: string;
|
|
117
|
+
/**
|
|
118
|
+
* Choices from another element of the document, in a select: the ids of the `tag` children of the element whose
|
|
119
|
+
* id is in this element's attribute `from`, listed by their text (e.g. the words of the bank a drop takes its
|
|
120
|
+
* words from). Without the document or that element, the attribute's own control.
|
|
121
|
+
*/
|
|
122
|
+
readonly options?: {
|
|
123
|
+
readonly from: string;
|
|
124
|
+
readonly tag: string;
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* Shown only while the element shows one of these variants (its valid `variant`, else the manifest's default),
|
|
128
|
+
* for an attribute that only one presentation reads (a dropdown's `native`). Absent: shown in every variant.
|
|
129
|
+
*/
|
|
130
|
+
readonly variants?: readonly string[];
|
|
131
|
+
} | {
|
|
132
|
+
readonly kind: 'text-list';
|
|
133
|
+
/** Child tag, e.g. `astl-alt`. */
|
|
134
|
+
readonly tag: string;
|
|
135
|
+
readonly label: string;
|
|
136
|
+
readonly help?: string;
|
|
137
|
+
/** Each child in a text area that keeps its line breaks (a transcript), not on one line. */
|
|
138
|
+
readonly multiline?: boolean;
|
|
139
|
+
} | {
|
|
140
|
+
readonly kind: 'child-flag' | 'child-text';
|
|
141
|
+
/** Child tag, e.g. `astl-option`. */
|
|
142
|
+
readonly tag: string;
|
|
143
|
+
/** Attribute on each child: a boolean for `child-flag` (e.g. `correct`), a string for `child-text`. */
|
|
144
|
+
readonly attribute: string;
|
|
145
|
+
readonly label: string;
|
|
146
|
+
readonly help?: string;
|
|
147
|
+
} | {
|
|
148
|
+
readonly kind: 'child-choice';
|
|
149
|
+
/** Child tag, e.g. `astl-statement` or `astl-card`. */
|
|
150
|
+
readonly tag: string;
|
|
151
|
+
/** Attribute on each child, e.g. `answer` or `category`. */
|
|
152
|
+
readonly attribute: string;
|
|
153
|
+
/**
|
|
154
|
+
* Where the choices come from. Absent: the attribute's enum values (`editor.value.<attribute>.<value>`, e.g.
|
|
155
|
+
* true / false of each statement). A child tag: the ids of the element's children with that tag, listed by their
|
|
156
|
+
* text (e.g. `astl-category` for the category of each card).
|
|
157
|
+
*/
|
|
158
|
+
readonly options?: string;
|
|
159
|
+
readonly label: string;
|
|
160
|
+
readonly help?: string;
|
|
161
|
+
} | {
|
|
162
|
+
readonly kind: 'child-table';
|
|
163
|
+
/** Child tag, e.g. `astl-crossword-word`. */
|
|
164
|
+
readonly tag: string;
|
|
165
|
+
/** The child's attributes edited in each row, in order, each with the message key of its label. */
|
|
166
|
+
readonly columns: readonly {
|
|
167
|
+
readonly attribute: string;
|
|
168
|
+
readonly label: string;
|
|
169
|
+
}[];
|
|
170
|
+
readonly label: string;
|
|
171
|
+
readonly help?: string;
|
|
172
|
+
} | {
|
|
173
|
+
readonly kind: 'picture-regions' | 'picture-points';
|
|
174
|
+
/** Child tag of a zone or a pin, e.g. `astl-region`. */
|
|
175
|
+
readonly tag: string;
|
|
176
|
+
/** The element's `url` attribute that holds the picture, e.g. `src`. */
|
|
177
|
+
readonly src: string;
|
|
178
|
+
readonly label: string;
|
|
179
|
+
readonly help?: string;
|
|
180
|
+
};
|
|
181
|
+
/** The component the cursor is in, by source id. */
|
|
182
|
+
export interface EditorSelection {
|
|
183
|
+
readonly id: string;
|
|
184
|
+
readonly tag: string;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* A text format a toolbar toggles (`EditorAdapter.format`), each one of content format 1: the marks `bold`
|
|
188
|
+
* (`<strong>` or `<b>`), `italic` (`<em>` or `<i>`), `underline` (`<u>`) and `link` (`<a href>`); the text styles
|
|
189
|
+
* `paragraph` (`<p>`), `heading` (`<h3>`, below the page title the player shows as `<h2>`) and `subheading` (`<h4>`);
|
|
190
|
+
* the lists `bulleted` (`<ul>`) and `numbered` (`<ol>`).
|
|
191
|
+
*/
|
|
192
|
+
export type EditorFormat = 'bold' | 'italic' | 'underline' | 'link' | 'paragraph' | 'heading' | 'subheading' | 'bulleted' | 'numbered';
|
|
193
|
+
/** The formats at the cursor (`EditorAdapter.formatState`), for a toolbar's pressed and disabled buttons. */
|
|
194
|
+
export interface EditorFormatState {
|
|
195
|
+
/**
|
|
196
|
+
* The formats in effect: each mark on all of the selected text (at a cursor: the text before it), the text style of
|
|
197
|
+
* the block at the cursor (an `<h2>` counts as `heading`) and the list it is in.
|
|
198
|
+
*/
|
|
199
|
+
readonly active: readonly EditorFormat[];
|
|
200
|
+
/**
|
|
201
|
+
* The formats that can be toggled here: none while a component is selected, marks only in text a component holds
|
|
202
|
+
* (an option, a word), all of them in a page's own text.
|
|
203
|
+
*/
|
|
204
|
+
readonly enabled: readonly EditorFormat[];
|
|
205
|
+
/** The address of the link at the cursor, or null. */
|
|
206
|
+
readonly href: string | null;
|
|
207
|
+
/** Whether `undo` would change the document. */
|
|
208
|
+
readonly undo: boolean;
|
|
209
|
+
/** Whether `redo` would change the document. */
|
|
210
|
+
readonly redo: boolean;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* A block by its place. A page's content is a list of blocks: each block component (`display: 'block'`) directly on
|
|
214
|
+
* the page is one block, and the content between two of them (paragraphs, headings, lists, quotes, pictures, with the
|
|
215
|
+
* inline components in their text) is one text block. The authoring kit's outline lists the same blocks
|
|
216
|
+
* (`OutlinePage.blocks`). The content format has no blocks: they are a way to show and move a page's content. A
|
|
217
|
+
* layout is not a block either: the blocks in its columns are on the page's list, in reading order, and a column's
|
|
218
|
+
* content divides as a page's does.
|
|
219
|
+
*/
|
|
220
|
+
export interface EditorBlockPlace {
|
|
221
|
+
/** The page's source id, or null for the content of a document without pages. */
|
|
222
|
+
readonly page: string | null;
|
|
223
|
+
/** The block's index on its page, from 0. */
|
|
224
|
+
readonly index: number;
|
|
225
|
+
}
|
|
226
|
+
/** How `EditorAdapter.insert` places a snippet. */
|
|
227
|
+
export interface EditorInsertOptions {
|
|
228
|
+
/**
|
|
229
|
+
* The snippet replaces the selected text (`EditorAdapter.selectedText`), e.g. a gap whose answer is that text.
|
|
230
|
+
* Default false: it goes after the cursor and the selection stays.
|
|
231
|
+
*/
|
|
232
|
+
readonly replaceSelection?: boolean;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* What takes a style besides the selected text (`EditorStyles`): a picture in text or in a figure, a figure, the text
|
|
236
|
+
* block with the cursor (a paragraph, a heading, a caption, an option), a component, a column or a layout.
|
|
237
|
+
*/
|
|
238
|
+
export type EditorStyleTargetKind = 'picture' | 'figure' | 'block' | 'component' | 'column' | 'layout';
|
|
239
|
+
/** An element at the cursor that takes a style (`EditorStyleState.targets`). */
|
|
240
|
+
export interface EditorStyleTarget {
|
|
241
|
+
readonly kind: EditorStyleTargetKind;
|
|
242
|
+
/** Its tag in the source: `p`, `img`, `astl-choice`. */
|
|
243
|
+
readonly tag: string;
|
|
244
|
+
/** Its own `style` in the allow-list's normal form (`name: value; name: value`), `''` without one. */
|
|
245
|
+
readonly style: string;
|
|
246
|
+
/** The named style on it (the first, for a source written by hand with more), or null. */
|
|
247
|
+
readonly className: string | null;
|
|
248
|
+
}
|
|
249
|
+
/** The state at the cursor (`EditorStyles.state`), for a toolbar and a form. */
|
|
250
|
+
export interface EditorStyleState {
|
|
251
|
+
/** Whether styles can go on text here: not with a component or a picture selected. */
|
|
252
|
+
readonly textEnabled: boolean;
|
|
253
|
+
/** Text is selected; without it, only a cursor. */
|
|
254
|
+
readonly hasSelection: boolean;
|
|
255
|
+
/** The declarations all of the selected text has, or what typing would get at the cursor. */
|
|
256
|
+
readonly text: Readonly<Record<string, string>>;
|
|
257
|
+
/** The properties that differ across the selected text. */
|
|
258
|
+
readonly mixed: readonly string[];
|
|
259
|
+
/** The named style on all of the selected text, or at the cursor; null: none, or not the same throughout. */
|
|
260
|
+
readonly textClass: string | null;
|
|
261
|
+
/** What the cursor is in, from the inside out. */
|
|
262
|
+
readonly targets: readonly EditorStyleTarget[];
|
|
263
|
+
}
|
|
264
|
+
/** Declarations to set; null removes one. Only what the style allow-list keeps is ever written. */
|
|
265
|
+
export type EditorStyleChanges = Readonly<Record<string, string | null>>;
|
|
266
|
+
/** A rule of the document (`<astl-style>`): a named style (`name`, `label`), or the style of a tag (`for`). */
|
|
267
|
+
export interface EditorStyleRule {
|
|
268
|
+
readonly name?: string;
|
|
269
|
+
readonly label?: string;
|
|
270
|
+
readonly for?: string;
|
|
271
|
+
readonly style: string;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* The styling commands of an editor (`EditorAdapter.style`). Each is one undo step, keeps the cursor and leaves the
|
|
275
|
+
* focus where it is, so a form beside the text can call them on every change.
|
|
276
|
+
*/
|
|
277
|
+
export interface EditorStyles {
|
|
278
|
+
state(): EditorStyleState;
|
|
279
|
+
/**
|
|
280
|
+
* Sets declarations on the selected text; with only a cursor, on what is typed next. Text ends up in one span, whose
|
|
281
|
+
* language and classes stay; a span left with nothing goes. Returns whether anything changed.
|
|
282
|
+
*/
|
|
283
|
+
setText(changes: EditorStyleChanges): boolean;
|
|
284
|
+
/** Sets declarations on the target of this kind at the cursor; `block`: on each text block of the selection. */
|
|
285
|
+
setTarget(kind: EditorStyleTargetKind, changes: EditorStyleChanges): boolean;
|
|
286
|
+
/** Replaces the target's own style with what the allow-list keeps of `style` (the "Own CSS" field). */
|
|
287
|
+
replaceTarget(kind: EditorStyleTargetKind, style: string): boolean;
|
|
288
|
+
/**
|
|
289
|
+
* Sets the named style on the selected text (`text`) or a target, in the place of any other; null clears it. With
|
|
290
|
+
* `rule` (a ready style: a named rule of the same `name`), a document without a rule of that name gets it in the same
|
|
291
|
+
* undo step; a rule of the document's own by that name stays as it is. Returns false, changing nothing, for a `rule`
|
|
292
|
+
* of another name or with `for`, a new rule past the limit, or a class that changes nothing (no target, or there).
|
|
293
|
+
*/
|
|
294
|
+
setClass(where: 'text' | EditorStyleTargetKind, name: string | null, rule?: EditorStyleRule): boolean;
|
|
295
|
+
/**
|
|
296
|
+
* Clears formatting: the marks and styles of the selected text (a language and a link stay), and the style and named
|
|
297
|
+
* style of the blocks it covers whole; with only a cursor, of its block.
|
|
298
|
+
*/
|
|
299
|
+
clear(): boolean;
|
|
300
|
+
/** The document's rules, in order. */
|
|
301
|
+
rules(): readonly EditorStyleRule[];
|
|
302
|
+
/**
|
|
303
|
+
* Adds a rule, or changes the one with its `name` or `for`, in place. A tag's rule without declarations goes. Returns
|
|
304
|
+
* false, changing nothing, for a name the format refuses, or a new rule past the limit.
|
|
305
|
+
*/
|
|
306
|
+
setRule(rule: EditorStyleRule): boolean;
|
|
307
|
+
/** Deletes a rule; a named style's class goes from every element too. Returns false for an unknown rule. */
|
|
308
|
+
removeRule(rule: Pick<EditorStyleRule, 'name' | 'for'>): boolean;
|
|
309
|
+
/**
|
|
310
|
+
* Makes the target's own style a named style: a new rule labelled `label`, the target's `style` gone and its class
|
|
311
|
+
* the new name, which it returns. Null, changing nothing, past the limit or without a target of this kind.
|
|
312
|
+
*/
|
|
313
|
+
saveRule(kind: EditorStyleTargetKind, label: string): string | null;
|
|
314
|
+
/** Inserts a layout (source HTML, one `<astl-columns>`) as `insert` does, the cursor in its first empty block. */
|
|
315
|
+
insertLayout(html: string): boolean;
|
|
316
|
+
/** The layout the cursor is in, or null. Absent: the editor cannot change a layout once inserted. */
|
|
317
|
+
layout?(): EditorLayoutState | null;
|
|
318
|
+
/**
|
|
319
|
+
* Changes the layout the cursor is in, in one undo step: `unwrap` removes the columns and keeps their content in
|
|
320
|
+
* place, one column after another; `delete` removes it with its content (a host asks first when it holds any); a
|
|
321
|
+
* shape gives it that many columns, the content kept: a column that goes gives its content to the last one left.
|
|
322
|
+
* Returns false, changing nothing, without a layout at the cursor or for the shape it has.
|
|
323
|
+
*/
|
|
324
|
+
editLayout?(edit: EditorLayoutEdit): boolean;
|
|
325
|
+
}
|
|
326
|
+
/** The shapes a layout can be changed to: two or three equal columns, or a wide and a narrow one. */
|
|
327
|
+
export type EditorLayoutShape = 'two' | 'three' | 'wide-narrow' | 'narrow-wide';
|
|
328
|
+
/** What `EditorStyles.editLayout` does to the layout at the cursor. */
|
|
329
|
+
export type EditorLayoutEdit = 'unwrap' | 'delete' | EditorLayoutShape;
|
|
330
|
+
/** The layout at the cursor (`EditorStyles.layout`). */
|
|
331
|
+
export interface EditorLayoutState {
|
|
332
|
+
/** Its shape, or null for one of none (four columns, other widths). */
|
|
333
|
+
readonly shape: EditorLayoutShape | null;
|
|
334
|
+
readonly columns: number;
|
|
335
|
+
/** Whether its columns hold nothing but empty paragraphs: it can go without asking. */
|
|
336
|
+
readonly empty: boolean;
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* What a WYSIWYG integration must provide so the authoring kit can drive it. Everything is in source HTML
|
|
340
|
+
* (the `<astl-doc>` format), so an adapter is free to use any internal model.
|
|
341
|
+
*/
|
|
342
|
+
export interface EditorAdapter {
|
|
343
|
+
/** The whole document as source HTML. */
|
|
344
|
+
getSource(): string;
|
|
345
|
+
/** Replaces the whole document. */
|
|
346
|
+
setSource(source: string): void;
|
|
347
|
+
/**
|
|
348
|
+
* Inserts a source snippet (an instantiated template) at the cursor, never into a component: after the component the
|
|
349
|
+
* cursor is in. With `replaceSelection`, an inline snippet takes the place of the selected text. A rich-text editor
|
|
350
|
+
* keeps the text whole: a snippet of blocks (a block component, a paragraph) goes after the element the cursor is in
|
|
351
|
+
* directly on its page or column (a paragraph, a heading, a list), or in the place of that element when it is an
|
|
352
|
+
* empty paragraph; a layout goes after the layout the cursor is in, as layouts do not nest. A source editor (the
|
|
353
|
+
* textarea adapter) puts any snippet at the caret, as the author would type it.
|
|
354
|
+
*/
|
|
355
|
+
insert(html: string, options?: EditorInsertOptions): void;
|
|
356
|
+
/** Source HTML of one component element, or null when the id is not in the document. */
|
|
357
|
+
getElement(id: string): string | null;
|
|
358
|
+
/** Replaces one component element in place (inspector edits); the rest of the document is untouched. */
|
|
359
|
+
replaceElement(id: string, html: string): void;
|
|
360
|
+
/** The component at the cursor, or null. */
|
|
361
|
+
getSelection(): EditorSelection | null;
|
|
362
|
+
/** Moves the cursor to an element by source id (a component or a page) and focuses the editor. */
|
|
363
|
+
select(id: string): void;
|
|
364
|
+
/** Subscribe to document changes. Returns an unsubscribe function. */
|
|
365
|
+
onChange(listener: () => void): () => void;
|
|
366
|
+
/** Subscribe to selection changes. Returns an unsubscribe function. */
|
|
367
|
+
onSelectionChange(listener: (selection: EditorSelection | null) => void): () => void;
|
|
368
|
+
/**
|
|
369
|
+
* Runs the `wrap` command of the type `tag` (`EditorDescriptor.wrap`) on the selection and focuses the editor;
|
|
370
|
+
* returns whether the document changed. Absent: the editor offers no such command.
|
|
371
|
+
*/
|
|
372
|
+
wrap?(tag: string): boolean;
|
|
373
|
+
/**
|
|
374
|
+
* A page break at the cursor (at the start of a selection, which stays): a new page from there on, whose id it
|
|
375
|
+
* returns, or null when the cursor is in no page's content. In a paragraph or a heading directly on a page, the page
|
|
376
|
+
* breaks at the cursor (at its start: before it; at its end: after it); anywhere else (a component, a rich block, a
|
|
377
|
+
* list, a column of a layout) after the block directly on the page, which stays whole. A side left without content gets one empty
|
|
378
|
+
* paragraph. The new page has a fresh id `page-<n>` (pages and components share one namespace), no `label`, and the
|
|
379
|
+
* `lang` and `dir` of the page it comes from; the cursor goes to the start of its first line. A document without
|
|
380
|
+
* pages becomes pages in the same step, the first with a fresh id too. One undo step. Absent: the editor cannot
|
|
381
|
+
* split pages.
|
|
382
|
+
*/
|
|
383
|
+
splitPage?(): string | null;
|
|
384
|
+
/**
|
|
385
|
+
* Adds an empty page (one empty paragraph) after the page `after`, or after the last page when `after` is not the
|
|
386
|
+
* id of one, and returns its id: fresh (`page-<n>`), without a `label`, `lang` or `dir`. The cursor goes into it. A
|
|
387
|
+
* document without pages becomes its first page in the same step. One undo step.
|
|
388
|
+
*/
|
|
389
|
+
addPage?(after?: string): string;
|
|
390
|
+
/**
|
|
391
|
+
* Joins the page `id` to the page before it: its content follows that page's content, and that page keeps its id,
|
|
392
|
+
* `label`, `lang` and `dir`. The cursor goes to the start of the joined content. Returns false, changing nothing, for
|
|
393
|
+
* the first page or an id that is not a page's. One undo step.
|
|
394
|
+
*/
|
|
395
|
+
mergePage?(id: string): boolean;
|
|
396
|
+
/**
|
|
397
|
+
* Deletes the page `id` and everything on it. The cursor goes to the start of the page before it, or of the next
|
|
398
|
+
* page when it was the first. Returns false, changing nothing, for the only page or an id that is not a page's. One
|
|
399
|
+
* undo step.
|
|
400
|
+
*/
|
|
401
|
+
removePage?(id: string): boolean;
|
|
402
|
+
/**
|
|
403
|
+
* Toggles a format on the selection and focuses the editor; returns whether the document changed. A mark goes on
|
|
404
|
+
* all of the selected text, or off when all of it has it; `link` with an `href` links the selected text (or changes
|
|
405
|
+
* the link at the cursor) and without one removes the link at the cursor; a text style sets the blocks of the
|
|
406
|
+
* selection to it (`heading` or `subheading` again sets `paragraph`); a list wraps them in that list, turns the
|
|
407
|
+
* other list into it, or lifts them out of it. One undo step. Absent (with `formatState`): no formatting commands.
|
|
408
|
+
*/
|
|
409
|
+
format?(format: EditorFormat, href?: string): boolean;
|
|
410
|
+
/** The formats at the cursor and whether undo or redo can run. Present with `format`. */
|
|
411
|
+
formatState?(): EditorFormatState;
|
|
412
|
+
/** Undoes the last step and focuses the editor; returns whether the document changed. Absent: no history. */
|
|
413
|
+
undo?(): boolean;
|
|
414
|
+
/** Redoes the last undone step and focuses the editor; returns whether the document changed. */
|
|
415
|
+
redo?(): boolean;
|
|
416
|
+
/**
|
|
417
|
+
* Moves a block one place up or down within its page, the cursor with it; returns false, changing nothing, at the
|
|
418
|
+
* page's start or end or for a place that holds no block. One undo step. Absent: blocks do not move. A block in a
|
|
419
|
+
* column stays in its column; a block directly on the page moves past a whole layout, which itself never moves.
|
|
420
|
+
*/
|
|
421
|
+
moveBlock?(block: EditorBlockPlace, direction: 'up' | 'down'): boolean;
|
|
422
|
+
/**
|
|
423
|
+
* Deletes a block: its component, or all of its text; a page or a column left without content keeps one empty
|
|
424
|
+
* paragraph.
|
|
425
|
+
* Returns false, changing nothing, for a place that holds no block. One undo step.
|
|
426
|
+
*/
|
|
427
|
+
removeBlock?(block: EditorBlockPlace): boolean;
|
|
428
|
+
/**
|
|
429
|
+
* The block holding the cursor (in a document without pages: `page` null), or null while the editor has no cursor
|
|
430
|
+
* in content. A host follows it to show the page being edited.
|
|
431
|
+
*/
|
|
432
|
+
getCursor?(): EditorBlockPlace | null;
|
|
433
|
+
/**
|
|
434
|
+
* Subscribe to every move of the cursor and every change of the document or its history: what `getCursor` and
|
|
435
|
+
* `formatState` return may have changed. Returns an unsubscribe function. Present with either.
|
|
436
|
+
*/
|
|
437
|
+
onCursorChange?(listener: () => void): () => void;
|
|
438
|
+
/**
|
|
439
|
+
* The plain text of the selection when it lies within one text block (trimmed), else `''`. A template's
|
|
440
|
+
* `{{selection}}` takes it, and `insert` with `replaceSelection` puts the snippet in its place. Absent: `''`.
|
|
441
|
+
*/
|
|
442
|
+
selectedText?(): string;
|
|
443
|
+
/**
|
|
444
|
+
* Focuses the editor, its cursor where it was (after a toolbar press from the keyboard). An editor that has the focus
|
|
445
|
+
* is left as it is, so a click there a moment before keeps its cursor.
|
|
446
|
+
*/
|
|
447
|
+
focus?(): void;
|
|
448
|
+
/** Styles at the cursor, named styles and layouts. Absent: an editor of source text (the textarea), no controls. */
|
|
449
|
+
readonly style?: EditorStyles;
|
|
450
|
+
}
|
|
451
|
+
//# sourceMappingURL=authoring.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authoring.d.ts","sourceRoot":"","sources":["../src/authoring.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEvD;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,QAAQ,EAAE,iBAAiB,CAAC;IACrC,iFAAiF;IACjF,QAAQ,CAAC,QAAQ,CAAC,EA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CAAC;IACvE;;;;OAIG;IACH,WAAW,CAAC,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC;IAC/C;;;OAGG;IACH,SAAS,CAAC,IAAI,gBAAgB,GAAG,IAAI,CAAC;IACtC;;;OAGG;IACH,cAAc,CAAC,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC;IAClD;;;OAGG;IACH,YAAY,CAAC,IAAI,MAAM,CAAC;IACxB;;;OAGG;IACH,KAAK,CAAC,IAAI,IAAI,CAAC;IACf,oHAAoH;IACpH,QAAQ,CAAC,KAAK,CAAC,EAAE,YAAY,CAAC;CAC/B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authoring.js","sourceRoot":"","sources":["../src/authoring.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checker: how a player gets verdicts without ever holding the answer key (unless the host opts into local grading).
|
|
3
|
+
* The HTTP binding of these bodies is the grading protocol (see protocol.ts and
|
|
4
|
+
* apps/docs/src/content/docs/reference/protocol.md).
|
|
5
|
+
*/
|
|
6
|
+
import type { Answers } from './answers.js';
|
|
7
|
+
import type { Feedback } from './help.js';
|
|
8
|
+
import type { ProblemDetails } from './protocol.js';
|
|
9
|
+
import type { GradeResult, Solution } from './result.js';
|
|
10
|
+
export interface CheckRequest {
|
|
11
|
+
readonly answers: Answers;
|
|
12
|
+
/** View page id: grade only that page. Omit to grade everything. */
|
|
13
|
+
readonly page?: string;
|
|
14
|
+
/**
|
|
15
|
+
* View element id: grade that interaction only, under a policy with `checkScope: 'interaction'`. It counts against
|
|
16
|
+
* `maxChecks` like any check. Never together with `page`.
|
|
17
|
+
*/
|
|
18
|
+
readonly element?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Help that comes with a result when the policy shows it (the engine's `helpShown`), for what was graded: absent when there is
|
|
22
|
+
* none, so responses without help stay as they were.
|
|
23
|
+
*/
|
|
24
|
+
export interface ResultHelp {
|
|
25
|
+
/** By view element id, and by view page id for a page's own feedback (picked by the page's score). */
|
|
26
|
+
readonly feedback?: Readonly<Record<string, Feedback>>;
|
|
27
|
+
/** HTML by view element id or view page id. */
|
|
28
|
+
readonly explanations?: Readonly<Record<string, string>>;
|
|
29
|
+
}
|
|
30
|
+
export interface CheckResponse extends ResultHelp {
|
|
31
|
+
readonly result: GradeResult;
|
|
32
|
+
/** Checks left in this attempt; null = unlimited. */
|
|
33
|
+
readonly checksLeft: number | null;
|
|
34
|
+
}
|
|
35
|
+
export interface SubmitRequest {
|
|
36
|
+
readonly answers: Answers;
|
|
37
|
+
}
|
|
38
|
+
export interface SubmitResponse extends ResultHelp {
|
|
39
|
+
/** null when the policy reveals nothing yet. */
|
|
40
|
+
readonly result: GradeResult | null;
|
|
41
|
+
/** Only when the policy reveals answers. */
|
|
42
|
+
readonly solution: Solution | null;
|
|
43
|
+
/** null when there is no pass mark or nothing is revealed. */
|
|
44
|
+
readonly passed: boolean | null;
|
|
45
|
+
/** ISO 8601, set by whoever grades. */
|
|
46
|
+
readonly submittedAt: string;
|
|
47
|
+
}
|
|
48
|
+
export interface HintRequest {
|
|
49
|
+
/** View element id, or a view page id for the page's own hints. */
|
|
50
|
+
readonly element: string;
|
|
51
|
+
}
|
|
52
|
+
/** The next hint of an interaction or page. Whoever grades records it: a hint's cost counts when it is used. */
|
|
53
|
+
export interface HintResponse {
|
|
54
|
+
/** HTML of content format 1. */
|
|
55
|
+
readonly html: string;
|
|
56
|
+
/** 0-based position of this hint. */
|
|
57
|
+
readonly index: number;
|
|
58
|
+
/** Hints still to come after this one. */
|
|
59
|
+
readonly left: number;
|
|
60
|
+
/** The fraction 0..1 of the points this hint takes off (0: free). */
|
|
61
|
+
readonly cost: number;
|
|
62
|
+
}
|
|
63
|
+
export interface Checker {
|
|
64
|
+
/** Practice only. Rejects with CheckerError (`check_not_allowed`) under other policies. */
|
|
65
|
+
check(request: CheckRequest): Promise<CheckResponse>;
|
|
66
|
+
submit(request: SubmitRequest): Promise<SubmitResponse>;
|
|
67
|
+
/**
|
|
68
|
+
* The next hint, practice only; checkers without hints leave it out. Rejects with CheckerError `hints_not_allowed`
|
|
69
|
+
* when the policy offers none, `hints_exhausted` when all are used, `not_found` for an unknown element.
|
|
70
|
+
*/
|
|
71
|
+
hint?(request: HintRequest): Promise<HintResponse>;
|
|
72
|
+
}
|
|
73
|
+
/** Thrown by checkers for protocol-level refusals, carrying the RFC 9457 problem document. */
|
|
74
|
+
export declare class CheckerError extends Error {
|
|
75
|
+
readonly problem: ProblemDetails;
|
|
76
|
+
constructor(problem: ProblemDetails);
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=checker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checker.d.ts","sourceRoot":"","sources":["../src/checker.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEzD,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,oEAAoE;IACpE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,sGAAsG;IACtG,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;IACvD,+CAA+C;IAC/C,QAAQ,CAAC,YAAY,CAAC,EAAE,QAAQ,CAAC,MA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C,CAAC;CACpD;AAED,8FAA8F;AAC9F,qBAAa,YAAa,SAAQ,KAAK;IACrC,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;IAEjC,YAAY,OAAO,EAAE,cAAc,EAIlC;CACF"}
|
package/dist/checker.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Thrown by checkers for protocol-level refusals, carrying the RFC 9457 problem document. */
|
|
2
|
+
export class CheckerError extends Error {
|
|
3
|
+
problem;
|
|
4
|
+
constructor(problem) {
|
|
5
|
+
super(problem.detail ?? problem.title);
|
|
6
|
+
this.name = 'CheckerError';
|
|
7
|
+
this.problem = problem;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=checker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checker.js","sourceRoot":"","sources":["../src/checker.ts"],"names":[],"mappings":"AAiFA,8FAA8F;AAC9F,MAAM,OAAO,YAAa,SAAQ,KAAK;IAC5B,OAAO,CAAiB;IAEjC,YAAY,OAAuB;QACjC,KAAK,CAAC,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC;QACvC,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CACF"}
|