@quillmark/svelte 0.27.0 → 0.28.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/NOTICE +4 -4
- package/README.md +26 -8
- package/THEMING.md +10 -8
- package/dist/core/address.d.ts +35 -64
- package/dist/core/address.js +35 -55
- package/dist/core/bloom.d.ts +4 -10
- package/dist/core/bloom.js +14 -27
- package/dist/core/codec/blocks.d.ts +41 -43
- package/dist/core/codec/blocks.js +97 -130
- package/dist/core/codec/code.d.ts +7 -10
- package/dist/core/codec/code.js +37 -46
- package/dist/core/codec/decode.d.ts +19 -23
- package/dist/core/codec/decode.js +76 -111
- package/dist/core/codec/encode.d.ts +11 -15
- package/dist/core/codec/encode.js +60 -67
- package/dist/core/codec/field.d.ts +62 -95
- package/dist/core/codec/field.js +107 -179
- package/dist/core/codec/islands.d.ts +33 -41
- package/dist/core/codec/islands.js +76 -86
- package/dist/core/codec/lists.d.ts +17 -26
- package/dist/core/codec/lists.js +117 -157
- package/dist/core/codec/marks.d.ts +4 -3
- package/dist/core/codec/marks.js +8 -3
- package/dist/core/codec/prose.css +84 -46
- package/dist/core/codec/schema.d.ts +18 -23
- package/dist/core/codec/schema.js +84 -76
- package/dist/core/codec/slash.d.ts +42 -48
- package/dist/core/codec/slash.js +0 -0
- package/dist/core/codec/table-copy.d.ts +4 -3
- package/dist/core/codec/table-copy.js +25 -7
- package/dist/core/codec/table-view.d.ts +12 -12
- package/dist/core/codec/table-view.js +460 -383
- package/dist/core/codec/table.d.ts +94 -61
- package/dist/core/codec/table.js +331 -83
- package/dist/core/codec/tasks.d.ts +6 -0
- package/dist/core/codec/tasks.js +30 -3
- package/dist/core/errors.d.ts +15 -30
- package/dist/core/errors.js +2 -6
- package/dist/core/index.js +7 -12
- package/dist/core/lifecycle.d.ts +7 -16
- package/dist/core/lifecycle.js +10 -21
- package/dist/core/rebind.svelte.d.ts +10 -20
- package/dist/core/rebind.svelte.js +15 -27
- package/dist/core/rungs.d.ts +14 -11
- package/dist/core/rungs.js +17 -19
- package/dist/core/teardown.d.ts +4 -6
- package/dist/core/teardown.js +7 -10
- package/dist/core/theme.css +74 -54
- package/dist/index.js +3 -8
- package/dist/preset/app.css +3 -1
- package/dist/preset/index.css +6 -8
- package/dist/preset/recipes.css +12 -15
- package/dist/preset/scale.css +18 -17
- package/dist/preset/shell.css +10 -0
- package/dist/preview/bridge.d.ts +18 -22
- package/dist/preview/bridge.js +29 -58
- package/dist/preview/controller.d.ts +21 -29
- package/dist/preview/controller.js +14 -39
- package/dist/preview/geometry.d.ts +13 -34
- package/dist/preview/geometry.js +13 -34
- package/dist/preview/index.js +4 -16
- package/dist/preview/paint.d.ts +3 -3
- package/dist/preview/paint.js +28 -68
- package/dist/preview/strings.d.ts +1 -1
- package/dist/preview/strings.js +2 -14
- package/dist/preview/zoom.d.ts +18 -23
- package/dist/preview/zoom.js +28 -27
- package/dist/visual/ArrayField.svelte +77 -16
- package/dist/visual/BooleanField.svelte +27 -14
- package/dist/visual/Card.svelte +61 -48
- package/dist/visual/CardControls.svelte +5 -11
- package/dist/visual/DateField.svelte +20 -4
- package/dist/visual/EnumField.svelte +3 -0
- package/dist/visual/FieldHint.svelte +2 -1
- package/dist/visual/FormatPopover.svelte +82 -15
- package/dist/visual/FormatPopover.svelte.d.ts +4 -0
- package/dist/visual/MatrixAdd.svelte +30 -12
- package/dist/visual/MatrixField.svelte +24 -16
- package/dist/visual/NumberField.svelte +7 -0
- package/dist/visual/ObjectField.svelte +4 -4
- package/dist/visual/ProseField.svelte +0 -5
- package/dist/visual/TipsCard.svelte +11 -10
- package/dist/visual/VariantField.svelte +3 -1
- package/dist/visual/VisualEditorInner.svelte +19 -3
- package/dist/visual/controls.css +7 -2
- package/dist/visual/fonts.d.ts +18 -0
- package/dist/visual/fonts.js +59 -0
- package/dist/visual/icons/nodes.d.ts +0 -5
- package/dist/visual/icons/nodes.js +0 -4
- package/dist/visual/props.d.ts +14 -1
- package/dist/visual/strings.d.ts +7 -0
- package/dist/visual/strings.js +5 -2
- package/dist/visual/structure.d.ts +43 -87
- package/dist/visual/structure.js +42 -83
- package/package.json +2 -2
|
@@ -1,67 +1,65 @@
|
|
|
1
1
|
import type { Attrs, Schema } from 'prosemirror-model';
|
|
2
2
|
import type { Command, EditorState, Transaction } from 'prosemirror-state';
|
|
3
|
-
/**
|
|
4
|
-
*
|
|
3
|
+
/**
|
|
4
|
+
* `# `: the heading `level` deep. `list_item` is `block+`, so a heading inside an item is a shape
|
|
5
|
+
* `importMarkdown` produces from `- # title`.
|
|
6
|
+
*/
|
|
5
7
|
export declare function toHeading(level: number): Command;
|
|
6
|
-
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
8
|
+
/**
|
|
9
|
+
* A fence, carrying `attrs` (its `lang`). The exit paragraph after it exists because a gap cursor
|
|
10
|
+
* will not sit beside a code block, so a fence at the end of a body would leave the caret nowhere
|
|
11
|
+
* to go. The caret stays in the fence.
|
|
12
|
+
*/
|
|
10
13
|
export declare function toCodeBlock(attrs?: Attrs): Command;
|
|
11
|
-
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
14
|
+
/**
|
|
15
|
+
* `---`. A divider is a whole block, so this replaces its textblock: `horizontal_rule` holds no
|
|
16
|
+
* content to retype into, and only an empty block may be replaced, anything else being a paragraph
|
|
17
|
+
* being edited.
|
|
18
|
+
*/
|
|
15
19
|
export declare function insertDivider(): Command;
|
|
16
|
-
/**
|
|
17
|
-
*
|
|
18
|
-
|
|
20
|
+
/**
|
|
21
|
+
* `> `. No item guard: wrapping an item's first block in a quote is a container the content holds.
|
|
22
|
+
*/
|
|
19
23
|
export declare function wrapInQuote(): Command;
|
|
20
|
-
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
+
/**
|
|
25
|
+
* `- ` / `1. `. Beside a list of its kind the line joins it, whatever `N` is typed: a number comes
|
|
26
|
+
* from position. Elsewhere `N. ` is the number the new list counts from; at the head of an item the
|
|
27
|
+
* shorthand is the item's (§`listAtItem`), and a marker the item already shows changes nothing.
|
|
28
|
+
*/
|
|
24
29
|
export declare function wrapInList(ordered: boolean, attrs?: Attrs | null): Command;
|
|
25
30
|
/**
|
|
26
|
-
* `a. `, `(1) `, `(a) `: the markers a nested level draws, typed at the head of a nested
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* else these stay text, being no markdown list marker.
|
|
31
|
+
* `a. `, `(1) `, `(a) `: the markers a nested level draws, typed at the head of a nested item's
|
|
32
|
+
* first line, where the item already is the thing typed. Taken as typed and changing nothing: the
|
|
33
|
+
* marker comes from the item's position and the quill's style for its depth. Anywhere else these
|
|
34
|
+
* stay text.
|
|
31
35
|
*/
|
|
32
36
|
export declare function takeNestedMarker(): Command;
|
|
33
37
|
/**
|
|
34
|
-
* A list pick, at whatever caret the writer has. `atHead` is the shorthand's guard
|
|
35
|
-
*
|
|
38
|
+
* A list pick, at whatever caret the writer has. `atHead` is the shorthand's guard against a prefix
|
|
39
|
+
* eating a dash mid-sentence; a pick is a gesture at the caret.
|
|
36
40
|
*
|
|
37
|
-
* At the end of a non-empty block it opens a fresh empty item below
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* item gesture (§`listAtItem`), offered only where that changes something.
|
|
41
|
+
* At the end of a non-empty block it opens a fresh empty item below (Enter then `- ` as one
|
|
42
|
+
* gesture); anywhere else it wraps the whole block. In an item's first block it is the item gesture
|
|
43
|
+
* (§`listAtItem`), offered only where that changes something.
|
|
41
44
|
*/
|
|
42
45
|
export declare function pickList(ordered: boolean): Command;
|
|
43
46
|
/**
|
|
44
|
-
* The bullet pick where it puts a line under an item one level deeper than the caret
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* retypes the list instead.
|
|
47
|
+
* The bullet pick where it puts a line under an item one level deeper than the caret stood, and
|
|
48
|
+
* nowhere else: the subparagraph pick. Elsewhere the bullet would mint a first-level list, or on a
|
|
49
|
+
* list's first item retype it.
|
|
48
50
|
*/
|
|
49
51
|
export declare function pickSubList(): Command;
|
|
50
52
|
/**
|
|
51
|
-
* Run `command` in place of the text at `[from, to)
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* against the state the delete leaves, which is exactly what its steps were computed
|
|
55
|
-
* for.
|
|
56
|
-
*
|
|
57
|
-
* `null` is a command that declined, and nothing is consumed: the shorthand stays the
|
|
58
|
-
* text it was typed as.
|
|
53
|
+
* Run `command` in place of the text at `[from, to)` as one transaction carrying the delete and the
|
|
54
|
+
* command's steps: two would be two commits, undo steps and recompiles for one gesture. `null` is a
|
|
55
|
+
* command that declined; nothing is consumed and the shorthand stays text.
|
|
59
56
|
*/
|
|
60
57
|
export declare function consuming(state: EditorState, from: number, to: number, command: Command): {
|
|
61
58
|
tr: Transaction;
|
|
62
59
|
produced: Transaction;
|
|
63
60
|
} | null;
|
|
64
|
-
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
61
|
+
/**
|
|
62
|
+
* The body-wide link of the leaf's key chains: `{}` for a schema with no paragraph to mint.
|
|
63
|
+
* Outermost of the structural links.
|
|
64
|
+
*/
|
|
67
65
|
export declare function blockKeymap(schema: Schema): Record<string, Command>;
|
|
@@ -5,8 +5,7 @@ import { canJoin, findWrapping } from 'prosemirror-transform';
|
|
|
5
5
|
import { withinNesting } from './nesting.js';
|
|
6
6
|
import { takesLineBreak } from './schema.js';
|
|
7
7
|
import { joinLists } from './touching.js';
|
|
8
|
-
/** The head of a textblock: where a shorthand fires
|
|
9
|
-
* run is consumed. */
|
|
8
|
+
/** The head of a textblock: where a shorthand fires and a pick lands once its run is consumed. */
|
|
10
9
|
function atHead(state) {
|
|
11
10
|
const { $from, empty } = state.selection;
|
|
12
11
|
return empty && $from.parent.isTextblock && $from.parentOffset === 0;
|
|
@@ -17,11 +16,9 @@ function fits($from, type) {
|
|
|
17
16
|
return $from.node(-1).canReplaceWith($from.index(-1), $from.indexAfter(-1), type);
|
|
18
17
|
}
|
|
19
18
|
/**
|
|
20
|
-
* The first block of an item that already exists: where a list gesture retypes the
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* later block of the item is not this case: wrapping a continuation paragraph is how a
|
|
24
|
-
* sub-list opens under text.
|
|
19
|
+
* The first block of an item that already exists: where a list gesture retypes the item's list
|
|
20
|
+
* rather than wrapping the block, which would mint an item whose only content is another item.
|
|
21
|
+
* Wrapping a later block is how a sub-list opens under text.
|
|
25
22
|
*/
|
|
26
23
|
function openingAnItem($from, item) {
|
|
27
24
|
if (!item || $from.depth < 2)
|
|
@@ -40,12 +37,12 @@ function retype(name, attrs) {
|
|
|
40
37
|
return true;
|
|
41
38
|
};
|
|
42
39
|
}
|
|
43
|
-
/**
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Replace every `hard_break` in the caret's block with a space, ahead of a retype into a type that
|
|
42
|
+
* holds none: `setBlockType` would delete them and glue the words (`breaks.ts`, `decode.ts` make
|
|
43
|
+
* the same space). Break and space are both one position wide, so later replacements stay
|
|
44
|
+
* addressed.
|
|
45
|
+
*/
|
|
49
46
|
function spaceBreaks(tr, $from, type) {
|
|
50
47
|
const br = tr.doc.type.schema.nodes.hard_break;
|
|
51
48
|
if (!br || takesLineBreak(type))
|
|
@@ -57,11 +54,11 @@ function spaceBreaks(tr, $from, type) {
|
|
|
57
54
|
at += child.nodeSize;
|
|
58
55
|
});
|
|
59
56
|
}
|
|
60
|
-
/**
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
|
|
57
|
+
/**
|
|
58
|
+
* `wrappingInputRule`'s body: wrap the block range at `pos`, then join a sibling of the same type
|
|
59
|
+
* (a list on both sides, a quote the one above; `touching.ts`). False where no wrap fits or it
|
|
60
|
+
* nests past `MAX_NESTING_DEPTH` (`nesting.ts`).
|
|
61
|
+
*/
|
|
65
62
|
function wrapAt(tr, pos, type, attrs) {
|
|
66
63
|
const range = tr.doc.resolve(pos).blockRange();
|
|
67
64
|
const wrapping = range && findWrapping(range, type, attrs);
|
|
@@ -76,15 +73,18 @@ function wrapAt(tr, pos, type, attrs) {
|
|
|
76
73
|
tr.join(range.start);
|
|
77
74
|
return withinNesting(tr.doc);
|
|
78
75
|
}
|
|
79
|
-
/**
|
|
80
|
-
*
|
|
76
|
+
/**
|
|
77
|
+
* `# `: the heading `level` deep. `list_item` is `block+`, so a heading inside an item is a shape
|
|
78
|
+
* `importMarkdown` produces from `- # title`.
|
|
79
|
+
*/
|
|
81
80
|
export function toHeading(level) {
|
|
82
81
|
return retype('heading', { level });
|
|
83
82
|
}
|
|
84
|
-
/**
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
83
|
+
/**
|
|
84
|
+
* A fence, carrying `attrs` (its `lang`). The exit paragraph after it exists because a gap cursor
|
|
85
|
+
* will not sit beside a code block, so a fence at the end of a body would leave the caret nowhere
|
|
86
|
+
* to go. The caret stays in the fence.
|
|
87
|
+
*/
|
|
88
88
|
export function toCodeBlock(attrs) {
|
|
89
89
|
return (state, dispatch) => {
|
|
90
90
|
const { code_block: code, paragraph } = state.schema.nodes;
|
|
@@ -99,10 +99,11 @@ export function toCodeBlock(attrs) {
|
|
|
99
99
|
return true;
|
|
100
100
|
};
|
|
101
101
|
}
|
|
102
|
-
/**
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
102
|
+
/**
|
|
103
|
+
* `---`. A divider is a whole block, so this replaces its textblock: `horizontal_rule` holds no
|
|
104
|
+
* content to retype into, and only an empty block may be replaced, anything else being a paragraph
|
|
105
|
+
* being edited.
|
|
106
|
+
*/
|
|
106
107
|
export function insertDivider() {
|
|
107
108
|
return (state, dispatch) => {
|
|
108
109
|
const { horizontal_rule: rule, paragraph } = state.schema.nodes;
|
|
@@ -121,9 +122,9 @@ export function insertDivider() {
|
|
|
121
122
|
return true;
|
|
122
123
|
};
|
|
123
124
|
}
|
|
124
|
-
/**
|
|
125
|
-
*
|
|
126
|
-
|
|
125
|
+
/**
|
|
126
|
+
* `> `. No item guard: wrapping an item's first block in a quote is a container the content holds.
|
|
127
|
+
*/
|
|
127
128
|
export function wrapInQuote() {
|
|
128
129
|
return (state, dispatch) => {
|
|
129
130
|
const quote = state.schema.nodes.blockquote;
|
|
@@ -137,10 +138,11 @@ export function wrapInQuote() {
|
|
|
137
138
|
return true;
|
|
138
139
|
};
|
|
139
140
|
}
|
|
140
|
-
/**
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
141
|
+
/**
|
|
142
|
+
* `- ` / `1. `. Beside a list of its kind the line joins it, whatever `N` is typed: a number comes
|
|
143
|
+
* from position. Elsewhere `N. ` is the number the new list counts from; at the head of an item the
|
|
144
|
+
* shorthand is the item's (§`listAtItem`), and a marker the item already shows changes nothing.
|
|
145
|
+
*/
|
|
144
146
|
export function wrapInList(ordered, attrs = null) {
|
|
145
147
|
return (state, dispatch) => {
|
|
146
148
|
if (!atHead(state))
|
|
@@ -152,11 +154,10 @@ export function wrapInList(ordered, attrs = null) {
|
|
|
152
154
|
};
|
|
153
155
|
}
|
|
154
156
|
/**
|
|
155
|
-
* `a. `, `(1) `, `(a) `: the markers a nested level draws, typed at the head of a nested
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
* else these stay text, being no markdown list marker.
|
|
157
|
+
* `a. `, `(1) `, `(a) `: the markers a nested level draws, typed at the head of a nested item's
|
|
158
|
+
* first line, where the item already is the thing typed. Taken as typed and changing nothing: the
|
|
159
|
+
* marker comes from the item's position and the quill's style for its depth. Anywhere else these
|
|
160
|
+
* stay text.
|
|
160
161
|
*/
|
|
161
162
|
export function takeNestedMarker() {
|
|
162
163
|
return (state, dispatch) => {
|
|
@@ -171,21 +172,16 @@ export function takeNestedMarker() {
|
|
|
171
172
|
};
|
|
172
173
|
}
|
|
173
174
|
/**
|
|
174
|
-
* A list gesture in an item's first block. On a list's first item it retypes the list
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
* whole memo turned to bullets. A sub-list already standing there of that kind takes the
|
|
181
|
-
* item as its next.
|
|
175
|
+
* A list gesture in an item's first block. On a list's first item it retypes the whole list;
|
|
176
|
+
* `number` is the shorthand's `N`, the list's `start`, the one door back to 1 for a list that
|
|
177
|
+
* arrived counting from elsewhere. On a later item, a list of the other kind is a sub-list: the
|
|
178
|
+
* item sinks under the one above, as Tab sinks it, into a list of that kind (`- ` in a numbered
|
|
179
|
+
* paragraph is its first lettered subparagraph). A sub-list already standing there takes the item
|
|
180
|
+
* as its next.
|
|
182
181
|
*
|
|
183
|
-
* A gesture that changes nothing
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
* `2. Second` into the second item meant the number the item already shows, and an item
|
|
187
|
-
* reading `2. 2. Second` is the one outcome no writer typed for. Backspace on the press
|
|
188
|
-
* after gives the text back.
|
|
182
|
+
* A gesture that changes nothing goes unoffered as a pick. As a shorthand (`take`) it is claimed
|
|
183
|
+
* and consumes the run, since `2. 2. Second` is an outcome no writer typed for; Backspace on the
|
|
184
|
+
* press after gives the text back.
|
|
189
185
|
*/
|
|
190
186
|
function listAtItem(ordered, number, take = false) {
|
|
191
187
|
return (state, dispatch) => {
|
|
@@ -229,13 +225,12 @@ function listAtItem(ordered, number, take = false) {
|
|
|
229
225
|
};
|
|
230
226
|
}
|
|
231
227
|
/**
|
|
232
|
-
* A list pick, at whatever caret the writer has. `atHead` is the shorthand's guard
|
|
233
|
-
*
|
|
228
|
+
* A list pick, at whatever caret the writer has. `atHead` is the shorthand's guard against a prefix
|
|
229
|
+
* eating a dash mid-sentence; a pick is a gesture at the caret.
|
|
234
230
|
*
|
|
235
|
-
* At the end of a non-empty block it opens a fresh empty item below
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
* item gesture (§`listAtItem`), offered only where that changes something.
|
|
231
|
+
* At the end of a non-empty block it opens a fresh empty item below (Enter then `- ` as one
|
|
232
|
+
* gesture); anywhere else it wraps the whole block. In an item's first block it is the item gesture
|
|
233
|
+
* (§`listAtItem`), offered only where that changes something.
|
|
239
234
|
*/
|
|
240
235
|
export function pickList(ordered) {
|
|
241
236
|
return (state, dispatch) => {
|
|
@@ -266,10 +261,9 @@ function itemDepth($pos, item) {
|
|
|
266
261
|
return n;
|
|
267
262
|
}
|
|
268
263
|
/**
|
|
269
|
-
* The bullet pick where it puts a line under an item one level deeper than the caret
|
|
270
|
-
*
|
|
271
|
-
*
|
|
272
|
-
* retypes the list instead.
|
|
264
|
+
* The bullet pick where it puts a line under an item one level deeper than the caret stood, and
|
|
265
|
+
* nowhere else: the subparagraph pick. Elsewhere the bullet would mint a first-level list, or on a
|
|
266
|
+
* list's first item retype it.
|
|
273
267
|
*/
|
|
274
268
|
export function pickSubList() {
|
|
275
269
|
const pick = pickList(false);
|
|
@@ -287,9 +281,10 @@ export function pickSubList() {
|
|
|
287
281
|
return true;
|
|
288
282
|
};
|
|
289
283
|
}
|
|
290
|
-
/**
|
|
291
|
-
*
|
|
292
|
-
*
|
|
284
|
+
/**
|
|
285
|
+
* Wrap the caret's whole block in a list wherever the caret sits; the wrap opens at the block's
|
|
286
|
+
* head, so it joins neighbouring lists as the shorthand does.
|
|
287
|
+
*/
|
|
293
288
|
function wrapBlock(state, dispatch, ordered, attrs) {
|
|
294
289
|
const { paragraph, list_item: item } = state.schema.nodes;
|
|
295
290
|
const list = state.schema.nodes[ordered ? 'ordered_list' : 'bullet_list'];
|
|
@@ -300,9 +295,8 @@ function wrapBlock(state, dispatch, ordered, attrs) {
|
|
|
300
295
|
return listAtItem(ordered, null)(state, dispatch);
|
|
301
296
|
const pos = $from.start();
|
|
302
297
|
const tr = state.tr;
|
|
303
|
-
// A paragraph item wherever this fires:
|
|
304
|
-
//
|
|
305
|
-
// that shape. Positions survive the retype — same content, same size.
|
|
298
|
+
// A paragraph item wherever this fires: a wrap keeping a heading would be a second door onto
|
|
299
|
+
// the `list_item > heading` shape `# ` mints. Positions survive the retype.
|
|
306
300
|
if ($from.parent.type !== paragraph)
|
|
307
301
|
tr.setBlockType(pos, pos, paragraph);
|
|
308
302
|
if (!wrapAt(tr, pos, list, attrs))
|
|
@@ -311,14 +305,9 @@ function wrapBlock(state, dispatch, ordered, attrs) {
|
|
|
311
305
|
return true;
|
|
312
306
|
}
|
|
313
307
|
/**
|
|
314
|
-
* Run `command` in place of the text at `[from, to)
|
|
315
|
-
*
|
|
316
|
-
*
|
|
317
|
-
* against the state the delete leaves, which is exactly what its steps were computed
|
|
318
|
-
* for.
|
|
319
|
-
*
|
|
320
|
-
* `null` is a command that declined, and nothing is consumed: the shorthand stays the
|
|
321
|
-
* text it was typed as.
|
|
308
|
+
* Run `command` in place of the text at `[from, to)` as one transaction carrying the delete and the
|
|
309
|
+
* command's steps: two would be two commits, undo steps and recompiles for one gesture. `null` is a
|
|
310
|
+
* command that declined; nothing is consumed and the shorthand stays text.
|
|
322
311
|
*/
|
|
323
312
|
export function consuming(state, from, to, command) {
|
|
324
313
|
const tr = state.tr.delete(from, to);
|
|
@@ -333,24 +322,20 @@ export function consuming(state, from, to, command) {
|
|
|
333
322
|
tr.setSelection(Selection.fromJSON(tr.doc, produced.selection.toJSON()));
|
|
334
323
|
return { tr, produced };
|
|
335
324
|
}
|
|
336
|
-
/** The head of the body's first block: one position per open token above the caret
|
|
337
|
-
* and nothing before it. */
|
|
325
|
+
/** The head of the body's first block: one position per open token above the caret. */
|
|
338
326
|
function atBodyStart($from) {
|
|
339
327
|
return $from.pos === $from.depth;
|
|
340
328
|
}
|
|
341
329
|
/**
|
|
342
|
-
* Enter at the very start of a body whose first block takes no caret above it → an
|
|
343
|
-
*
|
|
330
|
+
* Enter at the very start of a body whose first block takes no caret above it → an empty paragraph
|
|
331
|
+
* there, the caret staying with the text it pushed down.
|
|
344
332
|
*
|
|
345
|
-
*
|
|
346
|
-
*
|
|
347
|
-
* `> `) put one first, and a document carrying one there could never be given a title.
|
|
333
|
+
* `prosemirror-gapcursor` declines to sit beside a code block or a quote, and two keystrokes on an
|
|
334
|
+
* empty body (` ``` `, `> `) put one first, leaving a document that could never be given a title.
|
|
348
335
|
*
|
|
349
|
-
* Declines
|
|
350
|
-
*
|
|
351
|
-
*
|
|
352
|
-
* item, as at every item, and the empty item's own Enter lifts it out to the paragraph a
|
|
353
|
-
* title takes. A fence opening that item is the fence case and takes the paragraph.
|
|
336
|
+
* Declines where the first block is a plain textblock (its Enter-split leaves a paragraph above) or
|
|
337
|
+
* empty (the links after answer). An item's first line of prose declines too: Enter there is the
|
|
338
|
+
* list's new first item. A fence opening that item takes the paragraph.
|
|
354
339
|
*/
|
|
355
340
|
const paragraphAtBodyStart = (state, dispatch) => {
|
|
356
341
|
const { paragraph, list_item: item } = state.schema.nodes;
|
|
@@ -367,16 +352,10 @@ const paragraphAtBodyStart = (state, dispatch) => {
|
|
|
367
352
|
return true;
|
|
368
353
|
};
|
|
369
354
|
/**
|
|
370
|
-
* Enter in an empty fence that opens the body → the fence, retyped to a paragraph.
|
|
371
|
-
*
|
|
372
|
-
*
|
|
373
|
-
*
|
|
374
|
-
* `newlineInCode` instead — a line inside the block, in the direction already open —
|
|
375
|
-
* so the empty fence a body's first ` ``` ` mints holds a caret with nothing above it
|
|
376
|
-
* and no key that mints one.
|
|
377
|
-
*
|
|
378
|
-
* Retyping rather than inserting above, for the reason those exits leave one paragraph
|
|
379
|
-
* and not two: an empty fence carries nothing to keep.
|
|
355
|
+
* Enter in an empty fence that opens the body → the fence, retyped to a paragraph. An empty first
|
|
356
|
+
* item exits its list and an empty first quoted paragraph lifts out of the quote, each leaving the
|
|
357
|
+
* one paragraph a caret above needs; a fence would answer `newlineInCode` and leave no key that
|
|
358
|
+
* mints one. Retyped rather than inserted above: an empty fence carries nothing to keep.
|
|
380
359
|
*/
|
|
381
360
|
const paragraphFromEmptyFence = (state, dispatch) => {
|
|
382
361
|
const paragraph = state.schema.nodes.paragraph;
|
|
@@ -391,15 +370,10 @@ const paragraphFromEmptyFence = (state, dispatch) => {
|
|
|
391
370
|
return true;
|
|
392
371
|
};
|
|
393
372
|
/**
|
|
394
|
-
* Enter over a selection spanning two textblocks: take the selection, then split
|
|
395
|
-
*
|
|
396
|
-
*
|
|
397
|
-
*
|
|
398
|
-
* It deletes the selection inside its own transaction and then reads the default
|
|
399
|
-
* block's fit off the *pre-delete* document — `$from.node(splitDepth - 1)` against an
|
|
400
|
-
* index resolved in the new one — so where the range starts at the head of a
|
|
401
|
-
* `defining` block and ends inside a list, it retypes a `list_item` to a paragraph
|
|
402
|
-
* and throws `RangeError` out of the keystroke.
|
|
373
|
+
* Enter over a selection spanning two textblocks: take the selection, then split what is left, in
|
|
374
|
+
* one transaction. Upstream's `splitBlock` reads the default block's fit off the pre-delete
|
|
375
|
+
* document, so where the range starts at the head of a `defining` block and ends inside a list it
|
|
376
|
+
* retypes a `list_item` to a paragraph and throws `RangeError`.
|
|
403
377
|
*/
|
|
404
378
|
const splitAcrossBlocks = (state, dispatch) => {
|
|
405
379
|
const { $from, $to, empty } = state.selection;
|
|
@@ -417,21 +391,14 @@ const splitAcrossBlocks = (state, dispatch) => {
|
|
|
417
391
|
return true;
|
|
418
392
|
};
|
|
419
393
|
/**
|
|
420
|
-
* Delete on an empty textblock → take the line, whatever stands below moving up
|
|
421
|
-
*
|
|
422
|
-
*
|
|
423
|
-
*
|
|
424
|
-
* into it — a list's first item lifted out to fill it, its marker gone — and the atom
|
|
425
|
-
* link arms an island for the press after. Upstream takes the line only where the
|
|
426
|
-
* sibling holds the same kind of content, so a heading below keeps its level where a
|
|
427
|
-
* bullet loses its marker.
|
|
394
|
+
* Delete on an empty textblock → take the line, whatever stands below moving up whole and keeping
|
|
395
|
+
* what it is. The links below leave the line standing: the base keymap joins the block below into
|
|
396
|
+
* it (a list's first item loses its marker), and upstream takes the line only where the sibling
|
|
397
|
+
* holds the same kind of content.
|
|
428
398
|
*
|
|
429
|
-
* Declines where the parent cannot spare the block
|
|
430
|
-
*
|
|
431
|
-
*
|
|
432
|
-
* carries no text to lose. Declines with nothing after it too: a line with no next
|
|
433
|
-
* line is Backspace's. The line was the one thing between two lists of a kind, they
|
|
434
|
-
* are one list after it.
|
|
399
|
+
* Declines where the parent cannot spare the block (an empty item or quote is the whole of what
|
|
400
|
+
* holds it; an empty fence is spared) and with nothing after it, which is Backspace's. The line may
|
|
401
|
+
* have been the one thing between two lists of a kind; they are one list after it.
|
|
435
402
|
*/
|
|
436
403
|
const takeEmptyLine = (state, dispatch) => {
|
|
437
404
|
const { $from, empty } = state.selection;
|
|
@@ -450,10 +417,9 @@ const takeEmptyLine = (state, dispatch) => {
|
|
|
450
417
|
return true;
|
|
451
418
|
};
|
|
452
419
|
/**
|
|
453
|
-
* Backspace at a heading's head → a paragraph, where it stands
|
|
454
|
-
*
|
|
455
|
-
*
|
|
456
|
-
* and lose the heading with it, and at the body's start it does nothing at all.
|
|
420
|
+
* Backspace at a heading's head → a paragraph, where it stands; the press after is the join. The
|
|
421
|
+
* base keymap's join would merge the heading's text into the block above and lose the heading, and
|
|
422
|
+
* at the body's start does nothing.
|
|
457
423
|
*/
|
|
458
424
|
const unheading = (state, dispatch) => {
|
|
459
425
|
const paragraph = state.schema.nodes.paragraph;
|
|
@@ -465,9 +431,10 @@ const unheading = (state, dispatch) => {
|
|
|
465
431
|
dispatch?.(state.tr.setBlockType($from.pos, $from.pos, paragraph).scrollIntoView());
|
|
466
432
|
return true;
|
|
467
433
|
};
|
|
468
|
-
/**
|
|
469
|
-
*
|
|
470
|
-
*
|
|
434
|
+
/**
|
|
435
|
+
* The body-wide link of the leaf's key chains: `{}` for a schema with no paragraph to mint.
|
|
436
|
+
* Outermost of the structural links.
|
|
437
|
+
*/
|
|
471
438
|
export function blockKeymap(schema) {
|
|
472
439
|
if (!schema.nodes.paragraph)
|
|
473
440
|
return {};
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import type { Schema } from 'prosemirror-model';
|
|
2
2
|
import { type Command } from 'prosemirror-state';
|
|
3
3
|
/**
|
|
4
|
-
* The `code_block` link of the body's key chains: `{}` for the one-line and plain
|
|
5
|
-
*
|
|
4
|
+
* The `code_block` link of the body's key chains: `{}` for the one-line and plain schemas, which
|
|
5
|
+
* declare no code node.
|
|
6
6
|
*
|
|
7
|
-
* `Enter` is upstream's `newlineInCode`,
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* Every command here declines away from a code block — inside one for the keys about
|
|
13
|
-
* its text and its last line, against one for the two about its edge — so the list
|
|
14
|
-
* links keep the keys elsewhere.
|
|
7
|
+
* `Enter` is upstream's `newlineInCode`, load-bearing: inside a `list_item > code_block` the list
|
|
8
|
+
* link's `splitListItem` would otherwise split the item in two. `Shift-Enter` is the same command:
|
|
9
|
+
* the line break the key means elsewhere (`breaks.ts`) is, inside a fence, the newline Enter takes.
|
|
10
|
+
* Every command here declines away from a code block (inside it for the text and last-line keys,
|
|
11
|
+
* against it for the two edge keys), leaving the list links the keys elsewhere.
|
|
15
12
|
*/
|
|
16
13
|
export declare function codeKeymap(schema: Schema): Record<string, Command>;
|