@blocknote/core 0.47.2 → 0.48.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-B6RhuQ3V.js +27 -0
- package/dist/BlockNoteExtension-B6RhuQ3V.js.map +1 -0
- package/dist/BlockNoteExtension-ab0REuob.cjs +2 -0
- package/dist/BlockNoteExtension-ab0REuob.cjs.map +1 -0
- package/dist/EventEmitter-CuPnGDYt.js +22 -0
- package/dist/EventEmitter-CuPnGDYt.js.map +1 -0
- package/dist/EventEmitter-DHdSnYCD.cjs +2 -0
- package/dist/EventEmitter-DHdSnYCD.cjs.map +1 -0
- package/dist/ShowSelection-BsHFfdMi.js +29 -0
- package/dist/ShowSelection-BsHFfdMi.js.map +1 -0
- package/dist/ShowSelection-DhXglbt8.cjs +2 -0
- package/dist/ShowSelection-DhXglbt8.cjs.map +1 -0
- package/dist/blocknote.cjs +1 -5
- package/dist/blocknote.js +7 -4216
- package/dist/blocks-BEvIOzln.cjs +11 -0
- package/dist/blocks-BEvIOzln.cjs.map +1 -0
- package/dist/blocks-DYl7UTS4.js +3313 -0
- package/dist/blocks-DYl7UTS4.js.map +1 -0
- package/dist/blocks.cjs +1 -2
- package/dist/blocks.js +2 -74
- package/dist/comments.cjs +2 -2
- package/dist/comments.cjs.map +1 -1
- package/dist/comments.js +604 -900
- package/dist/comments.js.map +1 -1
- package/dist/en-C4ykW581.cjs +2 -0
- package/dist/en-C4ykW581.cjs.map +1 -0
- package/dist/en-QsSI16s5.js +453 -0
- package/dist/en-QsSI16s5.js.map +1 -0
- package/dist/extensions-3nf9PPhA.js +1495 -0
- package/dist/extensions-3nf9PPhA.js.map +1 -0
- package/dist/extensions-D9y6evn6.cjs +2 -0
- package/dist/extensions-D9y6evn6.cjs.map +1 -0
- package/dist/extensions.cjs +1 -2
- package/dist/extensions.js +4 -36
- package/dist/locales.cjs +2 -2
- package/dist/locales.cjs.map +1 -1
- package/dist/locales.js +10049 -9111
- package/dist/locales.js.map +1 -1
- package/dist/src-BKJH7Jla.cjs +5 -0
- package/dist/src-BKJH7Jla.cjs.map +1 -0
- package/dist/src-Hjv1f5lc.js +2386 -0
- package/dist/src-Hjv1f5lc.js.map +1 -0
- package/dist/style.css +2 -1
- package/dist/webpack-stats.json +1 -1
- package/dist/yjs.cjs +2 -2
- package/dist/yjs.cjs.map +1 -1
- package/dist/yjs.js +20 -38
- package/dist/yjs.js.map +1 -1
- package/package.json +8 -8
- package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.ts +15 -1
- package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.ts +5 -0
- package/src/api/blockManipulation/commands/nestBlock/__snapshots__/nestBlock.test.ts.snap +1095 -0
- package/src/api/blockManipulation/commands/nestBlock/nestBlock.test.ts +661 -0
- package/src/api/blockManipulation/commands/nestBlock/nestBlock.ts +128 -11
- package/src/api/parsers/html/parseHTML.ts +2 -0
- package/src/api/parsers/html/util/normalizeWhitespace.ts +87 -0
- package/src/blocks/File/helpers/render/createResizableFileBlockWrapper.ts +17 -23
- package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.test.ts +346 -0
- package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.ts +143 -71
- package/src/editor/Block.css +5 -8
- package/src/editor/BlockNoteEditor.ts +38 -1
- package/src/editor/editor.css +0 -20
- package/src/editor/managers/ExtensionManager/extensions.ts +12 -1
- package/src/editor/performance.test.ts +134 -0
- package/src/extensions/Collaboration/ForkYDoc.test.ts +115 -103
- package/src/extensions/Placeholder/Placeholder.ts +1 -1
- package/src/extensions/PreviousBlockType/PreviousBlockType.test.ts +86 -0
- package/src/extensions/PreviousBlockType/PreviousBlockType.ts +33 -49
- package/src/extensions/SideMenu/SideMenu.ts +14 -8
- package/src/extensions/TableHandles/TableHandles.ts +14 -0
- package/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +57 -17
- package/src/extensions/tiptap-extensions/UniqueID/UniqueID.ts +9 -8
- package/src/index.ts +1 -1
- package/src/schema/blocks/createSpec.ts +6 -2
- package/src/schema/inlineContent/types.ts +0 -1
- package/src/vite-env.d.ts +6 -0
- package/types/src/api/blockManipulation/commands/nestBlock/nestBlock.d.ts +14 -1
- package/types/src/api/blockManipulation/commands/nestBlock/nestBlock.test.d.ts +1 -0
- package/types/src/api/parsers/html/util/normalizeWhitespace.d.ts +6 -0
- package/types/src/blocks/ListItem/NumberedListItem/IndexingPlugin.test.d.ts +1 -0
- package/types/src/editor/BlockNoteEditor.d.ts +13 -0
- package/types/src/editor/performance.test.d.ts +1 -0
- package/types/src/extensions/PreviousBlockType/PreviousBlockType.test.d.ts +1 -0
- package/types/src/extensions/SideMenu/SideMenu.d.ts +6 -0
- package/types/src/extensions/TableHandles/TableHandles.d.ts +6 -0
- package/dist/BlockNoteExtension-BWw0r8Gy.cjs +0 -2
- package/dist/BlockNoteExtension-BWw0r8Gy.cjs.map +0 -1
- package/dist/BlockNoteExtension-C2X7LW-V.js +0 -25
- package/dist/BlockNoteExtension-C2X7LW-V.js.map +0 -1
- package/dist/BlockNoteSchema-CCs_V3lo.cjs +0 -2
- package/dist/BlockNoteSchema-CCs_V3lo.cjs.map +0 -1
- package/dist/BlockNoteSchema-ooiKsd5B.js +0 -270
- package/dist/BlockNoteSchema-ooiKsd5B.js.map +0 -1
- package/dist/EventEmitter-CLwfmbqG.cjs +0 -2
- package/dist/EventEmitter-CLwfmbqG.cjs.map +0 -1
- package/dist/EventEmitter-CjSwpTbz.js +0 -27
- package/dist/EventEmitter-CjSwpTbz.js.map +0 -1
- package/dist/ShowSelection-B0ch3unP.js +0 -51
- package/dist/ShowSelection-B0ch3unP.js.map +0 -1
- package/dist/ShowSelection-BxnbRvy4.cjs +0 -2
- package/dist/ShowSelection-BxnbRvy4.cjs.map +0 -1
- package/dist/TrailingNode-GzE59m_7.js +0 -2288
- package/dist/TrailingNode-GzE59m_7.js.map +0 -1
- package/dist/TrailingNode-n0WdMPUl.cjs +0 -2
- package/dist/TrailingNode-n0WdMPUl.cjs.map +0 -1
- package/dist/blockToNode-BNoNIXU7.js +0 -1140
- package/dist/blockToNode-BNoNIXU7.js.map +0 -1
- package/dist/blockToNode-CumVjgem.cjs +0 -7
- package/dist/blockToNode-CumVjgem.cjs.map +0 -1
- package/dist/blocknote.cjs.map +0 -1
- package/dist/blocknote.js.map +0 -1
- package/dist/blocks.cjs.map +0 -1
- package/dist/blocks.js.map +0 -1
- package/dist/defaultBlocks-Dg9kQWXm.cjs +0 -6
- package/dist/defaultBlocks-Dg9kQWXm.cjs.map +0 -1
- package/dist/defaultBlocks-ZzGbYgQn.js +0 -3284
- package/dist/defaultBlocks-ZzGbYgQn.js.map +0 -1
- package/dist/en-Cl87Uuyf.cjs +0 -2
- package/dist/en-Cl87Uuyf.cjs.map +0 -1
- package/dist/en-njEqD7AG.js +0 -408
- package/dist/en-njEqD7AG.js.map +0 -1
- package/dist/extensions.cjs.map +0 -1
- package/dist/extensions.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
import { Fragment, NodeType, Slice } from "prosemirror-model";
|
|
1
|
+
import { Fragment, NodeRange, NodeType, Slice } from "prosemirror-model";
|
|
2
2
|
import { Transaction } from "prosemirror-state";
|
|
3
|
-
import { ReplaceAroundStep } from "prosemirror-transform";
|
|
3
|
+
import { canJoin, liftTarget, ReplaceAroundStep } from "prosemirror-transform";
|
|
4
4
|
|
|
5
5
|
import { BlockNoteEditor } from "../../../../editor/BlockNoteEditor.js";
|
|
6
6
|
import { getBlockInfoFromTransaction } from "../../../getBlockInfoFromPos.js";
|
|
7
7
|
|
|
8
|
-
// TODO: Unit tests
|
|
9
8
|
/**
|
|
10
|
-
*
|
|
9
|
+
* Modified version of prosemirror-schema-list's sinkItem.
|
|
10
|
+
* https://github.com/ProseMirror/prosemirror-schema-list/blob/master/src/schema-list.ts
|
|
11
11
|
*
|
|
12
|
-
*
|
|
12
|
+
* Changes from the original:
|
|
13
|
+
* 1. Range predicate checks node.type instead of firstChild.type
|
|
14
|
+
* 2. nestedBefore checks groupType instead of parent.type
|
|
15
|
+
* 3. Slice creates groupType instead of parent.type
|
|
16
|
+
* 4. Operates on Transaction directly instead of state+dispatch
|
|
13
17
|
*/
|
|
14
|
-
function
|
|
18
|
+
function sinkItem(
|
|
15
19
|
tr: Transaction,
|
|
16
20
|
itemType: NodeType,
|
|
17
21
|
groupType: NodeType,
|
|
@@ -21,7 +25,7 @@ function sinkListItem(
|
|
|
21
25
|
$to,
|
|
22
26
|
(node) =>
|
|
23
27
|
node.childCount > 0 &&
|
|
24
|
-
(node.type.name === "blockGroup" || node.type.name === "column"), // change
|
|
28
|
+
(node.type.name === "blockGroup" || node.type.name === "column"), // change 1
|
|
25
29
|
);
|
|
26
30
|
if (!range) {
|
|
27
31
|
return false;
|
|
@@ -36,11 +40,11 @@ function sinkListItem(
|
|
|
36
40
|
return false;
|
|
37
41
|
}
|
|
38
42
|
const nestedBefore =
|
|
39
|
-
nodeBefore.lastChild && nodeBefore.lastChild.type === groupType; // change
|
|
43
|
+
nodeBefore.lastChild && nodeBefore.lastChild.type === groupType; // change 2
|
|
40
44
|
const inner = Fragment.from(nestedBefore ? itemType.create() : null);
|
|
41
45
|
const slice = new Slice(
|
|
42
46
|
Fragment.from(
|
|
43
|
-
itemType.create(null, Fragment.from(groupType.create(null, inner))), // change
|
|
47
|
+
itemType.create(null, Fragment.from(groupType.create(null, inner))), // change 3
|
|
44
48
|
),
|
|
45
49
|
nestedBefore ? 3 : 1,
|
|
46
50
|
0,
|
|
@@ -66,7 +70,7 @@ function sinkListItem(
|
|
|
66
70
|
|
|
67
71
|
export function nestBlock(editor: BlockNoteEditor<any, any, any>) {
|
|
68
72
|
return editor.transact((tr) => {
|
|
69
|
-
return
|
|
73
|
+
return sinkItem(
|
|
70
74
|
tr,
|
|
71
75
|
editor.pmSchema.nodes["blockContainer"],
|
|
72
76
|
editor.pmSchema.nodes["blockGroup"],
|
|
@@ -74,8 +78,121 @@ export function nestBlock(editor: BlockNoteEditor<any, any, any>) {
|
|
|
74
78
|
});
|
|
75
79
|
}
|
|
76
80
|
|
|
81
|
+
/**
|
|
82
|
+
* Modified version of prosemirror-schema-list's liftToOuterList.
|
|
83
|
+
* https://github.com/ProseMirror/prosemirror-schema-list/blob/master/src/schema-list.ts
|
|
84
|
+
*
|
|
85
|
+
* Changes from the original:
|
|
86
|
+
* 1. Operates on Transaction directly instead of state+dispatch (TipTap compat)
|
|
87
|
+
* 2. When the lifted block already has children (a groupType child), uses deeper
|
|
88
|
+
* openStart/offset so siblings merge into the existing group instead of
|
|
89
|
+
* creating a second one (which would violate blockContainer's schema)
|
|
90
|
+
* 3. Uses groupType.create() instead of range.parent.copy() (same as sinkItem)
|
|
91
|
+
*/
|
|
92
|
+
function liftToOuterList(
|
|
93
|
+
tr: Transaction,
|
|
94
|
+
itemType: NodeType,
|
|
95
|
+
groupType: NodeType, // change 3
|
|
96
|
+
range: NodeRange,
|
|
97
|
+
) {
|
|
98
|
+
const end = range.end;
|
|
99
|
+
const endOfList = range.$to.end(range.depth);
|
|
100
|
+
|
|
101
|
+
if (end < endOfList) {
|
|
102
|
+
// There are siblings after the lifted items, which must become
|
|
103
|
+
// children of the last item
|
|
104
|
+
const blockBeingLifted = range.parent.child(range.endIndex - 1);
|
|
105
|
+
const nestedAfter =
|
|
106
|
+
blockBeingLifted.lastChild &&
|
|
107
|
+
blockBeingLifted.lastChild.type === groupType; // change 2
|
|
108
|
+
|
|
109
|
+
tr.step(
|
|
110
|
+
new ReplaceAroundStep(
|
|
111
|
+
end - (nestedAfter ? 2 : 1), // change 2: go deeper when merging into existing children
|
|
112
|
+
endOfList,
|
|
113
|
+
end,
|
|
114
|
+
endOfList,
|
|
115
|
+
new Slice(
|
|
116
|
+
Fragment.from(
|
|
117
|
+
itemType.create(null, groupType.create()), // change 3
|
|
118
|
+
),
|
|
119
|
+
nestedAfter ? 2 : 1, // change 2: open deeper when merging into existing children
|
|
120
|
+
0,
|
|
121
|
+
),
|
|
122
|
+
nestedAfter ? 0 : 1, // change 2: Slice.insertAt offsets by openStart, so 0+2=2 lands inside existing bg
|
|
123
|
+
true,
|
|
124
|
+
),
|
|
125
|
+
);
|
|
126
|
+
range = new NodeRange(
|
|
127
|
+
tr.doc.resolve(range.$from.pos),
|
|
128
|
+
tr.doc.resolve(endOfList),
|
|
129
|
+
range.depth,
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const target = liftTarget(range);
|
|
134
|
+
if (target == null) {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
tr.lift(range, target);
|
|
139
|
+
|
|
140
|
+
const $after = tr.doc.resolve(tr.mapping.map(end, -1) - 1);
|
|
141
|
+
if (
|
|
142
|
+
canJoin(tr.doc, $after.pos) &&
|
|
143
|
+
$after.nodeBefore!.type === $after.nodeAfter!.type
|
|
144
|
+
) {
|
|
145
|
+
tr.join($after.pos);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
tr.scrollIntoView();
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Modified version of prosemirror-schema-list's liftListItem.
|
|
154
|
+
* https://github.com/ProseMirror/prosemirror-schema-list/blob/master/src/schema-list.ts
|
|
155
|
+
*
|
|
156
|
+
* Changes from the original:
|
|
157
|
+
* 1. Range predicate checks node.type instead of firstChild.type (same as sinkItem)
|
|
158
|
+
* 2. Passes groupType to liftToOuterList
|
|
159
|
+
* 3. Operates on Transaction directly instead of state+dispatch
|
|
160
|
+
* 4. Skips liftOutOfList (root-level blocks can't be unnested in BlockNote)
|
|
161
|
+
*/
|
|
162
|
+
export function liftItem(
|
|
163
|
+
tr: Transaction,
|
|
164
|
+
itemType: NodeType,
|
|
165
|
+
groupType: NodeType, // change 2
|
|
166
|
+
) {
|
|
167
|
+
const { $from, $to } = tr.selection;
|
|
168
|
+
const range = $from.blockRange(
|
|
169
|
+
$to,
|
|
170
|
+
(node) =>
|
|
171
|
+
node.childCount > 0 &&
|
|
172
|
+
(node.type.name === "blockGroup" || node.type.name === "column"), // change 1
|
|
173
|
+
);
|
|
174
|
+
if (!range) {
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if ($from.node(range.depth - 1).type === itemType) {
|
|
179
|
+
// Inside a parent node
|
|
180
|
+
return liftToOuterList(tr, itemType, groupType, range); // change 2
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// This is the "liftOutOfList" path — lifting out of a list entirely.
|
|
184
|
+
// Not applicable to BlockNote (root-level blocks can't be unnested). // change 4
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
|
|
77
188
|
export function unnestBlock(editor: BlockNoteEditor<any, any, any>) {
|
|
78
|
-
editor.
|
|
189
|
+
return editor.transact((tr) =>
|
|
190
|
+
liftItem(
|
|
191
|
+
tr,
|
|
192
|
+
editor.pmSchema.nodes["blockContainer"],
|
|
193
|
+
editor.pmSchema.nodes["blockGroup"],
|
|
194
|
+
),
|
|
195
|
+
);
|
|
79
196
|
}
|
|
80
197
|
|
|
81
198
|
export function canNestBlock(editor: BlockNoteEditor<any, any, any>) {
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
import { Block } from "../../../blocks/defaultBlocks.js";
|
|
9
9
|
import { nodeToBlock } from "../../nodeConversions/nodeToBlock.js";
|
|
10
10
|
import { nestedListsToBlockNoteStructure } from "./util/nestedLists.js";
|
|
11
|
+
import { preprocessHTMLWhitespace } from "./util/normalizeWhitespace.js";
|
|
11
12
|
|
|
12
13
|
export function HTMLToBlocks<
|
|
13
14
|
BSchema extends BlockSchema,
|
|
@@ -15,6 +16,7 @@ export function HTMLToBlocks<
|
|
|
15
16
|
S extends StyleSchema,
|
|
16
17
|
>(html: string, pmSchema: Schema): Block<BSchema, I, S>[] {
|
|
17
18
|
const htmlNode = nestedListsToBlockNoteStructure(html);
|
|
19
|
+
preprocessHTMLWhitespace(htmlNode);
|
|
18
20
|
const parser = DOMParser.fromSchema(pmSchema);
|
|
19
21
|
|
|
20
22
|
// Other approach might be to use
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if the given HTML element contains markers indicating it was
|
|
3
|
+
* generated by Notion. Notion uses `\n` in text nodes to represent hard
|
|
4
|
+
* breaks, which is non-standard but intentional.
|
|
5
|
+
*
|
|
6
|
+
* Detected by the `<!-- notionvc: UUID -->` comment that Notion places
|
|
7
|
+
* on the clipboard.
|
|
8
|
+
*/
|
|
9
|
+
function isNotionHTML(element: HTMLElement): boolean {
|
|
10
|
+
const walker = element.ownerDocument.createTreeWalker(
|
|
11
|
+
element,
|
|
12
|
+
// NodeFilter.SHOW_COMMENT
|
|
13
|
+
128,
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
let node: Node | null;
|
|
17
|
+
while ((node = walker.nextNode())) {
|
|
18
|
+
if (/^\s*notionvc:/.test(node.nodeValue || "")) {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Normalizes whitespace in text nodes by collapsing runs of whitespace
|
|
28
|
+
* (including newlines) to single spaces, matching CSS white-space:normal
|
|
29
|
+
* behavior.
|
|
30
|
+
*
|
|
31
|
+
* This is needed because ProseMirror's DOMParser, when `linebreakReplacement`
|
|
32
|
+
* is set in the schema (as BlockNote does for hard breaks), converts `\n`
|
|
33
|
+
* characters in text nodes to hard break nodes instead of collapsing them.
|
|
34
|
+
* This causes HTML source line wrapping (e.g. from MS Word) to create
|
|
35
|
+
* visible line breaks in the editor.
|
|
36
|
+
*
|
|
37
|
+
* Skipped for sources like Notion that intentionally use `\n` in text nodes
|
|
38
|
+
* to represent hard breaks instead of `<br>` tags.
|
|
39
|
+
*
|
|
40
|
+
* Skips `<pre>` and `<code>` elements where whitespace should be preserved.
|
|
41
|
+
*/
|
|
42
|
+
function normalizeTextNodeWhitespace(element: HTMLElement) {
|
|
43
|
+
const preserveWSTags = new Set(["PRE", "CODE"]);
|
|
44
|
+
const walker = element.ownerDocument.createTreeWalker(
|
|
45
|
+
element,
|
|
46
|
+
// NodeFilter.SHOW_TEXT
|
|
47
|
+
4,
|
|
48
|
+
{
|
|
49
|
+
acceptNode(node) {
|
|
50
|
+
// Skip text nodes inside pre/code elements
|
|
51
|
+
let parent = node.parentElement;
|
|
52
|
+
while (parent && parent !== element) {
|
|
53
|
+
if (preserveWSTags.has(parent.tagName)) {
|
|
54
|
+
// NodeFilter.FILTER_REJECT
|
|
55
|
+
return 2;
|
|
56
|
+
}
|
|
57
|
+
parent = parent.parentElement;
|
|
58
|
+
}
|
|
59
|
+
// NodeFilter.FILTER_ACCEPT
|
|
60
|
+
return 1;
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
const textNodes: Text[] = [];
|
|
66
|
+
let node: Node | null;
|
|
67
|
+
while ((node = walker.nextNode())) {
|
|
68
|
+
textNodes.push(node as Text);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
for (const textNode of textNodes) {
|
|
72
|
+
if (textNode.nodeValue && /[\r\n]/.test(textNode.nodeValue)) {
|
|
73
|
+
textNode.nodeValue = textNode.nodeValue.replace(/[ \t\r\n\f]+/g, " ");
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Normalizes whitespace in HTML text nodes to match standard CSS
|
|
80
|
+
* white-space:normal behavior. Skipped for Notion HTML which intentionally
|
|
81
|
+
* uses `\n` for hard breaks.
|
|
82
|
+
*/
|
|
83
|
+
export function preprocessHTMLWhitespace(element: HTMLElement) {
|
|
84
|
+
if (!isNotionHTML(element)) {
|
|
85
|
+
normalizeTextNodeWhitespace(element);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -47,9 +47,13 @@ export const createResizableFileBlockWrapper = (
|
|
|
47
47
|
const leftResizeHandle = document.createElement("div");
|
|
48
48
|
leftResizeHandle.className = "bn-resize-handle";
|
|
49
49
|
leftResizeHandle.style.left = "4px";
|
|
50
|
+
leftResizeHandle.style.display = "none";
|
|
51
|
+
resizeHandlesContainerElement.appendChild(leftResizeHandle);
|
|
50
52
|
const rightResizeHandle = document.createElement("div");
|
|
51
53
|
rightResizeHandle.className = "bn-resize-handle";
|
|
52
54
|
rightResizeHandle.style.right = "4px";
|
|
55
|
+
rightResizeHandle.style.display = "none";
|
|
56
|
+
resizeHandlesContainerElement.appendChild(rightResizeHandle);
|
|
53
57
|
|
|
54
58
|
// This element ensures `mousemove` and `mouseup` events are captured while
|
|
55
59
|
// resizing when the cursor is over the wrapper content. This is because
|
|
@@ -75,13 +79,9 @@ export const createResizableFileBlockWrapper = (
|
|
|
75
79
|
// offset from when the resize began, and which resize handle is being used.
|
|
76
80
|
const windowMouseMoveHandler = (event: MouseEvent | TouchEvent) => {
|
|
77
81
|
if (!resizeParams) {
|
|
78
|
-
if (
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
resizeHandlesContainerElement.contains(rightResizeHandle)
|
|
82
|
-
) {
|
|
83
|
-
resizeHandlesContainerElement.removeChild(leftResizeHandle);
|
|
84
|
-
resizeHandlesContainerElement.removeChild(rightResizeHandle);
|
|
82
|
+
if (!editor.isEditable) {
|
|
83
|
+
leftResizeHandle.style.display = "none";
|
|
84
|
+
rightResizeHandle.style.display = "none";
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
return;
|
|
@@ -128,14 +128,12 @@ export const createResizableFileBlockWrapper = (
|
|
|
128
128
|
const windowMouseUpHandler = (event: MouseEvent | TouchEvent) => {
|
|
129
129
|
// Hides the drag handles if the cursor is no longer over the element.
|
|
130
130
|
if (
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
resizeHandlesContainerElement.contains(leftResizeHandle) &&
|
|
135
|
-
resizeHandlesContainerElement.contains(rightResizeHandle)
|
|
131
|
+
!event.target ||
|
|
132
|
+
!wrapper.contains(event.target as Node) ||
|
|
133
|
+
!editor.isEditable
|
|
136
134
|
) {
|
|
137
|
-
|
|
138
|
-
|
|
135
|
+
leftResizeHandle.style.display = "none";
|
|
136
|
+
rightResizeHandle.style.display = "none";
|
|
139
137
|
}
|
|
140
138
|
|
|
141
139
|
if (!resizeParams) {
|
|
@@ -158,8 +156,8 @@ export const createResizableFileBlockWrapper = (
|
|
|
158
156
|
// Shows the resize handles when hovering over the wrapper with the cursor.
|
|
159
157
|
const wrapperMouseEnterHandler = () => {
|
|
160
158
|
if (editor.isEditable) {
|
|
161
|
-
|
|
162
|
-
|
|
159
|
+
leftResizeHandle.style.display = "";
|
|
160
|
+
rightResizeHandle.style.display = "";
|
|
163
161
|
}
|
|
164
162
|
};
|
|
165
163
|
// Hides the resize handles when the cursor leaves the wrapper, unless the
|
|
@@ -176,13 +174,9 @@ export const createResizableFileBlockWrapper = (
|
|
|
176
174
|
return;
|
|
177
175
|
}
|
|
178
176
|
|
|
179
|
-
if (
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
resizeHandlesContainerElement.contains(rightResizeHandle)
|
|
183
|
-
) {
|
|
184
|
-
resizeHandlesContainerElement.removeChild(leftResizeHandle);
|
|
185
|
-
resizeHandlesContainerElement.removeChild(rightResizeHandle);
|
|
177
|
+
if (editor.isEditable) {
|
|
178
|
+
leftResizeHandle.style.display = "none";
|
|
179
|
+
rightResizeHandle.style.display = "none";
|
|
186
180
|
}
|
|
187
181
|
};
|
|
188
182
|
|