mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-09 00:36:41 +02:00
cleanup, set keys automatically
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -10,13 +10,11 @@ import ReactDOM from 'react-dom'
|
|||||||
const state = {
|
const state = {
|
||||||
nodes: [
|
nodes: [
|
||||||
{
|
{
|
||||||
key: '1',
|
|
||||||
kind: 'node',
|
kind: 'node',
|
||||||
type: 'code',
|
type: 'code',
|
||||||
data: {},
|
data: {},
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
key: '2',
|
|
||||||
type: 'text',
|
type: 'text',
|
||||||
ranges: [
|
ranges: [
|
||||||
{
|
{
|
||||||
@@ -28,13 +26,11 @@ const state = {
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: '3',
|
|
||||||
kind: 'node',
|
kind: 'node',
|
||||||
type: 'paragraph',
|
type: 'paragraph',
|
||||||
data: {},
|
data: {},
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
key: '4',
|
|
||||||
type: 'text',
|
type: 'text',
|
||||||
ranges: [
|
ranges: [
|
||||||
{
|
{
|
||||||
@@ -53,13 +49,7 @@ const state = {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
]
|
||||||
selection: {
|
|
||||||
anchorKey: '4',
|
|
||||||
anchorOffset: 14,
|
|
||||||
focusKey: '4',
|
|
||||||
focusOffset: 14
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
|
|
||||||
import Text from './text'
|
import Text from './text'
|
||||||
|
import uid from 'uid'
|
||||||
import { Map, OrderedMap, Record } from 'immutable'
|
import { Map, OrderedMap, Record } from 'immutable'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -28,10 +29,10 @@ class Node extends NodeRecord {
|
|||||||
|
|
||||||
static create(object) {
|
static create(object) {
|
||||||
return new Node({
|
return new Node({
|
||||||
key: object.key,
|
children: Node.createMap(object.children),
|
||||||
type: object.type,
|
|
||||||
data: new Map(object.data),
|
data: new Map(object.data),
|
||||||
children: Node.createMap(object.children)
|
key: uid(4),
|
||||||
|
type: object.type
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,10 +44,11 @@ class Node extends NodeRecord {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static createMap(array) {
|
static createMap(array) {
|
||||||
return new OrderedMap(array.reduce((map, node) => {
|
return new OrderedMap(array.reduce((map, object) => {
|
||||||
map[node.key] = node.type == 'text'
|
const node = object.type == 'text'
|
||||||
? Text.create(node)
|
? Text.create(object)
|
||||||
: Node.create(node)
|
: Node.create(object)
|
||||||
|
map[node.key] = node
|
||||||
return map
|
return map
|
||||||
}, {}))
|
}, {}))
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
|
|
||||||
import convertRangesToCharacters from '../utils/convert-ranges-to-characters'
|
import convertRangesToCharacters from '../utils/convert-ranges-to-characters'
|
||||||
|
import uid from 'uid'
|
||||||
import { List, Record } from 'immutable'
|
import { List, Record } from 'immutable'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -27,7 +28,7 @@ class Text extends TextRecord {
|
|||||||
static create(attrs) {
|
static create(attrs) {
|
||||||
const characters = convertRangesToCharacters(attrs.ranges)
|
const characters = convertRangesToCharacters(attrs.ranges)
|
||||||
return new Text({
|
return new Text({
|
||||||
key: attrs.key,
|
key: uid(4),
|
||||||
characters
|
characters
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@@ -5,7 +5,7 @@ import findOffsetKey from './find-offset-key'
|
|||||||
* Offset key splitter.
|
* Offset key splitter.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const SPLITTER = /^(\d+)(?:\.(\d+)-(\d+))?$/
|
const SPLITTER = /^(\w+)(?:\.(\d+)-(\d+))?$/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the selection anchor properties from a `node`.
|
* Find the selection anchor properties from a `node`.
|
||||||
|
@@ -9,7 +9,8 @@
|
|||||||
"lodash": "^4.13.1",
|
"lodash": "^4.13.1",
|
||||||
"react": "^15.1.0",
|
"react": "^15.1.0",
|
||||||
"to-camel-case": "^1.0.0",
|
"to-camel-case": "^1.0.0",
|
||||||
"ua-parser-js": "^0.7.10"
|
"ua-parser-js": "^0.7.10",
|
||||||
|
"uid": "0.0.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"babel-core": "^6.9.1",
|
"babel-core": "^6.9.1",
|
||||||
|
Reference in New Issue
Block a user