slate-react: Separated type for onChange function (#36789)

* slate-react: Separated type for onChange function

* slate-react: Auto-fixes from the linter

* slate-react: Union duplicated imports

* slate-react: Removed an extra semicolon
This commit is contained in:
Yuri Drabik 2019-07-18 20:27:25 +02:00 committed by Andrew Branch
parent 919b9cddd5
commit dbf8b45905
2 changed files with 14 additions and 9 deletions

View File

@ -114,12 +114,18 @@ export interface Plugin extends CorePlugin {
export type PluginOrPlugins = Plugin | Plugins;
export interface Plugins extends Array<PluginOrPlugins> {}
export interface OnChangeParam {
operations: Immutable.List<Operation>;
value: Value;
}
export type OnChangeFn = (change: OnChangeParam) => any;
export interface BasicEditorProps {
value: Value;
autoCorrect?: boolean;
autoFocus?: boolean;
className?: string;
onChange?: (change: { operations: Immutable.List<Operation>; value: Value }) => any;
onChange?: OnChangeFn;
placeholder?: any;
plugins?: Plugins;
readOnly?: boolean;

View File

@ -1,15 +1,14 @@
import { Editor, Plugin, EditorProps, RenderBlockProps, RenderInlineProps } from "slate-react";
import { Value, Editor as Controller, Operation, Point, Range, Inline, Mark, Document, Decoration } from "slate";
import { Editor, Plugin, EditorProps, OnChangeFn, RenderBlockProps, RenderInlineProps } from 'slate-react';
import { Value, Editor as Controller, Point, Range, Inline, Mark, Document, Decoration } from 'slate';
import * as React from "react";
import * as Immutable from "immutable";
class MyPlugin implements Plugin {
renderBlock(props: RenderBlockProps, editor: Controller, next: () => void) {
const { node } = props;
if (node) {
switch (node.object) {
case "block":
return <div id="slate-block-test"/>;
case 'block':
return <div id="slate-block-test" />;
default:
return undefined;
}
@ -19,15 +18,15 @@ class MyPlugin implements Plugin {
const { node } = props;
if (node) {
switch (node.object) {
case "inline":
case 'inline':
return <span id="slate-inline-test">Hello world</span>;
default:
return undefined;
}
}
}
onChange = (change: {operations: Immutable.List<Operation>, value: Value}) => {
console.log(change.value);
onChange: OnChangeFn = ({ operations, value }) => {
console.log(operations, value);
}
}