@blocknote/core 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/dist/blocknote.cjs +10 -10
- package/dist/blocknote.cjs.map +1 -1
- package/dist/blocknote.js +1327 -1283
- package/dist/blocknote.js.map +1 -1
- package/dist/locales.cjs +1 -1
- package/dist/locales.cjs.map +1 -1
- package/dist/locales.js +10 -10
- package/dist/locales.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/webpack-stats.json +1 -1
- package/package.json +1 -5
- package/src/api/positionMapping.test.ts +370 -0
- package/src/api/positionMapping.ts +112 -0
- package/src/editor/BlockNoteEditor.ts +1 -0
- package/src/extensions/SuggestionMenu/SuggestionPlugin.ts +17 -7
- package/src/i18n/locales/de.ts +10 -10
- package/types/src/api/positionMapping.d.ts +25 -0
- package/types/src/api/positionMapping.test.d.ts +1 -0
- package/types/src/blocks/CodeBlockContent/defaultSupportedLanguages.d.ts +0 -6
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
StyleSchema,
|
|
11
11
|
} from "../../schema/index.js";
|
|
12
12
|
import { EventEmitter } from "../../util/EventEmitter.js";
|
|
13
|
+
import { trackPosition } from "../../api/positionMapping.js";
|
|
13
14
|
|
|
14
15
|
const findBlock = findParentNode((node) => node.type.name === "blockContainer");
|
|
15
16
|
|
|
@@ -129,7 +130,7 @@ class SuggestionMenuView<
|
|
|
129
130
|
.focus()
|
|
130
131
|
.deleteRange({
|
|
131
132
|
from:
|
|
132
|
-
this.pluginState.queryStartPos
|
|
133
|
+
this.pluginState.queryStartPos() -
|
|
133
134
|
(this.pluginState.deleteTriggerCharacter
|
|
134
135
|
? this.pluginState.triggerCharacter!.length
|
|
135
136
|
: 0),
|
|
@@ -143,7 +144,7 @@ type SuggestionPluginState =
|
|
|
143
144
|
| {
|
|
144
145
|
triggerCharacter: string;
|
|
145
146
|
deleteTriggerCharacter: boolean;
|
|
146
|
-
queryStartPos: number;
|
|
147
|
+
queryStartPos: () => number;
|
|
147
148
|
query: string;
|
|
148
149
|
decorationId: string;
|
|
149
150
|
ignoreQueryLength?: boolean;
|
|
@@ -220,13 +221,22 @@ export class SuggestionMenuProseMirrorPlugin<
|
|
|
220
221
|
suggestionPluginTransactionMeta !== null &&
|
|
221
222
|
prev === undefined
|
|
222
223
|
) {
|
|
224
|
+
const trackedPosition = trackPosition(
|
|
225
|
+
editor,
|
|
226
|
+
newState.selection.from -
|
|
227
|
+
// Need to account for the trigger char that was inserted, so we offset the position by the length of the trigger character.
|
|
228
|
+
suggestionPluginTransactionMeta.triggerCharacter.length
|
|
229
|
+
);
|
|
223
230
|
return {
|
|
224
231
|
triggerCharacter:
|
|
225
232
|
suggestionPluginTransactionMeta.triggerCharacter,
|
|
226
233
|
deleteTriggerCharacter:
|
|
227
234
|
suggestionPluginTransactionMeta.deleteTriggerCharacter !==
|
|
228
235
|
false,
|
|
229
|
-
queryStartPos
|
|
236
|
+
// When reading the queryStartPos, we offset the result by the length of the trigger character, to make it easy on the caller
|
|
237
|
+
queryStartPos: () =>
|
|
238
|
+
trackedPosition() +
|
|
239
|
+
suggestionPluginTransactionMeta.triggerCharacter.length,
|
|
230
240
|
query: "",
|
|
231
241
|
decorationId: `id_${Math.floor(Math.random() * 0xffffffff)}`,
|
|
232
242
|
ignoreQueryLength:
|
|
@@ -252,7 +262,7 @@ export class SuggestionMenuProseMirrorPlugin<
|
|
|
252
262
|
transaction.getMeta("pointer") ||
|
|
253
263
|
// Moving the caret before the character which triggered the menu should hide it.
|
|
254
264
|
(prev.triggerCharacter !== undefined &&
|
|
255
|
-
newState.selection.from < prev.queryStartPos
|
|
265
|
+
newState.selection.from < prev.queryStartPos())
|
|
256
266
|
) {
|
|
257
267
|
return undefined;
|
|
258
268
|
}
|
|
@@ -261,7 +271,7 @@ export class SuggestionMenuProseMirrorPlugin<
|
|
|
261
271
|
|
|
262
272
|
// Updates the current query.
|
|
263
273
|
next.query = newState.doc.textBetween(
|
|
264
|
-
prev.queryStartPos
|
|
274
|
+
prev.queryStartPos(),
|
|
265
275
|
newState.selection.from
|
|
266
276
|
);
|
|
267
277
|
|
|
@@ -324,9 +334,9 @@ export class SuggestionMenuProseMirrorPlugin<
|
|
|
324
334
|
// Creates an inline decoration around the trigger character.
|
|
325
335
|
return DecorationSet.create(state.doc, [
|
|
326
336
|
Decoration.inline(
|
|
327
|
-
suggestionPluginState.queryStartPos
|
|
337
|
+
suggestionPluginState.queryStartPos() -
|
|
328
338
|
suggestionPluginState.triggerCharacter!.length,
|
|
329
|
-
suggestionPluginState.queryStartPos
|
|
339
|
+
suggestionPluginState.queryStartPos(),
|
|
330
340
|
{
|
|
331
341
|
nodeName: "span",
|
|
332
342
|
class: "bn-suggestion-decorator",
|
package/src/i18n/locales/de.ts
CHANGED
|
@@ -24,19 +24,19 @@ export const de: Dictionary = {
|
|
|
24
24
|
title: "Zitat",
|
|
25
25
|
subtext: "Zitat oder Auszug",
|
|
26
26
|
aliases: ["quotation", "blockquote", "bq"],
|
|
27
|
-
group: "Grundlegende
|
|
27
|
+
group: "Grundlegende Blöcke",
|
|
28
28
|
},
|
|
29
29
|
numbered_list: {
|
|
30
30
|
title: "Nummerierte Liste",
|
|
31
31
|
subtext: "Liste mit nummerierten Elementen",
|
|
32
32
|
aliases: ["ol", "li", "liste", "nummerierteliste", "nummerierte liste"],
|
|
33
|
-
group: "Grundlegende
|
|
33
|
+
group: "Grundlegende Blöcke",
|
|
34
34
|
},
|
|
35
35
|
bullet_list: {
|
|
36
36
|
title: "Aufzählungsliste",
|
|
37
37
|
subtext: "Liste mit unnummerierten Elementen",
|
|
38
38
|
aliases: ["ul", "li", "liste", "aufzählungsliste", "aufzählung liste"],
|
|
39
|
-
group: "Grundlegende
|
|
39
|
+
group: "Grundlegende Blöcke",
|
|
40
40
|
},
|
|
41
41
|
check_list: {
|
|
42
42
|
title: "Checkliste",
|
|
@@ -50,19 +50,19 @@ export const de: Dictionary = {
|
|
|
50
50
|
"geprüfte liste",
|
|
51
51
|
"kontrollkästchen",
|
|
52
52
|
],
|
|
53
|
-
group: "Grundlegende
|
|
53
|
+
group: "Grundlegende Blöcke",
|
|
54
54
|
},
|
|
55
55
|
paragraph: {
|
|
56
56
|
title: "Absatz",
|
|
57
57
|
subtext: "Der Hauptteil Ihres Dokuments",
|
|
58
58
|
aliases: ["p", "absatz"],
|
|
59
|
-
group: "Grundlegende
|
|
59
|
+
group: "Grundlegende Blöcke",
|
|
60
60
|
},
|
|
61
61
|
code_block: {
|
|
62
62
|
title: "Codeblock",
|
|
63
63
|
subtext: "Codeblock mit Syntaxhervorhebung",
|
|
64
64
|
aliases: ["code", "pre"],
|
|
65
|
-
group: "Grundlegende
|
|
65
|
+
group: "Grundlegende Blöcke",
|
|
66
66
|
},
|
|
67
67
|
page_break: {
|
|
68
68
|
title: "Seitenumbruch",
|
|
@@ -137,9 +137,9 @@ export const de: Dictionary = {
|
|
|
137
137
|
bulletListItem: "Liste",
|
|
138
138
|
numberedListItem: "Liste",
|
|
139
139
|
checkListItem: "Liste",
|
|
140
|
-
new_comment: "Einen Kommentar schreiben
|
|
141
|
-
edit_comment: "Kommentar bearbeiten
|
|
142
|
-
comment_reply: "Kommentar hinzufügen
|
|
140
|
+
new_comment: "Einen Kommentar schreiben …",
|
|
141
|
+
edit_comment: "Kommentar bearbeiten …",
|
|
142
|
+
comment_reply: "Kommentar hinzufügen …",
|
|
143
143
|
},
|
|
144
144
|
file_blocks: {
|
|
145
145
|
image: {
|
|
@@ -178,7 +178,7 @@ export const de: Dictionary = {
|
|
|
178
178
|
},
|
|
179
179
|
suggestion_menu: {
|
|
180
180
|
no_items_title: "Keine Elemente gefunden",
|
|
181
|
-
loading: "Laden…",
|
|
181
|
+
loading: "Laden …",
|
|
182
182
|
},
|
|
183
183
|
color_picker: {
|
|
184
184
|
text_title: "Text",
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { BlockNoteEditor } from "../editor/BlockNoteEditor.js";
|
|
2
|
+
/**
|
|
3
|
+
* This is used to keep track of positions of elements in the editor.
|
|
4
|
+
* It is needed because y-prosemirror's sync plugin can disrupt normal prosemirror position mapping.
|
|
5
|
+
*
|
|
6
|
+
* It is specifically made to be able to be used whether the editor is being used in a collaboratively, or single user, providing the same API.
|
|
7
|
+
*
|
|
8
|
+
* @param editor The editor to track the position of.
|
|
9
|
+
* @param position The position to track.
|
|
10
|
+
* @param side The side of the position to track. "left" is the default. "right" would move with the change if the change is in the right direction.
|
|
11
|
+
* @returns A function that returns the position of the element.
|
|
12
|
+
*/
|
|
13
|
+
export declare function trackPosition(
|
|
14
|
+
/**
|
|
15
|
+
* The editor to track the position of.
|
|
16
|
+
*/
|
|
17
|
+
editor: BlockNoteEditor<any, any, any>,
|
|
18
|
+
/**
|
|
19
|
+
* The position to track.
|
|
20
|
+
*/
|
|
21
|
+
position: number,
|
|
22
|
+
/**
|
|
23
|
+
* This is the side of the position to track. "left" is the default. "right" would move with the change if the change is in the right direction.
|
|
24
|
+
*/
|
|
25
|
+
side?: "left" | "right"): () => number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|