mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-02-24 09:13:24 +01:00
clean up transforms
This commit is contained in:
parent
286e3620dd
commit
1a4ee5e1ec
@ -16,9 +16,7 @@ import { List } from 'immutable'
|
||||
*/
|
||||
|
||||
export function addMarkAtRange(transform, range, mark, options = {}) {
|
||||
if (range.isCollapsed) {
|
||||
return transform
|
||||
}
|
||||
if (range.isCollapsed) return transform
|
||||
|
||||
const { normalize = true } = options
|
||||
const { state } = transform
|
||||
@ -52,9 +50,7 @@ export function addMarkAtRange(transform, range, mark, options = {}) {
|
||||
*/
|
||||
|
||||
export function deleteAtRange(transform, range, options = {}) {
|
||||
if (range.isCollapsed) {
|
||||
return transform
|
||||
}
|
||||
if (range.isCollapsed) return transform
|
||||
|
||||
const { normalize = true } = options
|
||||
const { startKey, startOffset, endKey, endOffset } = range
|
||||
@ -113,8 +109,6 @@ export function deleteAtRange(transform, range, options = {}) {
|
||||
transform.normalizeNodeByKey(ancestor.key, SCHEMA)
|
||||
}
|
||||
|
||||
transform.normalizeDocument(SCHEMA)
|
||||
|
||||
return transform
|
||||
}
|
||||
|
||||
@ -488,11 +482,9 @@ export function insertTextAtRange(transform, range, text, marks, options = {}) {
|
||||
*/
|
||||
|
||||
export function removeMarkAtRange(transform, range, mark, options = {}) {
|
||||
const { normalize = true } = options
|
||||
if (range.isCollapsed) {
|
||||
return transform
|
||||
}
|
||||
if (range.isCollapsed) return transform
|
||||
|
||||
const { normalize = true } = options
|
||||
const { state } = transform
|
||||
const { document } = state
|
||||
const texts = document.getTextsAtRange(range)
|
||||
@ -574,6 +566,7 @@ export function setInlineAtRange(transform, range, properties, options = {}) {
|
||||
|
||||
export function splitBlockAtRange(transform, range, height = 1, options = {}) {
|
||||
const { normalize = true } = options
|
||||
|
||||
if (range.isExpanded) {
|
||||
transform.deleteAtRange(range, { normalize })
|
||||
range = range.collapseToStart()
|
||||
@ -594,9 +587,7 @@ export function splitBlockAtRange(transform, range, height = 1, options = {}) {
|
||||
h++
|
||||
}
|
||||
|
||||
transform.splitNodeByKey(node.key, offset, { normalize })
|
||||
|
||||
return transform
|
||||
return transform.splitNodeByKey(node.key, offset, { normalize })
|
||||
}
|
||||
|
||||
/**
|
||||
@ -612,6 +603,7 @@ export function splitBlockAtRange(transform, range, height = 1, options = {}) {
|
||||
|
||||
export function splitInlineAtRange(transform, range, height = Infinity, options = {}) {
|
||||
const { normalize = true } = options
|
||||
|
||||
if (range.isExpanded) {
|
||||
transform.deleteAtRange(range, { normalize })
|
||||
range = range.collapseToStart()
|
||||
@ -648,13 +640,11 @@ export function splitInlineAtRange(transform, range, height = Infinity, options
|
||||
*/
|
||||
|
||||
export function toggleMarkAtRange(transform, range, mark, options = {}) {
|
||||
const { normalize = true } = options
|
||||
if (range.isCollapsed) {
|
||||
return transform
|
||||
}
|
||||
if (range.isCollapsed) return transform
|
||||
|
||||
mark = Normalize.mark(mark)
|
||||
|
||||
const { normalize = true } = options
|
||||
const { state } = transform
|
||||
const { document } = state
|
||||
const marks = document.getMarksAtRange(range)
|
||||
@ -681,9 +671,9 @@ export function toggleMarkAtRange(transform, range, mark, options = {}) {
|
||||
*/
|
||||
|
||||
export function unwrapBlockAtRange(transform, range, properties, options = {}) {
|
||||
const { normalize = true } = options
|
||||
properties = Normalize.nodeProperties(properties)
|
||||
|
||||
const { normalize = true } = options
|
||||
let { state } = transform
|
||||
let { document } = state
|
||||
const blocks = document.getBlocksAtRange(range)
|
||||
@ -1030,8 +1020,7 @@ export function wrapTextAtRange(transform, range, prefix, suffix = prefix, optio
|
||||
end = end.moveForward(prefix.length)
|
||||
}
|
||||
|
||||
transform.insertTextAtRange(start, prefix, [], { normalize })
|
||||
transform.insertTextAtRange(end, suffix, [], { normalize })
|
||||
|
||||
return transform
|
||||
.insertTextAtRange(start, prefix, [], { normalize })
|
||||
.insertTextAtRange(end, suffix, [], { normalize })
|
||||
}
|
||||
|
@ -16,8 +16,8 @@ import SCHEMA from '../schemas/core'
|
||||
*/
|
||||
|
||||
export function addMarkByKey(transform, key, offset, length, mark, options = {}) {
|
||||
const { normalize = true } = options
|
||||
mark = Normalize.mark(mark)
|
||||
const { normalize = true } = options
|
||||
const { state } = transform
|
||||
const { document } = state
|
||||
const path = document.getPath(key)
|
||||
@ -164,8 +164,8 @@ export function moveNodeByKey(transform, key, newKey, newIndex, options = {}) {
|
||||
*/
|
||||
|
||||
export function removeMarkByKey(transform, key, offset, length, mark, options = {}) {
|
||||
const { normalize = true } = options
|
||||
mark = Normalize.mark(mark)
|
||||
const { normalize = true } = options
|
||||
const { state } = transform
|
||||
const { document } = state
|
||||
const path = document.getPath(key)
|
||||
@ -252,9 +252,9 @@ export function removeTextByKey(transform, key, offset, length, options = {}) {
|
||||
*/
|
||||
|
||||
export function setMarkByKey(transform, key, offset, length, mark, properties, options = {}) {
|
||||
const { normalize = true } = options
|
||||
mark = Normalize.mark(mark)
|
||||
properties = Normalize.markProperties(properties)
|
||||
const { normalize = true } = options
|
||||
const newMark = mark.merge(properties)
|
||||
const { state } = transform
|
||||
const { document } = state
|
||||
@ -282,8 +282,8 @@ export function setMarkByKey(transform, key, offset, length, mark, properties, o
|
||||
*/
|
||||
|
||||
export function setNodeByKey(transform, key, properties, options = {}) {
|
||||
const { normalize = true } = options
|
||||
properties = Normalize.nodeProperties(properties)
|
||||
const { normalize = true } = options
|
||||
const { state } = transform
|
||||
const { document } = state
|
||||
const path = document.getPath(key)
|
||||
|
@ -12,8 +12,6 @@ import warn from '../utils/warn'
|
||||
*/
|
||||
|
||||
export function normalize(transform, schema) {
|
||||
assertSchema(schema)
|
||||
|
||||
return transform
|
||||
.normalizeDocument(schema)
|
||||
.normalizeSelection(schema)
|
||||
@ -28,17 +26,9 @@ export function normalize(transform, schema) {
|
||||
*/
|
||||
|
||||
export function normalizeDocument(transform, schema) {
|
||||
assertSchema(schema)
|
||||
|
||||
// If the schema has no validation rules, there's nothing to normalize.
|
||||
if (!schema.hasValidators) {
|
||||
return transform
|
||||
}
|
||||
|
||||
const { state } = transform
|
||||
const { document } = state
|
||||
|
||||
return normalizeNodeWith(transform, document, schema)
|
||||
return transform.normalizeNodeByKey(document.key, schema)
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user