1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-28 17:39:57 +02:00

remove leaves (#2715)

* first stab at removing leaves with tests passing

* add deprecation warning for creating texts with leaves

* fixes

* update examples
This commit is contained in:
Ian Storm Taylor
2019-04-30 12:15:22 -07:00
committed by GitHub
parent a431576e73
commit a220cd5ae1
184 changed files with 2281 additions and 2599 deletions

View File

@@ -20,13 +20,8 @@ export const output = {
nodes: [
{
object: 'text',
leaves: [
{
object: 'leaf',
text: 'word',
marks: [],
},
],
text: 'word',
marks: [],
},
],
},

View File

@@ -15,17 +15,12 @@ export const output = {
nodes: [
{
object: 'text',
leaves: [
text: '',
marks: [
{
object: 'leaf',
text: '',
marks: [
{
object: 'mark',
type: 'bold',
data: {},
},
],
object: 'mark',
type: 'bold',
data: {},
},
],
},

View File

@@ -15,17 +15,12 @@ export const output = {
nodes: [
{
object: 'text',
leaves: [
text: 'word',
marks: [
{
object: 'leaf',
text: 'word',
marks: [
{
object: 'mark',
type: 'bold',
data: {},
},
],
object: 'mark',
type: 'bold',
data: {},
},
],
},

View File

@@ -0,0 +1,44 @@
/** @jsx h */
import h from 'slate-hyperscript'
export const input = (
<block type="paragraph">
<mark type="bold">one</mark>two<mark type="italic">three</mark>
</block>
)
export const output = {
object: 'block',
type: 'paragraph',
data: {},
nodes: [
{
object: 'text',
text: 'one',
marks: [
{
object: 'mark',
type: 'bold',
data: {},
},
],
},
{
object: 'text',
text: 'two',
marks: [],
},
{
object: 'text',
text: 'three',
marks: [
{
object: 'mark',
type: 'italic',
data: {},
},
],
},
],
}

View File

@@ -4,9 +4,11 @@ import h from 'slate-hyperscript'
export const input = (
<block type="paragraph">
<mark type="bold">w</mark>
<mark type="bold">
w<mark type="italic">or</mark>d
<mark type="italic">or</mark>
</mark>
<mark type="bold">d</mark>
</block>
)
@@ -17,44 +19,39 @@ export const output = {
nodes: [
{
object: 'text',
leaves: [
text: 'w',
marks: [
{
object: 'leaf',
text: 'w',
marks: [
{
object: 'mark',
type: 'bold',
data: {},
},
],
object: 'mark',
type: 'bold',
data: {},
},
],
},
{
object: 'text',
text: 'or',
marks: [
{
object: 'mark',
type: 'italic',
data: {},
},
{
object: 'leaf',
text: 'or',
marks: [
{
object: 'mark',
type: 'italic',
data: {},
},
{
object: 'mark',
type: 'bold',
data: {},
},
],
object: 'mark',
type: 'bold',
data: {},
},
],
},
{
object: 'text',
text: 'd',
marks: [
{
object: 'leaf',
text: 'd',
marks: [
{
object: 'mark',
type: 'bold',
data: {},
},
],
object: 'mark',
type: 'bold',
data: {},
},
],
},

View File

@@ -11,13 +11,8 @@ export const output = {
nodes: [
{
object: 'text',
leaves: [
{
object: 'leaf',
text: 'word',
marks: [],
},
],
text: 'word',
marks: [],
},
],
}

View File

@@ -15,13 +15,8 @@ export const output = {
nodes: [
{
object: 'text',
leaves: [
{
object: 'leaf',
text: '',
marks: [],
},
],
text: '',
marks: [],
},
],
}

View File

@@ -15,13 +15,8 @@ export const output = {
nodes: [
{
object: 'text',
leaves: [
{
object: 'leaf',
text: 'word',
marks: [],
},
],
text: 'word',
marks: [],
},
],
}

View File

@@ -33,13 +33,8 @@ export const output = {
{
object: 'text',
key: '0',
leaves: [
{
object: 'leaf',
text: 'word',
marks: [],
},
],
text: 'word',
marks: [],
},
],
},

View File

@@ -44,13 +44,8 @@ export const output = {
{
object: 'text',
key: '0',
leaves: [
{
object: 'leaf',
text: '',
marks: [],
},
],
text: '',
marks: [],
},
{
object: 'inline',
@@ -61,26 +56,16 @@ export const output = {
{
object: 'text',
key: '1',
leaves: [
{
object: 'leaf',
text: 'one',
marks: [],
},
],
text: 'one',
marks: [],
},
],
},
{
object: 'text',
key: '3',
leaves: [
{
object: 'leaf',
text: '',
marks: [],
},
],
text: '',
marks: [],
},
],
},
@@ -93,13 +78,8 @@ export const output = {
{
object: 'text',
key: '5',
leaves: [
{
object: 'leaf',
text: '',
marks: [],
},
],
text: '',
marks: [],
},
{
object: 'inline',
@@ -110,26 +90,16 @@ export const output = {
{
object: 'text',
key: '6',
leaves: [
{
object: 'leaf',
text: 'two',
marks: [],
},
],
text: 'two',
marks: [],
},
],
},
{
object: 'text',
key: '8',
leaves: [
{
object: 'leaf',
text: '',
marks: [],
},
],
text: '',
marks: [],
},
],
},

View File

@@ -36,13 +36,8 @@ export const output = {
{
object: 'text',
key: '0',
leaves: [
{
object: 'leaf',
text: 'one',
marks: [],
},
],
text: 'one',
marks: [],
},
],
},
@@ -55,13 +50,8 @@ export const output = {
{
object: 'text',
key: '2',
leaves: [
{
object: 'leaf',
text: 'two',
marks: [],
},
],
text: 'two',
marks: [],
},
],
},

View File

@@ -36,13 +36,8 @@ export const output = {
{
object: 'text',
key: '0',
leaves: [
{
object: 'leaf',
text: 'one',
marks: [],
},
],
text: 'one',
marks: [],
},
],
},
@@ -55,13 +50,8 @@ export const output = {
{
object: 'text',
key: '2',
leaves: [
{
object: 'leaf',
text: 'two',
marks: [],
},
],
text: 'two',
marks: [],
},
],
},

View File

@@ -36,13 +36,8 @@ export const output = {
{
object: 'text',
key: '0',
leaves: [
{
object: 'leaf',
text: 'one',
marks: [],
},
],
text: 'one',
marks: [],
},
],
},
@@ -55,13 +50,8 @@ export const output = {
{
object: 'text',
key: '2',
leaves: [
{
object: 'leaf',
text: 'two',
marks: [],
},
],
text: 'two',
marks: [],
},
],
},

View File

@@ -0,0 +1,81 @@
/** @jsx h */
import h from 'slate-hyperscript'
export const input = (
<value>
<document>
<block type="paragraph">
<text>
<anchor />
</text>
</block>
<block type="paragraph">
<text>
<focus />
</text>
</block>
</document>
</value>
)
export const options = {
preserveSelection: true,
preserveKeys: true,
}
export const output = {
object: 'value',
document: {
object: 'document',
key: '4',
data: {},
nodes: [
{
object: 'block',
key: '1',
type: 'paragraph',
data: {},
nodes: [
{
object: 'text',
key: '0',
text: '',
marks: [],
},
],
},
{
object: 'block',
key: '3',
type: 'paragraph',
data: {},
nodes: [
{
object: 'text',
key: '2',
text: '',
marks: [],
},
],
},
],
},
selection: {
object: 'selection',
anchor: {
object: 'point',
key: '0',
path: [0, 0],
offset: 0,
},
focus: {
object: 'point',
key: '2',
path: [1, 0],
offset: 0,
},
isFocused: true,
marks: null,
},
}

View File

@@ -37,13 +37,8 @@ export const output = {
{
object: 'text',
key: '0',
leaves: [
{
object: 'leaf',
text: 'one',
marks: [],
},
],
text: 'one',
marks: [],
},
],
},
@@ -56,13 +51,8 @@ export const output = {
{
object: 'text',
key: '2',
leaves: [
{
object: 'leaf',
text: 'two',
marks: [],
},
],
text: 'two',
marks: [],
},
],
},
@@ -75,13 +65,8 @@ export const output = {
{
object: 'text',
key: '4',
leaves: [
{
object: 'leaf',
text: 'three',
marks: [],
},
],
text: 'three',
marks: [],
},
],
},

View File

@@ -37,13 +37,8 @@ export const output = {
{
object: 'text',
key: '0',
leaves: [
{
object: 'leaf',
text: 'one',
marks: [],
},
],
text: 'one',
marks: [],
},
],
},
@@ -56,13 +51,8 @@ export const output = {
{
object: 'text',
key: '2',
leaves: [
{
object: 'leaf',
text: 'two',
marks: [],
},
],
text: 'two',
marks: [],
},
],
},
@@ -75,13 +65,8 @@ export const output = {
{
object: 'text',
key: '4',
leaves: [
{
object: 'leaf',
text: 'three',
marks: [],
},
],
text: 'three',
marks: [],
},
],
},

View File

@@ -37,13 +37,8 @@ export const output = {
{
object: 'text',
key: '0',
leaves: [
{
object: 'leaf',
text: 'one',
marks: [],
},
],
text: 'one',
marks: [],
},
],
},
@@ -56,13 +51,8 @@ export const output = {
{
object: 'text',
key: '2',
leaves: [
{
object: 'leaf',
text: 'two',
marks: [],
},
],
text: 'two',
marks: [],
},
],
},
@@ -75,13 +65,8 @@ export const output = {
{
object: 'text',
key: '4',
leaves: [
{
object: 'leaf',
text: 'three',
marks: [],
},
],
text: 'three',
marks: [],
},
],
},

View File

@@ -33,13 +33,8 @@ export const output = {
{
object: 'text',
key: '0',
leaves: [
{
object: 'leaf',
text: 'one',
marks: [],
},
],
text: 'one',
marks: [],
},
],
},

View File

@@ -33,13 +33,8 @@ export const output = {
{
object: 'text',
key: '0',
leaves: [
{
object: 'leaf',
text: 'one',
marks: [],
},
],
text: 'one',
marks: [],
},
],
},

View File

@@ -33,13 +33,8 @@ export const output = {
{
object: 'text',
key: '0',
leaves: [
{
object: 'leaf',
text: 'one',
marks: [],
},
],
text: 'one',
marks: [],
},
],
},

View File

@@ -39,13 +39,8 @@ export const output = {
{
object: 'text',
key: '0',
leaves: [
{
object: 'leaf',
text: 'one',
marks: [],
},
],
text: 'one',
marks: [],
},
],
},

View File

@@ -0,0 +1,62 @@
/** @jsx h */
import h from 'slate-hyperscript'
export const input = (
<value>
<document>
<block type="paragraph">
<text key="a">
<cursor />
</text>
</block>
</document>
</value>
)
export const options = {
preserveSelection: true,
preserveKeys: true,
}
export const output = {
object: 'value',
document: {
object: 'document',
key: '2',
data: {},
nodes: [
{
object: 'block',
key: '1',
type: 'paragraph',
data: {},
nodes: [
{
object: 'text',
key: 'a',
text: '',
marks: [],
},
],
},
],
},
selection: {
object: 'selection',
anchor: {
object: 'point',
key: 'a',
path: [0, 0],
offset: 0,
},
focus: {
object: 'point',
key: 'a',
path: [0, 0],
offset: 0,
},
isFocused: true,
marks: null,
},
}

View File

@@ -0,0 +1,62 @@
/** @jsx h */
import h from 'slate-hyperscript'
export const input = (
<value>
<document>
<block type="paragraph">
<text>
<cursor />
</text>
</block>
</document>
</value>
)
export const options = {
preserveSelection: true,
preserveKeys: true,
}
export const output = {
object: 'value',
document: {
object: 'document',
key: '2',
data: {},
nodes: [
{
object: 'block',
key: '1',
type: 'paragraph',
data: {},
nodes: [
{
object: 'text',
key: '0',
text: '',
marks: [],
},
],
},
],
},
selection: {
object: 'selection',
anchor: {
object: 'point',
key: '0',
path: [0, 0],
offset: 0,
},
focus: {
object: 'point',
key: '0',
path: [0, 0],
offset: 0,
},
isFocused: true,
marks: null,
},
}

View File

@@ -37,13 +37,8 @@ export const output = {
{
object: 'text',
key: '2',
leaves: [
{
object: 'leaf',
text: 'one',
marks: [],
},
],
text: 'one',
marks: [],
},
{
object: 'inline',
@@ -54,26 +49,16 @@ export const output = {
{
object: 'text',
key: '0',
leaves: [
{
object: 'leaf',
text: 'two',
marks: [],
},
],
text: 'two',
marks: [],
},
],
},
{
object: 'text',
key: '3',
leaves: [
{
object: 'leaf',
text: 'three',
marks: [],
},
],
text: 'three',
marks: [],
},
],
},

View File

@@ -37,13 +37,8 @@ export const output = {
{
object: 'text',
key: '2',
leaves: [
{
object: 'leaf',
text: 'one',
marks: [],
},
],
text: 'one',
marks: [],
},
{
object: 'inline',
@@ -54,26 +49,16 @@ export const output = {
{
object: 'text',
key: '0',
leaves: [
{
object: 'leaf',
text: 'two',
marks: [],
},
],
text: 'two',
marks: [],
},
],
},
{
object: 'text',
key: '3',
leaves: [
{
object: 'leaf',
text: 'three',
marks: [],
},
],
text: 'three',
marks: [],
},
],
},

View File

@@ -37,13 +37,8 @@ export const output = {
{
object: 'text',
key: '2',
leaves: [
{
object: 'leaf',
text: 'one',
marks: [],
},
],
text: 'one',
marks: [],
},
{
object: 'inline',
@@ -54,26 +49,16 @@ export const output = {
{
object: 'text',
key: '0',
leaves: [
{
object: 'leaf',
text: 'two',
marks: [],
},
],
text: 'two',
marks: [],
},
],
},
{
object: 'text',
key: '3',
leaves: [
{
object: 'leaf',
text: 'three',
marks: [],
},
],
text: 'three',
marks: [],
},
],
},

View File

@@ -33,13 +33,8 @@ export const output = {
{
object: 'text',
key: '0',
leaves: [
{
object: 'leaf',
text: 'one',
marks: [],
},
],
text: 'one',
marks: [],
},
],
},

View File

@@ -0,0 +1,73 @@
/** @jsx h */
import h from 'slate-hyperscript'
export const input = (
<value>
<document>
<block type="paragraph">
<mark type="bold">one</mark>
<cursor />two
</block>
</document>
</value>
)
export const options = {
preserveSelection: true,
preserveKeys: true,
}
export const output = {
object: 'value',
document: {
object: 'document',
data: {},
key: '3',
nodes: [
{
object: 'block',
key: '2',
type: 'paragraph',
data: {},
nodes: [
{
object: 'text',
text: 'one',
key: '0',
marks: [
{
object: 'mark',
type: 'bold',
data: {},
},
],
},
{
object: 'text',
key: '1',
text: 'two',
marks: [],
},
],
},
],
},
selection: {
object: 'selection',
anchor: {
object: 'point',
key: '1',
path: [0, 1],
offset: 0,
},
focus: {
object: 'point',
key: '1',
path: [0, 1],
offset: 0,
},
isFocused: true,
marks: null,
},
}

View File

@@ -26,41 +26,38 @@ export const output = {
document: {
object: 'document',
data: {},
key: '2',
key: '4',
nodes: [
{
object: 'block',
key: '1',
key: '3',
type: 'paragraph',
data: {},
nodes: [
{
object: 'text',
key: '1',
text: 'one',
marks: [],
},
{
object: 'text',
text: 'two',
key: '0',
leaves: [
marks: [
{
object: 'leaf',
text: 'one',
marks: [],
},
{
object: 'leaf',
text: 'two',
marks: [
{
object: 'mark',
type: 'bold',
data: {},
},
],
},
{
object: 'leaf',
text: 'three',
marks: [],
object: 'mark',
type: 'bold',
data: {},
},
],
},
{
object: 'text',
key: '2',
text: 'three',
marks: [],
},
],
},
],
@@ -70,14 +67,14 @@ export const output = {
anchor: {
object: 'point',
key: '0',
path: [0, 0],
offset: 6,
path: [0, 1],
offset: 3,
},
focus: {
object: 'point',
key: '0',
path: [0, 0],
offset: 6,
path: [0, 1],
offset: 3,
},
isFocused: true,
marks: null,

View File

@@ -26,41 +26,38 @@ export const output = {
document: {
object: 'document',
data: {},
key: '2',
key: '4',
nodes: [
{
object: 'block',
key: '1',
key: '3',
type: 'paragraph',
data: {},
nodes: [
{
object: 'text',
key: '1',
text: 'one',
marks: [],
},
{
object: 'text',
key: '0',
leaves: [
text: 'two',
marks: [
{
object: 'leaf',
text: 'one',
marks: [],
},
{
object: 'leaf',
text: 'two',
marks: [
{
object: 'mark',
type: 'bold',
data: {},
},
],
},
{
object: 'leaf',
text: 'three',
marks: [],
object: 'mark',
type: 'bold',
data: {},
},
],
},
{
object: 'text',
key: '2',
text: 'three',
marks: [],
},
],
},
],
@@ -70,14 +67,14 @@ export const output = {
anchor: {
object: 'point',
key: '0',
path: [0, 0],
offset: 3,
path: [0, 1],
offset: 0,
},
focus: {
object: 'point',
key: '0',
path: [0, 0],
offset: 3,
path: [0, 1],
offset: 0,
},
isFocused: true,
marks: null,

View File

@@ -26,41 +26,38 @@ export const output = {
document: {
object: 'document',
data: {},
key: '2',
key: '4',
nodes: [
{
object: 'block',
key: '1',
key: '3',
type: 'paragraph',
data: {},
nodes: [
{
object: 'text',
key: '1',
text: 'one',
marks: [],
},
{
object: 'text',
key: '0',
leaves: [
text: 'two',
marks: [
{
object: 'leaf',
text: 'one',
marks: [],
},
{
object: 'leaf',
text: 'two',
marks: [
{
object: 'mark',
type: 'bold',
data: {},
},
],
},
{
object: 'leaf',
text: 'three',
marks: [],
object: 'mark',
type: 'bold',
data: {},
},
],
},
{
object: 'text',
key: '2',
text: 'three',
marks: [],
},
],
},
],
@@ -70,14 +67,14 @@ export const output = {
anchor: {
object: 'point',
key: '0',
path: [0, 0],
offset: 4,
path: [0, 1],
offset: 1,
},
focus: {
object: 'point',
key: '0',
path: [0, 0],
offset: 4,
path: [0, 1],
offset: 1,
},
isFocused: true,
marks: null,

View File

@@ -33,13 +33,8 @@ export const output = {
{
object: 'text',
key: '0',
leaves: [
{
object: 'leaf',
text: 'one',
marks: [],
},
],
text: 'one',
marks: [],
},
],
},

View File

@@ -0,0 +1,68 @@
/** @jsx h */
import { createHyperscript } from 'slate-hyperscript'
const h = createHyperscript({
blocks: {
paragraph: 'paragraph',
},
marks: {
b: 'bold',
},
})
export const input = (
<value>
<document>
<paragraph>
<text>one</text>
<b>two</b>
<b>three</b>
</paragraph>
</document>
</value>
)
export const output = {
object: 'value',
document: {
object: 'document',
data: {},
nodes: [
{
object: 'block',
type: 'paragraph',
data: {},
nodes: [
{
object: 'text',
text: 'one',
marks: [],
},
{
object: 'text',
text: 'two',
marks: [
{
object: 'mark',
type: 'bold',
data: {},
},
],
},
{
object: 'text',
text: 'three',
marks: [
{
object: 'mark',
type: 'bold',
data: {},
},
],
},
],
},
],
},
}

View File

@@ -40,30 +40,25 @@ export const output = {
nodes: [
{
object: 'text',
leaves: [
text: 'A string of ',
marks: [],
},
{
object: 'text',
text: 'bold',
marks: [
{
object: 'leaf',
text: 'A string of ',
marks: [],
},
{
object: 'leaf',
text: 'bold',
marks: [
{
object: 'mark',
type: 'bold',
data: {},
},
],
},
{
object: 'leaf',
text: ' in a ',
marks: [],
object: 'mark',
type: 'bold',
data: {},
},
],
},
{
object: 'text',
text: ' in a ',
marks: [],
},
{
object: 'inline',
type: 'link',
@@ -73,25 +68,15 @@ export const output = {
nodes: [
{
object: 'text',
leaves: [
{
object: 'leaf',
text: 'Slate',
marks: [],
},
],
text: 'Slate',
marks: [],
},
],
},
{
object: 'text',
leaves: [
{
object: 'leaf',
text: ' editor!',
marks: [],
},
],
text: ' editor!',
marks: [],
},
],
},

View File

@@ -30,25 +30,20 @@ export const output = {
object: 'value',
document: {
object: 'document',
key: '2',
key: '3',
data: {},
nodes: [
{
object: 'block',
key: '1',
key: '2',
type: 'paragraph',
data: {},
nodes: [
{
object: 'text',
key: '0',
leaves: [
{
object: 'leaf',
text: 'onetwothree',
marks: [],
},
],
key: '1',
text: 'onetwothree',
marks: [],
},
],
},
@@ -59,13 +54,13 @@ export const output = {
object: 'decoration',
anchor: {
object: 'point',
key: '0',
key: '1',
path: [0, 0],
offset: 3,
},
focus: {
object: 'point',
key: '0',
key: '1',
path: [0, 0],
offset: 6,
},

View File

@@ -45,13 +45,8 @@ export const output = {
{
object: 'text',
key: '0',
leaves: [
{
object: 'leaf',
text: 'one',
marks: [],
},
],
text: 'one',
marks: [],
},
],
},
@@ -64,13 +59,8 @@ export const output = {
{
object: 'text',
key: '2',
leaves: [
{
object: 'leaf',
text: 'two',
marks: [],
},
],
text: 'two',
marks: [],
},
],
},

View File

@@ -11,13 +11,8 @@ export const output = {
nodes: [
{
object: 'text',
leaves: [
{
object: 'leaf',
text: 'word',
marks: [],
},
],
text: 'word',
marks: [],
},
],
}

View File

@@ -25,25 +25,20 @@ export const output = {
object: 'value',
document: {
object: 'document',
key: '1',
key: '2',
data: {},
nodes: [
{
object: 'block',
key: '0',
key: '1',
type: 'paragraph',
data: {},
nodes: [
{
object: 'text',
key: 'a',
leaves: [
{
object: 'leaf',
text: 'two',
marks: [],
},
],
text: 'two',
marks: [],
},
],
},

View File

@@ -6,11 +6,6 @@ export const input = <text />
export const output = {
object: 'text',
leaves: [
{
object: 'leaf',
text: '',
marks: [],
},
],
text: '',
marks: [],
}

View File

@@ -6,11 +6,6 @@ export const input = <text>word</text>
export const output = {
object: 'text',
leaves: [
{
object: 'leaf',
text: 'word',
marks: [],
},
],
text: 'word',
marks: [],
}

View File

@@ -0,0 +1,15 @@
/** @jsx h */
import h from 'slate-hyperscript'
export const input = (
<text>
<text>word</text>
</text>
)
export const output = {
object: 'text',
text: 'word',
marks: [],
}

View File

@@ -11,11 +11,6 @@ export const options = {
export const output = {
object: 'text',
key: 'a',
leaves: [
{
object: 'leaf',
text: 'word',
marks: [],
},
],
text: 'word',
marks: [],
}