Operations
Operations are the granular, low-level actions that occur while invoking transforms. A single transform could result in many low-level operations being applied to the editor.
Slate's core defines all of the possible operations that can occur on a richtext document. For example:
1
editor.apply({
2
type: 'insert_text',
3
path: [0, 0],
4
offset: 15,
5
text: 'A new string of text to be inserted.',
6
})
7
8
editor.apply({
9
type: 'remove_node',
10
path: [0, 0],
11
node: {
12
text: 'A line of text!',
13
},
14
})
15
16
editor.apply({
17
type: 'set_selection',
18
properties: {
19
anchor: { path: [0, 0], offset: 0 },
20
},
21
newProperties: {
22
anchor: { path: [0, 0], offset: 15 },
23
},
24
})
Copied!
Under the covers Slate converts complex transforms into the low-level operations and applies them to the editor automatically. So you rarely have to think about operations unless you're implementing collaborative editing.
🤖 Slate's editing behaviors being defined as operations is what makes things like collaborative editing possible, because each change is easily define-able, apply-able, compose-able and even undo-able!
Last modified 7mo ago
Copy link