From a7dfc6c9a868f8da8d8e0eb65ea2044e2883a041 Mon Sep 17 00:00:00 2001 From: Spencer Elliott Date: Wed, 14 Nov 2018 14:34:55 -0500 Subject: [PATCH] [slate] Fix ObjectAndType interface: `types` -> `type` (#30388) * Fix ObjectAndType interface: `types` -> `type` * Fix slate tests: use SchemaProperties The `Schema` class no longer exists, so `Schema.create` would not work. --- types/slate/index.d.ts | 2 +- types/slate/slate-tests.ts | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) 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, + }, + }, +};