跳至正文
Wener Notes

BlockNote

约 1 分钟阅读
    • MPLv2, TS, React
    • 基于 tiptap,prosemirror
    • UI mantine, shadcn
    • 原生 React - 非常好定制化和扩展
bash
npm add @blocknote/{core,react,shadcn}

Cutome

Model

TSX
type Block = {
  id: string;
  type: string;
  props: Record<string, boolean | number | string>;
  content: InlineContent[] | TableContent | undefined;
  children: Block[];
};

type InlineContent = Link | StyledText;

type Link = {
  type: 'link';
  content: StyledText[];
  href: string;
};

type StyledText = {
  type: 'text';
  text: string;
  styles: Styles;
};

type TableContent = {
  type: 'tableContent';
  rows: {
    cells: InlineContent[][];
  }[];
};

// 默认 Schema

type ParagraphBlock = {
  id: string;
  type: "paragraph";
  props: DefaultProps;
  content: InlineContent[];
  children: Block[];
};

type HeadingBlock = {
  id: string;
  type: "heading";
  props: {
    level: 1 | 2 | 3 = 1;
  } & DefaultProps;
  content: InlineContent[];
  children: Block[];
};

type BulletListItemBlock = {
  id: string;
  type: "bulletListItem";
  props: DefaultProps;
  content: InlineContent[];
  children: Block[];
};

type NumberedListItemBlock = {
  id: string;
  type: "numberedListItem";
  props: DefaultProps;
  content: InlineContent[];
  children: Block[];
};

type ImageBlock = {
  id: string;
  type: "image";
  props: {
    url: string = "";
    caption: string = "";
    width: number = 512;
  } & DefaultProps;
  content: undefined;
  children: Block[];
};

type TableBlock = {
  id: string;
  type: "table";
  props: DefaultProps;
  content: TableContent[];
  children: Block[];
};

type DefaultProps = {
  backgroundColor: string = "default";
  textColor: string = "default";
  textAlignment: "left" | "center" | "right" | "justify" = "left";
};

type Styles = {
  bold: boolean;
  italic: boolean;
  underline: boolean;
  strikethrough: boolean;
  textColor: string;
  backgroundColor: string;
};

关联信息

反向链接、本文链接的其他页面和外部资料。

参考资料

GitHub3 条
其他外链1 条
最近更新commit 136452c编辑