@blocknote/core 0.54.1 → 0.55.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/BlockNoteExtension-BJCLnwrE.cjs.map +1 -1
- package/dist/BlockNoteExtension-CbvDA0F7.js.map +1 -1
- package/dist/blocknote.cjs +1 -1
- package/dist/blocknote.js +6 -6
- package/dist/blocks-DLgTreVu.cjs +12 -0
- package/dist/blocks-DLgTreVu.cjs.map +1 -0
- package/dist/{blocks-Dol85hpH.js → blocks-DaEUT0O1.js} +346 -340
- package/dist/blocks-DaEUT0O1.js.map +1 -0
- package/dist/blocks.cjs +1 -1
- package/dist/blocks.js +1 -1
- package/dist/comments.cjs +1 -1
- package/dist/comments.cjs.map +1 -1
- package/dist/comments.js +62 -36
- package/dist/comments.js.map +1 -1
- package/dist/{en-uzHzj6eH.js → en-BAn9gxr-.js} +5 -2
- package/dist/{en-uzHzj6eH.js.map → en-BAn9gxr-.js.map} +1 -1
- package/dist/{en-BuzSuuTq.cjs → en-CHnrV5l8.cjs} +2 -2
- package/dist/{en-BuzSuuTq.cjs.map → en-CHnrV5l8.cjs.map} +1 -1
- package/dist/{extensions-D6JcJCwd.js → extensions-B1JQURVF.js} +221 -221
- package/dist/extensions-B1JQURVF.js.map +1 -0
- package/dist/{extensions-B7Rsp_Ft.cjs → extensions-CZkqKzJO.cjs} +3 -3
- package/dist/extensions-CZkqKzJO.cjs.map +1 -0
- package/dist/extensions.cjs +1 -1
- package/dist/extensions.js +2 -2
- package/dist/locales.cjs +1 -1
- package/dist/locales.cjs.map +1 -1
- package/dist/locales.js +89 -23
- package/dist/locales.js.map +1 -1
- package/dist/{src-Buuo5l7X.js → src-D5w0XAHX.js} +702 -640
- package/dist/src-D5w0XAHX.js.map +1 -0
- package/dist/{src-C54Ok9E0.cjs → src-th5uZEvx.cjs} +8 -8
- package/dist/src-th5uZEvx.cjs.map +1 -0
- package/dist/webpack-stats.json +1 -1
- package/dist/y.cjs +1 -1
- package/dist/y.js +3 -3
- package/dist/yjs.cjs +1 -1
- package/dist/yjs.js +1 -1
- package/package.json +12 -12
- package/src/comments/CommentEditorSubmitExtension.test.ts +141 -0
- package/src/comments/CommentEditorSubmitExtension.ts +56 -0
- package/src/comments/extension.ts +8 -0
- package/src/comments/index.ts +1 -0
- package/src/editor/BlockNoteEditor.ts +94 -41
- package/src/editor/BlockNoteExtension.ts +6 -1
- package/src/editor/managers/EventManager.browser.test.ts +334 -0
- package/src/editor/managers/EventManager.ts +128 -31
- package/src/editor/managers/ExtensionManager/ExtensionManager.test.ts +88 -1
- package/src/editor/managers/ExtensionManager/index.ts +30 -7
- package/src/editor/managers/StyleManager.browser.test.ts +122 -0
- package/src/editor/managers/StyleManager.test.ts +98 -0
- package/src/editor/managers/StyleManager.ts +31 -15
- package/src/editor/managers/index.ts +1 -0
- package/src/extensions/FormattingToolbar/FormattingToolbar.ts +23 -0
- package/src/extensions/SideMenu/SideMenu.ts +15 -0
- package/src/extensions/TableHandles/TableHandles.browser.test.ts +3 -1
- package/src/i18n/locales/ar.ts +1 -0
- package/src/i18n/locales/de.ts +1 -0
- package/src/i18n/locales/en.ts +1 -0
- package/src/i18n/locales/es.ts +1 -0
- package/src/i18n/locales/fa.ts +1 -0
- package/src/i18n/locales/fr.ts +1 -0
- package/src/i18n/locales/he.ts +1 -0
- package/src/i18n/locales/hr.ts +1 -0
- package/src/i18n/locales/is.ts +1 -0
- package/src/i18n/locales/it.ts +1 -0
- package/src/i18n/locales/ja.ts +1 -0
- package/src/i18n/locales/ko.ts +1 -0
- package/src/i18n/locales/nl.ts +1 -0
- package/src/i18n/locales/no.ts +1 -0
- package/src/i18n/locales/pl.ts +1 -0
- package/src/i18n/locales/pt.ts +1 -0
- package/src/i18n/locales/ru.ts +1 -0
- package/src/i18n/locales/sk.ts +1 -0
- package/src/i18n/locales/uk.ts +1 -0
- package/src/i18n/locales/uz.ts +1 -0
- package/src/i18n/locales/vi.ts +1 -0
- package/src/i18n/locales/zh-tw.ts +1 -0
- package/src/i18n/locales/zh.ts +1 -0
- package/src/index.ts +1 -0
- package/src/util/browser.ts +24 -0
- package/types/src/blocks/Code/helpers/extensions/CodeKeyboardShortcutsExtension.d.ts +4 -0
- package/types/src/comments/CommentEditorSubmitExtension.d.ts +19 -0
- package/types/src/comments/CommentEditorSubmitExtension.test.d.ts +1 -0
- package/types/src/comments/extension.d.ts +7 -0
- package/types/src/comments/index.d.ts +1 -0
- package/types/src/editor/BlockNoteEditor.d.ts +52 -19
- package/types/src/editor/BlockNoteExtension.d.ts +3 -0
- package/types/src/editor/managers/EventManager.browser.test.d.ts +1 -0
- package/types/src/editor/managers/EventManager.d.ts +55 -0
- package/types/src/editor/managers/StyleManager.browser.test.d.ts +1 -0
- package/types/src/editor/managers/StyleManager.d.ts +4 -2
- package/types/src/editor/managers/StyleManager.test.d.ts +1 -0
- package/types/src/editor/managers/index.d.ts +1 -0
- package/types/src/extensions/SourceBlockWithPreview/SourceBlockWithPreview.d.ts +3 -0
- package/types/src/extensions/SourceInlineContentWithPreview/SourceInlineContentWithPreview.d.ts +1 -0
- package/types/src/i18n/locales/en.d.ts +1 -0
- package/types/src/i18n/locales/fa.d.ts +1 -0
- package/types/src/i18n/locales/sk.d.ts +1 -0
- package/types/src/index.d.ts +1 -0
- package/types/src/util/browser.d.ts +2 -0
- package/dist/blocks-CTB_5Vyj.cjs +0 -12
- package/dist/blocks-CTB_5Vyj.cjs.map +0 -1
- package/dist/blocks-Dol85hpH.js.map +0 -1
- package/dist/extensions-B7Rsp_Ft.cjs.map +0 -1
- package/dist/extensions-D6JcJCwd.js.map +0 -1
- package/dist/src-Buuo5l7X.js.map +0 -1
- package/dist/src-C54Ok9E0.cjs.map +0 -1
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
AnyExtension as AnyTiptapExtension,
|
|
7
7
|
Extension as TiptapExtension,
|
|
8
8
|
} from "@tiptap/core";
|
|
9
|
-
import {
|
|
9
|
+
import { keydownHandler } from "@tiptap/pm/keymap";
|
|
10
10
|
import { Plugin, TextSelection } from "prosemirror-state";
|
|
11
11
|
import { updateBlockTr } from "../../../api/blockManipulation/commands/updateBlock/updateBlock.js";
|
|
12
12
|
import { setTextCursorPosition } from "../../../api/blockManipulation/selections/textCursorPosition.js";
|
|
@@ -592,16 +592,39 @@ export class ExtensionManager {
|
|
|
592
592
|
}
|
|
593
593
|
|
|
594
594
|
if (Object.keys(extension.keyboardShortcuts || {}).length) {
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
595
|
+
let currentEvent: KeyboardEvent | undefined;
|
|
596
|
+
const handleKeyDown = keydownHandler(
|
|
597
|
+
Object.fromEntries(
|
|
598
|
+
Object.entries(extension.keyboardShortcuts!).map(
|
|
599
|
+
([key, callback]) => [
|
|
599
600
|
key,
|
|
600
|
-
() =>
|
|
601
|
-
|
|
601
|
+
() => {
|
|
602
|
+
if (!currentEvent) {
|
|
603
|
+
throw new Error(
|
|
604
|
+
"Keyboard shortcut called outside handleKeyDown",
|
|
605
|
+
);
|
|
606
|
+
}
|
|
607
|
+
return callback({ editor: this.editor, event: currentEvent });
|
|
608
|
+
},
|
|
609
|
+
],
|
|
602
610
|
),
|
|
603
611
|
),
|
|
604
612
|
);
|
|
613
|
+
plugins.push(
|
|
614
|
+
new Plugin({
|
|
615
|
+
props: {
|
|
616
|
+
handleKeyDown: (view, event) => {
|
|
617
|
+
const previousEvent = currentEvent;
|
|
618
|
+
currentEvent = event;
|
|
619
|
+
try {
|
|
620
|
+
return handleKeyDown(view, event);
|
|
621
|
+
} finally {
|
|
622
|
+
currentEvent = previousEvent;
|
|
623
|
+
}
|
|
624
|
+
},
|
|
625
|
+
},
|
|
626
|
+
}),
|
|
627
|
+
);
|
|
605
628
|
}
|
|
606
629
|
|
|
607
630
|
return { plugins, inputRules };
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { TextSelection } from "prosemirror-state";
|
|
2
|
+
import { afterEach, beforeEach, describe, expect, it } from "vite-plus/test";
|
|
3
|
+
|
|
4
|
+
import { BlockNoteEditor } from "../BlockNoteEditor.js";
|
|
5
|
+
|
|
6
|
+
// `editLink` focuses the view when done, so it needs a mounted editor; the
|
|
7
|
+
// lookup itself is covered headless in StyleManager.test.ts.
|
|
8
|
+
describe.each(["link", "x"])("link editing (%s)", (text) => {
|
|
9
|
+
let editor: BlockNoteEditor;
|
|
10
|
+
let container: HTMLElement;
|
|
11
|
+
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
container = document.createElement("div");
|
|
14
|
+
const mountPoint = document.createElement("div");
|
|
15
|
+
container.append(mountPoint);
|
|
16
|
+
document.body.append(container);
|
|
17
|
+
editor = BlockNoteEditor.create({
|
|
18
|
+
initialContent: [
|
|
19
|
+
{
|
|
20
|
+
type: "paragraph",
|
|
21
|
+
content: [
|
|
22
|
+
{ type: "text", text: "before ", styles: {} },
|
|
23
|
+
{ type: "link", href: "https://example.com", content: text },
|
|
24
|
+
{ type: "text", text: " after", styles: {} },
|
|
25
|
+
],
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
});
|
|
29
|
+
editor.mount(mountPoint);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
afterEach(() => {
|
|
33
|
+
editor.unmount();
|
|
34
|
+
container.remove();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
/** Text nodes carrying a link mark, in document order, with positions. */
|
|
38
|
+
function links() {
|
|
39
|
+
const found: { href: string; text: string; from: number; to: number }[] =
|
|
40
|
+
[];
|
|
41
|
+
editor.prosemirrorState.doc.descendants((node, pos) => {
|
|
42
|
+
const link = node.marks.find((mark) => mark.type.name === "link");
|
|
43
|
+
if (node.isText && link) {
|
|
44
|
+
found.push({
|
|
45
|
+
href: link.attrs.href,
|
|
46
|
+
text: node.text ?? "",
|
|
47
|
+
from: pos,
|
|
48
|
+
to: pos + node.nodeSize,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
return found;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// The edit path has the same edge as `getSelectedLinkUrl`: a lookup at
|
|
56
|
+
// `position + 1` is outside the link at its end, so with only the last
|
|
57
|
+
// character selected the form pre-filled the URL and then re-linked that
|
|
58
|
+
// one character, splitting the link. Fails without `getMarkRange` in
|
|
59
|
+
// `getLinkMarkAtPos`.
|
|
60
|
+
it("edits the whole link with only its last character selected", () => {
|
|
61
|
+
const [link] = links();
|
|
62
|
+
expect(link).toMatchObject({ href: "https://example.com", text });
|
|
63
|
+
editor.transact((tr) =>
|
|
64
|
+
tr.setSelection(TextSelection.create(tr.doc, link.to - 1, link.to)),
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
editor.editLink("https://changed.example", text);
|
|
68
|
+
|
|
69
|
+
expect(links()).toEqual([
|
|
70
|
+
{
|
|
71
|
+
href: "https://changed.example",
|
|
72
|
+
text,
|
|
73
|
+
from: link.from,
|
|
74
|
+
to: link.to,
|
|
75
|
+
},
|
|
76
|
+
]);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("replaces the whole link at its end", () => {
|
|
80
|
+
const [link] = links();
|
|
81
|
+
editor.transact((tr) =>
|
|
82
|
+
tr.setSelection(TextSelection.create(tr.doc, link.to)),
|
|
83
|
+
);
|
|
84
|
+
editor.editLink("https://changed.example", "updated");
|
|
85
|
+
expect(links()).toEqual([
|
|
86
|
+
{
|
|
87
|
+
href: "https://changed.example",
|
|
88
|
+
text: "updated",
|
|
89
|
+
from: link.from,
|
|
90
|
+
to: link.from + 7,
|
|
91
|
+
},
|
|
92
|
+
]);
|
|
93
|
+
expect(editor.prosemirrorState.doc.textContent).toBe(
|
|
94
|
+
"before updated after",
|
|
95
|
+
);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("unlinks at the end without removing text", () => {
|
|
99
|
+
const [link] = links();
|
|
100
|
+
editor.transact((tr) =>
|
|
101
|
+
tr.setSelection(TextSelection.create(tr.doc, link.to)),
|
|
102
|
+
);
|
|
103
|
+
editor.deleteLink();
|
|
104
|
+
expect(links()).toEqual([]);
|
|
105
|
+
expect(editor.prosemirrorState.doc.textContent).toBe(
|
|
106
|
+
`before ${text} after`,
|
|
107
|
+
);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("does not throw at the document end", () => {
|
|
111
|
+
expect(() =>
|
|
112
|
+
editor.editLink(
|
|
113
|
+
"https://changed.example",
|
|
114
|
+
"updated",
|
|
115
|
+
editor.prosemirrorState.doc.content.size,
|
|
116
|
+
),
|
|
117
|
+
).not.toThrow();
|
|
118
|
+
expect(() =>
|
|
119
|
+
editor.deleteLink(editor.prosemirrorState.doc.content.size),
|
|
120
|
+
).not.toThrow();
|
|
121
|
+
});
|
|
122
|
+
});
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { TextSelection } from "prosemirror-state";
|
|
2
|
+
import { beforeEach, describe, expect, it } from "vite-plus/test";
|
|
3
|
+
|
|
4
|
+
import { BlockNoteEditor } from "../BlockNoteEditor.js";
|
|
5
|
+
|
|
6
|
+
// The "last character" and "one-character link" cases fail with a lookup at
|
|
7
|
+
// `from + 1`: that lands on the link's end boundary, where the non-inclusive
|
|
8
|
+
// link mark is not reported.
|
|
9
|
+
describe("getSelectedLinkUrl", () => {
|
|
10
|
+
let editor: BlockNoteEditor;
|
|
11
|
+
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
editor = BlockNoteEditor.create({
|
|
14
|
+
initialContent: [
|
|
15
|
+
{
|
|
16
|
+
type: "paragraph",
|
|
17
|
+
content: [
|
|
18
|
+
{ type: "text", text: "before ", styles: {} },
|
|
19
|
+
{ type: "link", href: "https://example.com", content: "link" },
|
|
20
|
+
{ type: "text", text: " after ", styles: {} },
|
|
21
|
+
{ type: "link", href: "https://one.example", content: "x" },
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
/** Start and end positions of the text node carrying `href`. */
|
|
29
|
+
function linkRange(href: string) {
|
|
30
|
+
let range: { from: number; to: number } | undefined;
|
|
31
|
+
editor.prosemirrorState.doc.descendants((node, pos) => {
|
|
32
|
+
if (
|
|
33
|
+
node.isText &&
|
|
34
|
+
node.marks.some(
|
|
35
|
+
(mark) => mark.type.name === "link" && mark.attrs.href === href,
|
|
36
|
+
)
|
|
37
|
+
) {
|
|
38
|
+
range = { from: pos, to: pos + node.nodeSize };
|
|
39
|
+
}
|
|
40
|
+
return range === undefined;
|
|
41
|
+
});
|
|
42
|
+
if (!range) {
|
|
43
|
+
throw new Error(`no link ${href} in the document`);
|
|
44
|
+
}
|
|
45
|
+
return range;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function select(from: number, to = from) {
|
|
49
|
+
editor.transact((tr) =>
|
|
50
|
+
tr.setSelection(TextSelection.create(tr.doc, from, to)),
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
it("reads the URL for the whole link", () => {
|
|
55
|
+
const { from, to } = linkRange("https://example.com");
|
|
56
|
+
select(from, to);
|
|
57
|
+
expect(editor.getSelectedLinkUrl()).toBe("https://example.com");
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("reads the URL for the link's last character", () => {
|
|
61
|
+
const { to } = linkRange("https://example.com");
|
|
62
|
+
select(to - 1, to);
|
|
63
|
+
expect(editor.getSelectedLinkUrl()).toBe("https://example.com");
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("reads the URL for a one-character link", () => {
|
|
67
|
+
const { from, to } = linkRange("https://one.example");
|
|
68
|
+
select(from, to);
|
|
69
|
+
expect(editor.getSelectedLinkUrl()).toBe("https://one.example");
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("reads the URL for a caret inside the link", () => {
|
|
73
|
+
const { from } = linkRange("https://example.com");
|
|
74
|
+
select(from + 2);
|
|
75
|
+
expect(editor.getSelectedLinkUrl()).toBe("https://example.com");
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("reads no URL outside links", () => {
|
|
79
|
+
const { from } = linkRange("https://example.com");
|
|
80
|
+
select(from - 3, from - 1);
|
|
81
|
+
expect(editor.getSelectedLinkUrl()).toBeUndefined();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("reads no URL for a selection starting right after a link", () => {
|
|
85
|
+
const { to } = linkRange("https://example.com");
|
|
86
|
+
select(to, to + 3);
|
|
87
|
+
expect(editor.getSelectedLinkUrl()).toBeUndefined();
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// The edit path is covered in StyleManager.browser.test.ts (it needs a
|
|
91
|
+
// mounted view); the lookup it relies on is pinned here.
|
|
92
|
+
it("finds the link at either edge for editing", () => {
|
|
93
|
+
const { from, to } = linkRange("https://example.com");
|
|
94
|
+
expect(editor.getLinkMarkAtPos(from)?.href).toBe("https://example.com");
|
|
95
|
+
expect(editor.getLinkMarkAtPos(to)?.href).toBe("https://example.com");
|
|
96
|
+
expect(editor.getLinkMarkAtPos(from - 2)).toBeUndefined();
|
|
97
|
+
});
|
|
98
|
+
});
|
|
@@ -55,7 +55,10 @@ export class StyleManager<
|
|
|
55
55
|
public getActiveStyles() {
|
|
56
56
|
return this.editor.transact((tr) => {
|
|
57
57
|
const styles: Styles<SSchema> = {};
|
|
58
|
-
const marks =
|
|
58
|
+
const marks =
|
|
59
|
+
// Also track active marks that are not in the document. E.g. the bold mark can be selected
|
|
60
|
+
// so that typing applies bold text, even if the text cursor isn't already within bold text.
|
|
61
|
+
(tr.selection.empty && tr.storedMarks) || tr.selection.$to.marks();
|
|
59
62
|
|
|
60
63
|
for (const mark of marks) {
|
|
61
64
|
const config = this.editor.schema.styleSchema[mark.type.name];
|
|
@@ -147,22 +150,26 @@ export class StyleManager<
|
|
|
147
150
|
}
|
|
148
151
|
|
|
149
152
|
/**
|
|
150
|
-
* Find the link mark and its range at the given position
|
|
153
|
+
* Find the link mark and its range at the given position, including at
|
|
154
|
+
* either edge of the link.
|
|
151
155
|
* Returns undefined if there is no link at that position.
|
|
152
156
|
*/
|
|
153
157
|
public getLinkMarkAtPos(pos: number) {
|
|
154
158
|
return this.editor.transact((tr) => {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
159
|
+
// The link mark is not inclusive, so `$pos.marks()` leaves it out at
|
|
160
|
+
// both ends of a link, and callers compensated with `pos + 1`, which
|
|
161
|
+
// covers the left end only. tiptap's `getMarkRange` looks at the node
|
|
162
|
+
// after `pos` and then the one before, so it finds the link at both
|
|
163
|
+
// ends; the mark itself is read off the node the range starts with.
|
|
164
|
+
const linkType = this.editor.pmSchema.marks["link"];
|
|
165
|
+
const range = getMarkRange(tr.doc.resolve(pos), linkType);
|
|
166
|
+
if (!range) {
|
|
161
167
|
return undefined;
|
|
162
168
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
169
|
+
const linkMark = tr.doc
|
|
170
|
+
.nodeAt(range.from)
|
|
171
|
+
?.marks.find((mark) => mark.type === linkType);
|
|
172
|
+
if (!linkMark) {
|
|
166
173
|
return undefined;
|
|
167
174
|
}
|
|
168
175
|
|
|
@@ -176,11 +183,20 @@ export class StyleManager<
|
|
|
176
183
|
}
|
|
177
184
|
|
|
178
185
|
/**
|
|
179
|
-
* Gets the URL of the
|
|
186
|
+
* Gets the URL of the link the current selection starts in, or `undefined`
|
|
187
|
+
* if it does not start in one.
|
|
180
188
|
*/
|
|
181
189
|
public getSelectedLinkUrl() {
|
|
182
190
|
return this.editor.transact((tr) => {
|
|
183
|
-
|
|
191
|
+
// The node the selection starts in, on purpose not `getLinkMarkAtPos`
|
|
192
|
+
// (which also looks at the node before `from`): a selection starting
|
|
193
|
+
// right after a link must not pre-fill the link form with that link's
|
|
194
|
+
// URL. A `from + 1` lookup would miss the right end of a link (a
|
|
195
|
+
// selection of its last character, or a one-character link, reads as
|
|
196
|
+
// no link).
|
|
197
|
+
const node = tr.doc.nodeAt(tr.selection.from);
|
|
198
|
+
const linkMark = node?.marks.find((mark) => mark.type.name === "link");
|
|
199
|
+
return linkMark?.attrs.href as string | undefined;
|
|
184
200
|
});
|
|
185
201
|
}
|
|
186
202
|
|
|
@@ -222,7 +238,7 @@ export class StyleManager<
|
|
|
222
238
|
position = this.editor.transact((tr) => tr.selection.anchor),
|
|
223
239
|
) {
|
|
224
240
|
this.editor.transact((tr) => {
|
|
225
|
-
const linkData = this.getLinkMarkAtPos(position
|
|
241
|
+
const linkData = this.getLinkMarkAtPos(position);
|
|
226
242
|
const { from, to } = linkData || {
|
|
227
243
|
from: tr.selection.from,
|
|
228
244
|
to: tr.selection.to,
|
|
@@ -246,7 +262,7 @@ export class StyleManager<
|
|
|
246
262
|
position = this.editor.transact((tr) => tr.selection.anchor),
|
|
247
263
|
) {
|
|
248
264
|
this.editor.transact((tr) => {
|
|
249
|
-
const linkData = this.getLinkMarkAtPos(position
|
|
265
|
+
const linkData = this.getLinkMarkAtPos(position);
|
|
250
266
|
const { from, to } = linkData || {
|
|
251
267
|
from: tr.selection.from,
|
|
252
268
|
to: tr.selection.to,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { BlockManager } from "./BlockManager.js";
|
|
2
2
|
export { EventManager } from "./EventManager.js";
|
|
3
|
+
export type { EditorFocusOptions } from "./EventManager.js";
|
|
3
4
|
export { ExportManager } from "./ExportManager.js";
|
|
4
5
|
export { ExtensionManager } from "./ExtensionManager/index.js";
|
|
5
6
|
export { SelectionManager } from "./SelectionManager.js";
|
|
@@ -70,6 +70,28 @@ export const FormattingToolbarExtension = createExtension(({ editor }) => {
|
|
|
70
70
|
// re-evaluate whether the toolbar should be shown
|
|
71
71
|
store.setState(shouldShow());
|
|
72
72
|
});
|
|
73
|
+
// The selection survives a blur, so without this the state would too:
|
|
74
|
+
// on a phone, tapping the page away from the editor closes the
|
|
75
|
+
// keyboard, and a controller mounting after that showed the toolbar over
|
|
76
|
+
// a blurred editor. Focus within the editor's own UI (a toolbar button,
|
|
77
|
+
// a popover's input) still counts as focused, and the event only fires
|
|
78
|
+
// once a focus handoff has settled. Known edge: with focus inside the
|
|
79
|
+
// toolbar (a menu open), scrolling the selection out of view hides the
|
|
80
|
+
// toolbar and the browser drops that focus, so the toolbar is gone until
|
|
81
|
+
// the next selection change.
|
|
82
|
+
const unsubscribeOnFocusChange = editor.onFocusChange(
|
|
83
|
+
(_editor, { focused }) => {
|
|
84
|
+
if (!focused) {
|
|
85
|
+
store.setState(false);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (preventShowWhileMouseDown || preventShowWhileDragging) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
store.setState(shouldShow());
|
|
92
|
+
},
|
|
93
|
+
{ includeEditorUI: true },
|
|
94
|
+
);
|
|
73
95
|
|
|
74
96
|
// To mimic Notion's behavior, we listen to the mouse down event to set the `preventShowWhileMouseDown` flag
|
|
75
97
|
dom.addEventListener(
|
|
@@ -122,6 +144,7 @@ export const FormattingToolbarExtension = createExtension(({ editor }) => {
|
|
|
122
144
|
signal.addEventListener("abort", () => {
|
|
123
145
|
unsubscribeOnChange();
|
|
124
146
|
unsubscribeOnSelectionChange();
|
|
147
|
+
unsubscribeOnFocusChange();
|
|
125
148
|
});
|
|
126
149
|
},
|
|
127
150
|
} as const;
|
|
@@ -617,6 +617,21 @@ export class SideMenuView<
|
|
|
617
617
|
return;
|
|
618
618
|
}
|
|
619
619
|
|
|
620
|
+
// Leaves the menu as it is while the pointer is over this editor's own UI
|
|
621
|
+
// (a toolbar, a menu, the side menu itself) rather than its content: the
|
|
622
|
+
// block under that UI is not what the pointer is about. It also keeps taps
|
|
623
|
+
// on the UI working on iOS Safari, which delivers a tap as a hover first
|
|
624
|
+
// and drops the click when that hover changes the page (WebKit's
|
|
625
|
+
// ContentChangeObserver); with the mobile toolbar far below the blocks,
|
|
626
|
+
// the hover would hide a shown side menu and every button needed two taps.
|
|
627
|
+
if (
|
|
628
|
+
event.target instanceof Node &&
|
|
629
|
+
!this.pmView.dom.contains(event.target) &&
|
|
630
|
+
this.editor.isWithinEditor(event.target as Element)
|
|
631
|
+
) {
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
634
|
+
|
|
620
635
|
this.mousePos = { x: event.clientX, y: event.clientY };
|
|
621
636
|
|
|
622
637
|
// We want the full area of the editor to check if the cursor is hovering
|
|
@@ -60,7 +60,9 @@ const nestedEditorBlock = createBlockSpec(
|
|
|
60
60
|
},
|
|
61
61
|
],
|
|
62
62
|
});
|
|
63
|
-
nestedEditor.mount(dom
|
|
63
|
+
nestedEditor.mount(dom);
|
|
64
|
+
// The nested editor's UI renders at the body, outside its own DOM tree.
|
|
65
|
+
nestedEditor.registerPortalElement(document.body);
|
|
64
66
|
|
|
65
67
|
return { dom, destroy: () => nestedEditor.unmount() };
|
|
66
68
|
},
|
package/src/i18n/locales/ar.ts
CHANGED
package/src/i18n/locales/de.ts
CHANGED
package/src/i18n/locales/en.ts
CHANGED
package/src/i18n/locales/es.ts
CHANGED
package/src/i18n/locales/fa.ts
CHANGED
package/src/i18n/locales/fr.ts
CHANGED
package/src/i18n/locales/he.ts
CHANGED
package/src/i18n/locales/hr.ts
CHANGED
package/src/i18n/locales/is.ts
CHANGED
package/src/i18n/locales/it.ts
CHANGED
package/src/i18n/locales/ja.ts
CHANGED
package/src/i18n/locales/ko.ts
CHANGED
package/src/i18n/locales/nl.ts
CHANGED
package/src/i18n/locales/no.ts
CHANGED
package/src/i18n/locales/pl.ts
CHANGED
package/src/i18n/locales/pt.ts
CHANGED
package/src/i18n/locales/ru.ts
CHANGED
package/src/i18n/locales/sk.ts
CHANGED
package/src/i18n/locales/uk.ts
CHANGED
package/src/i18n/locales/uz.ts
CHANGED
package/src/i18n/locales/vi.ts
CHANGED
package/src/i18n/locales/zh.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -11,6 +11,7 @@ export * from "./api/nodeUtil.js";
|
|
|
11
11
|
export * from "./api/pmUtil.js";
|
|
12
12
|
export * from "./blocks/index.js";
|
|
13
13
|
export * from "./editor/BlockNoteEditor.js";
|
|
14
|
+
export type { EditorFocusOptions } from "./editor/managers/EventManager.js";
|
|
14
15
|
export * from "./editor/BlockNoteExtension.js";
|
|
15
16
|
export * from "./editor/defaultColors.js";
|
|
16
17
|
export * from "./editor/selectionTypes.js";
|