@astl/editor-tiptap 0.2.0 → 0.2.2
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 +32 -0
- package/dist/blocks.d.ts +5 -3
- package/dist/blocks.d.ts.map +1 -1
- package/dist/blocks.js +63 -5
- package/dist/blocks.js.map +1 -1
- package/dist/element.d.ts.map +1 -1
- package/dist/element.js +12 -2
- package/dist/element.js.map +1 -1
- package/dist/nodes.d.ts +6 -1
- package/dist/nodes.d.ts.map +1 -1
- package/dist/nodes.js +170 -40
- package/dist/nodes.js.map +1 -1
- package/dist/styles.d.ts.map +1 -1
- package/dist/styles.js +142 -35
- package/dist/styles.js.map +1 -1
- package/package.json +6 -6
- package/src/blocks.ts +63 -3
- package/src/element.ts +14 -1
- package/src/nodes.ts +189 -42
- package/src/styles.ts +142 -35
package/src/nodes.ts
CHANGED
|
@@ -50,6 +50,7 @@ import { cleanClass, cleanStyle, isStyleName } from '@astl/core/declarations';
|
|
|
50
50
|
import {
|
|
51
51
|
type Authoring,
|
|
52
52
|
EDITOR_NAMESPACE,
|
|
53
|
+
type HelpPart,
|
|
53
54
|
type PictureFields,
|
|
54
55
|
type PictureRequest,
|
|
55
56
|
type Placement,
|
|
@@ -66,6 +67,7 @@ import {
|
|
|
66
67
|
type DOMOutputSpec,
|
|
67
68
|
DOMSerializer,
|
|
68
69
|
Fragment,
|
|
70
|
+
type MarkType,
|
|
69
71
|
type Mark as PMMark,
|
|
70
72
|
type Node as PMNode,
|
|
71
73
|
Slice,
|
|
@@ -74,6 +76,7 @@ import {
|
|
|
74
76
|
type EditorState,
|
|
75
77
|
NodeSelection,
|
|
76
78
|
Plugin,
|
|
79
|
+
PluginKey,
|
|
77
80
|
Selection,
|
|
78
81
|
TextSelection,
|
|
79
82
|
type Transaction,
|
|
@@ -375,7 +378,7 @@ const updater =
|
|
|
375
378
|
function summary(manifest: ComponentManifest | null, attrs: Record<string, unknown>): string {
|
|
376
379
|
const main = manifest?.attributes.find((a) => a.type === 'string')?.name;
|
|
377
380
|
if (main !== undefined) return (attrs.attributes as Attributes)[main] ?? '';
|
|
378
|
-
// Its help for students is not what it holds: the frame
|
|
381
|
+
// Its help for students is not what it holds: the frame's tags say it, the card edits it.
|
|
379
382
|
const children = (attrs.children as readonly Kept[]).filter(
|
|
380
383
|
(c) => typeof c === 'string' || !HELP_TAGS.has(c.tag),
|
|
381
384
|
);
|
|
@@ -428,6 +431,7 @@ const SVG_ICONS = {
|
|
|
428
431
|
check: 'M4 10.5l4 4 8-9',
|
|
429
432
|
warning: 'M10 3l8 14H2zM10 8v4M10 14.5v.5',
|
|
430
433
|
add: 'M10 4v12M4 10h12',
|
|
434
|
+
remove: 'M5 5l10 10M15 5L5 15',
|
|
431
435
|
};
|
|
432
436
|
|
|
433
437
|
/** A 20 by 20 line icon, hidden from assistive technology. */
|
|
@@ -541,9 +545,7 @@ function atomNode(
|
|
|
541
545
|
if (picture !== null) dom.append(picture.dom);
|
|
542
546
|
const body = dom.appendChild(document.createElement('div'));
|
|
543
547
|
body.className = 'astl-atom-summary';
|
|
544
|
-
// Its help for students
|
|
545
|
-
const help = dom.appendChild(document.createElement('div'));
|
|
546
|
-
help.className = 'astl-help-kept';
|
|
548
|
+
// Its help for students is not drawn: the frame's tags say what it has, the card edits it.
|
|
547
549
|
// Inside the frame, not on it: an author's border must not hide what the frame says.
|
|
548
550
|
const paint = placedPainter(body, tag);
|
|
549
551
|
const showPlace = authoring === undefined ? null : componentPlacing(authoring, dom, editor, getPos);
|
|
@@ -554,8 +556,6 @@ function atomNode(
|
|
|
554
556
|
// The picture shows the zones and pins; a summary of them would only repeat them.
|
|
555
557
|
body.textContent = picture === null ? summary(manifest, attrs) : '';
|
|
556
558
|
body.hidden = picture !== null;
|
|
557
|
-
if (authoring !== undefined)
|
|
558
|
-
help.replaceChildren(...keptHelp(attrs.children as readonly Kept[], authoring));
|
|
559
559
|
};
|
|
560
560
|
render(node.attrs);
|
|
561
561
|
return {
|
|
@@ -582,41 +582,11 @@ const FLOW = `(${FLOW_NODES.join(' | ')})+`;
|
|
|
582
582
|
/**
|
|
583
583
|
* The group of the help for students (`<astl-hint>`, `<astl-explanation>`, `<astl-feedback>`): rich content in a page
|
|
584
584
|
* or in a block component, never in a column or in text (an inline component or an atom keeps its own as data). In
|
|
585
|
-
* the editor, a labelled box; its select sets
|
|
585
|
+
* the editor, a page's is a labelled box; its select sets the verdict a feedback text is for. A block component's is
|
|
586
|
+
* kept, not drawn (the frame's tags say it, the card edits it): it cannot be selected, so no key reaches it unseen.
|
|
586
587
|
*/
|
|
587
588
|
const HELP = 'help';
|
|
588
589
|
|
|
589
|
-
/** The label of a help element in the UI language: what it is, with its cost or its verdict. */
|
|
590
|
-
function helpLabel(
|
|
591
|
-
tag: string,
|
|
592
|
-
attributes: Attributes,
|
|
593
|
-
t: (key: string, params?: MessageParams) => string,
|
|
594
|
-
): string {
|
|
595
|
-
if (tag === HINT_TAG) {
|
|
596
|
-
const percent = Math.round(Number(attributes.cost ?? 0) * 100);
|
|
597
|
-
return percent > 0 ? `${t('insert.hint')}, ${t('help.cost', { percent })}` : t('insert.hint');
|
|
598
|
-
}
|
|
599
|
-
if (tag === EXPLANATION_TAG) return t('insert.explanation');
|
|
600
|
-
return `${t('insert.feedback')}: ${t(`help.when.${attributes.when ?? ''}`)}`;
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
/** An atom's help kept as data, as read-only labelled boxes. */
|
|
604
|
-
function keptHelp(children: readonly Kept[], authoring: Authoring): HTMLElement[] {
|
|
605
|
-
const t = (key: string, params?: MessageParams) => authoring.t(EDITOR_NAMESPACE, key, params);
|
|
606
|
-
return children.flatMap((c) => {
|
|
607
|
-
if (typeof c === 'string' || !HELP_TAGS.has(c.tag)) return [];
|
|
608
|
-
const box = document.createElement('div');
|
|
609
|
-
box.className = 'astl-help-box';
|
|
610
|
-
box.dataset.help = c.tag;
|
|
611
|
-
const head = box.appendChild(document.createElement('div'));
|
|
612
|
-
head.className = 'astl-help-head';
|
|
613
|
-
head.lang = authoring.locale;
|
|
614
|
-
head.textContent = helpLabel(c.tag, c.attributes, t);
|
|
615
|
-
box.appendChild(document.createElement('div')).textContent = textOf(c).trim();
|
|
616
|
-
return [box];
|
|
617
|
-
});
|
|
618
|
-
}
|
|
619
|
-
|
|
620
590
|
/** Costs a question's hint offers, as written in `cost` ('0': free, no attribute); a cost besides them stays. */
|
|
621
591
|
const COSTS: readonly string[] = ['0', '0.1', '0.25', '0.5'];
|
|
622
592
|
|
|
@@ -722,6 +692,7 @@ function helpNode(tag: string, authoring?: Authoring): Node {
|
|
|
722
692
|
content: FLOW,
|
|
723
693
|
defining: true,
|
|
724
694
|
isolating: true,
|
|
695
|
+
selectable: false,
|
|
725
696
|
addAttributes: () => sourceAttributes,
|
|
726
697
|
parseHTML: () => [{ tag }],
|
|
727
698
|
renderHTML: ({ node }) => [tag, { ...node.attrs.attributes }, 0],
|
|
@@ -838,11 +809,14 @@ function helpNode(tag: string, authoring?: Authoring): Node {
|
|
|
838
809
|
else attributes[tag === HINT_TAG ? 'cost' : 'when'] = select.value;
|
|
839
810
|
editor.view.dispatch(editor.state.tr.setNodeAttribute(pos, 'attributes', attributes));
|
|
840
811
|
});
|
|
841
|
-
// "Remove" at the end of the head, named by the kind of box: a box the menu added empty has no other way
|
|
812
|
+
// "Remove" at the end of the head, an icon named by the kind of box: a box the menu added empty has no other way
|
|
813
|
+
// out.
|
|
842
814
|
const remove = head.appendChild(Object.assign(document.createElement('button'), { type: 'button' }));
|
|
843
815
|
remove.className = 'astl-help-remove';
|
|
844
|
-
remove.
|
|
845
|
-
|
|
816
|
+
remove.append(lineIcon('remove', 'astl-icon'));
|
|
817
|
+
const removeName = t('surface.helpRemove', { kind: tag.replace(/^astl-/, '') });
|
|
818
|
+
remove.setAttribute('aria-label', removeName);
|
|
819
|
+
remove.title = removeName;
|
|
846
820
|
remove.addEventListener('click', () => {
|
|
847
821
|
const pos = getPos();
|
|
848
822
|
if (typeof pos !== 'number') return;
|
|
@@ -927,6 +901,50 @@ export function helpNodes(authoring?: Authoring): Node[] {
|
|
|
927
901
|
return [HINT_TAG, EXPLANATION_TAG, FEEDBACK_TAG].map((tag) => helpNode(tag, authoring));
|
|
928
902
|
}
|
|
929
903
|
|
|
904
|
+
/**
|
|
905
|
+
* An empty help box's line says what to write there ("Write the hint..."): the box keeps one empty paragraph to type
|
|
906
|
+
* in, and a decoration marks it (`astl-help-empty`, the text in `data-placeholder`, which the surface's style shows).
|
|
907
|
+
*/
|
|
908
|
+
function helpPlaceholderExtension(authoring: Authoring): Extension {
|
|
909
|
+
const kinds = new Map(
|
|
910
|
+
[HINT_TAG, EXPLANATION_TAG, FEEDBACK_TAG].map(
|
|
911
|
+
(tag) => [nodeName(tag), tag.replace(/^astl-/, '')] as const,
|
|
912
|
+
),
|
|
913
|
+
);
|
|
914
|
+
const decorate = (doc: PMNode): DecorationSet => {
|
|
915
|
+
const decorations: Decoration[] = [];
|
|
916
|
+
doc.descendants((node, pos) => {
|
|
917
|
+
const kind = kinds.get(node.type.name);
|
|
918
|
+
if (kind === undefined) return !node.isTextblock;
|
|
919
|
+
const line = node.firstChild;
|
|
920
|
+
if (node.childCount === 1 && line !== null && line.isTextblock && line.content.size === 0) {
|
|
921
|
+
decorations.push(
|
|
922
|
+
Decoration.node(pos + 1, pos + 1 + line.nodeSize, {
|
|
923
|
+
class: 'astl-help-empty',
|
|
924
|
+
'data-placeholder': authoring.t(EDITOR_NAMESPACE, 'surface.helpPlaceholder', { kind }),
|
|
925
|
+
}),
|
|
926
|
+
);
|
|
927
|
+
}
|
|
928
|
+
return false;
|
|
929
|
+
});
|
|
930
|
+
return DecorationSet.create(doc, decorations);
|
|
931
|
+
};
|
|
932
|
+
const key = new PluginKey<DecorationSet>('astlHelpPlaceholder');
|
|
933
|
+
return Extension.create({
|
|
934
|
+
name: 'astlHelpPlaceholder',
|
|
935
|
+
addProseMirrorPlugins: () => [
|
|
936
|
+
new Plugin<DecorationSet>({
|
|
937
|
+
key,
|
|
938
|
+
state: {
|
|
939
|
+
init: (_, state) => decorate(state.doc),
|
|
940
|
+
apply: (tr, previous) => (tr.docChanged ? decorate(tr.doc) : previous),
|
|
941
|
+
},
|
|
942
|
+
props: { decorations: (state) => key.getState(state) },
|
|
943
|
+
}),
|
|
944
|
+
],
|
|
945
|
+
});
|
|
946
|
+
}
|
|
947
|
+
|
|
930
948
|
/**
|
|
931
949
|
* A block with rich children, or with rich content (`content: 'flow'`), framed and labelled in the editor, with its
|
|
932
950
|
* picture when it has picture fields.
|
|
@@ -972,6 +990,9 @@ function blockNode(manifest: ComponentManifest, pictures?: PictureView, authorin
|
|
|
972
990
|
({ node, getPos, editor }) => {
|
|
973
991
|
const dom = document.createElement('div');
|
|
974
992
|
dom.className = 'astl-block';
|
|
993
|
+
// A graded one's help for students is not drawn (its frame's tags say it, the card edits it); an ungraded one
|
|
994
|
+
// shows help it should not hold, which the engine warns of, so it can be taken away.
|
|
995
|
+
dom.toggleAttribute('data-astl-graded', manifest.graded);
|
|
975
996
|
const picture = pictures?.layers(manifest.tag).length ? pictures.create(manifest.tag) : null;
|
|
976
997
|
const contentDOM = document.createElement('div');
|
|
977
998
|
// Inside the frame, not on it: an author's border must not hide what the frame says.
|
|
@@ -1012,8 +1033,19 @@ function blockNode(manifest: ComponentManifest, pictures?: PictureView, authorin
|
|
|
1012
1033
|
add.addEventListener('click', () => {
|
|
1013
1034
|
const pos = getPos();
|
|
1014
1035
|
const block = typeof pos === 'number' ? editor.state.doc.nodeAt(pos) : null;
|
|
1036
|
+
if (typeof pos !== 'number' || block === null) return;
|
|
1037
|
+
// In a rich block the child is a mark in its text (Select words' word): a new word ends its last line.
|
|
1038
|
+
const markType = editor.schema.marks[childType];
|
|
1039
|
+
if (markType !== undefined) {
|
|
1040
|
+
const word = authoring.t(EDITOR_NAMESPACE, 'surface.newWord');
|
|
1041
|
+
const tr = addMarkedWord(editor.state, pos, block, markType, repeated.tag, word);
|
|
1042
|
+
if (tr === null) return;
|
|
1043
|
+
editor.view.dispatch(tr.scrollIntoView());
|
|
1044
|
+
editor.view.focus();
|
|
1045
|
+
return;
|
|
1046
|
+
}
|
|
1015
1047
|
const type = editor.schema.nodes[childType];
|
|
1016
|
-
if (
|
|
1048
|
+
if (type === undefined) return;
|
|
1017
1049
|
// After the last child of that tag (an option goes after the options, before anything after them).
|
|
1018
1050
|
let at = pos + block.nodeSize - 1;
|
|
1019
1051
|
block.forEach((child, offset) => {
|
|
@@ -1073,6 +1105,113 @@ function blockNode(manifest: ComponentManifest, pictures?: PictureView, authorin
|
|
|
1073
1105
|
});
|
|
1074
1106
|
}
|
|
1075
1107
|
|
|
1108
|
+
/**
|
|
1109
|
+
* A new child of a rich block that is a mark in its text (Select words' word, `markType`): `text` at the end of the
|
|
1110
|
+
* block's last line (after a space), with a fresh id, selected so that typing replaces it and keeps the mark; one undo
|
|
1111
|
+
* step. A block without a line of text gets one.
|
|
1112
|
+
*/
|
|
1113
|
+
function addMarkedWord(
|
|
1114
|
+
state: EditorState,
|
|
1115
|
+
pos: number,
|
|
1116
|
+
block: PMNode,
|
|
1117
|
+
markType: MarkType,
|
|
1118
|
+
tag: string,
|
|
1119
|
+
text: string,
|
|
1120
|
+
): Transaction | null {
|
|
1121
|
+
const tr = closeHistory(state.tr);
|
|
1122
|
+
let end: number | null = null;
|
|
1123
|
+
block.descendants((node, offset) => {
|
|
1124
|
+
if (node.type.name === 'paragraph' || node.type.name === 'heading')
|
|
1125
|
+
end = pos + 2 + offset + node.content.size;
|
|
1126
|
+
return !node.isTextblock;
|
|
1127
|
+
});
|
|
1128
|
+
if (end === null) {
|
|
1129
|
+
const paragraph = state.schema.nodes.paragraph;
|
|
1130
|
+
if (paragraph === undefined) return null;
|
|
1131
|
+
const at = pos + block.nodeSize - 1;
|
|
1132
|
+
tr.insert(at, paragraph.create());
|
|
1133
|
+
end = at + 1;
|
|
1134
|
+
}
|
|
1135
|
+
let at: number = end;
|
|
1136
|
+
const $end = tr.doc.resolve(at);
|
|
1137
|
+
const before = $end.parent.textBetween(0, $end.parentOffset, undefined, '\ufffc');
|
|
1138
|
+
// A plain space before it: inserted text would take the mark of a word that ends the line.
|
|
1139
|
+
if (before !== '' && !/\s$/u.test(before)) {
|
|
1140
|
+
tr.insert(at, state.schema.text(' '));
|
|
1141
|
+
at += 1;
|
|
1142
|
+
}
|
|
1143
|
+
const taken = idsIn(tr.doc);
|
|
1144
|
+
tr.doc.descendants((node) => {
|
|
1145
|
+
for (const mark of node.marks) if (mark.type === markType) taken.add(markId(mark));
|
|
1146
|
+
return true;
|
|
1147
|
+
});
|
|
1148
|
+
const id = freshId(tag.replace(/^astl-/, ''), taken);
|
|
1149
|
+
tr.insert(at, state.schema.text(text, [markType.create({ attributes: { id } })]));
|
|
1150
|
+
// The word grows as the author types over it or at its end (`growingWordExtension`).
|
|
1151
|
+
return tr
|
|
1152
|
+
.setSelection(TextSelection.create(tr.doc, at, at + text.length))
|
|
1153
|
+
.setMeta(GROWING, { id, type: markType });
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
/** The word "Add option" just added in a rich block: its id and mark type, until the cursor leaves it. */
|
|
1157
|
+
interface Growing {
|
|
1158
|
+
readonly id: string;
|
|
1159
|
+
readonly type: MarkType;
|
|
1160
|
+
}
|
|
1161
|
+
const GROWING = new PluginKey<Growing | null>('astlGrowingWord');
|
|
1162
|
+
|
|
1163
|
+
/** Where the run of text marked `growing` is (one word), with its mark, or null. */
|
|
1164
|
+
function growingRun(doc: PMNode, growing: Growing): { from: number; to: number; mark: PMMark } | null {
|
|
1165
|
+
let run: { from: number; to: number; mark: PMMark } | null = null;
|
|
1166
|
+
doc.descendants((node, pos) => {
|
|
1167
|
+
if (!node.isText) return run === null;
|
|
1168
|
+
const mark = node.marks.find((m) => m.type === growing.type && markId(m) === growing.id);
|
|
1169
|
+
if (mark === undefined) return false;
|
|
1170
|
+
run = run === null ? { from: pos, to: pos + node.nodeSize, mark } : { ...run, to: pos + node.nodeSize };
|
|
1171
|
+
return false;
|
|
1172
|
+
});
|
|
1173
|
+
return run;
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
/**
|
|
1177
|
+
* A word "Add option" added keeps growing while the author types it: text typed over it (it comes selected) or at its
|
|
1178
|
+
* end joins it, though the words' marks end with them, until a space or the cursor leaves it. Other words keep their
|
|
1179
|
+
* marks as they are.
|
|
1180
|
+
*/
|
|
1181
|
+
const growingWordExtension = Extension.create({
|
|
1182
|
+
name: 'astlGrowingWord',
|
|
1183
|
+
addProseMirrorPlugins: () => [
|
|
1184
|
+
new Plugin<Growing | null>({
|
|
1185
|
+
key: GROWING,
|
|
1186
|
+
state: {
|
|
1187
|
+
init: () => null,
|
|
1188
|
+
apply: (tr, value, _, state) => {
|
|
1189
|
+
const set = tr.getMeta(GROWING) as Growing | null | undefined;
|
|
1190
|
+
const growing = set === undefined ? value : set;
|
|
1191
|
+
if (growing === null) return null;
|
|
1192
|
+
const run = growingRun(state.doc, growing);
|
|
1193
|
+
const { from, to } = state.selection;
|
|
1194
|
+
return run !== null && from >= run.from && to <= run.to ? growing : null;
|
|
1195
|
+
},
|
|
1196
|
+
},
|
|
1197
|
+
props: {
|
|
1198
|
+
handleTextInput: (view, from, to, text) => {
|
|
1199
|
+
const growing = GROWING.getState(view.state);
|
|
1200
|
+
if (growing === null || growing === undefined || !/^[\p{L}\p{N}\p{M}'’-]+$/u.test(text))
|
|
1201
|
+
return false;
|
|
1202
|
+
const run = growingRun(view.state.doc, growing);
|
|
1203
|
+
if (run === null) return false;
|
|
1204
|
+
const over = from === run.from && to === run.to;
|
|
1205
|
+
if (!over && !(from === to && from === run.to)) return false;
|
|
1206
|
+
const tr = view.state.tr.insertText(text, from, to);
|
|
1207
|
+
view.dispatch(tr.addMark(from, from + text.length, run.mark));
|
|
1208
|
+
return true;
|
|
1209
|
+
},
|
|
1210
|
+
},
|
|
1211
|
+
}),
|
|
1212
|
+
],
|
|
1213
|
+
});
|
|
1214
|
+
|
|
1076
1215
|
/**
|
|
1077
1216
|
* A rich child of a block (prompt, option): one line of rich text, in a plain element so no custom element claims
|
|
1078
1217
|
* it. A child the manifest allows once (a prompt) is marked `single`.
|
|
@@ -1502,6 +1641,11 @@ export interface PictureHooks {
|
|
|
1502
1641
|
* does).
|
|
1503
1642
|
*/
|
|
1504
1643
|
style?(kind: 'picture' | 'figure' | 'component'): void;
|
|
1644
|
+
/**
|
|
1645
|
+
* Opens the help for students of the component at the cursor at a part, from a tag on its frame (`<astl-editor>`:
|
|
1646
|
+
* `astl-help-open`, else its inspector).
|
|
1647
|
+
*/
|
|
1648
|
+
help?(part: HelpPart): void;
|
|
1505
1649
|
}
|
|
1506
1650
|
|
|
1507
1651
|
/** A width from the corner handle on the node at `pos`, one undo step; a figure's picture follows. */
|
|
@@ -3029,12 +3173,15 @@ export function astrolabeExtensions(
|
|
|
3029
3173
|
referencesExtension(authoring, manifests),
|
|
3030
3174
|
childrenExtension(manifests),
|
|
3031
3175
|
richBlocksExtension(authoring, manifests),
|
|
3176
|
+
growingWordExtension,
|
|
3032
3177
|
pastedIdsExtension(authoring, manifests, hooks),
|
|
3033
3178
|
blocksExtension(
|
|
3034
3179
|
authoring,
|
|
3035
3180
|
(node) => types.get(node.type.name) ?? null,
|
|
3036
3181
|
nodeName,
|
|
3037
3182
|
hooks?.style === undefined ? undefined : () => hooks.style?.('component'),
|
|
3183
|
+
hooks?.help === undefined ? undefined : (part) => hooks.help?.(part),
|
|
3038
3184
|
),
|
|
3185
|
+
helpPlaceholderExtension(authoring),
|
|
3039
3186
|
];
|
|
3040
3187
|
}
|
package/src/styles.ts
CHANGED
|
@@ -186,6 +186,10 @@ const baseSurfaceStyles: CSSResult = css`
|
|
|
186
186
|
outline: var(--astl-focus-width) solid var(--astl-focus);
|
|
187
187
|
outline-offset: var(--astl-focus-offset);
|
|
188
188
|
}
|
|
189
|
+
/* The surface's authoring controls (the page heads' buttons, a page box's, the blocks' "Add option", a frame's
|
|
190
|
+
position line, a picture's buttons) are compact, ghost at rest, so that the exercise looks as students see it. A
|
|
191
|
+
host sizes them with --astl-editor-control-size (their height, 1.75rem), --astl-editor-control-font-size (0.8125rem)
|
|
192
|
+
and --astl-editor-control-icon-size (0.875rem); a target stays at least 24px (WCAG 2.5.8). */
|
|
189
193
|
.astl-surface
|
|
190
194
|
:is(
|
|
191
195
|
.astl-page-join,
|
|
@@ -196,17 +200,44 @@ const baseSurfaceStyles: CSSResult = css`
|
|
|
196
200
|
.astl-help-remove,
|
|
197
201
|
.astl-help-free
|
|
198
202
|
) {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
+
box-sizing: border-box;
|
|
204
|
+
display: inline-flex;
|
|
205
|
+
align-items: center;
|
|
206
|
+
justify-content: center;
|
|
207
|
+
gap: 0.25rem;
|
|
208
|
+
min-block-size: max(24px, var(--astl-editor-control-size, 1.75rem));
|
|
209
|
+
min-inline-size: max(24px, var(--astl-editor-control-size, 1.75rem));
|
|
210
|
+
padding-block: 0;
|
|
211
|
+
padding-inline: var(--astl-space-2);
|
|
212
|
+
border: var(--astl-outline-width) solid transparent;
|
|
203
213
|
border-radius: var(--astl-radius-s);
|
|
204
|
-
background:
|
|
205
|
-
color: var(--astl-ink);
|
|
214
|
+
background: transparent;
|
|
215
|
+
color: var(--astl-ink-muted);
|
|
206
216
|
font: inherit;
|
|
207
|
-
font-
|
|
217
|
+
font-family: var(--astl-font-body);
|
|
218
|
+
font-size: var(--astl-editor-control-font-size, 0.8125rem);
|
|
219
|
+
font-weight: 600;
|
|
220
|
+
line-height: 1.2;
|
|
221
|
+
white-space: nowrap;
|
|
208
222
|
cursor: pointer;
|
|
209
223
|
}
|
|
224
|
+
.astl-surface
|
|
225
|
+
:is(
|
|
226
|
+
.astl-page-join,
|
|
227
|
+
.astl-page-delete,
|
|
228
|
+
.astl-page-add-title,
|
|
229
|
+
.astl-page-remove-title,
|
|
230
|
+
.astl-page-check,
|
|
231
|
+
.astl-help-remove,
|
|
232
|
+
.astl-help-free
|
|
233
|
+
):hover {
|
|
234
|
+
background: var(--astl-accent-soft);
|
|
235
|
+
color: var(--astl-ink);
|
|
236
|
+
}
|
|
237
|
+
.astl-surface :is(.astl-help-remove, .astl-block-add button) .astl-icon {
|
|
238
|
+
inline-size: var(--astl-editor-control-icon-size, 0.875rem);
|
|
239
|
+
block-size: var(--astl-editor-control-icon-size, 0.875rem);
|
|
240
|
+
}
|
|
210
241
|
.astl-surface
|
|
211
242
|
:is(.astl-page-join, .astl-page-delete, .astl-page-add-title, .astl-page-remove-title, .astl-help-free)[hidden] {
|
|
212
243
|
display: none;
|
|
@@ -215,6 +246,7 @@ const baseSurfaceStyles: CSSResult = css`
|
|
|
215
246
|
.astl-surface .astl-page-check[aria-pressed='true'] {
|
|
216
247
|
border-color: var(--astl-accent);
|
|
217
248
|
background: var(--astl-accent-soft);
|
|
249
|
+
color: var(--astl-ink);
|
|
218
250
|
}
|
|
219
251
|
.astl-surface .astl-page-check[aria-pressed='true']::before {
|
|
220
252
|
content: '✓ ' / '';
|
|
@@ -292,7 +324,7 @@ const baseSurfaceStyles: CSSResult = css`
|
|
|
292
324
|
display: flex;
|
|
293
325
|
flex-wrap: wrap;
|
|
294
326
|
align-items: center;
|
|
295
|
-
gap: 0 var(--astl-space-1);
|
|
327
|
+
gap: 0.2em var(--astl-space-1);
|
|
296
328
|
inline-size: fit-content;
|
|
297
329
|
max-inline-size: 100%;
|
|
298
330
|
margin-block: var(--astl-space-4) calc(-1 * var(--frame-width));
|
|
@@ -413,8 +445,7 @@ const baseSurfaceStyles: CSSResult = css`
|
|
|
413
445
|
.astl-surface .astl-frame-note[data-severity='warning'] .astl-icon {
|
|
414
446
|
color: var(--astl-warning);
|
|
415
447
|
}
|
|
416
|
-
.astl-surface .astl-flag
|
|
417
|
-
.astl-surface .astl-block-add button {
|
|
448
|
+
.astl-surface .astl-flag {
|
|
418
449
|
box-sizing: border-box;
|
|
419
450
|
display: inline-flex;
|
|
420
451
|
align-items: center;
|
|
@@ -431,9 +462,9 @@ const baseSurfaceStyles: CSSResult = css`
|
|
|
431
462
|
font: inherit;
|
|
432
463
|
cursor: pointer;
|
|
433
464
|
}
|
|
434
|
-
.astl-surface .astl-block-add button:hover {
|
|
435
|
-
border-color: var(--astl-line);
|
|
465
|
+
.astl-surface .astl-block-add button:hover:not(:disabled) {
|
|
436
466
|
background: var(--astl-accent-soft);
|
|
467
|
+
color: var(--astl-ink);
|
|
437
468
|
}
|
|
438
469
|
.astl-surface .astl-block-add :focus-visible,
|
|
439
470
|
.astl-surface .astl-flag:focus-visible {
|
|
@@ -492,22 +523,25 @@ const baseSurfaceStyles: CSSResult = css`
|
|
|
492
523
|
position: relative;
|
|
493
524
|
z-index: 1;
|
|
494
525
|
box-sizing: border-box;
|
|
526
|
+
display: inline-flex;
|
|
527
|
+
align-items: center;
|
|
495
528
|
visibility: hidden;
|
|
496
|
-
min-block-size: var(--astl-
|
|
529
|
+
min-block-size: max(24px, var(--astl-editor-control-size, 1.75rem));
|
|
497
530
|
margin-block: 0 var(--astl-space-1);
|
|
498
531
|
margin-inline-start: auto;
|
|
499
|
-
padding-block:
|
|
532
|
+
padding-block: 0;
|
|
500
533
|
padding-inline: var(--astl-space-2);
|
|
501
|
-
border: var(--astl-outline-width) solid
|
|
534
|
+
border: var(--astl-outline-width) solid transparent;
|
|
502
535
|
border-radius: var(--astl-radius-s);
|
|
503
|
-
background:
|
|
504
|
-
color: var(--astl-ink);
|
|
536
|
+
background: transparent;
|
|
537
|
+
color: var(--astl-ink-muted);
|
|
505
538
|
font: inherit;
|
|
506
539
|
font-family: var(--astl-font-body);
|
|
507
|
-
font-size: var(--astl-editor-
|
|
540
|
+
font-size: var(--astl-editor-control-font-size, 0.8125rem);
|
|
508
541
|
font-style: normal;
|
|
509
|
-
font-weight:
|
|
510
|
-
line-height: 1.
|
|
542
|
+
font-weight: 600;
|
|
543
|
+
line-height: 1.2;
|
|
544
|
+
white-space: nowrap;
|
|
511
545
|
}
|
|
512
546
|
.astl-surface .astl-frame-head-current > .astl-frame-line {
|
|
513
547
|
visibility: visible;
|
|
@@ -517,6 +551,7 @@ const baseSurfaceStyles: CSSResult = css`
|
|
|
517
551
|
}
|
|
518
552
|
.astl-surface button.astl-frame-line:hover {
|
|
519
553
|
background: var(--astl-accent-soft);
|
|
554
|
+
color: var(--astl-ink);
|
|
520
555
|
}
|
|
521
556
|
.astl-surface .astl-frame-line:focus-visible {
|
|
522
557
|
outline: var(--astl-focus-width) solid var(--astl-focus);
|
|
@@ -528,13 +563,17 @@ const baseSurfaceStyles: CSSResult = css`
|
|
|
528
563
|
.astl-surface .astl-atom-summary {
|
|
529
564
|
color: var(--astl-ink);
|
|
530
565
|
}
|
|
531
|
-
/* Help for students: a labelled box
|
|
566
|
+
/* Help for students on the page: a compact labelled box at its place, never wider than the page. A graded block
|
|
567
|
+
component's own help is kept, not drawn: its frame's tags say what it has, the card edits it. */
|
|
568
|
+
.astl-surface .astl-block[data-astl-graded] .astl-help-box {
|
|
569
|
+
display: none;
|
|
570
|
+
}
|
|
532
571
|
.astl-surface .astl-help-box {
|
|
533
572
|
box-sizing: border-box;
|
|
534
573
|
max-inline-size: 100%;
|
|
535
574
|
margin-block: var(--astl-space-2);
|
|
536
|
-
padding-block: var(--astl-space-1)
|
|
537
|
-
padding-inline: var(--astl-space-
|
|
575
|
+
padding-block: 0 var(--astl-space-1);
|
|
576
|
+
padding-inline: var(--astl-space-2);
|
|
538
577
|
border: var(--astl-outline-width) dashed var(--astl-outline);
|
|
539
578
|
border-radius: var(--astl-radius-s);
|
|
540
579
|
background: var(--astl-surface-raised);
|
|
@@ -552,13 +591,15 @@ const baseSurfaceStyles: CSSResult = css`
|
|
|
552
591
|
}
|
|
553
592
|
.astl-surface .astl-help-head select {
|
|
554
593
|
box-sizing: border-box;
|
|
555
|
-
min-block-size: var(--astl-
|
|
594
|
+
min-block-size: max(24px, var(--astl-editor-control-size, 1.75rem));
|
|
595
|
+
padding-block: 0;
|
|
556
596
|
padding-inline: var(--astl-space-2);
|
|
557
597
|
border: var(--astl-outline-width) solid var(--astl-outline);
|
|
558
598
|
border-radius: var(--astl-radius-s);
|
|
559
599
|
background: var(--astl-surface);
|
|
560
600
|
color: var(--astl-ink);
|
|
561
601
|
font: inherit;
|
|
602
|
+
font-size: var(--astl-editor-control-font-size, 0.8125rem);
|
|
562
603
|
font-weight: 400;
|
|
563
604
|
cursor: pointer;
|
|
564
605
|
}
|
|
@@ -567,9 +608,13 @@ const baseSurfaceStyles: CSSResult = css`
|
|
|
567
608
|
outline-offset: var(--astl-focus-offset);
|
|
568
609
|
}
|
|
569
610
|
${unsafeCSS(nativeSelectCss('.astl-surface .astl-help-head select'))}
|
|
570
|
-
/* "Remove" closes the head, a page button's look. */
|
|
611
|
+
/* "Remove" closes the head: a cross, a page button's look. */
|
|
571
612
|
.astl-surface .astl-help-remove {
|
|
613
|
+
display: inline-flex;
|
|
614
|
+
align-items: center;
|
|
615
|
+
justify-content: center;
|
|
572
616
|
margin-inline-start: auto;
|
|
617
|
+
padding-inline: 0;
|
|
573
618
|
font-weight: 400;
|
|
574
619
|
}
|
|
575
620
|
/* A page's hint with a cost (an older source): what it costs, and "Make it free". */
|
|
@@ -584,11 +629,53 @@ const baseSurfaceStyles: CSSResult = css`
|
|
|
584
629
|
display: none;
|
|
585
630
|
}
|
|
586
631
|
.astl-surface .astl-help-content > :first-child {
|
|
587
|
-
margin-block-start:
|
|
632
|
+
margin-block-start: 0;
|
|
588
633
|
}
|
|
589
634
|
.astl-surface .astl-help-content > :last-child {
|
|
590
635
|
margin-block-end: 0;
|
|
591
636
|
}
|
|
637
|
+
/* An empty box's line says what to write there. */
|
|
638
|
+
.astl-surface .astl-help-content > .astl-help-empty::before {
|
|
639
|
+
content: attr(data-placeholder);
|
|
640
|
+
float: inline-start;
|
|
641
|
+
block-size: 0;
|
|
642
|
+
color: var(--astl-ink-muted);
|
|
643
|
+
pointer-events: none;
|
|
644
|
+
}
|
|
645
|
+
/* A frame's tags: the help for students its component has, small pills in its tab. Each is a 24px target that keeps
|
|
646
|
+
the tab as high as its line. */
|
|
647
|
+
.astl-surface .astl-frame-help {
|
|
648
|
+
box-sizing: border-box;
|
|
649
|
+
display: inline-flex;
|
|
650
|
+
align-items: center;
|
|
651
|
+
justify-content: center;
|
|
652
|
+
min-block-size: 24px;
|
|
653
|
+
min-inline-size: 24px;
|
|
654
|
+
margin-block: calc((1.3em - 24px) / 2);
|
|
655
|
+
padding: 0;
|
|
656
|
+
border: 0;
|
|
657
|
+
background: none;
|
|
658
|
+
color: inherit;
|
|
659
|
+
font: inherit;
|
|
660
|
+
}
|
|
661
|
+
.astl-surface .astl-frame-help > span {
|
|
662
|
+
padding-inline: 0.45em;
|
|
663
|
+
border: 1px solid currentColor;
|
|
664
|
+
border-radius: var(--astl-radius-pill);
|
|
665
|
+
line-height: 1.3;
|
|
666
|
+
white-space: nowrap;
|
|
667
|
+
}
|
|
668
|
+
.astl-surface button.astl-frame-help {
|
|
669
|
+
cursor: pointer;
|
|
670
|
+
}
|
|
671
|
+
.astl-surface button.astl-frame-help:hover > span {
|
|
672
|
+
background: var(--astl-accent-soft);
|
|
673
|
+
color: var(--astl-ink);
|
|
674
|
+
}
|
|
675
|
+
.astl-surface .astl-frame-help:focus-visible {
|
|
676
|
+
outline: var(--astl-focus-width) solid var(--astl-focus);
|
|
677
|
+
outline-offset: var(--astl-focus-offset);
|
|
678
|
+
}
|
|
592
679
|
.astl-surface .astl-child {
|
|
593
680
|
padding-block: var(--astl-space-1);
|
|
594
681
|
padding-inline-start: var(--astl-space-5);
|
|
@@ -656,17 +743,35 @@ const baseSurfaceStyles: CSSResult = css`
|
|
|
656
743
|
.astl-surface .astl-block-add {
|
|
657
744
|
display: flex;
|
|
658
745
|
flex-wrap: wrap;
|
|
659
|
-
gap: var(--astl-space-
|
|
746
|
+
gap: var(--astl-space-1);
|
|
660
747
|
padding-block-start: var(--astl-space-1);
|
|
661
748
|
}
|
|
662
749
|
.astl-surface .astl-block-add button[hidden],
|
|
663
750
|
.astl-surface .astl-block-add:not(:has(button:not([hidden]))) {
|
|
664
751
|
display: none;
|
|
665
752
|
}
|
|
753
|
+
/* A small text button under the last child, as the page heads' are. */
|
|
666
754
|
.astl-surface .astl-block-add button {
|
|
667
|
-
|
|
668
|
-
|
|
755
|
+
box-sizing: border-box;
|
|
756
|
+
display: inline-flex;
|
|
757
|
+
align-items: center;
|
|
758
|
+
gap: 0.25rem;
|
|
759
|
+
min-block-size: max(24px, var(--astl-editor-control-size, 1.75rem));
|
|
760
|
+
min-inline-size: max(24px, var(--astl-editor-control-size, 1.75rem));
|
|
761
|
+
margin: 0;
|
|
762
|
+
padding-block: 0;
|
|
763
|
+
padding-inline: var(--astl-space-1) var(--astl-space-2);
|
|
764
|
+
border: var(--astl-outline-width) solid transparent;
|
|
765
|
+
border-radius: var(--astl-radius-s);
|
|
766
|
+
background: transparent;
|
|
767
|
+
color: var(--astl-ink-muted);
|
|
768
|
+
font: inherit;
|
|
769
|
+
font-family: var(--astl-font-body);
|
|
770
|
+
font-size: var(--astl-editor-control-font-size, 0.8125rem);
|
|
669
771
|
font-weight: 600;
|
|
772
|
+
line-height: 1.2;
|
|
773
|
+
white-space: nowrap;
|
|
774
|
+
cursor: pointer;
|
|
670
775
|
}
|
|
671
776
|
.astl-surface .astl-block-add button:disabled {
|
|
672
777
|
color: var(--astl-ink-muted);
|
|
@@ -816,28 +921,30 @@ const baseSurfaceStyles: CSSResult = css`
|
|
|
816
921
|
font-size: var(--astl-size-small);
|
|
817
922
|
}
|
|
818
923
|
.astl-surface button.astl-picture-place {
|
|
819
|
-
min-block-size: var(--astl-
|
|
820
|
-
min-inline-size: var(--astl-
|
|
924
|
+
min-block-size: max(24px, var(--astl-editor-control-size, 1.75rem));
|
|
925
|
+
min-inline-size: max(24px, var(--astl-editor-control-size, 1.75rem));
|
|
926
|
+
padding-block: 0;
|
|
821
927
|
padding-inline: var(--astl-space-2);
|
|
822
928
|
border: var(--astl-outline-width) solid var(--astl-outline);
|
|
823
929
|
border-radius: var(--astl-radius-s);
|
|
824
930
|
background: var(--astl-surface);
|
|
825
931
|
color: var(--astl-ink);
|
|
826
932
|
font: inherit;
|
|
827
|
-
font-size: var(--astl-size
|
|
933
|
+
font-size: var(--astl-editor-control-font-size, 0.8125rem);
|
|
828
934
|
cursor: pointer;
|
|
829
935
|
}
|
|
830
936
|
.astl-surface .astl-picture-edit {
|
|
831
937
|
align-self: flex-start;
|
|
832
|
-
min-block-size: var(--astl-
|
|
833
|
-
min-inline-size: var(--astl-
|
|
938
|
+
min-block-size: max(24px, var(--astl-editor-control-size, 1.75rem));
|
|
939
|
+
min-inline-size: max(24px, var(--astl-editor-control-size, 1.75rem));
|
|
940
|
+
padding-block: 0;
|
|
834
941
|
padding-inline: var(--astl-space-2);
|
|
835
942
|
border: var(--astl-outline-width) solid var(--astl-outline);
|
|
836
943
|
border-radius: var(--astl-radius-s);
|
|
837
944
|
background: var(--astl-surface);
|
|
838
945
|
color: var(--astl-ink);
|
|
839
946
|
font: inherit;
|
|
840
|
-
font-size: var(--astl-size
|
|
947
|
+
font-size: var(--astl-editor-control-font-size, 0.8125rem);
|
|
841
948
|
cursor: pointer;
|
|
842
949
|
}
|
|
843
950
|
.astl-surface .astl-figure {
|