@astl/editor-tiptap 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +41 -0
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +46 -23
- package/dist/adapter.js.map +1 -1
- package/dist/blocks.d.ts +5 -3
- package/dist/blocks.d.ts.map +1 -1
- package/dist/blocks.js +6 -4
- package/dist/blocks.js.map +1 -1
- package/dist/element.js +3 -3
- package/dist/element.js.map +1 -1
- package/dist/nodes.d.ts.map +1 -1
- package/dist/nodes.js +256 -6
- package/dist/nodes.js.map +1 -1
- package/dist/source-view.js +2 -2
- package/dist/styles.d.ts.map +1 -1
- package/dist/styles.js +147 -30
- package/dist/styles.js.map +1 -1
- package/package.json +6 -6
- package/src/adapter.ts +59 -25
- package/src/blocks.ts +7 -4
- package/src/element.ts +3 -3
- package/src/nodes.ts +256 -5
- package/src/source-view.ts +2 -2
- package/src/styles.ts +147 -30
package/src/nodes.ts
CHANGED
|
@@ -21,12 +21,19 @@
|
|
|
21
21
|
*/
|
|
22
22
|
import {
|
|
23
23
|
CAPTION_TAG,
|
|
24
|
+
CHECK_FOR_ATTRIBUTE,
|
|
25
|
+
CHECK_LABEL_ATTRIBUTE,
|
|
26
|
+
CHECK_TAG,
|
|
27
|
+
type CheckTree,
|
|
24
28
|
type ChildSpec,
|
|
25
29
|
CLASS_ATTRIBUTE,
|
|
26
30
|
COLUMN_TAG,
|
|
27
31
|
COLUMNS_TAG,
|
|
28
32
|
CONTENT_ATTRIBUTES,
|
|
29
33
|
type ComponentManifest,
|
|
34
|
+
checkFor,
|
|
35
|
+
checkNodes,
|
|
36
|
+
checkParts,
|
|
30
37
|
childTagConflict,
|
|
31
38
|
directionOf,
|
|
32
39
|
type EditorDescriptor,
|
|
@@ -39,11 +46,13 @@ import {
|
|
|
39
46
|
HINT_TAG,
|
|
40
47
|
INERT_STYLE,
|
|
41
48
|
inertStyles,
|
|
49
|
+
isCheckable,
|
|
42
50
|
isSourceId,
|
|
43
51
|
MAX_COLUMNS,
|
|
44
52
|
type MessageParams,
|
|
45
53
|
MIN_COLUMNS,
|
|
46
54
|
PAGE_CHECK_ATTRIBUTE,
|
|
55
|
+
planChecks,
|
|
47
56
|
TAG_ATTRIBUTES,
|
|
48
57
|
} from '@astl/core';
|
|
49
58
|
import { cleanClass, cleanStyle, isStyleName } from '@astl/core/declarations';
|
|
@@ -81,10 +90,11 @@ import {
|
|
|
81
90
|
TextSelection,
|
|
82
91
|
type Transaction,
|
|
83
92
|
} from '@tiptap/pm/state';
|
|
84
|
-
import { Decoration, DecorationSet } from '@tiptap/pm/view';
|
|
93
|
+
import { Decoration, DecorationSet, type EditorView } from '@tiptap/pm/view';
|
|
85
94
|
import { StarterKit } from '@tiptap/starter-kit';
|
|
86
95
|
import {
|
|
87
96
|
blocksExtension,
|
|
97
|
+
CHECK_NODE,
|
|
88
98
|
historyKey,
|
|
89
99
|
LAYOUT,
|
|
90
100
|
LAYOUT_COLUMN,
|
|
@@ -945,6 +955,243 @@ function helpPlaceholderExtension(authoring: Authoring): Extension {
|
|
|
945
955
|
});
|
|
946
956
|
}
|
|
947
957
|
|
|
958
|
+
/** The group of `<astl-check>`: directly on a page or in a column, never in text or in a component. */
|
|
959
|
+
const CHECK = 'check';
|
|
960
|
+
|
|
961
|
+
/** The decoration spec key a Check element's view reads how many questions it checks from (`checksExtension`). */
|
|
962
|
+
const CHECK_COUNT = 'astlCheckCount';
|
|
963
|
+
|
|
964
|
+
/** The class of the questions the selected Check element checks. */
|
|
965
|
+
const CHECK_TARGET = 'astl-check-target';
|
|
966
|
+
|
|
967
|
+
/** A Check element's count among its view's decorations, or null before the plugin has given it. */
|
|
968
|
+
const countIn = (decorations: readonly { spec: Record<string, unknown> }[]): number | null => {
|
|
969
|
+
for (const decoration of decorations) {
|
|
970
|
+
const count = decoration.spec[CHECK_COUNT];
|
|
971
|
+
if (typeof count === 'number') return count;
|
|
972
|
+
}
|
|
973
|
+
return null;
|
|
974
|
+
};
|
|
975
|
+
|
|
976
|
+
/**
|
|
977
|
+
* `<astl-check>`, a Check for several questions: a block atom kept as data, drawn as the compact button it puts in the
|
|
978
|
+
* player (`astl-check-button`: its `label`, else "Check") with a tag saying how many questions it checks
|
|
979
|
+
* (`astl-check-tag`: "3 questions"; without any, "No questions" and `data-empty` on `astl-check`). Its card ticks them.
|
|
980
|
+
*/
|
|
981
|
+
function checkNode(authoring: Authoring): Node {
|
|
982
|
+
const t = (key: string, params?: MessageParams) => authoring.t(EDITOR_NAMESPACE, key, params);
|
|
983
|
+
const ui = { lang: authoring.locale, dir: directionOf(authoring.locale) };
|
|
984
|
+
return Node.create({
|
|
985
|
+
name: CHECK_NODE,
|
|
986
|
+
group: CHECK,
|
|
987
|
+
atom: true,
|
|
988
|
+
selectable: true,
|
|
989
|
+
addAttributes: () => sourceAttributes,
|
|
990
|
+
parseHTML: () => [{ tag: CHECK_TAG }],
|
|
991
|
+
renderHTML: ({ node }) => [CHECK_TAG, { ...node.attrs.attributes }],
|
|
992
|
+
addNodeView:
|
|
993
|
+
() =>
|
|
994
|
+
({ node, decorations }) => {
|
|
995
|
+
const dom = document.createElement('div');
|
|
996
|
+
dom.className = 'astl-check';
|
|
997
|
+
const button = dom.appendChild(document.createElement('span'));
|
|
998
|
+
button.className = 'astl-check-button';
|
|
999
|
+
button.append(lineIcon('check', 'astl-icon'));
|
|
1000
|
+
const label = button.appendChild(document.createElement('span'));
|
|
1001
|
+
const tag = dom.appendChild(Object.assign(document.createElement('span'), ui));
|
|
1002
|
+
tag.className = 'astl-check-tag';
|
|
1003
|
+
const render = (attrs: Record<string, unknown>, count: number | null) => {
|
|
1004
|
+
const own = ((attrs.attributes as Attributes)[CHECK_LABEL_ATTRIBUTE] ?? '').trim();
|
|
1005
|
+
label.textContent = own === '' ? t('check.button') : own;
|
|
1006
|
+
// The default words are the editor's, the author's the exercise's.
|
|
1007
|
+
if (own === '') Object.assign(label, ui);
|
|
1008
|
+
else {
|
|
1009
|
+
label.removeAttribute('lang');
|
|
1010
|
+
label.removeAttribute('dir');
|
|
1011
|
+
}
|
|
1012
|
+
tag.textContent =
|
|
1013
|
+
count === null ? '' : count === 0 ? t('check.none') : t('check.count', { n: count });
|
|
1014
|
+
dom.toggleAttribute('data-empty', count === 0);
|
|
1015
|
+
};
|
|
1016
|
+
render(node.attrs, countIn(decorations));
|
|
1017
|
+
return {
|
|
1018
|
+
dom,
|
|
1019
|
+
update: (next: NodeLike, nextDecorations: readonly { spec: Record<string, unknown> }[]) => {
|
|
1020
|
+
if (next.type.name !== CHECK_NODE) return false;
|
|
1021
|
+
render(next.attrs, countIn(nextDecorations));
|
|
1022
|
+
return true;
|
|
1023
|
+
},
|
|
1024
|
+
ignoreMutation: () => true,
|
|
1025
|
+
};
|
|
1026
|
+
},
|
|
1027
|
+
});
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
/**
|
|
1031
|
+
* Each Check element's questions, by the rule the engine and the player use (`planChecks`) over the editor's nodes: its
|
|
1032
|
+
* view says how many (a node decoration's spec), and while it is selected its questions are marked (`astl-check-target`
|
|
1033
|
+
* on each), inline ones and blocks alike. Where two or more questions of a run of text have none, the automatic Check
|
|
1034
|
+
* the player puts there shows after the block of the last of them (`astl-check astl-check-auto`: "automatic · 3
|
|
1035
|
+
* questions"), with "Make it a button" (`astl-check-make`), which writes a Check element for them in its place.
|
|
1036
|
+
*/
|
|
1037
|
+
function checksExtension(authoring: Authoring, manifests: readonly ComponentManifest[]): Extension {
|
|
1038
|
+
const t = (key: string, params?: MessageParams) => authoring.t(EDITOR_NAMESPACE, key, params);
|
|
1039
|
+
const ui = { lang: authoring.locale, dir: directionOf(authoring.locale) };
|
|
1040
|
+
const types = new Map(manifests.map((m) => [nodeName(m.tag), m]));
|
|
1041
|
+
const idOf = (node: PMNode): string | null => (node.attrs.attributes as Attributes | undefined)?.id || null;
|
|
1042
|
+
const childrenOf = (node: PMNode): PMNode[] => {
|
|
1043
|
+
const out: PMNode[] = [];
|
|
1044
|
+
node.forEach((child) => {
|
|
1045
|
+
out.push(child);
|
|
1046
|
+
});
|
|
1047
|
+
return out;
|
|
1048
|
+
};
|
|
1049
|
+
/** The positions of the Check elements directly in `node` and in its layouts' columns, as `checkNodes` meets them. */
|
|
1050
|
+
const checkPositions = (node: PMNode, start: number): number[] => {
|
|
1051
|
+
const out: number[] = [];
|
|
1052
|
+
node.forEach((child, offset) => {
|
|
1053
|
+
const pos = start + offset;
|
|
1054
|
+
if (child.type.name === CHECK_NODE) out.push(pos);
|
|
1055
|
+
else if (child.type.name === LAYOUT) {
|
|
1056
|
+
child.forEach((column, at) => {
|
|
1057
|
+
if (column.type.name === LAYOUT_COLUMN) out.push(...checkPositions(column, pos + 1 + at + 1));
|
|
1058
|
+
});
|
|
1059
|
+
}
|
|
1060
|
+
});
|
|
1061
|
+
return out;
|
|
1062
|
+
};
|
|
1063
|
+
/** A Check element for `run` at `pos` (after the block of its last question), selected, as one undo step. */
|
|
1064
|
+
const make = (view: EditorView, pos: number, run: readonly string[]): void => {
|
|
1065
|
+
const type = view.state.schema.nodes[CHECK_NODE];
|
|
1066
|
+
if (type === undefined) return;
|
|
1067
|
+
const used = idsIn(view.state.doc);
|
|
1068
|
+
let n = 1;
|
|
1069
|
+
while (used.has(`check-${n}`)) n++;
|
|
1070
|
+
const node = type.create({ attributes: { id: `check-${n}`, [CHECK_FOR_ATTRIBUTE]: run.join(' ') } });
|
|
1071
|
+
const tr = closeHistory(view.state.tr).insert(pos, node);
|
|
1072
|
+
view.dispatch(tr.setSelection(NodeSelection.create(tr.doc, pos)).scrollIntoView());
|
|
1073
|
+
view.focus();
|
|
1074
|
+
};
|
|
1075
|
+
/** The automatic Check of `run`: the button it is, its tag, and "Make it a button". */
|
|
1076
|
+
const automaticDom = (view: EditorView, run: readonly string[], getPos: () => number | undefined) => {
|
|
1077
|
+
const dom = Object.assign(document.createElement('div'), ui);
|
|
1078
|
+
dom.className = 'astl-check astl-check-auto';
|
|
1079
|
+
dom.contentEditable = 'false';
|
|
1080
|
+
const button = dom.appendChild(document.createElement('span'));
|
|
1081
|
+
button.className = 'astl-check-button';
|
|
1082
|
+
button.append(lineIcon('check', 'astl-icon'));
|
|
1083
|
+
button.appendChild(document.createElement('span')).textContent = t('check.button');
|
|
1084
|
+
const tag = dom.appendChild(document.createElement('span'));
|
|
1085
|
+
tag.className = 'astl-check-tag';
|
|
1086
|
+
tag.textContent = t('check.auto', { n: run.length });
|
|
1087
|
+
const press = dom.appendChild(document.createElement('button'));
|
|
1088
|
+
Object.assign(press, { type: 'button', tabIndex: -1, title: t('check.makeHelp') });
|
|
1089
|
+
press.className = 'astl-check-make';
|
|
1090
|
+
press.textContent = t('check.make');
|
|
1091
|
+
press.addEventListener('click', (event) => {
|
|
1092
|
+
event.preventDefault();
|
|
1093
|
+
const pos = getPos();
|
|
1094
|
+
if (pos !== undefined) make(view, pos, run);
|
|
1095
|
+
});
|
|
1096
|
+
return dom;
|
|
1097
|
+
};
|
|
1098
|
+
const decorate = (state: EditorState): DecorationSet => {
|
|
1099
|
+
const { doc, selection } = state;
|
|
1100
|
+
const selected =
|
|
1101
|
+
selection instanceof NodeSelection && selection.node.type.name === CHECK_NODE ? selection.from : null;
|
|
1102
|
+
const decorations: Decoration[] = [];
|
|
1103
|
+
const containers: { node: PMNode; start: number }[] = [];
|
|
1104
|
+
if (doc.firstChild?.type.name === PAGE) {
|
|
1105
|
+
doc.forEach((page, offset) => {
|
|
1106
|
+
containers.push({ node: page, start: offset + 1 });
|
|
1107
|
+
});
|
|
1108
|
+
} else containers.push({ node: doc, start: 0 });
|
|
1109
|
+
for (const container of containers) {
|
|
1110
|
+
// The page's graded questions by id, where they are.
|
|
1111
|
+
const questions = new Map<string, { readonly pos: number; readonly node: PMNode }>();
|
|
1112
|
+
container.node.descendants((node, offset) => {
|
|
1113
|
+
const manifest = types.get(node.type.name);
|
|
1114
|
+
if (manifest === undefined) return true;
|
|
1115
|
+
const id = idOf(node);
|
|
1116
|
+
if (isCheckable(manifest) && id !== null) questions.set(id, { pos: container.start + offset, node });
|
|
1117
|
+
return false;
|
|
1118
|
+
});
|
|
1119
|
+
const tree: CheckTree<PMNode> = {
|
|
1120
|
+
tag: (node) => {
|
|
1121
|
+
const name = node.type.name;
|
|
1122
|
+
if (node.isText) return null;
|
|
1123
|
+
if (name === CHECK_NODE) return CHECK_TAG;
|
|
1124
|
+
if (name === LAYOUT) return COLUMNS_TAG;
|
|
1125
|
+
if (name === LAYOUT_COLUMN) return COLUMN_TAG;
|
|
1126
|
+
return name === 'heading' ? `h${node.attrs.level as number}` : name;
|
|
1127
|
+
},
|
|
1128
|
+
children: childrenOf,
|
|
1129
|
+
component: (node) => {
|
|
1130
|
+
const manifest = types.get(node.type.name);
|
|
1131
|
+
if (manifest === undefined) return null;
|
|
1132
|
+
return { id: idOf(node), graded: isCheckable(manifest), block: manifest.display === 'block' };
|
|
1133
|
+
},
|
|
1134
|
+
checkFor: (node) => {
|
|
1135
|
+
const attributes = node.attrs.attributes as Attributes;
|
|
1136
|
+
return Object.hasOwn(attributes, CHECK_FOR_ATTRIBUTE)
|
|
1137
|
+
? checkFor(attributes[CHECK_FOR_ATTRIBUTE]).filter((id) => questions.has(id))
|
|
1138
|
+
: null;
|
|
1139
|
+
},
|
|
1140
|
+
};
|
|
1141
|
+
const content = childrenOf(container.node);
|
|
1142
|
+
const { targets, uncovered } = planChecks(checkParts(content, tree));
|
|
1143
|
+
const positions = checkPositions(container.node, container.start);
|
|
1144
|
+
checkNodes(content, tree).forEach((check, k) => {
|
|
1145
|
+
const pos = positions[k];
|
|
1146
|
+
if (pos === undefined) return;
|
|
1147
|
+
const own = targets[k] ?? [];
|
|
1148
|
+
decorations.push(Decoration.node(pos, pos + check.nodeSize, {}, { [CHECK_COUNT]: own.length }));
|
|
1149
|
+
if (pos !== selected) return;
|
|
1150
|
+
for (const id of own) {
|
|
1151
|
+
const question = questions.get(id);
|
|
1152
|
+
if (question !== undefined)
|
|
1153
|
+
decorations.push(
|
|
1154
|
+
Decoration.node(question.pos, question.pos + question.node.nodeSize, { class: CHECK_TARGET }),
|
|
1155
|
+
);
|
|
1156
|
+
}
|
|
1157
|
+
});
|
|
1158
|
+
// After the block, directly in the page or its column, that holds the last question of the run.
|
|
1159
|
+
for (const run of uncovered) {
|
|
1160
|
+
const last = questions.get(run.at(-1) ?? '');
|
|
1161
|
+
if (run.length < 2 || last === undefined) continue;
|
|
1162
|
+
const $last = doc.resolve(last.pos);
|
|
1163
|
+
let depth = $last.depth;
|
|
1164
|
+
while (depth > 0 && ![PAGE, LAYOUT_COLUMN].includes($last.node(depth).type.name)) depth--;
|
|
1165
|
+
const at = $last.after(depth + 1);
|
|
1166
|
+
decorations.push(
|
|
1167
|
+
// Before the tab and the notes of a block framed right there (sides -2 and -1): it ends the run above.
|
|
1168
|
+
Decoration.widget(at, (view, getPos) => automaticDom(view, run, getPos), {
|
|
1169
|
+
key: `auto\n${run.join(' ')}`,
|
|
1170
|
+
side: -3,
|
|
1171
|
+
stopEvent: () => true,
|
|
1172
|
+
ignoreSelection: true,
|
|
1173
|
+
}),
|
|
1174
|
+
);
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
return DecorationSet.create(doc, decorations);
|
|
1178
|
+
};
|
|
1179
|
+
const key = new PluginKey<DecorationSet>('astlChecks');
|
|
1180
|
+
return Extension.create({
|
|
1181
|
+
name: 'astlChecks',
|
|
1182
|
+
addProseMirrorPlugins: () => [
|
|
1183
|
+
new Plugin<DecorationSet>({
|
|
1184
|
+
key,
|
|
1185
|
+
state: {
|
|
1186
|
+
init: (_, state) => decorate(state),
|
|
1187
|
+
apply: (tr, previous, _, state) => (tr.docChanged || tr.selectionSet ? decorate(state) : previous),
|
|
1188
|
+
},
|
|
1189
|
+
props: { decorations: (state) => key.getState(state) },
|
|
1190
|
+
}),
|
|
1191
|
+
],
|
|
1192
|
+
});
|
|
1193
|
+
}
|
|
1194
|
+
|
|
948
1195
|
/**
|
|
949
1196
|
* A block with rich children, or with rich content (`content: 'flow'`), framed and labelled in the editor, with its
|
|
950
1197
|
* picture when it has picture fields.
|
|
@@ -1811,8 +2058,8 @@ function figureNode(authoring: Authoring, hooks: PictureHooks | undefined): Node
|
|
|
1811
2058
|
/** The node name of `<astl-page>`. */
|
|
1812
2059
|
const PAGE = 'astlPage';
|
|
1813
2060
|
|
|
1814
|
-
/** What a page or a document without pages holds: blocks and
|
|
1815
|
-
const PAGE_CONTENT = `(block | ${LAYOUT} | ${HELP})+`;
|
|
2061
|
+
/** What a page or a document without pages holds: blocks, layouts, help for students and Check elements. */
|
|
2062
|
+
const PAGE_CONTENT = `(block | ${LAYOUT} | ${HELP} | ${CHECK})+`;
|
|
1816
2063
|
|
|
1817
2064
|
/**
|
|
1818
2065
|
* A layout: `<astl-columns>` with its `<astl-column>`s, under their real tags (nothing in them asks for a node view).
|
|
@@ -1848,7 +2095,7 @@ const layoutNodes: readonly Node[] = [
|
|
|
1848
2095
|
}),
|
|
1849
2096
|
Node.create({
|
|
1850
2097
|
name: LAYOUT_COLUMN,
|
|
1851
|
-
content:
|
|
2098
|
+
content: `(block | ${CHECK})+`,
|
|
1852
2099
|
isolating: true,
|
|
1853
2100
|
selectable: false,
|
|
1854
2101
|
addAttributes: () => sourceAttributes,
|
|
@@ -1933,6 +2180,7 @@ export function pageNode(authoring: Authoring): Node {
|
|
|
1933
2180
|
return button;
|
|
1934
2181
|
};
|
|
1935
2182
|
const addTitle = named('add-title', t('surface.pageAddTitle'));
|
|
2183
|
+
addTitle.prepend(lineIcon('add', 'astl-icon'));
|
|
1936
2184
|
// "Check this page", pressed while the page has `check`: its own Check in practice, then its help.
|
|
1937
2185
|
const check = named('check', t('surface.pageCheck'));
|
|
1938
2186
|
// Hidden until numbered: the first page has no join button, the only page no delete button.
|
|
@@ -2761,7 +3009,8 @@ function pastedIdsExtension(
|
|
|
2761
3009
|
manifests: readonly ComponentManifest[],
|
|
2762
3010
|
hooks: PictureHooks | undefined,
|
|
2763
3011
|
): Extension {
|
|
2764
|
-
|
|
3012
|
+
// Check elements share the namespace: a pasted one whose id is taken gets `check-<n>`.
|
|
3013
|
+
const tags = new Map([...manifests.map((m) => [nodeName(m.tag), m.tag] as const), [CHECK_NODE, CHECK_TAG]]);
|
|
2765
3014
|
const prefixOf = (name: string): string => {
|
|
2766
3015
|
const tag = tags.get(name);
|
|
2767
3016
|
if (tag === undefined) return 'page';
|
|
@@ -3170,6 +3419,8 @@ export function astrolabeExtensions(
|
|
|
3170
3419
|
currentFigureExtension,
|
|
3171
3420
|
...componentNodes(manifests, label, zonesView(authoring), authoring),
|
|
3172
3421
|
...helpNodes(authoring),
|
|
3422
|
+
checkNode(authoring),
|
|
3423
|
+
checksExtension(authoring, manifests),
|
|
3173
3424
|
referencesExtension(authoring, manifests),
|
|
3174
3425
|
childrenExtension(manifests),
|
|
3175
3426
|
richBlocksExtension(authoring, manifests),
|
package/src/source-view.ts
CHANGED
|
@@ -101,8 +101,8 @@ const sourceStyles = css`
|
|
|
101
101
|
font: var(--astl-size-small) / 1.5 var(--astl-font-mono);
|
|
102
102
|
}
|
|
103
103
|
.source textarea:focus-visible {
|
|
104
|
-
outline: var(--astl-focus-width) solid var(--astl-focus);
|
|
105
|
-
outline-offset: var(--astl-focus-offset);
|
|
104
|
+
outline: var(--astl-editor-focus-width, 2px) solid var(--astl-focus);
|
|
105
|
+
outline-offset: var(--astl-editor-focus-offset, 1px);
|
|
106
106
|
}
|
|
107
107
|
`;
|
|
108
108
|
|
package/src/styles.ts
CHANGED
|
@@ -33,8 +33,8 @@ const baseSurfaceStyles: CSSResult = css`
|
|
|
33
33
|
}
|
|
34
34
|
/* A host with a focus cue of its own (the frame with the cursor) may set the sheet's ring to a quieter one. */
|
|
35
35
|
.astl-surface .tiptap:focus-visible {
|
|
36
|
-
outline: var(--astl-editor-sheet-focus-ring, var(--astl-focus-width) solid var(--astl-focus));
|
|
37
|
-
outline-offset: var(--astl-focus-offset);
|
|
36
|
+
outline: var(--astl-editor-sheet-focus-ring, var(--astl-editor-focus-width, 2px) solid var(--astl-focus));
|
|
37
|
+
outline-offset: var(--astl-editor-focus-offset, 1px);
|
|
38
38
|
}
|
|
39
39
|
.astl-surface .astl-vh {
|
|
40
40
|
position: absolute;
|
|
@@ -131,10 +131,13 @@ const baseSurfaceStyles: CSSResult = css`
|
|
|
131
131
|
padding-block-start: var(--astl-space-4);
|
|
132
132
|
border-block-start: var(--astl-outline-width) solid var(--astl-line);
|
|
133
133
|
}
|
|
134
|
+
/* A page head: its number, then its buttons at the end; in a narrow column a button that wraps stays at the end, under
|
|
135
|
+
the others, not under the number. */
|
|
134
136
|
.astl-surface .astl-page-head {
|
|
135
137
|
display: flex;
|
|
136
138
|
flex-wrap: wrap;
|
|
137
139
|
align-items: center;
|
|
140
|
+
justify-content: flex-end;
|
|
138
141
|
gap: var(--astl-space-2);
|
|
139
142
|
margin-block: 0 var(--astl-space-3);
|
|
140
143
|
}
|
|
@@ -183,13 +186,15 @@ const baseSurfaceStyles: CSSResult = css`
|
|
|
183
186
|
.astl-help-remove,
|
|
184
187
|
.astl-help-free
|
|
185
188
|
):focus-visible {
|
|
186
|
-
outline: var(--astl-focus-width) solid var(--astl-focus);
|
|
187
|
-
outline-offset: var(--astl-focus-offset);
|
|
189
|
+
outline: var(--astl-editor-focus-width, 2px) solid var(--astl-focus);
|
|
190
|
+
outline-offset: var(--astl-editor-focus-offset, 1px);
|
|
188
191
|
}
|
|
189
192
|
/* 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,
|
|
191
|
-
|
|
192
|
-
and
|
|
193
|
+
position line, a picture's buttons) are compact, so that the exercise looks as students see it, and each is
|
|
194
|
+
recognisable as a button at rest: a text button has a hairline in the outline colour (3:1 at least), an add action
|
|
195
|
+
a plus and the accent colour, an icon alone (a page box's cross) only its icon. A host sizes them with
|
|
196
|
+
--astl-editor-control-size (their height, 1.75rem), --astl-editor-control-font-size (0.8125rem) and
|
|
197
|
+
--astl-editor-control-icon-size (0.875rem); a target stays at least 24px (WCAG 2.5.8). */
|
|
193
198
|
.astl-surface
|
|
194
199
|
:is(
|
|
195
200
|
.astl-page-join,
|
|
@@ -198,7 +203,8 @@ const baseSurfaceStyles: CSSResult = css`
|
|
|
198
203
|
.astl-page-remove-title,
|
|
199
204
|
.astl-page-check,
|
|
200
205
|
.astl-help-remove,
|
|
201
|
-
.astl-help-free
|
|
206
|
+
.astl-help-free,
|
|
207
|
+
.astl-check-make
|
|
202
208
|
) {
|
|
203
209
|
box-sizing: border-box;
|
|
204
210
|
display: inline-flex;
|
|
@@ -209,7 +215,7 @@ const baseSurfaceStyles: CSSResult = css`
|
|
|
209
215
|
min-inline-size: max(24px, var(--astl-editor-control-size, 1.75rem));
|
|
210
216
|
padding-block: 0;
|
|
211
217
|
padding-inline: var(--astl-space-2);
|
|
212
|
-
border: var(--astl-outline
|
|
218
|
+
border: 1px solid var(--astl-outline);
|
|
213
219
|
border-radius: var(--astl-radius-s);
|
|
214
220
|
background: transparent;
|
|
215
221
|
color: var(--astl-ink-muted);
|
|
@@ -221,6 +227,14 @@ const baseSurfaceStyles: CSSResult = css`
|
|
|
221
227
|
white-space: nowrap;
|
|
222
228
|
cursor: pointer;
|
|
223
229
|
}
|
|
230
|
+
.astl-surface .astl-help-remove {
|
|
231
|
+
border-color: transparent;
|
|
232
|
+
}
|
|
233
|
+
.astl-surface .astl-page-add-title {
|
|
234
|
+
padding-inline-start: var(--astl-space-1);
|
|
235
|
+
border-color: transparent;
|
|
236
|
+
color: var(--astl-accent);
|
|
237
|
+
}
|
|
224
238
|
.astl-surface
|
|
225
239
|
:is(
|
|
226
240
|
.astl-page-join,
|
|
@@ -229,12 +243,13 @@ const baseSurfaceStyles: CSSResult = css`
|
|
|
229
243
|
.astl-page-remove-title,
|
|
230
244
|
.astl-page-check,
|
|
231
245
|
.astl-help-remove,
|
|
232
|
-
.astl-help-free
|
|
246
|
+
.astl-help-free,
|
|
247
|
+
.astl-check-make
|
|
233
248
|
):hover {
|
|
234
249
|
background: var(--astl-accent-soft);
|
|
235
250
|
color: var(--astl-ink);
|
|
236
251
|
}
|
|
237
|
-
.astl-surface :is(.astl-help-remove, .astl-block-add button) .astl-icon {
|
|
252
|
+
.astl-surface :is(.astl-help-remove, .astl-block-add button, .astl-page-add-title) .astl-icon {
|
|
238
253
|
inline-size: var(--astl-editor-control-icon-size, 0.875rem);
|
|
239
254
|
block-size: var(--astl-editor-control-icon-size, 0.875rem);
|
|
240
255
|
}
|
|
@@ -310,6 +325,102 @@ const baseSurfaceStyles: CSSResult = css`
|
|
|
310
325
|
color: var(--astl-danger);
|
|
311
326
|
}
|
|
312
327
|
|
|
328
|
+
/* A Check element (astl-check): the compact button it puts in the player, the accent's outline, then a tag saying how
|
|
329
|
+
many questions it checks; without any, the tag says so, dashed in the warning colour: never by colour alone. While
|
|
330
|
+
it is selected, the questions it checks have a dashed accent outline (astl-check-target), apart from the solid
|
|
331
|
+
focus ring. */
|
|
332
|
+
.astl-surface .astl-check {
|
|
333
|
+
box-sizing: border-box;
|
|
334
|
+
display: flex;
|
|
335
|
+
flex-wrap: wrap;
|
|
336
|
+
align-items: center;
|
|
337
|
+
gap: var(--astl-space-2);
|
|
338
|
+
inline-size: fit-content;
|
|
339
|
+
max-inline-size: 100%;
|
|
340
|
+
margin-block: var(--astl-space-2);
|
|
341
|
+
border-radius: var(--astl-radius-s);
|
|
342
|
+
font-family: var(--astl-font-body);
|
|
343
|
+
cursor: pointer;
|
|
344
|
+
}
|
|
345
|
+
.astl-surface .astl-check-button {
|
|
346
|
+
box-sizing: border-box;
|
|
347
|
+
display: inline-flex;
|
|
348
|
+
align-items: center;
|
|
349
|
+
gap: 0.25rem;
|
|
350
|
+
min-block-size: max(24px, var(--astl-editor-control-size, 1.75rem));
|
|
351
|
+
max-inline-size: 100%;
|
|
352
|
+
padding-inline: var(--astl-space-3);
|
|
353
|
+
border: var(--astl-outline-width) solid var(--astl-accent);
|
|
354
|
+
border-radius: var(--astl-radius-s);
|
|
355
|
+
background: var(--astl-surface);
|
|
356
|
+
color: var(--astl-ink);
|
|
357
|
+
font-size: var(--astl-editor-control-font-size, 0.8125rem);
|
|
358
|
+
font-weight: 600;
|
|
359
|
+
line-height: 1.2;
|
|
360
|
+
overflow-wrap: anywhere;
|
|
361
|
+
}
|
|
362
|
+
.astl-surface .astl-check-button .astl-icon {
|
|
363
|
+
flex: none;
|
|
364
|
+
inline-size: var(--astl-editor-control-icon-size, 0.875rem);
|
|
365
|
+
block-size: var(--astl-editor-control-icon-size, 0.875rem);
|
|
366
|
+
fill: none;
|
|
367
|
+
stroke: var(--astl-accent);
|
|
368
|
+
stroke-width: 2.2;
|
|
369
|
+
stroke-linecap: round;
|
|
370
|
+
stroke-linejoin: round;
|
|
371
|
+
}
|
|
372
|
+
.astl-surface .astl-check-tag {
|
|
373
|
+
padding-inline: 0.5em;
|
|
374
|
+
border: 1px solid transparent;
|
|
375
|
+
border-radius: var(--astl-radius-pill);
|
|
376
|
+
background: var(--astl-accent-soft);
|
|
377
|
+
color: var(--astl-ink);
|
|
378
|
+
font-size: var(--astl-size-small);
|
|
379
|
+
font-weight: 600;
|
|
380
|
+
line-height: 1.4;
|
|
381
|
+
}
|
|
382
|
+
.astl-surface .astl-check-tag:empty {
|
|
383
|
+
display: none;
|
|
384
|
+
}
|
|
385
|
+
.astl-surface .astl-check[data-empty] .astl-check-tag {
|
|
386
|
+
border-style: dashed;
|
|
387
|
+
border-color: var(--astl-warning);
|
|
388
|
+
background: var(--astl-warning-soft);
|
|
389
|
+
}
|
|
390
|
+
.astl-surface .astl-check-target {
|
|
391
|
+
outline: var(--astl-editor-focus-width, 2px) dashed var(--astl-accent);
|
|
392
|
+
outline-offset: 2px;
|
|
393
|
+
}
|
|
394
|
+
/* A chip sits in running text: its outline hugs it, never over the words beside it. */
|
|
395
|
+
.astl-surface .astl-chip.astl-check-target {
|
|
396
|
+
outline-offset: 0;
|
|
397
|
+
}
|
|
398
|
+
/* An automatic Check is the player's, not the exercise's: in a dashed box, its button dashed and muted, with "Make it
|
|
399
|
+
a button" after its tag. */
|
|
400
|
+
.astl-surface .astl-check-auto {
|
|
401
|
+
padding-block: var(--astl-space-1);
|
|
402
|
+
padding-inline: var(--astl-space-2);
|
|
403
|
+
border: 1px dashed var(--astl-outline);
|
|
404
|
+
cursor: default;
|
|
405
|
+
}
|
|
406
|
+
.astl-surface .astl-check-auto .astl-check-button {
|
|
407
|
+
border-style: dashed;
|
|
408
|
+
border-color: var(--astl-outline);
|
|
409
|
+
color: var(--astl-ink-muted);
|
|
410
|
+
}
|
|
411
|
+
.astl-surface .astl-check-make:focus-visible {
|
|
412
|
+
outline: var(--astl-editor-focus-width, 2px) solid var(--astl-focus);
|
|
413
|
+
outline-offset: var(--astl-editor-focus-offset, 1px);
|
|
414
|
+
}
|
|
415
|
+
@media (forced-colors: active) {
|
|
416
|
+
.astl-surface .astl-check-target {
|
|
417
|
+
outline-color: Highlight;
|
|
418
|
+
}
|
|
419
|
+
.astl-surface .astl-check-button .astl-icon {
|
|
420
|
+
stroke: CanvasText;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
313
424
|
/* The page is one flowing text; a block component on it is framed, with a label tab at the frame's top start (its
|
|
314
425
|
type's icon, its label, a summary). The tab sits on the frame's top border, covering it. The frame with the cursor
|
|
315
426
|
is the accent, its tab filled; one with an error or a warning is dashed in that colour and says its issues under
|
|
@@ -468,8 +579,8 @@ const baseSurfaceStyles: CSSResult = css`
|
|
|
468
579
|
}
|
|
469
580
|
.astl-surface .astl-block-add :focus-visible,
|
|
470
581
|
.astl-surface .astl-flag:focus-visible {
|
|
471
|
-
outline: var(--astl-focus-width) solid var(--astl-focus);
|
|
472
|
-
outline-offset: var(--astl-focus-offset);
|
|
582
|
+
outline: var(--astl-editor-focus-width, 2px) solid var(--astl-focus);
|
|
583
|
+
outline-offset: var(--astl-editor-focus-offset, 1px);
|
|
473
584
|
}
|
|
474
585
|
.astl-surface .astl-icon {
|
|
475
586
|
flex: none;
|
|
@@ -531,7 +642,7 @@ const baseSurfaceStyles: CSSResult = css`
|
|
|
531
642
|
margin-inline-start: auto;
|
|
532
643
|
padding-block: 0;
|
|
533
644
|
padding-inline: var(--astl-space-2);
|
|
534
|
-
border:
|
|
645
|
+
border: 1px solid transparent;
|
|
535
646
|
border-radius: var(--astl-radius-s);
|
|
536
647
|
background: transparent;
|
|
537
648
|
color: var(--astl-ink-muted);
|
|
@@ -546,16 +657,19 @@ const baseSurfaceStyles: CSSResult = css`
|
|
|
546
657
|
.astl-surface .astl-frame-head-current > .astl-frame-line {
|
|
547
658
|
visibility: visible;
|
|
548
659
|
}
|
|
660
|
+
/* As a button it opens the component's style form: outlined, with the selects' chevron. */
|
|
549
661
|
.astl-surface button.astl-frame-line {
|
|
662
|
+
border-color: var(--astl-outline);
|
|
550
663
|
cursor: pointer;
|
|
551
664
|
}
|
|
665
|
+
${unsafeCSS(nativeSelectCss('.astl-surface button.astl-frame-line'))}
|
|
552
666
|
.astl-surface button.astl-frame-line:hover {
|
|
553
|
-
background: var(--astl-accent-soft);
|
|
667
|
+
background-color: var(--astl-accent-soft);
|
|
554
668
|
color: var(--astl-ink);
|
|
555
669
|
}
|
|
556
670
|
.astl-surface .astl-frame-line:focus-visible {
|
|
557
|
-
outline: var(--astl-focus-width) solid var(--astl-focus);
|
|
558
|
-
outline-offset: var(--astl-focus-offset);
|
|
671
|
+
outline: var(--astl-editor-focus-width, 2px) solid var(--astl-focus);
|
|
672
|
+
outline-offset: var(--astl-editor-focus-offset, 1px);
|
|
559
673
|
}
|
|
560
674
|
.astl-surface .astl-block.astl-atom {
|
|
561
675
|
cursor: pointer;
|
|
@@ -594,7 +708,7 @@ const baseSurfaceStyles: CSSResult = css`
|
|
|
594
708
|
min-block-size: max(24px, var(--astl-editor-control-size, 1.75rem));
|
|
595
709
|
padding-block: 0;
|
|
596
710
|
padding-inline: var(--astl-space-2);
|
|
597
|
-
border:
|
|
711
|
+
border: 1px solid var(--astl-outline);
|
|
598
712
|
border-radius: var(--astl-radius-s);
|
|
599
713
|
background: var(--astl-surface);
|
|
600
714
|
color: var(--astl-ink);
|
|
@@ -604,8 +718,8 @@ const baseSurfaceStyles: CSSResult = css`
|
|
|
604
718
|
cursor: pointer;
|
|
605
719
|
}
|
|
606
720
|
.astl-surface .astl-help-head select:focus-visible {
|
|
607
|
-
outline: var(--astl-focus-width) solid var(--astl-focus);
|
|
608
|
-
outline-offset: var(--astl-focus-offset);
|
|
721
|
+
outline: var(--astl-editor-focus-width, 2px) solid var(--astl-focus);
|
|
722
|
+
outline-offset: var(--astl-editor-focus-offset, 1px);
|
|
609
723
|
}
|
|
610
724
|
${unsafeCSS(nativeSelectCss('.astl-surface .astl-help-head select'))}
|
|
611
725
|
/* "Remove" closes the head: a cross, a page button's look. */
|
|
@@ -643,7 +757,7 @@ const baseSurfaceStyles: CSSResult = css`
|
|
|
643
757
|
pointer-events: none;
|
|
644
758
|
}
|
|
645
759
|
/* 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. */
|
|
760
|
+
the tab as high as its line; its focus ring hugs the pill, so it stays off the tab's line above when the tab wraps. */
|
|
647
761
|
.astl-surface .astl-frame-help {
|
|
648
762
|
box-sizing: border-box;
|
|
649
763
|
display: inline-flex;
|
|
@@ -673,8 +787,11 @@ const baseSurfaceStyles: CSSResult = css`
|
|
|
673
787
|
color: var(--astl-ink);
|
|
674
788
|
}
|
|
675
789
|
.astl-surface .astl-frame-help:focus-visible {
|
|
676
|
-
outline:
|
|
677
|
-
|
|
790
|
+
outline: none;
|
|
791
|
+
}
|
|
792
|
+
.astl-surface .astl-frame-help:focus-visible > span {
|
|
793
|
+
outline: var(--astl-editor-focus-width, 2px) solid var(--astl-focus);
|
|
794
|
+
outline-offset: var(--astl-editor-focus-offset, 1px);
|
|
678
795
|
}
|
|
679
796
|
.astl-surface .astl-child {
|
|
680
797
|
padding-block: var(--astl-space-1);
|
|
@@ -761,10 +878,10 @@ const baseSurfaceStyles: CSSResult = css`
|
|
|
761
878
|
margin: 0;
|
|
762
879
|
padding-block: 0;
|
|
763
880
|
padding-inline: var(--astl-space-1) var(--astl-space-2);
|
|
764
|
-
border:
|
|
881
|
+
border: 1px solid transparent;
|
|
765
882
|
border-radius: var(--astl-radius-s);
|
|
766
883
|
background: transparent;
|
|
767
|
-
color: var(--astl-
|
|
884
|
+
color: var(--astl-accent);
|
|
768
885
|
font: inherit;
|
|
769
886
|
font-family: var(--astl-font-body);
|
|
770
887
|
font-size: var(--astl-editor-control-font-size, 0.8125rem);
|
|
@@ -796,11 +913,11 @@ const baseSurfaceStyles: CSSResult = css`
|
|
|
796
913
|
words beside it: its ring is inside it, and it is filled (its border is the accent already). An empty chip keeps
|
|
797
914
|
its colours: the solid ring stands out on its dashed one. */
|
|
798
915
|
.astl-surface .ProseMirror-selectednode {
|
|
799
|
-
outline: var(--astl-focus-width) solid var(--astl-focus);
|
|
800
|
-
outline-offset: var(--astl-focus-offset);
|
|
916
|
+
outline: var(--astl-editor-focus-width, 2px) solid var(--astl-focus);
|
|
917
|
+
outline-offset: var(--astl-editor-focus-offset, 1px);
|
|
801
918
|
}
|
|
802
919
|
.astl-surface .astl-chip.ProseMirror-selectednode {
|
|
803
|
-
outline-offset: calc(-1 * var(--astl-focus-width));
|
|
920
|
+
outline-offset: calc(-1 * var(--astl-editor-focus-width, 2px));
|
|
804
921
|
}
|
|
805
922
|
.astl-surface .astl-chip.ProseMirror-selectednode:not([data-empty]) {
|
|
806
923
|
background: var(--astl-accent);
|
|
@@ -925,7 +1042,7 @@ const baseSurfaceStyles: CSSResult = css`
|
|
|
925
1042
|
min-inline-size: max(24px, var(--astl-editor-control-size, 1.75rem));
|
|
926
1043
|
padding-block: 0;
|
|
927
1044
|
padding-inline: var(--astl-space-2);
|
|
928
|
-
border:
|
|
1045
|
+
border: 1px solid var(--astl-outline);
|
|
929
1046
|
border-radius: var(--astl-radius-s);
|
|
930
1047
|
background: var(--astl-surface);
|
|
931
1048
|
color: var(--astl-ink);
|
|
@@ -939,7 +1056,7 @@ const baseSurfaceStyles: CSSResult = css`
|
|
|
939
1056
|
min-inline-size: max(24px, var(--astl-editor-control-size, 1.75rem));
|
|
940
1057
|
padding-block: 0;
|
|
941
1058
|
padding-inline: var(--astl-space-2);
|
|
942
|
-
border:
|
|
1059
|
+
border: 1px solid var(--astl-outline);
|
|
943
1060
|
border-radius: var(--astl-radius-s);
|
|
944
1061
|
background: var(--astl-surface);
|
|
945
1062
|
color: var(--astl-ink);
|