@blocknote/core 0.36.0 → 0.37.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 +7 -7
- package/dist/blocknote.cjs.map +1 -1
- package/dist/blocknote.js +1064 -999
- package/dist/blocknote.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/webpack-stats.json +1 -1
- package/package.json +2 -1
- package/src/api/__snapshots__/blocks-moved-down-twice-in-same-parent.json +44 -0
- package/src/api/__snapshots__/blocks-moved-insert-changes-sibling-order.json +26 -0
- package/src/api/__snapshots__/blocks-moved-nested-sibling-reorder.json +180 -0
- package/src/api/__snapshots__/blocks-moved-up-down-in-same-parent.json +44 -0
- package/src/api/__snapshots__/blocks-moved-up-down-in-same-transaction.json +44 -0
- package/src/api/{nodeUtil.test.ts → getBlocksChangedByTransaction.test.ts} +117 -1
- package/src/api/getBlocksChangedByTransaction.ts +422 -0
- package/src/api/nodeUtil.ts +0 -250
- package/src/blocks/FileBlockContent/helpers/render/createResizableFileBlockWrapper.ts +22 -0
- package/src/blocks/TableBlockContent/TableBlockContent.ts +26 -2
- package/src/editor/BlockNoteEditor.ts +1 -1
- package/src/editor/editor.css +5 -0
- package/src/extensions/BlockChange/BlockChangePlugin.ts +4 -2
- package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +1 -5
- package/src/index.ts +1 -0
- package/types/src/api/getBlocksChangedByTransaction.d.ts +63 -0
- package/types/src/api/nodeUtil.d.ts +0 -63
- package/types/src/editor/BlockNoteEditor.d.ts +1 -1
- package/types/src/extensions/BlockChange/BlockChangePlugin.d.ts +1 -1
- package/types/src/extensions/TableHandles/TableHandlesPlugin.d.ts +2 -2
- package/types/src/index.d.ts +1 -0
- package/types/src/schema/inlineContent/internal.d.ts +1 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- /package/types/src/api/{nodeUtil.test.d.ts → getBlocksChangedByTransaction.test.d.ts} +0 -0
package/src/api/nodeUtil.ts
CHANGED
|
@@ -1,34 +1,4 @@
|
|
|
1
|
-
import { combineTransactionSteps } from "@tiptap/core";
|
|
2
1
|
import type { Node } from "prosemirror-model";
|
|
3
|
-
import type { Transaction } from "prosemirror-state";
|
|
4
|
-
import {
|
|
5
|
-
Block,
|
|
6
|
-
DefaultBlockSchema,
|
|
7
|
-
DefaultInlineContentSchema,
|
|
8
|
-
DefaultStyleSchema,
|
|
9
|
-
} from "../blocks/defaultBlocks.js";
|
|
10
|
-
import type { BlockSchema } from "../schema/index.js";
|
|
11
|
-
import type { InlineContentSchema } from "../schema/inlineContent/types.js";
|
|
12
|
-
import type { StyleSchema } from "../schema/styles/types.js";
|
|
13
|
-
import { nodeToBlock } from "./nodeConversions/nodeToBlock.js";
|
|
14
|
-
import { getPmSchema } from "./pmUtil.js";
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Gets the parent block of a node, if it has one.
|
|
18
|
-
*/
|
|
19
|
-
function getParentBlockId(doc: Node, pos: number): string | undefined {
|
|
20
|
-
if (pos === 0) {
|
|
21
|
-
return undefined;
|
|
22
|
-
}
|
|
23
|
-
const resolvedPos = doc.resolve(pos);
|
|
24
|
-
for (let i = resolvedPos.depth; i > 0; i--) {
|
|
25
|
-
const parent = resolvedPos.node(i);
|
|
26
|
-
if (isNodeBlock(parent)) {
|
|
27
|
-
return parent.attrs.id;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return undefined;
|
|
31
|
-
}
|
|
32
2
|
|
|
33
3
|
/**
|
|
34
4
|
* Get a TipTap node by id
|
|
@@ -70,223 +40,3 @@ export function getNodeById(
|
|
|
70
40
|
export function isNodeBlock(node: Node): boolean {
|
|
71
41
|
return node.type.isInGroup("bnBlock");
|
|
72
42
|
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* This attributes the changes to a specific source.
|
|
76
|
-
*/
|
|
77
|
-
export type BlockChangeSource =
|
|
78
|
-
| { type: "local" }
|
|
79
|
-
| { type: "paste" }
|
|
80
|
-
| { type: "drop" }
|
|
81
|
-
| { type: "undo" | "redo" | "undo-redo" }
|
|
82
|
-
| { type: "yjs-remote" };
|
|
83
|
-
|
|
84
|
-
export type BlocksChanged<
|
|
85
|
-
BSchema extends BlockSchema = DefaultBlockSchema,
|
|
86
|
-
ISchema extends InlineContentSchema = DefaultInlineContentSchema,
|
|
87
|
-
SSchema extends StyleSchema = DefaultStyleSchema,
|
|
88
|
-
> = Array<
|
|
89
|
-
{
|
|
90
|
-
/**
|
|
91
|
-
* The affected block.
|
|
92
|
-
*/
|
|
93
|
-
block: Block<BSchema, ISchema, SSchema>;
|
|
94
|
-
/**
|
|
95
|
-
* The source of the change.
|
|
96
|
-
*/
|
|
97
|
-
source: BlockChangeSource;
|
|
98
|
-
} & (
|
|
99
|
-
| {
|
|
100
|
-
type: "insert" | "delete";
|
|
101
|
-
/**
|
|
102
|
-
* Insert and delete changes don't have a previous block.
|
|
103
|
-
*/
|
|
104
|
-
prevBlock: undefined;
|
|
105
|
-
}
|
|
106
|
-
| {
|
|
107
|
-
type: "update";
|
|
108
|
-
/**
|
|
109
|
-
* The previous block.
|
|
110
|
-
*/
|
|
111
|
-
prevBlock: Block<BSchema, ISchema, SSchema>;
|
|
112
|
-
}
|
|
113
|
-
| {
|
|
114
|
-
type: "move";
|
|
115
|
-
/**
|
|
116
|
-
* The affected block.
|
|
117
|
-
*/
|
|
118
|
-
block: Block<BSchema, ISchema, SSchema>;
|
|
119
|
-
/**
|
|
120
|
-
* The block before the move.
|
|
121
|
-
*/
|
|
122
|
-
prevBlock: Block<BSchema, ISchema, SSchema>;
|
|
123
|
-
/**
|
|
124
|
-
* The previous parent block (if it existed).
|
|
125
|
-
*/
|
|
126
|
-
prevParent?: Block<BSchema, ISchema, SSchema>;
|
|
127
|
-
/**
|
|
128
|
-
* The current parent block (if it exists).
|
|
129
|
-
*/
|
|
130
|
-
currentParent?: Block<BSchema, ISchema, SSchema>;
|
|
131
|
-
}
|
|
132
|
-
)
|
|
133
|
-
>;
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Compares two blocks, ignoring their children.
|
|
137
|
-
* Returns true if the blocks are different (excluding children).
|
|
138
|
-
*/
|
|
139
|
-
function areBlocksDifferentExcludingChildren<
|
|
140
|
-
BSchema extends BlockSchema,
|
|
141
|
-
ISchema extends InlineContentSchema,
|
|
142
|
-
SSchema extends StyleSchema,
|
|
143
|
-
>(
|
|
144
|
-
block1: Block<BSchema, ISchema, SSchema>,
|
|
145
|
-
block2: Block<BSchema, ISchema, SSchema>,
|
|
146
|
-
): boolean {
|
|
147
|
-
return (
|
|
148
|
-
block1.id !== block2.id ||
|
|
149
|
-
block1.type !== block2.type ||
|
|
150
|
-
JSON.stringify(block1.props) !== JSON.stringify(block2.props) ||
|
|
151
|
-
JSON.stringify(block1.content) !== JSON.stringify(block2.content)
|
|
152
|
-
);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
function determineChangeSource(transaction: Transaction): BlockChangeSource {
|
|
156
|
-
if (transaction.getMeta("paste")) {
|
|
157
|
-
return { type: "paste" };
|
|
158
|
-
}
|
|
159
|
-
if (transaction.getMeta("uiEvent") === "drop") {
|
|
160
|
-
return { type: "drop" };
|
|
161
|
-
}
|
|
162
|
-
if (transaction.getMeta("history$")) {
|
|
163
|
-
return {
|
|
164
|
-
type: transaction.getMeta("history$").redo ? "redo" : "undo",
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
if (transaction.getMeta("y-sync$")) {
|
|
168
|
-
if (transaction.getMeta("y-sync$").isUndoRedoOperation) {
|
|
169
|
-
return { type: "undo-redo" };
|
|
170
|
-
}
|
|
171
|
-
return { type: "yjs-remote" };
|
|
172
|
-
}
|
|
173
|
-
return { type: "local" };
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function collectAllBlocks<
|
|
177
|
-
BSchema extends BlockSchema,
|
|
178
|
-
ISchema extends InlineContentSchema,
|
|
179
|
-
SSchema extends StyleSchema,
|
|
180
|
-
>(
|
|
181
|
-
doc: Node,
|
|
182
|
-
): Record<
|
|
183
|
-
string,
|
|
184
|
-
{
|
|
185
|
-
block: Block<BSchema, ISchema, SSchema>;
|
|
186
|
-
parentId: string | undefined;
|
|
187
|
-
}
|
|
188
|
-
> {
|
|
189
|
-
const blocks: Record<
|
|
190
|
-
string,
|
|
191
|
-
{
|
|
192
|
-
block: Block<BSchema, ISchema, SSchema>;
|
|
193
|
-
parentId: string | undefined;
|
|
194
|
-
}
|
|
195
|
-
> = {};
|
|
196
|
-
const pmSchema = getPmSchema(doc);
|
|
197
|
-
doc.descendants((node, pos) => {
|
|
198
|
-
if (isNodeBlock(node)) {
|
|
199
|
-
const parentId = getParentBlockId(doc, pos);
|
|
200
|
-
blocks[node.attrs.id] = {
|
|
201
|
-
block: nodeToBlock(node, pmSchema),
|
|
202
|
-
parentId,
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
return true;
|
|
206
|
-
});
|
|
207
|
-
return blocks;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* Get the blocks that were changed by a transaction.
|
|
212
|
-
*/
|
|
213
|
-
export function getBlocksChangedByTransaction<
|
|
214
|
-
BSchema extends BlockSchema = DefaultBlockSchema,
|
|
215
|
-
ISchema extends InlineContentSchema = DefaultInlineContentSchema,
|
|
216
|
-
SSchema extends StyleSchema = DefaultStyleSchema,
|
|
217
|
-
>(
|
|
218
|
-
transaction: Transaction,
|
|
219
|
-
appendedTransactions: Transaction[] = [],
|
|
220
|
-
): BlocksChanged<BSchema, ISchema, SSchema> {
|
|
221
|
-
const source = determineChangeSource(transaction);
|
|
222
|
-
const combinedTransaction = combineTransactionSteps(transaction.before, [
|
|
223
|
-
transaction,
|
|
224
|
-
...appendedTransactions,
|
|
225
|
-
]);
|
|
226
|
-
|
|
227
|
-
const prevBlocks = collectAllBlocks<BSchema, ISchema, SSchema>(
|
|
228
|
-
combinedTransaction.before,
|
|
229
|
-
);
|
|
230
|
-
const nextBlocks = collectAllBlocks<BSchema, ISchema, SSchema>(
|
|
231
|
-
combinedTransaction.doc,
|
|
232
|
-
);
|
|
233
|
-
|
|
234
|
-
const changes: BlocksChanged<BSchema, ISchema, SSchema> = [];
|
|
235
|
-
|
|
236
|
-
// Handle inserted blocks
|
|
237
|
-
Object.keys(nextBlocks)
|
|
238
|
-
.filter((id) => !(id in prevBlocks))
|
|
239
|
-
.forEach((id) => {
|
|
240
|
-
changes.push({
|
|
241
|
-
type: "insert",
|
|
242
|
-
block: nextBlocks[id].block,
|
|
243
|
-
source,
|
|
244
|
-
prevBlock: undefined,
|
|
245
|
-
});
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
// Handle deleted blocks
|
|
249
|
-
Object.keys(prevBlocks)
|
|
250
|
-
.filter((id) => !(id in nextBlocks))
|
|
251
|
-
.forEach((id) => {
|
|
252
|
-
changes.push({
|
|
253
|
-
type: "delete",
|
|
254
|
-
block: prevBlocks[id].block,
|
|
255
|
-
source,
|
|
256
|
-
prevBlock: undefined,
|
|
257
|
-
});
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
// Handle updated, moved, indented, outdented blocks
|
|
261
|
-
Object.keys(nextBlocks)
|
|
262
|
-
.filter((id) => id in prevBlocks)
|
|
263
|
-
.forEach((id) => {
|
|
264
|
-
const prev = prevBlocks[id];
|
|
265
|
-
const next = nextBlocks[id];
|
|
266
|
-
const isParentDifferent = prev.parentId !== next.parentId;
|
|
267
|
-
|
|
268
|
-
if (isParentDifferent) {
|
|
269
|
-
changes.push({
|
|
270
|
-
type: "move",
|
|
271
|
-
block: next.block,
|
|
272
|
-
prevBlock: prev.block,
|
|
273
|
-
source,
|
|
274
|
-
prevParent: prev.parentId
|
|
275
|
-
? prevBlocks[prev.parentId]?.block
|
|
276
|
-
: undefined,
|
|
277
|
-
currentParent: next.parentId
|
|
278
|
-
? nextBlocks[next.parentId]?.block
|
|
279
|
-
: undefined,
|
|
280
|
-
});
|
|
281
|
-
} else if (areBlocksDifferentExcludingChildren(prev.block, next.block)) {
|
|
282
|
-
changes.push({
|
|
283
|
-
type: "update",
|
|
284
|
-
block: next.block,
|
|
285
|
-
prevBlock: prev.block,
|
|
286
|
-
source,
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
return changes;
|
|
292
|
-
}
|
|
@@ -18,6 +18,7 @@ export const createResizableFileBlockWrapper = (
|
|
|
18
18
|
buttonIcon,
|
|
19
19
|
);
|
|
20
20
|
const wrapper = dom;
|
|
21
|
+
wrapper.style.position = "relative";
|
|
21
22
|
if (block.props.url && block.props.showPreview) {
|
|
22
23
|
if (block.props.previewWidth) {
|
|
23
24
|
wrapper.style.width = `${block.props.previewWidth}px`;
|
|
@@ -33,6 +34,15 @@ export const createResizableFileBlockWrapper = (
|
|
|
33
34
|
rightResizeHandle.className = "bn-resize-handle";
|
|
34
35
|
rightResizeHandle.style.right = "4px";
|
|
35
36
|
|
|
37
|
+
// This element ensures `mousemove` and `mouseup` events are captured while
|
|
38
|
+
// resizing when the cursor is over the wrapper content. This is because
|
|
39
|
+
// embeds are treated as separate HTML documents, so if the content is an
|
|
40
|
+
// embed, the events will only fire within that document.
|
|
41
|
+
const eventCaptureElement = document.createElement("div");
|
|
42
|
+
eventCaptureElement.style.position = "absolute";
|
|
43
|
+
eventCaptureElement.style.height = "100%";
|
|
44
|
+
eventCaptureElement.style.width = "100%";
|
|
45
|
+
|
|
36
46
|
// Temporary parameters set when the user begins resizing the element, used to
|
|
37
47
|
// calculate the new width of the element.
|
|
38
48
|
let resizeParams:
|
|
@@ -118,6 +128,10 @@ export const createResizableFileBlockWrapper = (
|
|
|
118
128
|
|
|
119
129
|
resizeParams = undefined;
|
|
120
130
|
|
|
131
|
+
if (wrapper.contains(eventCaptureElement)) {
|
|
132
|
+
wrapper.removeChild(eventCaptureElement);
|
|
133
|
+
}
|
|
134
|
+
|
|
121
135
|
editor.updateBlock(block, {
|
|
122
136
|
props: {
|
|
123
137
|
previewWidth: width,
|
|
@@ -161,6 +175,10 @@ export const createResizableFileBlockWrapper = (
|
|
|
161
175
|
const leftResizeHandleMouseDownHandler = (event: MouseEvent) => {
|
|
162
176
|
event.preventDefault();
|
|
163
177
|
|
|
178
|
+
if (!wrapper.contains(eventCaptureElement)) {
|
|
179
|
+
wrapper.appendChild(eventCaptureElement);
|
|
180
|
+
}
|
|
181
|
+
|
|
164
182
|
resizeParams = {
|
|
165
183
|
handleUsed: "left",
|
|
166
184
|
initialWidth: wrapper.clientWidth,
|
|
@@ -170,6 +188,10 @@ export const createResizableFileBlockWrapper = (
|
|
|
170
188
|
const rightResizeHandleMouseDownHandler = (event: MouseEvent) => {
|
|
171
189
|
event.preventDefault();
|
|
172
190
|
|
|
191
|
+
if (!wrapper.contains(eventCaptureElement)) {
|
|
192
|
+
wrapper.appendChild(eventCaptureElement);
|
|
193
|
+
}
|
|
194
|
+
|
|
173
195
|
resizeParams = {
|
|
174
196
|
handleUsed: "right",
|
|
175
197
|
initialWidth: wrapper.clientWidth,
|
|
@@ -34,8 +34,8 @@ export const TableBlockContent = createStronglyTypedTiptapNode({
|
|
|
34
34
|
];
|
|
35
35
|
},
|
|
36
36
|
|
|
37
|
-
renderHTML({ HTMLAttributes }) {
|
|
38
|
-
|
|
37
|
+
renderHTML({ node, HTMLAttributes }) {
|
|
38
|
+
const domOutputSpec = createDefaultBlockDOMOutputSpec(
|
|
39
39
|
this.name,
|
|
40
40
|
"table",
|
|
41
41
|
{
|
|
@@ -44,6 +44,30 @@ export const TableBlockContent = createStronglyTypedTiptapNode({
|
|
|
44
44
|
},
|
|
45
45
|
this.options.domAttributes?.inlineContent || {},
|
|
46
46
|
);
|
|
47
|
+
|
|
48
|
+
// Need to manually add colgroup element
|
|
49
|
+
const colGroup = document.createElement("colgroup");
|
|
50
|
+
for (const tableCell of node.children[0].children) {
|
|
51
|
+
const colWidths: null | (number | undefined)[] =
|
|
52
|
+
tableCell.attrs["colwidth"];
|
|
53
|
+
|
|
54
|
+
if (colWidths) {
|
|
55
|
+
for (const colWidth of tableCell.attrs["colwidth"]) {
|
|
56
|
+
const col = document.createElement("col");
|
|
57
|
+
if (colWidth) {
|
|
58
|
+
col.style = `width: ${colWidth}px`;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
colGroup.appendChild(col);
|
|
62
|
+
}
|
|
63
|
+
} else {
|
|
64
|
+
colGroup.appendChild(document.createElement("col"));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
domOutputSpec.dom.firstChild?.appendChild(colGroup);
|
|
69
|
+
|
|
70
|
+
return domOutputSpec;
|
|
47
71
|
},
|
|
48
72
|
|
|
49
73
|
// This node view is needed for the `columnResizing` plugin. By default, the
|
|
@@ -110,7 +110,7 @@ import { docToBlocks } from "../api/nodeConversions/nodeToBlock.js";
|
|
|
110
110
|
import {
|
|
111
111
|
BlocksChanged,
|
|
112
112
|
getBlocksChangedByTransaction,
|
|
113
|
-
} from "../api/
|
|
113
|
+
} from "../api/getBlocksChangedByTransaction.js";
|
|
114
114
|
import { nestedListsToBlockNoteStructure } from "../api/parsers/html/util/nestedLists.js";
|
|
115
115
|
import { CodeBlockOptions } from "../blocks/CodeBlockContent/CodeBlockContent.js";
|
|
116
116
|
import type { ThreadStore, User } from "../comments/index.js";
|
package/src/editor/editor.css
CHANGED
|
@@ -176,6 +176,11 @@ Tippy popups that are appended to document.body directly
|
|
|
176
176
|
text-align: left;
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
+
.bn-editor [data-content-type="table"] th > p,
|
|
180
|
+
.bn-editor [data-content-type="table"] td > p {
|
|
181
|
+
min-height: 1.5rem;
|
|
182
|
+
}
|
|
183
|
+
|
|
179
184
|
/* tiptap uses colwidth instead of data-colwidth, se we need to adjust this style from prosemirror-tables */
|
|
180
185
|
.ProseMirror td,
|
|
181
186
|
.ProseMirror th {
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { Plugin, Transaction } from "prosemirror-state";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
BlocksChanged,
|
|
4
|
+
getBlocksChangedByTransaction,
|
|
5
|
+
} from "../../api/getBlocksChangedByTransaction.js";
|
|
3
6
|
import { BlockNoteExtension } from "../../editor/BlockNoteExtension.js";
|
|
4
|
-
import { BlocksChanged } from "../../index.js";
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
* This plugin can filter transactions before they are applied to the editor, but with a higher-level API than `filterTransaction` from prosemirror.
|
|
@@ -211,11 +211,7 @@ export class FormattingToolbarView implements PluginView {
|
|
|
211
211
|
// content causes the formatting toolbar to be in the wrong place. We
|
|
212
212
|
// know the component has not yet rendered if the reference position has
|
|
213
213
|
// zero dimensions.
|
|
214
|
-
if (
|
|
215
|
-
newReferencePos.x === 0 ||
|
|
216
|
-
newReferencePos.y === 0 ||
|
|
217
|
-
newReferencePos.height === 0
|
|
218
|
-
) {
|
|
214
|
+
if (newReferencePos.height === 0 && newReferencePos.width === 0) {
|
|
219
215
|
// Updates the reference position again following the render.
|
|
220
216
|
queueMicrotask(() => {
|
|
221
217
|
const nextState = {
|
package/src/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * from "./api/blockManipulation/commands/updateBlock/updateBlock.js";
|
|
|
4
4
|
export * from "./api/exporters/html/externalHTMLExporter.js";
|
|
5
5
|
export * from "./api/exporters/html/internalHTMLSerializer.js";
|
|
6
6
|
export * from "./api/getBlockInfoFromPos.js";
|
|
7
|
+
export * from "./api/getBlocksChangedByTransaction.js";
|
|
7
8
|
export * from "./api/nodeUtil.js";
|
|
8
9
|
export * from "./api/pmUtil.js";
|
|
9
10
|
export * from "./blocks/AudioBlockContent/AudioBlockContent.js";
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { Transaction } from "prosemirror-state";
|
|
2
|
+
import { Block, DefaultBlockSchema, DefaultInlineContentSchema, DefaultStyleSchema } from "../blocks/defaultBlocks.js";
|
|
3
|
+
import type { BlockSchema } from "../schema/index.js";
|
|
4
|
+
import type { InlineContentSchema } from "../schema/inlineContent/types.js";
|
|
5
|
+
import type { StyleSchema } from "../schema/styles/types.js";
|
|
6
|
+
/**
|
|
7
|
+
* This attributes the changes to a specific source.
|
|
8
|
+
*/
|
|
9
|
+
export type BlockChangeSource = {
|
|
10
|
+
type: "local";
|
|
11
|
+
} | {
|
|
12
|
+
type: "paste";
|
|
13
|
+
} | {
|
|
14
|
+
type: "drop";
|
|
15
|
+
} | {
|
|
16
|
+
type: "undo" | "redo" | "undo-redo";
|
|
17
|
+
} | {
|
|
18
|
+
type: "yjs-remote";
|
|
19
|
+
};
|
|
20
|
+
export type BlocksChanged<BSchema extends BlockSchema = DefaultBlockSchema, ISchema extends InlineContentSchema = DefaultInlineContentSchema, SSchema extends StyleSchema = DefaultStyleSchema> = Array<{
|
|
21
|
+
/**
|
|
22
|
+
* The affected block.
|
|
23
|
+
*/
|
|
24
|
+
block: Block<BSchema, ISchema, SSchema>;
|
|
25
|
+
/**
|
|
26
|
+
* The source of the change.
|
|
27
|
+
*/
|
|
28
|
+
source: BlockChangeSource;
|
|
29
|
+
} & ({
|
|
30
|
+
type: "insert" | "delete";
|
|
31
|
+
/**
|
|
32
|
+
* Insert and delete changes don't have a previous block.
|
|
33
|
+
*/
|
|
34
|
+
prevBlock: undefined;
|
|
35
|
+
} | {
|
|
36
|
+
type: "update";
|
|
37
|
+
/**
|
|
38
|
+
* The previous block.
|
|
39
|
+
*/
|
|
40
|
+
prevBlock: Block<BSchema, ISchema, SSchema>;
|
|
41
|
+
} | {
|
|
42
|
+
type: "move";
|
|
43
|
+
/**
|
|
44
|
+
* The affected block.
|
|
45
|
+
*/
|
|
46
|
+
block: Block<BSchema, ISchema, SSchema>;
|
|
47
|
+
/**
|
|
48
|
+
* The block before the move.
|
|
49
|
+
*/
|
|
50
|
+
prevBlock: Block<BSchema, ISchema, SSchema>;
|
|
51
|
+
/**
|
|
52
|
+
* The previous parent block (if it existed).
|
|
53
|
+
*/
|
|
54
|
+
prevParent?: Block<BSchema, ISchema, SSchema>;
|
|
55
|
+
/**
|
|
56
|
+
* The current parent block (if it exists).
|
|
57
|
+
*/
|
|
58
|
+
currentParent?: Block<BSchema, ISchema, SSchema>;
|
|
59
|
+
})>;
|
|
60
|
+
/**
|
|
61
|
+
* Get the blocks that were changed by a transaction.
|
|
62
|
+
*/
|
|
63
|
+
export declare function getBlocksChangedByTransaction<BSchema extends BlockSchema = DefaultBlockSchema, ISchema extends InlineContentSchema = DefaultInlineContentSchema, SSchema extends StyleSchema = DefaultStyleSchema>(transaction: Transaction, appendedTransactions?: Transaction[]): BlocksChanged<BSchema, ISchema, SSchema>;
|
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
import type { Node } from "prosemirror-model";
|
|
2
|
-
import type { Transaction } from "prosemirror-state";
|
|
3
|
-
import { Block, DefaultBlockSchema, DefaultInlineContentSchema, DefaultStyleSchema } from "../blocks/defaultBlocks.js";
|
|
4
|
-
import type { BlockSchema } from "../schema/index.js";
|
|
5
|
-
import type { InlineContentSchema } from "../schema/inlineContent/types.js";
|
|
6
|
-
import type { StyleSchema } from "../schema/styles/types.js";
|
|
7
2
|
/**
|
|
8
3
|
* Get a TipTap node by id
|
|
9
4
|
*/
|
|
@@ -12,61 +7,3 @@ export declare function getNodeById(id: string, doc: Node): {
|
|
|
12
7
|
posBeforeNode: number;
|
|
13
8
|
} | undefined;
|
|
14
9
|
export declare function isNodeBlock(node: Node): boolean;
|
|
15
|
-
/**
|
|
16
|
-
* This attributes the changes to a specific source.
|
|
17
|
-
*/
|
|
18
|
-
export type BlockChangeSource = {
|
|
19
|
-
type: "local";
|
|
20
|
-
} | {
|
|
21
|
-
type: "paste";
|
|
22
|
-
} | {
|
|
23
|
-
type: "drop";
|
|
24
|
-
} | {
|
|
25
|
-
type: "undo" | "redo" | "undo-redo";
|
|
26
|
-
} | {
|
|
27
|
-
type: "yjs-remote";
|
|
28
|
-
};
|
|
29
|
-
export type BlocksChanged<BSchema extends BlockSchema = DefaultBlockSchema, ISchema extends InlineContentSchema = DefaultInlineContentSchema, SSchema extends StyleSchema = DefaultStyleSchema> = Array<{
|
|
30
|
-
/**
|
|
31
|
-
* The affected block.
|
|
32
|
-
*/
|
|
33
|
-
block: Block<BSchema, ISchema, SSchema>;
|
|
34
|
-
/**
|
|
35
|
-
* The source of the change.
|
|
36
|
-
*/
|
|
37
|
-
source: BlockChangeSource;
|
|
38
|
-
} & ({
|
|
39
|
-
type: "insert" | "delete";
|
|
40
|
-
/**
|
|
41
|
-
* Insert and delete changes don't have a previous block.
|
|
42
|
-
*/
|
|
43
|
-
prevBlock: undefined;
|
|
44
|
-
} | {
|
|
45
|
-
type: "update";
|
|
46
|
-
/**
|
|
47
|
-
* The previous block.
|
|
48
|
-
*/
|
|
49
|
-
prevBlock: Block<BSchema, ISchema, SSchema>;
|
|
50
|
-
} | {
|
|
51
|
-
type: "move";
|
|
52
|
-
/**
|
|
53
|
-
* The affected block.
|
|
54
|
-
*/
|
|
55
|
-
block: Block<BSchema, ISchema, SSchema>;
|
|
56
|
-
/**
|
|
57
|
-
* The block before the move.
|
|
58
|
-
*/
|
|
59
|
-
prevBlock: Block<BSchema, ISchema, SSchema>;
|
|
60
|
-
/**
|
|
61
|
-
* The previous parent block (if it existed).
|
|
62
|
-
*/
|
|
63
|
-
prevParent?: Block<BSchema, ISchema, SSchema>;
|
|
64
|
-
/**
|
|
65
|
-
* The current parent block (if it exists).
|
|
66
|
-
*/
|
|
67
|
-
currentParent?: Block<BSchema, ISchema, SSchema>;
|
|
68
|
-
})>;
|
|
69
|
-
/**
|
|
70
|
-
* Get the blocks that were changed by a transaction.
|
|
71
|
-
*/
|
|
72
|
-
export declare function getBlocksChangedByTransaction<BSchema extends BlockSchema = DefaultBlockSchema, ISchema extends InlineContentSchema = DefaultInlineContentSchema, SSchema extends StyleSchema = DefaultStyleSchema>(transaction: Transaction, appendedTransactions?: Transaction[]): BlocksChanged<BSchema, ISchema, SSchema>;
|
|
@@ -18,7 +18,7 @@ import { BlockNoteTipTapEditor } from "./BlockNoteTipTapEditor.js";
|
|
|
18
18
|
import { Dictionary } from "../i18n/dictionary.js";
|
|
19
19
|
import { type Command, type Plugin, type Transaction } from "@tiptap/pm/state";
|
|
20
20
|
import { EditorView } from "prosemirror-view";
|
|
21
|
-
import { BlocksChanged } from "../api/
|
|
21
|
+
import { BlocksChanged } from "../api/getBlocksChangedByTransaction.js";
|
|
22
22
|
import { CodeBlockOptions } from "../blocks/CodeBlockContent/CodeBlockContent.js";
|
|
23
23
|
import type { ThreadStore, User } from "../comments/index.js";
|
|
24
24
|
import type { ForkYDocPlugin } from "../extensions/Collaboration/ForkYDocPlugin.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Transaction } from "prosemirror-state";
|
|
2
|
+
import { BlocksChanged } from "../../api/getBlocksChangedByTransaction.js";
|
|
2
3
|
import { BlockNoteExtension } from "../../editor/BlockNoteExtension.js";
|
|
3
|
-
import { BlocksChanged } from "../../index.js";
|
|
4
4
|
/**
|
|
5
5
|
* This plugin can filter transactions before they are applied to the editor, but with a higher-level API than `filterTransaction` from prosemirror.
|
|
6
6
|
*/
|
|
@@ -138,9 +138,9 @@ export declare class TableHandlesProsemirrorPlugin<I extends InlineContentSchema
|
|
|
138
138
|
*/
|
|
139
139
|
getMergeDirection: (block: BlockFromConfigNoChildren<DefaultBlockSchema["table"], any, any> | undefined) => "vertical" | "horizontal" | undefined;
|
|
140
140
|
cropEmptyRowsOrColumns: (block: BlockFromConfigNoChildren<DefaultBlockSchema["table"], any, any>, removeEmpty: "columns" | "rows") => {
|
|
141
|
-
cells: (import("../../index.js").
|
|
141
|
+
cells: (import("../../index.js").StyledText<any> | import("../../index.js").Link<any> | import("../../index.js").CustomInlineContentFromConfig<any, any>)[][] | import("../../index.js").TableCell<any, any>[];
|
|
142
142
|
}[];
|
|
143
143
|
addRowsOrColumns: (block: BlockFromConfigNoChildren<DefaultBlockSchema["table"], any, any>, addType: "columns" | "rows", numToAdd: number) => {
|
|
144
|
-
cells: (import("../../index.js").
|
|
144
|
+
cells: (import("../../index.js").StyledText<any> | import("../../index.js").Link<any> | import("../../index.js").CustomInlineContentFromConfig<any, any>)[][] | import("../../index.js").TableCell<any, any>[];
|
|
145
145
|
}[];
|
|
146
146
|
}
|
package/types/src/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * from "./api/blockManipulation/commands/updateBlock/updateBlock.js";
|
|
|
4
4
|
export * from "./api/exporters/html/externalHTMLExporter.js";
|
|
5
5
|
export * from "./api/exporters/html/internalHTMLSerializer.js";
|
|
6
6
|
export * from "./api/getBlockInfoFromPos.js";
|
|
7
|
+
export * from "./api/getBlocksChangedByTransaction.js";
|
|
7
8
|
export * from "./api/nodeUtil.js";
|
|
8
9
|
export * from "./api/pmUtil.js";
|
|
9
10
|
export * from "./blocks/AudioBlockContent/AudioBlockContent.js";
|