diff --git a/docs/Readme.md b/docs/Readme.md index e27bbf205..9b08aa54f 100644 --- a/docs/Readme.md +++ b/docs/Readme.md @@ -73,4 +73,5 @@ - [`slate-plain-serializer`](./reference/slate-plain-serializer/index.md) - [`slate-prop-types`](./reference/slate-prop-types/index.md) - [`slate-simulator`](./reference/slate-simulator/index.md) +- [`slate-schema-violations`](./reference/slate-schema-violations/index.md) diff --git a/docs/reference/slate-schema-violations/index.md b/docs/reference/slate-schema-violations/index.md new file mode 100644 index 000000000..a2279b34c --- /dev/null +++ b/docs/reference/slate-schema-violations/index.md @@ -0,0 +1,217 @@ + +# `slate-schema-violations` + +```js +import { + CHILD_OBJECT_INVALID, + CHILD_REQUIRED, + CHILD_TYPE_INVALID, + CHILD_UNKNOWN, + FIRST_CHILD_OBJECT_INVALID, + FIRST_CHILD_TYPE_INVALID, + LAST_CHILD_OBJECT_INVALID, + LAST_CHILD_TYPE_INVALID, + NODE_DATA_INVALID, + NODE_IS_VOID_INVALID, + NODE_MARK_INVALID, + NODE_TEXT_INVALID, + PARENT_OBJECT_INVALID, + PARENT_TYPE_INVALID, +} from 'slate-schema-violations' +``` + +A set of constants for the built-in violations in a Slate schema. + + +## Example + +```js +import React from 'react' +import Types from 'slate-prop-types' + +class Toolbar extends React.Component { + + propTypes = { + block: Types.block, + schema: Types.schema.isRequired, + value: Types.value.isRequired, + } + + ... + +} +``` + + +## Exports + +### `CHILD_OBJECT_INVALID` + +```js +{ + child: Node, + index: Number, + node: Node, + rule: Object, +} +``` + +Raised when the `object` property of a child node is invalid. + +### `CHILD_REQUIRED` + +```js +{ + index: Number, + node: Node, + rule: Object, +} +``` + +Raised when a child node was required but none was found. + +### `CHILD_TYPE_INVALID` + +```js +{ + child: Node, + index: Number, + node: Node, + rule: Object, +} +``` + +Raised when the `type` property of a child node is invalid. + +### `CHILD_UNKNOWN` + +```js +{ + child: Node, + index: Number, + node: Node, + rule: Object, +} +``` + +Raised when a child was not expected but one was found. + +### `FIRST_CHILD_OBJECT_INVALID` + +```js +{ + child: Node, + node: Node, + rule: Object, +} +``` + +Raised when the `object` property of the first child node is invalid, when a specific `first` rule was defined in a schema. + +### `FIRST_CHILD_TYPE_INVALID` + +```js +{ + child: Node, + node: Node, + rule: Object, +} +``` + +Raised when the `type` property of the first child node is invalid, when a specific `first` rule was defined in a schema. + +### `LAST_CHILD_OBJECT_INVALID` + +```js +{ + child: Node, + node: Node, + rule: Object, +} +``` + +Raised when the `object` property of the last child node is invalid, when a specific `last` rule was defined in a schema. + +### `LAST_CHILD_TYPE_INVALID` + +```js +{ + child: Node, + node: Node, + rule: Object, +} +``` + +Raised when the `type` property of the last child node is invalid, when a specific `last` rule was defined in a schema. + +### `NODE_DATA_INVALID` + +```js +{ + key: String, + node: Node, + rule: Object, + value: Mixed, +} +``` + +Raised when the `data` property of a node contains an invalid entry. + +### `NODE_IS_VOID_INVALID` + +```js +{ + node: Node, + rule: Object, +} +``` + +Raised when the `isVoid` property of a node is invalid. + +### `NODE_MARK_INVALID` + +```js +{ + mark: Mark, + node: Node, + rule: Object, +} +``` + +Raised when one of the marks in a node is invalid. + +### `NODE_TEXT_INVALID` + +```js +{ + text: String, + node: Node, + rule: Object, +} +``` + +Raised when the text content of a node is invalid. + +### `PARENT_OBJECT_INVALID` + +```js +{ + node: Node, + parent: Node, + rule: Object, +} +``` + +Raised when the `object` property of the parent of a node is invalid, when a specific `parent` rule was defined in a schema. + +### `PARENT_TYPE_INVALID` + +```js +{ + node: Node, + parent: Node, + rule: Object, +} +``` + +Raised when the `type` property of the parent of a node is invalid, when a specific `parent` rule was defined in a schema. diff --git a/docs/reference/slate/schema.md b/docs/reference/slate/schema.md index 7337cefd5..56488f039 100644 --- a/docs/reference/slate/schema.md +++ b/docs/reference/slate/schema.md @@ -144,11 +144,11 @@ Will validate a node's children. The `nodes` definitions can declare the `object > 🤖 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. ### `normalize` -`normalize(change: Change, reason: String, context: Object) => Void` +`normalize(change: Change, violation: String, context: Object) => Void` ```js { - normalize: (change, reason, context) => { + normalize: (change, violation, context) => { case 'child_object_invalid': change.wrapBlockByKey(context.child.key, 'paragraph') return @@ -161,7 +161,7 @@ Will validate a node's children. The `nodes` definitions can declare the `object A function that can be provided to override the default behavior in the case of a rule being invalid. By default Slate will do what it can, but since it doesn't know much about your schema, it will often remove invalid nodes. If you want to override this behavior, and "fix" the node instead of removing it, pass a custom `normalize` function. -For more information on the arguments passed to `normalize`, see the [Invalid Reasons](#invalid-reasons) reference. +For more information on the arguments passed to `normalize`, see the [Violations](#violations) reference. ### `parent` `Array` @@ -212,162 +212,9 @@ Returns a boolean if the passed in argument is a `Schema`. Returns a JSON representation of the schema. -## Invalid Reasons +## Violations -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. +When supplying your own `normalize` property for a schema rule, it will be called with `(change, violation, context)`. The `violation` will be one of a set of potential violation strings, and `context` will vary depending on the violation. -`import { SchemaViolations } from 'slate'` +A set of the invalid violation strings are available as constants via the [`slate-schema-violations`](../slate-schema-violations) package. -Here's the full set: - -### `SchemaViolations.ChildObjectInvalid` - -```js -{ - child: Node, - index: Number, - node: Node, - rule: Object, -} -``` - -### `SchemaViolations.ChildRequired` - -```js -{ - index: Number, - node: Node, - rule: Object, -} -``` - -### `SchemaViolations.ChildTypeInvalid` - -```js -{ - child: Node, - index: Number, - node: Node, - rule: Object, -} -``` - -### `SchemaViolations.ChildUnknown` - -```js -{ - child: Node, - index: Number, - node: Node, - rule: Object, -} -``` - -### `SchemaViolations.FirstChildObjectInvalid` - -```js -{ - child: Node, - node: Node, - rule: Object, -} -``` - -### `SchemaViolations.FirstChildTypeInvalid` - -```js -{ - child: Node, - node: Node, - rule: Object, -} -``` - -### `SchemaViolations.LastChildObjectInvalid` - -```js -{ - child: Node, - node: Node, - rule: Object, -} -``` - -### `SchemaViolations.LastChildTypeInvalid` - -```js -{ - child: Node, - node: Node, - rule: Object, -} -``` - -### `SchemaViolations.NodeDataInvalid` - -```js -{ - key: String, - node: Node, - rule: Object, - value: Mixed, -} -``` - -### `SchemaViolations.NodeIsVoidInvalid` - -```js -{ - node: Node, - rule: Object, -} -``` - -### `SchemaViolations.NodeObjectInvalid` - -```js -{ - node: Node, - rule: Object, -} -``` - -### `SchemaViolations.NodeMarkInvalid` - -```js -{ - mark: Mark, - node: Node, - rule: Object, -} -``` - -### `SchemaViolations.NodeTextInvalid` - -```js -{ - text: String, - node: Node, - rule: Object, -} -``` - -### `SchemaViolations.ParentObjectInvalid` - -```js -{ - node: Node, - parent: Node, - rule: Object, -} -``` - -### `SchemaViolations.ParentTypeInvalid` - -```js -{ - node: Node, - parent: Node, - rule: Object, -} -``` diff --git a/examples/forced-layout/index.js b/examples/forced-layout/index.js index 308937bc1..65c1929d8 100644 --- a/examples/forced-layout/index.js +++ b/examples/forced-layout/index.js @@ -1,6 +1,7 @@ import { Editor } from 'slate-react' -import { Block, Value, SchemaViolations } from 'slate' +import { Block, Value } from 'slate' +import { CHILD_REQUIRED, CHILD_TYPE_INVALID } from 'slate-schema-violations' import React from 'react' import initialValue from './value.json' @@ -17,12 +18,12 @@ const schema = { { types: ['title'], min: 1, max: 1 }, { types: ['paragraph'], min: 1 }, ], - normalize: (change, reason, { node, child, index }) => { - switch (reason) { - case SchemaViolations.ChildTypeInvalid: { + normalize: (change, violation, { node, child, index }) => { + switch (violation) { + case CHILD_TYPE_INVALID: { return change.setNodeByKey(child.key, index == 0 ? 'title' : 'paragraph') } - case SchemaViolations.ChildRequired: { + case CHILD_REQUIRED: { const block = Block.create(index == 0 ? 'title' : 'paragraph') return change.insertNodeByKey(node.key, index, block) } diff --git a/package.json b/package.json index 2495539c4..088fb4aec 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,8 @@ "slate": "*", "slate-html-serializer": "*", "slate-plain-serializer": "*", - "slate-react": "*" + "slate-react": "*", + "slate-schema-violations": "*" }, "scripts": { "benchmark": "mkdir -p ./tmp && babel-node ./node_modules/.bin/_matcha --reporter ./support/benchmark-reporter ./packages/*/benchmark/index.js > ./tmp/benchmark-comparison.json && babel-node ./support/benchmark-compare", diff --git a/packages/slate-schema-violations/Changelog.md b/packages/slate-schema-violations/Changelog.md new file mode 100644 index 000000000..079668991 --- /dev/null +++ b/packages/slate-schema-violations/Changelog.md @@ -0,0 +1,13 @@ + +# Changelog + +This document maintains a list of changes to the `slate-schema-violations` package with each new version. Until `1.0.0` is released, breaking changes will be added as minor version bumps, and smaller changes won't be accounted for since the library is moving quickly. + + +--- + + +### `0.1.0` — January 26, 2018 + +:tada: + diff --git a/packages/slate-schema-violations/Readme.md b/packages/slate-schema-violations/Readme.md new file mode 100644 index 000000000..ece9f2f58 --- /dev/null +++ b/packages/slate-schema-violations/Readme.md @@ -0,0 +1,2 @@ + +This package contains a set of constants for the built-in violations in a Slate schema. diff --git a/packages/slate-schema-violations/package.json b/packages/slate-schema-violations/package.json new file mode 100644 index 000000000..07eeb7162 --- /dev/null +++ b/packages/slate-schema-violations/package.json @@ -0,0 +1,35 @@ +{ + "name": "slate-schema-violations", + "description": "A set of constants for the built-in violations in a Slate schema.", + "version": "0.0.0", + "license": "MIT", + "repository": "git://github.com/ianstormtaylor/slate.git", + "main": "./lib/index.js", + "files": [ + "dist/", + "lib/" + ], + "dependencies": {}, + "peerDependencies": {}, + "devDependencies": { + "babel-cli": "^6.10.1", + "browserify": "^13.0.1", + "mocha": "^2.5.3", + "slate": "^0.32.1", + "uglify-js": "^2.7.0" + }, + "scripts": { + "build": "babel --out-dir ./lib ./src", + "build:max": "mkdir -p ./dist && NODE_ENV=production browserify ./src/index.js --transform babelify --transform envify --transform [ browserify-global-shim --global ] --standalone SlateSchemaViolations > ./dist/slate-schema-violations.js", + "build:min": "mkdir -p ./dist && NODE_ENV=production browserify ./src/index.js --transform babelify --transform envify --transform [ browserify-global-shim --global ] --transform uglifyify --standalone SlateSchemaViolations | uglifyjs > ./dist/slate-schema-violations.min.js", + "clean": "rm -rf ./dist ./lib ./node_modules", + "prepublish": "yarn run build && yarn run build:max && yarn run build:min", + "watch": "babel --watch --out-dir ./lib ./src --source-maps inline" + }, + "keywords": [ + "constants", + "schema", + "slate", + "violation" + ] +} diff --git a/packages/slate-schema-violations/src/index.js b/packages/slate-schema-violations/src/index.js new file mode 100644 index 000000000..ba2350deb --- /dev/null +++ b/packages/slate-schema-violations/src/index.js @@ -0,0 +1,21 @@ + +/** + * Schema violations. + * + * @type {String} + */ + +export const CHILD_OBJECT_INVALID = 'child_object_invalid' +export const CHILD_REQUIRED = 'child_required' +export const CHILD_TYPE_INVALID = 'child_type_invalid' +export const CHILD_UNKNOWN = 'child_unknown' +export const FIRST_CHILD_OBJECT_INVALID = 'first_child_object_invalid' +export const FIRST_CHILD_TYPE_INVALID = 'first_child_type_invalid' +export const LAST_CHILD_OBJECT_INVALID = 'last_child_object_invalid' +export const LAST_CHILD_TYPE_INVALID = 'last_child_type_invalid' +export const NODE_DATA_INVALID = 'node_data_invalid' +export const NODE_IS_VOID_INVALID = 'node_is_void_invalid' +export const NODE_MARK_INVALID = 'node_mark_invalid' +export const NODE_TEXT_INVALID = 'node_text_invalid' +export const PARENT_OBJECT_INVALID = 'parent_object_invalid' +export const PARENT_TYPE_INVALID = 'parent_type_invalid' diff --git a/packages/slate-schema-violations/test/index.js b/packages/slate-schema-violations/test/index.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/slate/package.json b/packages/slate/package.json index d8e184598..663189b79 100644 --- a/packages/slate/package.json +++ b/packages/slate/package.json @@ -17,6 +17,7 @@ "is-plain-object": "^2.0.4", "lodash": "^4.17.4", "slate-dev-logger": "^0.1.36", + "slate-schema-violations": "^0.0.0", "type-of": "^2.0.1" }, "peerDependencies": { diff --git a/packages/slate/src/models/schema.js b/packages/slate/src/models/schema.js index c3507884d..9085f9902 100644 --- a/packages/slate/src/models/schema.js +++ b/packages/slate/src/models/schema.js @@ -5,49 +5,28 @@ import logger from 'slate-dev-logger' import mergeWith from 'lodash/mergeWith' import { Record } from 'immutable' +import { + CHILD_OBJECT_INVALID, + CHILD_REQUIRED, + CHILD_TYPE_INVALID, + CHILD_UNKNOWN, + FIRST_CHILD_OBJECT_INVALID, + FIRST_CHILD_TYPE_INVALID, + LAST_CHILD_OBJECT_INVALID, + LAST_CHILD_TYPE_INVALID, + NODE_DATA_INVALID, + NODE_IS_VOID_INVALID, + NODE_MARK_INVALID, + NODE_TEXT_INVALID, + PARENT_OBJECT_INVALID, + PARENT_TYPE_INVALID, +} from 'slate-schema-violations' + import CORE_SCHEMA_RULES from '../constants/core-schema-rules' import MODEL_TYPES from '../constants/model-types' import Stack from './stack' import memoize from '../utils/memoize' -/** - * Validation failure reasons. - * - * @type {Object} - */ - -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_OBJECT_INVALID = 'first_child_object_invalid' -const FIRST_CHILD_TYPE_INVALID = 'first_child_type_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_OBJECT_INVALID = 'parent_object_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. * @@ -203,32 +182,32 @@ class Schema extends Record(DEFAULTS) { /** * Fail validation by returning a normalizing change function. * - * @param {String} reason + * @param {String} violation * @param {Object} context * @return {Function} */ - fail(reason, context) { + fail(violation, context) { return (change) => { - debug(`normalizing`, { reason, context }) + debug(`normalizing`, { violation, context }) const { rule } = context const { size } = change.operations - if (rule.normalize) rule.normalize(change, reason, context) + if (rule.normalize) rule.normalize(change, violation, context) if (change.operations.size > size) return - this.normalize(change, reason, context) + this.normalize(change, violation, context) } } /** - * Normalize an invalid value with `reason` and `context`. + * Normalize an invalid value with `violation` and `context`. * * @param {Change} change - * @param {String} reason + * @param {String} violation * @param {Mixed} context */ - normalize(change, reason, context) { - switch (reason) { + normalize(change, violation, context) { + switch (violation) { case CHILD_OBJECT_INVALID: case CHILD_TYPE_INVALID: case CHILD_UNKNOWN: diff --git a/packages/slate/test/schema/custom/child-kind-invalid-custom-optional-first.js b/packages/slate/test/schema/custom/child-kind-invalid-custom-optional-first.js index 197615f05..3ae2d7766 100644 --- a/packages/slate/test/schema/custom/child-kind-invalid-custom-optional-first.js +++ b/packages/slate/test/schema/custom/child-kind-invalid-custom-optional-first.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { SchemaViolations } from '../../..' +import { CHILD_OBJECT_INVALID } from 'slate-schema-violations' import h from '../../helpers/h' export const schema = { @@ -12,7 +12,7 @@ export const schema = { { objects: ['block'], types: ['paragraph'], min: 1 } ], normalize: (change, reason, { node, child }) => { - if (reason == SchemaViolations.ChildObjectInvalid) { + if (reason == CHILD_OBJECT_INVALID) { change.wrapBlockByKey(child.key, 'paragraph') } } diff --git a/packages/slate/test/schema/custom/child-kind-invalid-custom.js b/packages/slate/test/schema/custom/child-kind-invalid-custom.js index 5493158d8..38e9d4c40 100644 --- a/packages/slate/test/schema/custom/child-kind-invalid-custom.js +++ b/packages/slate/test/schema/custom/child-kind-invalid-custom.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { SchemaViolations } from '../../..' +import { CHILD_OBJECT_INVALID } from 'slate-schema-violations' import h from '../../helpers/h' export const schema = { @@ -11,7 +11,7 @@ export const schema = { { objects: ['block'] }, ], normalize: (change, reason, { child }) => { - if (reason == SchemaViolations.ChildObjectInvalid) { + if (reason == CHILD_OBJECT_INVALID) { change.wrapBlockByKey(child.key, 'paragraph') } } diff --git a/packages/slate/test/schema/custom/child-required-custom.js b/packages/slate/test/schema/custom/child-required-custom.js index 5094e3d11..c7cf1daeb 100644 --- a/packages/slate/test/schema/custom/child-required-custom.js +++ b/packages/slate/test/schema/custom/child-required-custom.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { SchemaViolations } from '../../..' +import { CHILD_REQUIRED } from 'slate-schema-violations' import h from '../../helpers/h' export const schema = { @@ -11,7 +11,7 @@ export const schema = { { types: ['paragraph'], min: 2 }, ], normalize: (change, reason, { node, index }) => { - if (reason == SchemaViolations.ChildRequired) { + if (reason == CHILD_REQUIRED) { change.insertNodeByKey(node.key, index, { object: 'block', type: 'paragraph' }) } } diff --git a/packages/slate/test/schema/custom/child-type-invalid-custom.js b/packages/slate/test/schema/custom/child-type-invalid-custom.js index a40aafa97..9ae2ddaf1 100644 --- a/packages/slate/test/schema/custom/child-type-invalid-custom.js +++ b/packages/slate/test/schema/custom/child-type-invalid-custom.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { SchemaViolations } from '../../..' +import { CHILD_TYPE_INVALID } from 'slate-schema-violations' import h from '../../helpers/h' export const schema = { @@ -11,7 +11,7 @@ export const schema = { { types: ['paragraph'] }, ], normalize: (change, reason, { child }) => { - if (reason == SchemaViolations.ChildTypeInvalid) { + if (reason == CHILD_TYPE_INVALID) { change.wrapBlockByKey(child.key, 'paragraph') } } diff --git a/packages/slate/test/schema/custom/child-unknown-custom.js b/packages/slate/test/schema/custom/child-unknown-custom.js index eb6d1a7b2..878845259 100644 --- a/packages/slate/test/schema/custom/child-unknown-custom.js +++ b/packages/slate/test/schema/custom/child-unknown-custom.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { SchemaViolations } from '../../..' +import { CHILD_UNKNOWN } from 'slate-schema-violations' import h from '../../helpers/h' export const schema = { @@ -11,7 +11,7 @@ export const schema = { { types: ['paragraph'], max: 1 }, ], normalize: (change, reason, { node, child, index }) => { - if (reason == SchemaViolations.ChildUnknown) { + if (reason == CHILD_UNKNOWN) { const previous = node.getPreviousSibling(child.key) const offset = previous.nodes.size child.nodes.forEach((n, i) => change.moveNodeByKey(n.key, previous.key, offset + i, { normalize: false })) diff --git a/packages/slate/test/schema/custom/first-child-kind-invalid-custom.js b/packages/slate/test/schema/custom/first-child-kind-invalid-custom.js index 07d2303fb..56a938a18 100644 --- a/packages/slate/test/schema/custom/first-child-kind-invalid-custom.js +++ b/packages/slate/test/schema/custom/first-child-kind-invalid-custom.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { SchemaViolations } from '../../..' +import { FIRST_CHILD_OBJECT_INVALID } from 'slate-schema-violations' import h from '../../helpers/h' export const schema = { @@ -9,7 +9,7 @@ export const schema = { quote: { first: { objects: ['block'] }, normalize: (change, reason, { child }) => { - if (reason == SchemaViolations.FirstChildObjectInvalid) { + if (reason == FIRST_CHILD_OBJECT_INVALID) { change.wrapBlockByKey(child.key, 'paragraph') } } diff --git a/packages/slate/test/schema/custom/first-child-type-invalid-custom.js b/packages/slate/test/schema/custom/first-child-type-invalid-custom.js index a6e1ed582..7332d07ba 100644 --- a/packages/slate/test/schema/custom/first-child-type-invalid-custom.js +++ b/packages/slate/test/schema/custom/first-child-type-invalid-custom.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { SchemaViolations } from '../../..' +import { FIRST_CHILD_TYPE_INVALID } from 'slate-schema-violations' import h from '../../helpers/h' export const schema = { @@ -9,7 +9,7 @@ export const schema = { quote: { first: { types: ['paragraph'] }, normalize: (change, reason, { child }) => { - if (reason == SchemaViolations.FirstChildTypeInvalid) { + if (reason == FIRST_CHILD_TYPE_INVALID) { change.wrapBlockByKey(child.key, 'paragraph') } } diff --git a/packages/slate/test/schema/custom/last-child-kind-invalid-custom.js b/packages/slate/test/schema/custom/last-child-kind-invalid-custom.js index 61ade734b..ec0041a80 100644 --- a/packages/slate/test/schema/custom/last-child-kind-invalid-custom.js +++ b/packages/slate/test/schema/custom/last-child-kind-invalid-custom.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { SchemaViolations } from '../../..' +import { LAST_CHILD_OBJECT_INVALID } from 'slate-schema-violations' import h from '../../helpers/h' export const schema = { @@ -9,7 +9,7 @@ export const schema = { quote: { last: { objects: ['block'] }, normalize: (change, reason, { child }) => { - if (reason == SchemaViolations.LastChildObjectInvalid) { + if (reason == LAST_CHILD_OBJECT_INVALID) { change.wrapBlockByKey(child.key, 'paragraph') } } diff --git a/packages/slate/test/schema/custom/last-child-type-invalid-custom.js b/packages/slate/test/schema/custom/last-child-type-invalid-custom.js index c2f9cd6ab..74f73bf4c 100644 --- a/packages/slate/test/schema/custom/last-child-type-invalid-custom.js +++ b/packages/slate/test/schema/custom/last-child-type-invalid-custom.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { SchemaViolations } from '../../..' +import { LAST_CHILD_TYPE_INVALID } from 'slate-schema-violations' import h from '../../helpers/h' export const schema = { @@ -9,7 +9,7 @@ export const schema = { quote: { last: { types: ['paragraph'] }, normalize: (change, reason, { child }) => { - if (reason == SchemaViolations.LastChildTypeInvalid) { + if (reason == LAST_CHILD_TYPE_INVALID) { change.wrapBlockByKey(child.key, 'paragraph') } } diff --git a/packages/slate/test/schema/custom/node-data-invalid-custom.js b/packages/slate/test/schema/custom/node-data-invalid-custom.js index f006af801..2375b4820 100644 --- a/packages/slate/test/schema/custom/node-data-invalid-custom.js +++ b/packages/slate/test/schema/custom/node-data-invalid-custom.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { SchemaViolations } from '../../..' +import { NODE_DATA_INVALID } from 'slate-schema-violations' import h from '../../helpers/h' export const schema = { @@ -10,7 +10,7 @@ export const schema = { thing: v => v == 'value' }, normalize: (change, reason, { node, key }) => { - if (reason == SchemaViolations.NodeDataInvalid) { + if (reason == NODE_DATA_INVALID) { change.setNodeByKey(node.key, { data: { thing: 'value' }}) } } diff --git a/packages/slate/test/schema/custom/node-is-void-invalid-custom.js b/packages/slate/test/schema/custom/node-is-void-invalid-custom.js index fb945cef4..6e4e9abd7 100644 --- a/packages/slate/test/schema/custom/node-is-void-invalid-custom.js +++ b/packages/slate/test/schema/custom/node-is-void-invalid-custom.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { SchemaViolations } from '../../..' +import { NODE_IS_VOID_INVALID } from 'slate-schema-violations' import h from '../../helpers/h' export const schema = { @@ -8,7 +8,7 @@ export const schema = { paragraph: { isVoid: false, normalize: (change, reason, { node }) => { - if (reason == SchemaViolations.NodeIsVoidInvalid) { + if (reason == NODE_IS_VOID_INVALID) { change.removeNodeByKey(node.key, 'paragraph') } } diff --git a/packages/slate/test/schema/custom/node-mark-invalid-custom.js b/packages/slate/test/schema/custom/node-mark-invalid-custom.js index bd8e4429c..b4a115a49 100644 --- a/packages/slate/test/schema/custom/node-mark-invalid-custom.js +++ b/packages/slate/test/schema/custom/node-mark-invalid-custom.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { SchemaViolations } from '../../..' +import { NODE_MARK_INVALID } from 'slate-schema-violations' import h from '../../helpers/h' export const schema = { @@ -8,7 +8,7 @@ export const schema = { paragraph: { marks: [{ type: 'bold' }], normalize: (change, reason, { node }) => { - if (reason == SchemaViolations.NodeMarkInvalid) { + if (reason == NODE_MARK_INVALID) { node.nodes.forEach(n => change.removeNodeByKey(n.key)) } } diff --git a/packages/slate/test/schema/custom/node-text-invalid-custom.js b/packages/slate/test/schema/custom/node-text-invalid-custom.js index f40c932c9..6b37e4636 100644 --- a/packages/slate/test/schema/custom/node-text-invalid-custom.js +++ b/packages/slate/test/schema/custom/node-text-invalid-custom.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { SchemaViolations } from '../../..' +import { NODE_TEXT_INVALID } from 'slate-schema-violations' import h from '../../helpers/h' export const schema = { @@ -8,7 +8,7 @@ export const schema = { paragraph: { text: /^\d*$/, normalize: (change, reason, { node }) => { - if (reason == SchemaViolations.NodeTextInvalid) { + if (reason == NODE_TEXT_INVALID) { node.nodes.forEach(n => change.removeNodeByKey(n.key)) } } diff --git a/packages/slate/test/schema/custom/parent-kind-invalid-custom.js b/packages/slate/test/schema/custom/parent-kind-invalid-custom.js index a0ed5ccca..50c96d0ab 100644 --- a/packages/slate/test/schema/custom/parent-kind-invalid-custom.js +++ b/packages/slate/test/schema/custom/parent-kind-invalid-custom.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { SchemaViolations } from '../../..' +import { PARENT_OBJECT_INVALID } from 'slate-schema-violations' import h from '../../helpers/h' export const schema = { @@ -8,7 +8,7 @@ export const schema = { link: { parent: { objects: ['block'] }, normalize: (change, reason, { node }) => { - if (reason == SchemaViolations.ParentObjectInvalid) { + if (reason == PARENT_OBJECT_INVALID) { change.unwrapNodeByKey(node.key) } } diff --git a/packages/slate/test/schema/custom/parent-type-invalid-custom.js b/packages/slate/test/schema/custom/parent-type-invalid-custom.js index cd25fa81f..4ff6f7737 100644 --- a/packages/slate/test/schema/custom/parent-type-invalid-custom.js +++ b/packages/slate/test/schema/custom/parent-type-invalid-custom.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { SchemaViolations } from '../../..' +import { PARENT_TYPE_INVALID } from 'slate-schema-violations' import h from '../../helpers/h' export const schema = { @@ -9,7 +9,7 @@ export const schema = { item: { parent: { types: ['list'] }, normalize: (change, reason, { node }) => { - if (reason == SchemaViolations.ParentTypeInvalid) { + if (reason == PARENT_TYPE_INVALID) { change.wrapBlockByKey(node.key, 'list') } }