@blocknote/core 0.9.2 → 0.9.3

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.9.2",
6
+ "version": "0.9.3",
7
7
  "files": [
8
8
  "dist",
9
9
  "types",
@@ -109,5 +109,5 @@
109
109
  "access": "public",
110
110
  "registry": "https://registry.npmjs.org/"
111
111
  },
112
- "gitHead": "4d18bc8a01e841954672b9e522f20ce12f4ada10"
112
+ "gitHead": "3a3ca4dfc448556f9796ce884b6ba61f036dfe1a"
113
113
  }
@@ -192,18 +192,42 @@ export const BlockContainer = Node.create<{
192
192
  );
193
193
  }
194
194
 
195
- // Changes the blockContent node type and adds the provided props as attributes. Also preserves all existing
196
- // attributes that are compatible with the new type.
197
- state.tr.setNodeMarkup(
198
- startPos,
199
- block.type === undefined
200
- ? undefined
201
- : state.schema.nodes[block.type],
202
- {
203
- ...contentNode.attrs,
204
- ...block.props,
205
- }
206
- );
195
+ // Since some block types contain inline content and others don't,
196
+ // we either need to call setNodeMarkup to just update type &
197
+ // attributes, or replaceWith to replace the whole blockContent.
198
+ const oldType = contentNode.type.name;
199
+ const newType = block.type || oldType;
200
+
201
+ const oldContentType = state.schema.nodes[oldType].spec.content;
202
+ const newContentType = state.schema.nodes[newType].spec.content;
203
+
204
+ if (oldContentType === "inline*" && newContentType === "") {
205
+ // Replaces the blockContent node with one of the new type and
206
+ // adds the provided props as attributes. Also preserves all
207
+ // existing attributes that are compatible with the new type.
208
+ state.tr.replaceWith(
209
+ startPos,
210
+ endPos,
211
+ state.schema.nodes[newType].create({
212
+ ...contentNode.attrs,
213
+ ...block.props,
214
+ })
215
+ );
216
+ } else {
217
+ // Changes the blockContent node type and adds the provided props
218
+ // as attributes. Also preserves all existing attributes that are
219
+ // compatible with the new type.
220
+ state.tr.setNodeMarkup(
221
+ startPos,
222
+ block.type === undefined
223
+ ? undefined
224
+ : state.schema.nodes[block.type],
225
+ {
226
+ ...contentNode.attrs,
227
+ ...block.props,
228
+ }
229
+ );
230
+ }
207
231
 
208
232
  // Adds all provided props as attributes to the parent blockContainer node too, and also preserves existing
209
233
  // attributes.
@@ -73,6 +73,7 @@ export const HeadingBlockContent = createTipTapBlock<"heading">({
73
73
  return [
74
74
  "div",
75
75
  mergeAttributes(HTMLAttributes, {
76
+ ...blockContentDOMAttributes,
76
77
  class: mergeCSSClasses(
77
78
  styles.blockContent,
78
79
  blockContentDOMAttributes.class
@@ -82,6 +83,7 @@ export const HeadingBlockContent = createTipTapBlock<"heading">({
82
83
  [
83
84
  "h" + node.attrs.level,
84
85
  {
86
+ ...inlineContentDOMAttributes,
85
87
  class: mergeCSSClasses(
86
88
  styles.inlineContent,
87
89
  inlineContentDOMAttributes.class
@@ -91,6 +91,7 @@ export const BulletListItemBlockContent = createTipTapBlock<"bulletListItem">({
91
91
  return [
92
92
  "div",
93
93
  mergeAttributes(HTMLAttributes, {
94
+ ...blockContentDOMAttributes,
94
95
  class: mergeCSSClasses(
95
96
  styles.blockContent,
96
97
  blockContentDOMAttributes.class
@@ -100,6 +101,7 @@ export const BulletListItemBlockContent = createTipTapBlock<"bulletListItem">({
100
101
  [
101
102
  "p",
102
103
  {
104
+ ...inlineContentDOMAttributes,
103
105
  class: mergeCSSClasses(
104
106
  styles.inlineContent,
105
107
  inlineContentDOMAttributes.class
@@ -115,6 +115,7 @@ export const NumberedListItemBlockContent =
115
115
  return [
116
116
  "div",
117
117
  mergeAttributes(HTMLAttributes, {
118
+ ...blockContentDOMAttributes,
118
119
  class: mergeCSSClasses(
119
120
  styles.blockContent,
120
121
  blockContentDOMAttributes.class
@@ -126,6 +127,7 @@ export const NumberedListItemBlockContent =
126
127
  [
127
128
  "p",
128
129
  {
130
+ ...inlineContentDOMAttributes,
129
131
  class: mergeCSSClasses(
130
132
  styles.inlineContent,
131
133
  inlineContentDOMAttributes.class
@@ -64,7 +64,19 @@ export const TrailingNode = Extension.create<TrailingNodeOptions>({
64
64
  if (!lastNode || lastNode.type.name !== "blockContainer") {
65
65
  throw new Error("Expected blockContainer");
66
66
  }
67
- return lastNode.nodeSize > 4; // empty <block><content/></block> is length 4
67
+
68
+ const lastContentNode = lastNode.firstChild;
69
+
70
+ if (!lastContentNode) {
71
+ throw new Error("Expected blockContent");
72
+ }
73
+
74
+ // If last node is not empty (size > 4) or it doesn't contain
75
+ // inline content, we need to add a trailing node.
76
+ return (
77
+ lastNode.nodeSize > 4 ||
78
+ lastContentNode.type.spec.content !== "inline*"
79
+ );
68
80
  },
69
81
  },
70
82
  }),
@@ -0,0 +1,2 @@
1
+ import { Plugin } from "prosemirror-state";
2
+ export declare const NonEditableBlockPlugin: () => Plugin<any>;
@@ -0,0 +1,14 @@
1
+ import { Props } from "./blockTypes";
2
+ export declare const defaultProps: {
3
+ backgroundColor: {
4
+ default: "transparent";
5
+ };
6
+ textColor: {
7
+ default: "black";
8
+ };
9
+ textAlignment: {
10
+ default: "left";
11
+ values: readonly ["left", "center", "right", "justify"];
12
+ };
13
+ };
14
+ export type DefaultProps = Props<typeof defaultProps>;
@@ -0,0 +1,6 @@
1
+ import "@uppy/core/dist/style.css";
2
+ import "@uppy/dashboard/dist/style.css";
3
+ import "@uppy/drag-drop/dist/style.css";
4
+ import "@uppy/file-input/dist/style.css";
5
+ import "@uppy/progress-bar/dist/style.css";
6
+ export declare const Image: BlockSpec<BType, PSchema, ContainsInlineContent>;
@@ -0,0 +1,37 @@
1
+ import { BlockSpec } from "../../../api/blockTypes";
2
+ export declare const imagePropSchema: {
3
+ textAlignment: {
4
+ default: "left";
5
+ values: readonly ["left", "center", "right", "justify"];
6
+ };
7
+ backgroundColor: {
8
+ default: "transparent";
9
+ };
10
+ url: {
11
+ default: "";
12
+ };
13
+ caption: {
14
+ default: "";
15
+ };
16
+ width: {
17
+ default: 512;
18
+ };
19
+ };
20
+ export declare const Image: BlockSpec<"image", {
21
+ textAlignment: {
22
+ default: "left";
23
+ values: readonly ["left", "center", "right", "justify"];
24
+ };
25
+ backgroundColor: {
26
+ default: "transparent";
27
+ };
28
+ url: {
29
+ default: "";
30
+ };
31
+ caption: {
32
+ default: "";
33
+ };
34
+ width: {
35
+ default: 512;
36
+ };
37
+ }, false>;
@@ -0,0 +1,36 @@
1
+ import { EditorState, Plugin, PluginKey } from "prosemirror-state";
2
+ import { EditorView } from "prosemirror-view";
3
+ import { BaseUiElementCallbacks, BaseUiElementState, BlockNoteEditor, BlockSchema, BlockSpec, SpecificBlock } from "../..";
4
+ import { EventEmitter } from "../../shared/EventEmitter";
5
+ export type ImageToolbarCallbacks = BaseUiElementCallbacks;
6
+ export type ImageToolbarState = BaseUiElementState & {
7
+ block: SpecificBlock<BlockSchema & {
8
+ image: BlockSpec<"image", {
9
+ src: {
10
+ default: string;
11
+ };
12
+ }, false>;
13
+ }, "image">;
14
+ };
15
+ export declare class ImageToolbarView {
16
+ private readonly pluginKey;
17
+ private readonly pmView;
18
+ private imageToolbarState?;
19
+ updateImageToolbar: () => void;
20
+ prevWasEditable: boolean | null;
21
+ shouldShow: (state: EditorState) => boolean;
22
+ constructor(pluginKey: PluginKey, pmView: EditorView, updateImageToolbar: (imageToolbarState: ImageToolbarState) => void);
23
+ mouseDownHandler: () => void;
24
+ dragstartHandler: () => void;
25
+ blurHandler: (event: FocusEvent) => void;
26
+ scrollHandler: () => void;
27
+ update(view: EditorView, prevState: EditorState): void;
28
+ destroy(): void;
29
+ }
30
+ export declare const imageToolbarPluginKey: PluginKey<any>;
31
+ export declare class ImageToolbarProsemirrorPlugin<BSchema extends BlockSchema> extends EventEmitter<any> {
32
+ private view;
33
+ readonly plugin: Plugin;
34
+ constructor(_editor: BlockNoteEditor<BSchema>);
35
+ onUpdate(callback: (state: ImageToolbarState) => void): () => void;
36
+ }
@@ -1,5 +0,0 @@
1
- import { Node } from "@tiptap/core";
2
- export interface TableCellOptions {
3
- HTMLAttributes: Record<string, any>;
4
- }
5
- export declare const TableCell: Node<TableCellOptions, any>;
@@ -1,5 +0,0 @@
1
- import { Node } from "@tiptap/core";
2
- export interface TableRowOptions {
3
- HTMLAttributes: Record<string, any>;
4
- }
5
- export declare const TableRow: Node<TableRowOptions, any>;