@astl/editor 0.2.0 → 0.2.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 +14 -0
- package/dist/elements/help-form.d.ts +22 -7
- package/dist/elements/help-form.d.ts.map +1 -1
- package/dist/elements/help-form.js +271 -94
- package/dist/elements/help-form.js.map +1 -1
- package/dist/elements/inspector.d.ts +7 -0
- package/dist/elements/inspector.d.ts.map +1 -1
- package/dist/elements/inspector.js +18 -1
- package/dist/elements/inspector.js.map +1 -1
- package/dist/elements/style-load.d.ts +14 -0
- package/dist/elements/style-load.d.ts.map +1 -1
- package/dist/elements/style-load.js +7 -0
- package/dist/elements/style-load.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/messages/en.json +3 -1
- package/dist/messages/help/en.json +3 -2
- package/dist/messages/help/pl.json +3 -2
- package/dist/messages/pl.json +3 -1
- package/package.json +5 -5
- package/src/elements/help-form.ts +299 -103
- package/src/elements/inspector.ts +19 -2
- package/src/elements/style-load.ts +17 -0
- package/src/index.ts +2 -2
- package/src/messages/en.json +3 -1
- package/src/messages/help/en.json +3 -2
- package/src/messages/help/pl.json +3 -2
- package/src/messages/pl.json +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @astl/editor
|
|
2
2
|
|
|
3
|
+
## 0.2.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 8ce6118: The editor shows an exercise closer to the students' view: a question's help for students is no longer drawn on the surface. Its frame's tab says what it has with tags ("2 hints", "Explanation", "Feedback"), and a tag puts the cursor in the question and opens that help in the card, focused (`astl-help-open`, cancelable, `detail: { element, part }`; `AstlInspector.openHelp(part)`). The source keeps the help as the question's children, so a copy or an undo keeps it.
|
|
8
|
+
|
|
9
|
+
The card's "Help for students" is a disclosure, closed for each element until opened, that says what the element has ("2 hints · explanation"). Its buttons to order and remove hints, and to remove the explanation or a feedback text, are icons named by their task. "Add a hint" (in the card or "Elements") adds a draft that reaches the source with its first text, and the menu's "Explanation" and "Feedback" open their field, so adding help no longer raises `HELP_EMPTY`. Parts: `help-toggle`, `help-summary`, `help-body`, `help-add`, `help-move`, `help-remove` (on `<astl-editor>` as `inspector-help-*`).
|
|
10
|
+
|
|
11
|
+
Help on the page stays a box, more compact, with a cross to remove it; an empty one has a line that says what to write there.
|
|
12
|
+
- @astl/core@0.2.1
|
|
13
|
+
- @astl/engine@0.2.1
|
|
14
|
+
- @astl/player@0.2.1
|
|
15
|
+
- @astl/tokens@0.2.1
|
|
16
|
+
|
|
3
17
|
## 0.2.0
|
|
4
18
|
|
|
5
19
|
### Minor Changes
|
|
@@ -1,18 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `<astl-help-form>`: the inspector's "Help for students" section of a graded element
|
|
3
|
-
*
|
|
4
|
-
* element
|
|
5
|
-
*
|
|
2
|
+
* `<astl-help-form>`: the inspector's "Help for students" section of a graded element, a disclosure closed for each
|
|
3
|
+
* element until it is opened (its button, a tag on the element's frame, the insert menu): closed, it says what the
|
|
4
|
+
* element has ("2 hints · explanation"); open, its hints in order, each with its cost (Up, Down, a drag, Remove, Add),
|
|
5
|
+
* its explanation and its four feedback texts. Every edit rewrites the element's help (`writeHelp`) through
|
|
6
|
+
* `EditorAdapter.replaceElement`; a hint added here is a draft until it has text, so nothing empty reaches the source. A
|
|
7
|
+
* module of its own, outside the editor's first load (`loadHelpForm`), with its messages; `addHelp` is the insert
|
|
8
|
+
* menu's way in, `openHelp` the inspector's.
|
|
6
9
|
*/
|
|
7
|
-
import { type EditorAdapter } from '@astl/core';
|
|
10
|
+
import { type EditorAdapter, type FeedbackVariant } from '@astl/core';
|
|
8
11
|
import { type CSSResultGroup, nothing, type PropertyDeclarations, type PropertyValues, type TemplateResult } from 'lit';
|
|
9
12
|
import type { Authoring } from '../authoring.js';
|
|
10
13
|
import { AuthoringElement } from './base.js';
|
|
14
|
+
import type { HelpPart } from './style-load.js';
|
|
11
15
|
/** What the insert menu adds: a hint, the explanation, or the next feedback text the element lacks. */
|
|
12
16
|
export type HelpKind = 'hint' | 'explanation' | 'feedback';
|
|
17
|
+
/** Where a form opens: a part, a new hint (a draft), or one feedback text. */
|
|
18
|
+
type HelpPlace = HelpPart | 'hint-new' | `feedback-${FeedbackVariant}`;
|
|
13
19
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
20
|
+
* Opens the help for students of `element` at `place` in the form that shows it (or will): the section opens, a new
|
|
21
|
+
* hint shows as a draft, and the place's first field takes the focus.
|
|
22
|
+
*/
|
|
23
|
+
export declare function openHelp(adapter: EditorAdapter, element: string, place: HelpPlace): void;
|
|
24
|
+
/**
|
|
25
|
+
* Adds help to the graded element at the cursor: its form opens at a new hint (a draft until it has text), at its
|
|
26
|
+
* explanation or at the next feedback text it lacks, writing nothing yet; or else puts the help on the page at the
|
|
27
|
+
* cursor. Returns the HTML inserted on a page, or null when the element's form opened.
|
|
16
28
|
*/
|
|
17
29
|
export declare function addHelp(authoring: Authoring, adapter: EditorAdapter, kind: HelpKind): string | null;
|
|
18
30
|
export declare class AstlHelpForm extends AuthoringElement {
|
|
@@ -24,8 +36,11 @@ export declare class AstlHelpForm extends AuthoringElement {
|
|
|
24
36
|
/** The element sits in a line of text: its help holds text, not paragraphs. */
|
|
25
37
|
inline: boolean;
|
|
26
38
|
constructor();
|
|
39
|
+
connectedCallback(): void;
|
|
40
|
+
disconnectedCallback(): void;
|
|
27
41
|
protected willUpdate(changed: PropertyValues<this>): void;
|
|
28
42
|
protected updated(): void;
|
|
29
43
|
protected render(): TemplateResult | typeof nothing;
|
|
30
44
|
}
|
|
45
|
+
export {};
|
|
31
46
|
//# sourceMappingURL=help-form.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"help-form.d.ts","sourceRoot":"","sources":["../../src/elements/help-form.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"help-form.d.ts","sourceRoot":"","sources":["../../src/elements/help-form.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,KAAK,aAAa,EAAqB,KAAK,eAAe,EAAuB,MAAM,YAAY,CAAC;AAC9G,OAAO,EACL,KAAK,cAAc,EAGnB,OAAO,EACP,KAAK,oBAAoB,EACzB,KAAK,cAAc,EAGnB,KAAK,cAAc,EACpB,MAAM,KAAK,CAAC;AAEb,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAMjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAQhD,uGAAuG;AACvG,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,aAAa,GAAG,UAAU,CAAC;AAE3D,8EAA8E;AAC9E,KAAK,SAAS,GAAG,QAAQ,GAAG,UAAU,GAAG,YAAY,eAAe,EAAE,CAAC;AASvE;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,GAAG,IAAI,CAGxF;AAID;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,IAAI,CAmBnG;AA2BD,qBAAa,YAAa,SAAQ,gBAAgB;;IAChD,OAAgB,UAAU,EAAE,oBAAoB,CAI9C;IAEF,OAAgB,MAAM,EAAE,cAAc,CAwIpC;IAEF,mDAAmD;IAC3C,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,+EAA+E;IACvE,MAAM,EAAE,OAAO,CAAC;IAcxB,cAIC;IAEQ,iBAAiB,IAAI,IAAI,CAGjC;IAEQ,oBAAoB,IAAI,IAAI,CAGpC;IAED,UAAmB,UAAU,CAAC,OAAO,EAAE,cAAc,CAAC,IAAI,CAAC,GAAG,IAAI,CASjE;IAED,UAAmB,OAAO,IAAI,IAAI,CAMjC;IAkWD,UAAmB,MAAM,IAAI,cAAc,GAAG,OAAO,OAAO,CAqB3D;CACF"}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `<astl-help-form>`: the inspector's "Help for students" section of a graded element
|
|
3
|
-
*
|
|
4
|
-
* element
|
|
5
|
-
*
|
|
2
|
+
* `<astl-help-form>`: the inspector's "Help for students" section of a graded element, a disclosure closed for each
|
|
3
|
+
* element until it is opened (its button, a tag on the element's frame, the insert menu): closed, it says what the
|
|
4
|
+
* element has ("2 hints · explanation"); open, its hints in order, each with its cost (Up, Down, a drag, Remove, Add),
|
|
5
|
+
* its explanation and its four feedback texts. Every edit rewrites the element's help (`writeHelp`) through
|
|
6
|
+
* `EditorAdapter.replaceElement`; a hint added here is a draft until it has text, so nothing empty reaches the source. A
|
|
7
|
+
* module of its own, outside the editor's first load (`loadHelpForm`), with its messages; `addHelp` is the insert
|
|
8
|
+
* menu's way in, `openHelp` the inspector's.
|
|
6
9
|
*/
|
|
7
10
|
import { FEEDBACK_VARIANTS } from '@astl/core';
|
|
8
|
-
import { css, html, nothing, } from 'lit';
|
|
11
|
+
import { css, html, nothing, svg, } from 'lit';
|
|
9
12
|
import { live } from 'lit/directives/live.js';
|
|
10
13
|
import { helpFormatted, helpText, readHelp, textHelp, writeHelp } from '../help.js';
|
|
11
14
|
import en from '../messages/help/en.json' with { type: 'json' };
|
|
@@ -18,12 +21,25 @@ const helpMessages = [
|
|
|
18
21
|
{ namespace: EDITOR_NAMESPACE, locale: 'en', messages: en },
|
|
19
22
|
{ namespace: EDITOR_NAMESPACE, locale: 'pl', messages: pl },
|
|
20
23
|
];
|
|
21
|
-
/** The
|
|
24
|
+
/** The place the form of `element` on `adapter` opens at: taken by the form that shows it, now or once it does. */
|
|
22
25
|
let pending = null;
|
|
26
|
+
/** The forms on the page, so a request reaches the one that shows its element. */
|
|
27
|
+
const forms = new Set();
|
|
28
|
+
/**
|
|
29
|
+
* Opens the help for students of `element` at `place` in the form that shows it (or will): the section opens, a new
|
|
30
|
+
* hint shows as a draft, and the place's first field takes the focus.
|
|
31
|
+
*/
|
|
32
|
+
export function openHelp(adapter, element, place) {
|
|
33
|
+
pending = { adapter, element, place };
|
|
34
|
+
for (const form of forms)
|
|
35
|
+
if (form.adapter === adapter && form.element === element)
|
|
36
|
+
form.requestUpdate();
|
|
37
|
+
}
|
|
23
38
|
const graded = (authoring, tag) => authoring.descriptor(tag)?.manifest.graded === true;
|
|
24
39
|
/**
|
|
25
|
-
* Adds help to the graded element at the cursor
|
|
26
|
-
*
|
|
40
|
+
* Adds help to the graded element at the cursor: its form opens at a new hint (a draft until it has text), at its
|
|
41
|
+
* explanation or at the next feedback text it lacks, writing nothing yet; or else puts the help on the page at the
|
|
42
|
+
* cursor. Returns the HTML inserted on a page, or null when the element's form opened.
|
|
27
43
|
*/
|
|
28
44
|
export function addHelp(authoring, adapter, kind) {
|
|
29
45
|
const selection = adapter.getSelection();
|
|
@@ -36,23 +52,8 @@ export function addHelp(authoring, adapter, kind) {
|
|
|
36
52
|
return block;
|
|
37
53
|
}
|
|
38
54
|
const help = readHelp(current);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (kind === 'hint') {
|
|
42
|
-
next = { ...help, hints: [...help.hints, { html: '', cost: null }] };
|
|
43
|
-
field = `hint-${help.hints.length}`;
|
|
44
|
-
}
|
|
45
|
-
else if (kind === 'explanation') {
|
|
46
|
-
next = { ...help, explanation: help.explanation ?? '' };
|
|
47
|
-
field = 'explanation';
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
const when = FEEDBACK_ORDER.find((w) => help.feedback[w] === undefined) ?? 'correct';
|
|
51
|
-
next = { ...help, feedback: { ...help.feedback, [when]: help.feedback[when] ?? '' } };
|
|
52
|
-
field = `feedback-${when}`;
|
|
53
|
-
}
|
|
54
|
-
pending = { element: selection.id, field };
|
|
55
|
-
adapter.replaceElement(selection.id, writeHelp(current, next));
|
|
55
|
+
const when = FEEDBACK_ORDER.find((w) => help.feedback[w] === undefined) ?? 'correct';
|
|
56
|
+
openHelp(adapter, selection.id, kind === 'hint' ? 'hint-new' : kind === 'explanation' ? 'explanation' : `feedback-${when}`);
|
|
56
57
|
return null;
|
|
57
58
|
}
|
|
58
59
|
/** The order the menu fills feedback texts in: right and wrong first. */
|
|
@@ -64,6 +65,14 @@ const costOf = (cost) => cost ?? '0';
|
|
|
64
65
|
/** Rounds points for display, to at most 2 decimals. */
|
|
65
66
|
const round = (n) => Math.round(n * 100) / 100;
|
|
66
67
|
const inputValue = (event) => event.target.value;
|
|
68
|
+
/** The icons of the section: shapes only, stroked by the `.glyph` rule. */
|
|
69
|
+
const ICONS = {
|
|
70
|
+
chevron: svg `<path d="M8 5l5 5-5 5"/>`,
|
|
71
|
+
up: svg `<path d="M10 16V4M5 9l5-5 5 5"/>`,
|
|
72
|
+
down: svg `<path d="M10 4v12M5 11l5 5 5-5"/>`,
|
|
73
|
+
remove: svg `<path d="M5 5l10 10M15 5L5 15"/>`,
|
|
74
|
+
};
|
|
75
|
+
const icon = (name) => html `<svg class="glyph" viewBox="0 0 20 20" aria-hidden="true" focusable="false">${ICONS[name]}</svg>`;
|
|
67
76
|
export class AstlHelpForm extends AuthoringElement {
|
|
68
77
|
static properties = {
|
|
69
78
|
...AuthoringElement.properties,
|
|
@@ -80,13 +89,44 @@ export class AstlHelpForm extends AuthoringElement {
|
|
|
80
89
|
display: flex;
|
|
81
90
|
flex-direction: column;
|
|
82
91
|
gap: var(--astl-space-3);
|
|
83
|
-
padding-block-start: var(--astl-space-
|
|
92
|
+
padding-block-start: var(--astl-space-2);
|
|
84
93
|
border-block-start: var(--astl-outline-width) solid var(--astl-line);
|
|
85
94
|
}
|
|
86
95
|
h3 {
|
|
87
96
|
margin: 0;
|
|
88
97
|
font-size: 1rem;
|
|
89
98
|
}
|
|
99
|
+
.toggle {
|
|
100
|
+
inline-size: 100%;
|
|
101
|
+
flex-wrap: wrap;
|
|
102
|
+
gap: 0 var(--astl-space-2);
|
|
103
|
+
padding-inline: var(--astl-space-1);
|
|
104
|
+
border-color: transparent;
|
|
105
|
+
background: transparent;
|
|
106
|
+
font-weight: 700;
|
|
107
|
+
}
|
|
108
|
+
.toggle .glyph {
|
|
109
|
+
flex: none;
|
|
110
|
+
transition: rotate 0.15s;
|
|
111
|
+
}
|
|
112
|
+
.toggle[aria-expanded='true'] .glyph {
|
|
113
|
+
rotate: 90deg;
|
|
114
|
+
}
|
|
115
|
+
.toggle:dir(rtl) .glyph {
|
|
116
|
+
scale: -1 1;
|
|
117
|
+
}
|
|
118
|
+
.toggle:dir(rtl)[aria-expanded='true'] .glyph {
|
|
119
|
+
rotate: -90deg;
|
|
120
|
+
}
|
|
121
|
+
.summary {
|
|
122
|
+
color: var(--astl-ink-muted);
|
|
123
|
+
font-weight: 400;
|
|
124
|
+
}
|
|
125
|
+
.body {
|
|
126
|
+
display: flex;
|
|
127
|
+
flex-direction: column;
|
|
128
|
+
gap: var(--astl-space-3);
|
|
129
|
+
}
|
|
90
130
|
fieldset,
|
|
91
131
|
.field {
|
|
92
132
|
display: flex;
|
|
@@ -105,7 +145,7 @@ export class AstlHelpForm extends AuthoringElement {
|
|
|
105
145
|
ol {
|
|
106
146
|
display: flex;
|
|
107
147
|
flex-direction: column;
|
|
108
|
-
gap: var(--astl-space-
|
|
148
|
+
gap: var(--astl-space-2);
|
|
109
149
|
margin: 0;
|
|
110
150
|
padding: 0;
|
|
111
151
|
list-style: none;
|
|
@@ -121,16 +161,37 @@ export class AstlHelpForm extends AuthoringElement {
|
|
|
121
161
|
li[data-over] {
|
|
122
162
|
border-color: var(--astl-accent);
|
|
123
163
|
}
|
|
164
|
+
li[data-draft] {
|
|
165
|
+
border-style: dashed;
|
|
166
|
+
}
|
|
124
167
|
.row {
|
|
125
168
|
display: flex;
|
|
126
169
|
flex-wrap: wrap;
|
|
127
170
|
align-items: center;
|
|
128
|
-
gap: var(--astl-space-2);
|
|
171
|
+
gap: var(--astl-space-1) var(--astl-space-2);
|
|
172
|
+
}
|
|
173
|
+
.tools {
|
|
174
|
+
display: flex;
|
|
175
|
+
gap: var(--astl-space-1);
|
|
176
|
+
margin-inline-start: auto;
|
|
129
177
|
}
|
|
130
178
|
.handle {
|
|
131
179
|
cursor: grab;
|
|
132
180
|
user-select: none;
|
|
133
181
|
}
|
|
182
|
+
.icon {
|
|
183
|
+
justify-content: center;
|
|
184
|
+
padding: 0;
|
|
185
|
+
}
|
|
186
|
+
.glyph {
|
|
187
|
+
inline-size: 1.25rem;
|
|
188
|
+
block-size: 1.25rem;
|
|
189
|
+
fill: none;
|
|
190
|
+
stroke: currentColor;
|
|
191
|
+
stroke-width: 1.8;
|
|
192
|
+
stroke-linecap: round;
|
|
193
|
+
stroke-linejoin: round;
|
|
194
|
+
}
|
|
134
195
|
.cost {
|
|
135
196
|
display: flex;
|
|
136
197
|
align-items: center;
|
|
@@ -161,27 +222,67 @@ export class AstlHelpForm extends AuthoringElement {
|
|
|
161
222
|
#points = null;
|
|
162
223
|
#counting = null;
|
|
163
224
|
#dragged = null;
|
|
225
|
+
/** Whether the section is open: closed for each element until it is opened. */
|
|
226
|
+
#open = false;
|
|
227
|
+
/** A hint added and not yet written, with the cost picked for it: it goes into the source with its first text. */
|
|
228
|
+
#draft = null;
|
|
229
|
+
/** The field to focus once the form shows it. */
|
|
230
|
+
#focus = null;
|
|
164
231
|
constructor() {
|
|
165
232
|
super();
|
|
166
233
|
this.element = null;
|
|
167
234
|
this.inline = false;
|
|
168
235
|
}
|
|
236
|
+
connectedCallback() {
|
|
237
|
+
super.connectedCallback();
|
|
238
|
+
forms.add(this);
|
|
239
|
+
}
|
|
240
|
+
disconnectedCallback() {
|
|
241
|
+
super.disconnectedCallback();
|
|
242
|
+
forms.delete(this);
|
|
243
|
+
}
|
|
169
244
|
willUpdate(changed) {
|
|
170
245
|
super.willUpdate(changed);
|
|
171
246
|
if (changed.has('authoring'))
|
|
172
247
|
this.authoring?.addMessages(helpMessages);
|
|
173
|
-
if (changed.has('element'))
|
|
248
|
+
if (changed.has('element')) {
|
|
174
249
|
this.#drafts.clear();
|
|
250
|
+
this.#open = false;
|
|
251
|
+
this.#draft = null;
|
|
252
|
+
}
|
|
253
|
+
this.#take();
|
|
175
254
|
}
|
|
176
255
|
updated() {
|
|
177
|
-
if (
|
|
256
|
+
if (this.#focus === null)
|
|
178
257
|
return;
|
|
179
|
-
const field = this.renderRoot.querySelector(`[data-help="${
|
|
258
|
+
const field = this.renderRoot.querySelector(`[data-help="${this.#focus}"]`);
|
|
180
259
|
if (field === null)
|
|
181
260
|
return;
|
|
182
|
-
|
|
261
|
+
this.#focus = null;
|
|
183
262
|
field.focus();
|
|
184
263
|
}
|
|
264
|
+
/** Takes a request to open this form: the section opens at its place, a new hint as a draft. */
|
|
265
|
+
#take() {
|
|
266
|
+
if (pending === null || pending.adapter !== this.adapter || pending.element !== this.element)
|
|
267
|
+
return;
|
|
268
|
+
const { place } = pending;
|
|
269
|
+
const current = this.#help();
|
|
270
|
+
if (current === null)
|
|
271
|
+
return;
|
|
272
|
+
pending = null;
|
|
273
|
+
const { help } = current;
|
|
274
|
+
this.#open = true;
|
|
275
|
+
if (place === 'hint-new')
|
|
276
|
+
this.#draft ??= { cost: null };
|
|
277
|
+
if (place === 'hints')
|
|
278
|
+
this.#focus = help.hints.length > 0 ? 'hint-0' : 'add-hint';
|
|
279
|
+
else if (place === 'hint-new')
|
|
280
|
+
this.#focus = `hint-${help.hints.length}`;
|
|
281
|
+
else if (place === 'feedback')
|
|
282
|
+
this.#focus = `feedback-${FEEDBACK_VARIANTS.find((w) => help.feedback[w] !== undefined) ?? 'correct'}`;
|
|
283
|
+
else
|
|
284
|
+
this.#focus = place;
|
|
285
|
+
}
|
|
185
286
|
#help() {
|
|
186
287
|
const html = this.element === null ? null : (this.adapter?.getElement(this.element) ?? null);
|
|
187
288
|
return html === null ? null : { html, help: readHelp(html) };
|
|
@@ -228,6 +329,15 @@ export class AstlHelpForm extends AuthoringElement {
|
|
|
228
329
|
};
|
|
229
330
|
});
|
|
230
331
|
}
|
|
332
|
+
/** What the element has, as the closed section says it: "2 hints · explanation · feedback", or "none". */
|
|
333
|
+
#summary(help) {
|
|
334
|
+
const parts = [
|
|
335
|
+
...(help.hints.length > 0 ? [this.t('surface.helpHints', { n: help.hints.length })] : []),
|
|
336
|
+
...(help.explanation !== null ? [this.t('help.summaryExplanation')] : []),
|
|
337
|
+
...(Object.keys(help.feedback).length > 0 ? [this.t('help.summaryFeedback')] : []),
|
|
338
|
+
];
|
|
339
|
+
return parts.length === 0 ? this.t('help.summaryNone') : parts.join(' · ');
|
|
340
|
+
}
|
|
231
341
|
#write(change) {
|
|
232
342
|
const current = this.#help();
|
|
233
343
|
if (current === null || this.element === null || this.adapter === null)
|
|
@@ -236,6 +346,11 @@ export class AstlHelpForm extends AuthoringElement {
|
|
|
236
346
|
if (next !== current.html)
|
|
237
347
|
this.adapter.replaceElement(this.element, next);
|
|
238
348
|
}
|
|
349
|
+
/** Focuses a field once the form shows it again. */
|
|
350
|
+
#refocus(field) {
|
|
351
|
+
this.#focus = field;
|
|
352
|
+
this.requestUpdate();
|
|
353
|
+
}
|
|
239
354
|
/** A text field's value: as typed while it is being edited, else what the source says. */
|
|
240
355
|
#text(field, html) {
|
|
241
356
|
return this.#drafts.get(field) ?? helpText(html);
|
|
@@ -267,32 +382,63 @@ export class AstlHelpForm extends AuthoringElement {
|
|
|
267
382
|
});
|
|
268
383
|
this.#drafts.clear();
|
|
269
384
|
}
|
|
385
|
+
/** "Add a hint": a draft row (one at a time), focused. */
|
|
386
|
+
#addHint(help) {
|
|
387
|
+
this.#draft ??= { cost: null };
|
|
388
|
+
this.#refocus(`hint-${help.hints.length}`);
|
|
389
|
+
}
|
|
390
|
+
/** The draft goes without a trace: left empty, or removed. */
|
|
391
|
+
#dropDraft(field) {
|
|
392
|
+
this.#draft = null;
|
|
393
|
+
this.#drafts.delete(field);
|
|
394
|
+
this.requestUpdate();
|
|
395
|
+
}
|
|
396
|
+
/** A small button with an icon, named and with a tooltip by its text. */
|
|
397
|
+
#iconButton(name, label, off, run) {
|
|
398
|
+
return html `<button type="button" class=${name === 'remove' ? 'icon delete' : 'icon'}
|
|
399
|
+
part=${name === 'remove' ? 'help-remove' : 'help-move'} aria-label=${label} title=${label}
|
|
400
|
+
aria-disabled=${off ? 'true' : nothing}
|
|
401
|
+
@click=${() => {
|
|
402
|
+
if (!off)
|
|
403
|
+
run();
|
|
404
|
+
}}>${icon(name)}</button>`;
|
|
405
|
+
}
|
|
270
406
|
#hint(help, index, points) {
|
|
271
|
-
const
|
|
407
|
+
const draft = index === help.hints.length;
|
|
408
|
+
const hint = draft
|
|
409
|
+
? { html: '', cost: this.#draft?.cost ?? null }
|
|
410
|
+
: help.hints[index];
|
|
272
411
|
const n = index + 1;
|
|
273
412
|
const field = `hint-${index}`;
|
|
274
413
|
const last = index === help.hints.length - 1;
|
|
275
414
|
const formatted = this.#formatted(field, hint.html);
|
|
276
415
|
const over = (event, on) => {
|
|
277
|
-
if (this.#dragged === null)
|
|
416
|
+
if (this.#dragged === null || draft)
|
|
278
417
|
return;
|
|
279
418
|
event.preventDefault();
|
|
280
419
|
event.currentTarget.toggleAttribute('data-over', on);
|
|
281
420
|
};
|
|
282
421
|
return html `<li
|
|
422
|
+
?data-draft=${draft}
|
|
283
423
|
@dragover=${(e) => over(e, true)}
|
|
284
424
|
@dragleave=${(e) => over(e, false)}
|
|
285
425
|
@drop=${(e) => {
|
|
286
426
|
over(e, false);
|
|
287
|
-
if (this.#dragged !== null)
|
|
427
|
+
if (this.#dragged !== null && !draft)
|
|
288
428
|
this.#move(this.#dragged, index);
|
|
289
429
|
this.#dragged = null;
|
|
290
430
|
}}
|
|
431
|
+
@focusout=${(e) => {
|
|
432
|
+
// A draft left empty goes: the focus is outside its row, and it has no text yet.
|
|
433
|
+
const row = e.currentTarget;
|
|
434
|
+
if (draft && this.#draft !== null && !row.contains(e.relatedTarget))
|
|
435
|
+
this.#dropDraft(field);
|
|
436
|
+
}}
|
|
291
437
|
>
|
|
292
438
|
<div class="row">
|
|
293
439
|
<span
|
|
294
440
|
class="handle"
|
|
295
|
-
draggable
|
|
441
|
+
draggable=${draft ? 'false' : 'true'}
|
|
296
442
|
aria-hidden="true"
|
|
297
443
|
title=${this.t('help.drag')}
|
|
298
444
|
@dragstart=${(e) => {
|
|
@@ -305,6 +451,22 @@ export class AstlHelpForm extends AuthoringElement {
|
|
|
305
451
|
>⠿</span
|
|
306
452
|
>
|
|
307
453
|
<label for=${field}>${this.t('help.hintN', { n })}</label>
|
|
454
|
+
<span class="tools">
|
|
455
|
+
${draft
|
|
456
|
+
? nothing
|
|
457
|
+
: html `${this.#iconButton('up', this.t('help.upN', { n }), index === 0, () => this.#move(index, index - 1))}
|
|
458
|
+
${this.#iconButton('down', this.t('help.downN', { n }), last, () => this.#move(index, index + 1))}`}
|
|
459
|
+
${this.#iconButton('remove', this.t('help.removeN', { n }), false, () => {
|
|
460
|
+
if (draft) {
|
|
461
|
+
this.#dropDraft(field);
|
|
462
|
+
this.#refocus('add-hint');
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
this.#drafts.clear();
|
|
466
|
+
this.#write((h) => ({ ...h, hints: h.hints.filter((_, i) => i !== index) }));
|
|
467
|
+
this.#refocus(help.hints.length > 1 ? `hint-${Math.max(0, index - 1)}` : 'add-hint');
|
|
468
|
+
})}
|
|
469
|
+
</span>
|
|
308
470
|
</div>
|
|
309
471
|
<textarea
|
|
310
472
|
id=${field}
|
|
@@ -314,56 +476,64 @@ export class AstlHelpForm extends AuthoringElement {
|
|
|
314
476
|
.value=${live(this.#text(field, hint.html))}
|
|
315
477
|
@input=${(e) => {
|
|
316
478
|
const text = this.#typed(field, e);
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
479
|
+
if (!draft) {
|
|
480
|
+
this.#write((h) => ({
|
|
481
|
+
...h,
|
|
482
|
+
hints: h.hints.map((x, i) => (i === index ? { ...x, html: text } : x)),
|
|
483
|
+
}));
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
// The draft's first text writes it, with the cost picked for it.
|
|
487
|
+
if (inputValue(e).trim() === '')
|
|
488
|
+
return;
|
|
489
|
+
const cost = this.#draft?.cost ?? null;
|
|
490
|
+
this.#draft = null;
|
|
491
|
+
this.#write((h) => ({ ...h, hints: [...h.hints, { html: text, cost }] }));
|
|
321
492
|
}}
|
|
322
493
|
@change=${() => this.#done(field)}
|
|
323
494
|
></textarea>
|
|
324
495
|
${formatted ?? nothing}
|
|
325
|
-
<
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
@change=${(e) => {
|
|
496
|
+
<label class="cost">
|
|
497
|
+
${this.t('help.cost')}
|
|
498
|
+
<select
|
|
499
|
+
aria-label=${this.t('help.costN', { n })}
|
|
500
|
+
data-help=${`cost-${index}`}
|
|
501
|
+
@change=${(e) => {
|
|
332
502
|
const value = inputValue(e);
|
|
333
503
|
const cost = value === '0' ? null : value;
|
|
504
|
+
if (draft) {
|
|
505
|
+
this.#draft = { cost };
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
334
508
|
this.#write((h) => ({
|
|
335
509
|
...h,
|
|
336
510
|
hints: h.hints.map((x, i) => (i === index ? { ...x, cost } : x)),
|
|
337
511
|
}));
|
|
338
512
|
}}
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
<button type="button" aria-label=${this.t('help.upN', { n })} aria-disabled=${String(index === 0)}
|
|
344
|
-
@click=${() => this.#move(index, index - 1)}>${this.t('help.up')}</button>
|
|
345
|
-
<button type="button" aria-label=${this.t('help.downN', { n })} aria-disabled=${String(last)}
|
|
346
|
-
@click=${() => this.#move(index, index + 1)}>${this.t('help.down')}</button>
|
|
347
|
-
<button type="button" class="delete" aria-label=${this.t('help.removeN', { n })}
|
|
348
|
-
@click=${() => {
|
|
349
|
-
this.#drafts.clear();
|
|
350
|
-
this.#write((h) => ({ ...h, hints: h.hints.filter((_, i) => i !== index) }));
|
|
351
|
-
pending = {
|
|
352
|
-
element: this.element ?? '',
|
|
353
|
-
field: help.hints.length > 1 ? `hint-${Math.max(0, index - 1)}` : 'add-hint',
|
|
354
|
-
};
|
|
355
|
-
}}>${this.t('inspector.remove')}</button>
|
|
356
|
-
</div>
|
|
513
|
+
>
|
|
514
|
+
${this.#costs(hint.cost, points).map(({ value, label }) => html `<option value=${value} ?selected=${value === costOf(hint.cost)}>${label}</option>`)}
|
|
515
|
+
</select>
|
|
516
|
+
</label>
|
|
357
517
|
</li>`;
|
|
358
518
|
}
|
|
359
519
|
/**
|
|
360
|
-
* A text field of the help: the explanation or a feedback text.
|
|
361
|
-
*
|
|
520
|
+
* A text field of the help: the explanation or a feedback text. An empty field is none; while the element has it,
|
|
521
|
+
* "Remove" beside its label takes it away.
|
|
362
522
|
*/
|
|
363
523
|
#area(field, label, remove, value, set) {
|
|
364
524
|
const formatted = this.#formatted(field, value ?? '');
|
|
365
525
|
return html `<div class="field">
|
|
366
|
-
<
|
|
526
|
+
<div class="row">
|
|
527
|
+
<label for=${field}>${label}</label>
|
|
528
|
+
${value === null || value === undefined
|
|
529
|
+
? nothing
|
|
530
|
+
: html `<span class="tools">${this.#iconButton('remove', remove, false, () => {
|
|
531
|
+
this.#drafts.delete(field);
|
|
532
|
+
// The field stays, empty: the focus goes back to it.
|
|
533
|
+
set(null);
|
|
534
|
+
this.#refocus(field);
|
|
535
|
+
})}</span>`}
|
|
536
|
+
</div>
|
|
367
537
|
<textarea
|
|
368
538
|
id=${field}
|
|
369
539
|
data-help=${field}
|
|
@@ -377,39 +547,22 @@ export class AstlHelpForm extends AuthoringElement {
|
|
|
377
547
|
@change=${() => this.#done(field)}
|
|
378
548
|
></textarea>
|
|
379
549
|
${formatted ?? nothing}
|
|
380
|
-
${value === null || value === undefined
|
|
381
|
-
? nothing
|
|
382
|
-
: html `<div class="row">
|
|
383
|
-
<button type="button" class="delete" aria-label=${remove}
|
|
384
|
-
@click=${() => {
|
|
385
|
-
this.#drafts.delete(field);
|
|
386
|
-
// The field stays, empty: the focus goes back to it.
|
|
387
|
-
pending = { element: this.element ?? '', field };
|
|
388
|
-
set(null);
|
|
389
|
-
}}>${this.t('inspector.remove')}</button>
|
|
390
|
-
</div>`}
|
|
391
550
|
</div>`;
|
|
392
551
|
}
|
|
393
|
-
|
|
394
|
-
const
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
const { help } = current;
|
|
398
|
-
const { lang, dir } = this.ui;
|
|
399
|
-
return html `<section class="kit" part="help" lang=${lang} dir=${dir} aria-labelledby="help-title">
|
|
400
|
-
<h3 id="help-title">${this.t('help.title')}</h3>
|
|
552
|
+
#body(source, help) {
|
|
553
|
+
const rows = help.hints.length + (this.#draft === null ? 0 : 1);
|
|
554
|
+
const points = this.#pointsOf(source);
|
|
555
|
+
return html `<div class="body" id="help-body" part="help-body">
|
|
401
556
|
<fieldset aria-describedby="hints-note">
|
|
402
557
|
<legend>${this.t('help.hints')}</legend>
|
|
403
558
|
<p class="note" id="hints-note">${this.t('help.hintsNote')}</p>
|
|
404
|
-
${
|
|
559
|
+
${rows === 0
|
|
405
560
|
? nothing
|
|
406
|
-
: html `<ol>${
|
|
561
|
+
: html `<ol>${Array.from({ length: rows }, (_, i) => this.#hint(help, i, points))}</ol>`}
|
|
407
562
|
<div class="row">
|
|
408
|
-
<button type="button" data-help="add-hint"
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
this.#write((h) => ({ ...h, hints: [...h.hints, { html: '', cost: null }] }));
|
|
412
|
-
}}>${this.t('help.addHint')}</button>
|
|
563
|
+
<button type="button" data-help="add-hint" part="help-add" @click=${() => this.#addHint(help)}>
|
|
564
|
+
${this.t('help.addHint')}
|
|
565
|
+
</button>
|
|
413
566
|
</div>
|
|
414
567
|
</fieldset>
|
|
415
568
|
${this.#area('explanation', this.t('insert.explanation'), this.t('help.removeExplanation'), help.explanation, (text) => this.#write((h) => ({ ...h, explanation: text })))}
|
|
@@ -426,6 +579,30 @@ export class AstlHelpForm extends AuthoringElement {
|
|
|
426
579
|
return { ...h, feedback };
|
|
427
580
|
})))}
|
|
428
581
|
</fieldset>
|
|
582
|
+
</div>`;
|
|
583
|
+
}
|
|
584
|
+
render() {
|
|
585
|
+
const current = this.#help();
|
|
586
|
+
if (current === null || this.authoring === null)
|
|
587
|
+
return nothing;
|
|
588
|
+
const { help } = current;
|
|
589
|
+
const { lang, dir } = this.ui;
|
|
590
|
+
const open = this.#open;
|
|
591
|
+
return html `<section class="kit" part="help" lang=${lang} dir=${dir} aria-labelledby="help-title">
|
|
592
|
+
<h3>
|
|
593
|
+
<button type="button" class="toggle" part="help-toggle" aria-expanded=${String(open)}
|
|
594
|
+
aria-controls=${open ? 'help-body' : nothing}
|
|
595
|
+
@click=${() => {
|
|
596
|
+
this.#open = !open;
|
|
597
|
+
if (open)
|
|
598
|
+
this.#draft = null;
|
|
599
|
+
this.requestUpdate();
|
|
600
|
+
}}>
|
|
601
|
+
${icon('chevron')}<span id="help-title">${this.t('help.title')}</span>
|
|
602
|
+
${open ? nothing : html `<span class="summary" part="help-summary">${this.#summary(help)}</span>`}
|
|
603
|
+
</button>
|
|
604
|
+
</h3>
|
|
605
|
+
${open ? this.#body(current.html, help) : nothing}
|
|
429
606
|
</section>`;
|
|
430
607
|
}
|
|
431
608
|
}
|