Skip to content

Commit 060108a

Browse files
feat: Default blocks refactor fixes (#1953)
* WIP * WIP React
1 parent f934d26 commit 060108a

File tree

91 files changed

+1205
-3241
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+1205
-3241
lines changed

packages/core/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export function insertBlocks<
4848
// re-convert them into full `Block`s.
4949
const insertedBlocks = nodesToInsert.map((node) =>
5050
nodeToBlock(node, pmSchema),
51-
);
51+
) as Block<BSchema, I, S>[];
5252

5353
return insertedBlocks;
5454
}

packages/core/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export function removeAndInsertBlocks<
102102
// Converts the nodes created from `blocksToInsert` into full `Block`s.
103103
const insertedBlocks = nodesToInsert.map((node) =>
104104
nodeToBlock(node, pmSchema),
105-
);
105+
) as Block<BSchema, I, S>[];
106106

107107
return { insertedBlocks, removedBlocks };
108-
}
108+
}

packages/core/src/api/clipboard/toClipboard/copyExtension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ function fragmentToExternalHTML<
9494
);
9595
externalHTML = externalHTMLExporter.exportInlineContent(ic, {});
9696
} else {
97-
const blocks = fragmentToBlocks(selectedFragment);
97+
const blocks = fragmentToBlocks<BSchema, I, S>(selectedFragment);
9898
externalHTML = externalHTMLExporter.exportBlocks(blocks, {});
9999
}
100100
return externalHTML;

packages/core/src/api/exporters/html/util/serializeBlocksExternalHTML.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,19 @@ function serializeBlock<
112112
// we should change toExternalHTML so that this is not necessary
113113
const attrs = Array.from(bc.dom.attributes);
114114

115-
const ret = editor.blockImplementations[
116-
block.type as any
117-
].implementation.toExternalHTML({ ...block, props } as any, editor as any);
115+
const blockImplementation =
116+
editor.blockImplementations[block.type as any].implementation;
117+
const ret =
118+
blockImplementation.toExternalHTML?.(
119+
{ ...block, props } as any,
120+
editor as any,
121+
) || blockImplementation.render({ ...block, props } as any, editor as any);
118122

119123
const elementFragment = doc.createDocumentFragment();
120-
if (ret.dom.classList.contains("bn-block-content")) {
124+
if (
125+
ret.dom instanceof HTMLElement &&
126+
ret.dom.classList.contains("bn-block-content")
127+
) {
121128
const blockContentDataAttributes = [
122129
...attrs,
123130
...Array.from(ret.dom.attributes),

packages/core/src/api/exporters/html/util/serializeBlocksInternalHTML.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function serializeBlock<
7474
}
7575

7676
const impl = editor.blockImplementations[block.type as any].implementation;
77-
const ret = impl.toInternalHTML({ ...block, props } as any, editor as any);
77+
const ret = impl.render({ ...block, props } as any, editor as any);
7878

7979
if (block.type === "numberedListItem") {
8080
// This is a workaround to make sure there's a list index set.
@@ -83,7 +83,9 @@ function serializeBlock<
8383
// - (a) this information is not available on the Blocks passed to the serializer. (we only have access to BlockNote Blocks)
8484
// - (b) the NumberedListIndexingPlugin might not even have run, because we can manually call blocksToFullHTML
8585
// with blocks that are not part of the active document
86-
ret.dom.setAttribute("data-index", listIndex.toString());
86+
if (ret.dom instanceof HTMLElement) {
87+
ret.dom.setAttribute("data-index", listIndex.toString());
88+
}
8789
}
8890

8991
if (ret.contentDOM && block.content) {

packages/core/src/blks/Audio/definition.ts

Lines changed: 0 additions & 135 deletions
This file was deleted.

packages/core/src/blks/File/definition.ts

Lines changed: 0 additions & 89 deletions
This file was deleted.

0 commit comments

Comments
 (0)