mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-30 10:29:48 +02:00
Merge branch 'master' of github.com:ianstormtaylor/slate
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
"lib/"
|
||||
],
|
||||
"dependencies": {
|
||||
"debug": "^2.3.2",
|
||||
"debug": "^3.1.0",
|
||||
"get-window": "^1.1.1",
|
||||
"is-window": "^1.0.2",
|
||||
"keycode": "^2.1.2",
|
||||
|
@@ -99,9 +99,21 @@ class Leaf extends React.Component {
|
||||
const { marks, node, offset, text, editor } = this.props
|
||||
const { stack } = editor
|
||||
const leaf = this.renderText()
|
||||
const attributes = {
|
||||
'data-slate-leaf': true,
|
||||
}
|
||||
|
||||
return marks.reduce((children, mark) => {
|
||||
const props = { editor, mark, marks, node, offset, text, children }
|
||||
const props = {
|
||||
editor,
|
||||
mark,
|
||||
marks,
|
||||
node,
|
||||
offset,
|
||||
text,
|
||||
children,
|
||||
attributes,
|
||||
}
|
||||
const element = stack.find('renderMark', props)
|
||||
return element || children
|
||||
}, leaf)
|
||||
|
@@ -305,8 +305,8 @@ function AfterPlugin() {
|
||||
|
||||
// Get the selection point.
|
||||
const native = window.getSelection()
|
||||
const { anchorNode, anchorOffset } = native
|
||||
const point = findPoint(anchorNode, anchorOffset, value)
|
||||
const { anchorNode } = native
|
||||
const point = findPoint(anchorNode, 0, value)
|
||||
if (!point) return
|
||||
|
||||
// Get the text node and leaf in question.
|
||||
@@ -323,7 +323,7 @@ function AfterPlugin() {
|
||||
leaves.find(r => {
|
||||
start = end
|
||||
end += r.text.length
|
||||
if (end >= point.offset) return true
|
||||
if (end > point.offset) return true
|
||||
}) || lastLeaf
|
||||
|
||||
// Get the text information.
|
||||
|
@@ -17,7 +17,7 @@ function decorateNode(block) {
|
||||
}
|
||||
|
||||
function Bold(props) {
|
||||
return React.createElement('strong', null, props.children)
|
||||
return React.createElement('strong', { ...props.attributes }, props.children)
|
||||
}
|
||||
|
||||
function renderMark(props) {
|
||||
@@ -45,7 +45,7 @@ export const output = `
|
||||
<div style="position:relative">
|
||||
<span>
|
||||
<span>o</span>
|
||||
<span><strong>n</strong></span>
|
||||
<span><strong data-slate-leaf="true">n</strong></span>
|
||||
<span>e</span>
|
||||
</span>
|
||||
</div>
|
||||
|
@@ -4,7 +4,7 @@ import React from 'react'
|
||||
import h from '../../helpers/h'
|
||||
|
||||
function Bold(props) {
|
||||
return React.createElement('strong', null, props.children)
|
||||
return React.createElement('strong', { ...props.attributes }, props.children)
|
||||
}
|
||||
|
||||
function renderMark(props) {
|
||||
@@ -33,7 +33,7 @@ export const output = `
|
||||
<div style="position:relative">
|
||||
<span>
|
||||
<span>one</span>
|
||||
<span><strong>two</strong></span>
|
||||
<span><strong data-slate-leaf="true">two</strong></span>
|
||||
<span>three</span>
|
||||
</span>
|
||||
</div>
|
||||
|
@@ -13,7 +13,7 @@
|
||||
"lib/"
|
||||
],
|
||||
"dependencies": {
|
||||
"debug": "^2.3.2",
|
||||
"debug": "^3.1.0",
|
||||
"direction": "^0.1.5",
|
||||
"esrever": "^0.2.0",
|
||||
"is-empty": "^1.0.0",
|
||||
|
@@ -40,6 +40,11 @@ PROXY_TRANSFORMS.forEach(method => {
|
||||
const { selection } = value
|
||||
const methodAtRange = `${method}AtRange`
|
||||
change[methodAtRange](selection, ...args)
|
||||
if (method.match(/Backward$/)) {
|
||||
change.collapseToStart()
|
||||
} else if (method.match(/Forward$/)) {
|
||||
change.collapseToEnd()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -217,8 +222,12 @@ Changes.insertText = (change, text, marks) => {
|
||||
|
||||
Changes.splitBlock = (change, depth = 1) => {
|
||||
const { value } = change
|
||||
const { selection } = value
|
||||
const { selection, document } = value
|
||||
const marks = selection.marks || document.getInsertMarksAtRange(selection)
|
||||
change.splitBlockAtRange(selection, depth).collapseToEnd()
|
||||
if (marks && marks.size !== 0) {
|
||||
change.select({ marks })
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -671,7 +671,11 @@ Changes.insertFragmentAtRange = (change, range, fragment, options = {}) => {
|
||||
// If the range is expanded, delete it first.
|
||||
if (range.isExpanded) {
|
||||
change.deleteAtRange(range, { normalize: false })
|
||||
range = range.collapseToStart()
|
||||
if (change.value.document.getDescendant(range.startKey)) {
|
||||
range = range.collapseToStart()
|
||||
} else {
|
||||
range = range.collapseTo(range.endKey, 0)
|
||||
}
|
||||
}
|
||||
|
||||
// If the fragment is empty, there's nothing to do after deleting.
|
||||
@@ -988,12 +992,7 @@ Changes.setInlineAtRange = (...args) => {
|
||||
Changes.splitBlockAtRange = (change, range, height = 1, options = {}) => {
|
||||
const normalize = change.getFlag('normalize', options)
|
||||
|
||||
if (range.isExpanded) {
|
||||
change.deleteAtRange(range, { normalize })
|
||||
range = range.collapseToStart()
|
||||
}
|
||||
|
||||
const { startKey, startOffset } = range
|
||||
const { startKey, startOffset, endOffset, endKey } = range
|
||||
const { value } = change
|
||||
const { document } = value
|
||||
let node = document.assertDescendant(startKey)
|
||||
@@ -1006,7 +1005,19 @@ Changes.splitBlockAtRange = (change, range, height = 1, options = {}) => {
|
||||
h++
|
||||
}
|
||||
|
||||
change.splitDescendantsByKey(node.key, startKey, startOffset, { normalize })
|
||||
change.splitDescendantsByKey(node.key, startKey, startOffset, {
|
||||
normalize: normalize && range.isCollapsed,
|
||||
})
|
||||
|
||||
if (range.isExpanded) {
|
||||
if (range.isBackward) range = range.flip()
|
||||
const nextBlock = change.value.document.getNextBlock(node.key)
|
||||
range = range.moveAnchorToStartOf(nextBlock)
|
||||
if (startKey === endKey) {
|
||||
range = range.moveFocusTo(range.anchorKey, endOffset - startOffset)
|
||||
}
|
||||
change.deleteAtRange(range, { normalize })
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -47,7 +47,9 @@ Changes.normalizeNodeByKey = (change, key) => {
|
||||
if (!ancestors) return
|
||||
|
||||
ancestors.forEach(ancestor => {
|
||||
normalizeNode(change, ancestor, schema)
|
||||
if (change.value.document.getDescendant(ancestor.key)) {
|
||||
normalizeNode(change, ancestor, schema)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
@@ -23,9 +23,8 @@ export const output = (
|
||||
<value>
|
||||
<document>
|
||||
<paragraph>
|
||||
<anchor />
|
||||
<link>
|
||||
<focus />wo
|
||||
<cursor />wo
|
||||
</link>
|
||||
</paragraph>
|
||||
</document>
|
||||
|
@@ -0,0 +1,44 @@
|
||||
/** @jsx h */
|
||||
|
||||
import h from '../../../helpers/h'
|
||||
|
||||
const fragment = (
|
||||
<document>
|
||||
<paragraph>fragment zero</paragraph>
|
||||
<paragraph>fragment one</paragraph>
|
||||
<paragraph>fragment two</paragraph>
|
||||
</document>
|
||||
)
|
||||
export default function(change) {
|
||||
change.insertFragment(fragment)
|
||||
}
|
||||
|
||||
export const input = (
|
||||
<value>
|
||||
<document>
|
||||
<paragraph>zero</paragraph>
|
||||
<paragraph>
|
||||
<anchor />one
|
||||
</paragraph>
|
||||
<quote>
|
||||
<focus />two
|
||||
</quote>
|
||||
</document>
|
||||
</value>
|
||||
)
|
||||
|
||||
// The cursor position of insertFragment has some problems;
|
||||
// If you submit PR to fixed cursor position restore in insertFragment;
|
||||
// Please change this test as well
|
||||
export const output = (
|
||||
<value>
|
||||
<document>
|
||||
<paragraph>zero</paragraph>
|
||||
<quote>fragment zero</quote>
|
||||
<paragraph>fragment one</paragraph>
|
||||
<paragraph>
|
||||
<cursor />fragment twotwo
|
||||
</paragraph>
|
||||
</document>
|
||||
</value>
|
||||
)
|
@@ -0,0 +1,33 @@
|
||||
/** @jsx h */
|
||||
|
||||
import h from '../../../helpers/h'
|
||||
|
||||
export default function(change) {
|
||||
change.splitBlock()
|
||||
}
|
||||
|
||||
export const input = (
|
||||
<value>
|
||||
<document>
|
||||
<paragraph>zero</paragraph>
|
||||
<paragraph>
|
||||
<anchor />word
|
||||
</paragraph>
|
||||
<quote>
|
||||
<focus />cat is cute
|
||||
</quote>
|
||||
</document>
|
||||
</value>
|
||||
)
|
||||
|
||||
export const output = (
|
||||
<value>
|
||||
<document>
|
||||
<paragraph>zero</paragraph>
|
||||
<paragraph />
|
||||
<quote>
|
||||
<cursor />cat is cute
|
||||
</quote>
|
||||
</document>
|
||||
</value>
|
||||
)
|
@@ -0,0 +1,38 @@
|
||||
/** @jsx h */
|
||||
|
||||
import h from '../../../helpers/h'
|
||||
|
||||
export default function(change) {
|
||||
change
|
||||
.addMark('italic')
|
||||
.splitBlock()
|
||||
.insertText('cat is cute')
|
||||
}
|
||||
|
||||
export const input = (
|
||||
<value>
|
||||
<document>
|
||||
<paragraph>
|
||||
<b>word</b>
|
||||
<cursor />
|
||||
</paragraph>
|
||||
</document>
|
||||
</value>
|
||||
)
|
||||
|
||||
export const output = (
|
||||
<value>
|
||||
<document>
|
||||
<paragraph>
|
||||
<b>word</b>
|
||||
<cursor />
|
||||
</paragraph>
|
||||
<paragraph>
|
||||
<i>
|
||||
<b>cat is cute</b>
|
||||
</i>
|
||||
<cursor />
|
||||
</paragraph>
|
||||
</document>
|
||||
</value>
|
||||
)
|
Reference in New Issue
Block a user