Skip to content
Merged
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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.addMissingImports": "explicit"
},
"[javascript]": { "editor.defaultFormatter": "esbenp.prettier-vscode" },
"[typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { defaultProps } from "@blocknote/core";
import { createReactBlockSpec } from "@blocknote/react";
import { Menu } from "@mantine/core";
import { MdCancel, MdCheckCircle, MdError, MdInfo } from "react-icons/md";
import { z } from "zod/v4";

import { createPropSchemaFromZod, defaultZodPropSchema } from "@blocknote/core";
import "./styles.css";

// The types of alerts that users can choose from.
Expand Down Expand Up @@ -54,16 +54,18 @@ export const alertTypes = [
export const Alert = createReactBlockSpec(
{
type: "alert",
propSchema: defaultProps
.pick({
textAlignment: true,
textColor: true,
})
.extend({
type: z
.enum(["warning", "error", "info", "success"])
.default("warning"),
}),
propSchema: createPropSchemaFromZod(
defaultZodPropSchema
.pick({
textAlignment: true,
textColor: true,
})
.extend({
type: z
.enum(["warning", "error", "info", "success"])
.default("warning"),
}),
),
content: "inline",
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { createPropSchemaFromZod } from "@blocknote/core";
import { createReactInlineContentSpec } from "@blocknote/react";
import { z } from "zod/v4";

// The Mention inline content.
export const Mention = createReactInlineContentSpec(
{
type: "mention",
propSchema: z.object({
user: z.string().default("Unknown"),
}),
propSchema: createPropSchemaFromZod(
z.object({
user: z.string().default("Unknown"),
}),
),
content: "none",
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {
baseFilePropSchema,
baseFileZodPropSchema,
blockHasType,
BlockSchema,
InlineContentSchema,
optionalFileProps,
optionalFileZodPropSchema,
StyleSchema,
createPropSchemaFromZod
} from "@blocknote/core";
import {
useBlockNoteEditor,
Expand Down Expand Up @@ -47,9 +48,10 @@ export const FileReplaceButton = () => {
block,
editor,
block.type,
baseFilePropSchema.extend({
...optionalFileProps.pick({ url: true }).shape,
}),
// TODO
createPropSchemaFromZod(baseFileZodPropSchema.extend({
...optionalFileZodPropSchema.pick({ url: true }).shape,
})),
) ||
!editor.isEditable
) {
Expand Down
24 changes: 13 additions & 11 deletions examples/06-custom-schema/01-alert-block/src/Alert.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defaultProps } from "@blocknote/core";
import { createPropSchemaFromZod, defaultZodPropSchema } from "@blocknote/core";
import { createReactBlockSpec } from "@blocknote/react";
import { Menu } from "@mantine/core";
import { MdCancel, MdCheckCircle, MdError, MdInfo } from "react-icons/md";
Expand Down Expand Up @@ -54,16 +54,18 @@ export const alertTypes = [
export const createAlert = createReactBlockSpec(
{
type: "alert",
propSchema: defaultProps
.pick({
textAlignment: true,
textColor: true,
})
.extend({
type: z
.enum(["warning", "error", "info", "success"])
.default("warning"),
}),
propSchema: createPropSchemaFromZod(
defaultZodPropSchema
.pick({
textAlignment: true,
textColor: true,
})
.extend({
type: z
.enum(["warning", "error", "info", "success"])
.default("warning"),
}),
),
content: "inline",
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { createPropSchemaFromZod } from "@blocknote/core";
import { createReactInlineContentSpec } from "@blocknote/react";
import { z } from "zod/v4";

// The Mention inline content.
export const Mention = createReactInlineContentSpec(
{
type: "mention",
propSchema: z.object({
user: z.string().default("Unknown"),
}),
propSchema: createPropSchemaFromZod(
z.object({
user: z.string().default("Unknown"),
}),
),
content: "none",
},
{
Expand Down
23 changes: 13 additions & 10 deletions examples/06-custom-schema/04-pdf-file-block/src/PDF.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {
baseFilePropSchema,
baseFileZodPropSchema,
createPropSchemaFromZod,
FileBlockConfig,
optionalFileProps,
optionalFileZodPropSchema,
} from "@blocknote/core";
import {
createReactBlockSpec,
Expand Down Expand Up @@ -38,14 +39,16 @@ export const PDFPreview = (
export const PDF = createReactBlockSpec(
{
type: "pdf",
propSchema: z.object({}).extend({
...baseFilePropSchema.shape,
...optionalFileProps.pick({
url: true,
showPreview: true,
previewWidth: true,
}).shape,
}),
propSchema: createPropSchemaFromZod(
z.object({}).extend({
...baseFileZodPropSchema.shape,
...optionalFileZodPropSchema.pick({
url: true,
showPreview: true,
previewWidth: true,
}).shape,
}),
),
content: "none",
},
{
Expand Down
24 changes: 13 additions & 11 deletions examples/06-custom-schema/05-alert-block-full-ux/src/Alert.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defaultProps } from "@blocknote/core";
import { createPropSchemaFromZod, defaultZodPropSchema } from "@blocknote/core";
import { createReactBlockSpec } from "@blocknote/react";
import { Menu } from "@mantine/core";
import { MdCancel, MdCheckCircle, MdError, MdInfo } from "react-icons/md";
Expand Down Expand Up @@ -54,16 +54,18 @@ export const alertTypes = [
export const createAlert = createReactBlockSpec(
{
type: "alert",
propSchema: defaultProps
.pick({
textAlignment: true,
textColor: true,
})
.extend({
type: z
.enum(["warning", "error", "info", "success"])
.default("warning"),
}),
propSchema: createPropSchemaFromZod(
defaultZodPropSchema
.pick({
textAlignment: true,
textColor: true,
})
.extend({
type: z
.enum(["warning", "error", "info", "success"])
.default("warning"),
}),
),
content: "inline",
},
{
Expand Down
6 changes: 2 additions & 4 deletions examples/06-custom-schema/06-toggleable-blocks/src/Toggle.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { defaultProps } from "@blocknote/core";
import { defaultPropSchema } from "@blocknote/core";
import { createReactBlockSpec, ToggleWrapper } from "@blocknote/react";

// The Toggle block that we want to add to our editor.
export const ToggleBlock = createReactBlockSpec(
{
type: "toggle",
propSchema: {
...defaultProps,
} as typeof defaultProps,
propSchema: defaultPropSchema,
content: "inline",
},
{
Expand Down
14 changes: 10 additions & 4 deletions examples/06-custom-schema/draggable-inline-content/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { BlockNoteSchema, defaultInlineContentSpecs } from "@blocknote/core";
import {
BlockNoteSchema,
createPropSchemaFromZod,
defaultInlineContentSpecs,
} from "@blocknote/core";
import "@blocknote/core/fonts/inter.css";
import { BlockNoteView } from "@blocknote/mantine";
import "@blocknote/mantine/style.css";
Expand All @@ -11,9 +15,11 @@ import { z } from "zod/v4";
const draggableButton = createReactInlineContentSpec(
{
type: "draggableButton",
propSchema: z.object({
title: z.string().default(""),
}),
propSchema: createPropSchemaFromZod(
z.object({
title: z.string().default(""),
}),
),
content: "none",
},
{
Expand Down
46 changes: 25 additions & 21 deletions examples/06-custom-schema/react-custom-blocks/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import {
BlockNoteSchema,
createPropSchemaFromZod,
defaultBlockSpecs,
defaultProps,
defaultPropSchema,
defaultZodPropSchema,
} from "@blocknote/core";
import "@blocknote/core/fonts/inter.css";
import { BlockNoteView } from "@blocknote/mantine";
Expand Down Expand Up @@ -38,16 +40,18 @@ const alertTypes = {
export const alertBlock = createReactBlockSpec(
{
type: "alert",
propSchema: defaultProps
.pick({
textAlignment: true,
textColor: true,
})
.extend({
type: z
.enum(["warning", "error", "info", "success"])
.default("warning"),
}),
propSchema: createPropSchemaFromZod(
defaultZodPropSchema
.pick({
textAlignment: true,
textColor: true,
})
.extend({
type: z
.enum(["warning", "error", "info", "success"])
.default("warning"),
}),
),
content: "inline",
},
{
Expand Down Expand Up @@ -82,13 +86,15 @@ export const alertBlock = createReactBlockSpec(
const simpleImageBlock = createReactBlockSpec(
{
type: "simpleImage",
propSchema: z.object({
src: z
.string()
.default(
"https://www.pulsecarshalton.co.uk/wp-content/uploads/2016/08/jk-placeholder-image.jpg",
),
}),
propSchema: createPropSchemaFromZod(
z.object({
src: z
.string()
.default(
"https://www.pulsecarshalton.co.uk/wp-content/uploads/2016/08/jk-placeholder-image.jpg",
),
}),
),
content: "none",
},
{
Expand All @@ -106,9 +112,7 @@ export const bracketsParagraphBlock = createReactBlockSpec(
{
type: "bracketsParagraph",
content: "inline",
propSchema: {
...defaultProps,
},
propSchema: defaultPropSchema,
},
{
render: (props) => (
Expand Down
16 changes: 11 additions & 5 deletions examples/06-custom-schema/react-custom-inline-content/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { BlockNoteSchema, defaultInlineContentSpecs } from "@blocknote/core";
import {
BlockNoteSchema,
createPropSchemaFromZod,
defaultInlineContentSpecs,
} from "@blocknote/core";
import "@blocknote/core/fonts/inter.css";
import { BlockNoteView } from "@blocknote/mantine";
import "@blocknote/mantine/style.css";
Expand All @@ -11,9 +15,11 @@ import { z } from "zod/v4";
const mention = createReactInlineContentSpec(
{
type: "mention",
propSchema: z.object({
user: z.string().default(""),
}),
propSchema: createPropSchemaFromZod(
z.object({
user: z.string().default(""),
}),
),
content: "none",
},
{
Expand All @@ -26,7 +32,7 @@ const mention = createReactInlineContentSpec(
const tag = createReactInlineContentSpec(
{
type: "tag",
propSchema: z.object({}),
propSchema: createPropSchemaFromZod(z.object({})),
content: "styled",
},
{
Expand Down
Loading
Loading