diff --git a/types/slate/index.d.ts b/types/slate/index.d.ts index 3ea0d97817..ac58361ff8 100644 --- a/types/slate/index.d.ts +++ b/types/slate/index.d.ts @@ -27,7 +27,7 @@ export interface RulesByNodeType { export interface ObjectAndType { object?: string; - types?: string; + type?: string; } export interface Rules { diff --git a/types/slate/slate-tests.ts b/types/slate/slate-tests.ts index 8466784bf8..eb07649cba 100644 --- a/types/slate/slate-tests.ts +++ b/types/slate/slate-tests.ts @@ -1,4 +1,4 @@ -import { Value, Data, BlockJSON, Document, Editor, KeyUtils, Range, Point, Inline, Mark } from "slate"; +import { Block, Value, Data, BlockJSON, Document, Editor, KeyUtils, Range, Point, Inline, Mark, SchemaProperties } from "slate"; const data = Data.create({ foo: "bar " }); const value = Value.create({ data }); @@ -282,3 +282,36 @@ editor KeyUtils.setGenerator(() => "Test"); KeyUtils.create(); KeyUtils.resetGenerator(); + +const schema: SchemaProperties = { + document: { + nodes: [ + { + match: [ + { type: 'block-quote' }, + { type: 'heading-one' }, + { type: 'heading-two' }, + { type: 'image' }, + { type: 'paragraph' }, + { type: 'bulleted-list' }, + { type: 'numbered-list' }, + { type: 'list-item' }, + ], + }, + ], + last: { type: 'paragraph' }, + normalize: (editor: Editor, { code, node }: any) => { + switch (code) { + case 'last_child_type_invalid': { + const paragraph = Block.create('paragraph'); + return editor.insertNodeByKey(node.key, node.nodes.size, paragraph); + } + } + }, + }, + blocks: { + image: { + isVoid: true, + }, + }, +};