@astl/editor-tiptap 0.2.1 → 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 +16 -0
- package/dist/nodes.d.ts.map +1 -1
- package/dist/nodes.js +114 -1
- package/dist/nodes.js.map +1 -1
- package/dist/styles.d.ts.map +1 -1
- package/dist/styles.js +91 -32
- package/dist/styles.js.map +1 -1
- package/package.json +6 -6
- package/src/nodes.ts +121 -1
- package/src/styles.ts +91 -32
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @astl/editor-tiptap
|
|
2
2
|
|
|
3
|
+
## 0.2.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- f86ccf1: "Add option" in Select words works: it ends the exercise's last line with a new marked word, selected, so what the author types replaces it and stays a word to select (one undo step). It did nothing before, because the words are marks in the text and the button looked for a node.
|
|
8
|
+
|
|
9
|
+
The editor's authoring controls are compact, so an exercise looks as students see it: on the surface the page heads' buttons ("Add title", "Check this page"), "Add option" and "Add prompt", a frame's "In the text", a page box's select and cross, the tags and a picture's buttons; in the card (`<astl-inspector>`, its help form and picture fields) its buttons. They are small ghost buttons (no fill or line at rest, muted ink, a subtle fill on hover, the focus ring), 1.75rem high with 0.8125rem text and 0.875rem icons, sized by `--astl-editor-control-size`, `--astl-editor-control-font-size` and `--astl-editor-control-icon-size` on `<astl-editor>`; a target never goes under 24px (WCAG 2.5.8).
|
|
10
|
+
|
|
11
|
+
`@astl/astrolabe/editor` exports what a host of `<astl-editor>` needs for the help for students, as `@astl/editor` does: `HELP_OPEN` with the types `HelpOpen` and `HelpPart`, `loadHelpForm`, `EDITOR_NAMESPACE`, and the types `AstlInspector`, `AstlIssues` and `AstlHelpForm` for a host that places those elements itself. A test keeps the two entries in step.
|
|
12
|
+
- Updated dependencies [f86ccf1]
|
|
13
|
+
- @astl/editor@0.2.2
|
|
14
|
+
- @astl/core@0.2.2
|
|
15
|
+
- @astl/engine@0.2.2
|
|
16
|
+
- @astl/player@0.2.2
|
|
17
|
+
- @astl/tokens@0.2.2
|
|
18
|
+
|
|
3
19
|
## 0.2.1
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/dist/nodes.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nodes.d.ts","sourceRoot":"","sources":["../src/nodes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,EAOL,KAAK,iBAAiB,EAGtB,KAAK,gBAAgB,EAgBtB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,KAAK,SAAS,EAEd,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,KAAK,cAAc,EAQpB,MAAM,cAAc,CAAC;AACtB,OAAO,EAA0B,KAAK,UAAU,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"nodes.d.ts","sourceRoot":"","sources":["../src/nodes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,EAOL,KAAK,iBAAiB,EAGtB,KAAK,gBAAgB,EAgBtB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,KAAK,SAAS,EAEd,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,KAAK,cAAc,EAQpB,MAAM,cAAc,CAAC;AACtB,OAAO,EAA0B,KAAK,UAAU,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAWnF,OAAO,EAOL,KAAK,WAAW,EACjB,MAAM,kBAAkB,CAAC;AAe1B,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAOzC,qGAAqG;AACrG,eAAO,MAAM,QAAQ,QAAS,MAAM,KAAG,MACyB,CAAC;AAQjE;;;;GAIG;AACH,eAAO,MAAM,YAAY,OAAQ,OAAO,KAA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;;GAGG;AACH,wBAAgB,YAAY,CAAC,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAGjE;AAwOD,OAAO,QAAQ,cAAc,CAAC;IAC5B,UAAU,QAAQ,CAAC,UAAU;QAC3B,QAAQ,EAAE;YACR,4FAA4F;YAC5F,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,UAAU,CAAC;SACvC,CAAC;KACH;CACF;AAipBD,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,SAAS,EACpB,SAAS,GAAE,SAAS,iBAAiB,EAA+B,EACpE,OAAO,GAAE;IAAE,QAAQ,CAAC,QAAQ,CAAC,EAAE,YAAY,CAAA;CAAO,GACjD,UAAU,CA6CZ"}
|
package/dist/nodes.js
CHANGED
|
@@ -879,8 +879,21 @@ function blockNode(manifest, pictures, authoring) {
|
|
|
879
879
|
add.addEventListener('click', () => {
|
|
880
880
|
const pos = getPos();
|
|
881
881
|
const block = typeof pos === 'number' ? editor.state.doc.nodeAt(pos) : null;
|
|
882
|
+
if (typeof pos !== 'number' || block === null)
|
|
883
|
+
return;
|
|
884
|
+
// In a rich block the child is a mark in its text (Select words' word): a new word ends its last line.
|
|
885
|
+
const markType = editor.schema.marks[childType];
|
|
886
|
+
if (markType !== undefined) {
|
|
887
|
+
const word = authoring.t(EDITOR_NAMESPACE, 'surface.newWord');
|
|
888
|
+
const tr = addMarkedWord(editor.state, pos, block, markType, repeated.tag, word);
|
|
889
|
+
if (tr === null)
|
|
890
|
+
return;
|
|
891
|
+
editor.view.dispatch(tr.scrollIntoView());
|
|
892
|
+
editor.view.focus();
|
|
893
|
+
return;
|
|
894
|
+
}
|
|
882
895
|
const type = editor.schema.nodes[childType];
|
|
883
|
-
if (
|
|
896
|
+
if (type === undefined)
|
|
884
897
|
return;
|
|
885
898
|
// After the last child of that tag (an option goes after the options, before anything after them).
|
|
886
899
|
let at = pos + block.nodeSize - 1;
|
|
@@ -942,6 +955,105 @@ function blockNode(manifest, pictures, authoring) {
|
|
|
942
955
|
},
|
|
943
956
|
});
|
|
944
957
|
}
|
|
958
|
+
/**
|
|
959
|
+
* A new child of a rich block that is a mark in its text (Select words' word, `markType`): `text` at the end of the
|
|
960
|
+
* block's last line (after a space), with a fresh id, selected so that typing replaces it and keeps the mark; one undo
|
|
961
|
+
* step. A block without a line of text gets one.
|
|
962
|
+
*/
|
|
963
|
+
function addMarkedWord(state, pos, block, markType, tag, text) {
|
|
964
|
+
const tr = closeHistory(state.tr);
|
|
965
|
+
let end = null;
|
|
966
|
+
block.descendants((node, offset) => {
|
|
967
|
+
if (node.type.name === 'paragraph' || node.type.name === 'heading')
|
|
968
|
+
end = pos + 2 + offset + node.content.size;
|
|
969
|
+
return !node.isTextblock;
|
|
970
|
+
});
|
|
971
|
+
if (end === null) {
|
|
972
|
+
const paragraph = state.schema.nodes.paragraph;
|
|
973
|
+
if (paragraph === undefined)
|
|
974
|
+
return null;
|
|
975
|
+
const at = pos + block.nodeSize - 1;
|
|
976
|
+
tr.insert(at, paragraph.create());
|
|
977
|
+
end = at + 1;
|
|
978
|
+
}
|
|
979
|
+
let at = end;
|
|
980
|
+
const $end = tr.doc.resolve(at);
|
|
981
|
+
const before = $end.parent.textBetween(0, $end.parentOffset, undefined, '\ufffc');
|
|
982
|
+
// A plain space before it: inserted text would take the mark of a word that ends the line.
|
|
983
|
+
if (before !== '' && !/\s$/u.test(before)) {
|
|
984
|
+
tr.insert(at, state.schema.text(' '));
|
|
985
|
+
at += 1;
|
|
986
|
+
}
|
|
987
|
+
const taken = idsIn(tr.doc);
|
|
988
|
+
tr.doc.descendants((node) => {
|
|
989
|
+
for (const mark of node.marks)
|
|
990
|
+
if (mark.type === markType)
|
|
991
|
+
taken.add(markId(mark));
|
|
992
|
+
return true;
|
|
993
|
+
});
|
|
994
|
+
const id = freshId(tag.replace(/^astl-/, ''), taken);
|
|
995
|
+
tr.insert(at, state.schema.text(text, [markType.create({ attributes: { id } })]));
|
|
996
|
+
// The word grows as the author types over it or at its end (`growingWordExtension`).
|
|
997
|
+
return tr
|
|
998
|
+
.setSelection(TextSelection.create(tr.doc, at, at + text.length))
|
|
999
|
+
.setMeta(GROWING, { id, type: markType });
|
|
1000
|
+
}
|
|
1001
|
+
const GROWING = new PluginKey('astlGrowingWord');
|
|
1002
|
+
/** Where the run of text marked `growing` is (one word), with its mark, or null. */
|
|
1003
|
+
function growingRun(doc, growing) {
|
|
1004
|
+
let run = null;
|
|
1005
|
+
doc.descendants((node, pos) => {
|
|
1006
|
+
if (!node.isText)
|
|
1007
|
+
return run === null;
|
|
1008
|
+
const mark = node.marks.find((m) => m.type === growing.type && markId(m) === growing.id);
|
|
1009
|
+
if (mark === undefined)
|
|
1010
|
+
return false;
|
|
1011
|
+
run = run === null ? { from: pos, to: pos + node.nodeSize, mark } : { ...run, to: pos + node.nodeSize };
|
|
1012
|
+
return false;
|
|
1013
|
+
});
|
|
1014
|
+
return run;
|
|
1015
|
+
}
|
|
1016
|
+
/**
|
|
1017
|
+
* A word "Add option" added keeps growing while the author types it: text typed over it (it comes selected) or at its
|
|
1018
|
+
* end joins it, though the words' marks end with them, until a space or the cursor leaves it. Other words keep their
|
|
1019
|
+
* marks as they are.
|
|
1020
|
+
*/
|
|
1021
|
+
const growingWordExtension = Extension.create({
|
|
1022
|
+
name: 'astlGrowingWord',
|
|
1023
|
+
addProseMirrorPlugins: () => [
|
|
1024
|
+
new Plugin({
|
|
1025
|
+
key: GROWING,
|
|
1026
|
+
state: {
|
|
1027
|
+
init: () => null,
|
|
1028
|
+
apply: (tr, value, _, state) => {
|
|
1029
|
+
const set = tr.getMeta(GROWING);
|
|
1030
|
+
const growing = set === undefined ? value : set;
|
|
1031
|
+
if (growing === null)
|
|
1032
|
+
return null;
|
|
1033
|
+
const run = growingRun(state.doc, growing);
|
|
1034
|
+
const { from, to } = state.selection;
|
|
1035
|
+
return run !== null && from >= run.from && to <= run.to ? growing : null;
|
|
1036
|
+
},
|
|
1037
|
+
},
|
|
1038
|
+
props: {
|
|
1039
|
+
handleTextInput: (view, from, to, text) => {
|
|
1040
|
+
const growing = GROWING.getState(view.state);
|
|
1041
|
+
if (growing === null || growing === undefined || !/^[\p{L}\p{N}\p{M}'’-]+$/u.test(text))
|
|
1042
|
+
return false;
|
|
1043
|
+
const run = growingRun(view.state.doc, growing);
|
|
1044
|
+
if (run === null)
|
|
1045
|
+
return false;
|
|
1046
|
+
const over = from === run.from && to === run.to;
|
|
1047
|
+
if (!over && !(from === to && from === run.to))
|
|
1048
|
+
return false;
|
|
1049
|
+
const tr = view.state.tr.insertText(text, from, to);
|
|
1050
|
+
view.dispatch(tr.addMark(from, from + text.length, run.mark));
|
|
1051
|
+
return true;
|
|
1052
|
+
},
|
|
1053
|
+
},
|
|
1054
|
+
}),
|
|
1055
|
+
],
|
|
1056
|
+
});
|
|
945
1057
|
/**
|
|
946
1058
|
* A rich child of a block (prompt, option): one line of rich text, in a plain element so no custom element claims
|
|
947
1059
|
* it. A child the manifest allows once (a prompt) is marked `single`.
|
|
@@ -2793,6 +2905,7 @@ export function astrolabeExtensions(authoring, manifests = authoring.engine.mani
|
|
|
2793
2905
|
referencesExtension(authoring, manifests),
|
|
2794
2906
|
childrenExtension(manifests),
|
|
2795
2907
|
richBlocksExtension(authoring, manifests),
|
|
2908
|
+
growingWordExtension,
|
|
2796
2909
|
pastedIdsExtension(authoring, manifests, hooks),
|
|
2797
2910
|
blocksExtension(authoring, (node) => types.get(node.type.name) ?? null, nodeName, hooks?.style === undefined ? undefined : () => hooks.style?.('component'), hooks?.help === undefined ? undefined : (part) => hooks.help?.(part)),
|
|
2798
2911
|
helpPlaceholderExtension(authoring),
|