1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-30 02:19:52 +02:00

Add a Point model, and standardize Range/Point logic (#2035)

* add `Node.createRange` for range resolution

* fix lint

* fix range offset defaults to be `null`

* change `isBackward` to be computed from paths

* remove debuggers

* add point model, update range with deprecations, update hyperscript

* got all tests passing

* get tests passing, convert changes

* fix lint

* fix examples

* update deprecations

* update docs

* update slate-react point utils

* fix document.normalizeRange

* fix lint
This commit is contained in:
Ian Storm Taylor
2018-08-03 14:45:40 -07:00
committed by GitHub
parent b3535e11df
commit 08f270dc1b
95 changed files with 4199 additions and 1902 deletions

View File

@@ -48,12 +48,18 @@ export const output = {
},
selection: {
object: 'range',
anchorKey: '0',
anchorPath: [0, 0],
anchorOffset: 1,
focusKey: '0',
focusPath: [0, 0],
focusOffset: 3,
anchor: {
object: 'point',
key: '0',
path: [0, 0],
offset: 1,
},
focus: {
object: 'point',
key: '0',
path: [0, 0],
offset: 3,
},
isFocused: true,
isAtomic: false,
marks: null,

View File

@@ -137,12 +137,18 @@ export const output = {
},
selection: {
object: 'range',
anchorKey: '0',
anchorPath: [0, 1, 0],
anchorOffset: 2,
focusKey: '4',
focusPath: [1, 1, 0],
focusOffset: 1,
anchor: {
object: 'point',
key: '0',
path: [0, 1, 0],
offset: 2,
},
focus: {
object: 'point',
key: '4',
path: [1, 1, 0],
offset: 1,
},
isFocused: true,
isAtomic: false,
marks: null,

View File

@@ -71,12 +71,18 @@ export const output = {
},
selection: {
object: 'range',
anchorKey: '0',
anchorPath: [0, 0],
anchorOffset: 3,
focusKey: '2',
focusPath: [1, 0],
focusOffset: 3,
anchor: {
object: 'point',
key: '0',
path: [0, 0],
offset: 3,
},
focus: {
object: 'point',
key: '2',
path: [1, 0],
offset: 3,
},
isFocused: true,
isAtomic: false,
marks: null,

View File

@@ -71,12 +71,18 @@ export const output = {
},
selection: {
object: 'range',
anchorKey: '0',
anchorPath: [0, 0],
anchorOffset: 2,
focusKey: '2',
focusPath: [1, 0],
focusOffset: 1,
anchor: {
object: 'point',
key: '0',
path: [0, 0],
offset: 2,
},
focus: {
object: 'point',
key: '2',
path: [1, 0],
offset: 1,
},
isFocused: true,
isAtomic: false,
marks: null,

View File

@@ -71,12 +71,18 @@ export const output = {
},
selection: {
object: 'range',
anchorKey: '0',
anchorPath: [0, 0],
anchorOffset: 0,
focusKey: '2',
focusPath: [1, 0],
focusOffset: 0,
anchor: {
object: 'point',
key: '0',
path: [0, 0],
offset: 0,
},
focus: {
object: 'point',
key: '2',
path: [1, 0],
offset: 0,
},
isFocused: true,
isAtomic: false,
marks: null,

View File

@@ -92,12 +92,18 @@ export const output = {
},
selection: {
object: 'range',
anchorKey: '0',
anchorPath: [0, 0],
anchorOffset: 3,
focusKey: '4',
focusPath: [2, 0],
focusOffset: 5,
anchor: {
object: 'point',
key: '0',
path: [0, 0],
offset: 3,
},
focus: {
object: 'point',
key: '4',
path: [2, 0],
offset: 5,
},
isFocused: true,
isAtomic: false,
marks: null,

View File

@@ -92,12 +92,18 @@ export const output = {
},
selection: {
object: 'range',
anchorKey: '0',
anchorPath: [0, 0],
anchorOffset: 2,
focusKey: '4',
focusPath: [2, 0],
focusOffset: 1,
anchor: {
object: 'point',
key: '0',
path: [0, 0],
offset: 2,
},
focus: {
object: 'point',
key: '4',
path: [2, 0],
offset: 1,
},
isFocused: true,
isAtomic: false,
marks: null,

View File

@@ -92,12 +92,18 @@ export const output = {
},
selection: {
object: 'range',
anchorKey: '0',
anchorPath: [0, 0],
anchorOffset: 0,
focusKey: '4',
focusPath: [2, 0],
focusOffset: 0,
anchor: {
object: 'point',
key: '0',
path: [0, 0],
offset: 0,
},
focus: {
object: 'point',
key: '4',
path: [2, 0],
offset: 0,
},
isFocused: true,
isAtomic: false,
marks: null,

View File

@@ -48,12 +48,18 @@ export const output = {
},
selection: {
object: 'range',
anchorKey: '0',
anchorPath: [0, 0],
anchorOffset: 3,
focusKey: '0',
focusPath: [0, 0],
focusOffset: 3,
anchor: {
object: 'point',
key: '0',
path: [0, 0],
offset: 3,
},
focus: {
object: 'point',
key: '0',
path: [0, 0],
offset: 3,
},
isFocused: true,
isAtomic: false,
marks: null,

View File

@@ -48,12 +48,18 @@ export const output = {
},
selection: {
object: 'range',
anchorKey: '0',
anchorPath: [0, 0],
anchorOffset: 1,
focusKey: '0',
focusPath: [0, 0],
focusOffset: 1,
anchor: {
object: 'point',
key: '0',
path: [0, 0],
offset: 1,
},
focus: {
object: 'point',
key: '0',
path: [0, 0],
offset: 1,
},
isFocused: true,
isAtomic: false,
marks: null,

View File

@@ -48,12 +48,18 @@ export const output = {
},
selection: {
object: 'range',
anchorKey: '0',
anchorPath: [0, 0],
anchorOffset: 0,
focusKey: '0',
focusPath: [0, 0],
focusOffset: 0,
anchor: {
object: 'point',
key: '0',
path: [0, 0],
offset: 0,
},
focus: {
object: 'point',
key: '0',
path: [0, 0],
offset: 0,
},
isFocused: true,
isAtomic: false,
marks: null,

View File

@@ -54,12 +54,18 @@ export const output = {
},
selection: {
object: 'range',
anchorKey: '0',
anchorPath: [0, 0],
anchorOffset: 1,
focusKey: '0',
focusPath: [0, 0],
focusOffset: 1,
anchor: {
object: 'point',
key: '0',
path: [0, 0],
offset: 1,
},
focus: {
object: 'point',
key: '0',
path: [0, 0],
offset: 1,
},
isFocused: true,
isAtomic: false,
marks: null,

View File

@@ -0,0 +1,102 @@
/** @jsx h */
import h from '../..'
export const input = (
<value>
<document>
<block type="paragraph">
one
<inline type="link">
two<cursor />
</inline>
three
</block>
</document>
</value>
)
export const options = {
preserveSelection: true,
preserveKeys: true,
}
export const output = {
object: 'value',
document: {
object: 'document',
data: {},
key: '6',
nodes: [
{
object: 'block',
key: '4',
type: 'paragraph',
isVoid: false,
data: {},
nodes: [
{
object: 'text',
key: '2',
leaves: [
{
object: 'leaf',
text: 'one',
marks: [],
},
],
},
{
object: 'inline',
key: '1',
type: 'link',
isVoid: false,
data: {},
nodes: [
{
object: 'text',
key: '0',
leaves: [
{
object: 'leaf',
text: 'two',
marks: [],
},
],
},
],
},
{
object: 'text',
key: '3',
leaves: [
{
object: 'leaf',
text: 'three',
marks: [],
},
],
},
],
},
],
},
selection: {
object: 'range',
anchor: {
object: 'point',
key: '0',
path: [0, 1, 0],
offset: 3,
},
focus: {
object: 'point',
key: '0',
path: [0, 1, 0],
offset: 3,
},
isFocused: true,
isAtomic: false,
marks: null,
},
}

View File

@@ -0,0 +1,102 @@
/** @jsx h */
import h from '../..'
export const input = (
<value>
<document>
<block type="paragraph">
one
<inline type="link">
<cursor />two
</inline>
three
</block>
</document>
</value>
)
export const options = {
preserveSelection: true,
preserveKeys: true,
}
export const output = {
object: 'value',
document: {
object: 'document',
data: {},
key: '6',
nodes: [
{
object: 'block',
key: '4',
type: 'paragraph',
isVoid: false,
data: {},
nodes: [
{
object: 'text',
key: '2',
leaves: [
{
object: 'leaf',
text: 'one',
marks: [],
},
],
},
{
object: 'inline',
key: '1',
type: 'link',
isVoid: false,
data: {},
nodes: [
{
object: 'text',
key: '0',
leaves: [
{
object: 'leaf',
text: 'two',
marks: [],
},
],
},
],
},
{
object: 'text',
key: '3',
leaves: [
{
object: 'leaf',
text: 'three',
marks: [],
},
],
},
],
},
],
},
selection: {
object: 'range',
anchor: {
object: 'point',
key: '0',
path: [0, 1, 0],
offset: 0,
},
focus: {
object: 'point',
key: '0',
path: [0, 1, 0],
offset: 0,
},
isFocused: true,
isAtomic: false,
marks: null,
},
}

View File

@@ -83,12 +83,18 @@ export const output = {
},
selection: {
object: 'range',
anchorKey: '0',
anchorPath: [0, 1, 0],
anchorOffset: 1,
focusKey: '0',
focusPath: [0, 1, 0],
focusOffset: 1,
anchor: {
object: 'point',
key: '0',
path: [0, 1, 0],
offset: 1,
},
focus: {
object: 'point',
key: '0',
path: [0, 1, 0],
offset: 1,
},
isFocused: true,
isAtomic: false,
marks: null,

View File

@@ -0,0 +1,87 @@
/** @jsx h */
import h from '../..'
export const input = (
<value>
<document>
<block type="paragraph">
one
<mark type="bold">
two<cursor />
</mark>
three
</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: '1',
type: 'paragraph',
isVoid: false,
data: {},
nodes: [
{
object: 'text',
key: '0',
leaves: [
{
object: 'leaf',
text: 'one',
marks: [],
},
{
object: 'leaf',
text: 'two',
marks: [
{
object: 'mark',
type: 'bold',
data: {},
},
],
},
{
object: 'leaf',
text: 'three',
marks: [],
},
],
},
],
},
],
},
selection: {
object: 'range',
anchor: {
object: 'point',
key: '0',
path: [0, 0],
offset: 6,
},
focus: {
object: 'point',
key: '0',
path: [0, 0],
offset: 6,
},
isFocused: true,
isAtomic: false,
marks: null,
},
}

View File

@@ -0,0 +1,87 @@
/** @jsx h */
import h from '../..'
export const input = (
<value>
<document>
<block type="paragraph">
one
<mark type="bold">
<cursor />two
</mark>
three
</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: '1',
type: 'paragraph',
isVoid: false,
data: {},
nodes: [
{
object: 'text',
key: '0',
leaves: [
{
object: 'leaf',
text: 'one',
marks: [],
},
{
object: 'leaf',
text: 'two',
marks: [
{
object: 'mark',
type: 'bold',
data: {},
},
],
},
{
object: 'leaf',
text: 'three',
marks: [],
},
],
},
],
},
],
},
selection: {
object: 'range',
anchor: {
object: 'point',
key: '0',
path: [0, 0],
offset: 3,
},
focus: {
object: 'point',
key: '0',
path: [0, 0],
offset: 3,
},
isFocused: true,
isAtomic: false,
marks: null,
},
}

View File

@@ -0,0 +1,87 @@
/** @jsx h */
import h from '../..'
export const input = (
<value>
<document>
<block type="paragraph">
one
<mark type="bold">
t<cursor />wo
</mark>
three
</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: '1',
type: 'paragraph',
isVoid: false,
data: {},
nodes: [
{
object: 'text',
key: '0',
leaves: [
{
object: 'leaf',
text: 'one',
marks: [],
},
{
object: 'leaf',
text: 'two',
marks: [
{
object: 'mark',
type: 'bold',
data: {},
},
],
},
{
object: 'leaf',
text: 'three',
marks: [],
},
],
},
],
},
],
},
selection: {
object: 'range',
anchor: {
object: 'point',
key: '0',
path: [0, 0],
offset: 4,
},
focus: {
object: 'point',
key: '0',
path: [0, 0],
offset: 4,
},
isFocused: true,
isAtomic: false,
marks: null,
},
}

View File

@@ -0,0 +1,107 @@
/** @jsx h */
import { createHyperscript } from '../..'
const h = createHyperscript({
blocks: {
paragraph: 'paragraph',
},
decorators: {
highlight: 'highlight',
},
})
export const input = (
<value>
<document>
<block type="paragraph">
o<highlight key="a" />ne
</block>
<block type="paragraph">
tw<highlight key="a" />o
</block>
</document>
</value>
)
export const options = {
preserveDecorations: true,
preserveKeys: true,
}
export const output = {
object: 'value',
document: {
object: 'document',
key: '6',
data: {},
nodes: [
{
object: 'block',
key: '1',
type: 'paragraph',
isVoid: false,
data: {},
nodes: [
{
object: 'text',
key: '0',
leaves: [
{
object: 'leaf',
text: 'one',
marks: [],
},
],
},
],
},
{
object: 'block',
key: '3',
type: 'paragraph',
isVoid: false,
data: {},
nodes: [
{
object: 'text',
key: '2',
leaves: [
{
object: 'leaf',
text: 'two',
marks: [],
},
],
},
],
},
],
},
decorations: [
{
object: 'range',
anchor: {
object: 'point',
key: '0',
path: [0, 0],
offset: 1,
},
focus: {
object: 'point',
key: '2',
path: [1, 0],
offset: 2,
},
isFocused: false,
isAtomic: false,
marks: [
{
object: 'mark',
type: 'highlight',
data: {},
},
],
},
],
}

View File

@@ -58,12 +58,18 @@ export const output = {
decorations: [
{
object: 'range',
anchorKey: '0',
anchorPath: [0, 0],
anchorOffset: 3,
focusKey: '0',
focusPath: [0, 0],
focusOffset: 6,
anchor: {
object: 'point',
key: '0',
path: [0, 0],
offset: 3,
},
focus: {
object: 'point',
key: '0',
path: [0, 0],
offset: 6,
},
isFocused: false,
isAtomic: false,
marks: [

View File

@@ -9,7 +9,10 @@ export const input = (
one<text key="a">two</text>three
</block>
</document>
<selection anchorKey="a" anchorOffset={1} focusKey="a" focusOffset={2} />
<selection>
<anchor key="a" offset={1} />
<focus key="a" offset={2} />
</selection>
</value>
)
@@ -49,12 +52,18 @@ export const output = {
},
selection: {
object: 'range',
anchorKey: 'a',
anchorPath: [0, 0],
anchorOffset: 1,
focusKey: 'a',
focusPath: [0, 0],
focusOffset: 2,
anchor: {
object: 'point',
key: 'a',
path: [0, 0],
offset: 1,
},
focus: {
object: 'point',
key: 'a',
path: [0, 0],
offset: 2,
},
isFocused: false,
isAtomic: false,
marks: null,