Skip to content

Commit 5a685a1

Browse files
committed
Merge remote-tracking branch 'origin/main' into refactor/zod-props-v2
2 parents 60871a6 + f1d6e89 commit 5a685a1

File tree

18 files changed

+211
-158
lines changed

18 files changed

+211
-158
lines changed

packages/core/src/extensions/BackgroundColor/BackgroundColorMark.ts

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

packages/core/src/extensions/TextColor/TextColorMark.ts

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

packages/core/src/schema/CustomBlockNoteSchema.ts

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,12 @@ export class CustomBlockNoteSchema<
110110
const defaultSet = new Set<string>();
111111
dag.set("default", defaultSet);
112112

113-
for (const [key, specDef] of Object.entries(this.opts.blockSpecs)) {
114-
if (specDef.implementation.runsBefore) {
113+
for (const [key, specDef] of Object.entries({
114+
...this.opts.blockSpecs,
115+
...this.opts.inlineContentSpecs,
116+
...this.opts.styleSpecs,
117+
})) {
118+
if (specDef.implementation?.runsBefore) {
115119
dag.set(key, new Set(specDef.implementation.runsBefore));
116120
} else {
117121
defaultSet.add(key);
@@ -156,19 +160,58 @@ export class CustomBlockNoteSchema<
156160
: never;
157161
};
158162

163+
const inlineContentSpecs = Object.fromEntries(
164+
Object.entries(this.opts.inlineContentSpecs).map(
165+
([key, inlineContentSpec]) => {
166+
// Case for text and links.
167+
if (typeof inlineContentSpec.config !== "object") {
168+
return [key, inlineContentSpec];
169+
}
170+
171+
return [
172+
key,
173+
{
174+
...inlineContentSpec,
175+
implementation: {
176+
...inlineContentSpec.implementation,
177+
node: inlineContentSpec.implementation?.node.extend({
178+
priority: getPriority(key),
179+
}),
180+
},
181+
},
182+
];
183+
},
184+
),
185+
) as InlineContentSpecs;
186+
187+
const styleSpecs = Object.fromEntries(
188+
Object.entries(this.opts.styleSpecs).map(([key, styleSpec]) => [
189+
key,
190+
{
191+
...styleSpec,
192+
implementation: {
193+
...styleSpec.implementation,
194+
mark: styleSpec.implementation?.mark.extend({
195+
priority: getPriority(key),
196+
}),
197+
},
198+
},
199+
]),
200+
) as StyleSpecs;
201+
159202
return {
160203
blockSpecs,
161204
blockSchema: Object.fromEntries(
162205
Object.entries(blockSpecs).map(([key, blockDef]) => {
163206
return [key, blockDef.config];
164207
}),
165208
) as any,
166-
inlineContentSpecs: removeUndefined(this.opts.inlineContentSpecs),
167-
styleSpecs: removeUndefined(this.opts.styleSpecs),
209+
inlineContentSpecs: removeUndefined(inlineContentSpecs),
210+
styleSpecs: removeUndefined(styleSpecs),
168211
inlineContentSchema: getInlineContentSchemaFromSpecs(
169-
this.opts.inlineContentSpecs,
212+
inlineContentSpecs,
170213
) as any,
171-
styleSchema: getStyleSchemaFromSpecs(this.opts.styleSpecs) as any,
214+
styleSchema: getStyleSchemaFromSpecs(styleSpecs) as any,
172215
};
173216
}
174217

packages/core/src/schema/inlineContent/createSpec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ export type CustomInlineContentImplementation<
8282
contentDOM?: HTMLElement;
8383
}
8484
| undefined;
85+
86+
runsBefore?: string[];
8587
};
8688

8789
export function getInlineContentParseRules<C extends CustomInlineContentConfig>(
@@ -225,6 +227,7 @@ export function createInlineContentSpec<
225227
node,
226228
inlineContentConfig.propSchema,
227229
{
230+
...inlineContentImplementation,
228231
toExternalHTML: inlineContentImplementation.toExternalHTML,
229232
render(inlineContent, updateInlineContent, editor) {
230233
const output = inlineContentImplementation.render(

packages/core/src/schema/inlineContent/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export type InlineContentImplementation<T extends InlineContentConfig> =
4343
ignoreMutation?: (mutation: ViewMutationRecord) => boolean;
4444
destroy?: () => void;
4545
};
46+
runsBefore?: string[];
4647
};
4748

4849
export type InlineContentSchemaWithInlineContent<

packages/core/src/schema/styles/createSpec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export type CustomStyleImplementation<T extends StyleConfig> = {
2020
parse?: (
2121
element: HTMLElement,
2222
) => (T["propSchema"] extends "boolean" ? true : string) | undefined;
23+
runsBefore?: string[];
2324
};
2425

2526
export function getStyleParseRules<T extends StyleConfig>(
@@ -44,6 +45,10 @@ export function getStyleParseRules<T extends StyleConfig>(
4445
if (customParseFunction) {
4546
rules.push({
4647
tag: "*",
48+
// By default, styles can overlap each other, so the rules should not
49+
// completely consume the element they parse (which can have multiple
50+
// styles).
51+
consuming: false,
4752
getAttrs(node: string | HTMLElement) {
4853
if (typeof node === "string") {
4954
return false;
@@ -105,6 +110,7 @@ export function createStyleSpec<const T extends StyleConfig>(
105110
});
106111

107112
return createInternalStyleSpec(styleConfig, {
113+
...styleImplementation,
108114
mark,
109115
render: (value) => {
110116
const renderResult = styleImplementation.render(value as any);

packages/core/src/schema/styles/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export type StyleImplementation<T extends StyleConfig> = {
2828
dom: HTMLElement;
2929
contentDOM?: HTMLElement;
3030
};
31+
runsBefore?: string[];
3132
};
3233

3334
// Container for both the config and implementation of a Style,

packages/react/src/schema/ReactInlineContentSpec.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ export function createReactInlineContentSpec<
243243
return createInternalInlineContentSpec(
244244
inlineContentConfig as CustomInlineContentConfig,
245245
{
246+
...inlineContentImplementation,
246247
node,
247248
render(inlineContent, updateInlineContent, editor) {
248249
const Content = inlineContentImplementation.render;

packages/react/src/schema/ReactStyleSpec.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export type ReactCustomStyleImplementation<T extends StyleConfig> = {
2323
contentRef: (el: HTMLElement | null) => void;
2424
editor: BlockNoteEditor<any, any, any>;
2525
}>;
26+
runsBefore?: string[];
2627
};
2728

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

118119
return createInternalStyleSpec(styleConfig, {
120+
...styleImplementation,
119121
mark,
120122
render(value, editor) {
121123
const Content = styleImplementation.render;

0 commit comments

Comments
 (0)