[@types/slate] Update for version 0.47 (#37076)

* [@types/slate] Update for version 0.47

* [@types/slate-react] Changes Immutable import to just Immutable.List

* Move `rules` property from `Rules` interface to `SchemaProperties` interface

* Fix definitions in slate-react
This commit is contained in:
kay delaney 2019-08-02 18:59:20 +01:00 committed by Jesse Trinity
parent 3ca8c5d6ac
commit 8a51de6c03
4 changed files with 1358 additions and 681 deletions

View File

@ -10,48 +10,72 @@
// Francesco Agnoletto <https://github.com/Kornil>
// Jack Allen <https://github.com/jackall3n>
// Benjamin Evenson <https://github.com/benjiro>
// Kay Delaney <https://github.com/kaydelaney>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
import {
Document,
Editor as CoreEditor,
Mark,
Node,
Node as SlateNode,
Block,
Inline,
Operations,
Operation,
SchemaProperties,
Value,
Operation,
MarkProperties,
BlockProperties,
InlineProperties,
Path,
RangeProperties,
NodeProperties,
Range,
Controller,
Plugin as CorePlugin
} from "slate";
import * as Immutable from "immutable";
import * as React from "react";
Plugin as CorePlugin,
Range as SlateRange,
Selection as SlateSelection,
RangeType,
Annotation,
Decoration,
PointProperties,
PointJSON,
Point,
RangeTypeJSON,
RangeTypeProperties,
} 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;
}
export interface RenderMarkProps {
export interface RenderProps {
attributes: RenderAttributes;
children: React.ReactNode;
editor: Editor;
mark: Mark;
marks: Immutable.Set<Mark>;
node: Node;
annotations: Immutable.List<Annotation> | ReadonlyArray<Annotation>;
decorations: Immutable.List<Decoration> | ReadonlyArray<Annotation>;
node: SlateNode;
offset: number;
text: string;
}
export interface RenderMarkProps extends RenderProps {
mark: Mark;
children: React.ReactNode;
}
export interface RenderAnnotationProps extends RenderProps {
annotation: Annotation;
children: React.ReactNode;
}
export interface RenderDecorationProps extends RenderProps {
decoration: Decoration;
children: React.ReactNode;
}
export interface RenderNodeProps {
attributes: RenderAttributes;
children: React.ReactNode;
@ -59,7 +83,7 @@ export interface RenderNodeProps {
isFocused: boolean;
isSelected: boolean;
key: string;
parent: Node;
parent: SlateNode;
readOnly: boolean;
}
@ -75,20 +99,24 @@ export interface RenderInlineProps extends RenderNodeProps {
node: Inline;
}
export type EventHook = (
event: Event,
editor: CoreEditor,
next: () => any
) => any;
export type EventHook = (event: Event, editor: CoreEditor, next: () => any) => any;
export interface Plugin extends CorePlugin {
decorateNode?: (node: Node, editor: CoreEditor, next: () => any) => any;
renderEditor?: (props: EditorProps, editor: CoreEditor, next: () => any) => any;
renderMark?: (props: RenderMarkProps, editor: CoreEditor, next: () => any) => any;
decorateNode?: (node: SlateNode, editor: CoreEditor, next: () => any) => any;
renderAnnotation?: (props: RenderAnnotationProps, editor: CoreEditor, next: () => any) => any;
renderBlock?: (props: RenderBlockProps, editor: CoreEditor, next: () => any) => any;
renderDecoration?: (props: RenderDecorationProps, editor: CoreEditor, next: () => any) => any;
renderDocument?: (props: RenderDocumentProps, editor: CoreEditor, next: () => any) => any;
renderEditor?: (props: EditorProps, editor: CoreEditor, next: () => any) => any;
renderInline?: (props: RenderInlineProps, editor: CoreEditor, next: () => any) => any;
shouldNodeComponentUpdate?: (previousProps: RenderNodeProps, props: RenderNodeProps, editor: CoreEditor, next: () => any) => any;
renderMark?: (props: RenderMarkProps, editor: CoreEditor, next: () => any) => any;
shouldNodeComponentUpdate?: (
previousProps: RenderNodeProps,
props: RenderNodeProps,
editor: CoreEditor,
next: () => any
) => any;
onBeforeInput?: EventHook;
onBlur?: EventHook;
@ -154,16 +182,30 @@ export class Editor extends React.Component<EditorProps, EditorState> implements
resolveController(plugins: Plugin[], schema: SchemaProperties, commands: any[], queries: any[]): void;
// Controller
addAnnotation: CoreEditor['addAnnotation'];
addMark: CoreEditor['addMark'];
addMarks: CoreEditor['addMarks'];
delete: CoreEditor['delete'];
deleteBackward: CoreEditor['deleteBackward'];
deleteCharBackward: CoreEditor['deleteCharBackward'];
deleteCharForward: CoreEditor['deleteCharForward'];
deleteForward: CoreEditor['deleteForward'];
deleteLineBackward: CoreEditor['deleteLineBackward'];
deleteLineForward: CoreEditor['deleteLineForward'];
deleteWordBackward: CoreEditor['deleteWordBackward'];
deleteWordForward: CoreEditor['deleteWordForward'];
insertBlock: CoreEditor['insertBlock'];
insertFragment: CoreEditor['insertFragment'];
insertInline: CoreEditor['insertInline'];
insertText: CoreEditor['insertText'];
setAnchor: CoreEditor['setAnchor'];
setAnnotation: CoreEditor['setAnnotation'];
setBlocks: CoreEditor['setBlocks'];
setData: CoreEditor['setData'];
setEnd: CoreEditor['setEnd'];
setFocus: CoreEditor['setFocus'];
setInlines: CoreEditor['setInlines'];
setStart: CoreEditor['setStart'];
splitBlock: CoreEditor['splitBlock'];
splitInline: CoreEditor['splitInline'];
removeMark: CoreEditor['removeMark'];
@ -178,6 +220,7 @@ export class Editor extends React.Component<EditorProps, EditorState> implements
deselect: CoreEditor['deselect'];
flip: CoreEditor['flip'];
focus: CoreEditor['focus'];
moveAnchorBackward: CoreEditor['moveAnchorBackward'];
moveAnchorForward: CoreEditor['moveAnchorForward'];
moveAnchorTo: CoreEditor['moveAnchorTo'];
@ -187,7 +230,7 @@ export class Editor extends React.Component<EditorProps, EditorState> implements
moveAnchorToEndOfNextBlock: CoreEditor['moveAnchorToEndOfNextBlock'];
moveAnchorToEndOfNextInline: CoreEditor['moveAnchorToEndOfNextInline'];
moveAnchorToEndOfNextText: CoreEditor['moveAnchorToEndOfNextText'];
moveAnchorEndOfNode: CoreEditor['moveAnchorEndOfNode'];
moveAnchorToEndOfNode: CoreEditor['moveAnchorToEndOfNode'];
moveAnchorToEndOfPreviousBlock: CoreEditor['moveAnchorToEndOfPreviousBlock'];
moveAnchorToEndOfPreviousInline: CoreEditor['moveAnchorToEndOfPreviousInline'];
moveAnchorToEndOfPreviousText: CoreEditor['moveAnchorToEndOfPreviousText'];
@ -203,6 +246,9 @@ export class Editor extends React.Component<EditorProps, EditorState> implements
moveAnchorToStartOfPreviousInline: CoreEditor['moveAnchorToStartOfPreviousInline'];
moveAnchorToStartOfPreviousText: CoreEditor['moveAnchorToStartOfPreviousText'];
moveAnchorToStartOfText: CoreEditor['moveAnchorToStartOfText'];
moveAnchorWordBackward: CoreEditor['moveAnchorWordBackward'];
moveAnchorWordForward: CoreEditor['moveAnchorWordForward'];
moveBackward: CoreEditor['moveBackward'];
moveEndBackward: CoreEditor['moveEndBackward'];
moveEndForward: CoreEditor['moveEndForward'];
moveEndTo: CoreEditor['moveEndTo'];
@ -228,6 +274,8 @@ export class Editor extends React.Component<EditorProps, EditorState> implements
moveEndToStartOfPreviousInline: CoreEditor['moveEndToStartOfPreviousInline'];
moveEndToStartOfPreviousText: CoreEditor['moveEndToStartOfPreviousText'];
moveEndToStartOfText: CoreEditor['moveEndToStartOfText'];
moveEndWordBackward: CoreEditor['moveEndWordBackward'];
moveEndWordForward: CoreEditor['moveEndWordForward'];
moveFocusBackward: CoreEditor['moveFocusBackward'];
moveFocusForward: CoreEditor['moveFocusForward'];
moveFocusTo: CoreEditor['moveFocusTo'];
@ -253,6 +301,9 @@ export class Editor extends React.Component<EditorProps, EditorState> implements
moveFocusToStartOfPreviousInline: CoreEditor['moveFocusToStartOfPreviousInline'];
moveFocusToStartOfPreviousText: CoreEditor['moveFocusToStartOfPreviousText'];
moveFocusToStartOfText: CoreEditor['moveFocusToStartOfText'];
moveFocusWordBackward: CoreEditor['moveFocusWordBackward'];
moveFocusWordForward: CoreEditor['moveFocusWordForward'];
moveForward: CoreEditor['moveForward'];
moveStartForward: CoreEditor['moveStartForward'];
moveStartBackward: CoreEditor['moveStartBackward'];
moveStartTo: CoreEditor['moveStartTo'];
@ -278,12 +329,10 @@ export class Editor extends React.Component<EditorProps, EditorState> implements
moveStartToStartOfPreviousInline: CoreEditor['moveStartToStartOfPreviousInline'];
moveStartToStartOfPreviousText: CoreEditor['moveStartToStartOfPreviousText'];
moveStartToStartOfText: CoreEditor['moveStartToStartOfText'];
moveBackward: CoreEditor['moveBackward'];
moveForward: CoreEditor['moveForward'];
moveStartWordBackward: CoreEditor['moveStartWordBackward'];
moveStartWordForward: CoreEditor['moveStartWordForward'];
moveTo: CoreEditor['moveTo'];
moveToAnchor: CoreEditor['moveToAnchor'];
moveToFocus: CoreEditor['moveToFocus'];
moveToStart: CoreEditor['moveToStart'];
moveToEnd: CoreEditor['moveToEnd'];
moveToEndOfBlock: CoreEditor['moveToEndOfBlock'];
moveToEndOfDocument: CoreEditor['moveToEndOfDocument'];
@ -296,6 +345,10 @@ export class Editor extends React.Component<EditorProps, EditorState> implements
moveToEndOfPreviousInline: CoreEditor['moveToEndOfPreviousInline'];
moveToEndOfPreviousText: CoreEditor['moveToEndOfPreviousText'];
moveToEndOfText: CoreEditor['moveToEndOfText'];
moveToFocus: CoreEditor['moveToFocus'];
moveToRangeOfDocument: CoreEditor['moveToRangeOfDocument'];
moveToRangeOfNode: CoreEditor['moveToRangeOfNode'];
moveToStart: CoreEditor['moveToStart'];
moveToStartOfBlock: CoreEditor['moveToStartOfBlock'];
moveToStartOfDocument: CoreEditor['moveToStartOfDocument'];
moveToStartOfInline: CoreEditor['moveToStartOfInline'];
@ -307,36 +360,41 @@ export class Editor extends React.Component<EditorProps, EditorState> implements
moveToStartOfPreviousInline: CoreEditor['moveToStartOfPreviousInline'];
moveToStartOfPreviousText: CoreEditor['moveToStartOfPreviousText'];
moveToStartOfText: CoreEditor['moveToStartOfText'];
moveToRangeOfDocument: CoreEditor['moveToRangeOfDocument'];
moveToRangeOfNode: CoreEditor['moveToRangeOfNode'];
moveWordBackward: CoreEditor['moveWordBackward'];
moveWordForward: CoreEditor['moveWordForward'];
save: CoreEditor['save'];
select: CoreEditor['select'];
addMarkAtRange: CoreEditor['addMarkAtRange'];
addMarksAtRange: CoreEditor['addMarksAtRange'];
deleteAtRange: CoreEditor['deleteAtRange'];
deleteCharBackwardAtRange: CoreEditor['deleteCharBackwardAtRange'];
deleteLineBackwardAtRange: CoreEditor['deleteLineBackwardAtRange'];
deleteWordBackwardAtRange: CoreEditor['deleteWordBackwardAtRange'];
deleteBackwardAtRange: CoreEditor['deleteBackwardAtRange'];
deleteCharBackwardAtRange: CoreEditor['deleteCharBackwardAtRange'];
deleteCharForwardAtRange: CoreEditor['deleteCharForwardAtRange'];
deleteLineForwardAtRange: CoreEditor['deleteLineForwardAtRange'];
deleteWordForwardAtRange: CoreEditor['deleteWordForwardAtRange'];
deleteForwardAtRange: CoreEditor['deleteForwardAtRange'];
deleteLineBackwardAtRange: CoreEditor['deleteLineBackwardAtRange'];
deleteLineForwardAtRange: CoreEditor['deleteLineForwardAtRange'];
deleteWordBackwardAtRange: CoreEditor['deleteWordBackwardAtRange'];
deleteWordForwardAtRange: CoreEditor['deleteWordForwardAtRange'];
insertBlockAtRange: CoreEditor['insertBlockAtRange'];
insertFragmentAtRange: CoreEditor['insertFragmentAtRange'];
insertInlineAtRange: CoreEditor['insertInlineAtRange'];
insertTextAtRange: CoreEditor['insertTextAtRange'];
removeMarkAtRange: CoreEditor['removeMarkAtRange'];
setBlocksAtRange: CoreEditor['setBlocksAtRange'];
setInlinesAtRange: CoreEditor['setInlinesAtRange'];
splitBlockAtRange: CoreEditor['splitBlockAtRange'];
splitInlineAtRange: CoreEditor['splitInlineAtRange'];
removeMarkAtRange: CoreEditor['removeMarkAtRange'];
toggleMarkAtRange: CoreEditor['toggleMarkAtRange'];
unwrapBlockAtRange: CoreEditor['unwrapBlockAtRange'];
unwrapInlineAtRange: CoreEditor['unwrapInlineAtRange'];
wrapBlockAtRange: CoreEditor['wrapBlockAtRange'];
wrapInlineAtRange: CoreEditor['wrapInlineAtRange'];
wrapTextAtRange: CoreEditor['wrapTextAtRange'];
addMarkByKey: CoreEditor['addMarkByKey'];
addMarkByPath: CoreEditor['addMarkByPath'];
addMarksByPath: CoreEditor['addMarksByPath'];
insertNodeByKey: CoreEditor['insertNodeByKey'];
insertNodeByPath: CoreEditor['insertNodeByPath'];
insertFragmentByKey: CoreEditor['insertFragmentByKey'];
@ -347,33 +405,44 @@ export class Editor extends React.Component<EditorProps, EditorState> implements
mergeNodeByPath: CoreEditor['mergeNodeByPath'];
moveNodeByKey: CoreEditor['moveNodeByKey'];
moveNodeByPath: CoreEditor['moveNodeByPath'];
removeAllMarksByKey: CoreEditor['removeAllMarksByKey'];
removeAllMarksByPath: CoreEditor['removeAllMarksByPath'];
removeMarkByKey: CoreEditor['removeMarkByKey'];
removeMarkByPath: CoreEditor['removeMarkByPath'];
removeMarksByPath: CoreEditor['removeMarksByPath'];
removeNodeByKey: CoreEditor['removeNodeByKey'];
removeNodeByPath: CoreEditor['removeNodeByPath'];
replaceNodeByKey: CoreEditor['replaceNodeByKey'];
replaceNodeByPath: CoreEditor['replaceNodeByPath'];
removeTextByKey: CoreEditor['removeTextByKey'];
removeTextByPath: CoreEditor['removeTextByPath'];
setDecorations: CoreEditor['setDecorations'];
replaceNodeByKey: CoreEditor['replaceNodeByKey'];
replaceNodeByPath: CoreEditor['replaceNodeByPath'];
replaceTextByKey: CoreEditor['replaceTextByKey'];
replaceTextByPath: CoreEditor['replaceTextByPath'];
setMarkByKey: CoreEditor['setMarkByKey'];
setMarksByPath: CoreEditor['setMarksByPath'];
setMarkByPath: CoreEditor['setMarkByPath'];
setNodeByKey: CoreEditor['setNodeByKey'];
setNodeByPath: CoreEditor['setNodeByPath'];
setTextByKey: CoreEditor['setTextByKey'];
setTextByPath: CoreEditor['setTextByPath'];
splitDescendantsByKey: CoreEditor['splitDescendantsByKey'];
splitDescendantsByPath: CoreEditor['splitDescendantsByPath'];
splitNodeByKey: CoreEditor['splitNodeByKey'];
splitNodeByPath: CoreEditor['splitNodeByPath'];
unwrapInlineByKey: CoreEditor['unwrapInlineByKey'];
unwrapInlineByPath: CoreEditor['unwrapInlineByPath'];
unwrapBlockByKey: CoreEditor['unwrapBlockByKey'];
unwrapBlockByPath: CoreEditor['unwrapBlockByPath'];
unwrapChildrenByKey: CoreEditor['unwrapChildrenByKey'];
unwrapChildrenByPath: CoreEditor['unwrapChildrenByPath'];
unwrapInlineByKey: CoreEditor['unwrapInlineByKey'];
unwrapInlineByPath: CoreEditor['unwrapInlineByPath'];
unwrapNodeByKey: CoreEditor['unwrapNodeByKey'];
unwrapNodeByPath: CoreEditor['unwrapNodeByPath'];
wrapInlineByKey: CoreEditor['wrapInlineByKey'];
wrapInlineByPath: CoreEditor['wrapInlineByPath'];
wrapBlockByKey: CoreEditor['wrapBlockByKey'];
wrapBlockByPath: CoreEditor['wrapBlockByPath'];
wrapInlineByKey: CoreEditor['wrapInlineByKey'];
wrapInlineByPath: CoreEditor['wrapInlineByPath'];
wrapNodeByKey: CoreEditor['wrapNodeByKey'];
wrapNodeByPath: CoreEditor['wrapNodeByPath'];
normalize: CoreEditor['normalize'];
withoutNormalizing: CoreEditor['withoutNormalizing'];
withoutSaving: CoreEditor['withoutSaving'];
@ -387,21 +456,32 @@ export class Editor extends React.Component<EditorProps, EditorState> implements
registerQuery: CoreEditor['registerQuery'];
applyOperation: CoreEditor['applyOperation'];
run: CoreEditor['run'];
removeAnnotation: CoreEditor['removeAnnotation'];
findDOMNode: (path: Immutable.List<number> | number[]) => React.ReactNode | null;
findDOMPoint: (point: PointProperties | PointJSON | Point) => { node: Node; offset: number } | null;
findDOMRange: (range: RangeTypeProperties | RangeTypeJSON | RangeType) => Range | null;
findNode: (element: Element) => SlateNode | null;
findEventRange: (event: Event | React.SyntheticEvent) => SlateRange | null;
findPath: (element: Element) => Immutable.List<number> | null;
findPoint: (nativeNode: Element, nativeOffset: number) => Point | null;
findRange: (domRange: Range | Selection) => SlateRange | null;
findSelection: (domSelection: Selection) => SlateSelection | null;
}
export type SlateType =
| "fragment"
| "html"
| "node"
| "rich"
| "text"
| "files";
export type SlateType = 'fragment' | 'html' | 'node' | 'rich' | 'text' | 'files';
// Utilities
export function cloneFragment(event: Event | React.SyntheticEvent, editor: CoreEditor, callback?: () => void): void;
export function findDOMNode(node: Node, win?: Window): Element;
export function findDOMRange(range: Range, win?: Window): Range;
export function findNode(element: Element, editor: CoreEditor): Node;
export function findRange(selection: Selection | Range, editor: CoreEditor): Range;
export function getEventRange(event: Event | React.SyntheticEvent, editor: CoreEditor): Range;
export function getEventTransfer(event: Event | React.SyntheticEvent): { type: SlateType; node: Node };
export function getEventTransfer(event: Event | React.SyntheticEvent): { type: SlateType; node: SlateNode };
export function setEventTransfer(event: Event | React.SyntheticEvent, type: SlateType, data: any): void;
// Deprecated
export function findDOMNode(node: SlateNode | string, win?: Window): Element;
export function findDOMPoint(point: Point, win?: Window): { node: Node; offset: number } | null;
export function findDOMRange(range: RangeTypeProperties | RangeTypeJSON | RangeType, win?: Window): Range | null;
export function findNode(element: Element, editor: CoreEditor): SlateNode;
export function findPath(element: Element, editor: CoreEditor): Immutable.List<number> | null;
export function findPoint(nativeNode: Element, nativeOffset: number, editor: CoreEditor): Point | null;
export function findRange(domRange: Range | Selection, editor: CoreEditor): SlateRange | null;
export function getEventRange(event: Event | React.SyntheticEvent, editor: CoreEditor): SlateRange | null;

View File

@ -1,6 +1,7 @@
import { Editor, Plugin, EditorProps, OnChangeFn, RenderBlockProps, RenderInlineProps } from 'slate-react';
import { Value, Editor as Controller, Point, Range, Inline, Mark, Document, Decoration } from 'slate';
import { Value, Editor as Controller, Point, Range, Inline, Mark, Document, Decoration, Operation } from 'slate';
import * as React from "react";
import { List } from "immutable";
class MyPlugin implements Plugin {
renderBlock(props: RenderBlockProps, editor: Controller, next: () => void) {
@ -25,8 +26,9 @@ class MyPlugin implements Plugin {
}
}
}
onChange: OnChangeFn = ({ operations, value }) => {
console.log(operations, value);
onChange = (change: { operations: List<Operation>, value: Value }) => {
console.log(change.operations, change.value);
}
}
@ -64,7 +66,7 @@ const point = Point.create({ key: "a", offset: 0 });
const range = Range.create({ anchor: point, focus: point });
const inline = Inline.create("text");
const mark = Mark.create("bold");
const decorations = Decoration.createList([{ anchor: Point.create({ key: "a", offset: 0 }), focus: Point.create({ key: "a", offset: 0 }), mark }]);
const decorations = Decoration.createList([{ anchor: Point.create({ key: "a", offset: 0 }), focus: Point.create({ key: "a", offset: 0 }) }]);
const doc = Document.fromJSON({
object: "document",
@ -76,7 +78,7 @@ editor
.addMark("bold")
.addMarkAtRange(range, "italic")
.addMarkByKey("a", 0, 1, "bold")
.addMarkByPath("a", 0, 1, "bold")
.addMarkByPath(List([0]), 0, 1, "bold")
.blur()
.delete()
.deleteAtRange(range)
@ -106,19 +108,19 @@ editor
.insertFragment(doc)
.insertFragmentAtRange(range, doc)
.insertFragmentByKey("a", 0, doc)
.insertFragmentByPath("a", 0, doc)
.insertFragmentByPath(List([0]), 0, doc)
.insertInline(inline)
.insertInlineAtRange(range, inline)
.insertNodeByKey("a", 0, inline)
.insertNodeByPath("a", 0, inline)
.insertNodeByPath(List([0]), 0, inline)
.insertText("A bit of rich text, followed by...")
.insertTextAtRange(range, "More text")
.insertTextByKey("a", 0, "text")
.insertTextByPath("a", 0, "text")
.insertTextByPath(List([0]), 0, "text")
.mergeNodeByKey("b")
.mergeNodeByPath("b")
.mergeNodeByPath(List([0]))
.moveAnchorBackward()
.moveAnchorEndOfNode(inline)
.moveAnchorToEndOfNode(inline)
.moveAnchorForward()
.moveAnchorTo("a", 0)
.moveAnchorToEndOfBlock()
@ -195,7 +197,7 @@ editor
.moveFocusToStartOfText()
.moveForward()
.moveNodeByKey("b", "c", 2)
.moveNodeByPath("c", "b", 1)
.moveNodeByPath(List([1]), List([2]), 1)
.moveStartBackward()
.moveStartForward()
.moveStartTo("a", 0)
@ -255,31 +257,29 @@ editor
.removeMark("bold")
.removeMarkAtRange(range, "bold")
.removeMarkByKey("a", 0, 1, "bold")
.removeMarkByPath("a", 0, 1, "bold")
.removeMarkByPath(List([0]), 0, 1, "bold")
.removeNodeByKey("b")
.removeNodeByPath("b")
.removeNodeByPath(List([0]))
.removeTextByKey("a", 0, 1)
.removeTextByPath("a", 0, 1)
.removeTextByPath(List([0]), 0, 1)
.replaceMark("bold", "italic")
.replaceNodeByKey("a", inline)
.replaceNodeByPath("a", inline)
.replaceNodeByPath(List([0]), inline)
.select(range)
.setDecorations(decorations)
.setBlocks("paragraph")
.setBlocksAtRange(range, "paragraph")
.setInlines("paragraph")
.setInlinesAtRange(range, "paragraph")
.setMarkByKey("a", 0, 1, mark, { type: "bold" })
.setMarksByPath("a", 0, 1, mark, { type: "bold" })
.setNodeByKey("a", "paragraph")
.setNodeByPath("a", "paragraph")
.setNodeByPath(List([0]), "paragraph")
.snapshotSelection()
.splitBlock(0)
.splitBlockAtRange(range, 0)
.splitInline(0)
.splitInlineAtRange(range, 0)
.splitNodeByKey("a", 0)
.splitNodeByPath("a", 0)
.splitNodeByPath(List([0]), 0)
.toggleMark("bold")
.toggleMarkAtRange(range, "bold")
.undo()
@ -292,19 +292,20 @@ editor
.unwrapInlineByKey("a", "paragraph")
.unwrapInlineByPath("a", "paragraph")
.unwrapNodeByKey("a")
.unwrapNodeByPath("a")
.withoutMerging(() => { /* noop */ })
.withoutNormalizing(() => { /* noop */ })
.withoutSaving(() => { /* noop */ })
.unwrapNodeByPath(List([0]))
.wrapBlock("paragraph")
.wrapBlockAtRange(range, "paragraph")
.wrapBlockByKey("a", "paragraph")
.wrapBlockByPath("a", "paragraph")
.wrapBlockByPath(List([0]), "paragraph")
.wrapInline("paragraph")
.wrapInlineAtRange(range, "paragraph")
.wrapInlineByKey("a", "paragraph")
.wrapInlineByPath("a", "paragraph")
.wrapInlineByPath(List([0]), "paragraph")
.wrapNodeByKey("a", inline)
.wrapNodeByPath("a", inline)
.wrapNodeByPath(List([0]), inline)
.wrapText("a", "b")
.wrapTextAtRange(range, "a");
editor.withoutMerging(() => { /* noop */ });
editor.withoutNormalizing(() => { /* noop */ });
editor.withoutSaving(() => { /* noop */ });

1664
types/slate/index.d.ts vendored

File diff suppressed because it is too large Load Diff

View File

@ -16,8 +16,10 @@ import {
Node,
Command,
Query,
Decoration
Decoration,
Annotation
} from "slate";
import { List } from "immutable";
const data = Data.create({ foo: "bar " });
const value = Value.create({ data });
@ -28,18 +30,13 @@ const node: BlockJSON = {
nodes: [
{
object: "text",
key: "a",
leaves: [
{
object: "leaf",
text: "example",
marks: [{
data: { testData: "data"},
type: "mark",
object: "mark"
}]
}
]
key: "a",
text: "example",
marks: [{
data: { testData: "data"},
type: "mark",
object: "mark"
}]
}
]
};
@ -121,7 +118,8 @@ const point = Point.create({ key: "a", offset: 0 });
const range = Range.create({ anchor: point, focus: point });
const inline = Inline.create("text");
const mark = Mark.create("bold");
const decorations = Decoration.createList([{ anchor: Point.create({ key: "a", offset: 0 }), focus: Point.create({ key: "a", offset: 0 }), mark }]);
const decorations = Decoration.createList([{ anchor: Point.create({ key: "a", offset: 0 }), focus: Point.create({ key: "a", offset: 0 }), type: mark.type, data: mark.data }]);
const annotations = Annotation.createMap({ a: Annotation.create({ key: "a", type: "leaf", data: { foo: "bar "} })});
editor.command(pluginCommandName, 1);
editor.command(pluginCommandFunc, 1);
@ -137,10 +135,14 @@ editor.run("testCommand");
// Test all editor commands
editor
.addAnnotation({ key: 'a', type: 'leaf'})
.addMark("bold")
.addMarkAtRange(range, "italic")
.addMarkByKey("a", 0, 1, "bold")
.addMarkByPath("a", 0, 1, "bold")
.addMarkByPath(List([0]), 0, 1, "bold")
.addMarks(["bold", "italic"])
.addMarksAtRange(range, ["bold", "italic"])
.addMarksByPath(List([0]), 0, 1, ["bold", "italic"])
.blur()
.delete()
.deleteAtRange(range)
@ -171,19 +173,19 @@ editor
.insertFragment(doc)
.insertFragmentAtRange(range, doc)
.insertFragmentByKey("a", 0, doc)
.insertFragmentByPath("a", 0, doc)
.insertFragmentByPath(List([0]), 0, doc)
.insertInline(inline)
.insertInlineAtRange(range, inline)
.insertNodeByKey("a", 0, inline)
.insertNodeByPath("a", 0, inline)
.insertNodeByPath(List([0]), 0, inline)
.insertText("A bit of rich text, followed by...")
.insertTextAtRange(range, "More text")
.insertTextByKey("a", 0, "text")
.insertTextByPath("a", 0, "text")
.insertTextByPath(List([0]), 0, "text")
.mergeNodeByKey("b")
.mergeNodeByPath("b")
.mergeNodeByPath(List([0]))
.moveAnchorBackward()
.moveAnchorEndOfNode(inline)
.moveAnchorToEndOfNode(inline)
.moveAnchorForward()
.moveAnchorTo("a", 0)
.moveAnchorToEndOfBlock()
@ -260,7 +262,7 @@ editor
.moveFocusToStartOfText()
.moveForward()
.moveNodeByKey("b", "c", 2)
.moveNodeByPath("c", "b", 1)
.moveNodeByPath(List([0]), List([1]), 1)
.moveStartBackward()
.moveStartForward()
.moveStartTo("a", 0)
@ -317,27 +319,30 @@ editor
.moveToStartOfText()
.normalize()
.redo()
.removeAnnotation({ key: 'a', type: 'leaf'})
.removeAllMarksByKey('a')
.removeAllMarksByPath(List([0]))
.removeMarksByPath(List([0]), 0, 1, ["bold"])
.removeMark("bold")
.removeMarkAtRange(range, "bold")
.removeMarkByKey("a", 0, 1, "bold")
.removeMarkByPath("a", 0, 1, "bold")
.removeMarkByPath(List([1]), 0, 1, "bold")
.removeNodeByKey("b")
.removeNodeByPath("b")
.removeNodeByPath(List([0]))
.removeTextByKey("a", 0, 1)
.removeTextByPath("a", 0, 1)
.removeTextByPath(List([1]), 0, 1)
.replaceMark("bold", "italic")
.replaceNodeByKey("a", inline)
.replaceNodeByPath("a", inline)
.replaceNodeByPath(List([1]), inline)
.select(range)
.setDecorations(decorations)
.setAnnotation(Annotation.create({ key: 'a', type: 'old'}), { key: 'a', type: 'new'})
.setBlocks("paragraph")
.setBlocksAtRange(range, "paragraph")
.setInlines("paragraph")
.setInlinesAtRange(range, "paragraph")
.setMarkByKey("a", 0, 1, mark, { type: "bold" })
.setMarksByPath("a", 0, 1, mark, { type: "bold" })
.setMarkByKey('a', 0, 2, { type: 'bold', data: { thing: 'value' } }, { data: { thing: false } })
.setNodeByKey("a", "paragraph")
.setNodeByPath("a", "paragraph")
.setNodeByPath(List([0]), "paragraph")
.setReadOnly(true)
.setValue(value)
.snapshotSelection()
@ -346,7 +351,7 @@ editor
.splitInline(0)
.splitInlineAtRange(range, 0)
.splitNodeByKey("a", 0)
.splitNodeByPath("a", 0)
.splitNodeByPath(List([0]), 0)
.toggleMark("bold")
.toggleMarkAtRange(range, "bold")
.undo()
@ -359,97 +364,103 @@ editor
.unwrapInlineByKey("a", "paragraph")
.unwrapInlineByPath("a", "paragraph")
.unwrapNodeByKey("a")
.unwrapNodeByPath("a")
.withoutMerging(() => { /* noop */ })
.withoutNormalizing(() => { /* noop */ })
.withoutSaving(() => { /* noop */ })
.unwrapNodeByPath(List([0]))
.wrapBlock("paragraph")
.wrapBlockAtRange(range, "paragraph")
.wrapBlockByKey("a", "paragraph")
.wrapBlockByPath("a", "paragraph")
.wrapBlockByPath(List([0]), "paragraph")
.wrapInline("paragraph")
.wrapInlineAtRange(range, "paragraph")
.wrapInlineByKey("a", "paragraph")
.wrapInlineByPath("a", "paragraph")
.wrapInlineByPath(List([0]), "paragraph")
.wrapNodeByKey("a", inline)
.wrapNodeByPath("a", inline)
.wrapNodeByPath(List([0]), inline)
.wrapText("a", "b")
.wrapTextAtRange(range, "a")
.applyOperation({
type: "insert_text",
path: 'a',
path: List([0]),
offset: 0,
text: 'text',
marks: [Mark.create({type: 'test_mark'})],
data: Data.create({})
})
.applyOperation({
type: "remove_text",
path: 'a',
path: List([0]),
offset: 0,
text: 'text',
data: Data.create({})
})
.applyOperation({
type: "add_mark",
path: 'a',
offset: 0,
length: 1,
path: List([0]),
mark: Mark.create({type: 'test_mark'}),
data: Data.create({})
})
.applyOperation({
type: "remove_mark",
path: 'a',
offset: 0,
length: 1,
path: List([0]),
mark: Mark.create({type: 'test_mark'}),
data: Data.create({})
})
.applyOperation({
type: "set_mark",
path: 'a',
offset: 0,
length: 1,
path: List([0]),
properties: {type: 'test_mark'},
newProperties: {type: 'new_test_mark'},
data: Data.create({})
})
.applyOperation({
type: "add_annotation",
annotation: Annotation.create({ key: 'a', type: 'test_annotation'}),
data: Data.create({})
})
.applyOperation({
type: "remove_annotation",
annotation: Annotation.create({ key: 'a', type: 'test_annotation'}),
data: Data.create({})
})
.applyOperation({
type: "set_annotation",
properties: { key: 'a', type: 'test_annotation'},
newProperties: { key: 'a', type: 'new_annotation'},
data: Data.create({})
})
.applyOperation({
type: "insert_node",
path: 'a',
path: List([0]),
node: Block.create({type: 'block'}),
data: Data.create({})
})
.applyOperation({
type: "merge_node",
path: 'a',
path: List([0]),
position: 0,
properties: {type: 'node'},
data: Data.create({})
})
.applyOperation({
type: "move_node",
path: 'a',
newPath: 'a',
path: List([0]),
newPath: List([1]),
data: Data.create({})
})
.applyOperation({
type: "remove_node",
path: 'a',
path: List([0]),
node: Block.create({type: 'block'}),
data: Data.create({})
})
.applyOperation({
type: "set_node",
path: 'a',
path: List([0]),
properties: {type: 'node'},
newProperties: {type: 'new_node'},
data: Data.create({})
})
.applyOperation({
type: "split_node",
path: 'a',
path: List([0]),
position: 0,
target: 1,
properties: {type: 'block'},
@ -468,6 +479,10 @@ editor
data: Data.create({})
});
editor.withoutMerging(() => { /* noop */ });
editor.withoutNormalizing(() => { /* noop */ });
editor.withoutSaving(() => { /* noop */ });
KeyUtils.setGenerator(() => "Test");
KeyUtils.create();
KeyUtils.resetGenerator();
@ -496,9 +511,8 @@ PathUtils.relate(pathA, pathB);
PathUtils.transform(pathA, {
type: "insert_text",
path: 'a',
path: List([0]),
offset: 0,
text: 'text',
marks: [Mark.create({type: 'test_mark'})],
data: Data.create({})
});