mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-11 09:43:58 +02:00
fix examples
This commit is contained in:
@@ -12,21 +12,17 @@ import state from './state.json'
|
||||
*/
|
||||
|
||||
function deserialize(string) {
|
||||
const characters = string
|
||||
.split('')
|
||||
.reduce((list, char) => {
|
||||
return list.push(Character.create({ text: char }))
|
||||
}, Character.createList())
|
||||
|
||||
const text = Text.create({ characters })
|
||||
const texts = Block.createMap([text])
|
||||
const node = Block.create({
|
||||
type: 'paragraph',
|
||||
nodes: texts,
|
||||
const characters = string.split('').map(char => {
|
||||
return { text: char }
|
||||
})
|
||||
|
||||
const nodes = Block.createMap([node])
|
||||
const document = Document.create({ nodes })
|
||||
const text = Text.create({ characters })
|
||||
const block = Block.create({
|
||||
type: 'paragraph',
|
||||
nodes: [text]
|
||||
})
|
||||
|
||||
const document = Document.create({ nodes: [block] })
|
||||
const state = State.create({ document })
|
||||
return state
|
||||
}
|
||||
|
@@ -16,14 +16,14 @@ class App extends React.Component {
|
||||
|
||||
hasMark(type) {
|
||||
const { state } = this.state
|
||||
const { currentMarks } = state
|
||||
return currentMarks.some(mark => mark.type == type)
|
||||
const { marks } = state
|
||||
return marks.some(mark => mark.type == type)
|
||||
}
|
||||
|
||||
hasBlock(type) {
|
||||
const { state } = this.state
|
||||
const { currentBlockNodes } = state
|
||||
return currentBlockNodes.some(node => node.type == type)
|
||||
const { blocks } = state
|
||||
return blocks.some(node => node.type == type)
|
||||
}
|
||||
|
||||
onClickMark(e, type) {
|
||||
@@ -46,7 +46,7 @@ class App extends React.Component {
|
||||
|
||||
state = state
|
||||
.transform()
|
||||
.setType(isActive ? 'paragraph' : type)
|
||||
.setBlock(isActive ? 'paragraph' : type)
|
||||
.apply()
|
||||
|
||||
this.setState({ state })
|
||||
|
@@ -100,9 +100,7 @@ class App extends React.Component {
|
||||
*/
|
||||
|
||||
onKeyDown(e, state) {
|
||||
if (state.isCurrentlyExpanded) return
|
||||
const node = state.currentBlockNodes.first()
|
||||
if (node.type != 'table-cell') return
|
||||
if (state.startNode.type != 'table-cell') return
|
||||
|
||||
const key = keycode(e.which)
|
||||
switch (key) {
|
||||
@@ -121,7 +119,7 @@ class App extends React.Component {
|
||||
*/
|
||||
|
||||
onBackspace(e, state) {
|
||||
if (state.currentStartOffset != 0) return
|
||||
if (state.startOffset != 0) return
|
||||
e.preventDefault()
|
||||
return state
|
||||
}
|
||||
@@ -135,8 +133,7 @@ class App extends React.Component {
|
||||
*/
|
||||
|
||||
onDelete(e, state) {
|
||||
const node = state.currentBlockNodes.first()
|
||||
if (state.currentEndOffset != node.length) return
|
||||
if (state.endOffset != state.startNode.length) return
|
||||
e.preventDefault()
|
||||
return state
|
||||
}
|
||||
|
@@ -412,6 +412,7 @@ const Node = {
|
||||
|
||||
// If the range is collapsed at the start of the node, check the previous.
|
||||
if (range.isCollapsed && startOffset == 0) {
|
||||
const text = this.getDescendant(startKey)
|
||||
const previous = this.getPreviousText(startKey)
|
||||
if (!previous) return marks
|
||||
const char = text.characters.get(previous.length - 1)
|
||||
@@ -426,11 +427,9 @@ const Node = {
|
||||
}
|
||||
|
||||
// Otherwise, get a set of the marks for each character in the range.
|
||||
this
|
||||
return this
|
||||
.getCharactersAtRange(range)
|
||||
.reduce((marks, char) => {
|
||||
return marks.union(char.marks)
|
||||
}, marks)
|
||||
.reduce((marks, char) => marks.union(char.marks), marks)
|
||||
},
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user