From c02758953d897827d6cf4601791df85b42cae61b Mon Sep 17 00:00:00 2001 From: Nikolay Martynenko Date: Sat, 6 Apr 2019 23:16:10 +0300 Subject: [PATCH 1/3] Slate operations definition revised --- types/slate/index.d.ts | 50 ++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/types/slate/index.d.ts b/types/slate/index.d.ts index 3d971fa3fa..2d8472565c 100644 --- a/types/slate/index.d.ts +++ b/types/slate/index.d.ts @@ -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 { From 029269a426f727b2239585c100cf4ad9e5b23a93 Mon Sep 17 00:00:00 2001 From: Nikolay Martynenko Date: Sat, 6 Apr 2019 23:50:33 +0300 Subject: [PATCH 2/3] Property 'oprations' added to slate editor --- types/slate/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/slate/index.d.ts b/types/slate/index.d.ts index 2d8472565c..eac4822d6d 100644 --- a/types/slate/index.d.ts +++ b/types/slate/index.d.ts @@ -1014,6 +1014,7 @@ export interface EditorProperties { export class Editor implements Controller { object: "editor"; onChange: (change: { operations: Immutable.List, value: Value }) => void; + operations: Immutable.List; plugins: Plugin[]; readOnly: boolean; value: Value; From 607d9e07585f3a215f11208ddc76912911f034b2 Mon Sep 17 00:00:00 2001 From: Nikolay Martynenko Date: Wed, 10 Apr 2019 15:55:07 +0300 Subject: [PATCH 3/3] Update slate-tests.ts --- types/slate/slate-tests.ts | 96 +++++++++++++++++++++++++++++++++++++- 1 file changed, 94 insertions(+), 2 deletions(-) diff --git a/types/slate/slate-tests.ts b/types/slate/slate-tests.ts index 07a93ca894..98f717b484 100644 --- a/types/slate/slate-tests.ts +++ b/types/slate/slate-tests.ts @@ -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();