Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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

This file was deleted.

38 changes: 0 additions & 38 deletions packages/core/src/extensions/TextColor/TextColorMark.ts

This file was deleted.

4 changes: 4 additions & 0 deletions packages/core/src/schema/inlineContent/createSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ export type CustomInlineContentImplementation<
contentDOM?: HTMLElement;
}
| undefined;

runsBefore?: string[];
};

export function getInlineContentParseRules<C extends CustomInlineContentConfig>(
Expand Down Expand Up @@ -220,6 +222,8 @@ export function createInlineContentSpec<
node,
inlineContentConfig.propSchema,
{
...inlineContentImplementation,
runsBefore: inlineContentImplementation.runsBefore || ["default"],
toExternalHTML: inlineContentImplementation.toExternalHTML,
render(inlineContent, updateInlineContent, editor) {
const output = inlineContentImplementation.render(
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/schema/inlineContent/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export type InlineContentImplementation<T extends InlineContentConfig> =
ignoreMutation?: (mutation: ViewMutationRecord) => boolean;
destroy?: () => void;
};
runsBefore?: string[];
};

export type InlineContentSchemaWithInlineContent<
Expand Down
55 changes: 49 additions & 6 deletions packages/core/src/schema/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,12 @@ export class CustomBlockNoteSchema<
const defaultSet = new Set<string>();
dag.set("default", defaultSet);

for (const [key, specDef] of Object.entries(this.opts.blockSpecs)) {
if (specDef.implementation.runsBefore) {
for (const [key, specDef] of Object.entries({
...this.opts.blockSpecs,
...this.opts.inlineContentSpecs,
...this.opts.styleSpecs,
})) {
if (specDef.implementation?.runsBefore) {
dag.set(key, new Set(specDef.implementation.runsBefore));
} else {
defaultSet.add(key);
Expand Down Expand Up @@ -130,19 +134,58 @@ export class CustomBlockNoteSchema<
: never;
};

const inlineContentSpecs = Object.fromEntries(
Object.entries(this.opts.inlineContentSpecs).map(
([key, inlineContentSpec]) => {
// Case for text and links.
if (typeof inlineContentSpec.config !== "object") {
return [key, inlineContentSpec];
}

return [
key,
{
...inlineContentSpec,
implementation: {
...inlineContentSpec.implementation,
node: inlineContentSpec.implementation?.node.extend({
priority: getPriority(key),
}),
},
},
];
},
),
) as InlineContentSpecs;

const styleSpecs = Object.fromEntries(
Object.entries(this.opts.styleSpecs).map(([key, styleSpec]) => [
key,
{
...styleSpec,
implementation: {
...styleSpec.implementation,
mark: styleSpec.implementation?.mark.extend({
priority: getPriority(key),
}),
},
},
]),
) as StyleSpecs;

return {
blockSpecs,
blockSchema: Object.fromEntries(
Object.entries(blockSpecs).map(([key, blockDef]) => {
return [key, blockDef.config];
}),
) as any,
inlineContentSpecs: removeUndefined(this.opts.inlineContentSpecs),
styleSpecs: removeUndefined(this.opts.styleSpecs),
inlineContentSpecs: removeUndefined(inlineContentSpecs),
styleSpecs: removeUndefined(styleSpecs),
inlineContentSchema: getInlineContentSchemaFromSpecs(
this.opts.inlineContentSpecs,
inlineContentSpecs,
) as any,
styleSchema: getStyleSchemaFromSpecs(this.opts.styleSpecs) as any,
styleSchema: getStyleSchemaFromSpecs(styleSpecs) as any,
};
}

Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/schema/styles/createSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export type CustomStyleImplementation<T extends StyleConfig> = {
parse?: (
element: HTMLElement,
) => (T["propSchema"] extends "boolean" ? true : string) | undefined;
runsBefore?: string[];
};

export function getStyleParseRules<T extends StyleConfig>(
Expand All @@ -46,6 +47,7 @@ export function getStyleParseRules<T extends StyleConfig>(
if (customParseFunction) {
rules.push({
tag: "*",
consuming: false,
getAttrs(node: string | HTMLElement) {
if (typeof node === "string") {
return false;
Expand Down Expand Up @@ -107,7 +109,9 @@ export function createStyleSpec<const T extends StyleConfig>(
});

return createInternalStyleSpec(styleConfig, {
...styleImplementation,
mark,
runsBefore: styleImplementation.runsBefore || ["default"],
render: (value) => {
const renderResult = styleImplementation.render(value as any);

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/schema/styles/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export type StyleImplementation<T extends StyleConfig> = {
dom: HTMLElement;
contentDOM?: HTMLElement;
};
runsBefore?: string[];
};

// Container for both the config and implementation of a Style,
Expand Down
2 changes: 2 additions & 0 deletions packages/react/src/schema/ReactInlineContentSpec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ export function createReactInlineContentSpec<
return createInternalInlineContentSpec(
inlineContentConfig as CustomInlineContentConfig,
{
...inlineContentImplementation,
node,
render(inlineContent, updateInlineContent, editor) {
const Content = inlineContentImplementation.render;
Expand Down Expand Up @@ -288,6 +289,7 @@ export function createReactInlineContentSpec<
}, editor);
return output;
},
runsBefore: inlineContentImplementation.runsBefore || ["default"]
},
) as any;
}
3 changes: 3 additions & 0 deletions packages/react/src/schema/ReactStyleSpec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export type ReactCustomStyleImplementation<T extends StyleConfig> = {
contentRef: (el: HTMLElement | null) => void;
editor: BlockNoteEditor<any, any, any>;
}>;
runsBefore?: string[];
};

// A function to create custom block for API consumers
Expand Down Expand Up @@ -116,6 +117,7 @@ export function createReactStyleSpec<T extends StyleConfig>(
});

return createInternalStyleSpec(styleConfig, {
...styleImplementation,
mark,
render(value, editor) {
const Content = styleImplementation.render;
Expand Down Expand Up @@ -167,5 +169,6 @@ export function createReactStyleSpec<T extends StyleConfig>(
styleConfig.propSchema,
);
},
runsBefore: styleImplementation.runsBefore || ["default"],
});
}
Loading