mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-17 04:34:00 +02:00
rename kind
to object
for clarity (#1501)
* rename `kind` to `object` for clarity * add deprecation warning for direct access * add deprecation warning for node creation
This commit is contained in:
@@ -22,8 +22,8 @@ Specifically, Slate's models are [`Immutable.Record`](https://facebook.github.io
|
||||
```js
|
||||
const block = Block.create({ type: 'paragraph' })
|
||||
|
||||
block.kind // "block"
|
||||
block.type // "paragraph"
|
||||
block.object // "block"
|
||||
block.type // "paragraph"
|
||||
```
|
||||
|
||||
But for updating values, you'll need to use the [`Immutable.Record` API](https://facebook.github.io/immutable-js/docs/#/Record/set).
|
||||
|
@@ -94,7 +94,7 @@ However sometimes you want to customize things. Or maybe you want to render plac
|
||||
```js
|
||||
function renderPlaceholder(props) {
|
||||
const { node, editor } = props
|
||||
if (node.kind != 'block') return
|
||||
if (node.object != 'block') return
|
||||
if (node.type != 'caption') return
|
||||
if (node.text != '') return
|
||||
|
||||
|
@@ -24,7 +24,7 @@ const schema = {
|
||||
blocks: {
|
||||
paragraph: {
|
||||
nodes: [
|
||||
{ kinds: ['text'] }
|
||||
{ objects: ['text'] }
|
||||
]
|
||||
},
|
||||
image: {
|
||||
@@ -93,13 +93,13 @@ When you define a `validateNode` function, you either return nothing if the node
|
||||
|
||||
```js
|
||||
function validateNode(node) {
|
||||
if (node.kind != 'block') return
|
||||
if (node.object != 'block') return
|
||||
if (node.isVoid) return
|
||||
|
||||
const { nodes } = node
|
||||
if (nodes.size != 3) return
|
||||
if (nodes.first().kind != 'text') return
|
||||
if (nodes.last().kind != 'text') return
|
||||
if (nodes.first().object != 'text') return
|
||||
if (nodes.last().object != 'text') return
|
||||
|
||||
return (change) => {
|
||||
change.removeNodeByKey(node.key)
|
||||
|
@@ -86,28 +86,28 @@ The object should be one of:
|
||||
|
||||
```js
|
||||
{
|
||||
kind: 'block',
|
||||
object: 'block',
|
||||
type: String,
|
||||
data: Object,
|
||||
nodes: next(...)
|
||||
}
|
||||
|
||||
{
|
||||
kind: 'inline',
|
||||
object: 'inline',
|
||||
type: String,
|
||||
data: Object,
|
||||
nodes: next(...)
|
||||
}
|
||||
|
||||
{
|
||||
kind: 'mark',
|
||||
object: 'mark',
|
||||
type: String,
|
||||
data: Object,
|
||||
nodes: next(...)
|
||||
}
|
||||
|
||||
{
|
||||
kind: 'text',
|
||||
object: 'text',
|
||||
leaves: Array
|
||||
}
|
||||
```
|
||||
@@ -118,8 +118,8 @@ The object should be one of:
|
||||
|
||||
The `serialize` function should return a React element representing the serialized HTML, or nothing if the rule in question doesn't know how to serialize the object, in which case the next rule in the stack will be attempted.
|
||||
|
||||
The function will be called with either a `Node`, a `Mark`, or a special `String` immutable object, with a `kind: 'string'` property and a `text` property containing the text string.
|
||||
The function will be called with either a `Node`, a `Mark`, or a special `String` immutable object, with a `object: 'string'` property and a `text` property containing the text string.
|
||||
|
||||
### Default Text Rule
|
||||
|
||||
The HTML serializer includes a default rule to handle "normal text". That is, a final rule exists to serialize `kind: 'string'` text (replacing line feed characters with `<br>`), and to deserialize text inversely. To avoid this default handling simply provide your own `deserialize` and `serialize` rules for text.
|
||||
The HTML serializer includes a default rule to handle "normal text". That is, a final rule exists to serialize `object: 'string'` text (replacing line feed characters with `<br>`), and to deserialize text inversely. To avoid this default handling simply provide your own `deserialize` and `serialize` rules for text.
|
||||
|
@@ -39,7 +39,7 @@ Note that even though a node may be "void", it will still contain a single, empt
|
||||
|
||||
A unique identifier for the node.
|
||||
|
||||
### `kind`
|
||||
### `object`
|
||||
`String`
|
||||
|
||||
An immutable string value of `'block'` for easily separating this node from [`Inline`](./inline.md) or [`Text`](./text.md) nodes.
|
||||
|
@@ -12,7 +12,7 @@ All changes are performed through `Change` objects, so that a history of changes
|
||||
|
||||
## Properties
|
||||
|
||||
### `kind`
|
||||
### `object`
|
||||
`String`
|
||||
|
||||
A string with a value of `'change'`.
|
||||
|
@@ -19,7 +19,7 @@ Character({
|
||||
})
|
||||
```
|
||||
|
||||
### `kind`
|
||||
### `object`
|
||||
`String`
|
||||
|
||||
A string with a value of `'character'`.
|
||||
|
@@ -23,7 +23,7 @@ Document({
|
||||
### `data`
|
||||
`Immutable.Map`
|
||||
|
||||
### `kind`
|
||||
### `object`
|
||||
`String`
|
||||
|
||||
An immutable string value of `'document'` for easily separating this node from [`Block`](./block.md), [`Inline`](./inline.md) or [`Text`](./text.md) nodes.
|
||||
|
@@ -39,7 +39,7 @@ Note that even though a node may be "void", it will still contain a single, empt
|
||||
|
||||
A unique identifier for the node.
|
||||
|
||||
### `kind`
|
||||
### `object`
|
||||
`String`
|
||||
|
||||
An immutable string value of `'inline'` for easily separating this node from [`Block`](./block.md) or [`Text`](./text.md) nodes.
|
||||
|
@@ -22,7 +22,7 @@ Mark({
|
||||
|
||||
A map of [`Data`](./data.md).
|
||||
|
||||
### `kind`
|
||||
### `object`
|
||||
`String`
|
||||
|
||||
A string with a value of `'mark'`.
|
||||
|
@@ -15,16 +15,16 @@ By default, keys are **not** meant to be long-lived unique identifiers for nodes
|
||||
|
||||
If you want to make your keys uniqueness long-lived, you'll need to supply your own key generating function via the [`setKeyGenerator`](./utils.md#setkeygenerator) util.
|
||||
|
||||
### `kind`
|
||||
`String`
|
||||
|
||||
An immutable string value of `'document'`, `'block'`, `'inline'` or `'text'` for easily separating this node from [`Inline`](./inline.md) or [`Text`](./text.md) nodes.
|
||||
|
||||
### `nodes`
|
||||
`Immutable.List`
|
||||
|
||||
A list of child nodes. Defaults to a list with a single text node child.
|
||||
|
||||
### `object`
|
||||
`String`
|
||||
|
||||
An immutable string value of `'document'`, `'block'`, `'inline'` or `'text'` for easily separating this node from [`Inline`](./inline.md) or [`Text`](./text.md) nodes.
|
||||
|
||||
|
||||
## Computed Properties
|
||||
|
||||
|
@@ -55,7 +55,7 @@ Whether the range is backward. A range is considered "backward" when its focus p
|
||||
|
||||
Whether the range currently has focus.
|
||||
|
||||
### `kind`
|
||||
### `object`
|
||||
`String`
|
||||
|
||||
A string with a value of `'range'`.
|
||||
|
@@ -55,7 +55,7 @@ A dictionary of blocks by type, each with its own set of validation rules.
|
||||
inlines: {
|
||||
emoji: {
|
||||
isVoid: true,
|
||||
nodes: [{ kinds: ['text'] }]
|
||||
nodes: [{ objects: ['text'] }]
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -103,7 +103,7 @@ A dictionary of data attributes and their corresponding validation functions. Th
|
||||
}
|
||||
```
|
||||
|
||||
Will validate the first child node. The `first` definition can declare `kinds` and `types` properties.
|
||||
Will validate the first child node. The `first` definition can declare `objects` and `types` properties.
|
||||
|
||||
### `isVoid`
|
||||
`Boolean`
|
||||
@@ -125,7 +125,7 @@ Will validate a node's `isVoid` property.
|
||||
}
|
||||
```
|
||||
|
||||
Will validate the last child node. The `last` definition can declare `kinds` and `types` properties.
|
||||
Will validate the last child node. The `last` definition can declare `objects` and `types` properties.
|
||||
|
||||
### `nodes`
|
||||
`Array`
|
||||
@@ -139,7 +139,7 @@ Will validate the last child node. The `last` definition can declare `kinds` and
|
||||
}
|
||||
```
|
||||
|
||||
Will validate a node's children. The `nodes` definitions can declare the `kinds`, `types`, `min` and `max` properties.
|
||||
Will validate a node's children. The `nodes` definitions can declare the `objects`, `types`, `min` and `max` properties.
|
||||
|
||||
> 🤖 The `nodes` array is order-sensitive! The example above will require that the first node be either an `image` or `video`, and that it be followed by one or more `paragraph` nodes.
|
||||
|
||||
@@ -149,7 +149,7 @@ Will validate a node's children. The `nodes` definitions can declare the `kinds`
|
||||
```js
|
||||
{
|
||||
normalize: (change, reason, context) => {
|
||||
case 'child_kind_invalid':
|
||||
case 'child_object_invalid':
|
||||
change.wrapBlockByKey(context.child.key, 'paragraph')
|
||||
return
|
||||
case 'child_type_invalid':
|
||||
@@ -172,7 +172,7 @@ For more information on the arguments passed to `normalize`, see the [Invalid Re
|
||||
}
|
||||
```
|
||||
|
||||
Will validate a node's parent. The parent definition can declare the `kinds` and/or `types` properties.
|
||||
Will validate a node's parent. The parent definition can declare the `objects` and/or `types` properties.
|
||||
|
||||
### `text`
|
||||
`Array`
|
||||
@@ -216,7 +216,7 @@ Returns a JSON representation of the schema.
|
||||
|
||||
When supplying your own `normalize` property for a schema rule, it will be called with `(change, reason, context)`. The `reason` will be one of a set of reasons, and `context` will vary depending on the reason. Here's the full set:
|
||||
|
||||
### `child_kind_invalid`
|
||||
### `child_object_invalid`
|
||||
|
||||
```js
|
||||
{
|
||||
@@ -259,7 +259,7 @@ When supplying your own `normalize` property for a schema rule, it will be calle
|
||||
}
|
||||
```
|
||||
|
||||
### `first_child_kind_invalid`
|
||||
### `first_child_object_invalid`
|
||||
|
||||
```js
|
||||
{
|
||||
@@ -279,7 +279,7 @@ When supplying your own `normalize` property for a schema rule, it will be calle
|
||||
}
|
||||
```
|
||||
|
||||
### `last_child_kind_invalid`
|
||||
### `last_child_object_invalid`
|
||||
|
||||
```js
|
||||
{
|
||||
@@ -319,7 +319,7 @@ When supplying your own `normalize` property for a schema rule, it will be calle
|
||||
}
|
||||
```
|
||||
|
||||
### `node_kind_invalid`
|
||||
### `node_object_invalid`
|
||||
|
||||
```js
|
||||
{
|
||||
@@ -348,7 +348,7 @@ When supplying your own `normalize` property for a schema rule, it will be calle
|
||||
}
|
||||
```
|
||||
|
||||
### `parent_kind_invalid`
|
||||
### `parent_object_invalid`
|
||||
|
||||
```js
|
||||
{
|
||||
|
@@ -26,7 +26,7 @@ A list of [`Characters`](./character.md) with associated [`Marks`](./mark.md) th
|
||||
|
||||
A unique identifier for the node.
|
||||
|
||||
### `kind`
|
||||
### `object`
|
||||
`String`
|
||||
|
||||
An immutable string value of `'text'` for easily separating this node from [`Inline`](./inline.md) or [`Block`](./block.md) nodes.
|
||||
|
@@ -45,7 +45,7 @@ The current document of the value.
|
||||
|
||||
An object that stores the history of changes.
|
||||
|
||||
### `kind`
|
||||
### `object`
|
||||
`String`
|
||||
|
||||
A string with a value of `'value'`.
|
||||
|
@@ -36,11 +36,11 @@ const initialValue = Value.fromJSON({
|
||||
document: {
|
||||
nodes: [
|
||||
{
|
||||
kind: 'block',
|
||||
object: 'block',
|
||||
type: 'paragraph',
|
||||
nodes: [
|
||||
{
|
||||
kind: 'text',
|
||||
object: 'text',
|
||||
leaves: [
|
||||
{
|
||||
text: 'A line of text in a paragraph.'
|
||||
@@ -66,11 +66,11 @@ const initialValue = Value.fromJSON({
|
||||
document: {
|
||||
nodes: [
|
||||
{
|
||||
kind: 'block',
|
||||
object: 'block',
|
||||
type: 'paragraph',
|
||||
nodes: [
|
||||
{
|
||||
kind: 'text',
|
||||
object: 'text',
|
||||
leaves: [
|
||||
{
|
||||
text: 'A line of text in a paragraph.'
|
||||
|
@@ -54,7 +54,7 @@ const rules = [
|
||||
deserialize(el, next) {
|
||||
if (el.tagName.toLowerCase() == 'p') {
|
||||
return {
|
||||
kind: 'block',
|
||||
object: 'block',
|
||||
type: 'paragraph',
|
||||
nodes: next(el.childNodes)
|
||||
}
|
||||
@@ -76,15 +76,15 @@ const rules = [
|
||||
deserialize(el, next) {
|
||||
if (el.tagName.toLowerCase() == 'p') {
|
||||
return {
|
||||
kind: 'block',
|
||||
object: 'block',
|
||||
type: 'paragraph',
|
||||
nodes: next(el.childNodes)
|
||||
}
|
||||
}
|
||||
},
|
||||
// Add a serializing function property to our rule...
|
||||
serialize(object, children) {
|
||||
if (object.kind == 'block' && object.type == 'paragraph') {
|
||||
serialize(obj, children) {
|
||||
if (obj.object == 'block' && obj.type == 'paragraph') {
|
||||
return <p>{children}</p>
|
||||
}
|
||||
}
|
||||
@@ -115,15 +115,15 @@ const rules = [
|
||||
const type = BLOCK_TAGS[el.tagName.toLowerCase()]
|
||||
if (!type) return
|
||||
return {
|
||||
kind: 'block',
|
||||
object: 'block',
|
||||
type: type,
|
||||
nodes: next(el.childNodes)
|
||||
}
|
||||
},
|
||||
// Switch serialize to handle more blocks...
|
||||
serialize(object, children) {
|
||||
if (object.kind != 'block') return
|
||||
switch (object.type) {
|
||||
serialize(obj, children) {
|
||||
if (obj.object != 'block') return
|
||||
switch (obj.type) {
|
||||
case 'paragraph': return <p>{children}</p>
|
||||
case 'quote': return <blockquote>{children}</blockquote>
|
||||
case 'code': return <pre><code>{children}</code></pre>
|
||||
@@ -160,14 +160,14 @@ const rules = [
|
||||
const type = BLOCK_TAGS[el.tagName.toLowerCase()]
|
||||
if (!type) return
|
||||
return {
|
||||
kind: 'block',
|
||||
object: 'block',
|
||||
type: type,
|
||||
nodes: next(el.childNodes)
|
||||
}
|
||||
},
|
||||
serialize(object, children) {
|
||||
if (object.kind != 'block') return
|
||||
switch (object.type) {
|
||||
serialize(obj, children) {
|
||||
if (obj.object != 'block') return
|
||||
switch (obj.type) {
|
||||
case 'code': return <pre><code>{children}</code></pre>
|
||||
case 'paragraph': return <p>{children}</p>
|
||||
case 'quote': return <blockquote>{children}</blockquote>
|
||||
@@ -180,14 +180,14 @@ const rules = [
|
||||
const type = MARK_TAGS[el.tagName.toLowerCase()]
|
||||
if (!type) return
|
||||
return {
|
||||
kind: 'mark',
|
||||
object: 'mark',
|
||||
type: type,
|
||||
nodes: next(el.childNodes)
|
||||
}
|
||||
},
|
||||
serialize(object, children) {
|
||||
if (object.kind != 'mark') return
|
||||
switch (object.type) {
|
||||
serialize(obj, children) {
|
||||
if (obj.object != 'mark') return
|
||||
switch (obj.type) {
|
||||
case 'bold': return <strong>{children}</strong>
|
||||
case 'italic': return <em>{children}</em>
|
||||
case 'underline': return <u>{children}</u>
|
||||
|
@@ -19,11 +19,11 @@ const initialValue = Value.fromJSON({
|
||||
document: {
|
||||
nodes: [
|
||||
{
|
||||
kind: 'block',
|
||||
object: 'block',
|
||||
type: 'paragraph',
|
||||
nodes: [
|
||||
{
|
||||
kind: 'text',
|
||||
object: 'text',
|
||||
leaves: [
|
||||
{
|
||||
text: 'A line of text in a paragraph.'
|
||||
@@ -69,11 +69,11 @@ const initialValue = Value.fromJSON({
|
||||
document: {
|
||||
nodes: [
|
||||
{
|
||||
kind: 'block',
|
||||
object: 'block',
|
||||
type: 'paragraph',
|
||||
nodes: [
|
||||
{
|
||||
kind: 'text',
|
||||
object: 'text',
|
||||
leaves: [
|
||||
{
|
||||
text: 'A line of text in a paragraph.'
|
||||
@@ -123,11 +123,11 @@ const initialValue = Value.fromJSON(existingValue || {
|
||||
document: {
|
||||
nodes: [
|
||||
{
|
||||
kind: 'block',
|
||||
object: 'block',
|
||||
type: 'paragraph',
|
||||
nodes: [
|
||||
{
|
||||
kind: 'text',
|
||||
object: 'text',
|
||||
leaves: [
|
||||
{
|
||||
text: 'A line of text in a paragraph.'
|
||||
@@ -175,11 +175,11 @@ const initialValue = Value.fromJSON(existingValue || {
|
||||
document: {
|
||||
nodes: [
|
||||
{
|
||||
kind: 'block',
|
||||
object: 'block',
|
||||
type: 'paragraph',
|
||||
nodes: [
|
||||
{
|
||||
kind: 'text',
|
||||
object: 'text',
|
||||
leaves: [
|
||||
{
|
||||
text: 'A line of text in a paragraph.'
|
||||
|
@@ -2,11 +2,11 @@
|
||||
"document": {
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "paragraph",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "With Slate you can build complex block types that have their own embedded content and behaviors, like rendering checkboxes inside check list items!"
|
||||
@@ -16,14 +16,14 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "check-list-item",
|
||||
"data": {
|
||||
"checked": true,
|
||||
},
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "Slide to the left."
|
||||
@@ -33,14 +33,14 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "check-list-item",
|
||||
"data": {
|
||||
"checked": true,
|
||||
},
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "Slide to the right."
|
||||
@@ -50,14 +50,14 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "check-list-item",
|
||||
"data": {
|
||||
"checked": false,
|
||||
},
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "Criss-cross."
|
||||
@@ -67,14 +67,14 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "check-list-item",
|
||||
"data": {
|
||||
"checked": true,
|
||||
},
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "Criss-cross!"
|
||||
@@ -84,14 +84,14 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "check-list-item",
|
||||
"data": {
|
||||
"checked": false,
|
||||
},
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "Cha cha real smooth…"
|
||||
@@ -101,14 +101,14 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "check-list-item",
|
||||
"data": {
|
||||
"checked": false,
|
||||
},
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "Let's go to work!"
|
||||
@@ -118,11 +118,11 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "paragraph",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "Try it out for yourself!"
|
||||
|
@@ -2,11 +2,11 @@
|
||||
"document": {
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "paragraph",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "There are certain behaviors that require rendering dynamic marks on string of text, like rendering code highlighting. For example:"
|
||||
@@ -16,18 +16,18 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "code",
|
||||
"data": {
|
||||
"language": "js"
|
||||
},
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "code_line",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "// A simple FizzBuzz implementation."
|
||||
@@ -37,11 +37,11 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "code_line",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "for (var i = 1; i <= 100; i++) {"
|
||||
@@ -51,11 +51,11 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "code_line",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": " if (i % 15 == 0) {"
|
||||
@@ -65,11 +65,11 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "code_line",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": " console.log('Fizz Buzz');"
|
||||
@@ -79,11 +79,11 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "code_line",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": " } else if (i % 5 == 0) {"
|
||||
@@ -93,11 +93,11 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "code_line",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": " console.log('Buzz');"
|
||||
@@ -107,11 +107,11 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "code_line",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": " } else if (i % 3 == 0) {"
|
||||
@@ -121,11 +121,11 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "code_line",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": " console.log('Fizz');"
|
||||
@@ -135,11 +135,11 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "code_line",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": " } else {"
|
||||
@@ -149,11 +149,11 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "code_line",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": " console.log(i);"
|
||||
@@ -163,11 +163,11 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "code_line",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": " }"
|
||||
@@ -177,11 +177,11 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "code_line",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "}"
|
||||
@@ -193,11 +193,11 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "paragraph",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "Try it out for yourself!"
|
||||
|
@@ -2,11 +2,11 @@
|
||||
"document": {
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "paragraph",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "In addition to simple image nodes, you can actually create complex embedded nodes. For example, this one contains an input element that lets you change the video being rendered!"
|
||||
@@ -16,7 +16,7 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "video",
|
||||
"isVoid": true,
|
||||
"data": {
|
||||
@@ -24,11 +24,11 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "paragraph",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "Try it out! If you want another good video URL to try, go with: https://www.youtube.com/embed/6Ejga4kJUts"
|
||||
|
@@ -2,11 +2,11 @@
|
||||
"document": {
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "paragraph",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "In addition to block nodes, you can create inline void nodes, like "
|
||||
@@ -14,7 +14,7 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "inline",
|
||||
"object": "inline",
|
||||
"type": "emoji",
|
||||
"isVoid": true,
|
||||
"data": {
|
||||
@@ -22,7 +22,7 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "!"
|
||||
@@ -32,11 +32,11 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "paragraph",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "inline",
|
||||
"object": "inline",
|
||||
"type": "emoji",
|
||||
"isVoid": true,
|
||||
"data": {
|
||||
@@ -46,11 +46,11 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "paragraph",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "This example shows emojis in action."
|
||||
|
@@ -2,11 +2,11 @@
|
||||
"document": {
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "title",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "Enforce Your Layout!"
|
||||
@@ -16,11 +16,11 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "paragraph",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "This example shows how to enforce your layout with schema-specific rules. This document will always have a title block at the top and at least one paragraph in the body. Try deleting them and see what happens!"
|
||||
|
@@ -2,11 +2,11 @@
|
||||
"document": {
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "paragraph",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "Slate editors save all changes to an internal \"history\" automatically, so you don't need to implement undo/redo yourself. And the editor automatically binds to the browser's default undo/redo keyboard shortcuts."
|
||||
@@ -16,11 +16,11 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "paragraph",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "Try it out for yourself! Make any changes you'd like then press \"cmd+z\"."
|
||||
|
@@ -2,11 +2,11 @@
|
||||
"document": {
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "paragraph",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "This example shows how you can make a hovering menu appear above your content, which you can use to make text "
|
||||
@@ -38,11 +38,11 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "paragraph",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "Try it out yourself! Just "
|
||||
|
@@ -21,16 +21,16 @@ const json = {
|
||||
|
||||
for (let h = 0; h < HEADINGS; h++) {
|
||||
nodes.push({
|
||||
kind: 'block',
|
||||
object: 'block',
|
||||
type: 'heading',
|
||||
nodes: [{ kind: 'text', leaves: [{ text: faker.lorem.sentence() }] }]
|
||||
nodes: [{ object: 'text', leaves: [{ text: faker.lorem.sentence() }] }]
|
||||
})
|
||||
|
||||
for (let p = 0; p < PARAGRAPHS; p++) {
|
||||
nodes.push({
|
||||
kind: 'block',
|
||||
object: 'block',
|
||||
type: 'paragraph',
|
||||
nodes: [{ kind: 'text', leaves: [{ text: faker.lorem.paragraph() }] }]
|
||||
nodes: [{ object: 'text', leaves: [{ text: faker.lorem.paragraph() }] }]
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@@ -2,11 +2,11 @@
|
||||
"document": {
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "paragraph",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "In addition to nodes that contain editable text, you can also create other types of nodes, like images or videos."
|
||||
@@ -16,7 +16,7 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "image",
|
||||
"isVoid": true,
|
||||
"data": {
|
||||
@@ -24,11 +24,11 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "paragraph",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "This example shows images in action. It features two ways to add images. You can either add an image via the toolbar icon above, or if you want in on a little secret, copy an image URL to your keyboard and paste it anywhere in the editor!"
|
||||
|
@@ -2,11 +2,11 @@
|
||||
"document": {
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "paragraph",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "In addition to block nodes, you can create inline nodes, like "
|
||||
@@ -14,14 +14,14 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "inline",
|
||||
"object": "inline",
|
||||
"type": "link",
|
||||
"data": {
|
||||
"href": "https://en.wikipedia.org/wiki/Hypertext"
|
||||
},
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "hyperlinks"
|
||||
@@ -31,7 +31,7 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "!"
|
||||
@@ -41,11 +41,11 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "paragraph",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "This example shows hyperlinks in action. It features two ways to add links. You can either add a link via the toolbar icon above, or if you want in on a little secret, copy a URL to your keyboard and paste it while a range of text is selected."
|
||||
|
@@ -114,7 +114,7 @@ class MarkdownPreview extends React.Component {
|
||||
*/
|
||||
|
||||
decorateNode(node) {
|
||||
if (node.kind != 'block') return
|
||||
if (node.object != 'block') return
|
||||
|
||||
const string = node.text
|
||||
const texts = node.getTexts().toArray()
|
||||
|
@@ -2,11 +2,11 @@
|
||||
"document": {
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "paragraph",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "The editor gives you full control over the logic you can add. For example, it's fairly common to want to add markdown-like shortcuts to editors. So that, when you start a line with \"> \" you get a blockquote that looks like this:"
|
||||
@@ -16,11 +16,11 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "block-quote",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "A wise quote."
|
||||
@@ -30,11 +30,11 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "paragraph",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "Order when you start a line with \"## \" you get a level-two heading, like this:"
|
||||
@@ -44,11 +44,11 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "heading-two",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "Try it out!"
|
||||
@@ -58,11 +58,11 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "paragraph",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "Try it out for yourself! Try starting a new line with \">\", \"-\", or \"#\"s."
|
||||
|
@@ -53,7 +53,7 @@ const RULES = [
|
||||
const block = BLOCK_TAGS[el.tagName.toLowerCase()]
|
||||
if (!block) return
|
||||
return {
|
||||
kind: 'block',
|
||||
object: 'block',
|
||||
type: block,
|
||||
nodes: next(el.childNodes)
|
||||
}
|
||||
@@ -64,7 +64,7 @@ const RULES = [
|
||||
const mark = MARK_TAGS[el.tagName.toLowerCase()]
|
||||
if (!mark) return
|
||||
return {
|
||||
kind: 'mark',
|
||||
object: 'mark',
|
||||
type: mark,
|
||||
nodes: next(el.childNodes)
|
||||
}
|
||||
@@ -80,7 +80,7 @@ const RULES = [
|
||||
: el.childNodes
|
||||
|
||||
return {
|
||||
kind: 'block',
|
||||
object: 'block',
|
||||
type: 'code',
|
||||
nodes: next(childNodes)
|
||||
}
|
||||
@@ -91,7 +91,7 @@ const RULES = [
|
||||
deserialize(el, next) {
|
||||
if (el.tagName.toLowerCase() != 'img') return
|
||||
return {
|
||||
kind: 'block',
|
||||
object: 'block',
|
||||
type: 'image',
|
||||
isVoid: true,
|
||||
nodes: next(el.childNodes),
|
||||
@@ -106,7 +106,7 @@ const RULES = [
|
||||
deserialize(el, next) {
|
||||
if (el.tagName.toLowerCase() != 'a') return
|
||||
return {
|
||||
kind: 'inline',
|
||||
object: 'inline',
|
||||
type: 'link',
|
||||
nodes: next(el.childNodes),
|
||||
data: {
|
||||
|
@@ -2,11 +2,11 @@
|
||||
"document": {
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "paragraph",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "By default, pasting content into a Slate editor will use the content's plain text representation. This is fine for some use cases, but sometimes you want to actually be able to paste in content and have it parsed into blocks and links and things. To do this, you need to add a parser that triggers on paste. This is an example of doing exactly that!"
|
||||
@@ -16,11 +16,11 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "paragraph",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "Try it out for yourself! Copy and paste some HTML content from another site into this editor."
|
||||
|
@@ -2,11 +2,11 @@
|
||||
"document": {
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "paragraph",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "This is editable "
|
||||
@@ -49,11 +49,11 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "paragraph",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "Since it's rich text, you can do things like turn a selection of text "
|
||||
@@ -73,11 +73,11 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "block-quote",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "A wise quote."
|
||||
@@ -87,11 +87,11 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "paragraph",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "Try it out for yourself!"
|
||||
|
@@ -2,11 +2,11 @@
|
||||
"document": {
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "paragraph",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "Slate supports both left-to-right text editing (English, French, etc.) and right-to-left text editing (Arabic, Hebrew, etc.) which it automatically detects. Here's an example featuring excerpts from Khalil Gibran:"
|
||||
@@ -16,11 +16,11 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "block-quote",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "Et un jeune dit : parle-nous de l'amitié.\nEt il répondit, disant :\nVotre ami est votre besoin qui a trouvé une réponse.\nIl est le champ que vous semez avec amour et moissonnez avec reconnaissance.\nIl est votre table et votre foyer."
|
||||
@@ -30,11 +30,11 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "block-quote",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "ثم قال له شاب: هات حدثناعن الصداقة.\nفأجاب و قال:\nإن صديقك هو كفاية حاجاتك.\nهو حقك الذي تزرعه بالمحبة و تحصده بالشكر.\nهو مائدتك و موقدك."
|
||||
@@ -44,11 +44,11 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "block-quote",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "And a youth said, \"Speak to us of Friendship.\"\nYour friend is your needs answered.\nHe is your field which you sow with love and reap with thanksgiving.\nAnd he is your board and your fireside."
|
||||
@@ -58,11 +58,11 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "paragraph",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "Try it out for yourself!"
|
||||
|
@@ -2,11 +2,11 @@
|
||||
"document": {
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "paragraph",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "This is editable text that you can search. As you search, it looks for matching strings of text, and adds \"decoration\" marks to them in realtime."
|
||||
@@ -16,11 +16,11 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "paragraph",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "Try it out for yourself by typing in the search box above!"
|
||||
|
@@ -1,74 +0,0 @@
|
||||
{
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "block",
|
||||
"type": "paragraph",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "The editor gives you full control over the logic you can add. For example, it's fairly common to want to add markdown-like shortcuts to editors. So that, when you start a line with \"> \" you get a blockquote that looks like this:"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"type": "block-quote",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "A wise quote."
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"type": "paragraph",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "Order when you start a line with \"## \" you get a level-two heading, like this:"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"type": "heading-two",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "Try it out!"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"type": "paragraph",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "Try it out for yourself! Try starting a new line with \">\", \"-\", or \"#\"s."
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
@@ -2,11 +2,11 @@
|
||||
"document": {
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "paragraph",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "These two editors are kept "
|
||||
@@ -27,11 +27,11 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "paragraph",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "They achieve this by sending any document-altering operations to each other whenever a change occurs, and then applying them locally with "
|
||||
@@ -52,11 +52,11 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "paragraph",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "Note: ",
|
||||
|
@@ -2,11 +2,11 @@
|
||||
"document": {
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "paragraph",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "Since the editor is based on a recursive tree model, similar to an HTML document, you can create complex nested structures, like tables:"
|
||||
@@ -16,19 +16,19 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "table",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "table-row",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "table-cell",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": ""
|
||||
@@ -38,11 +38,11 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "table-cell",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "Human",
|
||||
@@ -57,11 +57,11 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "table-cell",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "Dog",
|
||||
@@ -76,11 +76,11 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "table-cell",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "Cat",
|
||||
@@ -97,15 +97,15 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "table-row",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "table-cell",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "# of Feet",
|
||||
@@ -120,11 +120,11 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "table-cell",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "2"
|
||||
@@ -134,11 +134,11 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "table-cell",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "4"
|
||||
@@ -148,11 +148,11 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "table-cell",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "4"
|
||||
@@ -164,15 +164,15 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "table-row",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "table-cell",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "# of Lives",
|
||||
@@ -187,11 +187,11 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "table-cell",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "1"
|
||||
@@ -201,11 +201,11 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "table-cell",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "1"
|
||||
@@ -215,11 +215,11 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "table-cell",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "9"
|
||||
@@ -233,11 +233,11 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "block",
|
||||
"object": "block",
|
||||
"type": "paragraph",
|
||||
"nodes": [
|
||||
{
|
||||
"kind": "text",
|
||||
"object": "text",
|
||||
"leaves": [
|
||||
{
|
||||
"text": "This table is just a basic example of rendering a table, and it doesn\'t have fancy functionality. But you could augment it to add support for navigating with arrow keys, displaying table headers, adding column and rows, or even formulas if you wanted to get really crazy!"
|
||||
|
@@ -80,7 +80,7 @@
|
||||
"open": "open http://localhost:8080/dev.html",
|
||||
"release": "yarn run test && yarn run lint && lerna publish && yarn run gh-pages",
|
||||
"start": "http-server ./examples",
|
||||
"test": "mocha --compilers js:babel-core/register ./packages/*/test/index.js",
|
||||
"test": "mocha --require babel-core/register ./packages/*/test/index.js",
|
||||
"watch": "npm-run-all --parallel --print-label watch:examples watch:packages start",
|
||||
"watch:examples": "watchify --debug --transform babelify ./examples/index.js -o ./examples/build.dev.js -v",
|
||||
"watch:packages": "lerna run --parallel watch"
|
||||
|
@@ -10,7 +10,7 @@ const html = new Html({
|
||||
rules: [
|
||||
{
|
||||
serialize(obj, children) {
|
||||
switch (obj.kind) {
|
||||
switch (obj.object) {
|
||||
case 'block': {
|
||||
switch (obj.type) {
|
||||
case 'paragraph': return React.createElement('p', {}, children)
|
||||
|
@@ -11,7 +11,7 @@ const html = new Html({
|
||||
rules: [
|
||||
{
|
||||
serialize(obj, children) {
|
||||
switch (obj.kind) {
|
||||
switch (obj.object) {
|
||||
case 'block': {
|
||||
switch (obj.type) {
|
||||
case 'paragraph': return React.createElement('p', {}, children)
|
||||
|
@@ -12,7 +12,7 @@ import { Record } from 'immutable'
|
||||
*/
|
||||
|
||||
const String = new Record({
|
||||
kind: 'string',
|
||||
object: 'string',
|
||||
text: ''
|
||||
})
|
||||
|
||||
@@ -28,9 +28,9 @@ const TEXT_RULE = {
|
||||
deserialize(el) {
|
||||
if (el.tagName && el.tagName.toLowerCase() === 'br') {
|
||||
return {
|
||||
kind: 'text',
|
||||
object: 'text',
|
||||
leaves: [{
|
||||
kind: 'leaf',
|
||||
object: 'leaf',
|
||||
text: '\n'
|
||||
}]
|
||||
}
|
||||
@@ -40,9 +40,9 @@ const TEXT_RULE = {
|
||||
if (el.nodeValue && el.nodeValue.match(/<!--.*?-->/)) return
|
||||
|
||||
return {
|
||||
kind: 'text',
|
||||
object: 'text',
|
||||
leaves: [{
|
||||
kind: 'leaf',
|
||||
object: 'leaf',
|
||||
text: el.nodeValue
|
||||
}]
|
||||
}
|
||||
@@ -50,7 +50,7 @@ const TEXT_RULE = {
|
||||
},
|
||||
|
||||
serialize(obj, children) {
|
||||
if (obj.kind === 'string') {
|
||||
if (obj.object === 'string') {
|
||||
return children
|
||||
.split('\n')
|
||||
.reduce((array, text, i) => {
|
||||
@@ -129,19 +129,19 @@ class Html {
|
||||
|
||||
// COMPAT: ensure that all top-level inline nodes are wrapped into a block.
|
||||
nodes = nodes.reduce((memo, node, i, original) => {
|
||||
if (node.kind == 'block') {
|
||||
if (node.object == 'block') {
|
||||
memo.push(node)
|
||||
return memo
|
||||
}
|
||||
|
||||
if (i > 0 && original[i - 1].kind != 'block') {
|
||||
if (i > 0 && original[i - 1].object != 'block') {
|
||||
const block = memo[memo.length - 1]
|
||||
block.nodes.push(node)
|
||||
return memo
|
||||
}
|
||||
|
||||
const block = {
|
||||
kind: 'block',
|
||||
object: 'block',
|
||||
data: {},
|
||||
isVoid: false,
|
||||
...defaultBlock,
|
||||
@@ -155,16 +155,16 @@ class Html {
|
||||
// TODO: pretty sure this is no longer needed.
|
||||
if (nodes.length == 0) {
|
||||
nodes = [{
|
||||
kind: 'block',
|
||||
object: 'block',
|
||||
data: {},
|
||||
isVoid: false,
|
||||
...defaultBlock,
|
||||
nodes: [
|
||||
{
|
||||
kind: 'text',
|
||||
object: 'text',
|
||||
leaves: [
|
||||
{
|
||||
kind: 'leaf',
|
||||
object: 'leaf',
|
||||
text: '',
|
||||
marks: [],
|
||||
}
|
||||
@@ -175,9 +175,9 @@ class Html {
|
||||
}
|
||||
|
||||
const json = {
|
||||
kind: 'value',
|
||||
object: 'value',
|
||||
document: {
|
||||
kind: 'document',
|
||||
object: 'document',
|
||||
data: {},
|
||||
nodes,
|
||||
}
|
||||
@@ -257,7 +257,7 @@ class Html {
|
||||
continue
|
||||
} else if (ret === null) {
|
||||
return null
|
||||
} else if (ret.kind == 'mark') {
|
||||
} else if (ret.object == 'mark') {
|
||||
node = this.deserializeMark(ret)
|
||||
} else {
|
||||
node = ret
|
||||
@@ -280,11 +280,11 @@ class Html {
|
||||
const { type, data } = mark
|
||||
|
||||
const applyMark = (node) => {
|
||||
if (node.kind == 'mark') {
|
||||
if (node.object == 'mark') {
|
||||
return this.deserializeMark(node)
|
||||
}
|
||||
|
||||
else if (node.kind == 'text') {
|
||||
else if (node.object == 'text') {
|
||||
node.leaves = node.leaves.map((leaf) => {
|
||||
leaf.marks = leaf.marks || []
|
||||
leaf.marks.push({ type, data })
|
||||
@@ -334,7 +334,7 @@ class Html {
|
||||
*/
|
||||
|
||||
serializeNode = (node) => {
|
||||
if (node.kind === 'text') {
|
||||
if (node.object === 'text') {
|
||||
const leaves = node.getLeaves()
|
||||
return leaves.map(this.serializeLeaf)
|
||||
}
|
||||
|
@@ -10,14 +10,14 @@ export const config = {
|
||||
switch (el.tagName.toLowerCase()) {
|
||||
case 'p': {
|
||||
return {
|
||||
kind: 'block',
|
||||
object: 'block',
|
||||
type: 'paragraph',
|
||||
nodes: next(el.childNodes),
|
||||
}
|
||||
}
|
||||
case 'blockquote': {
|
||||
return {
|
||||
kind: 'block',
|
||||
object: 'block',
|
||||
type: 'quote',
|
||||
nodes: next(el.childNodes),
|
||||
}
|
||||
|
@@ -10,7 +10,7 @@ export const config = {
|
||||
switch (el.tagName.toLowerCase()) {
|
||||
case 'p': {
|
||||
return {
|
||||
kind: 'block',
|
||||
object: 'block',
|
||||
type: 'paragraph',
|
||||
nodes: next(el.childNodes),
|
||||
}
|
||||
|
@@ -10,7 +10,7 @@ export const config = {
|
||||
switch (el.tagName.toLowerCase()) {
|
||||
case 'p': {
|
||||
return {
|
||||
kind: 'block',
|
||||
object: 'block',
|
||||
type: 'paragraph',
|
||||
data: { thing: 'value' },
|
||||
nodes: next(el.childNodes),
|
||||
|
@@ -10,7 +10,7 @@ export const config = {
|
||||
switch (el.tagName.toLowerCase()) {
|
||||
case 'img': {
|
||||
return {
|
||||
kind: 'block',
|
||||
object: 'block',
|
||||
type: 'image',
|
||||
isVoid: true,
|
||||
}
|
||||
|
@@ -10,7 +10,7 @@ export const config = {
|
||||
switch (el.tagName.toLowerCase()) {
|
||||
case 'p': {
|
||||
return {
|
||||
kind: 'block',
|
||||
object: 'block',
|
||||
type: 'paragraph',
|
||||
nodes: next(el.childNodes),
|
||||
}
|
||||
|
@@ -10,7 +10,7 @@ export const config = {
|
||||
switch (el.tagName.toLowerCase()) {
|
||||
case 'p': {
|
||||
return {
|
||||
kind: 'block',
|
||||
object: 'block',
|
||||
type: 'paragraph',
|
||||
nodes: next(el.childNodes),
|
||||
}
|
||||
|
@@ -10,7 +10,7 @@ export const config = {
|
||||
switch (el.tagName.toLowerCase()) {
|
||||
case 'p': {
|
||||
return {
|
||||
kind: 'block',
|
||||
object: 'block',
|
||||
type: 'paragraph',
|
||||
nodes: next(el.childNodes),
|
||||
}
|
||||
|
@@ -10,21 +10,21 @@ export const config = {
|
||||
switch (el.tagName.toLowerCase()) {
|
||||
case 'p': {
|
||||
return {
|
||||
kind: 'block',
|
||||
object: 'block',
|
||||
type: 'paragraph',
|
||||
nodes: next(el.childNodes),
|
||||
}
|
||||
}
|
||||
case 'a': {
|
||||
return {
|
||||
kind: 'inline',
|
||||
object: 'inline',
|
||||
type: 'link',
|
||||
nodes: next(el.childNodes),
|
||||
}
|
||||
}
|
||||
case 'span': {
|
||||
return {
|
||||
kind: 'inline',
|
||||
object: 'inline',
|
||||
type: 'hashtag',
|
||||
nodes: next(el.childNodes),
|
||||
}
|
||||
|
@@ -10,14 +10,14 @@ export const config = {
|
||||
switch (el.tagName.toLowerCase()) {
|
||||
case 'p': {
|
||||
return {
|
||||
kind: 'block',
|
||||
object: 'block',
|
||||
type: 'paragraph',
|
||||
nodes: next(el.childNodes),
|
||||
}
|
||||
}
|
||||
case 'a': {
|
||||
return {
|
||||
kind: 'inline',
|
||||
object: 'inline',
|
||||
type: 'link',
|
||||
nodes: next(el.childNodes),
|
||||
}
|
||||
|
@@ -10,14 +10,14 @@ export const config = {
|
||||
switch (el.tagName.toLowerCase()) {
|
||||
case 'p': {
|
||||
return {
|
||||
kind: 'block',
|
||||
object: 'block',
|
||||
type: 'paragraph',
|
||||
nodes: next(el.childNodes),
|
||||
}
|
||||
}
|
||||
case 'a': {
|
||||
return {
|
||||
kind: 'inline',
|
||||
object: 'inline',
|
||||
type: 'link',
|
||||
data: { thing: 'value' },
|
||||
nodes: next(el.childNodes),
|
||||
|
@@ -10,14 +10,14 @@ export const config = {
|
||||
switch (el.tagName.toLowerCase()) {
|
||||
case 'p': {
|
||||
return {
|
||||
kind: 'block',
|
||||
object: 'block',
|
||||
type: 'paragraph',
|
||||
nodes: next(el.childNodes),
|
||||
}
|
||||
}
|
||||
case 'img': {
|
||||
return {
|
||||
kind: 'inline',
|
||||
object: 'inline',
|
||||
type: 'emoji',
|
||||
isVoid: true,
|
||||
nodes: next(el.childNodes),
|
||||
|
@@ -10,14 +10,14 @@ export const config = {
|
||||
switch (el.tagName.toLowerCase()) {
|
||||
case 'p': {
|
||||
return {
|
||||
kind: 'block',
|
||||
object: 'block',
|
||||
type: 'paragraph',
|
||||
nodes: next(el.childNodes),
|
||||
}
|
||||
}
|
||||
case 'a': {
|
||||
return {
|
||||
kind: 'inline',
|
||||
object: 'inline',
|
||||
type: 'link',
|
||||
nodes: next(el.childNodes),
|
||||
}
|
||||
|
@@ -10,21 +10,21 @@ export const config = {
|
||||
switch (el.tagName.toLowerCase()) {
|
||||
case 'p': {
|
||||
return {
|
||||
kind: 'block',
|
||||
object: 'block',
|
||||
type: 'paragraph',
|
||||
nodes: next(el.childNodes),
|
||||
}
|
||||
}
|
||||
case 'strong': {
|
||||
return {
|
||||
kind: 'mark',
|
||||
object: 'mark',
|
||||
type: 'bold',
|
||||
nodes: next(el.childNodes),
|
||||
}
|
||||
}
|
||||
case 'em': {
|
||||
return {
|
||||
kind: 'mark',
|
||||
object: 'mark',
|
||||
type: 'italic',
|
||||
nodes: next(el.childNodes),
|
||||
}
|
||||
|
@@ -10,21 +10,21 @@ export const config = {
|
||||
switch (el.tagName.toLowerCase()) {
|
||||
case 'p': {
|
||||
return {
|
||||
kind: 'block',
|
||||
object: 'block',
|
||||
type: 'paragraph',
|
||||
nodes: next(el.childNodes),
|
||||
}
|
||||
}
|
||||
case 'strong': {
|
||||
return {
|
||||
kind: 'mark',
|
||||
object: 'mark',
|
||||
type: 'bold',
|
||||
nodes: next(el.childNodes),
|
||||
}
|
||||
}
|
||||
case 'em': {
|
||||
return {
|
||||
kind: 'mark',
|
||||
object: 'mark',
|
||||
type: 'italic',
|
||||
nodes: next(el.childNodes),
|
||||
}
|
||||
|
@@ -10,14 +10,14 @@ export const config = {
|
||||
switch (el.tagName.toLowerCase()) {
|
||||
case 'p': {
|
||||
return {
|
||||
kind: 'block',
|
||||
object: 'block',
|
||||
type: 'paragraph',
|
||||
nodes: next(el.childNodes),
|
||||
}
|
||||
}
|
||||
case 'strong': {
|
||||
return {
|
||||
kind: 'mark',
|
||||
object: 'mark',
|
||||
type: 'bold',
|
||||
data: { thing: 'value' },
|
||||
nodes: next(el.childNodes),
|
||||
|
@@ -10,14 +10,14 @@ export const config = {
|
||||
switch (el.tagName.toLowerCase()) {
|
||||
case 'p': {
|
||||
return {
|
||||
kind: 'block',
|
||||
object: 'block',
|
||||
type: 'paragraph',
|
||||
nodes: next(el.childNodes),
|
||||
}
|
||||
}
|
||||
case 'strong': {
|
||||
return {
|
||||
kind: 'mark',
|
||||
object: 'mark',
|
||||
type: 'bold',
|
||||
nodes: next(el.childNodes),
|
||||
}
|
||||
|
@@ -8,7 +8,7 @@ export const config = {
|
||||
{
|
||||
deserialize(el, next) {
|
||||
return {
|
||||
kind: 'block',
|
||||
object: 'block',
|
||||
type: 'paragraph',
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ export const config = {
|
||||
{
|
||||
deserialize(el, next) {
|
||||
return {
|
||||
kind: 'block',
|
||||
object: 'block',
|
||||
type: 'quote',
|
||||
}
|
||||
}
|
||||
|
@@ -10,7 +10,7 @@ export const config = {
|
||||
switch (el.tagName.toLowerCase()) {
|
||||
case 'p': {
|
||||
return {
|
||||
kind: 'block',
|
||||
object: 'block',
|
||||
type: 'paragraph',
|
||||
nodes: next(),
|
||||
}
|
||||
|
@@ -13,14 +13,14 @@ export const config = {
|
||||
}
|
||||
case 'p': {
|
||||
return {
|
||||
kind: 'block',
|
||||
object: 'block',
|
||||
type: 'paragraph',
|
||||
nodes: next(el.childNodes),
|
||||
}
|
||||
}
|
||||
case 'img': {
|
||||
return {
|
||||
kind: 'block',
|
||||
object: 'block',
|
||||
type: 'image',
|
||||
isVoid: true,
|
||||
}
|
||||
|
@@ -6,7 +6,7 @@ export const config = {
|
||||
switch (el.tagName.toLowerCase()) {
|
||||
case 'p': {
|
||||
return {
|
||||
kind: 'block',
|
||||
object: 'block',
|
||||
type: 'paragraph',
|
||||
nodes: next(el.childNodes),
|
||||
}
|
||||
@@ -22,20 +22,20 @@ export const input = `
|
||||
`.trim()
|
||||
|
||||
export const output = {
|
||||
kind: 'value',
|
||||
object: 'value',
|
||||
document: {
|
||||
kind: 'document',
|
||||
object: 'document',
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
kind: 'block',
|
||||
object: 'block',
|
||||
type: 'paragraph',
|
||||
nodes: [
|
||||
{
|
||||
kind: 'text',
|
||||
object: 'text',
|
||||
leaves: [
|
||||
{
|
||||
kind: 'leaf',
|
||||
object: 'leaf',
|
||||
text: 'one',
|
||||
}
|
||||
]
|
||||
|
@@ -7,7 +7,7 @@ import h from '../helpers/h'
|
||||
export const rules = [
|
||||
{
|
||||
serialize(obj, children) {
|
||||
if (obj.kind != 'block') return
|
||||
if (obj.object != 'block') return
|
||||
switch (obj.type) {
|
||||
case 'paragraph': return React.createElement('p', {}, children)
|
||||
case 'quote': return React.createElement('blockquote', {}, children)
|
||||
|
@@ -7,7 +7,7 @@ import h from '../helpers/h'
|
||||
export const rules = [
|
||||
{
|
||||
serialize(obj, children) {
|
||||
if (obj.kind == 'block' && obj.type == 'paragraph') {
|
||||
if (obj.object == 'block' && obj.type == 'paragraph') {
|
||||
return React.createElement('p', { 'data-thing': obj.data.get('thing') }, children)
|
||||
}
|
||||
}
|
||||
|
@@ -7,7 +7,7 @@ import h from '../helpers/h'
|
||||
export const rules = [
|
||||
{
|
||||
serialize(obj, children) {
|
||||
if (obj.kind == 'block' && obj.type == 'image') {
|
||||
if (obj.object == 'block' && obj.type == 'image') {
|
||||
return React.createElement('img')
|
||||
}
|
||||
}
|
||||
|
@@ -7,11 +7,11 @@ import h from '../helpers/h'
|
||||
export const rules = [
|
||||
{
|
||||
serialize(obj, children) {
|
||||
if (obj.kind == 'block' && obj.type == 'paragraph') {
|
||||
if (obj.object == 'block' && obj.type == 'paragraph') {
|
||||
return React.createElement('p', {}, children)
|
||||
}
|
||||
|
||||
if (obj.kind == 'mark' && obj.type == 'bold') {
|
||||
if (obj.object == 'mark' && obj.type == 'bold') {
|
||||
return React.createElement('strong', {}, children)
|
||||
}
|
||||
}
|
||||
|
@@ -7,7 +7,7 @@ import h from '../helpers/h'
|
||||
export const rules = [
|
||||
{
|
||||
serialize(obj, children) {
|
||||
if (obj.kind == 'block' && obj.type == 'paragraph') {
|
||||
if (obj.object == 'block' && obj.type == 'paragraph') {
|
||||
return React.createElement('p', {}, children)
|
||||
}
|
||||
}
|
||||
|
@@ -7,15 +7,15 @@ import h from '../helpers/h'
|
||||
export const rules = [
|
||||
{
|
||||
serialize(obj, children) {
|
||||
if (obj.kind == 'block' && obj.type == 'paragraph') {
|
||||
if (obj.object == 'block' && obj.type == 'paragraph') {
|
||||
return React.createElement('p', {}, children)
|
||||
}
|
||||
|
||||
if (obj.kind == 'inline' && obj.type == 'link') {
|
||||
if (obj.object == 'inline' && obj.type == 'link') {
|
||||
return React.createElement('a', {}, children)
|
||||
}
|
||||
|
||||
if (obj.kind == 'inline' && obj.type == 'hashtag') {
|
||||
if (obj.object == 'inline' && obj.type == 'hashtag') {
|
||||
return React.createElement('span', {}, children)
|
||||
}
|
||||
}
|
||||
|
@@ -7,11 +7,11 @@ import h from '../helpers/h'
|
||||
export const rules = [
|
||||
{
|
||||
serialize(obj, children) {
|
||||
if (obj.kind == 'block' && obj.type == 'paragraph') {
|
||||
if (obj.object == 'block' && obj.type == 'paragraph') {
|
||||
return React.createElement('p', {}, children)
|
||||
}
|
||||
|
||||
if (obj.kind == 'inline' && obj.type == 'link') {
|
||||
if (obj.object == 'inline' && obj.type == 'link') {
|
||||
return React.createElement('a', { href: obj.data.get('href') }, children)
|
||||
}
|
||||
}
|
||||
|
@@ -7,11 +7,11 @@ import h from '../helpers/h'
|
||||
export const rules = [
|
||||
{
|
||||
serialize(obj, children) {
|
||||
if (obj.kind == 'block' && obj.type == 'paragraph') {
|
||||
if (obj.object == 'block' && obj.type == 'paragraph') {
|
||||
return React.createElement('p', {}, children)
|
||||
}
|
||||
|
||||
if (obj.kind == 'inline' && obj.type == 'emoji') {
|
||||
if (obj.object == 'inline' && obj.type == 'emoji') {
|
||||
return React.createElement('img')
|
||||
}
|
||||
}
|
||||
|
@@ -7,15 +7,15 @@ import h from '../helpers/h'
|
||||
export const rules = [
|
||||
{
|
||||
serialize(obj, children) {
|
||||
if (obj.kind == 'block' && obj.type == 'paragraph') {
|
||||
if (obj.object == 'block' && obj.type == 'paragraph') {
|
||||
return React.createElement('p', {}, children)
|
||||
}
|
||||
|
||||
if (obj.kind == 'inline' && obj.type == 'link') {
|
||||
if (obj.object == 'inline' && obj.type == 'link') {
|
||||
return React.createElement('a', {}, children)
|
||||
}
|
||||
|
||||
if (obj.kind == 'mark' && obj.type == 'bold') {
|
||||
if (obj.object == 'mark' && obj.type == 'bold') {
|
||||
return React.createElement('strong', {}, children)
|
||||
}
|
||||
}
|
||||
|
@@ -7,11 +7,11 @@ import h from '../helpers/h'
|
||||
export const rules = [
|
||||
{
|
||||
serialize(obj, children) {
|
||||
if (obj.kind == 'block' && obj.type == 'paragraph') {
|
||||
if (obj.object == 'block' && obj.type == 'paragraph') {
|
||||
return React.createElement('p', {}, children)
|
||||
}
|
||||
|
||||
if (obj.kind == 'inline' && obj.type == 'link') {
|
||||
if (obj.object == 'inline' && obj.type == 'link') {
|
||||
return React.createElement('a', {}, children)
|
||||
}
|
||||
}
|
||||
|
@@ -11,7 +11,7 @@ export const rules = [
|
||||
},
|
||||
{
|
||||
serialize(obj, children) {
|
||||
if (obj.kind == 'block' && obj.type == 'paragraph') {
|
||||
if (obj.object == 'block' && obj.type == 'paragraph') {
|
||||
return React.createElement('p', {}, children)
|
||||
}
|
||||
}
|
||||
|
@@ -270,15 +270,15 @@ function resolveCreators(options) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize a node creator with `key` and `value`, of `kind`.
|
||||
* Normalize a node creator with `key` and `value`, of `object`.
|
||||
*
|
||||
* @param {String} key
|
||||
* @param {Function|Object|String} value
|
||||
* @param {String} kind
|
||||
* @param {String} object
|
||||
* @return {Function}
|
||||
*/
|
||||
|
||||
function normalizeNode(key, value, kind) {
|
||||
function normalizeNode(key, value, object) {
|
||||
if (typeof value == 'function') {
|
||||
return value
|
||||
}
|
||||
@@ -292,7 +292,7 @@ function normalizeNode(key, value, kind) {
|
||||
const { key: attrKey, ...rest } = attributes
|
||||
const attrs = {
|
||||
...value,
|
||||
kind,
|
||||
object,
|
||||
key: attrKey,
|
||||
data: {
|
||||
...(value.data || {}),
|
||||
@@ -300,11 +300,11 @@ function normalizeNode(key, value, kind) {
|
||||
}
|
||||
}
|
||||
|
||||
return CREATORS[kind](tagName, attrs, children)
|
||||
return CREATORS[object](tagName, attrs, children)
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error(`Slate hyperscript ${kind} creators can be either functions, objects or strings, but you passed: ${value}`)
|
||||
throw new Error(`Slate hyperscript ${object} creators can be either functions, objects or strings, but you passed: ${value}`)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -28,22 +28,22 @@ function deserialize(string, options = {}) {
|
||||
defaultMarks = defaultMarks.map(Mark.createProperties)
|
||||
|
||||
const json = {
|
||||
kind: 'value',
|
||||
object: 'value',
|
||||
document: {
|
||||
kind: 'document',
|
||||
object: 'document',
|
||||
data: {},
|
||||
nodes: string.split('\n').map((line) => {
|
||||
return {
|
||||
...defaultBlock,
|
||||
kind: 'block',
|
||||
object: 'block',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
kind: 'text',
|
||||
object: 'text',
|
||||
leaves: [
|
||||
{
|
||||
kind: 'leaf',
|
||||
object: 'leaf',
|
||||
text: line,
|
||||
marks: defaultMarks,
|
||||
}
|
||||
@@ -79,8 +79,8 @@ function serialize(value) {
|
||||
|
||||
function serializeNode(node) {
|
||||
if (
|
||||
(node.kind == 'document') ||
|
||||
(node.kind == 'block' && Block.isBlockList(node.nodes))
|
||||
(node.object == 'document') ||
|
||||
(node.object == 'block' && Block.isBlockList(node.nodes))
|
||||
) {
|
||||
return node.nodes.map(serializeNode).join('\n')
|
||||
} else {
|
||||
|
@@ -4,22 +4,22 @@ one
|
||||
`.trim()
|
||||
|
||||
export const output = {
|
||||
kind: 'value',
|
||||
object: 'value',
|
||||
document: {
|
||||
kind: 'document',
|
||||
object: 'document',
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
kind: 'block',
|
||||
object: 'block',
|
||||
type: 'line',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
kind: 'text',
|
||||
object: 'text',
|
||||
leaves: [
|
||||
{
|
||||
kind: 'leaf',
|
||||
object: 'leaf',
|
||||
text: 'one',
|
||||
marks: [],
|
||||
}
|
||||
|
@@ -131,7 +131,7 @@ class Node extends React.Component {
|
||||
|
||||
// If it's a block node with inline children, add the proper `dir` attribute
|
||||
// for text direction.
|
||||
if (node.kind == 'block' && node.nodes.first().kind != 'block') {
|
||||
if (node.object == 'block' && node.nodes.first().object != 'block') {
|
||||
const direction = node.getTextDirection()
|
||||
if (direction == 'rtl') attributes.dir = 'rtl'
|
||||
}
|
||||
@@ -170,11 +170,11 @@ class Node extends React.Component {
|
||||
renderNode = (child, isSelected) => {
|
||||
const { block, decorations, editor, node, readOnly } = this.props
|
||||
const { stack } = editor
|
||||
const Component = child.kind == 'text' ? Text : Node
|
||||
const Component = child.object == 'text' ? Text : Node
|
||||
const decs = decorations.concat(node.getDecorations(stack))
|
||||
return (
|
||||
<Component
|
||||
block={node.kind == 'block' ? node : block}
|
||||
block={node.object == 'block' ? node : block}
|
||||
decorations={decs}
|
||||
editor={editor}
|
||||
isSelected={isSelected}
|
||||
|
@@ -82,7 +82,7 @@ class Text extends React.Component {
|
||||
|
||||
// If the node parent is a block node, and it was the last child of the
|
||||
// block, re-render to cleanup extra `\n`.
|
||||
if (n.parent.kind == 'block') {
|
||||
if (n.parent.object == 'block') {
|
||||
const pLast = p.parent.nodes.last()
|
||||
const nLast = n.parent.nodes.last()
|
||||
if (p.node == pLast && n.node != nLast) return true
|
||||
|
@@ -60,7 +60,7 @@ class Void extends React.Component {
|
||||
render() {
|
||||
const { props } = this
|
||||
const { children, node, readOnly } = props
|
||||
const Tag = node.kind == 'block' ? 'div' : 'span'
|
||||
const Tag = node.object == 'block' ? 'div' : 'span'
|
||||
const style = {
|
||||
height: '0',
|
||||
color: 'transparent',
|
||||
@@ -114,7 +114,7 @@ class Void extends React.Component {
|
||||
const child = node.getFirstText()
|
||||
return (
|
||||
<Text
|
||||
block={node.kind == 'block' ? node : block}
|
||||
block={node.object == 'block' ? node : block}
|
||||
decorations={decorations}
|
||||
editor={editor}
|
||||
isSelected={isSelected}
|
||||
|
@@ -614,8 +614,8 @@ function AfterPlugin() {
|
||||
|
||||
function renderNode(props) {
|
||||
const { attributes, children, node } = props
|
||||
if (node.kind != 'block' && node.kind != 'inline') return
|
||||
const Tag = node.kind == 'block' ? 'div' : 'span'
|
||||
if (node.object != 'block' && node.object != 'inline') return
|
||||
const Tag = node.object == 'block' ? 'div' : 'span'
|
||||
const style = { position: 'relative' }
|
||||
return <Tag {...attributes} style={style}>{children}</Tag>
|
||||
}
|
||||
@@ -631,7 +631,7 @@ function AfterPlugin() {
|
||||
const { editor, node } = props
|
||||
if (!editor.props.placeholder) return
|
||||
if (editor.state.isComposing) return
|
||||
if (node.kind != 'block') return
|
||||
if (node.object != 'block') return
|
||||
if (!Text.isTextList(node.nodes)) return
|
||||
if (node.text != '') return
|
||||
if (editor.value.document.getBlocks().size > 1) return
|
||||
|
@@ -30,7 +30,7 @@ function getEventRange(event, value) {
|
||||
// closest to.
|
||||
if (node.isVoid) {
|
||||
const rect = target.getBoundingClientRect()
|
||||
const isPrevious = node.kind == 'inline'
|
||||
const isPrevious = node.object == 'inline'
|
||||
? x - rect.left < rect.left + rect.width - x
|
||||
: y - rect.top < rect.top + rect.height - y
|
||||
|
||||
|
@@ -9,15 +9,15 @@ export default function (json) {
|
||||
export const input = {
|
||||
document: {
|
||||
nodes: Array.from(Array(10)).map(() => ({
|
||||
kind: 'block',
|
||||
object: 'block',
|
||||
type: 'quote',
|
||||
nodes: [
|
||||
{
|
||||
kind: 'block',
|
||||
object: 'block',
|
||||
type: 'paragraph',
|
||||
nodes: [
|
||||
{
|
||||
kind: 'text',
|
||||
object: 'text',
|
||||
leaves: [
|
||||
{
|
||||
text: 'This is editable ',
|
||||
|
@@ -299,7 +299,7 @@ Changes.deleteLineBackwardAtRange = (change, range, options) => {
|
||||
const startWithVoidInline = (
|
||||
startBlock.nodes.size > 1 &&
|
||||
startBlock.nodes.get(0).text == '' &&
|
||||
startBlock.nodes.get(1).kind == 'inline'
|
||||
startBlock.nodes.get(1).object == 'inline'
|
||||
)
|
||||
|
||||
let o = offset + startOffset
|
||||
@@ -992,7 +992,7 @@ Changes.splitBlockAtRange = (change, range, height = 1, options = {}) => {
|
||||
let parent = document.getClosestBlock(node.key)
|
||||
let h = 0
|
||||
|
||||
while (parent && parent.kind == 'block' && h < height) {
|
||||
while (parent && parent.object == 'block' && h < height) {
|
||||
node = parent
|
||||
parent = document.getClosestBlock(parent.key)
|
||||
h++
|
||||
@@ -1026,7 +1026,7 @@ Changes.splitInlineAtRange = (change, range, height = Infinity, options = {}) =>
|
||||
let parent = document.getClosestInline(node.key)
|
||||
let h = 0
|
||||
|
||||
while (parent && parent.kind == 'inline' && h < height) {
|
||||
while (parent && parent.object == 'inline' && h < height) {
|
||||
node = parent
|
||||
parent = document.getClosestInline(parent.key)
|
||||
h++
|
||||
@@ -1084,7 +1084,7 @@ Changes.unwrapBlockAtRange = (change, range, properties, options = {}) => {
|
||||
const wrappers = blocks
|
||||
.map((block) => {
|
||||
return document.getClosest(block.key, (parent) => {
|
||||
if (parent.kind != 'block') return false
|
||||
if (parent.object != 'block') return false
|
||||
if (properties.type != null && parent.type != properties.type) return false
|
||||
if (properties.isVoid != null && parent.isVoid != properties.isVoid) return false
|
||||
if (properties.data != null && !parent.data.isSuperset(properties.data)) return false
|
||||
@@ -1176,7 +1176,7 @@ Changes.unwrapInlineAtRange = (change, range, properties, options = {}) => {
|
||||
const inlines = texts
|
||||
.map((text) => {
|
||||
return document.getClosest(text.key, (parent) => {
|
||||
if (parent.kind != 'inline') return false
|
||||
if (parent.object != 'inline') return false
|
||||
if (properties.type != null && parent.type != properties.type) return false
|
||||
if (properties.isVoid != null && parent.isVoid != properties.isVoid) return false
|
||||
if (properties.data != null && !parent.data.isSuperset(properties.data)) return false
|
||||
|
@@ -179,7 +179,7 @@ Changes.mergeNodeByKey = (change, key, options = {}) => {
|
||||
throw new Error(`Unable to merge node with key "${key}", no previous key.`)
|
||||
}
|
||||
|
||||
const position = previous.kind == 'text' ? previous.text.length : previous.nodes.size
|
||||
const position = previous.object == 'text' ? previous.text.length : previous.nodes.size
|
||||
|
||||
change.applyOperation({
|
||||
type: 'merge_node',
|
||||
@@ -300,7 +300,7 @@ Changes.removeAllMarksByKey = (change, key, options = {}) => {
|
||||
const { state } = change
|
||||
const { document } = state
|
||||
const node = document.getNode(key)
|
||||
const texts = node.kind === 'text' ? [node] : node.getTextsAsArray()
|
||||
const texts = node.object === 'text' ? [node] : node.getTextsAsArray()
|
||||
|
||||
texts.forEach((text) => {
|
||||
text.getMarksAsArray().forEach((mark) => {
|
||||
@@ -711,12 +711,12 @@ Changes.wrapNodeByKey = (change, key, parent) => {
|
||||
parent = Node.create(parent)
|
||||
parent = parent.set('nodes', parent.nodes.clear())
|
||||
|
||||
if (parent.kind == 'block') {
|
||||
if (parent.object == 'block') {
|
||||
change.wrapBlockByKey(key, parent)
|
||||
return
|
||||
}
|
||||
|
||||
if (parent.kind == 'inline') {
|
||||
if (parent.object == 'inline') {
|
||||
change.wrapInlineByKey(key, parent)
|
||||
return
|
||||
}
|
||||
|
@@ -346,7 +346,7 @@ const DIRECTIONS = [
|
||||
'Previous',
|
||||
]
|
||||
|
||||
const KINDS = [
|
||||
const OBJECTS = [
|
||||
'Block',
|
||||
'Inline',
|
||||
'Text',
|
||||
@@ -365,10 +365,10 @@ PREFIXES.forEach((prefix) => {
|
||||
edges.forEach((edge) => {
|
||||
const method = `${prefix}${edge}Of`
|
||||
|
||||
KINDS.forEach((kind) => {
|
||||
const getNode = kind == 'Text' ? 'getNode' : `getClosest${kind}`
|
||||
OBJECTS.forEach((object) => {
|
||||
const getNode = object == 'Text' ? 'getNode' : `getClosest${object}`
|
||||
|
||||
Changes[`${method}${kind}`] = (change) => {
|
||||
Changes[`${method}${object}`] = (change) => {
|
||||
const { value } = change
|
||||
const { document, selection } = value
|
||||
const node = document[getNode](selection.startKey)
|
||||
@@ -377,10 +377,10 @@ PREFIXES.forEach((prefix) => {
|
||||
}
|
||||
|
||||
DIRECTIONS.forEach((direction) => {
|
||||
const getDirectionNode = `get${direction}${kind}`
|
||||
const getDirectionNode = `get${direction}${object}`
|
||||
const directionKey = direction == 'Next' ? 'startKey' : 'endKey'
|
||||
|
||||
Changes[`${method}${direction}${kind}`] = (change) => {
|
||||
Changes[`${method}${direction}${object}`] = (change) => {
|
||||
const { value } = change
|
||||
const { document, selection } = value
|
||||
const node = document[getNode](selection[directionKey])
|
||||
|
@@ -63,7 +63,7 @@ Changes.normalizeNodeByKey = (change, key) => {
|
||||
*/
|
||||
|
||||
function normalizeNodeAndChildren(change, node, schema) {
|
||||
if (node.kind == 'text') {
|
||||
if (node.object == 'text') {
|
||||
normalizeNode(change, node, schema)
|
||||
return
|
||||
}
|
||||
@@ -124,7 +124,7 @@ function normalizeNodeAndChildren(change, node, schema) {
|
||||
function refindNode(change, node) {
|
||||
const { value } = change
|
||||
const { document } = value
|
||||
return node.kind == 'document'
|
||||
return node.object == 'document'
|
||||
? document
|
||||
: document.getDescendant(node.key)
|
||||
}
|
||||
|
@@ -19,8 +19,8 @@ const CORE_SCHEMA_RULES = [
|
||||
|
||||
{
|
||||
validateNode(node) {
|
||||
if (node.kind != 'document') return
|
||||
const invalids = node.nodes.filter(n => n.kind != 'block')
|
||||
if (node.object != 'document') return
|
||||
const invalids = node.nodes.filter(n => n.object != 'block')
|
||||
if (!invalids.size) return
|
||||
|
||||
return (change) => {
|
||||
@@ -39,11 +39,11 @@ const CORE_SCHEMA_RULES = [
|
||||
|
||||
{
|
||||
validateNode(node) {
|
||||
if (node.kind != 'block') return
|
||||
if (node.object != 'block') return
|
||||
const first = node.nodes.first()
|
||||
if (!first) return
|
||||
const kinds = first.kind == 'block' ? ['block'] : ['inline', 'text']
|
||||
const invalids = node.nodes.filter(n => !kinds.includes(n.kind))
|
||||
const objects = first.object == 'block' ? ['block'] : ['inline', 'text']
|
||||
const invalids = node.nodes.filter(n => !objects.includes(n.object))
|
||||
if (!invalids.size) return
|
||||
|
||||
return (change) => {
|
||||
@@ -62,8 +62,8 @@ const CORE_SCHEMA_RULES = [
|
||||
|
||||
{
|
||||
validateNode(node) {
|
||||
if (node.kind != 'inline') return
|
||||
const invalids = node.nodes.filter(n => n.kind != 'inline' && n.kind != 'text')
|
||||
if (node.object != 'inline') return
|
||||
const invalids = node.nodes.filter(n => n.object != 'inline' && n.object != 'text')
|
||||
if (!invalids.size) return
|
||||
|
||||
return (change) => {
|
||||
@@ -82,7 +82,7 @@ const CORE_SCHEMA_RULES = [
|
||||
|
||||
{
|
||||
validateNode(node) {
|
||||
if (node.kind != 'block' && node.kind != 'inline') return
|
||||
if (node.object != 'block' && node.object != 'inline') return
|
||||
if (node.nodes.size > 0) return
|
||||
|
||||
return (change) => {
|
||||
@@ -101,7 +101,7 @@ const CORE_SCHEMA_RULES = [
|
||||
{
|
||||
validateNode(node) {
|
||||
if (!node.isVoid) return
|
||||
if (node.kind != 'block' && node.kind != 'inline') return
|
||||
if (node.object != 'block' && node.object != 'inline') return
|
||||
if (node.text == ' ' && node.nodes.size == 1) return
|
||||
|
||||
return (change) => {
|
||||
@@ -130,8 +130,8 @@ const CORE_SCHEMA_RULES = [
|
||||
|
||||
{
|
||||
validateNode(node) {
|
||||
if (node.kind != 'block') return
|
||||
const invalids = node.nodes.filter(n => n.kind == 'inline' && n.text == '')
|
||||
if (node.object != 'block') return
|
||||
const invalids = node.nodes.filter(n => n.object == 'inline' && n.text == '')
|
||||
if (!invalids.size) return
|
||||
|
||||
return (change) => {
|
||||
@@ -158,16 +158,16 @@ const CORE_SCHEMA_RULES = [
|
||||
|
||||
{
|
||||
validateNode(node) {
|
||||
if (node.kind != 'block' && node.kind != 'inline') return
|
||||
if (node.object != 'block' && node.object != 'inline') return
|
||||
|
||||
const invalids = node.nodes.reduce((list, child, index) => {
|
||||
if (child.kind !== 'inline') return list
|
||||
if (child.object !== 'inline') return list
|
||||
|
||||
const prev = index > 0 ? node.nodes.get(index - 1) : null
|
||||
const next = node.nodes.get(index + 1)
|
||||
// We don't test if "prev" is inline, since it has already been processed in the loop
|
||||
const insertBefore = !prev
|
||||
const insertAfter = !next || (next.kind == 'inline')
|
||||
const insertAfter = !next || (next.object == 'inline')
|
||||
|
||||
if (insertAfter || insertBefore) {
|
||||
list = list.push({ insertAfter, insertBefore, index })
|
||||
@@ -205,13 +205,13 @@ const CORE_SCHEMA_RULES = [
|
||||
|
||||
{
|
||||
validateNode(node) {
|
||||
if (node.kind != 'block' && node.kind != 'inline') return
|
||||
if (node.object != 'block' && node.object != 'inline') return
|
||||
|
||||
const invalids = node.nodes
|
||||
.map((child, i) => {
|
||||
const next = node.nodes.get(i + 1)
|
||||
if (child.kind != 'text') return
|
||||
if (!next || next.kind != 'text') return
|
||||
if (child.object != 'text') return
|
||||
if (!next || next.object != 'text') return
|
||||
return next
|
||||
})
|
||||
.filter(Boolean)
|
||||
@@ -236,25 +236,25 @@ const CORE_SCHEMA_RULES = [
|
||||
|
||||
{
|
||||
validateNode(node) {
|
||||
if (node.kind != 'block' && node.kind != 'inline') return
|
||||
if (node.object != 'block' && node.object != 'inline') return
|
||||
const { nodes } = node
|
||||
if (nodes.size <= 1) return
|
||||
|
||||
const invalids = nodes.filter((desc, i) => {
|
||||
if (desc.kind != 'text') return
|
||||
if (desc.object != 'text') return
|
||||
if (desc.text.length > 0) return
|
||||
|
||||
const prev = i > 0 ? nodes.get(i - 1) : null
|
||||
const next = nodes.get(i + 1)
|
||||
|
||||
// If it's the first node, and the next is a void, preserve it.
|
||||
if (!prev && next.kind == 'inline') return
|
||||
if (!prev && next.object == 'inline') return
|
||||
|
||||
// It it's the last node, and the previous is an inline, preserve it.
|
||||
if (!next && prev.kind == 'inline') return
|
||||
if (!next && prev.object == 'inline') return
|
||||
|
||||
// If it's surrounded by inlines, preserve it.
|
||||
if (next && prev && next.kind == 'inline' && prev.kind == 'inline') return
|
||||
if (next && prev && next.object == 'inline' && prev.object == 'inline') return
|
||||
|
||||
// Otherwise, remove it.
|
||||
return true
|
||||
|
@@ -10,6 +10,7 @@ import './document'
|
||||
*/
|
||||
|
||||
import isPlainObject from 'is-plain-object'
|
||||
import logger from 'slate-dev-logger'
|
||||
import { List, Map, Record } from 'immutable'
|
||||
|
||||
import MODEL_TYPES from '../constants/model-types'
|
||||
@@ -141,15 +142,20 @@ class Block extends Record(DEFAULTS) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the node's kind.
|
||||
* Object.
|
||||
*
|
||||
* @return {String}
|
||||
*/
|
||||
|
||||
get kind() {
|
||||
get object() {
|
||||
return 'block'
|
||||
}
|
||||
|
||||
get kind() {
|
||||
logger.deprecate('slate@0.32.0', 'The `kind` property of Slate objects has been renamed to `object`.')
|
||||
return this.object
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the block is empty.
|
||||
*
|
||||
@@ -179,7 +185,7 @@ class Block extends Record(DEFAULTS) {
|
||||
|
||||
toJSON(options = {}) {
|
||||
const object = {
|
||||
kind: this.kind,
|
||||
object: this.object,
|
||||
type: this.type,
|
||||
isVoid: this.isVoid,
|
||||
data: this.data.toJSON(),
|
||||
|
@@ -1,6 +1,7 @@
|
||||
|
||||
import Debug from 'debug'
|
||||
import isPlainObject from 'is-plain-object'
|
||||
import logger from 'slate-dev-logger'
|
||||
import pick from 'lodash/pick'
|
||||
import { List } from 'immutable'
|
||||
|
||||
@@ -51,15 +52,20 @@ class Change {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the kind.
|
||||
* Object.
|
||||
*
|
||||
* @return {String}
|
||||
*/
|
||||
|
||||
get kind() {
|
||||
get object() {
|
||||
return 'change'
|
||||
}
|
||||
|
||||
get kind() {
|
||||
logger.deprecate('slate@0.32.0', 'The `kind` property of Slate objects has been renamed to `object`.')
|
||||
return this.object
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply an `operation` to the current value, saving the operation to the
|
||||
* history if needed.
|
||||
|
@@ -1,5 +1,6 @@
|
||||
|
||||
import isPlainObject from 'is-plain-object'
|
||||
import logger from 'slate-dev-logger'
|
||||
import { List, Record, Set } from 'immutable'
|
||||
|
||||
import MODEL_TYPES from '../constants/model-types'
|
||||
@@ -120,15 +121,20 @@ class Character extends Record(DEFAULTS) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the kind.
|
||||
* Object.
|
||||
*
|
||||
* @return {String}
|
||||
*/
|
||||
|
||||
get kind() {
|
||||
get object() {
|
||||
return 'character'
|
||||
}
|
||||
|
||||
get kind() {
|
||||
logger.deprecate('slate@0.32.0', 'The `kind` property of Slate objects has been renamed to `object`.')
|
||||
return this.object
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a JSON representation of the character.
|
||||
*
|
||||
@@ -137,7 +143,7 @@ class Character extends Record(DEFAULTS) {
|
||||
|
||||
toJSON() {
|
||||
const object = {
|
||||
kind: this.kind,
|
||||
object: this.object,
|
||||
text: this.text,
|
||||
marks: this.marks.toArray().map(m => m.toJSON()),
|
||||
}
|
||||
|
@@ -11,6 +11,7 @@ import './inline'
|
||||
*/
|
||||
|
||||
import isPlainObject from 'is-plain-object'
|
||||
import logger from 'slate-dev-logger'
|
||||
import { List, Map, Record } from 'immutable'
|
||||
|
||||
import Node from './node'
|
||||
@@ -105,15 +106,20 @@ class Document extends Record(DEFAULTS) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the node's kind.
|
||||
* Object.
|
||||
*
|
||||
* @return {String}
|
||||
*/
|
||||
|
||||
get kind() {
|
||||
get object() {
|
||||
return 'document'
|
||||
}
|
||||
|
||||
get kind() {
|
||||
logger.deprecate('slate@0.32.0', 'The `kind` property of Slate objects has been renamed to `object`.')
|
||||
return this.object
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the document is empty.
|
||||
*
|
||||
@@ -143,7 +149,7 @@ class Document extends Record(DEFAULTS) {
|
||||
|
||||
toJSON(options = {}) {
|
||||
const object = {
|
||||
kind: this.kind,
|
||||
object: this.object,
|
||||
data: this.data.toJSON(),
|
||||
nodes: this.nodes.toArray().map(n => n.toJSON(options)),
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@
|
||||
import Debug from 'debug'
|
||||
import isEqual from 'lodash/isEqual'
|
||||
import isPlainObject from 'is-plain-object'
|
||||
import logger from 'slate-dev-logger'
|
||||
import { List, Record, Stack } from 'immutable'
|
||||
|
||||
import MODEL_TYPES from '../constants/model-types'
|
||||
@@ -91,15 +92,20 @@ class History extends Record(DEFAULTS) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the kind.
|
||||
* Object.
|
||||
*
|
||||
* @return {String}
|
||||
*/
|
||||
|
||||
get kind() {
|
||||
get object() {
|
||||
return 'history'
|
||||
}
|
||||
|
||||
get kind() {
|
||||
logger.deprecate('slate@0.32.0', 'The `kind` property of Slate objects has been renamed to `object`.')
|
||||
return this.object
|
||||
}
|
||||
|
||||
/**
|
||||
* Save an `operation` into the history.
|
||||
*
|
||||
@@ -161,7 +167,7 @@ class History extends Record(DEFAULTS) {
|
||||
|
||||
toJSON() {
|
||||
const object = {
|
||||
kind: this.kind,
|
||||
object: this.object,
|
||||
redos: this.redos.toJSON(),
|
||||
undos: this.undos.toJSON(),
|
||||
}
|
||||
|
@@ -10,6 +10,7 @@ import './document'
|
||||
*/
|
||||
|
||||
import isPlainObject from 'is-plain-object'
|
||||
import logger from 'slate-dev-logger'
|
||||
import { List, Map, Record } from 'immutable'
|
||||
|
||||
import Node from './node'
|
||||
@@ -141,15 +142,20 @@ class Inline extends Record(DEFAULTS) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the node's kind.
|
||||
* Object.
|
||||
*
|
||||
* @return {String}
|
||||
*/
|
||||
|
||||
get kind() {
|
||||
get object() {
|
||||
return 'inline'
|
||||
}
|
||||
|
||||
get kind() {
|
||||
logger.deprecate('slate@0.32.0', 'The `kind` property of Slate objects has been renamed to `object`.')
|
||||
return this.object
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the inline is empty.
|
||||
*
|
||||
@@ -179,7 +185,7 @@ class Inline extends Record(DEFAULTS) {
|
||||
|
||||
toJSON(options = {}) {
|
||||
const object = {
|
||||
kind: this.kind,
|
||||
object: this.object,
|
||||
type: this.type,
|
||||
isVoid: this.isVoid,
|
||||
data: this.data.toJSON(),
|
||||
|
@@ -1,5 +1,6 @@
|
||||
|
||||
import isPlainObject from 'is-plain-object'
|
||||
import logger from 'slate-dev-logger'
|
||||
import { List, Record, Set } from 'immutable'
|
||||
|
||||
import MODEL_TYPES from '../constants/model-types'
|
||||
@@ -114,15 +115,20 @@ class Leaf extends Record(DEFAULTS) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the node's kind.
|
||||
* Object.
|
||||
*
|
||||
* @return {String}
|
||||
*/
|
||||
|
||||
get kind() {
|
||||
get object() {
|
||||
return 'leaf'
|
||||
}
|
||||
|
||||
get kind() {
|
||||
logger.deprecate('slate@0.32.0', 'The `kind` property of Slate objects has been renamed to `object`.')
|
||||
return this.object
|
||||
}
|
||||
|
||||
/**
|
||||
* Return leaf as a list of characters
|
||||
*
|
||||
@@ -151,7 +157,7 @@ class Leaf extends Record(DEFAULTS) {
|
||||
|
||||
toJSON() {
|
||||
const object = {
|
||||
kind: this.kind,
|
||||
object: this.object,
|
||||
text: this.text,
|
||||
marks: this.marks.toArray().map(m => m.toJSON()),
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
|
||||
import isPlainObject from 'is-plain-object'
|
||||
import logger from 'slate-dev-logger'
|
||||
import { Map, Record, Set } from 'immutable'
|
||||
|
||||
import MODEL_TYPES from '../constants/model-types'
|
||||
@@ -151,13 +152,18 @@ class Mark extends Record(DEFAULTS) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the kind.
|
||||
* Object.
|
||||
*/
|
||||
|
||||
get kind() {
|
||||
get object() {
|
||||
return 'mark'
|
||||
}
|
||||
|
||||
get kind() {
|
||||
logger.deprecate('slate@0.32.0', 'The `kind` property of Slate objects has been renamed to `object`.')
|
||||
return this.object
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the component for the node from a `schema`.
|
||||
*
|
||||
@@ -177,7 +183,7 @@ class Mark extends Record(DEFAULTS) {
|
||||
|
||||
toJSON() {
|
||||
const object = {
|
||||
kind: this.kind,
|
||||
object: this.object,
|
||||
type: this.type,
|
||||
data: this.data.toJSON(),
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
|
||||
import direction from 'direction'
|
||||
import isPlainObject from 'is-plain-object'
|
||||
import logger from 'slate-dev-logger'
|
||||
import { List, OrderedSet, Set } from 'immutable'
|
||||
|
||||
import Block from './block'
|
||||
@@ -37,13 +38,20 @@ class Node {
|
||||
}
|
||||
|
||||
if (isPlainObject(attrs)) {
|
||||
switch (attrs.kind) {
|
||||
let { object } = attrs
|
||||
|
||||
if (!object && attrs.kind) {
|
||||
logger.deprecate('slate@0.32.0', 'The `kind` property of Slate objects has been renamed to `object`.')
|
||||
object = attrs.kind
|
||||
}
|
||||
|
||||
switch (object) {
|
||||
case 'block': return Block.create(attrs)
|
||||
case 'document': return Document.create(attrs)
|
||||
case 'inline': return Inline.create(attrs)
|
||||
case 'text': return Text.create(attrs)
|
||||
default: {
|
||||
throw new Error('`Node.create` requires a `kind` string.')
|
||||
throw new Error('`Node.create` requires a `object` string.')
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -99,22 +107,27 @@ class Node {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a `Node` from a JSON `object`.
|
||||
* Create a `Node` from a JSON `value`.
|
||||
*
|
||||
* @param {Object} object
|
||||
* @param {Object} value
|
||||
* @return {Node}
|
||||
*/
|
||||
|
||||
static fromJSON(object) {
|
||||
const { kind } = object
|
||||
static fromJSON(value) {
|
||||
let { object } = value
|
||||
|
||||
switch (kind) {
|
||||
case 'block': return Block.fromJSON(object)
|
||||
case 'document': return Document.fromJSON(object)
|
||||
case 'inline': return Inline.fromJSON(object)
|
||||
case 'text': return Text.fromJSON(object)
|
||||
if (!object && value.kind) {
|
||||
logger.deprecate('slate@0.32.0', 'The `kind` property of Slate objects has been renamed to `object`.')
|
||||
object = value.kind
|
||||
}
|
||||
|
||||
switch (object) {
|
||||
case 'block': return Block.fromJSON(value)
|
||||
case 'document': return Document.fromJSON(value)
|
||||
case 'inline': return Inline.fromJSON(value)
|
||||
case 'text': return Text.fromJSON(value)
|
||||
default: {
|
||||
throw new Error(`\`Node.fromJSON\` requires a \`kind\` of either 'block', 'document', 'inline' or 'text', but you passed: ${kind}`)
|
||||
throw new Error(`\`Node.fromJSON\` requires an \`object\` of either 'block', 'document', 'inline' or 'text', but you passed: ${value}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -297,7 +310,7 @@ class Node {
|
||||
return false
|
||||
}
|
||||
|
||||
if (child.kind != 'text') {
|
||||
if (child.object != 'text') {
|
||||
ret = child.forEachDescendant(iterator)
|
||||
return ret
|
||||
}
|
||||
@@ -321,7 +334,7 @@ class Node {
|
||||
|
||||
let ancestors
|
||||
this.nodes.find((node) => {
|
||||
if (node.kind == 'text') return false
|
||||
if (node.object == 'text') return false
|
||||
ancestors = node.getAncestors(key)
|
||||
return ancestors
|
||||
})
|
||||
@@ -352,7 +365,7 @@ class Node {
|
||||
|
||||
getBlocksAsArray() {
|
||||
return this.nodes.reduce((array, child) => {
|
||||
if (child.kind != 'block') return array
|
||||
if (child.object != 'block') return array
|
||||
if (!child.isLeafBlock()) return array.concat(child.getBlocksAsArray())
|
||||
array.push(child)
|
||||
return array
|
||||
@@ -418,7 +431,7 @@ class Node {
|
||||
|
||||
getBlocksByTypeAsArray(type) {
|
||||
return this.nodes.reduce((array, node) => {
|
||||
if (node.kind != 'block') {
|
||||
if (node.object != 'block') {
|
||||
return array
|
||||
} else if (node.isLeafBlock() && node.type == type) {
|
||||
array.push(node)
|
||||
@@ -448,7 +461,7 @@ class Node {
|
||||
|
||||
getCharactersAsArray() {
|
||||
return this.nodes.reduce((arr, node) => {
|
||||
return node.kind == 'text'
|
||||
return node.object == 'text'
|
||||
? arr.concat(node.characters.toArray())
|
||||
: arr.concat(node.getCharactersAsArray())
|
||||
}, [])
|
||||
@@ -527,7 +540,7 @@ class Node {
|
||||
*/
|
||||
|
||||
getClosestBlock(key) {
|
||||
return this.getClosest(key, parent => parent.kind == 'block')
|
||||
return this.getClosest(key, parent => parent.object == 'block')
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -538,7 +551,7 @@ class Node {
|
||||
*/
|
||||
|
||||
getClosestInline(key) {
|
||||
return this.getClosest(key, parent => parent.kind == 'inline')
|
||||
return this.getClosest(key, parent => parent.object == 'inline')
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -627,7 +640,7 @@ class Node {
|
||||
const found = this.nodes.find((node) => {
|
||||
if (node.key === key) {
|
||||
return node
|
||||
} else if (node.kind !== 'text') {
|
||||
} else if (node.object !== 'text') {
|
||||
descendantFound = node.getDescendant(key)
|
||||
return descendantFound
|
||||
} else {
|
||||
@@ -667,7 +680,7 @@ class Node {
|
||||
let descendantFound = null
|
||||
|
||||
const found = this.nodes.find((node) => {
|
||||
if (node.kind == 'text') return true
|
||||
if (node.object == 'text') return true
|
||||
descendantFound = node.getFirstText()
|
||||
return descendantFound
|
||||
})
|
||||
@@ -700,7 +713,7 @@ class Node {
|
||||
|
||||
while (parent = node.getParent(child.key)) {
|
||||
const index = parent.nodes.indexOf(child)
|
||||
const position = child.kind == 'text'
|
||||
const position = child.object == 'text'
|
||||
? startOffset
|
||||
: child.nodes.indexOf(previous)
|
||||
|
||||
@@ -714,7 +727,7 @@ class Node {
|
||||
|
||||
while (parent = node.getParent(child.key)) {
|
||||
const index = parent.nodes.indexOf(child)
|
||||
const position = child.kind == 'text'
|
||||
const position = child.object == 'text'
|
||||
? startKey == endKey ? endOffset - startOffset : endOffset
|
||||
: child.nodes.indexOf(previous)
|
||||
|
||||
@@ -766,7 +779,7 @@ class Node {
|
||||
*/
|
||||
|
||||
getFurthestBlock(key) {
|
||||
return this.getFurthest(key, node => node.kind == 'block')
|
||||
return this.getFurthest(key, node => node.object == 'block')
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -777,7 +790,7 @@ class Node {
|
||||
*/
|
||||
|
||||
getFurthestInline(key) {
|
||||
return this.getFurthest(key, node => node.kind == 'inline')
|
||||
return this.getFurthest(key, node => node.object == 'inline')
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -791,7 +804,7 @@ class Node {
|
||||
key = assertKey(key)
|
||||
return this.nodes.find((node) => {
|
||||
if (node.key == key) return true
|
||||
if (node.kind == 'text') return false
|
||||
if (node.object == 'text') return false
|
||||
return node.hasDescendant(key)
|
||||
})
|
||||
}
|
||||
@@ -841,7 +854,7 @@ class Node {
|
||||
let array = []
|
||||
|
||||
this.nodes.forEach((child) => {
|
||||
if (child.kind == 'text') return
|
||||
if (child.object == 'text') return
|
||||
if (child.isLeafInline()) {
|
||||
array.push(child)
|
||||
} else {
|
||||
@@ -903,7 +916,7 @@ class Node {
|
||||
|
||||
getInlinesByTypeAsArray(type) {
|
||||
return this.nodes.reduce((inlines, node) => {
|
||||
if (node.kind == 'text') {
|
||||
if (node.object == 'text') {
|
||||
return inlines
|
||||
} else if (node.isLeafInline() && node.type == type) {
|
||||
inlines.push(node)
|
||||
@@ -951,7 +964,7 @@ class Node {
|
||||
let descendantFound = null
|
||||
|
||||
const found = this.nodes.findLast((node) => {
|
||||
if (node.kind == 'text') return true
|
||||
if (node.object == 'text') return true
|
||||
descendantFound = node.getLastText()
|
||||
return descendantFound
|
||||
})
|
||||
@@ -1142,7 +1155,7 @@ class Node {
|
||||
|
||||
getMarksByTypeAsArray(type) {
|
||||
return this.nodes.reduce((array, node) => {
|
||||
return node.kind == 'text'
|
||||
return node.object == 'text'
|
||||
? array.concat(node.getMarksAsArray().filter(m => m.type == type))
|
||||
: array.concat(node.getMarksByTypeAsArray(type))
|
||||
}, [])
|
||||
@@ -1159,7 +1172,7 @@ class Node {
|
||||
const child = this.assertDescendant(key)
|
||||
let last
|
||||
|
||||
if (child.kind == 'block') {
|
||||
if (child.object == 'block') {
|
||||
last = child.getLastText()
|
||||
} else {
|
||||
const block = this.getClosestBlock(key)
|
||||
@@ -1286,7 +1299,7 @@ class Node {
|
||||
let node = null
|
||||
|
||||
this.nodes.find((child) => {
|
||||
if (child.kind == 'text') {
|
||||
if (child.object == 'text') {
|
||||
return false
|
||||
} else {
|
||||
node = child.getParent(key)
|
||||
@@ -1340,7 +1353,7 @@ class Node {
|
||||
const child = this.assertDescendant(key)
|
||||
let first
|
||||
|
||||
if (child.kind == 'block') {
|
||||
if (child.object == 'block') {
|
||||
first = child.getFirstText()
|
||||
} else {
|
||||
const block = this.getClosestBlock(key)
|
||||
@@ -1423,7 +1436,7 @@ class Node {
|
||||
let end = null
|
||||
|
||||
this.nodes.forEach((child, i) => {
|
||||
if (child.kind == 'text') {
|
||||
if (child.object == 'text') {
|
||||
if (start == null && child.key == startKey) start = i
|
||||
if (end == null && child.key == endKey) end = i + 1
|
||||
} else {
|
||||
@@ -1507,7 +1520,7 @@ class Node {
|
||||
let array = []
|
||||
|
||||
this.nodes.forEach((node) => {
|
||||
if (node.kind == 'text') {
|
||||
if (node.object == 'text') {
|
||||
array.push(node)
|
||||
} else {
|
||||
array = array.concat(node.getTextsAsArray())
|
||||
@@ -1613,7 +1626,7 @@ class Node {
|
||||
node = node.regenerateKey()
|
||||
}
|
||||
|
||||
if (node.kind != 'text') {
|
||||
if (node.object != 'text') {
|
||||
node = node.mapDescendants((desc) => {
|
||||
return keys.contains(desc.key)
|
||||
? desc.regenerateKey()
|
||||
@@ -1676,8 +1689,8 @@ class Node {
|
||||
|
||||
isLeafBlock() {
|
||||
return (
|
||||
this.kind == 'block' &&
|
||||
this.nodes.every(n => n.kind != 'block')
|
||||
this.object == 'block' &&
|
||||
this.nodes.every(n => n.object != 'block')
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1689,8 +1702,8 @@ class Node {
|
||||
|
||||
isLeafInline() {
|
||||
return (
|
||||
this.kind == 'inline' &&
|
||||
this.nodes.every(n => n.kind != 'inline')
|
||||
this.object == 'inline' &&
|
||||
this.nodes.every(n => n.object != 'inline')
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1709,12 +1722,12 @@ class Node {
|
||||
let one = node.nodes.get(withIndex)
|
||||
const two = node.nodes.get(index)
|
||||
|
||||
if (one.kind != two.kind) {
|
||||
throw new Error(`Tried to merge two nodes of different kinds: "${one.kind}" and "${two.kind}".`)
|
||||
if (one.object != two.object) {
|
||||
throw new Error(`Tried to merge two nodes of different objects: "${one.object}" and "${two.object}".`)
|
||||
}
|
||||
|
||||
// If the nodes are text nodes, concatenate their characters together.
|
||||
if (one.kind == 'text') {
|
||||
if (one.object == 'text') {
|
||||
const characters = one.characters.concat(two.characters)
|
||||
one = one.set('characters', characters)
|
||||
}
|
||||
@@ -1763,7 +1776,7 @@ class Node {
|
||||
|
||||
nodes.forEach((node, i) => {
|
||||
let ret = node
|
||||
if (ret.kind != 'text') ret = ret.mapDescendants(iterator)
|
||||
if (ret.object != 'text') ret = ret.mapDescendants(iterator)
|
||||
ret = iterator(ret, i, this.nodes)
|
||||
if (ret == node) return
|
||||
|
||||
@@ -1835,7 +1848,7 @@ class Node {
|
||||
|
||||
// If the child is a text node, the `position` refers to the text offset at
|
||||
// which to split it.
|
||||
if (child.kind == 'text') {
|
||||
if (child.object == 'text') {
|
||||
const befores = child.characters.take(position)
|
||||
const afters = child.characters.skip(position)
|
||||
one = child.set('characters', befores)
|
||||
|
@@ -1,5 +1,6 @@
|
||||
|
||||
import isPlainObject from 'is-plain-object'
|
||||
import logger from 'slate-dev-logger'
|
||||
import { List, Record } from 'immutable'
|
||||
|
||||
import MODEL_TYPES from '../constants/model-types'
|
||||
@@ -194,15 +195,20 @@ class Operation extends Record(DEFAULTS) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the node's kind.
|
||||
* Object.
|
||||
*
|
||||
* @return {String}
|
||||
*/
|
||||
|
||||
get kind() {
|
||||
get object() {
|
||||
return 'operation'
|
||||
}
|
||||
|
||||
get kind() {
|
||||
logger.deprecate('slate@0.32.0', 'The `kind` property of Slate objects has been renamed to `object`.')
|
||||
return this.object
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a JSON representation of the operation.
|
||||
*
|
||||
@@ -211,8 +217,8 @@ class Operation extends Record(DEFAULTS) {
|
||||
*/
|
||||
|
||||
toJSON(options = {}) {
|
||||
const { kind, type } = this
|
||||
const object = { kind, type }
|
||||
const { object, type } = this
|
||||
const json = { object, type }
|
||||
const ATTRIBUTES = OPERATION_ATTRIBUTES[type]
|
||||
|
||||
for (const key of ATTRIBUTES) {
|
||||
@@ -264,10 +270,10 @@ class Operation extends Record(DEFAULTS) {
|
||||
value = v
|
||||
}
|
||||
|
||||
object[key] = value
|
||||
json[key] = value
|
||||
}
|
||||
|
||||
return object
|
||||
return json
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -151,15 +151,20 @@ class Range extends Record(DEFAULTS) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the kind.
|
||||
* Object.
|
||||
*
|
||||
* @return {String}
|
||||
*/
|
||||
|
||||
get kind() {
|
||||
get object() {
|
||||
return 'range'
|
||||
}
|
||||
|
||||
get kind() {
|
||||
logger.deprecate('slate@0.32.0', 'The `kind` property of Slate objects has been renamed to `object`.')
|
||||
return this.object
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the range is blurred.
|
||||
*
|
||||
@@ -315,7 +320,7 @@ class Range extends Record(DEFAULTS) {
|
||||
*/
|
||||
|
||||
hasAnchorIn(node) {
|
||||
return node.kind == 'text'
|
||||
return node.object == 'text'
|
||||
? node.key == this.anchorKey
|
||||
: this.anchorKey != null && node.hasDescendant(this.anchorKey)
|
||||
}
|
||||
@@ -371,7 +376,7 @@ class Range extends Record(DEFAULTS) {
|
||||
*/
|
||||
|
||||
hasFocusIn(node) {
|
||||
return node.kind == 'text'
|
||||
return node.object == 'text'
|
||||
? node.key == this.focusKey
|
||||
: this.focusKey != null && node.hasDescendant(this.focusKey)
|
||||
}
|
||||
@@ -698,7 +703,7 @@ class Range extends Record(DEFAULTS) {
|
||||
}
|
||||
|
||||
// If the anchor node isn't a text node, match it to one.
|
||||
if (anchorNode.kind != 'text') {
|
||||
if (anchorNode.object != 'text') {
|
||||
logger.warn('The range anchor was set to a Node that is not a Text node. This should not happen and can degrade performance. The node in question was:', anchorNode)
|
||||
const anchorText = anchorNode.getTextAtOffset(anchorOffset)
|
||||
const offset = anchorNode.getOffset(anchorText.key)
|
||||
@@ -707,7 +712,7 @@ class Range extends Record(DEFAULTS) {
|
||||
}
|
||||
|
||||
// If the focus node isn't a text node, match it to one.
|
||||
if (focusNode.kind != 'text') {
|
||||
if (focusNode.object != 'text') {
|
||||
logger.warn('The range focus was set to a Node that is not a Text node. This should not happen and can degrade performance. The node in question was:', focusNode)
|
||||
const focusText = focusNode.getTextAtOffset(focusOffset)
|
||||
const offset = focusNode.getOffset(focusText.key)
|
||||
@@ -742,7 +747,7 @@ class Range extends Record(DEFAULTS) {
|
||||
|
||||
toJSON() {
|
||||
const object = {
|
||||
kind: this.kind,
|
||||
object: this.object,
|
||||
anchorKey: this.anchorKey,
|
||||
anchorOffset: this.anchorOffset,
|
||||
focusKey: this.focusKey,
|
||||
@@ -861,7 +866,7 @@ ALIAS_METHODS.forEach(([ alias, method ]) => {
|
||||
*/
|
||||
|
||||
function getFirst(node) {
|
||||
return node.kind == 'text' ? node : node.getFirstText()
|
||||
return node.object == 'text' ? node : node.getFirstText()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -872,7 +877,7 @@ function getFirst(node) {
|
||||
*/
|
||||
|
||||
function getLast(node) {
|
||||
return node.kind == 'text' ? node : node.getLastText()
|
||||
return node.object == 'text' ? node : node.getLastText()
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -1,6 +1,7 @@
|
||||
|
||||
import Debug from 'debug'
|
||||
import isPlainObject from 'is-plain-object'
|
||||
import logger from 'slate-dev-logger'
|
||||
import mergeWith from 'lodash/mergeWith'
|
||||
import { Record } from 'immutable'
|
||||
|
||||
@@ -15,19 +16,19 @@ import memoize from '../utils/memoize'
|
||||
* @type {Object}
|
||||
*/
|
||||
|
||||
const CHILD_KIND_INVALID = 'child_kind_invalid'
|
||||
const CHILD_OBJECT_INVALID = 'child_object_invalid'
|
||||
const CHILD_REQUIRED = 'child_required'
|
||||
const CHILD_TYPE_INVALID = 'child_type_invalid'
|
||||
const CHILD_UNKNOWN = 'child_unknown'
|
||||
const FIRST_CHILD_KIND_INVALID = 'first_child_kind_invalid'
|
||||
const FIRST_CHILD_OBJECT_INVALID = 'first_child_object_invalid'
|
||||
const FIRST_CHILD_TYPE_INVALID = 'first_child_type_invalid'
|
||||
const LAST_CHILD_KIND_INVALID = 'last_child_kind_invalid'
|
||||
const LAST_CHILD_OBJECT_INVALID = 'last_child_object_invalid'
|
||||
const LAST_CHILD_TYPE_INVALID = 'last_child_type_invalid'
|
||||
const NODE_DATA_INVALID = 'node_data_invalid'
|
||||
const NODE_IS_VOID_INVALID = 'node_is_void_invalid'
|
||||
const NODE_MARK_INVALID = 'node_mark_invalid'
|
||||
const NODE_TEXT_INVALID = 'node_text_invalid'
|
||||
const PARENT_KIND_INVALID = 'parent_kind_invalid'
|
||||
const PARENT_OBJECT_INVALID = 'parent_object_invalid'
|
||||
const PARENT_TYPE_INVALID = 'parent_type_invalid'
|
||||
|
||||
/**
|
||||
@@ -128,15 +129,20 @@ class Schema extends Record(DEFAULTS) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the kind.
|
||||
* Object.
|
||||
*
|
||||
* @return {String}
|
||||
*/
|
||||
|
||||
get kind() {
|
||||
get object() {
|
||||
return 'schema'
|
||||
}
|
||||
|
||||
get kind() {
|
||||
logger.deprecate('slate@0.32.0', 'The `kind` property of Slate objects has been renamed to `object`.')
|
||||
return this.object
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the rule for an `object`.
|
||||
*
|
||||
@@ -145,7 +151,7 @@ class Schema extends Record(DEFAULTS) {
|
||||
*/
|
||||
|
||||
getRule(object) {
|
||||
switch (object.kind) {
|
||||
switch (object.object) {
|
||||
case 'document': return this.document
|
||||
case 'block': return this.blocks[object.type]
|
||||
case 'inline': return this.inlines[object.type]
|
||||
@@ -206,32 +212,32 @@ class Schema extends Record(DEFAULTS) {
|
||||
|
||||
normalize(change, reason, context) {
|
||||
switch (reason) {
|
||||
case CHILD_KIND_INVALID:
|
||||
case CHILD_OBJECT_INVALID:
|
||||
case CHILD_TYPE_INVALID:
|
||||
case CHILD_UNKNOWN:
|
||||
case FIRST_CHILD_KIND_INVALID:
|
||||
case FIRST_CHILD_OBJECT_INVALID:
|
||||
case FIRST_CHILD_TYPE_INVALID:
|
||||
case LAST_CHILD_KIND_INVALID:
|
||||
case LAST_CHILD_OBJECT_INVALID:
|
||||
case LAST_CHILD_TYPE_INVALID: {
|
||||
const { child, node } = context
|
||||
return child.kind == 'text' && node.kind == 'block' && node.nodes.size == 1
|
||||
return child.object == 'text' && node.object == 'block' && node.nodes.size == 1
|
||||
? change.removeNodeByKey(node.key)
|
||||
: change.removeNodeByKey(child.key)
|
||||
}
|
||||
|
||||
case CHILD_REQUIRED:
|
||||
case NODE_TEXT_INVALID:
|
||||
case PARENT_KIND_INVALID:
|
||||
case PARENT_OBJECT_INVALID:
|
||||
case PARENT_TYPE_INVALID: {
|
||||
const { node } = context
|
||||
return node.kind == 'document'
|
||||
return node.object == 'document'
|
||||
? node.nodes.forEach(child => change.removeNodeByKey(child.key))
|
||||
: change.removeNodeByKey(node.key)
|
||||
}
|
||||
|
||||
case NODE_DATA_INVALID: {
|
||||
const { node, key } = context
|
||||
return node.data.get(key) === undefined && node.kind != 'document'
|
||||
return node.data.get(key) === undefined && node.object != 'document'
|
||||
? change.removeNodeByKey(node.key)
|
||||
: change.setNodeByKey(node.key, { data: node.data.delete(key) })
|
||||
}
|
||||
@@ -260,7 +266,7 @@ class Schema extends Record(DEFAULTS) {
|
||||
const ret = this.stack.find('validateNode', node)
|
||||
if (ret) return ret
|
||||
|
||||
if (node.kind == 'text') return
|
||||
if (node.object == 'text') return
|
||||
|
||||
const rule = this.getRule(node) || {}
|
||||
const parents = this.getParentRules()
|
||||
@@ -302,11 +308,11 @@ class Schema extends Record(DEFAULTS) {
|
||||
}
|
||||
|
||||
if (rule.first != null) {
|
||||
const { kinds, types } = rule.first
|
||||
const { objects, types } = rule.first
|
||||
const child = node.nodes.first()
|
||||
|
||||
if (child && kinds && !kinds.includes(child.kind)) {
|
||||
return this.fail(FIRST_CHILD_KIND_INVALID, { ...ctx, child })
|
||||
if (child && objects && !objects.includes(child.object)) {
|
||||
return this.fail(FIRST_CHILD_OBJECT_INVALID, { ...ctx, child })
|
||||
}
|
||||
|
||||
if (child && types && !types.includes(child.type)) {
|
||||
@@ -315,11 +321,11 @@ class Schema extends Record(DEFAULTS) {
|
||||
}
|
||||
|
||||
if (rule.last != null) {
|
||||
const { kinds, types } = rule.last
|
||||
const { objects, types } = rule.last
|
||||
const child = node.nodes.last()
|
||||
|
||||
if (child && kinds && !kinds.includes(child.kind)) {
|
||||
return this.fail(LAST_CHILD_KIND_INVALID, { ...ctx, child })
|
||||
if (child && objects && !objects.includes(child.object)) {
|
||||
return this.fail(LAST_CHILD_OBJECT_INVALID, { ...ctx, child })
|
||||
}
|
||||
|
||||
if (child && types && !types.includes(child.type)) {
|
||||
@@ -363,11 +369,11 @@ class Schema extends Record(DEFAULTS) {
|
||||
}
|
||||
|
||||
while (nextChild()) {
|
||||
if (parents != null && child.kind != 'text' && child.type in parents) {
|
||||
if (parents != null && child.object != 'text' && child.type in parents) {
|
||||
const r = parents[child.type]
|
||||
|
||||
if (r.parent.kinds != null && !r.parent.kinds.includes(node.kind)) {
|
||||
return this.fail(PARENT_KIND_INVALID, { node: child, parent: node, rule: r })
|
||||
if (r.parent.objects != null && !r.parent.objects.includes(node.object)) {
|
||||
return this.fail(PARENT_OBJECT_INVALID, { node: child, parent: node, rule: r })
|
||||
}
|
||||
|
||||
if (r.parent.types != null && !r.parent.types.includes(node.type)) {
|
||||
@@ -380,12 +386,12 @@ class Schema extends Record(DEFAULTS) {
|
||||
return this.fail(CHILD_UNKNOWN, { ...ctx, child, index })
|
||||
}
|
||||
|
||||
if (def.kinds != null && !def.kinds.includes(child.kind)) {
|
||||
if (def.objects != null && !def.objects.includes(child.object)) {
|
||||
if (offset >= min && nextDef()) {
|
||||
rewind()
|
||||
continue
|
||||
}
|
||||
return this.fail(CHILD_KIND_INVALID, { ...ctx, child, index })
|
||||
return this.fail(CHILD_OBJECT_INVALID, { ...ctx, child, index })
|
||||
}
|
||||
|
||||
if (def.types != null && !def.types.includes(child.type)) {
|
||||
@@ -418,7 +424,7 @@ class Schema extends Record(DEFAULTS) {
|
||||
|
||||
toJSON() {
|
||||
const object = {
|
||||
kind: this.kind,
|
||||
object: this.object,
|
||||
document: this.document,
|
||||
blocks: this.blocks,
|
||||
inlines: this.inlines,
|
||||
@@ -501,13 +507,13 @@ function resolveDocumentRule(obj) {
|
||||
/**
|
||||
* Resolve a node rule with `type` from `obj`.
|
||||
*
|
||||
* @param {String} kind
|
||||
* @param {String} object
|
||||
* @param {String} type
|
||||
* @param {Object} obj
|
||||
* @return {Object}
|
||||
*/
|
||||
|
||||
function resolveNodeRule(kind, type, obj) {
|
||||
function resolveNodeRule(object, type, obj) {
|
||||
return {
|
||||
data: {},
|
||||
isVoid: null,
|
||||
@@ -521,7 +527,7 @@ function resolveNodeRule(kind, type, obj) {
|
||||
}
|
||||
|
||||
/**
|
||||
* A Lodash customizer for merging schema definitions. Special cases `kinds`
|
||||
* A Lodash customizer for merging schema definitions. Special cases `objects`
|
||||
* and `types` arrays to be unioned, and ignores new `null` values.
|
||||
*
|
||||
* @param {Mixed} target
|
||||
@@ -530,7 +536,7 @@ function resolveNodeRule(kind, type, obj) {
|
||||
*/
|
||||
|
||||
function customizer(target, source, key) {
|
||||
if (key == 'kinds' || key == 'types') {
|
||||
if (key == 'objects' || key == 'types') {
|
||||
return target == null ? source : target.concat(source)
|
||||
} else {
|
||||
return source == null ? target : source
|
||||
|
@@ -1,4 +1,5 @@
|
||||
|
||||
import logger from 'slate-dev-logger'
|
||||
import { Record } from 'immutable'
|
||||
|
||||
import MODEL_TYPES from '../constants/model-types'
|
||||
@@ -46,15 +47,20 @@ class Stack extends Record(DEFAULTS) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the kind.
|
||||
* Object.
|
||||
*
|
||||
* @return {String}
|
||||
*/
|
||||
|
||||
get kind() {
|
||||
get object() {
|
||||
return 'stack'
|
||||
}
|
||||
|
||||
get kind() {
|
||||
logger.deprecate('slate@0.32.0', 'The `kind` property of Slate objects has been renamed to `object`.')
|
||||
return this.object
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all plugins with `property`.
|
||||
*
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user