mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-31 19:01:54 +02:00
Expose transforms (#836)
* refactor to extract applyOperation util * change handlers to receive transform instead of state * change onChange to receive a transform, update rich-text example * fix stack iterationg, convert check-list example * convert code-highlighting, embeds, emojis examples * change operations to use full paths, not indexes * switch split and join to be recursive * fix linter * fix onChange calls * make all operations invertable, add src/operations/* logic * rename "join" to "merge" * remove .length property of nodes * fix node.getFragmentAtRange logic * convert remaining examples, fix existing changes * fix .apply() calls and tests * change setSave and setIsNative transforms * fix insert_text operations to include marks always * cleanup and fixes * fix node inheritance * fix core onCut handler * skip constructor in node inheritance * cleanup * change updateDescendant to updateNode * add and update docs * eliminate need for .apply(), change history to mutable * add missing file * add deprecation support to Transform objects * rename "transform" to "change" * update benchmark * add deprecation util to logger * update transform isNative attr * fix remaining warn use * simplify history checkpointing logic * fix tests * revert history to being immutable * fix history * fix normalize * fix syntax error from merge
This commit is contained in:
@@ -91,9 +91,9 @@ class App extends React.Component {
|
||||
// Prevent the ampersand character from being inserted.
|
||||
event.preventDefault()
|
||||
|
||||
// Transform the state by inserting "and" at the cursor's position.
|
||||
// Change the state by inserting "and" at the cursor's position.
|
||||
const newState = state
|
||||
.transform()
|
||||
.change()
|
||||
.insertText('and')
|
||||
.apply()
|
||||
|
||||
|
@@ -33,7 +33,7 @@ class App extends React.Component {
|
||||
const isCode = state.blocks.some(block => block.type == 'code')
|
||||
|
||||
return state
|
||||
.transform()
|
||||
.change()
|
||||
.setBlock(isCode ? 'paragraph' : 'code')
|
||||
.apply()
|
||||
}
|
||||
@@ -79,7 +79,7 @@ class App extends React.Component {
|
||||
case 66: {
|
||||
event.preventDefault()
|
||||
return state
|
||||
.transform()
|
||||
.change()
|
||||
.addMark('bold')
|
||||
.apply()
|
||||
}
|
||||
@@ -89,7 +89,7 @@ class App extends React.Component {
|
||||
const isCode = state.blocks.some(block => block.type == 'code')
|
||||
event.preventDefault()
|
||||
return state
|
||||
.transform()
|
||||
.change()
|
||||
.setBlock(isCode ? 'paragraph' : 'code')
|
||||
.apply()
|
||||
}
|
||||
@@ -158,7 +158,7 @@ class App extends React.Component {
|
||||
case 66: {
|
||||
event.preventDefault()
|
||||
return state
|
||||
.transform()
|
||||
.change()
|
||||
.toggleMark('bold')
|
||||
.apply()
|
||||
}
|
||||
@@ -167,7 +167,7 @@ class App extends React.Component {
|
||||
const isCode = state.blocks.some(block => block.type == 'code')
|
||||
event.preventDefault()
|
||||
return state
|
||||
.transform()
|
||||
.change()
|
||||
.setBlock(isCode ? 'paragraph' : 'code')
|
||||
.apply()
|
||||
}
|
||||
|
@@ -28,7 +28,7 @@ class App extends React.Component {
|
||||
event.preventDefault()
|
||||
|
||||
const newState = state
|
||||
.transform()
|
||||
.change()
|
||||
.insertText('and')
|
||||
.apply()
|
||||
|
||||
@@ -96,7 +96,7 @@ class App extends React.Component {
|
||||
event.preventDefault()
|
||||
|
||||
const newState = state
|
||||
.transform()
|
||||
.change()
|
||||
.insertText('and')
|
||||
.apply()
|
||||
|
||||
@@ -149,7 +149,7 @@ class App extends React.Component {
|
||||
|
||||
// Otherwise, set the currently selected blocks type to "code".
|
||||
return state
|
||||
.transform()
|
||||
.change()
|
||||
.setBlock('code')
|
||||
.apply()
|
||||
}
|
||||
@@ -202,7 +202,7 @@ class App extends React.Component {
|
||||
|
||||
// Toggle the block type depending on `isCode`.
|
||||
return state
|
||||
.transform()
|
||||
.change()
|
||||
.setBlock(isCode ? 'paragraph' : 'code')
|
||||
.apply()
|
||||
|
||||
|
@@ -33,7 +33,7 @@ class App extends React.Component {
|
||||
if (!event.metaKey || event.which != 66) return
|
||||
event.preventDefault()
|
||||
return state
|
||||
.transform()
|
||||
.change()
|
||||
.toggleMark('bold')
|
||||
.apply()
|
||||
}
|
||||
@@ -82,7 +82,7 @@ function MarkHotkey(options) {
|
||||
|
||||
// Toggle the mark `type`.
|
||||
return state
|
||||
.transform()
|
||||
.change()
|
||||
.toggleMark(type)
|
||||
.apply()
|
||||
}
|
||||
@@ -220,7 +220,7 @@ function MarkHotkey(options) {
|
||||
if (!event.metaKey || keycode(event.which) != key || event.altKey != isAltKey) return
|
||||
event.preventDefault()
|
||||
return state
|
||||
.transform()
|
||||
.change()
|
||||
.toggleMark(type)
|
||||
.apply()
|
||||
}
|
||||
|
Reference in New Issue
Block a user