@quillmark/svelte 0.30.0 → 0.32.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/README.md +5 -5
- package/dist/core/address.d.ts +1 -1
- package/dist/core/address.js +1 -1
- package/dist/core/codec/atoms.js +1 -1
- package/dist/core/codec/breaks.js +3 -2
- package/dist/core/codec/decode.d.ts +4 -3
- package/dist/core/codec/decode.js +17 -13
- package/dist/core/codec/field.d.ts +5 -4
- package/dist/core/codec/field.js +139 -49
- package/dist/core/codec/index.d.ts +2 -0
- package/dist/core/codec/index.js +5 -1
- package/dist/core/codec/inputrules.js +3 -3
- package/dist/core/codec/islands.d.ts +1 -1
- package/dist/core/codec/islands.js +3 -3
- package/dist/core/codec/keymap.d.ts +1 -1
- package/dist/core/codec/keymap.js +3 -2
- package/dist/core/codec/list-move.js +2 -1
- package/dist/core/codec/list-paste.js +1 -1
- package/dist/core/codec/lists.d.ts +1 -1
- package/dist/core/codec/lists.js +7 -6
- package/dist/core/codec/markdown-paste.js +2 -2
- package/dist/core/codec/positions.d.ts +12 -1
- package/dist/core/codec/prose.css +3 -11
- package/dist/core/codec/schema.d.ts +3 -3
- package/dist/core/codec/schema.js +6 -6
- package/dist/core/codec/shortcuts.d.ts +91 -0
- package/dist/core/codec/shortcuts.js +135 -0
- package/dist/core/codec/slash.d.ts +4 -2
- package/dist/core/codec/slash.js +11 -1
- package/dist/core/codec/table-paste.js +1 -1
- package/dist/core/codec/table-view.d.ts +1 -1
- package/dist/core/codec/table-view.js +27 -37
- package/dist/core/codec/tasks.js +1 -1
- package/dist/core/index.d.ts +1 -0
- package/dist/core/theme.css +16 -8
- package/dist/preset/scale.css +1 -1
- package/dist/preview/Preview.svelte +2 -3
- package/dist/preview/bridge.js +2 -2
- package/dist/preview/geometry.d.ts +2 -2
- package/dist/preview/geometry.js +2 -2
- package/dist/preview/paint.js +1 -1
- package/dist/visual/ArrayField.svelte +172 -87
- package/dist/visual/BooleanField.svelte +3 -3
- package/dist/visual/Card.svelte +68 -47
- package/dist/visual/CardControls.svelte +1 -1
- package/dist/visual/DateField.svelte +17 -2
- package/dist/visual/DiagnosticList.svelte +35 -3
- package/dist/visual/EnumField.svelte +59 -45
- package/dist/visual/Field.svelte +16 -6
- package/dist/visual/Field.svelte.d.ts +3 -1
- package/dist/visual/FieldHint.svelte +10 -3
- package/dist/visual/FormatPopover.svelte +9 -3
- package/dist/visual/MatrixAdd.svelte +4 -19
- package/dist/visual/MatrixField.svelte +21 -13
- package/dist/visual/NumberField.svelte +2 -3
- package/dist/visual/ObjectField.svelte +166 -147
- package/dist/visual/ProseField.svelte +8 -3
- package/dist/visual/SlashMenu.svelte +24 -12
- package/dist/visual/SlashMenu.svelte.d.ts +2 -0
- package/dist/visual/TextField.svelte +1 -1
- package/dist/visual/VariantField.svelte +1 -1
- package/dist/visual/VisualEditor.svelte +1 -1
- package/dist/visual/VisualEditor.svelte.d.ts +1 -1
- package/dist/visual/VisualEditorInner.svelte +159 -24
- package/dist/visual/VisualEditorInner.svelte.d.ts +1 -1
- package/dist/visual/controls.css +43 -5
- package/dist/visual/diagnostics.d.ts +2 -2
- package/dist/visual/diagnostics.js +2 -2
- package/dist/visual/index.d.ts +2 -0
- package/dist/visual/index.js +3 -0
- package/dist/visual/leaves.js +1 -1
- package/dist/visual/props.d.ts +2 -2
- package/dist/visual/strings.d.ts +33 -15
- package/dist/visual/strings.js +42 -7
- package/dist/visual/structure.d.ts +27 -18
- package/dist/visual/structure.js +32 -28
- package/dist/visual/tips.js +1 -1
- package/dist/visual/undo.svelte.d.ts +36 -0
- package/dist/visual/undo.svelte.js +119 -0
- package/package.json +2 -2
- package/dist/visual/hold.d.ts +0 -17
- package/dist/visual/hold.js +0 -39
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isList } from './list-node.js';
|
|
2
|
+
import { LIST_KEYS } from './shortcuts.js';
|
|
2
3
|
/** The items the selection stands in, in the innermost list holding all of them, moved
|
|
3
4
|
* one place up (`-1`) or down (`1`). */
|
|
4
5
|
function moveItems(dir) {
|
|
@@ -26,5 +27,5 @@ function moveItems(dir) {
|
|
|
26
27
|
export function listMoveKeymap(schema) {
|
|
27
28
|
if (!schema.nodes.list_item)
|
|
28
29
|
return {};
|
|
29
|
-
return {
|
|
30
|
+
return { [LIST_KEYS.moveUp]: moveItems(-1), [LIST_KEYS.moveDown]: moveItems(1) };
|
|
30
31
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// A pasted list takes the numbering of where it lands (
|
|
1
|
+
// A pasted list takes the numbering of where it lands (INVARIANTS §"Markdown at the edges").
|
|
2
2
|
// An item's number is its position, so a paste counts where it stands: items pasted into
|
|
3
3
|
// a list are that list's next items, of its kind and in its count, and items pasted on
|
|
4
4
|
// the empty line a list was just left by are the same list's. A list pasted on a line of
|
|
@@ -5,7 +5,7 @@ import type { Command } from 'prosemirror-state';
|
|
|
5
5
|
* no list nodes.
|
|
6
6
|
*
|
|
7
7
|
* `Tab` / `Shift-Tab` hold the list link of the body's Tab chain; surfaces owning Tab more locally
|
|
8
|
-
* prepend a link in `keymap.ts` (
|
|
8
|
+
* prepend a link in `keymap.ts` (INVARIANTS §Chrome). `Tab` sinks an unnumbered
|
|
9
9
|
* line alone into a sub-list, any other line its whole item, and a block right after a list into
|
|
10
10
|
* the list's last item. `Mod-Shift-7` / `Mod-Shift-8` are the list toggle (`list-toggle.ts`).
|
|
11
11
|
* `Mod-Enter` ticks the task item around the caret (`toggleTask`).
|
package/dist/core/codec/lists.js
CHANGED
|
@@ -21,6 +21,7 @@ import { withinNesting } from './nesting.js';
|
|
|
21
21
|
import { toggleList } from './list-toggle.js';
|
|
22
22
|
import { splitTaskItem, toggleTask } from './tasks.js';
|
|
23
23
|
import { joinAll, joinLists, touching } from './touching.js';
|
|
24
|
+
import { LIST_KEYS } from './shortcuts.js';
|
|
24
25
|
/**
|
|
25
26
|
* The caret's enclosing `list_item` when it sits at the very start of that item's first block,
|
|
26
27
|
* where both structural keys branch; `null` otherwise.
|
|
@@ -473,7 +474,7 @@ function sinkIntoList(itemType) {
|
|
|
473
474
|
* no list nodes.
|
|
474
475
|
*
|
|
475
476
|
* `Tab` / `Shift-Tab` hold the list link of the body's Tab chain; surfaces owning Tab more locally
|
|
476
|
-
* prepend a link in `keymap.ts` (
|
|
477
|
+
* prepend a link in `keymap.ts` (INVARIANTS §Chrome). `Tab` sinks an unnumbered
|
|
477
478
|
* line alone into a sub-list, any other line its whole item, and a block right after a list into
|
|
478
479
|
* the list's last item. `Mod-Shift-7` / `Mod-Shift-8` are the list toggle (`list-toggle.ts`).
|
|
479
480
|
* `Mod-Enter` ticks the task item around the caret (`toggleTask`).
|
|
@@ -497,11 +498,11 @@ export function listKeymap(schema) {
|
|
|
497
498
|
return {};
|
|
498
499
|
const backspace = chainCommands(markerOff(itemType), joinOntoList(itemType));
|
|
499
500
|
return {
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
501
|
+
[LIST_KEYS.numbered]: toggleList(true),
|
|
502
|
+
[LIST_KEYS.bulleted]: toggleList(false),
|
|
503
|
+
[LIST_KEYS.indent]: chainCommands(sinkLine(itemType), sinkWithin(itemType), sinkIntoList(itemType)),
|
|
504
|
+
[LIST_KEYS.outdent]: outdent(itemType),
|
|
505
|
+
[LIST_KEYS.task]: toggleTask(itemType),
|
|
505
506
|
Enter: chainCommands(lineAbove(itemType, paragraph), lineOutOfMiddle(itemType), markerOn(itemType), splitTaskItem(itemType), liftListItem(itemType)),
|
|
506
507
|
Backspace: chainCommands(deleteAcross, markerOff(itemType), lineOut(itemType), joinOntoList(itemType)),
|
|
507
508
|
Delete: chainCommands(deleteAcross, deleteBelow(itemType, backspace))
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// Markdown on the clipboard as text lands parsed in a block leaf (
|
|
2
|
-
// edges"). A line opening a block is the shape a draft written in Notepad or copied out of
|
|
1
|
+
// Markdown on the clipboard as text lands parsed in a block leaf (INVARIANTS §"Markdown at
|
|
2
|
+
// the edges"). A line opening a block is the shape a draft written in Notepad or copied out of
|
|
3
3
|
// an LLM chat carries, and text holding one runs through `importMarkdown` and `decode`, so
|
|
4
4
|
// the paste stores what the source editor stores of the same text. Text holding none stays
|
|
5
5
|
// literal: a sentence with a dash in it, or a `**` with no block around it, keeps every
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import type { Node as PMNode } from 'prosemirror-model';
|
|
2
|
-
import type { Delta } from '@quillmark/wasm';
|
|
3
2
|
import { type PosRun, type Scan } from './encode.js';
|
|
3
|
+
/** A text change as one pass over the text before, offsets in UTF-16 code units: what a host
|
|
4
|
+
* hands `applyExternal` for a field another writer changed, such as `@quillmark/collab`'s
|
|
5
|
+
* `RemoteChange` delta. */
|
|
6
|
+
export interface Delta {
|
|
7
|
+
ops: ({
|
|
8
|
+
retain: number;
|
|
9
|
+
} | {
|
|
10
|
+
insert: string;
|
|
11
|
+
} | {
|
|
12
|
+
delete: number;
|
|
13
|
+
})[];
|
|
14
|
+
}
|
|
4
15
|
/** A prebuilt position index for a PM doc, rebuilt on structural change. */
|
|
5
16
|
export interface LineIndex {
|
|
6
17
|
runs: PosRun[];
|
|
@@ -72,14 +72,6 @@ li.ProseMirror-selectednode::after {
|
|
|
72
72
|
margin-top: var(--_qm-space-3);
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
/* A plain leaf's paragraph is a line of literal text (`schema.ts` §`plainSchema`), and
|
|
76
|
-
a boundary between two stores the one `\n` a hard break does. So no rhythm: a gap
|
|
77
|
-
would draw a blank line the value does not hold, and the two spellings of one string
|
|
78
|
-
would read apart. */
|
|
79
|
-
.ProseMirror > [data-qm-line] + [data-qm-line] {
|
|
80
|
-
margin-top: 0;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
75
|
/* A blockquote's UA indent was its only mark, and the reset above takes it. The rule
|
|
84
76
|
and the inset carry it instead: the same hairline every surface reads, so a quote
|
|
85
77
|
reads as set apart without a fill or a second box. */
|
|
@@ -155,7 +147,7 @@ li.ProseMirror-selectednode::after {
|
|
|
155
147
|
pointer-events: none;
|
|
156
148
|
}
|
|
157
149
|
|
|
158
|
-
/* A footnote and an equation are read, not edited (
|
|
150
|
+
/* A footnote and an equation are read, not edited (INVARIANTS §Decode), and draw as what
|
|
159
151
|
their markdown writes: a footnote its reference mark, numbered in reading order off a
|
|
160
152
|
counter each leaf resets, its note the marker's title (`islands.ts`); an equation its
|
|
161
153
|
TeX between its dollars, in the code face. */
|
|
@@ -597,7 +589,7 @@ li.ProseMirror-selectednode::after {
|
|
|
597
589
|
top: 100%;
|
|
598
590
|
height: var(--_qm-tap-min);
|
|
599
591
|
}
|
|
600
|
-
/* The reveal is the control's own (
|
|
592
|
+
/* The reveal is the control's own (INVARIANTS §"The table island"): one comes up while the
|
|
601
593
|
pointer is on that control, or while it is what a gesture is about — the selected line's grip, and the lifted one, which is drawn through a drag the
|
|
602
594
|
pointer has travelled off. A cell under the pointer draws its row's and its column's
|
|
603
595
|
grips (`table-view.ts` §`onHover`), one pill on each axis and none anywhere else.
|
|
@@ -659,7 +651,7 @@ li.ProseMirror-selectednode::after {
|
|
|
659
651
|
first row, the band's top edge being the grips'. Up only while its column is held and
|
|
660
652
|
absent otherwise (`table-view.ts` §`alignCluster`), so the reveal is `hidden` rather
|
|
661
653
|
than the band's opacity. It is a row of glyphs floating over text, the format popover's
|
|
662
|
-
family (
|
|
654
|
+
family (INVARIANTS §Styling), and takes that recipe: the popover's translucent
|
|
663
655
|
surface over a blur, the edge and `--_qm-lift` for its separation, and a scale-in on
|
|
664
656
|
arrival, stated from its starting style since the codec shows it by clearing
|
|
665
657
|
`hidden`. Its geometry is the popover's too, a row of toggles held one rung in from
|
|
@@ -11,7 +11,7 @@ export declare const inlineSchema: Schema<string, string>;
|
|
|
11
11
|
* The inline schema with no mark types: a `plaintext(inline)` field, whose value is literal text
|
|
12
12
|
* the boundary refuses to coerce back once it carries a mark. Declaring none makes that structural:
|
|
13
13
|
* `toggleMark` has no type, the mark input rules build nothing, a paste parses marks away, and
|
|
14
|
-
* `decode` drops any a stray content carries (
|
|
14
|
+
* `decode` drops any a stray content carries (INVARIANTS §"Inline mode").
|
|
15
15
|
*/
|
|
16
16
|
export declare const plaintextSchema: Schema<string, never>;
|
|
17
17
|
/**
|
|
@@ -22,8 +22,8 @@ export declare const plaintextSchema: Schema<string, never>;
|
|
|
22
22
|
export declare const cellSchema: Schema<"hard_break", string>;
|
|
23
23
|
/**
|
|
24
24
|
* A `text` field declaring `multiline: true`: paragraphs and hard breaks, no marks, islands or
|
|
25
|
-
* containers, the shape `Content::is_plain` admits.
|
|
26
|
-
*
|
|
25
|
+
* containers, the shape `Content::is_plain` admits. Its literal text spells a break as a `\n` and a
|
|
26
|
+
* paragraph boundary as a blank line.
|
|
27
27
|
*/
|
|
28
28
|
export declare const plainSchema: Schema<"text" | "paragraph" | "hard_break" | "doc", never>;
|
|
29
29
|
/** The schema a leaf of the declared type mounts: `inline` narrows either type to one
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
// with hard breaks, for a table cell. Anchors are not marks here (decorations).
|
|
8
8
|
//
|
|
9
9
|
// `toDOM` and `parseDOM` are one tier: a copy and a paste inside one body run the whole document
|
|
10
|
-
// through them (
|
|
10
|
+
// through them (INVARIANTS §"Markdown at the edges"), so every attribute written here is read back here.
|
|
11
11
|
// Foreign HTML spells none of this package's `data-qm-*` names; the rules that widen that door on
|
|
12
12
|
// purpose are the fence's and a span's styled marks, a `<table>` being the block leaf's clipboard
|
|
13
13
|
// parser's (`table-paste.ts`).
|
|
@@ -210,7 +210,7 @@ const blockNodes = {
|
|
|
210
210
|
// A list stating no `start` starts at one, the absence `toDOM` writes;
|
|
211
211
|
// `Number(null)` would read it as zero. A value the store would normalize away
|
|
212
212
|
// reads as that absence too, since a PM doc keeping one would disagree with the
|
|
213
|
-
// store for the session (
|
|
213
|
+
// store for the session (INVARIANTS §Reconciliation). Zero is not one: `0.` is an
|
|
214
214
|
// ordinal `importMarkdown` produces.
|
|
215
215
|
const stated = el.getAttribute('start');
|
|
216
216
|
const start = stated ? Number(stated) : 1;
|
|
@@ -279,7 +279,7 @@ export const inlineSchema = new Schema({ nodes: inlineNodes, marks });
|
|
|
279
279
|
* The inline schema with no mark types: a `plaintext(inline)` field, whose value is literal text
|
|
280
280
|
* the boundary refuses to coerce back once it carries a mark. Declaring none makes that structural:
|
|
281
281
|
* `toggleMark` has no type, the mark input rules build nothing, a paste parses marks away, and
|
|
282
|
-
* `decode` drops any a stray content carries (
|
|
282
|
+
* `decode` drops any a stray content carries (INVARIANTS §"Inline mode").
|
|
283
283
|
*/
|
|
284
284
|
export const plaintextSchema = new Schema({ nodes: inlineNodes, marks: {} });
|
|
285
285
|
/**
|
|
@@ -293,13 +293,13 @@ export const cellSchema = new Schema({
|
|
|
293
293
|
});
|
|
294
294
|
/**
|
|
295
295
|
* A `text` field declaring `multiline: true`: paragraphs and hard breaks, no marks, islands or
|
|
296
|
-
* containers, the shape `Content::is_plain` admits.
|
|
297
|
-
*
|
|
296
|
+
* containers, the shape `Content::is_plain` admits. Its literal text spells a break as a `\n` and a
|
|
297
|
+
* paragraph boundary as a blank line.
|
|
298
298
|
*/
|
|
299
299
|
export const plainSchema = new Schema({
|
|
300
300
|
nodes: {
|
|
301
301
|
doc: { content: 'paragraph+' },
|
|
302
|
-
paragraph:
|
|
302
|
+
paragraph: blockNodes.paragraph,
|
|
303
303
|
text: inlineLeafNodes.text,
|
|
304
304
|
hard_break: inlineLeafNodes.hard_break
|
|
305
305
|
},
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { Schema } from 'prosemirror-model';
|
|
2
|
+
import type { Command } from 'prosemirror-state';
|
|
3
|
+
/** Every prose leaf, a table cell included: history and the marks. `link` binds in the
|
|
4
|
+
* formatting popover, which is the surface that prompts for the URL. */
|
|
5
|
+
export declare const FIELD_KEYS: {
|
|
6
|
+
readonly undo: "Mod-z";
|
|
7
|
+
readonly redo: "Mod-Shift-z";
|
|
8
|
+
readonly redoAlt: "Mod-y";
|
|
9
|
+
readonly bold: "Mod-b";
|
|
10
|
+
readonly italic: "Mod-i";
|
|
11
|
+
readonly underline: "Mod-u";
|
|
12
|
+
readonly strike: "Mod-Shift-x";
|
|
13
|
+
readonly code: "Mod-e";
|
|
14
|
+
readonly link: "Mod-k";
|
|
15
|
+
};
|
|
16
|
+
/** A multi-block body, outside any surface nested in it. */
|
|
17
|
+
export declare const BODY_KEYS: {
|
|
18
|
+
readonly lineBreak: "Shift-Enter";
|
|
19
|
+
readonly leave: "Escape";
|
|
20
|
+
};
|
|
21
|
+
/** A list item (`lists.ts`, `list-move.ts`). */
|
|
22
|
+
export declare const LIST_KEYS: {
|
|
23
|
+
readonly numbered: "Mod-Shift-7";
|
|
24
|
+
readonly bulleted: "Mod-Shift-8";
|
|
25
|
+
readonly indent: "Tab";
|
|
26
|
+
readonly outdent: "Shift-Tab";
|
|
27
|
+
readonly task: "Mod-Enter";
|
|
28
|
+
readonly moveUp: "Alt-ArrowUp";
|
|
29
|
+
readonly moveDown: "Alt-ArrowDown";
|
|
30
|
+
};
|
|
31
|
+
/** A table island's cell (`table-view.ts`). */
|
|
32
|
+
export declare const TABLE_KEYS: {
|
|
33
|
+
readonly next: "Tab";
|
|
34
|
+
readonly previous: "Shift-Tab";
|
|
35
|
+
readonly nextRow: "Enter";
|
|
36
|
+
readonly select: "Escape";
|
|
37
|
+
readonly selectAll: "Mod-a";
|
|
38
|
+
readonly moveUp: "Alt-ArrowUp";
|
|
39
|
+
readonly moveDown: "Alt-ArrowDown";
|
|
40
|
+
readonly moveLeft: "Alt-ArrowLeft";
|
|
41
|
+
readonly moveRight: "Alt-ArrowRight";
|
|
42
|
+
readonly alignLeft: "Shift-ArrowLeft";
|
|
43
|
+
readonly alignRight: "Shift-ArrowRight";
|
|
44
|
+
readonly erase: "Backspace";
|
|
45
|
+
readonly eraseAlt: "Delete";
|
|
46
|
+
};
|
|
47
|
+
/** The mark toggles, each bound only where the schema declares its mark. */
|
|
48
|
+
export declare function markKeymap(schema: Schema): Record<string, Command>;
|
|
49
|
+
/** Where a shortcut answers: any prose field, a multi-block body, a list item, a table cell. */
|
|
50
|
+
export type ShortcutScope = 'field' | 'body' | 'list' | 'table';
|
|
51
|
+
/** One shortcut as a host lists it. `keys` are the alternatives in `prosemirror-keymap`
|
|
52
|
+
* notation (`Mod-Shift-7`, `Alt-ArrowUp`): `Mod` is ⌘ on Apple platforms and Ctrl
|
|
53
|
+
* elsewhere, and the host prints them. */
|
|
54
|
+
export interface EditorShortcut {
|
|
55
|
+
keys: readonly string[];
|
|
56
|
+
label: string;
|
|
57
|
+
scope: ShortcutScope;
|
|
58
|
+
}
|
|
59
|
+
/** A shortcut's description, the gesture it names: a list's line, not a tooltip. */
|
|
60
|
+
export interface ShortcutStrings {
|
|
61
|
+
shortcutUndo: string;
|
|
62
|
+
shortcutRedo: string;
|
|
63
|
+
shortcutBold: string;
|
|
64
|
+
shortcutItalic: string;
|
|
65
|
+
shortcutUnderline: string;
|
|
66
|
+
shortcutStrikethrough: string;
|
|
67
|
+
shortcutCode: string;
|
|
68
|
+
shortcutLink: string;
|
|
69
|
+
shortcutLineBreak: string;
|
|
70
|
+
shortcutLeave: string;
|
|
71
|
+
shortcutNumberedList: string;
|
|
72
|
+
shortcutBulletedList: string;
|
|
73
|
+
shortcutIndent: string;
|
|
74
|
+
shortcutOutdent: string;
|
|
75
|
+
shortcutTask: string;
|
|
76
|
+
shortcutMoveItem: string;
|
|
77
|
+
shortcutNextCell: string;
|
|
78
|
+
shortcutPreviousCell: string;
|
|
79
|
+
shortcutNextRow: string;
|
|
80
|
+
shortcutSelectCells: string;
|
|
81
|
+
shortcutSelectRow: string;
|
|
82
|
+
shortcutMoveLine: string;
|
|
83
|
+
shortcutAlignColumn: string;
|
|
84
|
+
shortcutDeleteCells: string;
|
|
85
|
+
}
|
|
86
|
+
export declare const DEFAULT_SHORTCUT_STRINGS: ShortcutStrings;
|
|
87
|
+
/**
|
|
88
|
+
* The rich editor's shortcuts, worded by `strings` (the package's English where a key is unset),
|
|
89
|
+
* so a host's shortcut list is read off the bindings rather than copied from them.
|
|
90
|
+
*/
|
|
91
|
+
export declare function editorShortcuts(strings?: Partial<ShortcutStrings>): EditorShortcut[];
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// The chords the prose leaf binds, named once: every keymap that binds one of these reads
|
|
2
|
+
// its key from here, and `editorShortcuts` describes them from the same tables, so a rebinding
|
|
3
|
+
// is one edit that moves the binding and the host's shortcut list together.
|
|
4
|
+
//
|
|
5
|
+
// A key a surface takes only to decline, hold or pass on (Backspace at a block edge, the
|
|
6
|
+
// body's Tab hold, a code fence's Tab) is not a shortcut a writer looks up, and stays a
|
|
7
|
+
// literal in its keymap.
|
|
8
|
+
import { toggleMark } from 'prosemirror-commands';
|
|
9
|
+
/** Every prose leaf, a table cell included: history and the marks. `link` binds in the
|
|
10
|
+
* formatting popover, which is the surface that prompts for the URL. */
|
|
11
|
+
export const FIELD_KEYS = {
|
|
12
|
+
undo: 'Mod-z',
|
|
13
|
+
redo: 'Mod-Shift-z',
|
|
14
|
+
redoAlt: 'Mod-y',
|
|
15
|
+
bold: 'Mod-b',
|
|
16
|
+
italic: 'Mod-i',
|
|
17
|
+
underline: 'Mod-u',
|
|
18
|
+
strike: 'Mod-Shift-x',
|
|
19
|
+
code: 'Mod-e',
|
|
20
|
+
link: 'Mod-k'
|
|
21
|
+
};
|
|
22
|
+
/** A multi-block body, outside any surface nested in it. */
|
|
23
|
+
export const BODY_KEYS = {
|
|
24
|
+
lineBreak: 'Shift-Enter',
|
|
25
|
+
leave: 'Escape'
|
|
26
|
+
};
|
|
27
|
+
/** A list item (`lists.ts`, `list-move.ts`). */
|
|
28
|
+
export const LIST_KEYS = {
|
|
29
|
+
numbered: 'Mod-Shift-7',
|
|
30
|
+
bulleted: 'Mod-Shift-8',
|
|
31
|
+
indent: 'Tab',
|
|
32
|
+
outdent: 'Shift-Tab',
|
|
33
|
+
task: 'Mod-Enter',
|
|
34
|
+
moveUp: 'Alt-ArrowUp',
|
|
35
|
+
moveDown: 'Alt-ArrowDown'
|
|
36
|
+
};
|
|
37
|
+
/** A table island's cell (`table-view.ts`). */
|
|
38
|
+
export const TABLE_KEYS = {
|
|
39
|
+
next: 'Tab',
|
|
40
|
+
previous: 'Shift-Tab',
|
|
41
|
+
nextRow: 'Enter',
|
|
42
|
+
select: 'Escape',
|
|
43
|
+
selectAll: 'Mod-a',
|
|
44
|
+
moveUp: 'Alt-ArrowUp',
|
|
45
|
+
moveDown: 'Alt-ArrowDown',
|
|
46
|
+
moveLeft: 'Alt-ArrowLeft',
|
|
47
|
+
moveRight: 'Alt-ArrowRight',
|
|
48
|
+
alignLeft: 'Shift-ArrowLeft',
|
|
49
|
+
alignRight: 'Shift-ArrowRight',
|
|
50
|
+
erase: 'Backspace',
|
|
51
|
+
eraseAlt: 'Delete'
|
|
52
|
+
};
|
|
53
|
+
/** The mark toggles, each bound only where the schema declares its mark. */
|
|
54
|
+
export function markKeymap(schema) {
|
|
55
|
+
const map = {};
|
|
56
|
+
if (schema.marks.strong)
|
|
57
|
+
map[FIELD_KEYS.bold] = toggleMark(schema.marks.strong);
|
|
58
|
+
if (schema.marks.em)
|
|
59
|
+
map[FIELD_KEYS.italic] = toggleMark(schema.marks.em);
|
|
60
|
+
if (schema.marks.underline)
|
|
61
|
+
map[FIELD_KEYS.underline] = toggleMark(schema.marks.underline);
|
|
62
|
+
if (schema.marks.strike)
|
|
63
|
+
map[FIELD_KEYS.strike] = toggleMark(schema.marks.strike);
|
|
64
|
+
if (schema.marks.code)
|
|
65
|
+
map[FIELD_KEYS.code] = toggleMark(schema.marks.code);
|
|
66
|
+
return map;
|
|
67
|
+
}
|
|
68
|
+
export const DEFAULT_SHORTCUT_STRINGS = {
|
|
69
|
+
shortcutUndo: 'Undo',
|
|
70
|
+
shortcutRedo: 'Redo',
|
|
71
|
+
shortcutBold: 'Bold',
|
|
72
|
+
shortcutItalic: 'Italic',
|
|
73
|
+
shortcutUnderline: 'Underline',
|
|
74
|
+
shortcutStrikethrough: 'Strikethrough',
|
|
75
|
+
shortcutCode: 'Code',
|
|
76
|
+
shortcutLink: 'Link',
|
|
77
|
+
shortcutLineBreak: 'Line break within a paragraph',
|
|
78
|
+
shortcutLeave: 'Leave the editor',
|
|
79
|
+
shortcutNumberedList: 'Numbered list',
|
|
80
|
+
shortcutBulletedList: 'Bulleted list',
|
|
81
|
+
shortcutIndent: 'Nest under the item above',
|
|
82
|
+
shortcutOutdent: 'Move back up a level',
|
|
83
|
+
shortcutTask: 'Check or uncheck a task',
|
|
84
|
+
shortcutMoveItem: 'Move the item up or down',
|
|
85
|
+
shortcutNextCell: 'Next cell, adding a row past the last',
|
|
86
|
+
shortcutPreviousCell: 'Previous cell',
|
|
87
|
+
shortcutNextRow: 'Next row, adding one past the last',
|
|
88
|
+
shortcutSelectCells: "Select the cell's text, then its row, then the table",
|
|
89
|
+
shortcutSelectRow: 'Select the row, then the table',
|
|
90
|
+
shortcutMoveLine: 'Move a selected row or column',
|
|
91
|
+
shortcutAlignColumn: 'Align a selected column',
|
|
92
|
+
shortcutDeleteCells: 'Delete the selected cells, rows or columns'
|
|
93
|
+
};
|
|
94
|
+
const F = FIELD_KEYS;
|
|
95
|
+
const L = LIST_KEYS;
|
|
96
|
+
const T = TABLE_KEYS;
|
|
97
|
+
/** The described shortcuts, in the order a host lists them. */
|
|
98
|
+
const SHORTCUTS = [
|
|
99
|
+
{ scope: 'field', label: 'shortcutUndo', keys: [F.undo] },
|
|
100
|
+
{ scope: 'field', label: 'shortcutRedo', keys: [F.redo, F.redoAlt] },
|
|
101
|
+
{ scope: 'field', label: 'shortcutBold', keys: [F.bold] },
|
|
102
|
+
{ scope: 'field', label: 'shortcutItalic', keys: [F.italic] },
|
|
103
|
+
{ scope: 'field', label: 'shortcutUnderline', keys: [F.underline] },
|
|
104
|
+
{ scope: 'field', label: 'shortcutStrikethrough', keys: [F.strike] },
|
|
105
|
+
{ scope: 'field', label: 'shortcutCode', keys: [F.code] },
|
|
106
|
+
{ scope: 'field', label: 'shortcutLink', keys: [F.link] },
|
|
107
|
+
{ scope: 'body', label: 'shortcutLineBreak', keys: [BODY_KEYS.lineBreak] },
|
|
108
|
+
{ scope: 'body', label: 'shortcutLeave', keys: [BODY_KEYS.leave] },
|
|
109
|
+
{ scope: 'list', label: 'shortcutNumberedList', keys: [L.numbered] },
|
|
110
|
+
{ scope: 'list', label: 'shortcutBulletedList', keys: [L.bulleted] },
|
|
111
|
+
{ scope: 'list', label: 'shortcutIndent', keys: [L.indent] },
|
|
112
|
+
{ scope: 'list', label: 'shortcutOutdent', keys: [L.outdent] },
|
|
113
|
+
{ scope: 'list', label: 'shortcutTask', keys: [L.task] },
|
|
114
|
+
{ scope: 'list', label: 'shortcutMoveItem', keys: [L.moveUp, L.moveDown] },
|
|
115
|
+
{ scope: 'table', label: 'shortcutNextCell', keys: [T.next] },
|
|
116
|
+
{ scope: 'table', label: 'shortcutPreviousCell', keys: [T.previous] },
|
|
117
|
+
{ scope: 'table', label: 'shortcutNextRow', keys: [T.nextRow] },
|
|
118
|
+
{ scope: 'table', label: 'shortcutSelectCells', keys: [T.selectAll] },
|
|
119
|
+
{ scope: 'table', label: 'shortcutSelectRow', keys: [T.select] },
|
|
120
|
+
{
|
|
121
|
+
scope: 'table',
|
|
122
|
+
label: 'shortcutMoveLine',
|
|
123
|
+
keys: [T.moveUp, T.moveDown, T.moveLeft, T.moveRight]
|
|
124
|
+
},
|
|
125
|
+
{ scope: 'table', label: 'shortcutAlignColumn', keys: [T.alignLeft, T.alignRight] },
|
|
126
|
+
{ scope: 'table', label: 'shortcutDeleteCells', keys: [T.erase, T.eraseAlt] }
|
|
127
|
+
];
|
|
128
|
+
/**
|
|
129
|
+
* The rich editor's shortcuts, worded by `strings` (the package's English where a key is unset),
|
|
130
|
+
* so a host's shortcut list is read off the bindings rather than copied from them.
|
|
131
|
+
*/
|
|
132
|
+
export function editorShortcuts(strings = {}) {
|
|
133
|
+
const words = { ...DEFAULT_SHORTCUT_STRINGS, ...strings };
|
|
134
|
+
return SHORTCUTS.map(({ keys, label, scope }) => ({ keys, label: words[label], scope }));
|
|
135
|
+
}
|
|
@@ -18,13 +18,15 @@ export interface SlashState {
|
|
|
18
18
|
anchor: RangeAnchor;
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
|
-
* The menu's wording: its accessible name
|
|
22
|
-
*
|
|
21
|
+
* The menu's wording: its accessible name, the empty line's hint, and each row's name. The tokens
|
|
22
|
+
* a row shows beside its name are not translated: they are what is typed.
|
|
23
23
|
*/
|
|
24
24
|
export interface SlashStrings {
|
|
25
25
|
slashLabel: string;
|
|
26
26
|
/** Drawn on the empty line a focused caret holds, naming the key that opens the menu. */
|
|
27
27
|
slashHint: string;
|
|
28
|
+
/** A command's row name, by its token: `numbered-list` → `Numbered list`. */
|
|
29
|
+
slashName: (command: string) => string;
|
|
28
30
|
}
|
|
29
31
|
/** The package's English, beside the surface that draws it; the visual `strings` set extends it. */
|
|
30
32
|
export declare const DEFAULT_SLASH_STRINGS: SlashStrings;
|
package/dist/core/codec/slash.js
CHANGED
|
@@ -4,10 +4,20 @@ import { rangeAnchor } from './anchor.js';
|
|
|
4
4
|
import { consuming, pickList, pickSubList, toCodeBlock, toHeading, wrapInQuote } from './blocks.js';
|
|
5
5
|
import { mintIslandId } from './islands.js';
|
|
6
6
|
import { islandOf, newTable } from './table.js';
|
|
7
|
+
const SLASH_NAMES = {
|
|
8
|
+
heading: 'Heading',
|
|
9
|
+
list: 'Bulleted list',
|
|
10
|
+
'numbered-list': 'Numbered list',
|
|
11
|
+
subparagraph: 'Subparagraph',
|
|
12
|
+
quote: 'Quote',
|
|
13
|
+
code: 'Code block',
|
|
14
|
+
table: 'Table'
|
|
15
|
+
};
|
|
7
16
|
/** The package's English, beside the surface that draws it; the visual `strings` set extends it. */
|
|
8
17
|
export const DEFAULT_SLASH_STRINGS = {
|
|
9
18
|
slashLabel: 'Insert',
|
|
10
|
-
slashHint: 'Type / to insert'
|
|
19
|
+
slashHint: 'Type / to insert',
|
|
20
|
+
slashName: (command) => SLASH_NAMES[command] ?? command.charAt(0).toUpperCase() + command.slice(1).replace(/-/g, ' ')
|
|
11
21
|
};
|
|
12
22
|
/**
|
|
13
23
|
* The vocabulary a caret can run, in menu order, each name asked whether it would fire here: a row
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// A table on the clipboard lands as a table island (
|
|
1
|
+
// A table on the clipboard lands as a table island (INVARIANTS §"Markdown at the edges"). Two
|
|
2
2
|
// spellings carry one: an HTML `<table>`, and the tab-separated text a spreadsheet writes
|
|
3
3
|
// beside it, which ProseMirror hands over only where the clipboard holds no HTML. Either
|
|
4
4
|
// builds its props through `normalizeTable` and arrives with no id, which the paste's
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EditorView, type NodeViewConstructor } from 'prosemirror-view';
|
|
2
2
|
/** Everything the island's chrome says. Accessible names, not decoration: every
|
|
3
3
|
* control here is a bar, so an untranslated one reads the wrong language rather than
|
|
4
|
-
* merely inconsistent (
|
|
4
|
+
* merely inconsistent (INVARIANTS §"What the surface says"). */
|
|
5
5
|
export interface TableChromeStrings {
|
|
6
6
|
/** The island's own name, on the wrapper. */
|
|
7
7
|
tableLabel: string;
|
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
// The table island's NodeView (
|
|
1
|
+
// The table island's NodeView (INVARIANTS §"The table island"): vanilla DOM holding one nested
|
|
2
2
|
// `EditorView` per cell, each on its own schema (`table.ts`).
|
|
3
3
|
//
|
|
4
4
|
// A cell edit writes the projection back onto the node's `props` with `setNodeMarkup`, which the
|
|
5
|
-
// field lowers to an `islandOps` `set` (
|
|
5
|
+
// field lowers to an `islandOps` `set` (INVARIANTS §Encode), so every anchor stays in the field.
|
|
6
6
|
//
|
|
7
7
|
// The nested views carry no history (Mod-z routes to the field's), no anchor plugin (an anchor in a
|
|
8
8
|
// cell is preserved, never minted), and no placeholder.
|
|
9
9
|
//
|
|
10
10
|
// Every control is absolutely positioned out of the grid; `codec/prose.css` draws the band, the
|
|
11
11
|
// clusters and the selection wash.
|
|
12
|
-
import { baseKeymap, chainCommands, selectAll
|
|
12
|
+
import { baseKeymap, chainCommands, selectAll } from 'prosemirror-commands';
|
|
13
13
|
import { redo, undo } from 'prosemirror-history';
|
|
14
14
|
import { keymap } from 'prosemirror-keymap';
|
|
15
15
|
import { EditorState, NodeSelection, Selection, TextSelection } from 'prosemirror-state';
|
|
16
16
|
import { EditorView } from 'prosemirror-view';
|
|
17
17
|
import { decode } from './decode.js';
|
|
18
|
+
import { FIELD_KEYS, markKeymap, TABLE_KEYS as T } from './shortcuts.js';
|
|
18
19
|
import { inputRulesPlugin, undoRuleKeymap } from './inputrules.js';
|
|
19
20
|
import { linkPastePlugin } from './link-paste.js';
|
|
20
21
|
import { tableOfNode } from './table.js';
|
|
@@ -305,7 +306,7 @@ class TableIslandView {
|
|
|
305
306
|
}
|
|
306
307
|
// ── The pointer ───────────────────────────────────────────────────────────
|
|
307
308
|
/**
|
|
308
|
-
* Route a press to its band (
|
|
309
|
+
* Route a press to its band (INVARIANTS §"The table island"): inside the frame the nearest cell's
|
|
309
310
|
* caret, outside it the document's, and a band control answers for itself.
|
|
310
311
|
*
|
|
311
312
|
* A press in a cell is a caret the nested view takes; only the promotion to a block is armed
|
|
@@ -455,7 +456,7 @@ class TableIslandView {
|
|
|
455
456
|
}
|
|
456
457
|
/**
|
|
457
458
|
* The island as the selection: the Escape that climbs out of a cell or held rectangle.
|
|
458
|
-
* Backspace there deletes the table, as over every island (
|
|
459
|
+
* Backspace there deletes the table, as over every island (INVARIANTS §"The table island").
|
|
459
460
|
*/
|
|
460
461
|
selectIsland() {
|
|
461
462
|
const pos = this.getPos();
|
|
@@ -549,7 +550,7 @@ class TableIslandView {
|
|
|
549
550
|
: { floor: 0, limit: columnCount(props) - 1 };
|
|
550
551
|
}
|
|
551
552
|
/** Select a line, and land the caret on it. The line verbs bind in the cell
|
|
552
|
-
* (
|
|
553
|
+
* (INVARIANTS §"The table island"), so the rectangle has to run through the caret for the
|
|
553
554
|
* next key to read a line off it. The focus moves first and the paint follows: a cell
|
|
554
555
|
* taking the focus retires whatever was held. */
|
|
555
556
|
selectLine(line) {
|
|
@@ -693,7 +694,7 @@ class TableIslandView {
|
|
|
693
694
|
this.write(props, { r: block.r0, c: block.c0 });
|
|
694
695
|
}
|
|
695
696
|
/**
|
|
696
|
-
* What Backspace means over the selection (
|
|
697
|
+
* What Backspace means over the selection (INVARIANTS §"The table island"). Swept cells clear and
|
|
697
698
|
* keep their lines. Named lines go; every rank on both axes is the table, which goes as the
|
|
698
699
|
* island.
|
|
699
700
|
*/
|
|
@@ -1455,21 +1456,10 @@ class TableIslandView {
|
|
|
1455
1456
|
}
|
|
1456
1457
|
/**
|
|
1457
1458
|
* A cell's keys. Traversal binds on the nested view, since the outer keymap never sees a
|
|
1458
|
-
* keystroke a cell handled (`stopEvent`;
|
|
1459
|
+
* keystroke a cell handled (`stopEvent`; INVARIANTS §Chrome). Enter is the next row;
|
|
1459
1460
|
* Shift-Enter is the body's line break (`breaks.ts`).
|
|
1460
1461
|
*/
|
|
1461
1462
|
cellKeys(r, c) {
|
|
1462
|
-
const marks = {};
|
|
1463
|
-
if (cellSchema.marks.strong)
|
|
1464
|
-
marks['Mod-b'] = toggleMark(cellSchema.marks.strong);
|
|
1465
|
-
if (cellSchema.marks.em)
|
|
1466
|
-
marks['Mod-i'] = toggleMark(cellSchema.marks.em);
|
|
1467
|
-
if (cellSchema.marks.underline)
|
|
1468
|
-
marks['Mod-u'] = toggleMark(cellSchema.marks.underline);
|
|
1469
|
-
if (cellSchema.marks.strike)
|
|
1470
|
-
marks['Mod-Shift-x'] = toggleMark(cellSchema.marks.strike);
|
|
1471
|
-
if (cellSchema.marks.code)
|
|
1472
|
-
marks['Mod-e'] = toggleMark(cellSchema.marks.code);
|
|
1473
1463
|
// The arrows walk the grid, each leaving a cell only from the text's edge on its side. Up
|
|
1474
1464
|
// and down clamp at the top and bottom; left and right follow reading order and stop at the
|
|
1475
1465
|
// first and last cells. No arrow grows the table.
|
|
@@ -1575,28 +1565,28 @@ class TableIslandView {
|
|
|
1575
1565
|
return true;
|
|
1576
1566
|
};
|
|
1577
1567
|
return {
|
|
1578
|
-
...
|
|
1568
|
+
...markKeymap(cellSchema),
|
|
1579
1569
|
...breakKeymap(cellSchema),
|
|
1580
1570
|
// One undo stack per leaf: Mod-z unwinds a cell keystroke and a row op in order.
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1571
|
+
[FIELD_KEYS.undo]: () => undo(this.outer.state, this.outer.dispatch),
|
|
1572
|
+
[FIELD_KEYS.redoAlt]: () => redo(this.outer.state, this.outer.dispatch),
|
|
1573
|
+
[FIELD_KEYS.redo]: () => redo(this.outer.state, this.outer.dispatch),
|
|
1574
|
+
[T.erase]: erase,
|
|
1575
|
+
[T.eraseAlt]: erase,
|
|
1586
1576
|
ArrowUp: chainCommands(line('row', -1, false), walk('up')),
|
|
1587
1577
|
ArrowDown: chainCommands(line('row', 1, false), walk('down')),
|
|
1588
1578
|
ArrowLeft: chainCommands(line('column', -1, false), cross(-1)),
|
|
1589
1579
|
ArrowRight: chainCommands(line('column', 1, false), cross(1)),
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1580
|
+
[T.moveUp]: line('row', -1, true),
|
|
1581
|
+
[T.moveDown]: line('row', 1, true),
|
|
1582
|
+
[T.moveLeft]: line('column', -1, true),
|
|
1583
|
+
[T.moveRight]: line('column', 1, true),
|
|
1584
|
+
[T.alignLeft]: slide(-1),
|
|
1585
|
+
[T.alignRight]: slide(1),
|
|
1586
|
+
[T.selectAll]: grow,
|
|
1587
|
+
[T.next]: () => this.step(r, c, 1),
|
|
1588
|
+
[T.previous]: () => this.step(r, c, -1),
|
|
1589
|
+
[T.nextRow]: () => {
|
|
1600
1590
|
// Over a rectangle it hands the caret back: the caret never left the cell.
|
|
1601
1591
|
if (this.selected) {
|
|
1602
1592
|
this.clearSelection();
|
|
@@ -1617,8 +1607,8 @@ class TableIslandView {
|
|
|
1617
1607
|
},
|
|
1618
1608
|
// Escape climbs a rung a press: the caret's row (the keyboard's only route to a held
|
|
1619
1609
|
// rectangle), then the island. What a press past the island means is the shell's
|
|
1620
|
-
// (
|
|
1621
|
-
|
|
1610
|
+
// (INVARIANTS §Chrome).
|
|
1611
|
+
[T.select]: () => {
|
|
1622
1612
|
if (this.selected)
|
|
1623
1613
|
this.selectIsland();
|
|
1624
1614
|
else
|
package/dist/core/codec/tasks.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// A task item is a `list_item` whose `checked` is a boolean (
|
|
1
|
+
// A task item is a `list_item` whose `checked` is a boolean (INVARIANTS §"Task items"). Its
|
|
2
2
|
// `toDOM` draws a checkbox ahead of the item's blocks, disabled, which is the drawing a
|
|
3
3
|
// held leaf, a copy and `renderContent` take; a leaf that edits mounts the item through
|
|
4
4
|
// `taskItemView`, whose checkbox toggles, as `Mod-Enter` does (`toggleTask`). A task item
|
package/dist/core/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { init } from './lifecycle.js';
|
|
2
2
|
export type { DocPath, Landing, Place } from './address.js';
|
|
3
3
|
export { fieldPathForAddr, addrForFieldPath } from './address.js';
|
|
4
|
+
export type { Delta } from './codec/positions.js';
|
|
4
5
|
export type { EditorError, EditorErrorCode, EditorErrorHandler } from './errors.js';
|