@blocknote/core 0.52.1 → 0.53.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 +1 -1
- package/dist/blocknote.js +6 -6
- package/dist/{blocks-CiuUGa1E.js → blocks-BEJW9OM_.js} +516 -476
- package/dist/blocks-BEJW9OM_.js.map +1 -0
- package/dist/blocks-BPmJglFo.cjs +12 -0
- package/dist/blocks-BPmJglFo.cjs.map +1 -0
- package/dist/blocks.cjs +1 -1
- package/dist/blocks.js +2 -2
- package/dist/extensions-AitWbYdJ.cjs +52 -0
- package/dist/extensions-AitWbYdJ.cjs.map +1 -0
- package/dist/{extensions-CrUGDOks.js → extensions-BR5hkAio.js} +421 -391
- package/dist/extensions-BR5hkAio.js.map +1 -0
- package/dist/extensions.cjs +1 -1
- package/dist/extensions.js +3 -3
- package/dist/src-BHPuOo7W.cjs +21 -0
- package/dist/src-BHPuOo7W.cjs.map +1 -0
- package/dist/{src-DTF83Cl9.js → src-BUXut68d.js} +797 -779
- package/dist/src-BUXut68d.js.map +1 -0
- package/dist/style.css +1 -1
- package/dist/webpack-stats.json +1 -1
- package/dist/y.cjs +1 -1
- package/dist/y.js +9 -9
- package/dist/yjs.cjs +1 -1
- package/dist/yjs.js +1 -1
- package/package.json +14 -14
- package/src/api/clipboard/fromClipboard/handleFileInsertion.ts +10 -1
- package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +42 -8
- package/src/api/exporters/markdown/markdownExporter.ts +10 -1
- package/src/api/parsers/html/parseHTML.ts +43 -0
- package/src/blocks/Table/TableExtension.test.ts +102 -0
- package/src/blocks/ToggleWrapper/createToggleWrapper.ts +16 -5
- package/src/blocks/defaultBlockTypeGuards.ts +6 -0
- package/src/editor/Block.css +51 -1
- package/src/extensions/SideMenu/SideMenu.ts +20 -3
- package/src/extensions/SuggestionMenu/SuggestionMenu.test.ts +118 -0
- package/src/extensions/SuggestionMenu/SuggestionMenu.ts +40 -27
- package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +13 -3
- package/src/extensions/TableHandles/TableHandles.ts +25 -12
- package/src/extensions/TrailingNode/TrailingNode.ts +98 -32
- package/src/index.ts +1 -0
- package/src/schema/blocks/createSpec.ts +16 -3
- package/src/schema/blocks/internal.test.ts +86 -0
- package/src/schema/blocks/internal.ts +64 -0
- package/src/schema/inlineContent/createSpec.ts +9 -1
- package/src/schema/nodeViewMutations.test.ts +121 -0
- package/src/schema/nodeViewMutations.ts +46 -0
- package/types/src/api/exporters/html/util/serializeBlocksExternalHTML.d.ts +13 -0
- package/types/src/blocks/defaultBlockTypeGuards.d.ts +2 -0
- package/types/src/extensions/SideMenu/SideMenu.d.ts +5 -0
- package/types/src/extensions/SuggestionMenu/SuggestionMenu.d.ts +6 -0
- package/types/src/extensions/TrailingNode/TrailingNode.d.ts +5 -4
- package/types/src/index.d.ts +1 -0
- package/types/src/schema/blocks/internal.d.ts +21 -0
- package/types/src/schema/blocks/internal.test.d.ts +1 -0
- package/types/src/schema/nodeViewMutations.d.ts +3 -0
- package/types/src/schema/nodeViewMutations.test.d.ts +1 -0
- package/dist/blocks-BqHv0xhc.cjs +0 -12
- package/dist/blocks-BqHv0xhc.cjs.map +0 -1
- package/dist/blocks-CiuUGa1E.js.map +0 -1
- package/dist/extensions-CrUGDOks.js.map +0 -1
- package/dist/extensions-Ghr9QqqR.cjs +0 -52
- package/dist/extensions-Ghr9QqqR.cjs.map +0 -1
- package/dist/src-DTF83Cl9.js.map +0 -1
- package/dist/src-OfbaVbMw.cjs +0 -21
- package/dist/src-OfbaVbMw.cjs.map +0 -1
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"directory": "packages/core"
|
|
12
12
|
},
|
|
13
13
|
"license": "MPL-2.0",
|
|
14
|
-
"version": "0.
|
|
14
|
+
"version": "0.53.0",
|
|
15
15
|
"files": [
|
|
16
16
|
"dist",
|
|
17
17
|
"types",
|
|
@@ -88,24 +88,24 @@
|
|
|
88
88
|
"@handlewithcare/prosemirror-inputrules": "^0.1.4",
|
|
89
89
|
"@shikijs/types": "^4",
|
|
90
90
|
"@tanstack/store": "^0.7.7",
|
|
91
|
-
"@tiptap/core": "^3.
|
|
92
|
-
"@tiptap/extension-bold": "^3.
|
|
93
|
-
"@tiptap/extension-code": "^3.
|
|
94
|
-
"@tiptap/extension-italic": "^3.
|
|
95
|
-
"@tiptap/extension-strike": "^3.
|
|
96
|
-
"@tiptap/extension-text": "^3.
|
|
97
|
-
"@tiptap/extension-underline": "^3.
|
|
98
|
-
"@tiptap/extensions": "^3.
|
|
99
|
-
"@tiptap/pm": "^3.
|
|
91
|
+
"@tiptap/core": "^3.29.2",
|
|
92
|
+
"@tiptap/extension-bold": "^3.29.2",
|
|
93
|
+
"@tiptap/extension-code": "^3.29.2",
|
|
94
|
+
"@tiptap/extension-italic": "^3.29.2",
|
|
95
|
+
"@tiptap/extension-strike": "^3.29.2",
|
|
96
|
+
"@tiptap/extension-text": "^3.29.2",
|
|
97
|
+
"@tiptap/extension-underline": "^3.29.2",
|
|
98
|
+
"@tiptap/extensions": "^3.29.2",
|
|
99
|
+
"@tiptap/pm": "^3.29.2",
|
|
100
100
|
"emoji-mart": "^5.6.0",
|
|
101
101
|
"fast-deep-equal": "^3.1.3",
|
|
102
102
|
"lib0": "1.0.0-rc.22",
|
|
103
103
|
"prosemirror-highlight": "^0.15.1",
|
|
104
|
-
"prosemirror-model": "^1.25.
|
|
104
|
+
"prosemirror-model": "^1.25.11",
|
|
105
105
|
"prosemirror-state": "^1.4.4",
|
|
106
|
-
"prosemirror-tables": "^1.8.
|
|
107
|
-
"prosemirror-transform": "^1.
|
|
108
|
-
"prosemirror-view": "^1.41.
|
|
106
|
+
"prosemirror-tables": "^1.8.5",
|
|
107
|
+
"prosemirror-transform": "^1.12.0",
|
|
108
|
+
"prosemirror-view": "^1.41.9"
|
|
109
109
|
},
|
|
110
110
|
"devDependencies": {
|
|
111
111
|
"jsdom": "^29.0.2",
|
|
@@ -170,9 +170,14 @@ export async function handleFileInsertion<
|
|
|
170
170
|
|
|
171
171
|
const blockRect = blockElement?.getBoundingClientRect();
|
|
172
172
|
|
|
173
|
+
const existingBlock = editor.getBlock(id);
|
|
174
|
+
if (!existingBlock) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
|
|
173
178
|
return insertOrUpdateBlock(
|
|
174
179
|
editor,
|
|
175
|
-
|
|
180
|
+
existingBlock,
|
|
176
181
|
fileBlock,
|
|
177
182
|
blockRect && (blockRect.top + blockRect.bottom) / 2 > coords.top
|
|
178
183
|
? "before"
|
|
@@ -183,6 +188,10 @@ export async function handleFileInsertion<
|
|
|
183
188
|
return;
|
|
184
189
|
}
|
|
185
190
|
|
|
191
|
+
if (!insertedBlockId) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
|
|
186
195
|
const updateData = await editor.uploadFile(file, insertedBlockId);
|
|
187
196
|
|
|
188
197
|
const updatedFileBlock =
|
|
@@ -15,6 +15,20 @@ import {
|
|
|
15
15
|
} from "../../../nodeConversions/blockToNode.js";
|
|
16
16
|
import { nodeToCustomInlineContent } from "../../../nodeConversions/nodeToBlock.js";
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Placeholder character inserted into empty inline-content blocks when
|
|
20
|
+
* exporting to external HTML. An empty block serializes to an element with no
|
|
21
|
+
* children (e.g. `<p></p>`), which is dropped when the HTML is parsed back into
|
|
22
|
+
* blocks. Filling it with this character keeps the block alive through the
|
|
23
|
+
* round trip, and the parser strips the character again so the block ends up
|
|
24
|
+
* empty (see `HTMLToBlocks`).
|
|
25
|
+
*
|
|
26
|
+
* The Unicode object replacement character (U+FFFC) is used because it's a
|
|
27
|
+
* reserved placeholder that users don't type, so it can be safely removed on
|
|
28
|
+
* import without discarding legitimate content (unlike a non-breaking space).
|
|
29
|
+
*/
|
|
30
|
+
export const EMPTY_BLOCK_PLACEHOLDER = "";
|
|
31
|
+
|
|
18
32
|
function addAttributesAndRemoveClasses(element: HTMLElement) {
|
|
19
33
|
// Removes all BlockNote specific class names.
|
|
20
34
|
const className =
|
|
@@ -265,15 +279,35 @@ function serializeBlock<
|
|
|
265
279
|
}
|
|
266
280
|
}
|
|
267
281
|
|
|
268
|
-
if (ret.contentDOM
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
282
|
+
if (ret.contentDOM) {
|
|
283
|
+
if (block.content) {
|
|
284
|
+
const ic = serializeInlineContentExternalHTML(
|
|
285
|
+
editor,
|
|
286
|
+
block.content as any, // TODO
|
|
287
|
+
serializer,
|
|
288
|
+
{ ...options, blockType: block.type },
|
|
289
|
+
);
|
|
290
|
+
|
|
291
|
+
ret.contentDOM.appendChild(ic);
|
|
292
|
+
}
|
|
275
293
|
|
|
276
|
-
|
|
294
|
+
// Blocks with empty inline content (e.g. an empty paragraph) serialize to
|
|
295
|
+
// an element with no children (e.g. `<p></p>`), which is ignored when the
|
|
296
|
+
// HTML is parsed back into blocks. To make these blocks survive such a
|
|
297
|
+
// round trip, we fill their content with a placeholder character that the
|
|
298
|
+
// parser strips out again (see `EMPTY_BLOCK_PLACEHOLDER`).
|
|
299
|
+
//
|
|
300
|
+
// Only applies to blocks that hold inline content: containers (columns,
|
|
301
|
+
// tables) fill their `contentDOM` with child blocks later on, and code
|
|
302
|
+
// blocks would turn the placeholder into literal content.
|
|
303
|
+
const blockNodeType = editor.pmSchema.nodes[block.type as any];
|
|
304
|
+
if (
|
|
305
|
+
blockNodeType?.inlineContent &&
|
|
306
|
+
!blockNodeType.spec.code &&
|
|
307
|
+
ret.contentDOM.childNodes.length === 0
|
|
308
|
+
) {
|
|
309
|
+
ret.contentDOM.appendChild(doc.createTextNode(EMPTY_BLOCK_PLACEHOLDER));
|
|
310
|
+
}
|
|
277
311
|
}
|
|
278
312
|
|
|
279
313
|
let listType = undefined;
|
|
@@ -8,11 +8,20 @@ import {
|
|
|
8
8
|
StyleSchema,
|
|
9
9
|
} from "../../../schema/index.js";
|
|
10
10
|
import { createExternalHTMLExporter } from "../html/externalHTMLExporter.js";
|
|
11
|
+
import { EMPTY_BLOCK_PLACEHOLDER } from "../html/util/serializeBlocksExternalHTML.js";
|
|
11
12
|
import { htmlToMarkdown } from "./htmlToMarkdown.js";
|
|
12
13
|
|
|
13
14
|
// Needs to be sync because it's used in drag handler event (SideMenuPlugin)
|
|
14
15
|
export function cleanHTMLToMarkdown(cleanHTMLString: string) {
|
|
15
|
-
|
|
16
|
+
// The external HTML exporter fills empty inline-content blocks with a
|
|
17
|
+
// placeholder character so they survive an HTML round trip (see
|
|
18
|
+
// `EMPTY_BLOCK_PLACEHOLDER`). Markdown has no need for that placeholder, so we
|
|
19
|
+
// remove it to avoid it showing up as a stray character in the output.
|
|
20
|
+
const withoutPlaceholder = cleanHTMLString
|
|
21
|
+
.split(EMPTY_BLOCK_PLACEHOLDER)
|
|
22
|
+
.join("");
|
|
23
|
+
|
|
24
|
+
return htmlToMarkdown(withoutPlaceholder);
|
|
16
25
|
}
|
|
17
26
|
|
|
18
27
|
export function blocksToMarkdown<
|
|
@@ -6,10 +6,51 @@ import {
|
|
|
6
6
|
} from "../../../schema/index.js";
|
|
7
7
|
|
|
8
8
|
import { Block } from "../../../blocks/defaultBlocks.js";
|
|
9
|
+
import { EMPTY_BLOCK_PLACEHOLDER } from "../../exporters/html/util/serializeBlocksExternalHTML.js";
|
|
9
10
|
import { nodeToBlock } from "../../nodeConversions/nodeToBlock.js";
|
|
10
11
|
import { nestedListsToBlockNoteStructure } from "./util/nestedLists.js";
|
|
11
12
|
import { preprocessHTMLWhitespace } from "./util/normalizeWhitespace.js";
|
|
12
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Removes the placeholder character that the external HTML exporter inserts
|
|
16
|
+
* into empty inline-content blocks (see `EMPTY_BLOCK_PLACEHOLDER`). The
|
|
17
|
+
* placeholder keeps such blocks from being dropped while the HTML is parsed;
|
|
18
|
+
* stripping it here lets the block round trip back to genuinely empty content.
|
|
19
|
+
*/
|
|
20
|
+
function stripEmptyBlockPlaceholder(content: any[]): any[] {
|
|
21
|
+
const stripped: any[] = [];
|
|
22
|
+
|
|
23
|
+
for (const item of content) {
|
|
24
|
+
if (item.type === "text") {
|
|
25
|
+
const text = item.text.split(EMPTY_BLOCK_PLACEHOLDER).join("");
|
|
26
|
+
if (text.length > 0) {
|
|
27
|
+
stripped.push({ ...item, text });
|
|
28
|
+
}
|
|
29
|
+
} else if (Array.isArray(item.content)) {
|
|
30
|
+
// Links and custom inline content that hold nested styled text.
|
|
31
|
+
stripped.push({
|
|
32
|
+
...item,
|
|
33
|
+
content: stripEmptyBlockPlaceholder(item.content),
|
|
34
|
+
});
|
|
35
|
+
} else {
|
|
36
|
+
stripped.push(item);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return stripped;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function stripEmptyBlockPlaceholderFromBlocks(blocks: Block<any, any, any>[]) {
|
|
44
|
+
for (const block of blocks) {
|
|
45
|
+
if (Array.isArray(block.content)) {
|
|
46
|
+
(block as any).content = stripEmptyBlockPlaceholder(block.content);
|
|
47
|
+
}
|
|
48
|
+
if (block.children.length > 0) {
|
|
49
|
+
stripEmptyBlockPlaceholderFromBlocks(block.children);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
13
54
|
export function HTMLToBlocks<
|
|
14
55
|
BSchema extends BlockSchema,
|
|
15
56
|
I extends InlineContentSchema,
|
|
@@ -33,5 +74,7 @@ export function HTMLToBlocks<
|
|
|
33
74
|
blocks.push(nodeToBlock(parentNode.child(i), parentNode));
|
|
34
75
|
}
|
|
35
76
|
|
|
77
|
+
stripEmptyBlockPlaceholderFromBlocks(blocks);
|
|
78
|
+
|
|
36
79
|
return blocks;
|
|
37
80
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { GapCursor } from "@tiptap/pm/gapcursor";
|
|
1
2
|
import { TextSelection } from "prosemirror-state";
|
|
2
3
|
import { CellSelection } from "prosemirror-tables";
|
|
3
4
|
import {
|
|
@@ -10,6 +11,7 @@ import {
|
|
|
10
11
|
} from "vite-plus/test";
|
|
11
12
|
|
|
12
13
|
import { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
|
|
14
|
+
import { TableHandlesExtension } from "../../extensions/TableHandles/TableHandles.js";
|
|
13
15
|
import type { PartialBlock } from "../defaultBlocks.js";
|
|
14
16
|
|
|
15
17
|
/**
|
|
@@ -127,3 +129,103 @@ describe("Table Enter keyboard shortcut", () => {
|
|
|
127
129
|
expect(editor.document).toStrictEqual(before);
|
|
128
130
|
});
|
|
129
131
|
});
|
|
132
|
+
|
|
133
|
+
describe("TableHandlesExtension.getCellSelection", () => {
|
|
134
|
+
let editor: BlockNoteEditor;
|
|
135
|
+
const div = document.createElement("div");
|
|
136
|
+
|
|
137
|
+
beforeAll(() => {
|
|
138
|
+
editor = BlockNoteEditor.create();
|
|
139
|
+
editor.mount(div);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
afterAll(() => {
|
|
143
|
+
editor._tiptapEditor.destroy();
|
|
144
|
+
editor = undefined as any;
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
function getCellSelection() {
|
|
148
|
+
return editor.getExtension(TableHandlesExtension)!.getCellSelection();
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
it("returns undefined for a gap cursor left of a leading table without crashing", () => {
|
|
152
|
+
// A table as the first block in the document, matching the crash repro
|
|
153
|
+
// where clicking in the left margin places a gap cursor at doc start.
|
|
154
|
+
editor.replaceBlocks(editor.document, [
|
|
155
|
+
{
|
|
156
|
+
type: "table",
|
|
157
|
+
content: {
|
|
158
|
+
type: "tableContent",
|
|
159
|
+
rows: [{ cells: ["Cell 1", "Cell 2"] }],
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
]);
|
|
163
|
+
|
|
164
|
+
editor.transact((tr) => tr.setSelection(new GapCursor(tr.doc.resolve(0))));
|
|
165
|
+
|
|
166
|
+
expect(() => getCellSelection()).not.toThrow();
|
|
167
|
+
expect(getCellSelection()).toBeUndefined();
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it("returns undefined for a gap cursor next to a nested block without crashing", () => {
|
|
171
|
+
// A table as the first block, followed by a nested block. Clicking the
|
|
172
|
+
// nested block's left margin places a gap cursor that is not inside a cell.
|
|
173
|
+
editor.replaceBlocks(editor.document, [
|
|
174
|
+
{
|
|
175
|
+
type: "table",
|
|
176
|
+
content: {
|
|
177
|
+
type: "tableContent",
|
|
178
|
+
rows: [{ cells: ["Cell 1", "Cell 2"] }],
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
type: "paragraph",
|
|
183
|
+
content: "Parent",
|
|
184
|
+
children: [{ type: "paragraph", content: "Nested" }],
|
|
185
|
+
},
|
|
186
|
+
]);
|
|
187
|
+
|
|
188
|
+
let nestedPos = -1;
|
|
189
|
+
editor.prosemirrorView.state.doc.descendants((node, pos) => {
|
|
190
|
+
if (nestedPos === -1 && node.isText && node.text === "Nested") {
|
|
191
|
+
nestedPos = pos;
|
|
192
|
+
}
|
|
193
|
+
return true;
|
|
194
|
+
});
|
|
195
|
+
editor.transact((tr) =>
|
|
196
|
+
tr.setSelection(new GapCursor(tr.doc.resolve(nestedPos - 1))),
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
expect(() => getCellSelection()).not.toThrow();
|
|
200
|
+
expect(getCellSelection()).toBeUndefined();
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it("returns the cell indices for a text selection inside a cell", () => {
|
|
204
|
+
editor.replaceBlocks(editor.document, [
|
|
205
|
+
{
|
|
206
|
+
type: "table",
|
|
207
|
+
content: {
|
|
208
|
+
type: "tableContent",
|
|
209
|
+
rows: [
|
|
210
|
+
{ cells: ["Cell 1", "Cell 2"] },
|
|
211
|
+
{ cells: ["Cell 3", "Cell 4"] },
|
|
212
|
+
],
|
|
213
|
+
},
|
|
214
|
+
},
|
|
215
|
+
]);
|
|
216
|
+
|
|
217
|
+
let cellPos = -1;
|
|
218
|
+
editor.prosemirrorView.state.doc.descendants((node, pos) => {
|
|
219
|
+
if (cellPos === -1 && node.isText && node.text === "Cell 4") {
|
|
220
|
+
cellPos = pos;
|
|
221
|
+
}
|
|
222
|
+
return true;
|
|
223
|
+
});
|
|
224
|
+
editor.transact((tr) =>
|
|
225
|
+
tr.setSelection(TextSelection.create(tr.doc, cellPos + 1)),
|
|
226
|
+
);
|
|
227
|
+
|
|
228
|
+
expect(getCellSelection()?.from).toEqual({ row: 1, col: 1 });
|
|
229
|
+
expect(getCellSelection()?.to).toEqual({ row: 1, col: 1 });
|
|
230
|
+
});
|
|
231
|
+
});
|
|
@@ -50,20 +50,25 @@ export const createToggleWrapper = (
|
|
|
50
50
|
const toggleButtonOnClick = () => {
|
|
51
51
|
// Toggles visibility of child blocks. Also adds/removes the "add block"
|
|
52
52
|
// button if there are no child blocks.
|
|
53
|
+
const currentBlock = editor.getBlock(block);
|
|
54
|
+
if (!currentBlock) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
53
58
|
if (toggleWrapper.getAttribute("data-show-children") === "true") {
|
|
54
59
|
toggleWrapper.setAttribute("data-show-children", "false");
|
|
55
|
-
toggledState.set(
|
|
60
|
+
toggledState.set(currentBlock, false);
|
|
56
61
|
|
|
57
62
|
if (dom.contains(toggleAddBlockButton)) {
|
|
58
63
|
dom.removeChild(toggleAddBlockButton);
|
|
59
64
|
}
|
|
60
65
|
} else {
|
|
61
66
|
toggleWrapper.setAttribute("data-show-children", "true");
|
|
62
|
-
toggledState.set(
|
|
67
|
+
toggledState.set(currentBlock, true);
|
|
63
68
|
|
|
64
69
|
if (
|
|
65
70
|
editor.isEditable &&
|
|
66
|
-
|
|
71
|
+
currentBlock.children.length === 0 &&
|
|
67
72
|
!dom.contains(toggleAddBlockButton)
|
|
68
73
|
) {
|
|
69
74
|
dom.appendChild(toggleAddBlockButton);
|
|
@@ -111,7 +116,10 @@ export const createToggleWrapper = (
|
|
|
111
116
|
// If a child block is added while children are hidden, show children.
|
|
112
117
|
if (toggleWrapper.getAttribute("data-show-children") === "false") {
|
|
113
118
|
toggleWrapper.setAttribute("data-show-children", "true");
|
|
114
|
-
|
|
119
|
+
const currentBlock = editor.getBlock(block);
|
|
120
|
+
if (currentBlock) {
|
|
121
|
+
toggledState.set(currentBlock, true);
|
|
122
|
+
}
|
|
115
123
|
}
|
|
116
124
|
|
|
117
125
|
// Remove the "add block" button as we want to show child blocks and
|
|
@@ -124,7 +132,10 @@ export const createToggleWrapper = (
|
|
|
124
132
|
// children.
|
|
125
133
|
if (toggleWrapper.getAttribute("data-show-children") === "true") {
|
|
126
134
|
toggleWrapper.setAttribute("data-show-children", "false");
|
|
127
|
-
|
|
135
|
+
const currentBlock = editor.getBlock(block);
|
|
136
|
+
if (currentBlock) {
|
|
137
|
+
toggledState.set(currentBlock, false);
|
|
138
|
+
}
|
|
128
139
|
}
|
|
129
140
|
|
|
130
141
|
// Remove the "add block" button as we want to hide child blocks,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Node } from "prosemirror-model";
|
|
1
2
|
import { CellSelection } from "prosemirror-tables";
|
|
2
3
|
import type { BlockNoteEditor } from "../editor/BlockNoteEditor.js";
|
|
3
4
|
import { BlockConfig, PropSchema, PropSpec } from "../schema/index.js";
|
|
@@ -159,3 +160,8 @@ export function isTableCellSelection(
|
|
|
159
160
|
): selection is CellSelection {
|
|
160
161
|
return selection instanceof CellSelection;
|
|
161
162
|
}
|
|
163
|
+
|
|
164
|
+
export function isTableCellNode(node: Node): boolean {
|
|
165
|
+
const tableRole = node.type.spec.tableRole;
|
|
166
|
+
return tableRole === "cell" || tableRole === "header_cell";
|
|
167
|
+
}
|
package/src/editor/Block.css
CHANGED
|
@@ -735,9 +735,59 @@ NESTED BLOCKS
|
|
|
735
735
|
|
|
736
736
|
.bn-block-column {
|
|
737
737
|
flex: 1;
|
|
738
|
-
padding: 12px
|
|
738
|
+
padding: 12px 15px 12px 25px;
|
|
739
739
|
/* scroll if we overflow, for example when tables or images are in the column */
|
|
740
740
|
overflow-x: auto;
|
|
741
|
+
/* Lets the trailing block widget grow to fill the column's leftover height
|
|
742
|
+
when a sibling column is taller. */
|
|
743
|
+
display: flex;
|
|
744
|
+
flex-direction: column;
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
/* Shows separators between a column list's columns while the mouse is over
|
|
748
|
+
it. This clarifies where each column (and its clickable empty space) ends.
|
|
749
|
+
The class is managed by the multi-column package's column resize plugin. The
|
|
750
|
+
transition delay stops the separators from flashing in when the mouse just
|
|
751
|
+
passes through the column list. */
|
|
752
|
+
.bn-editor[contenteditable="true"]
|
|
753
|
+
.bn-column-list-hovered
|
|
754
|
+
> .bn-block-column:not(:last-child) {
|
|
755
|
+
box-shadow: 4px 0 0 #eee;
|
|
756
|
+
transition: box-shadow 0.2s ease 0.2s;
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
.bn-editor[contenteditable="true"]
|
|
760
|
+
.bn-column-list-hovered
|
|
761
|
+
> .bn-block-column:not(:last-child):where(.dark, .dark *) {
|
|
762
|
+
box-shadow: 4px 0 0 rgb(70, 70, 70);
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
/* The border between two columns when the cursor is near their boundary or
|
|
766
|
+
they're being resized, rendered on the boundary's left column. The class is
|
|
767
|
+
managed by the multi-column package's column resize plugin. */
|
|
768
|
+
.bn-editor[contenteditable="true"]
|
|
769
|
+
.bn-column-list-hovered
|
|
770
|
+
> .bn-block-column.bn-column-resize-border {
|
|
771
|
+
box-shadow: 4px 0 0 #ccc;
|
|
772
|
+
cursor: col-resize;
|
|
773
|
+
transition: box-shadow 0.2s ease;
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
.bn-editor[contenteditable="true"]
|
|
777
|
+
.bn-column-list-hovered
|
|
778
|
+
> .bn-block-column.bn-column-resize-border:where(.dark, .dark *) {
|
|
779
|
+
box-shadow: 4px 0 0 rgb(110, 110, 110);
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
.bn-editor[contenteditable="true"]
|
|
783
|
+
.bn-block-column.bn-column-resize-border
|
|
784
|
+
+ .bn-block-column {
|
|
785
|
+
cursor: col-resize;
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
.bn-block-column > .bn-trailing-block {
|
|
789
|
+
height: auto;
|
|
790
|
+
flex-grow: 1;
|
|
741
791
|
}
|
|
742
792
|
|
|
743
793
|
.bn-block-column:first-child {
|
|
@@ -241,6 +241,17 @@ export class SideMenuView<
|
|
|
241
241
|
if (this.editor.isEditable) {
|
|
242
242
|
const blockContentBoundingBox = block.node.getBoundingClientRect();
|
|
243
243
|
const column = block.node.closest("[data-node-type=column]");
|
|
244
|
+
const sideMenuBlock = this.editor.getBlock(
|
|
245
|
+
this.hoveredBlock!.getAttribute("data-id")!,
|
|
246
|
+
);
|
|
247
|
+
if (!sideMenuBlock) {
|
|
248
|
+
if (this.state?.show) {
|
|
249
|
+
this.state.show = false;
|
|
250
|
+
this.hoveredBlock = undefined;
|
|
251
|
+
this.emitUpdate(this.state);
|
|
252
|
+
}
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
244
255
|
this.state = {
|
|
245
256
|
show: true,
|
|
246
257
|
referencePos: new DOMRect(
|
|
@@ -257,9 +268,7 @@ export class SideMenuView<
|
|
|
257
268
|
blockContentBoundingBox.width,
|
|
258
269
|
blockContentBoundingBox.height,
|
|
259
270
|
),
|
|
260
|
-
block:
|
|
261
|
-
this.hoveredBlock!.getAttribute("data-id")!,
|
|
262
|
-
)!,
|
|
271
|
+
block: sideMenuBlock,
|
|
263
272
|
};
|
|
264
273
|
this.updateState(this.state);
|
|
265
274
|
}
|
|
@@ -764,6 +773,14 @@ export const SideMenuExtension = createExtension(({ editor }) => {
|
|
|
764
773
|
editor.blur();
|
|
765
774
|
},
|
|
766
775
|
|
|
776
|
+
/**
|
|
777
|
+
* Whether the side menu is currently frozen (e.g. because the drag handle
|
|
778
|
+
* menu is open).
|
|
779
|
+
*/
|
|
780
|
+
get menuFrozen() {
|
|
781
|
+
return view!.menuFrozen;
|
|
782
|
+
},
|
|
783
|
+
|
|
767
784
|
/**
|
|
768
785
|
* Freezes the side menu. When frozen, the side menu will stay
|
|
769
786
|
* attached to the same block regardless of which block is hovered by the
|
|
@@ -140,6 +140,124 @@ describe("SuggestionMenu", () => {
|
|
|
140
140
|
editor._tiptapEditor.destroy();
|
|
141
141
|
});
|
|
142
142
|
|
|
143
|
+
it("should open a suggestion menu with a multi-character trigger", () => {
|
|
144
|
+
const editor = createEditor();
|
|
145
|
+
const sm = editor.getExtension(SuggestionMenu)!;
|
|
146
|
+
|
|
147
|
+
sm.addSuggestionMenu({ triggerCharacter: "img:" });
|
|
148
|
+
|
|
149
|
+
editor.replaceBlocks(editor.document, [
|
|
150
|
+
{
|
|
151
|
+
id: "paragraph-0",
|
|
152
|
+
type: "paragraph",
|
|
153
|
+
content: "img",
|
|
154
|
+
},
|
|
155
|
+
]);
|
|
156
|
+
|
|
157
|
+
editor.setTextCursorPosition("paragraph-0", "end");
|
|
158
|
+
|
|
159
|
+
expect(getSuggestionPluginState(editor)).toBeUndefined();
|
|
160
|
+
|
|
161
|
+
// Typing the final ":" completes the "img:" trigger.
|
|
162
|
+
const handled = simulateTextInput(editor, ":");
|
|
163
|
+
|
|
164
|
+
expect(handled).toBe(true);
|
|
165
|
+
|
|
166
|
+
const pluginState = getSuggestionPluginState(editor);
|
|
167
|
+
expect(pluginState).toBeDefined();
|
|
168
|
+
expect(pluginState.triggerCharacter).toBe("img:");
|
|
169
|
+
|
|
170
|
+
editor._tiptapEditor.destroy();
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it("should match a multi-character trigger that is preceded by other text", () => {
|
|
174
|
+
const editor = createEditor();
|
|
175
|
+
const sm = editor.getExtension(SuggestionMenu)!;
|
|
176
|
+
|
|
177
|
+
sm.addSuggestionMenu({ triggerCharacter: "img:" });
|
|
178
|
+
|
|
179
|
+
editor.replaceBlocks(editor.document, [
|
|
180
|
+
{
|
|
181
|
+
id: "paragraph-0",
|
|
182
|
+
type: "paragraph",
|
|
183
|
+
content: "hello img",
|
|
184
|
+
},
|
|
185
|
+
]);
|
|
186
|
+
|
|
187
|
+
editor.setTextCursorPosition("paragraph-0", "end");
|
|
188
|
+
|
|
189
|
+
expect(getSuggestionPluginState(editor)).toBeUndefined();
|
|
190
|
+
|
|
191
|
+
const handled = simulateTextInput(editor, ":");
|
|
192
|
+
|
|
193
|
+
expect(handled).toBe(true);
|
|
194
|
+
|
|
195
|
+
const pluginState = getSuggestionPluginState(editor);
|
|
196
|
+
expect(pluginState).toBeDefined();
|
|
197
|
+
expect(pluginState.triggerCharacter).toBe("img:");
|
|
198
|
+
|
|
199
|
+
editor._tiptapEditor.destroy();
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it("should prefer a longer trigger over a shorter one that would shadow it", () => {
|
|
203
|
+
const editor = createEditor();
|
|
204
|
+
const sm = editor.getExtension(SuggestionMenu)!;
|
|
205
|
+
|
|
206
|
+
// Register the shorter ":" trigger first so it would win in insertion
|
|
207
|
+
// order, then the longer "img:" trigger that ends in the same character.
|
|
208
|
+
sm.addSuggestionMenu({ triggerCharacter: ":" });
|
|
209
|
+
sm.addSuggestionMenu({ triggerCharacter: "img:" });
|
|
210
|
+
|
|
211
|
+
editor.replaceBlocks(editor.document, [
|
|
212
|
+
{
|
|
213
|
+
id: "paragraph-0",
|
|
214
|
+
type: "paragraph",
|
|
215
|
+
content: "img",
|
|
216
|
+
},
|
|
217
|
+
]);
|
|
218
|
+
|
|
219
|
+
editor.setTextCursorPosition("paragraph-0", "end");
|
|
220
|
+
|
|
221
|
+
const handled = simulateTextInput(editor, ":");
|
|
222
|
+
|
|
223
|
+
expect(handled).toBe(true);
|
|
224
|
+
|
|
225
|
+
const pluginState = getSuggestionPluginState(editor);
|
|
226
|
+
expect(pluginState).toBeDefined();
|
|
227
|
+
expect(pluginState.triggerCharacter).toBe("img:");
|
|
228
|
+
|
|
229
|
+
editor._tiptapEditor.destroy();
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it("should fall back to the shorter trigger when the longer one does not match", () => {
|
|
233
|
+
const editor = createEditor();
|
|
234
|
+
const sm = editor.getExtension(SuggestionMenu)!;
|
|
235
|
+
|
|
236
|
+
sm.addSuggestionMenu({ triggerCharacter: ":" });
|
|
237
|
+
sm.addSuggestionMenu({ triggerCharacter: "img:" });
|
|
238
|
+
|
|
239
|
+
editor.replaceBlocks(editor.document, [
|
|
240
|
+
{
|
|
241
|
+
id: "paragraph-0",
|
|
242
|
+
type: "paragraph",
|
|
243
|
+
content: "hello",
|
|
244
|
+
},
|
|
245
|
+
]);
|
|
246
|
+
|
|
247
|
+
editor.setTextCursorPosition("paragraph-0", "end");
|
|
248
|
+
|
|
249
|
+
// "hello" + ":" doesn't complete "img:", so the bare ":" trigger wins.
|
|
250
|
+
const handled = simulateTextInput(editor, ":");
|
|
251
|
+
|
|
252
|
+
expect(handled).toBe(true);
|
|
253
|
+
|
|
254
|
+
const pluginState = getSuggestionPluginState(editor);
|
|
255
|
+
expect(pluginState).toBeDefined();
|
|
256
|
+
expect(pluginState.triggerCharacter).toBe(":");
|
|
257
|
+
|
|
258
|
+
editor._tiptapEditor.destroy();
|
|
259
|
+
});
|
|
260
|
+
|
|
143
261
|
it("should still allow suggestion menus without shouldTrigger in table content", () => {
|
|
144
262
|
const editor = createEditor();
|
|
145
263
|
const sm = editor.getExtension(SuggestionMenu)!;
|