Merge pull request #34532 from jerkly/master

Slate operations definition revised
This commit is contained in:
Benjamin Lichtman
2019-04-11 10:48:07 -07:00
committed by GitHub
2 changed files with 128 additions and 19 deletions

View File

@@ -790,91 +790,107 @@ export type Operation =
export interface InsertTextOperation {
type: "insert_text";
path: number[];
path: Path;
offset: number;
text: string;
marks: Mark[];
data: Data;
}
export interface RemoveTextOperation {
type: "remove_text";
path: number[];
path: Path;
offset: number;
text: string;
data: Data;
}
export interface AddMarkOperation {
type: "add_mark";
path: number[];
path: Path;
offset: number;
length: number;
mark: Mark;
data: Data;
}
export interface RemoveMarkOperation {
type: "remove_mark";
path: number[];
path: Path;
offset: number;
length: number;
mark: Mark;
data: Data;
}
export interface SetMarkOperation {
type: "set_mark";
path: number[];
path: Path;
offset: number;
length: number;
mark: Mark;
properties: MarkProperties;
newProperties: MarkProperties;
data: Data;
}
export interface InsertNodeOperation {
type: "insert_node";
path: number[];
path: Path;
node: Node;
data: Data;
}
export interface MergeNodeOperation {
type: "merge_node";
path: number[];
path: Path;
position: number;
properties: NodeProperties;
data: Data;
}
export interface MoveNodeOperation {
type: "move_node";
path: number[];
newPath: number[];
path: Path;
newPath: Path | number[];
data: Data;
}
export interface RemoveNodeOperation {
type: "remove_node";
path: number[];
path: Path;
node: Node;
data: Data;
}
export interface SetNodeOperation {
type: "set_node";
path: number[];
properties: BlockProperties | InlineProperties | TextProperties;
path: Path;
properties: NodeProperties;
newProperties: NodeProperties;
data: Data;
}
export interface SplitNodeOperation {
type: "split_node";
path: number[];
path: Path;
position: number;
target: number;
properties: NodeProperties;
data: Data;
}
export interface SetSelectionOperation {
type: "set_selection";
properties: RangeProperties;
selection: Range;
properties: SelectionProperties;
newProperties: SelectionProperties;
data: Data;
}
export interface SetValueOperation {
type: "set_value";
properties: ValueProperties;
value: Value;
newProperties: ValueProperties;
data: Data;
}
export interface Operations {
@@ -998,6 +1014,7 @@ export interface EditorProperties {
export class Editor implements Controller {
object: "editor";
onChange: (change: { operations: Immutable.List<Operation>, value: Value }) => void;
operations: Immutable.List<Operation>;
plugins: Plugin[];
readOnly: boolean;
value: Value;

View File

@@ -15,7 +15,7 @@ import {
Node,
Command,
Query,
Decoration
Decoration,
} from "slate";
const data = Data.create({ foo: "bar " });
@@ -356,7 +356,99 @@ editor
.wrapNodeByKey("a", inline)
.wrapNodeByPath("a", inline)
.wrapText("a", "b")
.wrapTextAtRange(range, "a");
.wrapTextAtRange(range, "a")
.applyOperation({
type: "insert_text",
path: 'a',
offset: 0,
text: 'text',
marks: [Mark.create({type: 'test_mark'})],
data: Data.create({})
})
.applyOperation({
type: "remove_text",
path: 'a',
offset: 0,
text: 'text',
data: Data.create({})
})
.applyOperation({
type: "add_mark",
path: 'a',
offset: 0,
length: 1,
mark: Mark.create({type: 'test_mark'}),
data: Data.create({})
})
.applyOperation({
type: "remove_mark",
path: 'a',
offset: 0,
length: 1,
mark: Mark.create({type: 'test_mark'}),
data: Data.create({})
})
.applyOperation({
type: "set_mark",
path: 'a',
offset: 0,
length: 1,
properties: {type: 'test_mark'},
newProperties: {type: 'new_test_mark'},
data: Data.create({})
})
.applyOperation({
type: "insert_node",
path: 'a',
node: Block.create({type: 'block'}),
data: Data.create({})
})
.applyOperation({
type: "merge_node",
path: 'a',
position: 0,
properties: {type: 'node'},
data: Data.create({})
})
.applyOperation({
type: "move_node",
path: 'a',
newPath: 'a',
data: Data.create({})
})
.applyOperation({
type: "remove_node",
path: 'a',
node: Block.create({type: 'block'}),
data: Data.create({})
})
.applyOperation({
type: "set_node",
path: 'a',
properties: {type: 'node'},
newProperties: {type: 'new_node'},
data: Data.create({})
})
.applyOperation({
type: "split_node",
path: 'a',
position: 0,
target: 1,
properties: {type: 'block'},
data: Data.create({})
})
.applyOperation({
type: "set_selection",
properties: {},
newProperties: {},
data: Data.create({})
})
.applyOperation({
type: "set_value",
properties: {},
newProperties: {},
data: Data.create({})
});
KeyUtils.setGenerator(() => "Test");
KeyUtils.create();