[@types/slate-react] Support nested plugin stacks on the "plugins" property of the Editor React component (#36350)

* fix: react editor takes a recursively nested plugin stack as property

* refactor: remove obsolete list type. naming. inline with feedback on #36349

* fix: enforce a list as root data type. See also #36349
This commit is contained in:
Lukas Bünger
2019-06-27 11:04:37 -07:00
committed by Benjamin Lichtman
parent 587afaa16c
commit 01bb26d2c0
2 changed files with 15 additions and 7 deletions
+5 -2
View File
@@ -111,14 +111,17 @@ export interface Plugin extends CorePlugin {
onSelect?: EventHook;
}
export type PluginOrPlugins = Plugin | Plugins;
export interface Plugins extends Array<PluginOrPlugins> {}
export interface BasicEditorProps {
value: Value;
autoCorrect?: boolean;
autoFocus?: boolean;
className?: string;
onChange?: (change: { operations: Immutable.List<Operation>, value: Value }) => any;
onChange?: (change: { operations: Immutable.List<Operation>; value: Value }) => any;
placeholder?: any;
plugins?: Plugin[];
plugins?: Plugins;
readOnly?: boolean;
role?: string;
schema?: SchemaProperties;
+10 -5
View File
@@ -32,6 +32,7 @@ class MyPlugin implements Plugin {
}
const myPlugin = new MyPlugin();
const plugins = [myPlugin, [myPlugin, [myPlugin]]];
interface MyEditorState {
value: Value;
@@ -47,11 +48,15 @@ class MyEditor extends React.Component<EditorProps, MyEditorState> {
};
}
render() {
return <Editor
value={this.state.value}
renderBlock={ myPlugin.renderBlock }
renderInline={ myPlugin.renderInline }
onChange={ myPlugin.onChange }/>;
return (
<Editor
plugins={plugins}
value={this.state.value}
renderBlock={myPlugin.renderBlock}
renderInline={myPlugin.renderInline}
onChange={myPlugin.onChange}
/>
);
}
}