@blocknote/core 0.36.0 → 0.36.1

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.
Files changed (28) hide show
  1. package/dist/blocknote.cjs +7 -7
  2. package/dist/blocknote.cjs.map +1 -1
  3. package/dist/blocknote.js +1141 -1078
  4. package/dist/blocknote.js.map +1 -1
  5. package/dist/tsconfig.tsbuildinfo +1 -1
  6. package/dist/webpack-stats.json +1 -1
  7. package/package.json +2 -1
  8. package/src/api/__snapshots__/blocks-moved-down-twice-in-same-parent.json +44 -0
  9. package/src/api/__snapshots__/blocks-moved-insert-changes-sibling-order.json +26 -0
  10. package/src/api/__snapshots__/blocks-moved-nested-sibling-reorder.json +180 -0
  11. package/src/api/__snapshots__/blocks-moved-up-down-in-same-parent.json +44 -0
  12. package/src/api/__snapshots__/blocks-moved-up-down-in-same-transaction.json +44 -0
  13. package/src/api/{nodeUtil.test.ts → getBlocksChangedByTransaction.test.ts} +117 -1
  14. package/src/api/getBlocksChangedByTransaction.ts +422 -0
  15. package/src/api/nodeUtil.ts +0 -250
  16. package/src/blocks/TableBlockContent/TableBlockContent.ts +31 -4
  17. package/src/editor/BlockNoteEditor.ts +1 -1
  18. package/src/extensions/BlockChange/BlockChangePlugin.ts +4 -2
  19. package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +1 -5
  20. package/src/index.ts +1 -0
  21. package/types/src/api/getBlocksChangedByTransaction.d.ts +63 -0
  22. package/types/src/api/nodeUtil.d.ts +0 -63
  23. package/types/src/editor/BlockNoteEditor.d.ts +1 -1
  24. package/types/src/extensions/BlockChange/BlockChangePlugin.d.ts +1 -1
  25. package/types/src/extensions/TableHandles/TableHandlesPlugin.d.ts +2 -2
  26. package/types/src/index.d.ts +1 -0
  27. package/types/src/schema/inlineContent/internal.d.ts +1 -1
  28. /package/types/src/api/{nodeUtil.test.d.ts → getBlocksChangedByTransaction.test.d.ts} +0 -0
@@ -34,8 +34,8 @@ export const TableBlockContent = createStronglyTypedTiptapNode({
34
34
  ];
35
35
  },
36
36
 
37
- renderHTML({ HTMLAttributes }) {
38
- return createDefaultBlockDOMOutputSpec(
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
@@ -146,8 +170,11 @@ const TableParagraph = createStronglyTypedTiptapNode({
146
170
  ];
147
171
  },
148
172
 
149
- renderHTML({ HTMLAttributes }) {
150
- return ["p", HTMLAttributes, 0];
173
+ renderHTML({ node, HTMLAttributes }) {
174
+ // Insert a line break if there is no content, in order to preserve the
175
+ // correct cell height. Otherwise, the cell will have a height of zero +
176
+ // padding.
177
+ return ["p", HTMLAttributes, node.childCount ? 0 : ["br"]];
151
178
  },
152
179
  });
153
180
 
@@ -110,7 +110,7 @@ import { docToBlocks } from "../api/nodeConversions/nodeToBlock.js";
110
110
  import {
111
111
  BlocksChanged,
112
112
  getBlocksChangedByTransaction,
113
- } from "../api/nodeUtil.js";
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";
@@ -1,7 +1,9 @@
1
1
  import { Plugin, Transaction } from "prosemirror-state";
2
- import { getBlocksChangedByTransaction } from "../../api/nodeUtil.js";
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/nodeUtil.js";
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").CustomInlineContentFromConfig<any, any> | import("../../index.js").StyledText<any> | import("../../index.js").Link<any>)[][] | import("../../index.js").TableCell<any, any>[];
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").CustomInlineContentFromConfig<any, any> | import("../../index.js").StyledText<any> | import("../../index.js").Link<any>)[][] | import("../../index.js").TableCell<any, any>[];
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
  }
@@ -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";
@@ -19,7 +19,7 @@ export declare function createInlineContentSpecFromTipTapNode<T extends Node, P
19
19
  config: {
20
20
  type: T["name"];
21
21
  propSchema: P;
22
- content: "styled" | "none";
22
+ content: "none" | "styled";
23
23
  };
24
24
  implementation: {
25
25
  node: Node;