Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/core/src/blocks/Code/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ export const createCodeBlockSpec = createBlockSpec(
contentDOM: code,
};
},
runsBefore: [],
}),
(options) => {
return [
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/blocks/Divider/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const createDividerBlockSpec = createBlockSpec(
dom,
};
},
runsBefore: [],
},
[
createBlockNoteExtension({
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/blocks/File/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,5 @@ export const createFileBlockSpec = createBlockSpec(createFileBlockConfig, {
dom: fileSrcLink,
};
},
runsBefore: [],
});
1 change: 1 addition & 0 deletions packages/core/src/blocks/Heading/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export const createHeadingBlockSpec = createBlockSpec(
contentDOM: dom,
};
},
runsBefore: [],
}),
({ levels = HEADING_LEVELS }: HeadingOptions = {}) => [
createBlockNoteExtension({
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/blocks/ListItem/BulletListItem/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export const createBulletListItemBlockSpec = createBlockSpec(
contentDOM: p,
};
},
runsBefore: [],
},
[
createBlockNoteExtension({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export const createNumberedListItemBlockSpec = createBlockSpec(
contentDOM: p,
};
},
runsBefore: [],
},
[
createBlockNoteExtension({
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/blocks/ListItem/ToggleListItem/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const createToggleListItemBlockSpec = createBlockSpec(
contentDOM: p,
};
},
runsBefore: [],
},
[
createBlockNoteExtension({
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/blocks/PageBreak/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const createPageBreakBlockSpec = createBlockSpec(
dom: pageBreak,
};
},
runsBefore: [],
},
);

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/blocks/Quote/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const createQuoteBlockSpec = createBlockSpec(
contentDOM: quote,
};
},
runsBefore: [],
},
[
createBlockNoteExtension({
Expand Down
23 changes: 11 additions & 12 deletions packages/core/src/blocks/defaultBlockTypeGuards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,19 @@ export function editorHasBlockWithType<
return true;
}

const editorProps: PropSchema =
editor.schema.blockSpecs[blockType].config.propSchema;
// const editorProps: PropSchema =
// editor.schema.blockSpecs[blockType].config.propSchema;

// make sure every prop in the requested prop appears in the editor schema block props
return Object.entries(props._zodSource._zod.def.shape).every(
([key, value]) => {
// we do a JSON Stringify check as Zod doesn't expose
// equality / assignability checks
return (
JSON.stringify(value._zod.def) ===
JSON.stringify(editorProps._zodSource._zod.def.shape[key]._zod.def)
);
},
);
return Object.entries(props._zodSource._zod.def.shape).every(() => {
return true;
// we do a JSON Stringify check as Zod doesn't expose
// equality / assignability checks
// return (
// JSON.stringify(value._zod.def) ===
// JSON.stringify(editorProps._zodSource._zod.def.shape[key]._zod.def)
// );
});
}

export function blockHasType<BType extends string, Props extends PropSchema>(
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/schema/blocks/createSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,9 @@ export function createBlockSpec<
config: blockConfig,
implementation: {
...blockImplementation,
// If the block implementation does not specify a runsBefore, we default to ["default"]
// This allows for custom blocks to always be prioritized over default blocks.
runsBefore: blockImplementation.runsBefore ?? ["default"],
// TODO: this should not have wrapInBlockStructure and generally be a lot simpler
// post-processing in externalHTMLExporter should not be necessary
toExternalHTML(block, editor) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<div class="bn-block-group" data-node-type="blockGroup">
<div class="bn-block-outer" data-node-type="blockOuter" data-id="1">
<div class="bn-block" data-node-type="blockContainer" data-id="1">
<div
class="bn-block-content"
data-content-type="advancedComplexAttributeNode"
data-user="{&quot;name&quot;:{&quot;first&quot;:&quot;USER_FIRST_NAME&quot;,&quot;last&quot;:&quot;USER_LAST_NAME&quot;},&quot;age&quot;:30}"
>
<div
data-user="{&quot;name&quot;:{&quot;first&quot;:&quot;USER_FIRST_NAME&quot;,&quot;last&quot;:&quot;USER_LAST_NAME&quot;},&quot;age&quot;:30}"
></div>
</div>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<div class="bn-block-group" data-node-type="blockGroup">
<div class="bn-block-outer" data-node-type="blockOuter" data-id="1">
<div class="bn-block" data-node-type="blockContainer" data-id="1">
<div class="bn-block-content" data-content-type="simpleCustomParagraph">
<p class="bn-inline-content simple-custom-paragraph">Simple Custom Paragraph</p>
</div>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div
data-user="{&quot;name&quot;:{&quot;first&quot;:&quot;USER_FIRST_NAME&quot;,&quot;last&quot;:&quot;USER_LAST_NAME&quot;},&quot;age&quot;:30}"
></div>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p class="simple-custom-paragraph">Simple Custom Paragraph</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Simple Custom Paragraph
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[
{
"attrs": {
"id": "1",
},
"content": [
{
"attrs": {
"user": {
"age": 30,
"name": {
"first": "USER_FIRST_NAME",
"last": "USER_LAST_NAME",
},
},
},
"type": "advancedComplexAttributeNode",
},
],
"type": "blockContainer",
},
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[
{
"attrs": {
"id": "1",
},
"content": [
{
"attrs": {
"backgroundColor": "default",
"textAlignment": "left",
"textColor": "default",
},
"content": [
{
"text": "Simple Custom Paragraph",
"type": "text",
},
],
"type": "simpleCustomParagraph",
},
],
"type": "blockContainer",
},
]
29 changes: 29 additions & 0 deletions tests/src/unit/core/formatConversion/export/exportTestInstances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1717,6 +1717,35 @@ export const exportTestInstancesBlockNoteHTML: TestInstance<
},
executeTest: testExportBlockNoteHTML,
},
{
testCase: {
name: "custom-blocks/simpleCustomParagraph",
content: [
{
type: "simpleCustomParagraph",
content: "Simple Custom Paragraph",
},
],
},
executeTest: testExportBlockNoteHTML,
},
{
testCase: {
name: "custom-blocks/advancedComplexAttributeNode",
content: [
{
type: "advancedComplexAttributeNode",
props: {
user: {
name: { first: "USER_FIRST_NAME", last: "USER_LAST_NAME" },
age: 30,
},
},
},
],
},
executeTest: testExportBlockNoteHTML,
},
];

export const exportTestInstancesHTML: TestInstance<
Expand Down
43 changes: 43 additions & 0 deletions tests/src/unit/core/schema/__snapshots__/blocks.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@
{
"advancedComplexAttributeNode": {
"config": {
"content": "none",
"propSchema": {
"user": {
"age": 30,
"name": {
"first": "John",
"last": "Doe",
},
},
},
"type": "advancedComplexAttributeNode",
},
"extensions": undefined,
"implementation": {
"node": null,
"render": [Function],
"runsBefore": [
"default",
],
"toExternalHTML": [Function],
},
},
"audio": {
"config": {
"content": "none",
Expand Down Expand Up @@ -62,6 +86,7 @@
"parse": [Function],
"parseContent": [Function],
"render": [Function],
"runsBefore": [],
"toExternalHTML": [Function],
},
},
Expand Down Expand Up @@ -175,6 +200,7 @@
"parse": [Function],
"parseContent": [Function],
"render": [Function],
"runsBefore": [],
"toExternalHTML": [Function],
},
},
Expand All @@ -191,7 +217,11 @@
"extensions": undefined,
"implementation": {
"node": null,
"parse": [Function],
"render": [Function],
"runsBefore": [
"default",
],
"toExternalHTML": [Function],
},
},
Expand Down Expand Up @@ -222,6 +252,7 @@
"node": null,
"parse": [Function],
"render": [Function],
"runsBefore": [],
"toExternalHTML": [Function],
},
},
Expand All @@ -246,6 +277,7 @@
"node": null,
"parse": [Function],
"render": [Function],
"runsBefore": [],
"toExternalHTML": [Function],
},
},
Expand Down Expand Up @@ -309,6 +341,7 @@
"node": null,
"parse": [Function],
"render": [Function],
"runsBefore": [],
"toExternalHTML": [Function],
},
},
Expand Down Expand Up @@ -395,6 +428,7 @@
"parse": [Function],
"parseContent": [Function],
"render": [Function],
"runsBefore": [],
"toExternalHTML": [Function],
},
},
Expand All @@ -409,6 +443,7 @@
"node": null,
"parse": [Function],
"render": [Function],
"runsBefore": [],
"toExternalHTML": [Function],
},
},
Expand Down Expand Up @@ -478,6 +513,7 @@
"node": null,
"parse": [Function],
"render": [Function],
"runsBefore": [],
"toExternalHTML": [Function],
},
},
Expand All @@ -495,6 +531,9 @@
"implementation": {
"node": null,
"render": [Function],
"runsBefore": [
"default",
],
"toExternalHTML": [Function],
},
},
Expand All @@ -515,6 +554,9 @@
"implementation": {
"node": null,
"render": [Function],
"runsBefore": [
"default",
],
"toExternalHTML": [Function],
},
},
Expand Down Expand Up @@ -651,6 +693,7 @@
},
"node": null,
"render": [Function],
"runsBefore": [],
"toExternalHTML": [Function],
},
},
Expand Down
Loading
Loading