@blocknote/core 0.30.0 → 0.30.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 (148) hide show
  1. package/dist/blocknote.cjs +2 -2
  2. package/dist/blocknote.cjs.map +1 -1
  3. package/dist/blocknote.js +22 -20
  4. package/dist/blocknote.js.map +1 -1
  5. package/dist/comments.cjs.map +1 -1
  6. package/dist/comments.js.map +1 -1
  7. package/dist/style.css +1 -1
  8. package/dist/tsconfig.tsbuildinfo +1 -1
  9. package/dist/webpack-stats.json +1 -1
  10. package/package.json +5 -3
  11. package/src/api/README.md +1 -1
  12. package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.test.ts +19 -14
  13. package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts +5 -5
  14. package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.ts +3 -3
  15. package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.ts +12 -12
  16. package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.test.ts +14 -14
  17. package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.ts +16 -16
  18. package/src/api/blockManipulation/commands/nestBlock/nestBlock.ts +8 -8
  19. package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.test.ts +12 -12
  20. package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts +7 -7
  21. package/src/api/blockManipulation/commands/splitBlock/splitBlock.test.ts +10 -10
  22. package/src/api/blockManipulation/commands/splitBlock/splitBlock.ts +2 -2
  23. package/src/api/blockManipulation/commands/updateBlock/updateBlock.test.ts +42 -42
  24. package/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +18 -18
  25. package/src/api/blockManipulation/getBlock/getBlock.ts +9 -9
  26. package/src/api/blockManipulation/insertContentAt.ts +1 -1
  27. package/src/api/blockManipulation/selections/selection.ts +11 -11
  28. package/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.test.ts +7 -7
  29. package/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.ts +6 -6
  30. package/src/api/blockManipulation/tables/tables.test.ts +106 -106
  31. package/src/api/blockManipulation/tables/tables.ts +35 -35
  32. package/src/api/clipboard/fromClipboard/fileDropExtension.ts +2 -2
  33. package/src/api/clipboard/fromClipboard/handleFileInsertion.ts +9 -9
  34. package/src/api/clipboard/fromClipboard/handleVSCodePaste.ts +3 -3
  35. package/src/api/clipboard/fromClipboard/pasteExtension.ts +3 -3
  36. package/src/api/clipboard/toClipboard/copyExtension.ts +22 -22
  37. package/src/api/exporters/html/externalHTMLExporter.ts +6 -6
  38. package/src/api/exporters/html/internalHTMLSerializer.ts +3 -3
  39. package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +16 -16
  40. package/src/api/exporters/html/util/serializeBlocksInternalHTML.ts +14 -14
  41. package/src/api/exporters/markdown/markdownExporter.ts +3 -3
  42. package/src/api/exporters/markdown/util/addSpacesToCheckboxesRehypePlugin.ts +3 -3
  43. package/src/api/getBlockInfoFromPos.ts +6 -6
  44. package/src/api/nodeConversions/blockToNode.ts +26 -26
  45. package/src/api/nodeConversions/fragmentToBlocks.ts +1 -1
  46. package/src/api/nodeConversions/nodeToBlock.ts +37 -33
  47. package/src/api/nodeUtil.test.ts +16 -16
  48. package/src/api/nodeUtil.ts +10 -10
  49. package/src/api/parsers/html/parseHTML.ts +1 -1
  50. package/src/api/parsers/html/util/nestedLists.ts +2 -2
  51. package/src/api/parsers/markdown/parseMarkdown.ts +1 -1
  52. package/src/api/pmUtil.ts +4 -4
  53. package/src/api/positionMapping.test.ts +3 -3
  54. package/src/api/positionMapping.ts +5 -5
  55. package/src/blocks/AudioBlockContent/AudioBlockContent.ts +4 -4
  56. package/src/blocks/CodeBlockContent/CodeBlockContent.ts +12 -12
  57. package/src/blocks/FileBlockContent/FileBlockContent.ts +2 -2
  58. package/src/blocks/FileBlockContent/helpers/parse/parseFigureElement.ts +2 -2
  59. package/src/blocks/FileBlockContent/helpers/render/createAddFileButton.ts +5 -5
  60. package/src/blocks/FileBlockContent/helpers/render/createFileBlockWrapper.ts +2 -2
  61. package/src/blocks/FileBlockContent/helpers/render/createFileNameWithIcon.ts +1 -1
  62. package/src/blocks/FileBlockContent/helpers/render/createResizableFileBlockWrapper.ts +7 -7
  63. package/src/blocks/FileBlockContent/helpers/toExternalHTML/createFigureWithCaption.ts +1 -1
  64. package/src/blocks/FileBlockContent/helpers/toExternalHTML/createLinkWithCaption.ts +1 -1
  65. package/src/blocks/FileBlockContent/uploadToTmpFilesDotOrg_DEV_ONLY.ts +2 -2
  66. package/src/blocks/HeadingBlockContent/HeadingBlockContent.ts +6 -6
  67. package/src/blocks/ImageBlockContent/ImageBlockContent.ts +4 -4
  68. package/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts +4 -4
  69. package/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.ts +10 -10
  70. package/src/blocks/ListItemBlockContent/ListItemKeyboardShortcuts.ts +1 -1
  71. package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.ts +1 -1
  72. package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts +4 -4
  73. package/src/blocks/ListItemBlockContent/getListItemContent.ts +5 -5
  74. package/src/blocks/PageBreakBlockContent/PageBreakBlockContent.ts +1 -1
  75. package/src/blocks/PageBreakBlockContent/getPageBreakSlashMenuItems.ts +3 -3
  76. package/src/blocks/PageBreakBlockContent/schema.ts +2 -2
  77. package/src/blocks/ParagraphBlockContent/ParagraphBlockContent.ts +3 -3
  78. package/src/blocks/QuoteBlockContent/QuoteBlockContent.ts +4 -4
  79. package/src/blocks/README.md +1 -1
  80. package/src/blocks/TableBlockContent/TableBlockContent.ts +5 -5
  81. package/src/blocks/TableBlockContent/TableExtension.ts +3 -3
  82. package/src/blocks/VideoBlockContent/VideoBlockContent.ts +4 -4
  83. package/src/blocks/defaultBlockHelpers.ts +8 -8
  84. package/src/blocks/defaultBlockTypeGuards.ts +16 -16
  85. package/src/blocks/defaultBlocks.ts +3 -3
  86. package/src/comments/threadstore/DefaultThreadStoreAuth.ts +3 -3
  87. package/src/comments/threadstore/ThreadStore.ts +1 -1
  88. package/src/comments/threadstore/TipTapThreadStore.ts +10 -10
  89. package/src/comments/threadstore/yjs/RESTYjsThreadStore.ts +4 -4
  90. package/src/comments/threadstore/yjs/YjsThreadStore.test.ts +2 -2
  91. package/src/comments/threadstore/yjs/YjsThreadStore.ts +14 -14
  92. package/src/comments/threadstore/yjs/YjsThreadStoreBase.ts +1 -1
  93. package/src/comments/threadstore/yjs/yjsHelpers.ts +6 -6
  94. package/src/editor/Block.css +8 -0
  95. package/src/editor/BlockNoteEditor.test.ts +3 -3
  96. package/src/editor/BlockNoteEditor.ts +7 -1
  97. package/src/editor/BlockNoteExtensions.ts +10 -10
  98. package/src/editor/BlockNoteSchema.ts +4 -4
  99. package/src/editor/BlockNoteTipTapEditor.ts +10 -10
  100. package/src/editor/README.md +1 -1
  101. package/src/editor/cursorPositionTypes.ts +1 -1
  102. package/src/editor/editor.css +15 -3
  103. package/src/editor/selectionTypes.ts +1 -1
  104. package/src/editor/transformPasted.ts +2 -2
  105. package/src/exporter/Exporter.ts +5 -5
  106. package/src/exporter/mapping.ts +7 -7
  107. package/src/extensions/BackgroundColor/BackgroundColorMark.ts +1 -1
  108. package/src/extensions/Collaboration/CursorPlugin.ts +2 -2
  109. package/src/extensions/Comments/CommentsPlugin.ts +9 -9
  110. package/src/extensions/Comments/userstore/UserStore.ts +2 -2
  111. package/src/extensions/FilePanel/FilePanelPlugin.ts +7 -7
  112. package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +4 -4
  113. package/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +26 -26
  114. package/src/extensions/LinkToolbar/LinkToolbarPlugin.ts +11 -11
  115. package/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.ts +4 -4
  116. package/src/extensions/Placeholder/PlaceholderPlugin.ts +10 -10
  117. package/src/extensions/PreviousBlockType/PreviousBlockTypePlugin.ts +2 -2
  118. package/src/extensions/README.md +1 -1
  119. package/src/extensions/SideMenu/MultipleNodeSelection.ts +1 -1
  120. package/src/extensions/SideMenu/SideMenuPlugin.ts +31 -31
  121. package/src/extensions/SideMenu/dragging.ts +8 -8
  122. package/src/extensions/SuggestionMenu/SuggestionPlugin.ts +17 -17
  123. package/src/extensions/SuggestionMenu/getDefaultEmojiPickerItems.ts +2 -2
  124. package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +12 -12
  125. package/src/extensions/TableHandles/TableHandlesPlugin.ts +54 -53
  126. package/src/extensions/TrailingNode/TrailingNodeExtension.ts +1 -1
  127. package/src/extensions/UniqueID/UniqueID.ts +6 -6
  128. package/src/extensions/getDraggableBlockFromElement.ts +1 -1
  129. package/src/fonts/inter.css +18 -9
  130. package/src/locales.ts +1 -1
  131. package/src/pm-nodes/BlockGroup.ts +1 -1
  132. package/src/pm-nodes/Doc.ts +4 -4
  133. package/src/schema/README.md +1 -1
  134. package/src/schema/blocks/createSpec.ts +14 -14
  135. package/src/schema/blocks/internal.ts +17 -17
  136. package/src/schema/blocks/types.ts +25 -25
  137. package/src/schema/inlineContent/createSpec.ts +16 -20
  138. package/src/schema/inlineContent/internal.ts +9 -9
  139. package/src/schema/inlineContent/types.ts +26 -26
  140. package/src/schema/propTypes.ts +8 -8
  141. package/src/schema/styles/createSpec.ts +2 -2
  142. package/src/schema/styles/internal.ts +7 -7
  143. package/src/schema/styles/types.ts +2 -2
  144. package/src/util/EventEmitter.ts +4 -4
  145. package/src/util/README.md +1 -1
  146. package/src/util/combineByGroup.ts +1 -1
  147. package/src/util/table.ts +33 -30
  148. package/types/src/editor/BlockNoteEditor.d.ts +3 -1
@@ -25,7 +25,7 @@ export type CustomInlineContentImplementation<
25
25
  T extends CustomInlineContentConfig,
26
26
  // B extends BlockSchema,
27
27
  // I extends InlineContentSchema,
28
- S extends StyleSchema
28
+ S extends StyleSchema,
29
29
  > = {
30
30
  render: (
31
31
  /**
@@ -33,14 +33,14 @@ export type CustomInlineContentImplementation<
33
33
  */
34
34
  inlineContent: InlineContentFromConfig<T, S>,
35
35
  updateInlineContent: (
36
- update: PartialCustomInlineContentFromConfig<T, S>
36
+ update: PartialCustomInlineContentFromConfig<T, S>,
37
37
  ) => void,
38
38
  /**
39
39
  * The BlockNote editor instance
40
40
  * This is typed generically. If you want an editor with your custom schema, you need to
41
41
  * cast it manually, e.g.: `const e = editor as BlockNoteEditor<typeof mySchema>;`
42
42
  */
43
- editor: BlockNoteEditor<any, any, S>
43
+ editor: BlockNoteEditor<any, any, S>,
44
44
  // (note) if we want to fix the manual cast, we need to prevent circular references and separate block definition and render implementations
45
45
  // or allow manually passing <BSchema>, but that's not possible without passing the other generics because Typescript doesn't support partial inferred generics
46
46
  ) => {
@@ -51,7 +51,7 @@ export type CustomInlineContentImplementation<
51
51
  };
52
52
 
53
53
  export function getInlineContentParseRules(
54
- config: CustomInlineContentConfig
54
+ config: CustomInlineContentConfig,
55
55
  ): TagParseRule[] {
56
56
  return [
57
57
  {
@@ -71,10 +71,10 @@ export function getInlineContentParseRules(
71
71
 
72
72
  export function createInlineContentSpec<
73
73
  T extends CustomInlineContentConfig,
74
- S extends StyleSchema
74
+ S extends StyleSchema,
75
75
  >(
76
76
  inlineContentConfig: T,
77
- inlineContentImplementation: CustomInlineContentImplementation<T, S>
77
+ inlineContentImplementation: CustomInlineContentImplementation<T, S>,
78
78
  ): InlineContentSpec<T> {
79
79
  const node = Node.create({
80
80
  name: inlineContentConfig.type,
@@ -105,31 +105,31 @@ export function createInlineContentSpec<
105
105
  nodeToCustomInlineContent(
106
106
  node,
107
107
  editor.schema.inlineContentSchema,
108
- editor.schema.styleSchema
108
+ editor.schema.styleSchema,
109
109
  ) as any as InlineContentFromConfig<T, S>, // TODO: fix cast
110
110
  () => {
111
111
  // No-op
112
112
  },
113
- editor
113
+ editor,
114
114
  );
115
115
 
116
116
  return addInlineContentAttributes(
117
117
  output,
118
118
  inlineContentConfig.type,
119
119
  node.attrs as Props<T["propSchema"]>,
120
- inlineContentConfig.propSchema
120
+ inlineContentConfig.propSchema,
121
121
  );
122
122
  },
123
123
 
124
124
  addNodeView() {
125
125
  return ({ node, getPos }) => {
126
- const editor = this.options.editor;
126
+ const editor = this.options.editor as BlockNoteEditor<any, any, S>;
127
127
 
128
128
  const output = inlineContentImplementation.render(
129
129
  nodeToCustomInlineContent(
130
130
  node,
131
131
  editor.schema.inlineContentSchema,
132
- editor.schema.styleSchema
132
+ editor.schema.styleSchema,
133
133
  ) as any as InlineContentFromConfig<T, S>, // TODO: fix cast
134
134
  (update) => {
135
135
  if (typeof getPos === "boolean") {
@@ -138,22 +138,18 @@ export function createInlineContentSpec<
138
138
 
139
139
  const content = inlineContentToNodes([update], editor.pmSchema);
140
140
 
141
- editor.dispatch(
142
- editor.prosemirrorView.state.tr.replaceWith(
143
- getPos(),
144
- getPos() + node.nodeSize,
145
- content
146
- )
141
+ editor.transact((tr) =>
142
+ tr.replaceWith(getPos(), getPos() + node.nodeSize, content),
147
143
  );
148
144
  },
149
- editor
145
+ editor,
150
146
  );
151
147
 
152
148
  return addInlineContentAttributes(
153
149
  output,
154
150
  inlineContentConfig.type,
155
151
  node.attrs as Props<T["propSchema"]>,
156
- inlineContentConfig.propSchema
152
+ inlineContentConfig.propSchema,
157
153
  );
158
154
  };
159
155
  },
@@ -161,6 +157,6 @@ export function createInlineContentSpec<
161
157
 
162
158
  return createInlineContentSpecFromTipTapNode(
163
159
  node,
164
- inlineContentConfig.propSchema
160
+ inlineContentConfig.propSchema,
165
161
  ) as InlineContentSpec<T>; // TODO: fix cast
166
162
  }
@@ -16,7 +16,7 @@ import {
16
16
  // is lost on internal copy & paste.
17
17
  export function addInlineContentAttributes<
18
18
  IType extends string,
19
- PSchema extends PropSchema
19
+ PSchema extends PropSchema,
20
20
  >(
21
21
  element: {
22
22
  dom: HTMLElement;
@@ -24,7 +24,7 @@ export function addInlineContentAttributes<
24
24
  },
25
25
  inlineContentType: IType,
26
26
  inlineContentProps: Props<PSchema>,
27
- propSchema: PSchema
27
+ propSchema: PSchema,
28
28
  ): {
29
29
  dom: HTMLElement;
30
30
  contentDOM?: HTMLElement;
@@ -52,9 +52,9 @@ export function addInlineContentAttributes<
52
52
 
53
53
  // see https://github.com/TypeCellOS/BlockNote/pull/435
54
54
  export function addInlineContentKeyboardShortcuts<
55
- T extends CustomInlineContentConfig
55
+ T extends CustomInlineContentConfig,
56
56
  >(
57
- config: T
57
+ config: T,
58
58
  ): {
59
59
  [p: string]: KeyboardShortcutCommand;
60
60
  } {
@@ -75,7 +75,7 @@ export function addInlineContentKeyboardShortcuts<
75
75
  // config and implementation that conform to the type of Config
76
76
  export function createInternalInlineContentSpec<T extends InlineContentConfig>(
77
77
  config: T,
78
- implementation: InlineContentImplementation<T>
78
+ implementation: InlineContentImplementation<T>,
79
79
  ) {
80
80
  return {
81
81
  config,
@@ -85,7 +85,7 @@ export function createInternalInlineContentSpec<T extends InlineContentConfig>(
85
85
 
86
86
  export function createInlineContentSpecFromTipTapNode<
87
87
  T extends Node,
88
- P extends PropSchema
88
+ P extends PropSchema,
89
89
  >(node: T, propSchema: P) {
90
90
  return createInternalInlineContentSpec(
91
91
  {
@@ -95,14 +95,14 @@ export function createInlineContentSpecFromTipTapNode<
95
95
  },
96
96
  {
97
97
  node,
98
- }
98
+ },
99
99
  );
100
100
  }
101
101
 
102
102
  export function getInlineContentSchemaFromSpecs<T extends InlineContentSpecs>(
103
- specs: T
103
+ specs: T,
104
104
  ) {
105
105
  return Object.fromEntries(
106
- Object.entries(specs).map(([key, value]) => [key, value.config])
106
+ Object.entries(specs).map(([key, value]) => [key, value.config]),
107
107
  ) as InlineContentSchemaFromSpecs<T>;
108
108
  }
@@ -44,55 +44,55 @@ export type InlineContentSchemaFromSpecs<T extends InlineContentSpecs> = {
44
44
 
45
45
  export type CustomInlineContentFromConfig<
46
46
  I extends CustomInlineContentConfig,
47
- S extends StyleSchema
47
+ S extends StyleSchema,
48
48
  > = {
49
49
  type: I["type"];
50
50
  props: Props<I["propSchema"]>;
51
51
  content: I["content"] extends "styled"
52
52
  ? StyledText<S>[]
53
53
  : I["content"] extends "plain"
54
- ? string
55
- : I["content"] extends "none"
56
- ? undefined
57
- : never;
54
+ ? string
55
+ : I["content"] extends "none"
56
+ ? undefined
57
+ : never;
58
58
  };
59
59
 
60
60
  export type InlineContentFromConfig<
61
61
  I extends InlineContentConfig,
62
- S extends StyleSchema
62
+ S extends StyleSchema,
63
63
  > = I extends "text"
64
64
  ? StyledText<S>
65
65
  : I extends "link"
66
- ? Link<S>
67
- : I extends CustomInlineContentConfig
68
- ? CustomInlineContentFromConfig<I, S>
69
- : never;
66
+ ? Link<S>
67
+ : I extends CustomInlineContentConfig
68
+ ? CustomInlineContentFromConfig<I, S>
69
+ : never;
70
70
 
71
71
  export type PartialCustomInlineContentFromConfig<
72
72
  I extends CustomInlineContentConfig,
73
- S extends StyleSchema
73
+ S extends StyleSchema,
74
74
  > = {
75
75
  type: I["type"];
76
76
  props?: Props<I["propSchema"]>;
77
77
  content?: I["content"] extends "styled"
78
78
  ? StyledText<S>[] | string
79
79
  : I["content"] extends "plain"
80
- ? string
81
- : I["content"] extends "none"
82
- ? undefined
83
- : never;
80
+ ? string
81
+ : I["content"] extends "none"
82
+ ? undefined
83
+ : never;
84
84
  };
85
85
 
86
86
  export type PartialInlineContentFromConfig<
87
87
  I extends InlineContentConfig,
88
- S extends StyleSchema
88
+ S extends StyleSchema,
89
89
  > = I extends "text"
90
90
  ? string | StyledText<S>
91
91
  : I extends "link"
92
- ? PartialLink<S>
93
- : I extends CustomInlineContentConfig
94
- ? PartialCustomInlineContentFromConfig<I, S>
95
- : never;
92
+ ? PartialLink<S>
93
+ : I extends CustomInlineContentConfig
94
+ ? PartialCustomInlineContentFromConfig<I, S>
95
+ : never;
96
96
 
97
97
  export type StyledText<T extends StyleSchema> = {
98
98
  type: "text";
@@ -112,33 +112,33 @@ export type PartialLink<T extends StyleSchema> = Omit<Link<T>, "content"> & {
112
112
 
113
113
  export type InlineContent<
114
114
  I extends InlineContentSchema,
115
- T extends StyleSchema
115
+ T extends StyleSchema,
116
116
  > = InlineContentFromConfig<I[keyof I], T>;
117
117
 
118
118
  type PartialInlineContentElement<
119
119
  I extends InlineContentSchema,
120
- T extends StyleSchema
120
+ T extends StyleSchema,
121
121
  > = PartialInlineContentFromConfig<I[keyof I], T>;
122
122
 
123
123
  export type PartialInlineContent<
124
124
  I extends InlineContentSchema,
125
- T extends StyleSchema
125
+ T extends StyleSchema,
126
126
  > = PartialInlineContentElement<I, T>[] | string;
127
127
 
128
128
  export function isLinkInlineContent<T extends StyleSchema>(
129
- content: InlineContent<any, T>
129
+ content: InlineContent<any, T>,
130
130
  ): content is Link<T> {
131
131
  return content.type === "link";
132
132
  }
133
133
 
134
134
  export function isPartialLinkInlineContent<T extends StyleSchema>(
135
- content: PartialInlineContentElement<any, T>
135
+ content: PartialInlineContentElement<any, T>,
136
136
  ): content is PartialLink<T> {
137
137
  return typeof content !== "string" && content.type === "link";
138
138
  }
139
139
 
140
140
  export function isStyledTextInlineContent<T extends StyleSchema>(
141
- content: PartialInlineContentElement<any, T>
141
+ content: PartialInlineContentElement<any, T>,
142
142
  ): content is StyledText<T> {
143
143
  return typeof content !== "string" && content.type === "text";
144
144
  }
@@ -39,14 +39,14 @@ export type Props<PSchema extends PropSchema> = {
39
39
  ? PSchema[PName]["values"][number]
40
40
  : boolean
41
41
  : PSchema[PName] extends { default: number } | { type: "number" }
42
- ? PSchema[PName]["values"] extends readonly number[]
43
- ? PSchema[PName]["values"][number]
44
- : number
45
- : PSchema[PName] extends { default: string } | { type: "string" }
46
- ? PSchema[PName]["values"] extends readonly string[]
47
- ? PSchema[PName]["values"][number]
48
- : string
49
- : never
42
+ ? PSchema[PName]["values"] extends readonly number[]
43
+ ? PSchema[PName]["values"][number]
44
+ : number
45
+ : PSchema[PName] extends { default: string } | { type: "string" }
46
+ ? PSchema[PName]["values"] extends readonly string[]
47
+ ? PSchema[PName]["values"][number]
48
+ : string
49
+ : never
50
50
  ) extends infer T
51
51
  ? PSchema[PName] extends { optional: true }
52
52
  ? T | undefined
@@ -42,7 +42,7 @@ export function getStyleParseRules(config: StyleConfig): ParseRule[] {
42
42
 
43
43
  export function createStyleSpec<T extends StyleConfig>(
44
44
  styleConfig: T,
45
- styleImplementation: CustomStyleImplementation<T>
45
+ styleImplementation: CustomStyleImplementation<T>,
46
46
  ): StyleSpec<T> {
47
47
  const mark = Mark.create({
48
48
  name: styleConfig.type,
@@ -75,7 +75,7 @@ export function createStyleSpec<T extends StyleConfig>(
75
75
  renderResult,
76
76
  styleConfig.type,
77
77
  mark.attrs.stringValue,
78
- styleConfig.propSchema
78
+ styleConfig.propSchema,
79
79
  );
80
80
  },
81
81
  });
@@ -9,7 +9,7 @@ import {
9
9
  } from "./types.js";
10
10
 
11
11
  export function stylePropsToAttributes(
12
- propSchema: StylePropSchema
12
+ propSchema: StylePropSchema,
13
13
  ): Attributes {
14
14
  if (propSchema === "boolean") {
15
15
  return {};
@@ -34,7 +34,7 @@ export function stylePropsToAttributes(
34
34
  // on internal copy & paste.
35
35
  export function addStyleAttributes<
36
36
  SType extends string,
37
- PSchema extends StylePropSchema
37
+ PSchema extends StylePropSchema,
38
38
  >(
39
39
  element: {
40
40
  dom: HTMLElement;
@@ -42,7 +42,7 @@ export function addStyleAttributes<
42
42
  },
43
43
  styleType: SType,
44
44
  styleValue: PSchema extends "boolean" ? undefined : string,
45
- propSchema: PSchema
45
+ propSchema: PSchema,
46
46
  ): {
47
47
  dom: HTMLElement;
48
48
  contentDOM?: HTMLElement;
@@ -66,7 +66,7 @@ export function addStyleAttributes<
66
66
  // config and implementation that conform to the type of Config
67
67
  export function createInternalStyleSpec<T extends StyleConfig>(
68
68
  config: T,
69
- implementation: StyleImplementation
69
+ implementation: StyleImplementation,
70
70
  ) {
71
71
  return {
72
72
  config,
@@ -76,7 +76,7 @@ export function createInternalStyleSpec<T extends StyleConfig>(
76
76
 
77
77
  export function createStyleSpecFromTipTapMark<
78
78
  T extends Mark,
79
- P extends StylePropSchema
79
+ P extends StylePropSchema,
80
80
  >(mark: T, propSchema: P) {
81
81
  return createInternalStyleSpec(
82
82
  {
@@ -85,12 +85,12 @@ export function createStyleSpecFromTipTapMark<
85
85
  },
86
86
  {
87
87
  mark,
88
- }
88
+ },
89
89
  );
90
90
  }
91
91
 
92
92
  export function getStyleSchemaFromSpecs<T extends StyleSpecs>(specs: T) {
93
93
  return Object.fromEntries(
94
- Object.entries(specs).map(([key, value]) => [key, value.config])
94
+ Object.entries(specs).map(([key, value]) => [key, value.config]),
95
95
  ) as StyleSchemaFromSpecs<T>;
96
96
  }
@@ -37,6 +37,6 @@ export type Styles<T extends StyleSchema> = {
37
37
  [K in keyof T]?: T[K]["propSchema"] extends "boolean"
38
38
  ? boolean
39
39
  : T[K]["propSchema"] extends "string"
40
- ? string
41
- : never;
40
+ ? string
41
+ : never;
42
42
  };
@@ -3,11 +3,11 @@
3
3
  type StringKeyOf<T> = Extract<keyof T, string>;
4
4
  type CallbackType<
5
5
  T extends Record<string, any>,
6
- EventName extends StringKeyOf<T>
6
+ EventName extends StringKeyOf<T>,
7
7
  > = T[EventName] extends any[] ? T[EventName] : [T[EventName]];
8
8
  type CallbackFunction<
9
9
  T extends Record<string, any>,
10
- EventName extends StringKeyOf<T>
10
+ EventName extends StringKeyOf<T>,
11
11
  > = (...props: CallbackType<T, EventName>) => any;
12
12
 
13
13
  export class EventEmitter<T extends Record<string, any>> {
@@ -16,7 +16,7 @@ export class EventEmitter<T extends Record<string, any>> {
16
16
 
17
17
  public on<EventName extends StringKeyOf<T>>(
18
18
  event: EventName,
19
- fn: CallbackFunction<T, EventName>
19
+ fn: CallbackFunction<T, EventName>,
20
20
  ) {
21
21
  if (!this.callbacks[event]) {
22
22
  this.callbacks[event] = [];
@@ -40,7 +40,7 @@ export class EventEmitter<T extends Record<string, any>> {
40
40
 
41
41
  public off<EventName extends StringKeyOf<T>>(
42
42
  event: EventName,
43
- fn?: CallbackFunction<T, EventName>
43
+ fn?: CallbackFunction<T, EventName>,
44
44
  ) {
45
45
  const callbacks = this.callbacks[event];
46
46
 
@@ -1,3 +1,3 @@
1
1
  ### @blocknote/core/src/@util
2
2
 
3
- Contains generic utility files with helper functions / classes.
3
+ Contains generic utility files with helper functions / classes.
@@ -12,7 +12,7 @@ export function combineByGroup<T extends { group?: string }>(
12
12
  for (const additionalItems of additionalItemsArray) {
13
13
  for (const additionalItem of additionalItems) {
14
14
  const lastItemWithSameGroup = combinedItems.findLastIndex(
15
- (item) => item.group === additionalItem.group
15
+ (item) => item.group === additionalItem.group,
16
16
  );
17
17
  if (lastItemWithSameGroup === -1) {
18
18
  combinedItems.push(additionalItem as T);
package/src/util/table.ts CHANGED
@@ -13,47 +13,50 @@ import { PartialTableCell, TableCell } from "../schema/blocks/types.js";
13
13
  */
14
14
  export function mapTableCell<
15
15
  T extends InlineContentSchema,
16
- S extends StyleSchema
16
+ S extends StyleSchema,
17
17
  >(
18
- content: PartialInlineContent<T, S> | PartialTableCell<T, S> | TableCell<T, S>
18
+ content:
19
+ | PartialInlineContent<T, S>
20
+ | PartialTableCell<T, S>
21
+ | TableCell<T, S>,
19
22
  ): TableCell<T, S> {
20
23
  return isTableCell(content)
21
24
  ? { ...content }
22
25
  : isPartialTableCell(content)
23
- ? {
24
- type: "tableCell",
25
- content: ([] as InlineContent<T, S>[]).concat(content.content as any),
26
- props: {
27
- backgroundColor: content.props?.backgroundColor ?? "default",
28
- textColor: content.props?.textColor ?? "default",
29
- textAlignment: content.props?.textAlignment ?? "left",
30
- colspan: content.props?.colspan ?? 1,
31
- rowspan: content.props?.rowspan ?? 1,
32
- },
33
- }
34
- : {
35
- type: "tableCell",
36
- content: ([] as InlineContent<T, S>[]).concat(content as any),
37
- props: {
38
- backgroundColor: "default",
39
- textColor: "default",
40
- textAlignment: "left",
41
- colspan: 1,
42
- rowspan: 1,
43
- },
44
- };
26
+ ? {
27
+ type: "tableCell",
28
+ content: ([] as InlineContent<T, S>[]).concat(content.content as any),
29
+ props: {
30
+ backgroundColor: content.props?.backgroundColor ?? "default",
31
+ textColor: content.props?.textColor ?? "default",
32
+ textAlignment: content.props?.textAlignment ?? "left",
33
+ colspan: content.props?.colspan ?? 1,
34
+ rowspan: content.props?.rowspan ?? 1,
35
+ },
36
+ }
37
+ : {
38
+ type: "tableCell",
39
+ content: ([] as InlineContent<T, S>[]).concat(content as any),
40
+ props: {
41
+ backgroundColor: "default",
42
+ textColor: "default",
43
+ textAlignment: "left",
44
+ colspan: 1,
45
+ rowspan: 1,
46
+ },
47
+ };
45
48
  }
46
49
 
47
50
  export function isPartialTableCell<
48
51
  T extends InlineContentSchema,
49
- S extends StyleSchema
52
+ S extends StyleSchema,
50
53
  >(
51
54
  content:
52
55
  | TableCell<T, S>
53
56
  | PartialInlineContent<T, S>
54
57
  | PartialTableCell<T, S>
55
58
  | undefined
56
- | null
59
+ | null,
57
60
  ): content is PartialTableCell<T, S> {
58
61
  return (
59
62
  content !== undefined &&
@@ -66,14 +69,14 @@ export function isPartialTableCell<
66
69
 
67
70
  export function isTableCell<
68
71
  T extends InlineContentSchema,
69
- S extends StyleSchema
72
+ S extends StyleSchema,
70
73
  >(
71
74
  content:
72
75
  | TableCell<T, S>
73
76
  | PartialInlineContent<T, S>
74
77
  | PartialTableCell<T, S>
75
78
  | undefined
76
- | null
79
+ | null,
77
80
  ): content is TableCell<T, S> {
78
81
  return (
79
82
  isPartialTableCell(content) &&
@@ -86,7 +89,7 @@ export function getColspan(
86
89
  cell:
87
90
  | TableCell<any, any>
88
91
  | PartialTableCell<any, any>
89
- | PartialInlineContent<any, any>
92
+ | PartialInlineContent<any, any>,
90
93
  ): number {
91
94
  if (isTableCell(cell)) {
92
95
  return cell.props.colspan ?? 1;
@@ -98,7 +101,7 @@ export function getRowspan(
98
101
  cell:
99
102
  | TableCell<any, any>
100
103
  | PartialTableCell<any, any>
101
- | PartialInlineContent<any, any>
104
+ | PartialInlineContent<any, any>,
102
105
  ): number {
103
106
  if (isTableCell(cell)) {
104
107
  return cell.props.rowspan ?? 1;
@@ -538,7 +538,9 @@ export declare class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockS
538
538
  *
539
539
  * @param content can be a string, or array of partial inline content elements
540
540
  */
541
- insertInlineContent(content: PartialInlineContent<ISchema, SSchema>): void;
541
+ insertInlineContent(content: PartialInlineContent<ISchema, SSchema>, { updateSelection }?: {
542
+ updateSelection?: boolean;
543
+ }): void;
542
544
  /**
543
545
  * Gets the active text styles at the text cursor position or at the end of the current selection if it's active.
544
546
  */