@blocknote/core 0.8.3 → 0.8.4

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/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "homepage": "https://github.com/TypeCellOS/BlockNote",
4
4
  "private": false,
5
5
  "license": "MPL-2.0",
6
- "version": "0.8.3",
6
+ "version": "0.8.4",
7
7
  "files": [
8
8
  "dist",
9
9
  "types",
@@ -71,6 +71,10 @@
71
71
  "@tiptap/pm": "^2.0.3",
72
72
  "hast-util-from-dom": "^4.2.0",
73
73
  "lodash": "^4.17.21",
74
+ "prosemirror-model": "^1.18.3",
75
+ "prosemirror-state": "^1.4.3",
76
+ "prosemirror-transform": "^1.7.2",
77
+ "prosemirror-view": "^1.31.4",
74
78
  "rehype-parse": "^8.0.4",
75
79
  "rehype-remark": "^9.1.2",
76
80
  "rehype-stringify": "^9.0.3",
@@ -89,26 +93,21 @@
89
93
  "@types/lodash": "^4.14.179",
90
94
  "@types/uuid": "^8.3.4",
91
95
  "eslint": "^8.10.0",
92
- "eslint-config-react-app": "^7.0.0",
93
96
  "jsdom": "^21.1.0",
94
97
  "prettier": "^2.7.1",
95
98
  "typescript": "^5.0.4",
96
- "vite": "^4.1.2",
99
+ "vite": "^4.4.8",
97
100
  "vite-plugin-eslint": "^1.8.1",
98
- "vitest": "^0.28.5"
101
+ "vitest": "^0.34.1"
99
102
  },
100
103
  "eslintConfig": {
101
104
  "extends": [
102
- "react-app",
103
- "react-app/jest"
104
- ],
105
- "rules": {
106
- "curly": 1
107
- }
105
+ "../../.eslintrc.js"
106
+ ]
108
107
  },
109
108
  "publishConfig": {
110
109
  "access": "public",
111
110
  "registry": "https://registry.npmjs.org/"
112
111
  },
113
- "gitHead": "4b0778beb0b0857491273b37eb2cd9405b4d12fd"
112
+ "gitHead": "cac9d29dcf826e84af07199f839901d90928c490"
114
113
  }
@@ -205,12 +205,15 @@ export class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockSchema> {
205
205
 
206
206
  this.schema = newOptions.blockSchema;
207
207
 
208
- const initialContent = newOptions.initialContent || [
209
- {
210
- type: "paragraph",
211
- id: UniqueID.options.generateID(),
212
- },
213
- ];
208
+ const initialContent =
209
+ newOptions.initialContent || options.collaboration
210
+ ? undefined
211
+ : [
212
+ {
213
+ type: "paragraph",
214
+ id: UniqueID.options.generateID(),
215
+ },
216
+ ];
214
217
 
215
218
  const tiptapOptions: EditorOptions = {
216
219
  ...blockNoteTipTapOptions,
@@ -220,6 +223,10 @@ export class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockSchema> {
220
223
  this.ready = true;
221
224
  },
222
225
  onBeforeCreate(editor) {
226
+ if (!initialContent) {
227
+ // when using collaboration
228
+ return;
229
+ }
223
230
  // we have to set the initial content here, because now we can use the editor schema
224
231
  // which has been created at this point
225
232
  const schema = editor.editor.schema;
@@ -12,27 +12,45 @@ export type BlockInfo = {
12
12
  };
13
13
 
14
14
  /**
15
- * Retrieves information regarding the most nested block node in a ProseMirror doc, that a given position lies in.
15
+ * Retrieves information regarding the nearest blockContainer node in a
16
+ * ProseMirror doc, relative to a position.
16
17
  * @param doc The ProseMirror doc.
17
- * @param posInBlock A position somewhere within a block node.
18
- * @returns A BlockInfo object for the block the given position is in, or undefined if the position is not in a block
19
- * for the given doc.
18
+ * @param pos An integer position.
19
+ * @returns A BlockInfo object for the nearest blockContainer node.
20
20
  */
21
- export function getBlockInfoFromPos(
22
- doc: Node,
23
- posInBlock: number
24
- ): BlockInfo | undefined {
25
- if (posInBlock < 0 || posInBlock > doc.nodeSize) {
26
- return undefined;
21
+ export function getBlockInfoFromPos(doc: Node, pos: number): BlockInfo {
22
+ // If the position is outside the outer block group, we need to move it to the
23
+ // nearest block. This happens when the collaboration plugin is active, where
24
+ // the selection is placed at the very end of the doc.
25
+ const outerBlockGroupStartPos = 1;
26
+ const outerBlockGroupEndPos = doc.nodeSize - 2;
27
+ if (pos <= outerBlockGroupStartPos) {
28
+ pos = outerBlockGroupStartPos + 1;
29
+
30
+ while (
31
+ doc.resolve(pos).parent.type.name !== "blockContainer" &&
32
+ pos < outerBlockGroupEndPos
33
+ ) {
34
+ pos++;
35
+ }
36
+ } else if (pos >= outerBlockGroupEndPos) {
37
+ pos = outerBlockGroupEndPos - 1;
38
+
39
+ while (
40
+ doc.resolve(pos).parent.type.name !== "blockContainer" &&
41
+ pos > outerBlockGroupStartPos
42
+ ) {
43
+ pos--;
44
+ }
27
45
  }
28
46
 
29
47
  // This gets triggered when a node selection on a block is active, i.e. when
30
48
  // you drag and drop a block.
31
- if (doc.resolve(posInBlock).parent.type.name === "blockGroup") {
32
- posInBlock++;
49
+ if (doc.resolve(pos).parent.type.name === "blockGroup") {
50
+ pos++;
33
51
  }
34
52
 
35
- const $pos = doc.resolve(posInBlock);
53
+ const $pos = doc.resolve(pos);
36
54
 
37
55
  const maxDepth = $pos.depth;
38
56
  let node = $pos.node(maxDepth);
@@ -40,7 +58,9 @@ export function getBlockInfoFromPos(
40
58
 
41
59
  while (true) {
42
60
  if (depth < 0) {
43
- return undefined;
61
+ throw new Error(
62
+ "Could not find blockContainer node. This can only happen if the underlying BlockNote schema has been edited."
63
+ );
44
64
  }
45
65
 
46
66
  if (node.type.name === "blockContainer") {
@@ -10,10 +10,10 @@ export type BlockInfo = {
10
10
  depth: number;
11
11
  };
12
12
  /**
13
- * Retrieves information regarding the most nested block node in a ProseMirror doc, that a given position lies in.
13
+ * Retrieves information regarding the nearest blockContainer node in a
14
+ * ProseMirror doc, relative to a position.
14
15
  * @param doc The ProseMirror doc.
15
- * @param posInBlock A position somewhere within a block node.
16
- * @returns A BlockInfo object for the block the given position is in, or undefined if the position is not in a block
17
- * for the given doc.
16
+ * @param pos An integer position.
17
+ * @returns A BlockInfo object for the nearest blockContainer node.
18
18
  */
19
- export declare function getBlockInfoFromPos(doc: Node, posInBlock: number): BlockInfo | undefined;
19
+ export declare function getBlockInfoFromPos(doc: Node, pos: number): BlockInfo;