Merge pull request #28343 from isubasti/slate-0.40

[@types/slate] update to 0.40, [@types/slate-react] update to 0.18
This commit is contained in:
Mine Starks
2018-09-06 11:13:50 -07:00
committed by GitHub
3 changed files with 1500 additions and 677 deletions

View File

@@ -1,108 +1,166 @@
// Type definitions for slate-react 0.12
// Type definitions for slate-react 0.18
// Project: https://github.com/ianstormtaylor/slate
// Definitions by: Andy Kent <https://github.com/andykent>
// Jamie Talbot <https://github.com/majelbstoat>
// Jan Löbel <https://github.com/JanLoebel>
// Patrick Sachs <https://github.com/PatrickSachs>
// Brandon Shelton <https://github.com/YangusKhan>
// Irwan Fario Subastian <https://github.com/isubasti>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
import { Mark, Node, Block, Change, Schema, Value, Stack } from 'slate';
import * as Immutable from 'immutable';
import * as React from 'react';
import { Mark, Node, Change, Schema, Value, Stack, Document } from "slate";
import * as Immutable from "immutable";
import * as React from "react";
// Values prefixed with "data-..." (Used for spellchecking according to docs)
export interface RenderAttributes {
[key: string]: any;
[key: string]: any;
}
export interface RenderMarkProps {
attributes: RenderAttributes;
children: React.ReactNode;
editor: Editor;
mark: Mark;
marks: Immutable.Set<Mark>;
node: Node;
offset: number;
text: string;
attributes: RenderAttributes;
children: React.ReactNode;
editor: Editor;
mark: Mark;
marks: Immutable.Set<Mark>;
node: Node;
offset: number;
text: string;
}
export interface RenderNodeProps {
attributes: RenderAttributes;
children: React.ReactNode;
editor: Editor;
isSelected: boolean;
key: string;
node: Node;
parent: Node;
attributes: RenderAttributes;
children: React.ReactNode;
editor: Editor;
isSelected: boolean;
key: string;
node: Node;
parent: Node;
}
export interface Plugin {
onBeforeInput?: (event: Event, change: Change, editor: Editor) => Change | void;
onBlur?: (event: Event, change: Change, editor: Editor) => Change | void;
onFocus?: (event: Event, change: Change, editor: Editor) => Change | void;
onClick?: (event: Event, change: Change, editor: Editor) => Change | void;
onCopy?: (event: Event, change: Change, editor: Editor) => Change | void;
onCut?: (event: Event, change: Change, editor: Editor) => Change | void;
onDrop?: (event: Event, change: Change, editor: Editor) => Change | void;
onKeyDown?: (event: Event, change: Change, editor: Editor) => Change | void;
onKeyUp?: (event: Event, change: Change, editor: Editor) => Change | void;
onPaste?: (event: Event, change: Change, editor: Editor) => Change | void;
onSelect?: (event: Event, change: Change, editor: Editor) => Change | void;
onChange?: (change: Change) => any;
renderEditor?: (props: RenderAttributes, editor: Editor) => object | void;
schema?: Schema;
decorateNode?: (node: Node) => Range[] | void;
renderMark?: (props: RenderMarkProps) => any;
renderNode?: (props: RenderNodeProps) => any;
renderPlaceholder?: (props: RenderAttributes) => any;
renderPortal?: (props: RenderAttributes) => any;
validateNode?: (node: Node) => any;
onBeforeInput?: (
event: Event,
change: Change,
editor: Editor
) => Change | void;
onBlur?: (event: Event, change: Change, editor?: Editor) => Change | void;
onFocus?: (event: Event, change: Change, editor?: Editor) => Change | void;
onClick?: (event: Event, change: Change, editor?: Editor) => Change | void;
onCopy?: (event: Event, change: Change, editor?: Editor) => Change | void;
onCut?: (event: Event, change: Change, editor?: Editor) => Change | void;
onDragEnd?: (
event: Event,
change: Change,
editor?: Editor
) => Change | void;
onDragEnter?: (
event: Event,
change: Change,
editor?: Editor
) => Change | void;
onDragExit?: (
event: Event,
change: Change,
editor?: Editor
) => Change | void;
onDragLeave?: (
event: Event,
change: Change,
editor?: Editor
) => Change | void;
onDragOver?: (
event: Event,
change: Change,
editor?: Editor
) => Change | void;
onDragStart?: (
event: Event,
change: Change,
editor?: Editor
) => Change | void;
onDrop?: (event: Event, change: Change, editor?: Editor) => Change | void;
onInput?: (event: Event, change: Change, editor?: Editor) => Change | void;
onKeyDown?: (
event: Event,
change: Change,
editor?: Editor
) => Change | void;
onKeyUp?: (event: Event, change: Change, editor?: Editor) => Change | void;
onPaste?: (event: Event, change: Change, editor?: Editor) => Change | void;
onSelect?: (event: Event, change: Change, editor?: Editor) => Change | void;
onChange?: (change: Change, editor?: Editor) => any;
renderEditor?: (props: RenderAttributes, editor?: Editor) => object | void;
schema?: Schema;
decorateNode?: (node: Node) => Range[] | void;
renderMark?: (props: RenderMarkProps) => any;
renderNode?: (props: RenderNodeProps) => any;
renderPlaceholder?: (props: RenderAttributes) => any;
renderPortal?: (props: RenderAttributes) => any;
validateNode?: (node: Node) => any;
}
export interface BasicEditorProps {
value: Value;
autoCorrect?: boolean;
autoFocus?: boolean;
className?: string;
onChange?: (change: Change) => any;
placeholder?: any;
plugins?: Plugin[];
readOnly?: boolean;
role?: string;
schema?: Schema;
spellCheck?: boolean;
style?: { [key: string]: string };
tabIndex?: number;
value: Value;
autoCorrect?: boolean;
autoFocus?: boolean;
className?: string;
onChange?: (change: Change) => any;
placeholder?: any;
plugins?: Plugin[];
readOnly?: boolean;
role?: string;
schema?: Schema;
spellCheck?: boolean;
style?: React.CSSProperties;
tabIndex?: number;
}
// tsling:disable interface-over-type-literal
export type EditorProps = BasicEditorProps & Plugin;
export interface EditorState {
schema: Schema;
value: Value;
stack: Stack; // [TODO] define stack
schema: Schema;
value: Value;
stack: Stack; // [TODO] define stack
}
export class Editor extends React.Component<EditorProps, EditorState> {
schema: Schema;
value: Value;
stack: Stack;
schema: Schema;
value: Value;
stack: Stack;
// Instance Methods
blur(): void;
change(fn: (change: Change) => any): void;
change(...args: any[]): void;
focus(): void;
readonly plugins: Plugin[];
// Instance Methods
blur(): void;
change(fn: (change: Change) => any): void;
change(...args: any[]): void;
focus(): void;
}
export type SlateType = 'fragment' | 'html' | 'node' | 'rich' | 'text' | 'files';
export type SlateType =
| "fragment"
| "html"
| "node"
| "rich"
| "text"
| "files";
export function findDOMNode(node: Node): Element;
export function findDOMRange(range: Range): Range;
export function cloneFragment(
event: Event,
value: Value,
fragment?: Document,
callback?: () => void
): void;
export function findDOMNode(node: Node, win?: Window): Element;
export function findDOMRange(range: Range, win?: Window): Range;
export function findNode(element: Element, value: Value): Node;
export function findRange(selection: Selection, value: Value): Range;
export function getEventRange(event: Event, value: Value): Range;
export function getEventTransfer(event: Event): { type: SlateType; node: Node };
export function setEventTransfer(event: Event, type: SlateType, data: any): void;
export function setEventTransfer(
event: Event,
type: SlateType,
data: any
): void;

1929
types/slate/index.d.ts vendored

File diff suppressed because it is too large Load Diff

View File

@@ -1,39 +1,39 @@
import { Value, Data, NodeJSON, Document } from "slate";
import { Value, Data, BlockJSON, Document } from "slate";
const data = Data.create({ foo: "bar "});
const data = Data.create({ foo: "bar " });
const value = Value.create({ data });
const change = value.change()
.focus()
.selectAll()
.delete()
.insertText('A bit of rich text, followed by...')
.moveOffsetsTo(10, 14)
.addMark('bold')
.collapseToEndOfNextBlock()
.insertBlock({
type: 'image',
isVoid: true,
data: {
src: 'http://placekitten.com/200/300',
alt: 'Kittens',
className: 'img-responsive',
},
})
.insertBlock('paragraph');
const change = value
.change()
.focus()
.moveAnchorToStartOfDocument()
.moveFocusToEndOfDocument()
.delete()
.insertText("A bit of rich text, followed by...")
.moveToStartOfText()
.move(10)
.moveFocusForward(4)
.addMark("bold")
.moveToEndOfNextBlock()
.insertBlock({
type: "image",
data: {
src: "http://placekitten.com/200/300",
alt: "Kittens",
className: "img-responsive"
}
})
.insertBlock("paragraph");
const node: NodeJSON = {
const node: BlockJSON = {
object: "block",
type: "paragraph",
isVoid: false,
data: {},
nodes: [
{
object: "text",
leaves: [
{
object: 'leaf',
text: "example",
marks: [],
marks: []
}
]
}
@@ -43,7 +43,5 @@ const node: NodeJSON = {
const doc = Document.fromJSON({
object: "document",
data: {},
nodes: [
node
],
nodes: [node]
});