mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-09-02 19:52:32 +02:00
added export constant enum for schema violations (#1532)
* added export constant enum for schema violations * updated examples to use the schema violations enum * use SchemaViolations enum in tests and docs * fixed path for schema violations import
This commit is contained in:
committed by
Zach Schneider
parent
e6c7934cb9
commit
7d5a33025b
@@ -214,9 +214,13 @@ Returns a JSON representation of the schema.
|
|||||||
|
|
||||||
## Invalid Reasons
|
## Invalid Reasons
|
||||||
|
|
||||||
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:
|
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. Invalid reason constants are available through the`SchemaViolations` object.
|
||||||
|
|
||||||
### `child_object_invalid`
|
`import { SchemaViolations } from 'slate'`
|
||||||
|
|
||||||
|
Here's the full set:
|
||||||
|
|
||||||
|
### `SchemaViolations.ChildObjectInvalid`
|
||||||
|
|
||||||
```js
|
```js
|
||||||
{
|
{
|
||||||
@@ -227,7 +231,7 @@ When supplying your own `normalize` property for a schema rule, it will be calle
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### `child_required`
|
### `SchemaViolations.ChildRequired`
|
||||||
|
|
||||||
```js
|
```js
|
||||||
{
|
{
|
||||||
@@ -237,7 +241,7 @@ When supplying your own `normalize` property for a schema rule, it will be calle
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### `child_type_invalid`
|
### `SchemaViolations.ChildTypeInvalid`
|
||||||
|
|
||||||
```js
|
```js
|
||||||
{
|
{
|
||||||
@@ -248,7 +252,7 @@ When supplying your own `normalize` property for a schema rule, it will be calle
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### `child_unknown`
|
### `SchemaViolations.ChildUnknown`
|
||||||
|
|
||||||
```js
|
```js
|
||||||
{
|
{
|
||||||
@@ -259,7 +263,7 @@ When supplying your own `normalize` property for a schema rule, it will be calle
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### `first_child_object_invalid`
|
### `SchemaViolations.FirstChildObjectInvalid`
|
||||||
|
|
||||||
```js
|
```js
|
||||||
{
|
{
|
||||||
@@ -269,7 +273,7 @@ When supplying your own `normalize` property for a schema rule, it will be calle
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### `first_child_type_invalid`
|
### `SchemaViolations.FirstChildTypeInvalid`
|
||||||
|
|
||||||
```js
|
```js
|
||||||
{
|
{
|
||||||
@@ -279,7 +283,7 @@ When supplying your own `normalize` property for a schema rule, it will be calle
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### `last_child_object_invalid`
|
### `SchemaViolations.LastChildObjectInvalid`
|
||||||
|
|
||||||
```js
|
```js
|
||||||
{
|
{
|
||||||
@@ -289,7 +293,7 @@ When supplying your own `normalize` property for a schema rule, it will be calle
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### `last_child_type_invalid`
|
### `SchemaViolations.LastChildTypeInvalid`
|
||||||
|
|
||||||
```js
|
```js
|
||||||
{
|
{
|
||||||
@@ -299,7 +303,7 @@ When supplying your own `normalize` property for a schema rule, it will be calle
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### `node_data_invalid`
|
### `SchemaViolations.NodeDataInvalid`
|
||||||
|
|
||||||
```js
|
```js
|
||||||
{
|
{
|
||||||
@@ -310,7 +314,7 @@ When supplying your own `normalize` property for a schema rule, it will be calle
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### `node_is_void_invalid`
|
### `SchemaViolations.NodeIsVoidInvalid`
|
||||||
|
|
||||||
```js
|
```js
|
||||||
{
|
{
|
||||||
@@ -319,7 +323,7 @@ When supplying your own `normalize` property for a schema rule, it will be calle
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### `node_object_invalid`
|
### `SchemaViolations.NodeObjectInvalid`
|
||||||
|
|
||||||
```js
|
```js
|
||||||
{
|
{
|
||||||
@@ -328,7 +332,7 @@ When supplying your own `normalize` property for a schema rule, it will be calle
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### `node_mark_invalid`
|
### `SchemaViolations.NodeMarkInvalid`
|
||||||
|
|
||||||
```js
|
```js
|
||||||
{
|
{
|
||||||
@@ -338,7 +342,7 @@ When supplying your own `normalize` property for a schema rule, it will be calle
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### `node_text_invalid`
|
### `SchemaViolations.NodeTextInvalid`
|
||||||
|
|
||||||
```js
|
```js
|
||||||
{
|
{
|
||||||
@@ -348,7 +352,7 @@ When supplying your own `normalize` property for a schema rule, it will be calle
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### `parent_object_invalid`
|
### `SchemaViolations.ParentObjectInvalid`
|
||||||
|
|
||||||
```js
|
```js
|
||||||
{
|
{
|
||||||
@@ -358,7 +362,7 @@ When supplying your own `normalize` property for a schema rule, it will be calle
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### `parent_type_invalid`
|
### `SchemaViolations.ParentTypeInvalid`
|
||||||
|
|
||||||
```js
|
```js
|
||||||
{
|
{
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
import { Editor } from 'slate-react'
|
import { Editor } from 'slate-react'
|
||||||
import { Block, Value } from 'slate'
|
import { Block, Value, SchemaViolations } from 'slate'
|
||||||
|
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import initialValue from './value.json'
|
import initialValue from './value.json'
|
||||||
@@ -19,10 +19,10 @@ const schema = {
|
|||||||
],
|
],
|
||||||
normalize: (change, reason, { node, child, index }) => {
|
normalize: (change, reason, { node, child, index }) => {
|
||||||
switch (reason) {
|
switch (reason) {
|
||||||
case 'child_type_invalid': {
|
case SchemaViolations.ChildTypeInvalid: {
|
||||||
return change.setNodeByKey(child.key, index == 0 ? 'title' : 'paragraph')
|
return change.setNodeByKey(child.key, index == 0 ? 'title' : 'paragraph')
|
||||||
}
|
}
|
||||||
case 'child_required': {
|
case SchemaViolations.ChildRequired: {
|
||||||
const block = Block.create(index == 0 ? 'title' : 'paragraph')
|
const block = Block.create(index == 0 ? 'title' : 'paragraph')
|
||||||
return change.insertNodeByKey(node.key, index, block)
|
return change.insertNodeByKey(node.key, index, block)
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
import { Editor, getEventRange, getEventTransfer } from 'slate-react'
|
import { Editor, getEventRange, getEventTransfer } from 'slate-react'
|
||||||
import { Block, Value } from 'slate'
|
import { Block, Value, SchemaViolations } from 'slate'
|
||||||
|
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import initialValue from './value.json'
|
import initialValue from './value.json'
|
||||||
@@ -38,7 +38,7 @@ const schema = {
|
|||||||
last: { types: ['paragraph'] },
|
last: { types: ['paragraph'] },
|
||||||
normalize: (change, reason, { node, child }) => {
|
normalize: (change, reason, { node, child }) => {
|
||||||
switch (reason) {
|
switch (reason) {
|
||||||
case 'last_child_type_invalid': {
|
case SchemaViolations.LastChildTypeInvalid: {
|
||||||
const paragraph = Block.create('paragraph')
|
const paragraph = Block.create('paragraph')
|
||||||
return change.insertNodeByKey(node.key, node.nodes.size, paragraph)
|
return change.insertNodeByKey(node.key, node.nodes.size, paragraph)
|
||||||
}
|
}
|
||||||
|
@@ -12,7 +12,7 @@ import Node from './models/node'
|
|||||||
import Operation from './models/operation'
|
import Operation from './models/operation'
|
||||||
import Operations from './operations'
|
import Operations from './operations'
|
||||||
import Range from './models/range'
|
import Range from './models/range'
|
||||||
import Schema from './models/schema'
|
import Schema, { SchemaViolations } from './models/schema'
|
||||||
import Stack from './models/stack'
|
import Stack from './models/stack'
|
||||||
import Text from './models/text'
|
import Text from './models/text'
|
||||||
import Value from './models/value'
|
import Value from './models/value'
|
||||||
@@ -39,6 +39,7 @@ export {
|
|||||||
Operations,
|
Operations,
|
||||||
Range,
|
Range,
|
||||||
Schema,
|
Schema,
|
||||||
|
SchemaViolations,
|
||||||
Stack,
|
Stack,
|
||||||
Text,
|
Text,
|
||||||
Value,
|
Value,
|
||||||
@@ -61,6 +62,7 @@ export default {
|
|||||||
Operations,
|
Operations,
|
||||||
Range,
|
Range,
|
||||||
Schema,
|
Schema,
|
||||||
|
SchemaViolations,
|
||||||
Stack,
|
Stack,
|
||||||
Text,
|
Text,
|
||||||
Value,
|
Value,
|
||||||
|
@@ -31,6 +31,23 @@ const NODE_TEXT_INVALID = 'node_text_invalid'
|
|||||||
const PARENT_OBJECT_INVALID = 'parent_object_invalid'
|
const PARENT_OBJECT_INVALID = 'parent_object_invalid'
|
||||||
const PARENT_TYPE_INVALID = 'parent_type_invalid'
|
const PARENT_TYPE_INVALID = 'parent_type_invalid'
|
||||||
|
|
||||||
|
export const SchemaViolations = Object.freeze({
|
||||||
|
ChildObjectInvalid: CHILD_OBJECT_INVALID,
|
||||||
|
ChildRequired: CHILD_REQUIRED,
|
||||||
|
ChildTypeInvalid: CHILD_TYPE_INVALID,
|
||||||
|
ChildUnknown: CHILD_UNKNOWN,
|
||||||
|
FirstChildObjectInvalid: FIRST_CHILD_OBJECT_INVALID,
|
||||||
|
FirstChildTypeInvalid: FIRST_CHILD_TYPE_INVALID,
|
||||||
|
LastChildObjectInvalid: LAST_CHILD_OBJECT_INVALID,
|
||||||
|
LastChildTypeInvalid: LAST_CHILD_TYPE_INVALID,
|
||||||
|
NodeDataInvalid: NODE_DATA_INVALID,
|
||||||
|
NodeIsVoidInvalid: NODE_IS_VOID_INVALID,
|
||||||
|
NodeMarkInvalid: NODE_MARK_INVALID,
|
||||||
|
NodeTextInvalid: NODE_TEXT_INVALID,
|
||||||
|
ParentObjectInvalid: PARENT_OBJECT_INVALID,
|
||||||
|
ParentTypeInvalid: PARENT_TYPE_INVALID,
|
||||||
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Debug.
|
* Debug.
|
||||||
*
|
*
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
/** @jsx h */
|
/** @jsx h */
|
||||||
|
|
||||||
|
import { SchemaViolations } from '../../..'
|
||||||
import h from '../../helpers/h'
|
import h from '../../helpers/h'
|
||||||
|
|
||||||
export const schema = {
|
export const schema = {
|
||||||
@@ -11,7 +12,7 @@ export const schema = {
|
|||||||
{ objects: ['block'], types: ['paragraph'], min: 1 }
|
{ objects: ['block'], types: ['paragraph'], min: 1 }
|
||||||
],
|
],
|
||||||
normalize: (change, reason, { node, child }) => {
|
normalize: (change, reason, { node, child }) => {
|
||||||
if (reason == 'child_object_invalid') {
|
if (reason == SchemaViolations.ChildObjectInvalid) {
|
||||||
change.wrapBlockByKey(child.key, 'paragraph')
|
change.wrapBlockByKey(child.key, 'paragraph')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
/** @jsx h */
|
/** @jsx h */
|
||||||
|
|
||||||
|
import { SchemaViolations } from '../../..'
|
||||||
import h from '../../helpers/h'
|
import h from '../../helpers/h'
|
||||||
|
|
||||||
export const schema = {
|
export const schema = {
|
||||||
@@ -10,7 +11,7 @@ export const schema = {
|
|||||||
{ objects: ['block'] },
|
{ objects: ['block'] },
|
||||||
],
|
],
|
||||||
normalize: (change, reason, { child }) => {
|
normalize: (change, reason, { child }) => {
|
||||||
if (reason == 'child_object_invalid') {
|
if (reason == SchemaViolations.ChildObjectInvalid) {
|
||||||
change.wrapBlockByKey(child.key, 'paragraph')
|
change.wrapBlockByKey(child.key, 'paragraph')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
/** @jsx h */
|
/** @jsx h */
|
||||||
|
|
||||||
|
import { SchemaViolations } from '../../..'
|
||||||
import h from '../../helpers/h'
|
import h from '../../helpers/h'
|
||||||
|
|
||||||
export const schema = {
|
export const schema = {
|
||||||
@@ -10,7 +11,7 @@ export const schema = {
|
|||||||
{ types: ['paragraph'], min: 2 },
|
{ types: ['paragraph'], min: 2 },
|
||||||
],
|
],
|
||||||
normalize: (change, reason, { node, index }) => {
|
normalize: (change, reason, { node, index }) => {
|
||||||
if (reason == 'child_required') {
|
if (reason == SchemaViolations.ChildRequired) {
|
||||||
change.insertNodeByKey(node.key, index, { object: 'block', type: 'paragraph' })
|
change.insertNodeByKey(node.key, index, { object: 'block', type: 'paragraph' })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
/** @jsx h */
|
/** @jsx h */
|
||||||
|
|
||||||
|
import { SchemaViolations } from '../../..'
|
||||||
import h from '../../helpers/h'
|
import h from '../../helpers/h'
|
||||||
|
|
||||||
export const schema = {
|
export const schema = {
|
||||||
@@ -10,7 +11,7 @@ export const schema = {
|
|||||||
{ types: ['paragraph'] },
|
{ types: ['paragraph'] },
|
||||||
],
|
],
|
||||||
normalize: (change, reason, { child }) => {
|
normalize: (change, reason, { child }) => {
|
||||||
if (reason == 'child_type_invalid') {
|
if (reason == SchemaViolations.ChildTypeInvalid) {
|
||||||
change.wrapBlockByKey(child.key, 'paragraph')
|
change.wrapBlockByKey(child.key, 'paragraph')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
/** @jsx h */
|
/** @jsx h */
|
||||||
|
|
||||||
|
import { SchemaViolations } from '../../..'
|
||||||
import h from '../../helpers/h'
|
import h from '../../helpers/h'
|
||||||
|
|
||||||
export const schema = {
|
export const schema = {
|
||||||
@@ -10,7 +11,7 @@ export const schema = {
|
|||||||
{ types: ['paragraph'], max: 1 },
|
{ types: ['paragraph'], max: 1 },
|
||||||
],
|
],
|
||||||
normalize: (change, reason, { node, child, index }) => {
|
normalize: (change, reason, { node, child, index }) => {
|
||||||
if (reason == 'child_unknown') {
|
if (reason == SchemaViolations.ChildUnknown) {
|
||||||
const previous = node.getPreviousSibling(child.key)
|
const previous = node.getPreviousSibling(child.key)
|
||||||
const offset = previous.nodes.size
|
const offset = previous.nodes.size
|
||||||
child.nodes.forEach((n, i) => change.moveNodeByKey(n.key, previous.key, offset + i, { normalize: false }))
|
child.nodes.forEach((n, i) => change.moveNodeByKey(n.key, previous.key, offset + i, { normalize: false }))
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
/** @jsx h */
|
/** @jsx h */
|
||||||
|
|
||||||
|
import { SchemaViolations } from '../../..'
|
||||||
import h from '../../helpers/h'
|
import h from '../../helpers/h'
|
||||||
|
|
||||||
export const schema = {
|
export const schema = {
|
||||||
@@ -8,7 +9,7 @@ export const schema = {
|
|||||||
quote: {
|
quote: {
|
||||||
first: { objects: ['block'] },
|
first: { objects: ['block'] },
|
||||||
normalize: (change, reason, { child }) => {
|
normalize: (change, reason, { child }) => {
|
||||||
if (reason == 'first_child_object_invalid') {
|
if (reason == SchemaViolations.FirstChildObjectInvalid) {
|
||||||
change.wrapBlockByKey(child.key, 'paragraph')
|
change.wrapBlockByKey(child.key, 'paragraph')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
/** @jsx h */
|
/** @jsx h */
|
||||||
|
|
||||||
|
import { SchemaViolations } from '../../..'
|
||||||
import h from '../../helpers/h'
|
import h from '../../helpers/h'
|
||||||
|
|
||||||
export const schema = {
|
export const schema = {
|
||||||
@@ -8,7 +9,7 @@ export const schema = {
|
|||||||
quote: {
|
quote: {
|
||||||
first: { types: ['paragraph'] },
|
first: { types: ['paragraph'] },
|
||||||
normalize: (change, reason, { child }) => {
|
normalize: (change, reason, { child }) => {
|
||||||
if (reason == 'first_child_type_invalid') {
|
if (reason == SchemaViolations.FirstChildTypeInvalid) {
|
||||||
change.wrapBlockByKey(child.key, 'paragraph')
|
change.wrapBlockByKey(child.key, 'paragraph')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
/** @jsx h */
|
/** @jsx h */
|
||||||
|
|
||||||
|
import { SchemaViolations } from '../../..'
|
||||||
import h from '../../helpers/h'
|
import h from '../../helpers/h'
|
||||||
|
|
||||||
export const schema = {
|
export const schema = {
|
||||||
@@ -8,7 +9,7 @@ export const schema = {
|
|||||||
quote: {
|
quote: {
|
||||||
last: { objects: ['block'] },
|
last: { objects: ['block'] },
|
||||||
normalize: (change, reason, { child }) => {
|
normalize: (change, reason, { child }) => {
|
||||||
if (reason == 'last_child_object_invalid') {
|
if (reason == SchemaViolations.LastChildObjectInvalid) {
|
||||||
change.wrapBlockByKey(child.key, 'paragraph')
|
change.wrapBlockByKey(child.key, 'paragraph')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
/** @jsx h */
|
/** @jsx h */
|
||||||
|
|
||||||
|
import { SchemaViolations } from '../../..'
|
||||||
import h from '../../helpers/h'
|
import h from '../../helpers/h'
|
||||||
|
|
||||||
export const schema = {
|
export const schema = {
|
||||||
@@ -8,7 +9,7 @@ export const schema = {
|
|||||||
quote: {
|
quote: {
|
||||||
last: { types: ['paragraph'] },
|
last: { types: ['paragraph'] },
|
||||||
normalize: (change, reason, { child }) => {
|
normalize: (change, reason, { child }) => {
|
||||||
if (reason == 'last_child_type_invalid') {
|
if (reason == SchemaViolations.LastChildTypeInvalid) {
|
||||||
change.wrapBlockByKey(child.key, 'paragraph')
|
change.wrapBlockByKey(child.key, 'paragraph')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
/** @jsx h */
|
/** @jsx h */
|
||||||
|
|
||||||
|
import { SchemaViolations } from '../../..'
|
||||||
import h from '../../helpers/h'
|
import h from '../../helpers/h'
|
||||||
|
|
||||||
export const schema = {
|
export const schema = {
|
||||||
@@ -9,7 +10,7 @@ export const schema = {
|
|||||||
thing: v => v == 'value'
|
thing: v => v == 'value'
|
||||||
},
|
},
|
||||||
normalize: (change, reason, { node, key }) => {
|
normalize: (change, reason, { node, key }) => {
|
||||||
if (reason == 'node_data_invalid') {
|
if (reason == SchemaViolations.NodeDataInvalid) {
|
||||||
change.setNodeByKey(node.key, { data: { thing: 'value' }})
|
change.setNodeByKey(node.key, { data: { thing: 'value' }})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
/** @jsx h */
|
/** @jsx h */
|
||||||
|
|
||||||
|
import { SchemaViolations } from '../../..'
|
||||||
import h from '../../helpers/h'
|
import h from '../../helpers/h'
|
||||||
|
|
||||||
export const schema = {
|
export const schema = {
|
||||||
@@ -7,7 +8,7 @@ export const schema = {
|
|||||||
paragraph: {
|
paragraph: {
|
||||||
isVoid: false,
|
isVoid: false,
|
||||||
normalize: (change, reason, { node }) => {
|
normalize: (change, reason, { node }) => {
|
||||||
if (reason == 'node_is_void_invalid') {
|
if (reason == SchemaViolations.NodeIsVoidInvalid) {
|
||||||
change.removeNodeByKey(node.key, 'paragraph')
|
change.removeNodeByKey(node.key, 'paragraph')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
/** @jsx h */
|
/** @jsx h */
|
||||||
|
|
||||||
|
import { SchemaViolations } from '../../..'
|
||||||
import h from '../../helpers/h'
|
import h from '../../helpers/h'
|
||||||
|
|
||||||
export const schema = {
|
export const schema = {
|
||||||
@@ -7,7 +8,7 @@ export const schema = {
|
|||||||
paragraph: {
|
paragraph: {
|
||||||
marks: [{ type: 'bold' }],
|
marks: [{ type: 'bold' }],
|
||||||
normalize: (change, reason, { node }) => {
|
normalize: (change, reason, { node }) => {
|
||||||
if (reason == 'node_mark_invalid') {
|
if (reason == SchemaViolations.NodeMarkInvalid) {
|
||||||
node.nodes.forEach(n => change.removeNodeByKey(n.key))
|
node.nodes.forEach(n => change.removeNodeByKey(n.key))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
/** @jsx h */
|
/** @jsx h */
|
||||||
|
|
||||||
|
import { SchemaViolations } from '../../..'
|
||||||
import h from '../../helpers/h'
|
import h from '../../helpers/h'
|
||||||
|
|
||||||
export const schema = {
|
export const schema = {
|
||||||
@@ -7,7 +8,7 @@ export const schema = {
|
|||||||
paragraph: {
|
paragraph: {
|
||||||
text: /^\d*$/,
|
text: /^\d*$/,
|
||||||
normalize: (change, reason, { node }) => {
|
normalize: (change, reason, { node }) => {
|
||||||
if (reason == 'node_text_invalid') {
|
if (reason == SchemaViolations.NodeTextInvalid) {
|
||||||
node.nodes.forEach(n => change.removeNodeByKey(n.key))
|
node.nodes.forEach(n => change.removeNodeByKey(n.key))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
/** @jsx h */
|
/** @jsx h */
|
||||||
|
|
||||||
|
import { SchemaViolations } from '../../..'
|
||||||
import h from '../../helpers/h'
|
import h from '../../helpers/h'
|
||||||
|
|
||||||
export const schema = {
|
export const schema = {
|
||||||
@@ -7,7 +8,7 @@ export const schema = {
|
|||||||
link: {
|
link: {
|
||||||
parent: { objects: ['block'] },
|
parent: { objects: ['block'] },
|
||||||
normalize: (change, reason, { node }) => {
|
normalize: (change, reason, { node }) => {
|
||||||
if (reason == 'parent_object_invalid') {
|
if (reason == SchemaViolations.ParentObjectInvalid) {
|
||||||
change.unwrapNodeByKey(node.key)
|
change.unwrapNodeByKey(node.key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
/** @jsx h */
|
/** @jsx h */
|
||||||
|
|
||||||
|
import { SchemaViolations } from '../../..'
|
||||||
import h from '../../helpers/h'
|
import h from '../../helpers/h'
|
||||||
|
|
||||||
export const schema = {
|
export const schema = {
|
||||||
@@ -8,7 +9,7 @@ export const schema = {
|
|||||||
item: {
|
item: {
|
||||||
parent: { types: ['list'] },
|
parent: { types: ['list'] },
|
||||||
normalize: (change, reason, { node }) => {
|
normalize: (change, reason, { node }) => {
|
||||||
if (reason == 'parent_type_invalid') {
|
if (reason == SchemaViolations.ParentTypeInvalid) {
|
||||||
change.wrapBlockByKey(node.key, 'list')
|
change.wrapBlockByKey(node.key, 'list')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user