mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-22 23:12:52 +02:00
cleanup
This commit is contained in:
@@ -765,7 +765,6 @@ const Node = {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
getPath(key) {
|
getPath(key) {
|
||||||
debugger
|
|
||||||
key = Normalize.key(key)
|
key = Normalize.key(key)
|
||||||
|
|
||||||
if (key == this.key) return []
|
if (key == this.key) return []
|
||||||
|
@@ -76,6 +76,20 @@ class Transform {
|
|||||||
return 'transform'
|
return 'transform'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add an `operation` to the transform that resulted in `state`.
|
||||||
|
*
|
||||||
|
* @param {State} state
|
||||||
|
* @param {Object} operation
|
||||||
|
* @return {Transform}
|
||||||
|
*/
|
||||||
|
|
||||||
|
add(state, operation) {
|
||||||
|
this.state = state
|
||||||
|
this.operations.push(operation)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply the transform and return the new state.
|
* Apply the transform and return the new state.
|
||||||
*
|
*
|
||||||
|
@@ -25,16 +25,13 @@ export function addMarkByKey(transform, key, offset, length, mark) {
|
|||||||
document = document.updateDescendant(node)
|
document = document.updateDescendant(node)
|
||||||
state = state.merge({ document })
|
state = state.merge({ document })
|
||||||
|
|
||||||
transform.state = state
|
return transform.add(state, {
|
||||||
transform.operations.push({
|
|
||||||
type: 'add-mark',
|
type: 'add-mark',
|
||||||
offset,
|
|
||||||
length,
|
length,
|
||||||
mark,
|
mark,
|
||||||
|
offset,
|
||||||
path,
|
path,
|
||||||
})
|
})
|
||||||
|
|
||||||
return transform
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -60,15 +57,12 @@ export function insertNodeByKey(transform, key, index, node) {
|
|||||||
document = document.normalize()
|
document = document.normalize()
|
||||||
state = state.merge({ document })
|
state = state.merge({ document })
|
||||||
|
|
||||||
transform.state = state
|
return transform.add(state, {
|
||||||
transform.operations.push({
|
|
||||||
type: 'insert-node',
|
type: 'insert-node',
|
||||||
index,
|
index,
|
||||||
node,
|
node,
|
||||||
path,
|
path,
|
||||||
})
|
})
|
||||||
|
|
||||||
return transform
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -92,16 +86,13 @@ export function insertTextByKey(transform, key, offset, text, marks) {
|
|||||||
document = document.updateDescendant(node)
|
document = document.updateDescendant(node)
|
||||||
state = state.merge({ document })
|
state = state.merge({ document })
|
||||||
|
|
||||||
transform.state = state
|
return transform.add(state, {
|
||||||
transform.operations.push({
|
|
||||||
type: 'insert-text',
|
type: 'insert-text',
|
||||||
offset,
|
offset,
|
||||||
marks,
|
marks,
|
||||||
path,
|
path,
|
||||||
text,
|
text,
|
||||||
})
|
})
|
||||||
|
|
||||||
return transform
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -135,15 +126,12 @@ export function moveNodeByKey(transform, key, newKey, newIndex) {
|
|||||||
document = document.normalize()
|
document = document.normalize()
|
||||||
state = state.merge({ document })
|
state = state.merge({ document })
|
||||||
|
|
||||||
transform.state = state
|
return transform.add(state, {
|
||||||
transform.operations.push({
|
|
||||||
type: 'move-node',
|
type: 'move-node',
|
||||||
path,
|
path,
|
||||||
newPath,
|
newPath,
|
||||||
newIndex,
|
newIndex,
|
||||||
})
|
})
|
||||||
|
|
||||||
return transform
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -169,16 +157,13 @@ export function removeMarkByKey(transform, key, offset, length, mark) {
|
|||||||
document = document.updateDescendant(node)
|
document = document.updateDescendant(node)
|
||||||
state = state.merge({ document })
|
state = state.merge({ document })
|
||||||
|
|
||||||
transform.state = state
|
return transform.add(state, {
|
||||||
transform.operations.push({
|
|
||||||
type: 'remove-mark',
|
type: 'remove-mark',
|
||||||
offset,
|
offset,
|
||||||
length,
|
length,
|
||||||
mark,
|
mark,
|
||||||
path,
|
path,
|
||||||
})
|
})
|
||||||
|
|
||||||
return transform
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -203,13 +188,10 @@ export function removeNodeByKey(transform, key) {
|
|||||||
document = document.normalize()
|
document = document.normalize()
|
||||||
state = state.merge({ document })
|
state = state.merge({ document })
|
||||||
|
|
||||||
transform.state = state
|
return transform.add(state, {
|
||||||
transform.operations.push({
|
|
||||||
type: 'remove-node',
|
type: 'remove-node',
|
||||||
path,
|
path,
|
||||||
})
|
})
|
||||||
|
|
||||||
return transform
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -233,15 +215,12 @@ export function removeTextByKey(transform, key, offset, length) {
|
|||||||
document = document.normalize()
|
document = document.normalize()
|
||||||
state = state.merge({ document })
|
state = state.merge({ document })
|
||||||
|
|
||||||
transform.state = state
|
return transform.add(state, {
|
||||||
transform.operations.push({
|
|
||||||
type: 'remove-text',
|
type: 'remove-text',
|
||||||
offset,
|
offset,
|
||||||
length,
|
length,
|
||||||
path,
|
path,
|
||||||
})
|
})
|
||||||
|
|
||||||
return transform
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -268,8 +247,7 @@ export function setMarkByKey(transform, key, offset, length, mark, properties) {
|
|||||||
document = document.updateDescendant(node)
|
document = document.updateDescendant(node)
|
||||||
state = state.merge({ document })
|
state = state.merge({ document })
|
||||||
|
|
||||||
transform.state = state
|
return transform.add(state, {
|
||||||
transform.operations.push({
|
|
||||||
type: 'set-mark',
|
type: 'set-mark',
|
||||||
offset,
|
offset,
|
||||||
length,
|
length,
|
||||||
@@ -277,8 +255,6 @@ export function setMarkByKey(transform, key, offset, length, mark, properties) {
|
|||||||
path,
|
path,
|
||||||
properties,
|
properties,
|
||||||
})
|
})
|
||||||
|
|
||||||
return transform
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -303,14 +279,11 @@ export function setNodeByKey(transform, key, properties) {
|
|||||||
document = document.normalize()
|
document = document.normalize()
|
||||||
state = state.merge({ document })
|
state = state.merge({ document })
|
||||||
|
|
||||||
transform.state = state
|
return transform.add(state, {
|
||||||
transform.operations.push({
|
|
||||||
type: 'set-node',
|
type: 'set-node',
|
||||||
path,
|
path,
|
||||||
properties,
|
properties,
|
||||||
})
|
})
|
||||||
|
|
||||||
return transform
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -366,13 +339,10 @@ export function splitNodeByKey(transform, key, offset) {
|
|||||||
document = isParent ? parent : document.updateDescendant(parent)
|
document = isParent ? parent : document.updateDescendant(parent)
|
||||||
state = state.merge({ document })
|
state = state.merge({ document })
|
||||||
|
|
||||||
transform.state = state
|
return transform.add(state, {
|
||||||
transform.operations.push({
|
|
||||||
type: 'split-node',
|
type: 'split-node',
|
||||||
offset,
|
offset,
|
||||||
path,
|
path,
|
||||||
})
|
})
|
||||||
|
|
||||||
return transform
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user