@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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { CHECK_TAG, type EditorBlockPlace, type EditorStyleTargetKind } from '@astl/core';
|
|
2
2
|
import {
|
|
3
3
|
type CSSResultGroup,
|
|
4
4
|
css,
|
|
@@ -14,6 +14,7 @@ import { refusalOf } from '../authoring.js';
|
|
|
14
14
|
import type { InspectorChange } from '../edit.js';
|
|
15
15
|
import type {
|
|
16
16
|
CheckboxFieldModel,
|
|
17
|
+
CheckTargetsFieldModel,
|
|
17
18
|
ChildChoiceFieldModel,
|
|
18
19
|
ChildFlagFieldModel,
|
|
19
20
|
ChildTableFieldModel,
|
|
@@ -30,7 +31,15 @@ import { GLYPHS, TYPE_GLYPHS } from './insert-menu.js';
|
|
|
30
31
|
import { SEVERITY_ICONS, sortIssues } from './issue-list.js';
|
|
31
32
|
import type { FieldChange } from './picture-field.js';
|
|
32
33
|
import { type HelpPart, loadHelpForm, loadStyleElements, STYLE_OPEN, type StyleOpen } from './style-load.js';
|
|
33
|
-
import {
|
|
34
|
+
import {
|
|
35
|
+
addIcon,
|
|
36
|
+
compactButtons,
|
|
37
|
+
inheritTokens,
|
|
38
|
+
kitStyles,
|
|
39
|
+
NarrowCard,
|
|
40
|
+
narrowCard,
|
|
41
|
+
narrowMark,
|
|
42
|
+
} from './styles.js';
|
|
34
43
|
|
|
35
44
|
/** A control to focus after the next render (text list rows come and go). */
|
|
36
45
|
interface PendingFocus {
|
|
@@ -71,6 +80,7 @@ const checkedOf = (event: Event) => (event.target as HTMLInputElement).checked;
|
|
|
71
80
|
export class AstlInspector extends AuthoringElement {
|
|
72
81
|
static override styles: CSSResultGroup = [
|
|
73
82
|
kitStyles,
|
|
83
|
+
narrowCard,
|
|
74
84
|
compactButtons,
|
|
75
85
|
// The picture fields redeclare the tokens on their :host: they take this element's (theme, host overrides).
|
|
76
86
|
inheritTokens('astl-picture-field, astl-style-form, astl-help-form'),
|
|
@@ -175,6 +185,20 @@ export class AstlInspector extends AuthoringElement {
|
|
|
175
185
|
font-size: var(--astl-size-small);
|
|
176
186
|
}
|
|
177
187
|
`,
|
|
188
|
+
// A question another Check element has: its name after the question's, muted. The line under a question's head that
|
|
189
|
+
// names the Check element checking it, a button that selects it.
|
|
190
|
+
css`
|
|
191
|
+
.check .other {
|
|
192
|
+
color: var(--astl-ink-muted);
|
|
193
|
+
font-size: var(--astl-size-small);
|
|
194
|
+
}
|
|
195
|
+
.checked-by {
|
|
196
|
+
align-self: flex-start;
|
|
197
|
+
}
|
|
198
|
+
.checked-by .glyph {
|
|
199
|
+
flex: none;
|
|
200
|
+
}
|
|
201
|
+
`,
|
|
178
202
|
// One row of a child-table field: its text, then its controls side by side while they fit, and Remove.
|
|
179
203
|
css`
|
|
180
204
|
.row {
|
|
@@ -301,6 +325,7 @@ export class AstlInspector extends AuthoringElement {
|
|
|
301
325
|
];
|
|
302
326
|
|
|
303
327
|
/** Source id of the element shown: edits go to it. */
|
|
328
|
+
#narrow = new NarrowCard(this);
|
|
304
329
|
#shown: string | null = null;
|
|
305
330
|
/** The document's settings are shown: edits go to the start tag of `<astl-doc>`. */
|
|
306
331
|
#document = false;
|
|
@@ -744,6 +769,46 @@ export class AstlInspector extends AuthoringElement {
|
|
|
744
769
|
</fieldset>`;
|
|
745
770
|
}
|
|
746
771
|
|
|
772
|
+
/**
|
|
773
|
+
* A checkbox per graded question of the check's page, named as authors know it ("Gap 2"); one another Check element
|
|
774
|
+
* has is unavailable and says which. A change writes `for` with the ticked ones in the page's order, empty for none.
|
|
775
|
+
*/
|
|
776
|
+
#checkTargets(field: CheckTargetsFieldModel, i: number): TemplateResult {
|
|
777
|
+
const write = (id: string, on: boolean) => {
|
|
778
|
+
const ids = field.targets.filter((target) => (target.id === id ? on : target.checked));
|
|
779
|
+
this.#apply({ kind: 'attribute', name: field.name, value: ids.map((target) => target.id).join(' ') });
|
|
780
|
+
};
|
|
781
|
+
return html`<fieldset data-name=${field.name} part="field check-targets" aria-describedby=${ifDefined(this.#describedBy(field, i))}>
|
|
782
|
+
<legend part="label">${field.label}</legend>
|
|
783
|
+
${this.#help(field, i)}
|
|
784
|
+
${field.targets.length === 0 ? html`<p class="note">${this.t('check.noQuestions')}</p>` : nothing}
|
|
785
|
+
${field.targets.map(
|
|
786
|
+
(target) => html`<label class="check">
|
|
787
|
+
<input
|
|
788
|
+
type="checkbox"
|
|
789
|
+
data-id=${target.id}
|
|
790
|
+
.checked=${live(target.checked)}
|
|
791
|
+
?disabled=${target.other !== null}
|
|
792
|
+
@change=${(event: Event) => write(target.id, checkedOf(event))}
|
|
793
|
+
/>
|
|
794
|
+
<span dir="auto">${target.label}</span>
|
|
795
|
+
${target.other === null ? nothing : html`<span class="other">${this.t('check.checkedBy', { check: target.other })}</span>`}
|
|
796
|
+
</label>`,
|
|
797
|
+
)}
|
|
798
|
+
</fieldset>`;
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
/** Under a question's head, the Check element that checks it ("Checked by Check button 1"): a press selects it. */
|
|
802
|
+
#checkedBy(model: InspectorModel): TemplateResult | typeof nothing {
|
|
803
|
+
const by = model.checkedBy ?? null;
|
|
804
|
+
if (by === null || this.adapter === null) return nothing;
|
|
805
|
+
return html`<button type="button" class="checked-by" part="checked-by" data-check=${by.id}
|
|
806
|
+
@click=${() => this.adapter?.select(by.id)}>
|
|
807
|
+
<svg class="icon glyph" viewBox="0 0 20 20" aria-hidden="true" focusable="false">${TYPE_GLYPHS.get('check')}</svg>
|
|
808
|
+
<span>${this.t('check.checkedBy', { check: by.name })}</span>
|
|
809
|
+
</button>`;
|
|
810
|
+
}
|
|
811
|
+
|
|
747
812
|
#field(field: InspectorFieldModel, i: number): TemplateResult {
|
|
748
813
|
switch (field.kind) {
|
|
749
814
|
case 'picture-regions':
|
|
@@ -764,6 +829,8 @@ export class AstlInspector extends AuthoringElement {
|
|
|
764
829
|
return this.#childChoices(field, i);
|
|
765
830
|
case 'child-table':
|
|
766
831
|
return this.#childTable(field, i);
|
|
832
|
+
case 'check-targets':
|
|
833
|
+
return this.#checkTargets(field, i);
|
|
767
834
|
case 'attribute':
|
|
768
835
|
switch (field.control) {
|
|
769
836
|
case 'text':
|
|
@@ -787,7 +854,8 @@ export class AstlInspector extends AuthoringElement {
|
|
|
787
854
|
const { authoring, adapter } = this;
|
|
788
855
|
const place: EditorBlockPlace | null = adapter?.getCursor?.() ?? null;
|
|
789
856
|
if (authoring === null || adapter === null || place === null) return nothing;
|
|
790
|
-
|
|
857
|
+
// A block component, or a Check element: a block of its own.
|
|
858
|
+
if (tag !== CHECK_TAG && authoring.descriptor(tag)?.manifest.display !== 'block') return nothing;
|
|
791
859
|
const page = authoring.outline(adapter.getSource()).pages.find((p) => p.id === place.page);
|
|
792
860
|
const button = (name: keyof typeof ACTION_ICONS, off: boolean, run: () => void) =>
|
|
793
861
|
html`<button type="button" class=${name} data-action=${name} aria-label=${this.t(`inspector.${name}`)}
|
|
@@ -951,7 +1019,7 @@ export class AstlInspector extends AuthoringElement {
|
|
|
951
1019
|
// A graded element's help for students heads the card, before its fields: a form of its own, loaded on first use.
|
|
952
1020
|
const manifest = authoring.descriptor(model.tag)?.manifest;
|
|
953
1021
|
if (manifest?.graded === true) void loadHelpForm().catch(() => {});
|
|
954
|
-
body = html`${this.#head(model)}${this.#issues(model)}
|
|
1022
|
+
body = html`${this.#head(model)}${this.#issues(model)}${this.#checkedBy(model)}
|
|
955
1023
|
${
|
|
956
1024
|
manifest?.graded === true
|
|
957
1025
|
? html`<astl-help-form .authoring=${authoring} .adapter=${adapter} .element=${this.#shown}
|
|
@@ -960,6 +1028,13 @@ export class AstlInspector extends AuthoringElement {
|
|
|
960
1028
|
}
|
|
961
1029
|
<div class="fields" data-tag=${model.tag}>${model.fields.map((f, i) => this.#field(f, i))}</div>`;
|
|
962
1030
|
}
|
|
963
|
-
return html
|
|
1031
|
+
return html`${narrowMark}<section
|
|
1032
|
+
class="kit"
|
|
1033
|
+
part="root"
|
|
1034
|
+
lang=${lang}
|
|
1035
|
+
dir=${dir}
|
|
1036
|
+
aria-labelledby="title"
|
|
1037
|
+
data-narrow=${this.#narrow.step || nothing}
|
|
1038
|
+
>${body}${this.#styleSection()}</section>`;
|
|
964
1039
|
}
|
|
965
1040
|
}
|
package/src/elements/issues.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { Issue } from '@astl/core';
|
|
|
2
2
|
import { type CSSResultGroup, html, nothing, type PropertyValues, type TemplateResult } from 'lit';
|
|
3
3
|
import { AuthoringElement } from './base.js';
|
|
4
4
|
import { issueStyles, renderIssues } from './issue-list.js';
|
|
5
|
-
import { kitStyles } from './styles.js';
|
|
5
|
+
import { kitStyles, NarrowCard, narrowCard, narrowMark } from './styles.js';
|
|
6
6
|
|
|
7
7
|
/** Validation waits this long after the last change, so typing is not interrupted. */
|
|
8
8
|
export const VALIDATION_DELAY_MS = 300;
|
|
@@ -12,8 +12,9 @@ export const VALIDATION_DELAY_MS = 300;
|
|
|
12
12
|
* editor's cursor to its element (`adapter.select`).
|
|
13
13
|
*/
|
|
14
14
|
export class AstlIssues extends AuthoringElement {
|
|
15
|
-
static override styles: CSSResultGroup = [kitStyles, issueStyles];
|
|
15
|
+
static override styles: CSSResultGroup = [kitStyles, narrowCard, issueStyles];
|
|
16
16
|
|
|
17
|
+
#narrow = new NarrowCard(this);
|
|
17
18
|
#issues: readonly Issue[] | null = null;
|
|
18
19
|
/** The source the issues are about. */
|
|
19
20
|
#source = '';
|
|
@@ -80,7 +81,14 @@ export class AstlIssues extends AuthoringElement {
|
|
|
80
81
|
warnings: this.t('issues.warnings', { count: issues.length - errors }),
|
|
81
82
|
});
|
|
82
83
|
}
|
|
83
|
-
return html
|
|
84
|
+
return html`${narrowMark}<section
|
|
85
|
+
class="kit"
|
|
86
|
+
part="root"
|
|
87
|
+
lang=${lang}
|
|
88
|
+
dir=${dir}
|
|
89
|
+
aria-labelledby="title"
|
|
90
|
+
data-narrow=${this.#narrow.step || nothing}
|
|
91
|
+
>
|
|
84
92
|
<h2 class="title" id="title" part="title">${this.t('issues.title')}</h2>
|
|
85
93
|
<p class="note summary" role="status" ?hidden=${issues === null}>${summary}</p>
|
|
86
94
|
${issues === null ? nothing : renderIssues(issues, authoring, adapter, this.#source)}
|
|
@@ -2,7 +2,7 @@ import { type CSSResultGroup, css, html, nothing, type TemplateResult } from 'li
|
|
|
2
2
|
import { live } from 'lit/directives/live.js';
|
|
3
3
|
import { type PictureFields, pictureSize, refusalOf, type UploadedAsset } from '../authoring.js';
|
|
4
4
|
import { AuthoringElement } from './base.js';
|
|
5
|
-
import { kitStyles } from './styles.js';
|
|
5
|
+
import { fitViewport, kitStyles } from './styles.js';
|
|
6
6
|
|
|
7
7
|
/** What `ask` opens the dialog with. */
|
|
8
8
|
export interface PictureRequest {
|
|
@@ -40,8 +40,8 @@ export class AstlPictureDialog extends AuthoringElement {
|
|
|
40
40
|
css`
|
|
41
41
|
dialog {
|
|
42
42
|
box-sizing: border-box;
|
|
43
|
-
inline-size: min(32rem, calc(100vw - 2 * var(--astl-space-4)));
|
|
44
|
-
max-block-size: calc(100dvh - 2 * var(--astl-space-4));
|
|
43
|
+
inline-size: min(32rem, var(--room-inline, calc(100vw - 2 * var(--astl-space-4))));
|
|
44
|
+
max-block-size: var(--room-block, calc(100dvh - 2 * var(--astl-space-4)));
|
|
45
45
|
padding: var(--astl-space-4);
|
|
46
46
|
border: var(--astl-outline-width) solid var(--astl-outline);
|
|
47
47
|
border-radius: var(--astl-radius-l);
|
|
@@ -159,16 +159,29 @@ export class AstlPictureDialog extends AuthoringElement {
|
|
|
159
159
|
this.#resolve = resolve;
|
|
160
160
|
});
|
|
161
161
|
this.#dialog()?.showModal();
|
|
162
|
+
this.#fit();
|
|
162
163
|
if (request.file !== undefined) void this.#upload(request.file);
|
|
163
164
|
return result;
|
|
164
165
|
}
|
|
165
166
|
|
|
167
|
+
override connectedCallback(): void {
|
|
168
|
+
super.connectedCallback();
|
|
169
|
+
window.addEventListener('resize', this.#fit);
|
|
170
|
+
}
|
|
171
|
+
|
|
166
172
|
override disconnectedCallback(): void {
|
|
167
173
|
super.disconnectedCallback();
|
|
174
|
+
window.removeEventListener('resize', this.#fit);
|
|
168
175
|
// Out of the document the dialog is out of the top layer, and a pick that ends later could not open it again.
|
|
169
176
|
this.#finish(null);
|
|
170
177
|
}
|
|
171
178
|
|
|
179
|
+
/** Keeps the open dialog inside the viewport (`fitViewport`): as it opens, and when the viewport changes. */
|
|
180
|
+
#fit = (): void => {
|
|
181
|
+
const dialog = this.#dialog();
|
|
182
|
+
if (dialog?.open === true) fitViewport(dialog);
|
|
183
|
+
};
|
|
184
|
+
|
|
172
185
|
#dialog(): HTMLDialogElement | null {
|
|
173
186
|
return this.renderRoot.querySelector('dialog');
|
|
174
187
|
}
|
|
@@ -282,6 +295,7 @@ export class AstlPictureDialog extends AuthoringElement {
|
|
|
282
295
|
}
|
|
283
296
|
this.#picking = false;
|
|
284
297
|
shown.showModal();
|
|
298
|
+
this.#fit();
|
|
285
299
|
const next = picked ? (this.#decorative ? 'button[type="submit"]' : '#alt') : '[data-library]';
|
|
286
300
|
this.renderRoot.querySelector<HTMLElement>(next)?.focus();
|
|
287
301
|
this.#uploadMessage = message;
|
package/src/elements/preview.ts
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
import type { Authoring } from '../authoring.js';
|
|
13
13
|
import { AuthoringElement } from './base.js';
|
|
14
14
|
import { issueStyles, renderIssues } from './issue-list.js';
|
|
15
|
-
import { inheritTokens, kitStyles } from './styles.js';
|
|
15
|
+
import { inheritTokens, kitStyles, NarrowCard, narrowCard, narrowMark } from './styles.js';
|
|
16
16
|
|
|
17
17
|
type PreviewState = 'idle' | 'loading' | 'ready' | 'invalid' | 'failed';
|
|
18
18
|
|
|
@@ -34,6 +34,7 @@ export class AstlPreview extends AuthoringElement {
|
|
|
34
34
|
kitStyles,
|
|
35
35
|
issueStyles,
|
|
36
36
|
inheritTokens('astl-player'),
|
|
37
|
+
narrowCard,
|
|
37
38
|
css`
|
|
38
39
|
.bar {
|
|
39
40
|
display: flex;
|
|
@@ -61,6 +62,7 @@ export class AstlPreview extends AuthoringElement {
|
|
|
61
62
|
#state: PreviewState = 'idle';
|
|
62
63
|
#issues: readonly Issue[] = [];
|
|
63
64
|
/** The source the issues are about. */
|
|
65
|
+
#narrow = new NarrowCard(this);
|
|
64
66
|
#source = '';
|
|
65
67
|
#stale = false;
|
|
66
68
|
#generation = 0;
|
|
@@ -167,7 +169,14 @@ export class AstlPreview extends AuthoringElement {
|
|
|
167
169
|
${renderIssues(this.#issues, authoring, adapter, this.#source)}`;
|
|
168
170
|
}
|
|
169
171
|
const theme = this.getAttribute('data-theme') ?? 'light';
|
|
170
|
-
return html
|
|
172
|
+
return html`${narrowMark}<section
|
|
173
|
+
class="kit"
|
|
174
|
+
part="root"
|
|
175
|
+
lang=${lang}
|
|
176
|
+
dir=${dir}
|
|
177
|
+
aria-labelledby="title"
|
|
178
|
+
data-narrow=${this.#narrow.step || nothing}
|
|
179
|
+
>
|
|
171
180
|
<div class="bar">
|
|
172
181
|
<h2 class="title" id="title" part="title">${this.t('preview.title')}</h2>
|
|
173
182
|
<button type="button" class="primary" part="button" ?disabled=${adapter === null} @click=${() => this.refresh()}>
|
|
@@ -35,11 +35,11 @@ interface Choice {
|
|
|
35
35
|
export const stylePopupStyles: CSSResult = css`
|
|
36
36
|
${colorStyles}
|
|
37
37
|
.colors {
|
|
38
|
-
inline-size: min(16rem,
|
|
38
|
+
inline-size: min(16rem, var(--room-inline));
|
|
39
39
|
}
|
|
40
40
|
.panel {
|
|
41
|
-
inline-size: min(26rem,
|
|
42
|
-
max-block-size: min(40rem,
|
|
41
|
+
inline-size: min(26rem, var(--room-inline));
|
|
42
|
+
max-block-size: min(40rem, var(--room-block));
|
|
43
43
|
}
|
|
44
44
|
.panel astl-style-rules::part(root) {
|
|
45
45
|
padding: 0;
|
package/src/elements/styles.ts
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import { visuallyHidden } from '@astl/player';
|
|
2
2
|
import { nativeSelectCss, tokens, tokensCss } from '@astl/tokens';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
type CSSResult,
|
|
5
|
+
type CSSResultGroup,
|
|
6
|
+
css,
|
|
7
|
+
html,
|
|
8
|
+
type ReactiveController,
|
|
9
|
+
type ReactiveControllerHost,
|
|
10
|
+
type TemplateResult,
|
|
11
|
+
unsafeCSS,
|
|
12
|
+
} from 'lit';
|
|
4
13
|
|
|
5
14
|
/**
|
|
6
15
|
* Every token as `inherit` on `selector`, for elements that redeclare the tokens on their own `:host` (the player): a
|
|
@@ -221,3 +230,104 @@ export const compactButtons: CSSResult = css`
|
|
|
221
230
|
stroke-linejoin: round;
|
|
222
231
|
}
|
|
223
232
|
`;
|
|
233
|
+
|
|
234
|
+
/** How far a floating element (a popup, a dialog) keeps from the viewport's edges, in the viewport's pixels. */
|
|
235
|
+
export const VIEWPORT_MARGIN = 8;
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Tells a floating element how much of the viewport it may take (`--room-inline`, `--room-block`: the viewport less a
|
|
239
|
+
* margin on each side), which its styles use as its largest size, so it scrolls inside rather than past an edge.
|
|
240
|
+
* Lengths go through its effective zoom (`currentCSSZoom`): a page that enlarges its text with `zoom` multiplies the
|
|
241
|
+
* element's own lengths, viewport units included, while the viewport's size is in its own pixels. Returns that zoom.
|
|
242
|
+
*/
|
|
243
|
+
export function fitViewport(element: HTMLElement): number {
|
|
244
|
+
const zoom = (element as HTMLElement & { readonly currentCSSZoom?: number }).currentCSSZoom || 1;
|
|
245
|
+
const { clientWidth, clientHeight } = document.documentElement;
|
|
246
|
+
element.style.setProperty('--room-inline', `${(clientWidth - 2 * VIEWPORT_MARGIN) / zoom}px`);
|
|
247
|
+
element.style.setProperty('--room-block', `${(clientHeight - 2 * VIEWPORT_MARGIN) / zoom}px`);
|
|
248
|
+
return zoom;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* The cards of the editor's column (problems, properties, the student view) in a narrow column, a small phone or larger
|
|
253
|
+
* text: less padding, in two steps (`data-narrow` on the card, which `NarrowCard` sets); all of them switch together
|
|
254
|
+
* in a column of one width.
|
|
255
|
+
*/
|
|
256
|
+
export const narrowCard: CSSResult = css`
|
|
257
|
+
.narrow-mark {
|
|
258
|
+
block-size: 1rem;
|
|
259
|
+
margin-block-end: -1rem;
|
|
260
|
+
}
|
|
261
|
+
.kit[data-narrow] {
|
|
262
|
+
padding: var(--astl-space-2);
|
|
263
|
+
}
|
|
264
|
+
.kit[data-narrow='2'] {
|
|
265
|
+
padding-inline: var(--astl-space-1);
|
|
266
|
+
}
|
|
267
|
+
`;
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* What a `NarrowCard` measures, first in the card's shadow root: as wide as the card and 1rem tall, so a new root font
|
|
271
|
+
* size is a resize too, and it takes no room.
|
|
272
|
+
*/
|
|
273
|
+
export const narrowMark: TemplateResult = html`<div class="narrow-mark"></div>`;
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* How narrow a card of the editor's column is (`step`, for `data-narrow` on its `.kit`), from its width in the root font
|
|
277
|
+
* size: 1 at 20rem and under, 2 at 13rem and under. It measures `narrowMark` and puts no size containment on the card,
|
|
278
|
+
* so in any layout the card takes the width it had: at once when rendered or connected, before it is painted, then on
|
|
279
|
+
* every resize, a frame later (outside the observer's delivery, which a change of size would loop), or at once when the
|
|
280
|
+
* card was hidden, as the mark does not follow the padding.
|
|
281
|
+
*/
|
|
282
|
+
export class NarrowCard implements ReactiveController {
|
|
283
|
+
step: 0 | 1 | 2 = 0;
|
|
284
|
+
readonly #host: ReactiveControllerHost & HTMLElement;
|
|
285
|
+
#observer: ResizeObserver | null = null;
|
|
286
|
+
/** The mark's width when last seen: 0 while hidden. */
|
|
287
|
+
#seen = 0;
|
|
288
|
+
#frame = 0;
|
|
289
|
+
|
|
290
|
+
constructor(host: ReactiveControllerHost & HTMLElement) {
|
|
291
|
+
this.#host = host;
|
|
292
|
+
host.addController(this);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
hostConnected(): void {
|
|
296
|
+
this.#watch();
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
hostUpdated(): void {
|
|
300
|
+
if (this.#observer === null) this.#watch();
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
hostDisconnected(): void {
|
|
304
|
+
this.#observer?.disconnect();
|
|
305
|
+
cancelAnimationFrame(this.#frame);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
#watch(): void {
|
|
309
|
+
const mark = this.#host.shadowRoot?.querySelector('.narrow-mark');
|
|
310
|
+
if (mark === null || mark === undefined || typeof ResizeObserver === 'undefined') return;
|
|
311
|
+
this.#seen = mark.clientWidth;
|
|
312
|
+
this.#set(this.#seen);
|
|
313
|
+
this.#observer ??= new ResizeObserver(([entry]) => {
|
|
314
|
+
const width = entry?.contentRect.width ?? 0;
|
|
315
|
+
const shown = this.#seen === 0;
|
|
316
|
+
this.#seen = width;
|
|
317
|
+
cancelAnimationFrame(this.#frame);
|
|
318
|
+
if (shown) this.#set(width);
|
|
319
|
+
else this.#frame = requestAnimationFrame(() => this.#set(width));
|
|
320
|
+
});
|
|
321
|
+
this.#observer.observe(mark);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
#set(width: number): void {
|
|
325
|
+
// Not laid out (hidden): it keeps the step it had.
|
|
326
|
+
if (width === 0) return;
|
|
327
|
+
const rem = Number.parseFloat(getComputedStyle(document.documentElement).fontSize) || 16;
|
|
328
|
+
const step = width <= 13 * rem ? 2 : width <= 20 * rem ? 1 : 0;
|
|
329
|
+
if (step === this.step) return;
|
|
330
|
+
this.step = step;
|
|
331
|
+
this.#host.requestUpdate();
|
|
332
|
+
}
|
|
333
|
+
}
|
package/src/elements/toolbar.ts
CHANGED
|
@@ -26,7 +26,7 @@ import { AuthoringElement } from './base.js';
|
|
|
26
26
|
import { type AstlInsertMenu, GLYPHS, type Glyph, type InsertGroup, TYPE_GLYPHS } from './insert-menu.js';
|
|
27
27
|
import { loadStyleElements, STYLE_OPEN, type StyleOpen } from './style-load.js';
|
|
28
28
|
import type { StylePopup } from './style-popups.js';
|
|
29
|
-
import { inheritTokens, kitStyles } from './styles.js';
|
|
29
|
+
import { fitViewport, inheritTokens, kitStyles, VIEWPORT_MARGIN } from './styles.js';
|
|
30
30
|
|
|
31
31
|
/** Kit items a host can feature besides component tags (`tag`) and starters (`tag:template`). */
|
|
32
32
|
export const FEATURED_ITEMS: readonly string[] = ['text', 'picture', 'page-break'];
|
|
@@ -293,6 +293,8 @@ const popupStyles: CSSResult = css`
|
|
|
293
293
|
block-size: 1rem;
|
|
294
294
|
}
|
|
295
295
|
[popover] {
|
|
296
|
+
--room-inline: calc(100vw - 2 * var(--astl-space-4));
|
|
297
|
+
--room-block: calc(100dvh - 2 * var(--astl-space-4));
|
|
296
298
|
box-sizing: border-box;
|
|
297
299
|
position: fixed;
|
|
298
300
|
inset: auto;
|
|
@@ -304,6 +306,8 @@ const popupStyles: CSSResult = css`
|
|
|
304
306
|
color: var(--astl-ink);
|
|
305
307
|
box-shadow: 0 0.5rem 1.5rem rgb(0 0 0 / 0.2);
|
|
306
308
|
overflow: auto;
|
|
309
|
+
max-inline-size: var(--room-inline);
|
|
310
|
+
max-block-size: var(--room-block);
|
|
307
311
|
}
|
|
308
312
|
[popover]:not(:popover-open) {
|
|
309
313
|
display: none;
|
|
@@ -312,8 +316,7 @@ const popupStyles: CSSResult = css`
|
|
|
312
316
|
display: flex;
|
|
313
317
|
flex-direction: column;
|
|
314
318
|
gap: 2px;
|
|
315
|
-
min-inline-size: 12rem;
|
|
316
|
-
max-block-size: calc(100dvh - 2 * var(--astl-space-4));
|
|
319
|
+
min-inline-size: min(12rem, var(--room-inline));
|
|
317
320
|
}
|
|
318
321
|
.menu button {
|
|
319
322
|
justify-content: flex-start;
|
|
@@ -326,8 +329,8 @@ const popupStyles: CSSResult = css`
|
|
|
326
329
|
font-weight: 600;
|
|
327
330
|
}
|
|
328
331
|
.insert {
|
|
329
|
-
inline-size: min(26rem,
|
|
330
|
-
max-block-size: min(32rem,
|
|
332
|
+
inline-size: min(26rem, var(--room-inline));
|
|
333
|
+
max-block-size: min(32rem, var(--room-block));
|
|
331
334
|
padding: 0;
|
|
332
335
|
}
|
|
333
336
|
.insert .search {
|
|
@@ -355,7 +358,7 @@ const popupStyles: CSSResult = css`
|
|
|
355
358
|
.link {
|
|
356
359
|
display: flex;
|
|
357
360
|
flex-direction: column;
|
|
358
|
-
inline-size: min(22rem,
|
|
361
|
+
inline-size: min(22rem, var(--room-inline));
|
|
359
362
|
}
|
|
360
363
|
.menu .menu-section {
|
|
361
364
|
display: contents;
|
|
@@ -536,6 +539,7 @@ export class AstlToolbar extends AuthoringElement {
|
|
|
536
539
|
this.#follow();
|
|
537
540
|
document.addEventListener('pointerdown', this.#outside, true);
|
|
538
541
|
document.addEventListener('keydown', this.#escape);
|
|
542
|
+
window.addEventListener('resize', this.#replace);
|
|
539
543
|
}
|
|
540
544
|
|
|
541
545
|
override disconnectedCallback(): void {
|
|
@@ -543,6 +547,7 @@ export class AstlToolbar extends AuthoringElement {
|
|
|
543
547
|
this.#follow();
|
|
544
548
|
document.removeEventListener('pointerdown', this.#outside, true);
|
|
545
549
|
document.removeEventListener('keydown', this.#escape);
|
|
550
|
+
window.removeEventListener('resize', this.#replace);
|
|
546
551
|
}
|
|
547
552
|
|
|
548
553
|
protected override willUpdate(changed: PropertyValues<this>): void {
|
|
@@ -629,18 +634,34 @@ export class AstlToolbar extends AuthoringElement {
|
|
|
629
634
|
this.requestUpdate();
|
|
630
635
|
}
|
|
631
636
|
|
|
632
|
-
/**
|
|
637
|
+
/**
|
|
638
|
+
* Puts a popup below its button, its start edge on the button's, and keeps it inside the viewport: no wider or taller
|
|
639
|
+
* than the viewport less a margin (`fitViewport`: it scrolls inside), moved along to fit, and above the button where
|
|
640
|
+
* it fits only there (else as low as it fits). Rectangles are in the viewport's pixels, the popup's insets in its own,
|
|
641
|
+
* zoomed ones (a page that enlarges its text with `zoom`).
|
|
642
|
+
*/
|
|
633
643
|
#place(popup: HTMLElement, opener: HTMLElement): void {
|
|
644
|
+
const zoom = fitViewport(popup);
|
|
645
|
+
const margin = VIEWPORT_MARGIN;
|
|
646
|
+
const { clientWidth: width, clientHeight: height } = document.documentElement;
|
|
647
|
+
// Measured at the start, where a popup that sizes to its content has the whole width to take.
|
|
648
|
+
popup.style.setProperty('inset-inline-start', `${margin / zoom}px`);
|
|
649
|
+
popup.style.setProperty('inset-block-start', `${margin / zoom}px`);
|
|
650
|
+
const box = popup.getBoundingClientRect();
|
|
634
651
|
const rect = opener.getBoundingClientRect();
|
|
635
652
|
const rtl = getComputedStyle(opener).direction === 'rtl';
|
|
636
|
-
const
|
|
637
|
-
const
|
|
638
|
-
const
|
|
639
|
-
const
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
653
|
+
const start = rtl ? width - rect.right : rect.left;
|
|
654
|
+
const inline = Math.max(margin, Math.min(start, width - box.width - margin));
|
|
655
|
+
const below = rect.bottom + 4;
|
|
656
|
+
const above = rect.top - 4 - box.height;
|
|
657
|
+
const block =
|
|
658
|
+
below + box.height <= height - margin
|
|
659
|
+
? below
|
|
660
|
+
: above >= margin
|
|
661
|
+
? above
|
|
662
|
+
: Math.max(margin, height - margin - box.height);
|
|
663
|
+
popup.style.setProperty('inset-inline-start', `${inline / zoom}px`);
|
|
664
|
+
popup.style.setProperty('inset-block-start', `${block / zoom}px`);
|
|
644
665
|
}
|
|
645
666
|
|
|
646
667
|
/** After a command: the editor gets the focus back when a key pressed the button (a pointer never took it). */
|
|
@@ -1420,11 +1441,16 @@ export class AstlToolbar extends AuthoringElement {
|
|
|
1420
1441
|
choice.style.fontFamily = choice.dataset.font ?? '';
|
|
1421
1442
|
}
|
|
1422
1443
|
// Popups stay where their buttons are while the page scrolls or the bar wraps.
|
|
1444
|
+
this.#replace();
|
|
1445
|
+
}
|
|
1446
|
+
|
|
1447
|
+
/** Places the open popup again: its button moved, or the viewport changed (a turned phone). */
|
|
1448
|
+
#replace = (): void => {
|
|
1423
1449
|
if (this.#popup === null) return;
|
|
1424
1450
|
const element = this.renderRoot.querySelector<HTMLElement>(`#${popoverOf(this.#popup)}`);
|
|
1425
1451
|
const opener = this.renderRoot.querySelector<HTMLElement>(`[data-popup="${openerOf(this.#popup)}"]`);
|
|
1426
1452
|
if (element !== null && opener !== null && element.matches(':popover-open')) this.#place(element, opener);
|
|
1427
|
-
}
|
|
1453
|
+
};
|
|
1428
1454
|
}
|
|
1429
1455
|
|
|
1430
1456
|
declare global {
|
package/src/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ export type {
|
|
|
4
4
|
DescribeOptions,
|
|
5
5
|
Outline,
|
|
6
6
|
OutlineBlock,
|
|
7
|
+
OutlineCheck,
|
|
7
8
|
OutlineComponent,
|
|
8
9
|
OutlinePage,
|
|
9
10
|
PickPicture,
|
|
@@ -13,7 +14,7 @@ export type {
|
|
|
13
14
|
UploadAsset,
|
|
14
15
|
UploadedAsset,
|
|
15
16
|
} from './authoring.js';
|
|
16
|
-
export { createAuthoring, pictureHtml, pictureSize, UploadRefused } from './authoring.js';
|
|
17
|
+
export { createAuthoring, insertCheck, pictureHtml, pictureSize, UploadRefused } from './authoring.js';
|
|
17
18
|
export { defineAuthoringElements } from './define.js';
|
|
18
19
|
export type { InspectorChange } from './edit.js';
|
|
19
20
|
export type { AstlHelpForm, HelpKind } from './elements/help-form.js';
|
|
@@ -35,6 +36,8 @@ export type { InsertMenu, ToolbarView } from './elements/toolbar.js';
|
|
|
35
36
|
export { AstlToolbar, FEATURED_ITEMS, VIEW_PICKED } from './elements/toolbar.js';
|
|
36
37
|
export type {
|
|
37
38
|
CheckboxFieldModel,
|
|
39
|
+
CheckTargetModel,
|
|
40
|
+
CheckTargetsFieldModel,
|
|
38
41
|
ChildChoiceFieldModel,
|
|
39
42
|
ChildChoiceModel,
|
|
40
43
|
ChildFlagFieldModel,
|
package/src/inspect.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Inspector models: what an inspector shows for one component element. Fields come from the EditorDescriptor, or
|
|
3
3
|
* are derived from the manifest; controls follow the AttributeSpec types. Every component also gets `variant` (when
|
|
4
|
-
* its manifest has variants) and `style-template` (when templates are offered for it), after those fields.
|
|
5
|
-
* data, so any UI can render them.
|
|
4
|
+
* its manifest has variants) and `style-template` (when templates are offered for it), after those fields. A Check
|
|
5
|
+
* element (`astl-check`) has a model of its own (`Authoring.inspect`). Plain data, so any UI can render them.
|
|
6
6
|
*/
|
|
7
7
|
import {
|
|
8
8
|
type AttributeSpec,
|
|
@@ -235,6 +235,30 @@ export interface PicturePointsFieldModel extends PictureFieldBase {
|
|
|
235
235
|
readonly points: readonly PicturePointModel[];
|
|
236
236
|
}
|
|
237
237
|
|
|
238
|
+
/** A question a Check element can check, in its `check-targets` field. */
|
|
239
|
+
export interface CheckTargetModel {
|
|
240
|
+
/** Its source id. */
|
|
241
|
+
readonly id: string;
|
|
242
|
+
/** How authors know it on its page: its type and number ("Gap 2"). */
|
|
243
|
+
readonly label: string;
|
|
244
|
+
/** Whether this Check element checks it. */
|
|
245
|
+
readonly checked: boolean;
|
|
246
|
+
/** The name of another Check element of the page that checks it ("Check button 2"), or null. */
|
|
247
|
+
readonly other: string | null;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* The questions a Check element checks (`for`): the graded questions of its page in order, each ticked when it checks
|
|
252
|
+
* it; one another Check element has says which. A change writes `for` with the ticked ones in this order (empty for
|
|
253
|
+
* none: it then checks nothing).
|
|
254
|
+
*/
|
|
255
|
+
export interface CheckTargetsFieldModel extends FieldTexts {
|
|
256
|
+
readonly kind: 'check-targets';
|
|
257
|
+
/** The attribute it writes: `for`. */
|
|
258
|
+
readonly name: string;
|
|
259
|
+
readonly targets: readonly CheckTargetModel[];
|
|
260
|
+
}
|
|
261
|
+
|
|
238
262
|
export type InspectorFieldModel =
|
|
239
263
|
| TextFieldModel
|
|
240
264
|
| NumberFieldModel
|
|
@@ -246,7 +270,8 @@ export type InspectorFieldModel =
|
|
|
246
270
|
| ChildChoiceFieldModel
|
|
247
271
|
| ChildTableFieldModel
|
|
248
272
|
| PictureRegionsFieldModel
|
|
249
|
-
| PicturePointsFieldModel
|
|
273
|
+
| PicturePointsFieldModel
|
|
274
|
+
| CheckTargetsFieldModel;
|
|
250
275
|
|
|
251
276
|
export interface InspectorModel {
|
|
252
277
|
readonly tag: string;
|
|
@@ -256,6 +281,11 @@ export interface InspectorModel {
|
|
|
256
281
|
/** Icon name from the descriptor. */
|
|
257
282
|
readonly icon: string | null;
|
|
258
283
|
readonly fields: readonly InspectorFieldModel[];
|
|
284
|
+
/**
|
|
285
|
+
* The Check element that checks this question (`OutlineComponent.check`): its source id and its name ("Check button
|
|
286
|
+
* 1"); absent or null when none does, or without the document (`Authoring.inspect` without `source`).
|
|
287
|
+
*/
|
|
288
|
+
readonly checkedBy?: { readonly id: string; readonly name: string } | null;
|
|
259
289
|
}
|
|
260
290
|
|
|
261
291
|
/** Texts the model needs: messages of the manifest namespace (with a fallback) and kit strings. */
|