1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-31 10:51:44 +02:00

Add controller (#2221)

* fold Stack into Editor

* switch Change objects to be tied to editors, not values

* introduce controller

* add the "commands" concept

* convert history into commands on `value.data`

* add the ability to not normalize on editor creation/setting

* convert schema to a mutable constructor

* add editor.command method

* convert plugin handlers to receive `next`

* switch commands to use the onCommand middleware

* add queries support, convert schema to queries

* split out browser plugin

* remove noop util

* fixes

* fixes

* start fixing tests, refactor hyperscript to be more literal

* fix slate-html-serializer tests

* fix schema tests with hyperscript

* fix text model tests with hyperscript

* fix more tests

* get all tests passing

* fix lint

* undo decorations example update

* update examples

* small changes to the api to make it nicer

* update docs

* update commands/queries plugin logic

* change normalizeNode and validateNode to be middleware

* fix decoration removal

* rename commands tests

* add useful errors to existing APIs

* update changelogs

* cleanup

* fixes

* update docs

* add editor docs
This commit is contained in:
Ian Storm Taylor
2018-10-09 14:03:27 -07:00
committed by GitHub
parent e6372d829a
commit 7a71de387c
709 changed files with 6073 additions and 5927 deletions

View File

@@ -0,0 +1,12 @@
/** @jsx h */
import h from 'slate-hyperscript'
export const input = <block type="paragraph" />
export const output = {
object: 'block',
type: 'paragraph',
data: {},
nodes: [],
}

View File

@@ -0,0 +1,23 @@
/** @jsx h */
import h from 'slate-hyperscript'
export const input = (
<block type="paragraph">
<inline type="link" />
</block>
)
export const output = {
object: 'block',
type: 'paragraph',
data: {},
nodes: [
{
object: 'inline',
type: 'link',
data: {},
nodes: [],
},
],
}

View File

@@ -3,18 +3,19 @@
import h from 'slate-hyperscript'
export const input = (
<document>
<block type="paragraph">word</block>
</document>
<block type="paragraph">
<inline type="link">word</inline>
</block>
)
export const output = {
object: 'document',
object: 'block',
type: 'paragraph',
data: {},
nodes: [
{
object: 'block',
type: 'paragraph',
object: 'inline',
type: 'link',
data: {},
nodes: [
{

View File

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

View File

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

View File

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

View File

@@ -0,0 +1,23 @@
/** @jsx h */
import h from 'slate-hyperscript'
export const input = <block type="paragraph">word</block>
export const output = {
object: 'block',
type: 'paragraph',
data: {},
nodes: [
{
object: 'text',
leaves: [
{
object: 'leaf',
text: 'word',
marks: [],
},
],
},
],
}

View File

@@ -0,0 +1,27 @@
/** @jsx h */
import h from 'slate-hyperscript'
export const input = (
<block type="paragraph">
<text />
</block>
)
export const output = {
object: 'block',
type: 'paragraph',
data: {},
nodes: [
{
object: 'text',
leaves: [
{
object: 'leaf',
text: '',
marks: [],
},
],
},
],
}

View File

@@ -0,0 +1,27 @@
/** @jsx h */
import h from 'slate-hyperscript'
export const input = (
<block type="paragraph">
<text>word</text>
</block>
)
export const output = {
object: 'block',
type: 'paragraph',
data: {},
nodes: [
{
object: 'text',
leaves: [
{
object: 'leaf',
text: 'word',
marks: [],
},
],
},
],
}

View File

@@ -21,7 +21,7 @@ export const output = {
object: 'value',
document: {
object: 'document',
key: '3',
key: '2',
data: {},
nodes: [
{

View File

@@ -6,14 +6,18 @@ export const input = (
<value>
<document>
<block type="paragraph">
<text />
<inline type="link">
on<anchor />e
</inline>
<text />
</block>
<block type="paragraph">
<text />
<inline type="link">
t<focus />wo
</inline>
<text />
</block>
</document>
</value>
@@ -33,13 +37,13 @@ export const output = {
nodes: [
{
object: 'block',
key: '3',
key: '4',
type: 'paragraph',
data: {},
nodes: [
{
object: 'text',
key: '13',
key: '0',
leaves: [
{
object: 'leaf',
@@ -50,13 +54,13 @@ export const output = {
},
{
object: 'inline',
key: '1',
key: '2',
type: 'link',
data: {},
nodes: [
{
object: 'text',
key: '0',
key: '1',
leaves: [
{
object: 'leaf',
@@ -69,7 +73,7 @@ export const output = {
},
{
object: 'text',
key: '14',
key: '3',
leaves: [
{
object: 'leaf',
@@ -82,13 +86,13 @@ export const output = {
},
{
object: 'block',
key: '7',
key: '9',
type: 'paragraph',
data: {},
nodes: [
{
object: 'text',
key: '11',
key: '5',
leaves: [
{
object: 'leaf',
@@ -99,13 +103,13 @@ export const output = {
},
{
object: 'inline',
key: '5',
key: '7',
type: 'link',
data: {},
nodes: [
{
object: 'text',
key: '4',
key: '6',
leaves: [
{
object: 'leaf',
@@ -118,7 +122,7 @@ export const output = {
},
{
object: 'text',
key: '12',
key: '8',
leaves: [
{
object: 'leaf',
@@ -135,13 +139,13 @@ export const output = {
object: 'selection',
anchor: {
object: 'point',
key: '0',
key: '1',
path: [0, 1, 0],
offset: 2,
},
focus: {
object: 'point',
key: '4',
key: '6',
path: [1, 1, 0],
offset: 1,
},

View File

@@ -24,7 +24,7 @@ export const output = {
object: 'value',
document: {
object: 'document',
key: '6',
key: '4',
data: {},
nodes: [
{

View File

@@ -24,7 +24,7 @@ export const output = {
object: 'value',
document: {
object: 'document',
key: '6',
key: '4',
data: {},
nodes: [
{

View File

@@ -24,7 +24,7 @@ export const output = {
object: 'value',
document: {
object: 'document',
key: '6',
key: '4',
data: {},
nodes: [
{

View File

@@ -25,7 +25,7 @@ export const output = {
object: 'value',
document: {
object: 'document',
key: '9',
key: '6',
data: {},
nodes: [
{

View File

@@ -25,7 +25,7 @@ export const output = {
object: 'value',
document: {
object: 'document',
key: '9',
key: '6',
data: {},
nodes: [
{

View File

@@ -25,7 +25,7 @@ export const output = {
object: 'value',
document: {
object: 'document',
key: '9',
key: '6',
data: {},
nodes: [
{

View File

@@ -21,7 +21,7 @@ export const output = {
object: 'value',
document: {
object: 'document',
key: '3',
key: '2',
data: {},
nodes: [
{

View File

@@ -21,7 +21,7 @@ export const output = {
object: 'value',
document: {
object: 'document',
key: '3',
key: '2',
data: {},
nodes: [
{

View File

@@ -21,7 +21,7 @@ export const output = {
object: 'value',
document: {
object: 'document',
key: '3',
key: '2',
data: {},
nodes: [
{

View File

@@ -27,7 +27,7 @@ export const output = {
object: 'value',
document: {
object: 'document',
key: '3',
key: '2',
data: {},
nodes: [
{

View File

@@ -26,7 +26,7 @@ export const output = {
document: {
object: 'document',
data: {},
key: '6',
key: '5',
nodes: [
{
object: 'block',

View File

@@ -26,7 +26,7 @@ export const output = {
document: {
object: 'document',
data: {},
key: '6',
key: '5',
nodes: [
{
object: 'block',

View File

@@ -26,7 +26,7 @@ export const output = {
document: {
object: 'document',
data: {},
key: '6',
key: '5',
nodes: [
{
object: 'block',

View File

@@ -26,7 +26,7 @@ export const output = {
document: {
object: 'document',
data: {},
key: '3',
key: '2',
nodes: [
{
object: 'block',

View File

@@ -26,7 +26,7 @@ export const output = {
document: {
object: 'document',
data: {},
key: '3',
key: '2',
nodes: [
{
object: 'block',

View File

@@ -26,7 +26,7 @@ export const output = {
document: {
object: 'document',
data: {},
key: '3',
key: '2',
nodes: [
{
object: 'block',

View File

@@ -101,18 +101,7 @@ export const output = {
data: {
src: 'https://...',
},
nodes: [
{
object: 'text',
leaves: [
{
object: 'leaf',
text: '',
marks: [],
},
],
},
],
nodes: [],
},
],
},

View File

@@ -30,7 +30,7 @@ export const output = {
object: 'value',
document: {
object: 'document',
key: '3',
key: '2',
data: {},
nodes: [
{

View File

@@ -33,7 +33,7 @@ export const output = {
object: 'value',
document: {
object: 'document',
key: '6',
key: '4',
data: {},
nodes: [
{

View File

@@ -0,0 +1,11 @@
/** @jsx h */
import h from 'slate-hyperscript'
export const input = <document />
export const output = {
object: 'document',
data: {},
nodes: [],
}

View File

@@ -0,0 +1,12 @@
/** @jsx h */
import h from 'slate-hyperscript'
export const input = <inline type="link" />
export const output = {
object: 'inline',
type: 'link',
data: {},
nodes: [],
}

View File

@@ -0,0 +1,23 @@
/** @jsx h */
import h from 'slate-hyperscript'
export const input = <inline type="link">word</inline>
export const output = {
object: 'inline',
type: 'link',
data: {},
nodes: [
{
object: 'text',
leaves: [
{
object: 'leaf',
text: 'word',
marks: [],
},
],
},
],
}

View File

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

View File

@@ -1,39 +0,0 @@
/** @jsx h */
import h from 'slate-hyperscript'
export const input = (
<value>
<document>
<block type="paragraph">word</block>
<text>invalid</text>
</document>
</value>
)
export const output = {
object: 'value',
document: {
object: 'document',
data: {},
nodes: [
{
object: 'block',
type: 'paragraph',
data: {},
nodes: [
{
object: 'text',
leaves: [
{
object: 'leaf',
text: 'word',
marks: [],
},
],
},
],
},
],
},
}

View File

@@ -1,49 +0,0 @@
/** @jsx h */
import h from 'slate-hyperscript'
export const input = (
<value normalize={false}>
<document>
<block type="paragraph">word</block>
<text>invalid</text>
</document>
</value>
)
export const output = {
object: 'value',
document: {
object: 'document',
data: {},
nodes: [
{
object: 'block',
type: 'paragraph',
data: {},
nodes: [
{
object: 'text',
leaves: [
{
object: 'leaf',
text: 'word',
marks: [],
},
],
},
],
},
{
object: 'text',
leaves: [
{
object: 'leaf',
text: 'invalid',
marks: [],
},
],
},
],
},
}

View File

@@ -6,7 +6,7 @@ export const input = (
<value>
<document>
<block type="paragraph">
one<text key="a">two</text>three
<text key="a">two</text>
</block>
</document>
<selection>
@@ -25,7 +25,7 @@ export const output = {
object: 'value',
document: {
object: 'document',
key: '2',
key: '1',
data: {},
nodes: [
{
@@ -40,7 +40,7 @@ export const output = {
leaves: [
{
object: 'leaf',
text: 'onetwothree',
text: 'two',
marks: [],
},
],

View File

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

View File

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

View File

@@ -1,73 +0,0 @@
/** @jsx h */
import h from 'slate-hyperscript'
export const input = (
<document>
<block type="paragraph">
Cat <inline type="link">is</inline>
<text key="a"> cute</text>
</block>
</document>
)
export const options = {
preserveKeys: true,
}
export const output = {
object: 'document',
key: '6',
data: {},
nodes: [
{
object: 'block',
key: '4',
type: 'paragraph',
data: {},
nodes: [
{
object: 'text',
key: '2',
leaves: [
{
object: 'leaf',
text: 'Cat ',
marks: [],
},
],
},
{
object: 'inline',
key: '1',
type: 'link',
data: {},
nodes: [
{
object: 'text',
key: '0',
leaves: [
{
object: 'leaf',
text: 'is',
marks: [],
},
],
},
],
},
{
object: 'text',
key: 'a',
leaves: [
{
object: 'leaf',
text: ' cute',
marks: [],
},
],
},
],
},
],
}

View File

@@ -0,0 +1,21 @@
/** @jsx h */
import h from 'slate-hyperscript'
export const input = <text key="a">word</text>
export const options = {
preserveKeys: true,
}
export const output = {
object: 'text',
key: 'a',
leaves: [
{
object: 'leaf',
text: 'word',
marks: [],
},
],
}

View File

@@ -1,109 +0,0 @@
/** @jsx h */
import h from 'slate-hyperscript'
export const input = (
<value>
<document>
<block type="paragraph">
A string of <mark type="bold">bold</mark> in a{' '}
<inline type="link" data={{ src: 'http://slatejs.org' }}>
Slate
</inline>{' '}
editor!
</block>
<block type="image" data={{ src: 'https://...' }} />
</document>
</value>
)
export const output = {
object: 'value',
document: {
object: 'document',
data: {},
nodes: [
{
object: 'block',
type: 'paragraph',
data: {},
nodes: [
{
object: 'text',
leaves: [
{
object: 'leaf',
text: 'A string of ',
marks: [],
},
{
object: 'leaf',
text: 'bold',
marks: [
{
object: 'mark',
type: 'bold',
data: {},
},
],
},
{
object: 'leaf',
text: ' in a ',
marks: [],
},
],
},
{
object: 'inline',
type: 'link',
data: {
src: 'http://slatejs.org',
},
nodes: [
{
object: 'text',
leaves: [
{
object: 'leaf',
text: 'Slate',
marks: [],
},
],
},
],
},
{
object: 'text',
leaves: [
{
object: 'leaf',
text: ' editor!',
marks: [],
},
],
},
],
},
{
object: 'block',
type: 'image',
data: {
src: 'https://...',
},
nodes: [
{
object: 'text',
leaves: [
{
object: 'leaf',
text: '',
marks: [],
},
],
},
],
},
],
},
}