From e68a5cd3059200fba553fe401236b31f2f8a51ac Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Tue, 10 Dec 2019 17:53:27 -0500 Subject: [PATCH] remove the slate-schema package (#3291) --- Readme.md | 13 +- config/rollup/rollup.config.js | 2 - docs/concepts/XX-migrating.md | 3 +- docs/general/faq.md | 2 +- .../04-applying-custom-formatting.md | 2 +- package.json | 1 - packages/slate-hyperscript/src/hyperscript.ts | 2 +- packages/slate-schema/Readme.md | 1 - packages/slate-schema/package.json | 38 --- packages/slate-schema/src/checkers.ts | 319 ------------------ packages/slate-schema/src/define-schema.ts | 150 -------- packages/slate-schema/src/errors.ts | 92 ----- packages/slate-schema/src/index.ts | 3 - packages/slate-schema/src/rules.ts | 29 -- packages/slate-schema/test/index.js | 14 - .../children/match/invalid-array.js | 30 -- .../children/match/invalid-many.js | 32 -- .../children/match/invalid-second.js | 30 -- .../validations/children/match/invalid.js | 30 -- .../validations/children/match/valid-array.js | 24 -- .../children/match/valid-second.js | 27 -- .../test/validations/children/match/valid.js | 23 -- .../validations/children/max/invalid-many.js | 30 -- .../validations/children/max/invalid-match.js | 29 -- .../children/max/invalid-second.js | 32 -- .../test/validations/children/max/invalid.js | 30 -- .../validations/children/max/valid-second.js | 24 -- .../test/validations/children/max/valid.js | 23 -- .../children/min/invalid-second-with-match.js | 26 -- .../children/min/invalid-second.js | 23 -- .../test/validations/children/min/invalid.js | 23 -- .../min/valid-second-optional-exists.js | 27 -- .../min/valid-second-optional-missing.js | 26 -- .../validations/children/min/valid-second.js | 24 -- .../test/validations/children/min/valid.js | 23 -- .../test/validations/first/invalid-many.js | 32 -- .../test/validations/first/invalid-one.js | 23 -- .../test/validations/first/valid.js | 25 -- .../test/validations/last/invalid-many.js | 32 -- .../test/validations/last/invalid-one.js | 23 -- .../test/validations/last/valid.js | 25 -- .../validations/leaves/invalid-unknown.js | 31 -- .../test/validations/leaves/invalid-value.js | 31 -- .../test/validations/leaves/valid.js | 31 -- .../test/validations/next/invalid-extra.js | 33 -- .../test/validations/next/invalid.js | 28 -- .../test/validations/next/valid.js | 23 -- .../test/validations/parent/invalid-extra.js | 37 -- .../test/validations/parent/invalid.js | 32 -- .../test/validations/parent/valid.js | 33 -- .../validations/previous/invalid-extra.js | 33 -- .../test/validations/previous/invalid.js | 28 -- .../test/validations/previous/valid.js | 23 -- .../validations/properties/invalid-unknown.js | 25 -- .../validations/properties/invalid-value.js | 26 -- .../test/validations/properties/valid.js | 26 -- .../test/validations/text/invalid.js | 21 -- .../test/validations/text/valid.js | 21 -- packages/slate-schema/tsconfig.json | 9 - packages/slate/src/interfaces/element.ts | 2 +- .../test/normalization/block/remove-block.js | 2 - .../test/normalization/inline/remove-block.js | 2 - .../text/merge-adjacent-empty.js | 2 - .../text/merge-adjacent-match-empty.js | 2 - .../text/merge-adjacent-match.js | 2 - site/examples/Readme.md | 2 +- site/examples/forced-layout.js | 57 ++-- tsconfig.json | 3 +- 68 files changed, 40 insertions(+), 1892 deletions(-) delete mode 100644 packages/slate-schema/Readme.md delete mode 100644 packages/slate-schema/package.json delete mode 100644 packages/slate-schema/src/checkers.ts delete mode 100644 packages/slate-schema/src/define-schema.ts delete mode 100644 packages/slate-schema/src/errors.ts delete mode 100644 packages/slate-schema/src/index.ts delete mode 100644 packages/slate-schema/src/rules.ts delete mode 100644 packages/slate-schema/test/index.js delete mode 100644 packages/slate-schema/test/validations/children/match/invalid-array.js delete mode 100644 packages/slate-schema/test/validations/children/match/invalid-many.js delete mode 100644 packages/slate-schema/test/validations/children/match/invalid-second.js delete mode 100644 packages/slate-schema/test/validations/children/match/invalid.js delete mode 100644 packages/slate-schema/test/validations/children/match/valid-array.js delete mode 100644 packages/slate-schema/test/validations/children/match/valid-second.js delete mode 100644 packages/slate-schema/test/validations/children/match/valid.js delete mode 100644 packages/slate-schema/test/validations/children/max/invalid-many.js delete mode 100644 packages/slate-schema/test/validations/children/max/invalid-match.js delete mode 100644 packages/slate-schema/test/validations/children/max/invalid-second.js delete mode 100644 packages/slate-schema/test/validations/children/max/invalid.js delete mode 100644 packages/slate-schema/test/validations/children/max/valid-second.js delete mode 100644 packages/slate-schema/test/validations/children/max/valid.js delete mode 100644 packages/slate-schema/test/validations/children/min/invalid-second-with-match.js delete mode 100644 packages/slate-schema/test/validations/children/min/invalid-second.js delete mode 100644 packages/slate-schema/test/validations/children/min/invalid.js delete mode 100644 packages/slate-schema/test/validations/children/min/valid-second-optional-exists.js delete mode 100644 packages/slate-schema/test/validations/children/min/valid-second-optional-missing.js delete mode 100644 packages/slate-schema/test/validations/children/min/valid-second.js delete mode 100644 packages/slate-schema/test/validations/children/min/valid.js delete mode 100644 packages/slate-schema/test/validations/first/invalid-many.js delete mode 100644 packages/slate-schema/test/validations/first/invalid-one.js delete mode 100644 packages/slate-schema/test/validations/first/valid.js delete mode 100644 packages/slate-schema/test/validations/last/invalid-many.js delete mode 100644 packages/slate-schema/test/validations/last/invalid-one.js delete mode 100644 packages/slate-schema/test/validations/last/valid.js delete mode 100644 packages/slate-schema/test/validations/leaves/invalid-unknown.js delete mode 100644 packages/slate-schema/test/validations/leaves/invalid-value.js delete mode 100644 packages/slate-schema/test/validations/leaves/valid.js delete mode 100644 packages/slate-schema/test/validations/next/invalid-extra.js delete mode 100644 packages/slate-schema/test/validations/next/invalid.js delete mode 100644 packages/slate-schema/test/validations/next/valid.js delete mode 100644 packages/slate-schema/test/validations/parent/invalid-extra.js delete mode 100644 packages/slate-schema/test/validations/parent/invalid.js delete mode 100644 packages/slate-schema/test/validations/parent/valid.js delete mode 100644 packages/slate-schema/test/validations/previous/invalid-extra.js delete mode 100644 packages/slate-schema/test/validations/previous/invalid.js delete mode 100644 packages/slate-schema/test/validations/previous/valid.js delete mode 100644 packages/slate-schema/test/validations/properties/invalid-unknown.js delete mode 100644 packages/slate-schema/test/validations/properties/invalid-value.js delete mode 100644 packages/slate-schema/test/validations/properties/valid.js delete mode 100644 packages/slate-schema/test/validations/text/invalid.js delete mode 100644 packages/slate-schema/test/validations/text/valid.js delete mode 100644 packages/slate-schema/tsconfig.json diff --git a/Readme.md b/Readme.md index ea3ac1d7f4..538ccdd725 100644 --- a/Readme.md +++ b/Readme.md @@ -141,13 +141,12 @@ If you're maintaining a translation, feel free to pull request it here! Slate's codebase is monorepo managed with [Lerna](https://lernajs.io/). It consists of a handful of packages—although you won't always use all of them. They are: -| **Package** | **Version** | **Size** | **Description** | -| --------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------- | -| [`slate`](./packages/slate) | [![](https://img.shields.io/npm/v/slate.svg?maxAge=3600&label=version&colorB=007ec6)](./slate/package.json) | [![](http://img.badgesize.io/https://unpkg.com/slate/dist/slate.min.js?compression=gzip&label=size)](https://unpkg.com/slate/dist/slate.min.js) | Slate's core data model logic. | -| [`slate-history`](./packages/slate-history) | [![](https://img.shields.io/npm/v/slate-history.svg?maxAge=3600&label=version&colorB=007ec6)](./slate-history/package.json) | [![](http://img.badgesize.io/https://unpkg.com/slate-history/dist/slate-history.min.js?compression=gzip&label=size)](https://unpkg.com/slate-history/dist/slate-history.min.js) | A plugin that adds undo/redo history to Slate. | -| [`slate-hyperscript`](./packages/slate-hyperscript) | [![](https://img.shields.io/npm/v/slate-hyperscript.svg?maxAge=3600&label=version&colorB=007ec6)](./slate-hyperscript/package.json) | [![](http://img.badgesize.io/https://unpkg.com/slate-hyperscript/dist/slate-hyperscript.min.js?compression=gzip&label=size)](https://unpkg.com/slate-hyperscript/dist/slate-hyperscript.min.js) | A hyperscript tool to write JSX Slate documents! | -| [`slate-react`](./packages/slate-react) | [![](https://img.shields.io/npm/v/slate-react.svg?maxAge=3600&label=version&colorB=007ec6)](./slate-react/package.json) | [![](http://img.badgesize.io/https://unpkg.com/slate-react/dist/slate-react.min.js?compression=gzip&label=size)](https://unpkg.com/slate-react/dist/slate-react.min.js) | React components for rendering Slate editors. | -| [`slate-schema`](./packages/slate-schema) | [![](https://img.shields.io/npm/v/slate-schema.svg?maxAge=3600&label=version&colorB=007ec6)](./slate-schema/package.json) | [![](http://img.badgesize.io/https://unpkg.com/slate-schema/dist/slate-schema.min.js?compression=gzip&label=size)](https://unpkg.com/slate-schema/dist/slate-schema.min.js) | A plugin for enforcing constraints on Slate content. | +| **Package** | **Version** | **Size** | **Description** | +| --------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------ | +| [`slate`](./packages/slate) | [![](https://img.shields.io/npm/v/slate.svg?maxAge=3600&label=version&colorB=007ec6)](./slate/package.json) | [![](http://img.badgesize.io/https://unpkg.com/slate/dist/slate.min.js?compression=gzip&label=size)](https://unpkg.com/slate/dist/slate.min.js) | Slate's core data model logic. | +| [`slate-history`](./packages/slate-history) | [![](https://img.shields.io/npm/v/slate-history.svg?maxAge=3600&label=version&colorB=007ec6)](./slate-history/package.json) | [![](http://img.badgesize.io/https://unpkg.com/slate-history/dist/slate-history.min.js?compression=gzip&label=size)](https://unpkg.com/slate-history/dist/slate-history.min.js) | A plugin that adds undo/redo history to Slate. | +| [`slate-hyperscript`](./packages/slate-hyperscript) | [![](https://img.shields.io/npm/v/slate-hyperscript.svg?maxAge=3600&label=version&colorB=007ec6)](./slate-hyperscript/package.json) | [![](http://img.badgesize.io/https://unpkg.com/slate-hyperscript/dist/slate-hyperscript.min.js?compression=gzip&label=size)](https://unpkg.com/slate-hyperscript/dist/slate-hyperscript.min.js) | A hyperscript tool to write JSX Slate documents! | +| [`slate-react`](./packages/slate-react) | [![](https://img.shields.io/npm/v/slate-react.svg?maxAge=3600&label=version&colorB=007ec6)](./slate-react/package.json) | [![](http://img.badgesize.io/https://unpkg.com/slate-react/dist/slate-react.min.js?compression=gzip&label=size)](https://unpkg.com/slate-react/dist/slate-react.min.js) | React components for rendering Slate editors. |
diff --git a/config/rollup/rollup.config.js b/config/rollup/rollup.config.js index c94edabc22..4c5734ac64 100644 --- a/config/rollup/rollup.config.js +++ b/config/rollup/rollup.config.js @@ -13,7 +13,6 @@ import Core from '../../packages/slate/package.json' import History from '../../packages/slate-history/package.json' import Hyperscript from '../../packages/slate-hyperscript/package.json' import React from '../../packages/slate-react/package.json' -import Schema from '../../packages/slate-schema/package.json' /** * Return a Rollup configuration for a `pkg` with `env` and `target`. @@ -168,5 +167,4 @@ export default [ ...factory(History), ...factory(Hyperscript), ...factory(React), - ...factory(Schema), ] diff --git a/docs/concepts/XX-migrating.md b/docs/concepts/XX-migrating.md index 9acaafcb19..0921f052cc 100644 --- a/docs/concepts/XX-migrating.md +++ b/docs/concepts/XX-migrating.md @@ -97,9 +97,8 @@ slate-hyperscript 447 -> 345 slate-plain-serializer 56 -> 0 slate-prop-types 62 -> 0 slate-react-placeholder 62 -> 0 -slate-schema 0 -> 439 -total 13,807 -> 5,344 (39%) +total 13,807 -> 4,905 (36%) ``` It's quite a big difference! And that doesn't even include the dependencies that were shed in the process too. diff --git a/docs/general/faq.md b/docs/general/faq.md index 299337eccb..fc9296b84d 100644 --- a/docs/general/faq.md +++ b/docs/general/faq.md @@ -12,7 +12,7 @@ One of Slate's core principles is that, unlike most other editors, it does **not For the most part, this leads to increased flexbility without many downsides, but there are certain cases where you have to do a bit more work. Pasting is one of those cases. -Since Slate knows nothing about your schema, it can't know how to parse pasted HTML content (or other content). So, by default whenever a user pastes content into a Slate editor, it will parse it as plain text. If you want it to be smarter about pasted content, you need to override the `insert_data` command and deserialize the `DataTransfer` object's `text/html` data as you wish. +Since Slate knows nothing about your domain, it can't know how to parse pasted HTML content (or other content). So, by default whenever a user pastes content into a Slate editor, it will parse it as plain text. If you want it to be smarter about pasted content, you need to override the `insert_data` command and deserialize the `DataTransfer` object's `text/html` data as you wish. ### What browsers and devices does Slate support? diff --git a/docs/walkthroughs/04-applying-custom-formatting.md b/docs/walkthroughs/04-applying-custom-formatting.md index a89f5cfa46..89f39df4fb 100644 --- a/docs/walkthroughs/04-applying-custom-formatting.md +++ b/docs/walkthroughs/04-applying-custom-formatting.md @@ -130,7 +130,7 @@ const App = () => { Okay, so we've got the hotkey handler setup... but! If you happen to now try selecting text and hitting `Ctrl-B`, you won't notice any change. That's because we haven't told Slate how to render a "bold" mark. -For every format you want to add to your schema, Slate will break up the text content into "leaves", and you need to tell Slate how to read it, just like for elements. So let's define a `Leaf` component: +For every format you add, Slate will break up the text content into "leaves", and you need to tell Slate how to read it, just like for elements. So let's define a `Leaf` component: ```js // Define a React component to render leaves with bold text. diff --git a/package.json b/package.json index fab592e77a..c98cd910bf 100644 --- a/package.json +++ b/package.json @@ -83,7 +83,6 @@ "slate-history": "*", "slate-hyperscript": "*", "slate-react": "*", - "slate-schema": "*", "typescript": "^3.7.2" } } diff --git a/packages/slate-hyperscript/src/hyperscript.ts b/packages/slate-hyperscript/src/hyperscript.ts index f120364155..a65092aa52 100644 --- a/packages/slate-hyperscript/src/hyperscript.ts +++ b/packages/slate-hyperscript/src/hyperscript.ts @@ -39,7 +39,7 @@ type HyperscriptCreators = Record< /** * `HyperscriptShorthands` are dictionaries of properties applied to specific * kind of object, keyed by tag name. They allow you to easily define custom - * hyperscript tags for your schema. + * hyperscript tags for your domain. */ type HyperscriptShorthands = Record> diff --git a/packages/slate-schema/Readme.md b/packages/slate-schema/Readme.md deleted file mode 100644 index 47ac3a1b6d..0000000000 --- a/packages/slate-schema/Readme.md +++ /dev/null @@ -1 +0,0 @@ -This package contains the core logic of Slate. Feel free to poke around to learn more! diff --git a/packages/slate-schema/package.json b/packages/slate-schema/package.json deleted file mode 100644 index b39300c5de..0000000000 --- a/packages/slate-schema/package.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "name": "slate-schema", - "description": "A mixin for ensuring your Slate content conforms to a set of rules.", - "version": "0.52.6", - "license": "MIT", - "repository": "git://github.com/ianstormtaylor/slate.git", - "main": "dist/index.js", - "module": "dist/index.es.js", - "types": "dist/index.d.ts", - "umd": "dist/slate-schema.js", - "umdMin": "dist/slate-schema.min.js", - "sideEffects": false, - "files": [ - "dist/" - ], - "devDependencies": { - "slate": "^0.52.6", - "slate-hyperscript": "^0.52.6" - }, - "peerDependencies": { - "slate": ">=0.50.0" - }, - "umdGlobals": { - "slate": "Slate" - }, - "keywords": [ - "content", - "editor", - "enforce", - "normalize", - "normalization", - "rules", - "schema", - "slate", - "validate", - "validation" - ] -} diff --git a/packages/slate-schema/src/checkers.ts b/packages/slate-schema/src/checkers.ts deleted file mode 100644 index c7f1b625b1..0000000000 --- a/packages/slate-schema/src/checkers.ts +++ /dev/null @@ -1,319 +0,0 @@ -import { - NodeEntry, - Node, - Text, - Editor, - AncestorEntry, - Descendant, - DescendantEntry, -} from 'slate' - -import { NodeError } from './errors' -import { NodeRule, ChildValidation } from './rules' - -/** - * Check a node object. - */ - -export const checkNode = ( - editor: Editor, - entry: NodeEntry, - rule: NodeRule, - rules: NodeRule[] -): NodeError | undefined => { - const { match: m, validate: v } = rule - const [node, path] = entry - - if (Editor.isMatch(editor, entry, m)) { - if ('properties' in v) { - const { children, text, ...existing } = node - - for (const k in v.properties) { - const p = v.properties[k] - const value = node[k] - const isInvalid = typeof p === 'function' ? !p(value) : p !== value - - if (isInvalid) { - return { code: 'node_property_invalid', node, path, property: k } - } - - delete existing[k] - } - - for (const k in existing) { - return { code: 'node_property_invalid', node, path, property: k } - } - } - - if ('text' in v && v.text != null) { - const text = Node.text(node) - - if (!v.text(text)) { - return { code: 'node_text_invalid', node, path, text } - } - } - - if (!Text.isText(node)) { - if ('first' in v && v.first != null && node.children.length !== 0) { - const n = Node.child(node, 0) - const p = path.concat(0) - - if (!Editor.isMatch(editor, [n, p], v.first)) { - return { code: 'first_child_invalid', node: n, path: p, index: 0 } - } - } - - if ('last' in v && v.last != null && node.children.length !== 0) { - const i = node.children.length - 1 - const n = Node.child(node, i) - const p = path.concat(i) - - if (!Editor.isMatch(editor, [n, p], v.last)) { - return { code: 'last_child_invalid', node: n, path: p, index: i } - } - } - - if ('leaves' in v && v.leaves != null) { - for (const [n, p] of Editor.texts(editor, { at: path })) { - const { text, ...existing } = n - - for (const k in v.leaves) { - const l = v.leaves[k] - const value = n[k] - const isInvalid = typeof l === 'function' ? !l(value) : l !== value - - if (isInvalid) { - return { - code: 'node_leaf_invalid', - node: n, - path: p, - property: k, - } - } - - delete existing[k] - } - - for (const k in existing) { - return { code: 'node_leaf_invalid', node: n, path: p, property: k } - } - } - } - } - } -} - -/** - * Check an ancestor node object's children. - */ - -export const checkAncestor = ( - editor: Editor, - entry: AncestorEntry, - rule: NodeRule, - parentRules: NodeRule[] -): [NodeRule, NodeError] | undefined => { - const { validate: v } = rule - const [parent, parentPath] = entry - const processed = new Set() - const isMatch = Editor.isMatch(editor, entry, rule.match) - const groups = 'children' in v && v.children != null ? v.children : [] - let index = 0 - let count = 0 - let g = 0 - - while (true) { - const group = groups[g] as ChildValidation | undefined - const child = parent.children[index] as Descendant | undefined - const childPath = parentPath.concat(index) - - // For each child check the parent-related validations. But ensure that we - // only ever check each child once, which isn't guaranteed since we're not - // iterating just over the children in one go. - if (child && !processed.has(child)) { - processed.add(child) - - for (const r of parentRules) { - const e = checkParent(editor, entry, [child, childPath], r) - - if (e) { - return [r, e] - } - } - } - - // If we're out of children and groups we're done. - if (!child && !group) { - break - } - - // If the entry doesn't match the rule, then the `children` validation is - // irrelevant, so just keep iterating the children. - if (!isMatch) { - if (child) { - index++ - continue - } else { - break - } - } - - // If we're out of groups, just continue iterating the children. - if (!group) { - index++ - continue - } - - if ( - child && - Editor.isMatch(editor, [child, childPath], group.match || {}) - ) { - count++ - } - // Since we want to report overflow on last matching child we don't - // immediately v for count > max, but instead do so once we find - // a child that doesn't match. - if (child && group.max != null && count > group.max) { - if (g < groups.length - 1 && (group.min == null || count >= group.min)) { - g++ - count = 0 - continue - } else { - return [ - rule, - { - code: 'child_max_invalid', - node: child, - path: childPath, - count, - max: group.max, - }, - ] - } - } - - // If there's no child, we're either done, we're in an optional group, or - // we're missing a child in a group with a mininmum set. - if (!child) { - if (group.min != null && count < group.min) { - return [ - rule, - { - code: 'child_min_invalid', - node: child, - path: childPath, - count, - min: group.min, - }, - ] - } else { - g++ - count = 0 - continue - } - } - - if (Editor.isMatch(editor, [child, childPath], group.match || {})) { - index++ - continue - } - - // If there are more children definitions after this one, then this - // child might actually be valid for a future one. - if (g + 1 < groups.length) { - // If we've already satisfied the current child definition's minimum - // then we can proceed to the next definition. - if (group.min == null || count >= group.min) { - g++ - count = 0 - continue - } - - // The current group might be missing an element, and the child is - // actually a member of the next group. If so, the next validation - // won't report errors, and we can break to error out as minimum. - const nc = groups[g + 1] - - if (nc && Editor.isMatch(editor, [child, childPath], nc.match || {})) { - return [ - rule, - { - code: 'child_min_invalid', - node: child, - path: childPath, - count, - min: group.min, - }, - ] - } - } - - return [rule, { code: 'child_invalid', node: child, path: childPath }] - } -} - -/** - * Check a parent node object's children. - */ - -export const checkParent = ( - editor: Editor, - entry: AncestorEntry, - childEntry: DescendantEntry, - rule: NodeRule -): NodeError | undefined => { - const { match: m, validate: v } = rule - const [parent, parentPath] = entry - const [child, childPath] = childEntry - const index = childPath[childPath.length - 1] - - if ( - 'parent' in v && - v.parent != null && - Editor.isMatch(editor, [child, childPath], m) && - !Editor.isMatch(editor, [parent, parentPath], v.parent) - ) { - return { - code: 'parent_invalid', - node: parent, - path: parentPath, - index, - } - } - - if ( - 'previous' in v && - v.previous != null && - index > 0 && - Editor.isMatch(editor, [child, childPath], m) - ) { - const prevChild = Node.child(parent, index - 1) - const prevPath = parentPath.concat(index - 1) - - if (!Editor.isMatch(editor, [prevChild, prevPath], v.previous)) { - return { - code: 'previous_sibling_invalid', - node: prevChild, - path: prevPath, - } - } - } - - if ( - 'next' in v && - v.next != null && - index < parent.children.length - 1 && - Editor.isMatch(editor, [child, childPath], m) - ) { - const nextChild = Node.child(parent, index + 1) - const nextPath = parentPath.concat(index + 1) - - if (!Editor.isMatch(editor, [nextChild, nextPath], v.next)) { - return { - code: 'next_sibling_invalid', - node: nextChild, - path: nextPath, - } - } - } -} diff --git a/packages/slate-schema/src/define-schema.ts b/packages/slate-schema/src/define-schema.ts deleted file mode 100644 index 858770f2e9..0000000000 --- a/packages/slate-schema/src/define-schema.ts +++ /dev/null @@ -1,150 +0,0 @@ -import { Editor, Text, NodeEntry } from 'slate' - -import { NodeRule, SchemaRule } from './rules' -import { NodeError } from './errors' -import { checkNode, checkAncestor } from './checkers' - -/** - * The schema plugin augments an editor to ensure that its content is normalized - * to always obey a schema after operations are applied. - */ - -export const defineSchema = ( - rules: SchemaRule[] = [] -): ((editor: Editor) => Editor) => { - const nodeRules: NodeRule[] = rules - const parentRules = rules.filter(rule => { - return ( - 'parent' in rule.validate || - 'next' in rule.validate || - 'previous' in rule.validate - ) - }) - - return (editor: Editor): Editor => { - const { normalizeNode } = editor - - editor.normalizeNode = (entry: NodeEntry) => { - const [n, p] = entry - let error: NodeError | undefined - let rule: NodeRule | undefined - - for (const r of nodeRules) { - error = checkNode(editor, [n, p], r, nodeRules) - - if (error) { - rule = r - break - } - - if (!Text.isText(n)) { - const failure = checkAncestor(editor, [n, p], r, parentRules) - - if (failure) { - rule = failure[0] - error = failure[1] - break - } - } - } - - if (error == null) { - return normalizeNode(entry) - } - - const prevLength = editor.operations.length - - // First run the user-provided `normalize` function if one exists... - if (rule != null && rule.normalize) { - rule.normalize(editor, error) - } - - // If the `normalize` function did add any operations to the editor, - // we assume that it fully handled the normalization and exit. - if (editor.operations.length > prevLength) { - return - } - - switch (error.code) { - case 'first_child_invalid': - case 'last_child_invalid': { - const { path } = error - const [parent, parentPath] = Editor.parent(editor, path) - - if (parent.children.length > 1) { - Editor.removeNodes(editor, { at: path }) - } else if (parentPath.length === 0) { - const range = Editor.range(editor, parentPath) - Editor.removeNodes(editor, { - at: range, - match: ([, p]) => p.length === 1, - }) - } else { - Editor.removeNodes(editor, { at: parentPath }) - } - - break - } - - case 'child_max_invalid': { - const { path } = error - const [parent, parentPath] = Editor.parent(editor, path) - - if (parent.children.length === 1 && parentPath.length !== 0) { - Editor.removeNodes(editor, { at: parentPath }) - } else { - Editor.removeNodes(editor, { at: path }) - } - - break - } - - case 'child_min_invalid': { - const { path } = error - const [, parentPath] = Editor.parent(editor, path) - - if (parentPath.length === 0) { - const range = Editor.range(editor, parentPath) - Editor.removeNodes(editor, { - at: range, - match: ([, p]) => p.length === 1, - }) - } else { - Editor.removeNodes(editor, { at: parentPath }) - } - - break - } - - case 'child_invalid': - case 'next_sibling_invalid': - case 'node_leaf_invalid': - case 'node_property_invalid': - case 'node_text_invalid': - case 'previous_sibling_invalid': { - const { path } = error - Editor.removeNodes(editor, { at: path }) - break - } - - case 'parent_invalid': { - const { path, index } = error - const childPath = path.concat(index) - Editor.removeNodes(editor, { at: childPath }) - break - } - - default: { - const _: never = error - throw new Error( - `Cannot normalize unknown validation error: "${JSON.stringify( - error - )}"` - ) - } - } - } - - return editor - } -} diff --git a/packages/slate-schema/src/errors.ts b/packages/slate-schema/src/errors.ts deleted file mode 100644 index 892b7301ce..0000000000 --- a/packages/slate-schema/src/errors.ts +++ /dev/null @@ -1,92 +0,0 @@ -import { Ancestor, Descendant, Node, Path } from 'slate' - -export interface ChildInvalidError { - code: 'child_invalid' - node: Descendant - path: Path -} - -export interface ChildMaxInvalidError { - code: 'child_max_invalid' - node: Descendant - path: Path - count: number - max: number -} - -export interface ChildMinInvalidError { - code: 'child_min_invalid' - node: Descendant | undefined - path: Path - count: number - min: number -} - -export interface FirstChildInvalidError { - code: 'first_child_invalid' - node: Descendant - path: Path - index: number -} - -export interface LastChildInvalidError { - code: 'last_child_invalid' - node: Descendant - path: Path - index: number -} - -export interface NextSiblingInvalidError { - code: 'next_sibling_invalid' - node: Node - path: Path -} - -export interface NodeLeafInvalidError { - code: 'node_leaf_invalid' - node: Node - path: Path - property: string -} - -export interface NodePropertyInvalidError { - code: 'node_property_invalid' - node: Node - path: Path - property: string -} - -export interface NodeTextInvalidError { - code: 'node_text_invalid' - node: Node - path: Path - text: string -} - -export interface ParentInvalidError { - code: 'parent_invalid' - node: Ancestor - path: Path - index: number -} - -export interface PreviousSiblingInvalidError { - code: 'previous_sibling_invalid' - node: Node - path: Path -} - -export type NodeError = - | ChildInvalidError - | ChildMaxInvalidError - | ChildMinInvalidError - | FirstChildInvalidError - | LastChildInvalidError - | NextSiblingInvalidError - | NodeLeafInvalidError - | NodePropertyInvalidError - | NodeTextInvalidError - | ParentInvalidError - | PreviousSiblingInvalidError - -export type SchemaError = NodeError diff --git a/packages/slate-schema/src/index.ts b/packages/slate-schema/src/index.ts deleted file mode 100644 index 98f7f5df9b..0000000000 --- a/packages/slate-schema/src/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './errors' -export * from './define-schema' -export * from './rules' diff --git a/packages/slate-schema/src/rules.ts b/packages/slate-schema/src/rules.ts deleted file mode 100644 index 29e227c2b2..0000000000 --- a/packages/slate-schema/src/rules.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { Editor, NodeMatch } from 'slate' -import { NodeError } from './errors' - -export interface ChildValidation { - match?: NodeMatch - min?: number - max?: number -} - -export interface NodeValidation { - children?: ChildValidation[] - first?: NodeMatch - last?: NodeMatch - leaves?: Record - next?: NodeMatch - parent?: NodeMatch - previous?: NodeMatch - properties?: Record - text?: (text: string) => boolean -} - -export interface NodeRule { - for: 'node' - match: NodeMatch - validate: NodeValidation - normalize: (editor: Editor, error: NodeError) => void -} - -export type SchemaRule = NodeRule diff --git a/packages/slate-schema/test/index.js b/packages/slate-schema/test/index.js deleted file mode 100644 index 8ddb8991ce..0000000000 --- a/packages/slate-schema/test/index.js +++ /dev/null @@ -1,14 +0,0 @@ -import assert from 'assert' -import { fixtures } from '../../../support/fixtures' -import { Editor } from 'slate' -import { defineSchema } from '..' - -describe('slate-schema', () => { - fixtures(__dirname, 'validations', ({ module }) => { - const { input, schema, output } = module - const withSchema = defineSchema(schema) - const editor = withSchema(input) - Editor.normalize(editor, { force: true }) - assert.deepEqual(editor.children, output.children) - }) -}) diff --git a/packages/slate-schema/test/validations/children/match/invalid-array.js b/packages/slate-schema/test/validations/children/match/invalid-array.js deleted file mode 100644 index 480dc21952..0000000000 --- a/packages/slate-schema/test/validations/children/match/invalid-array.js +++ /dev/null @@ -1,30 +0,0 @@ -/** @jsx jsx */ - -import { jsx } from 'slate-hyperscript' - -export const schema = [ - { - for: 'node', - match: { a: true }, - validate: { - children: [{ match: [{ b: true }, { c: true }] }], - }, - }, -] - -export const input = ( - - - one - two - - -) - -export const output = ( - - - one - - -) diff --git a/packages/slate-schema/test/validations/children/match/invalid-many.js b/packages/slate-schema/test/validations/children/match/invalid-many.js deleted file mode 100644 index f0fdcc03aa..0000000000 --- a/packages/slate-schema/test/validations/children/match/invalid-many.js +++ /dev/null @@ -1,32 +0,0 @@ -/** @jsx jsx */ - -import { jsx } from 'slate-hyperscript' - -export const schema = [ - { - for: 'node', - match: { a: true }, - validate: { - children: [{ match: { b: true } }], - }, - }, -] - -export const input = ( - - - one - two - three - four - - -) - -export const output = ( - - - one - - -) diff --git a/packages/slate-schema/test/validations/children/match/invalid-second.js b/packages/slate-schema/test/validations/children/match/invalid-second.js deleted file mode 100644 index 8a88feb9ed..0000000000 --- a/packages/slate-schema/test/validations/children/match/invalid-second.js +++ /dev/null @@ -1,30 +0,0 @@ -/** @jsx jsx */ - -import { jsx } from 'slate-hyperscript' - -export const schema = [ - { - for: 'node', - match: { a: true }, - validate: { - children: [{ max: 1, match: { b: true } }, { match: { b: true } }], - }, - }, -] - -export const input = ( - - - one - two - - -) - -export const output = ( - - - one - - -) diff --git a/packages/slate-schema/test/validations/children/match/invalid.js b/packages/slate-schema/test/validations/children/match/invalid.js deleted file mode 100644 index fbd0bc606e..0000000000 --- a/packages/slate-schema/test/validations/children/match/invalid.js +++ /dev/null @@ -1,30 +0,0 @@ -/** @jsx jsx */ - -import { jsx } from 'slate-hyperscript' - -export const schema = [ - { - for: 'node', - match: { a: true }, - validate: { - children: [{ match: { b: true } }], - }, - }, -] - -export const input = ( - - - one - two - - -) - -export const output = ( - - - one - - -) diff --git a/packages/slate-schema/test/validations/children/match/valid-array.js b/packages/slate-schema/test/validations/children/match/valid-array.js deleted file mode 100644 index cc621499b4..0000000000 --- a/packages/slate-schema/test/validations/children/match/valid-array.js +++ /dev/null @@ -1,24 +0,0 @@ -/** @jsx jsx */ - -import { jsx } from 'slate-hyperscript' - -export const schema = [ - { - for: 'node', - match: { a: true }, - validate: { - children: [{ match: [{ b: true }, { c: true }] }], - }, - }, -] - -export const input = ( - - - one - two - - -) - -export const output = input diff --git a/packages/slate-schema/test/validations/children/match/valid-second.js b/packages/slate-schema/test/validations/children/match/valid-second.js deleted file mode 100644 index 4ed79a886a..0000000000 --- a/packages/slate-schema/test/validations/children/match/valid-second.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx jsx */ - -import { jsx } from 'slate-hyperscript' - -export const schema = [ - { - for: 'node', - match: { a: true }, - validate: { - children: [ - { max: 1, match: { b: true } }, - { max: 1, match: { b: true } }, - ], - }, - }, -] - -export const input = ( - - - one - one - - -) - -export const output = input diff --git a/packages/slate-schema/test/validations/children/match/valid.js b/packages/slate-schema/test/validations/children/match/valid.js deleted file mode 100644 index e84359f409..0000000000 --- a/packages/slate-schema/test/validations/children/match/valid.js +++ /dev/null @@ -1,23 +0,0 @@ -/** @jsx jsx */ - -import { jsx } from 'slate-hyperscript' - -export const schema = [ - { - for: 'node', - match: { a: true }, - validate: { - children: [{ match: { b: true } }], - }, - }, -] - -export const input = ( - - - one - - -) - -export const output = input diff --git a/packages/slate-schema/test/validations/children/max/invalid-many.js b/packages/slate-schema/test/validations/children/max/invalid-many.js deleted file mode 100644 index e9ea77cdda..0000000000 --- a/packages/slate-schema/test/validations/children/max/invalid-many.js +++ /dev/null @@ -1,30 +0,0 @@ -/** @jsx jsx */ - -import { jsx } from 'slate-hyperscript' - -export const schema = [ - { - for: 'node', - match: { a: true }, - validate: { - children: [{ match: 'text', max: 1 }], - }, - }, -] - -export const input = ( - - - one - two - - -) - -export const output = ( - - - - - -) diff --git a/packages/slate-schema/test/validations/children/max/invalid-match.js b/packages/slate-schema/test/validations/children/max/invalid-match.js deleted file mode 100644 index 2e593d46cb..0000000000 --- a/packages/slate-schema/test/validations/children/max/invalid-match.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx jsx */ - -import { jsx } from 'slate-hyperscript' - -export const schema = [ - { - for: 'node', - match: { a: true }, - validate: { - children: [{ match: 'text', max: 1 }], - }, - }, -] - -export const input = ( - - - one - - -) - -export const output = ( - - - - - -) diff --git a/packages/slate-schema/test/validations/children/max/invalid-second.js b/packages/slate-schema/test/validations/children/max/invalid-second.js deleted file mode 100644 index b0e6155052..0000000000 --- a/packages/slate-schema/test/validations/children/max/invalid-second.js +++ /dev/null @@ -1,32 +0,0 @@ -/** @jsx jsx */ - -import { jsx } from 'slate-hyperscript' - -export const schema = [ - { - for: 'node', - match: { a: true }, - validate: { - children: [{ max: 1 }, { max: 1 }], - }, - }, -] - -export const input = ( - - - one - two - three - - -) - -export const output = ( - - - one - two - - -) diff --git a/packages/slate-schema/test/validations/children/max/invalid.js b/packages/slate-schema/test/validations/children/max/invalid.js deleted file mode 100644 index 2f586b3468..0000000000 --- a/packages/slate-schema/test/validations/children/max/invalid.js +++ /dev/null @@ -1,30 +0,0 @@ -/** @jsx jsx */ - -import { jsx } from 'slate-hyperscript' - -export const schema = [ - { - for: 'node', - match: { a: true }, - validate: { - children: [{ max: 1 }], - }, - }, -] - -export const input = ( - - - one - two - - -) - -export const output = ( - - - one - - -) diff --git a/packages/slate-schema/test/validations/children/max/valid-second.js b/packages/slate-schema/test/validations/children/max/valid-second.js deleted file mode 100644 index bcbfcc1600..0000000000 --- a/packages/slate-schema/test/validations/children/max/valid-second.js +++ /dev/null @@ -1,24 +0,0 @@ -/** @jsx jsx */ - -import { jsx } from 'slate-hyperscript' - -export const schema = [ - { - for: 'node', - match: { a: true }, - validate: { - children: [{ max: 1 }, { max: 1 }], - }, - }, -] - -export const input = ( - - - one - one - - -) - -export const output = input diff --git a/packages/slate-schema/test/validations/children/max/valid.js b/packages/slate-schema/test/validations/children/max/valid.js deleted file mode 100644 index bffe4d0a30..0000000000 --- a/packages/slate-schema/test/validations/children/max/valid.js +++ /dev/null @@ -1,23 +0,0 @@ -/** @jsx jsx */ - -import { jsx } from 'slate-hyperscript' - -export const schema = [ - { - for: 'node', - match: { a: true }, - validate: { - children: [{ max: 1 }], - }, - }, -] - -export const input = ( - - - one - - -) - -export const output = input diff --git a/packages/slate-schema/test/validations/children/min/invalid-second-with-match.js b/packages/slate-schema/test/validations/children/min/invalid-second-with-match.js deleted file mode 100644 index 13aea49eac..0000000000 --- a/packages/slate-schema/test/validations/children/min/invalid-second-with-match.js +++ /dev/null @@ -1,26 +0,0 @@ -/** @jsx jsx */ - -import { jsx } from 'slate-hyperscript' - -export const schema = [ - { - for: 'node', - match: { a: true }, - validate: { - children: [ - { match: { b: true }, min: 1 }, - { match: { c: true }, min: 0 }, - ], - }, - }, -] - -export const input = ( - - - one - - -) - -export const output = diff --git a/packages/slate-schema/test/validations/children/min/invalid-second.js b/packages/slate-schema/test/validations/children/min/invalid-second.js deleted file mode 100644 index e98e758dc4..0000000000 --- a/packages/slate-schema/test/validations/children/min/invalid-second.js +++ /dev/null @@ -1,23 +0,0 @@ -/** @jsx jsx */ - -import { jsx } from 'slate-hyperscript' - -export const schema = [ - { - for: 'node', - match: { a: true }, - validate: { - children: [{ min: 1, max: 1 }, { min: 1 }], - }, - }, -] - -export const input = ( - - - one - - -) - -export const output = diff --git a/packages/slate-schema/test/validations/children/min/invalid.js b/packages/slate-schema/test/validations/children/min/invalid.js deleted file mode 100644 index 12a239d42c..0000000000 --- a/packages/slate-schema/test/validations/children/min/invalid.js +++ /dev/null @@ -1,23 +0,0 @@ -/** @jsx jsx */ - -import { jsx } from 'slate-hyperscript' - -export const schema = [ - { - for: 'node', - match: { a: true }, - validate: { - children: [{ min: 2 }], - }, - }, -] - -export const input = ( - - - one - - -) - -export const output = diff --git a/packages/slate-schema/test/validations/children/min/valid-second-optional-exists.js b/packages/slate-schema/test/validations/children/min/valid-second-optional-exists.js deleted file mode 100644 index cfaf0806ab..0000000000 --- a/packages/slate-schema/test/validations/children/min/valid-second-optional-exists.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx jsx */ - -import { jsx } from 'slate-hyperscript' - -export const schema = [ - { - for: 'node', - match: { a: true }, - validate: { - children: [ - { match: { b: true }, min: 1, max: 1 }, - { match: { c: true }, min: 0 }, - ], - }, - }, -] - -export const input = ( - - - one - two - - -) - -export const output = input diff --git a/packages/slate-schema/test/validations/children/min/valid-second-optional-missing.js b/packages/slate-schema/test/validations/children/min/valid-second-optional-missing.js deleted file mode 100644 index 36dc0212bb..0000000000 --- a/packages/slate-schema/test/validations/children/min/valid-second-optional-missing.js +++ /dev/null @@ -1,26 +0,0 @@ -/** @jsx jsx */ - -import { jsx } from 'slate-hyperscript' - -export const schema = [ - { - for: 'node', - match: { a: true }, - validate: { - children: [ - { match: { b: true }, min: 1, max: 1 }, - { match: { c: true }, min: 0 }, - ], - }, - }, -] - -export const input = ( - - - one - - -) - -export const output = input diff --git a/packages/slate-schema/test/validations/children/min/valid-second.js b/packages/slate-schema/test/validations/children/min/valid-second.js deleted file mode 100644 index 8538aec998..0000000000 --- a/packages/slate-schema/test/validations/children/min/valid-second.js +++ /dev/null @@ -1,24 +0,0 @@ -/** @jsx jsx */ - -import { jsx } from 'slate-hyperscript' - -export const schema = [ - { - for: 'node', - match: { a: true }, - validate: { - children: [{ min: 1, max: 1 }, { min: 1 }], - }, - }, -] - -export const input = ( - - - one - one - - -) - -export const output = input diff --git a/packages/slate-schema/test/validations/children/min/valid.js b/packages/slate-schema/test/validations/children/min/valid.js deleted file mode 100644 index 2e1d05792b..0000000000 --- a/packages/slate-schema/test/validations/children/min/valid.js +++ /dev/null @@ -1,23 +0,0 @@ -/** @jsx jsx */ - -import { jsx } from 'slate-hyperscript' - -export const schema = [ - { - for: 'node', - match: { a: true }, - validate: { - children: [{ min: 1 }], - }, - }, -] - -export const input = ( - - - one - - -) - -export const output = input diff --git a/packages/slate-schema/test/validations/first/invalid-many.js b/packages/slate-schema/test/validations/first/invalid-many.js deleted file mode 100644 index e644114945..0000000000 --- a/packages/slate-schema/test/validations/first/invalid-many.js +++ /dev/null @@ -1,32 +0,0 @@ -/** @jsx jsx */ - -import { jsx } from 'slate-hyperscript' - -export const schema = [ - { - for: 'node', - match: { a: true }, - validate: { - first: [{ b: true }], - }, - }, -] - -export const input = ( - - - one - two - three - - -) - -export const output = ( - - - two - three - - -) diff --git a/packages/slate-schema/test/validations/first/invalid-one.js b/packages/slate-schema/test/validations/first/invalid-one.js deleted file mode 100644 index 52d9880fd6..0000000000 --- a/packages/slate-schema/test/validations/first/invalid-one.js +++ /dev/null @@ -1,23 +0,0 @@ -/** @jsx jsx */ - -import { jsx } from 'slate-hyperscript' - -export const schema = [ - { - for: 'node', - match: { a: true }, - validate: { - first: [{ b: true }], - }, - }, -] - -export const input = ( - - - one - - -) - -export const output = diff --git a/packages/slate-schema/test/validations/first/valid.js b/packages/slate-schema/test/validations/first/valid.js deleted file mode 100644 index 8f7b788625..0000000000 --- a/packages/slate-schema/test/validations/first/valid.js +++ /dev/null @@ -1,25 +0,0 @@ -/** @jsx jsx */ - -import { jsx } from 'slate-hyperscript' - -export const schema = [ - { - for: 'node', - match: { a: true }, - validate: { - first: [{ b: true }], - }, - }, -] - -export const input = ( - - - one - two - three - - -) - -export const output = input diff --git a/packages/slate-schema/test/validations/last/invalid-many.js b/packages/slate-schema/test/validations/last/invalid-many.js deleted file mode 100644 index 01de669a35..0000000000 --- a/packages/slate-schema/test/validations/last/invalid-many.js +++ /dev/null @@ -1,32 +0,0 @@ -/** @jsx jsx */ - -import { jsx } from 'slate-hyperscript' - -export const schema = [ - { - for: 'node', - match: { a: true }, - validate: { - last: [{ b: true }], - }, - }, -] - -export const input = ( - - - one - two - three - - -) - -export const output = ( - - - one - two - - -) diff --git a/packages/slate-schema/test/validations/last/invalid-one.js b/packages/slate-schema/test/validations/last/invalid-one.js deleted file mode 100644 index 6c2ff8619f..0000000000 --- a/packages/slate-schema/test/validations/last/invalid-one.js +++ /dev/null @@ -1,23 +0,0 @@ -/** @jsx jsx */ - -import { jsx } from 'slate-hyperscript' - -export const schema = [ - { - for: 'node', - match: { a: true }, - validate: { - last: [{ b: true }], - }, - }, -] - -export const input = ( - - - one - - -) - -export const output = diff --git a/packages/slate-schema/test/validations/last/valid.js b/packages/slate-schema/test/validations/last/valid.js deleted file mode 100644 index 972b860e7c..0000000000 --- a/packages/slate-schema/test/validations/last/valid.js +++ /dev/null @@ -1,25 +0,0 @@ -/** @jsx jsx */ - -import { jsx } from 'slate-hyperscript' - -export const schema = [ - { - for: 'node', - match: { a: true }, - validate: { - last: [{ b: true }], - }, - }, -] - -export const input = ( - - - one - two - three - - -) - -export const output = input diff --git a/packages/slate-schema/test/validations/leaves/invalid-unknown.js b/packages/slate-schema/test/validations/leaves/invalid-unknown.js deleted file mode 100644 index 53acc54f17..0000000000 --- a/packages/slate-schema/test/validations/leaves/invalid-unknown.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx jsx */ - -import { jsx } from 'slate-hyperscript' - -export const schema = [ - { - for: 'node', - match: { a: true }, - validate: { - leaves: { - bold: v => v === true || v === undefined, - }, - }, - }, -] - -export const input = ( - - - word - - -) - -export const output = ( - - - - - -) diff --git a/packages/slate-schema/test/validations/leaves/invalid-value.js b/packages/slate-schema/test/validations/leaves/invalid-value.js deleted file mode 100644 index d9395e0181..0000000000 --- a/packages/slate-schema/test/validations/leaves/invalid-value.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx jsx */ - -import { jsx } from 'slate-hyperscript' - -export const schema = [ - { - for: 'node', - match: { a: true }, - validate: { - leaves: { - bold: v => v === true || v === undefined, - }, - }, - }, -] - -export const input = ( - - - word - - -) - -export const output = ( - - - - - -) diff --git a/packages/slate-schema/test/validations/leaves/valid.js b/packages/slate-schema/test/validations/leaves/valid.js deleted file mode 100644 index 699d824313..0000000000 --- a/packages/slate-schema/test/validations/leaves/valid.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx jsx */ - -import { jsx } from 'slate-hyperscript' - -export const schema = [ - { - for: 'node', - match: { a: true }, - validate: { - leaves: { - bold: v => v === true || v === undefined, - }, - }, - }, -] - -export const input = ( - - - word - - -) - -export const output = ( - - - word - - -) diff --git a/packages/slate-schema/test/validations/next/invalid-extra.js b/packages/slate-schema/test/validations/next/invalid-extra.js deleted file mode 100644 index 9eadff7813..0000000000 --- a/packages/slate-schema/test/validations/next/invalid-extra.js +++ /dev/null @@ -1,33 +0,0 @@ -/** @jsx jsx */ - -import { jsx } from 'slate-hyperscript' - -export const schema = [ - { - for: 'node', - match: { a: true }, - validate: { - next: [{ b: true }], - }, - }, - { - for: 'node', - match: { a: true }, - validate: {}, - }, -] - -export const input = ( - - one - two - three - -) - -export const output = ( - - one - three - -) diff --git a/packages/slate-schema/test/validations/next/invalid.js b/packages/slate-schema/test/validations/next/invalid.js deleted file mode 100644 index ae5bbd8b8a..0000000000 --- a/packages/slate-schema/test/validations/next/invalid.js +++ /dev/null @@ -1,28 +0,0 @@ -/** @jsx jsx */ - -import { jsx } from 'slate-hyperscript' - -export const schema = [ - { - for: 'node', - match: { a: true }, - validate: { - next: [{ b: true }], - }, - }, -] - -export const input = ( - - one - two - three - -) - -export const output = ( - - one - three - -) diff --git a/packages/slate-schema/test/validations/next/valid.js b/packages/slate-schema/test/validations/next/valid.js deleted file mode 100644 index 116b3dd47d..0000000000 --- a/packages/slate-schema/test/validations/next/valid.js +++ /dev/null @@ -1,23 +0,0 @@ -/** @jsx jsx */ - -import { jsx } from 'slate-hyperscript' - -export const schema = [ - { - for: 'node', - match: { a: true }, - validate: { - next: [{ b: true }], - }, - }, -] - -export const input = ( - - one - two - three - -) - -export const output = input diff --git a/packages/slate-schema/test/validations/parent/invalid-extra.js b/packages/slate-schema/test/validations/parent/invalid-extra.js deleted file mode 100644 index 7e2b48263f..0000000000 --- a/packages/slate-schema/test/validations/parent/invalid-extra.js +++ /dev/null @@ -1,37 +0,0 @@ -/** @jsx jsx */ - -import { jsx } from 'slate-hyperscript' - -export const schema = [ - { - for: 'node', - match: { c: true }, - validate: { - parent: { b: true }, - }, - }, - { - for: 'node', - match: { a: true }, - validate: {}, - }, -] - -export const input = ( - - - one - two - three - - -) - -export const output = ( - - - one - two - - -) diff --git a/packages/slate-schema/test/validations/parent/invalid.js b/packages/slate-schema/test/validations/parent/invalid.js deleted file mode 100644 index f89742c960..0000000000 --- a/packages/slate-schema/test/validations/parent/invalid.js +++ /dev/null @@ -1,32 +0,0 @@ -/** @jsx jsx */ - -import { jsx } from 'slate-hyperscript' - -export const schema = [ - { - for: 'node', - match: { c: true }, - validate: { - parent: { b: true }, - }, - }, -] - -export const input = ( - - - one - two - three - - -) - -export const output = ( - - - one - two - - -) diff --git a/packages/slate-schema/test/validations/parent/valid.js b/packages/slate-schema/test/validations/parent/valid.js deleted file mode 100644 index b14005928f..0000000000 --- a/packages/slate-schema/test/validations/parent/valid.js +++ /dev/null @@ -1,33 +0,0 @@ -/** @jsx jsx */ - -import { jsx } from 'slate-hyperscript' - -export const schema = [ - { - for: 'node', - match: { c: true }, - validate: { - parent: { b: true }, - }, - }, -] - -export const input = ( - - - one - two - three - - -) - -export const output = ( - - - one - two - three - - -) diff --git a/packages/slate-schema/test/validations/previous/invalid-extra.js b/packages/slate-schema/test/validations/previous/invalid-extra.js deleted file mode 100644 index 1c849f3e54..0000000000 --- a/packages/slate-schema/test/validations/previous/invalid-extra.js +++ /dev/null @@ -1,33 +0,0 @@ -/** @jsx jsx */ - -import { jsx } from 'slate-hyperscript' - -export const schema = [ - { - for: 'node', - match: { a: true }, - validate: { - next: [{ b: true }], - }, - }, - { - for: 'node', - match: { c: true }, - validate: {}, - }, -] - -export const input = ( - - one - two - three - -) - -export const output = ( - - one - three - -) diff --git a/packages/slate-schema/test/validations/previous/invalid.js b/packages/slate-schema/test/validations/previous/invalid.js deleted file mode 100644 index ae5bbd8b8a..0000000000 --- a/packages/slate-schema/test/validations/previous/invalid.js +++ /dev/null @@ -1,28 +0,0 @@ -/** @jsx jsx */ - -import { jsx } from 'slate-hyperscript' - -export const schema = [ - { - for: 'node', - match: { a: true }, - validate: { - next: [{ b: true }], - }, - }, -] - -export const input = ( - - one - two - three - -) - -export const output = ( - - one - three - -) diff --git a/packages/slate-schema/test/validations/previous/valid.js b/packages/slate-schema/test/validations/previous/valid.js deleted file mode 100644 index 116b3dd47d..0000000000 --- a/packages/slate-schema/test/validations/previous/valid.js +++ /dev/null @@ -1,23 +0,0 @@ -/** @jsx jsx */ - -import { jsx } from 'slate-hyperscript' - -export const schema = [ - { - for: 'node', - match: { a: true }, - validate: { - next: [{ b: true }], - }, - }, -] - -export const input = ( - - one - two - three - -) - -export const output = input diff --git a/packages/slate-schema/test/validations/properties/invalid-unknown.js b/packages/slate-schema/test/validations/properties/invalid-unknown.js deleted file mode 100644 index 4c774356a6..0000000000 --- a/packages/slate-schema/test/validations/properties/invalid-unknown.js +++ /dev/null @@ -1,25 +0,0 @@ -/** @jsx jsx */ - -import { jsx } from 'slate-hyperscript' - -export const schema = [ - { - for: 'node', - match: { a: true }, - validate: { - properties: { - a: true, - }, - }, - }, -] - -export const input = ( - - - word - - -) - -export const output = diff --git a/packages/slate-schema/test/validations/properties/invalid-value.js b/packages/slate-schema/test/validations/properties/invalid-value.js deleted file mode 100644 index c980cfa1c6..0000000000 --- a/packages/slate-schema/test/validations/properties/invalid-value.js +++ /dev/null @@ -1,26 +0,0 @@ -/** @jsx jsx */ - -import { jsx } from 'slate-hyperscript' - -export const schema = [ - { - for: 'node', - match: { a: true }, - validate: { - properties: { - a: true, - thing: v => v == null || v === 'valid', - }, - }, - }, -] - -export const input = ( - - - word - - -) - -export const output = diff --git a/packages/slate-schema/test/validations/properties/valid.js b/packages/slate-schema/test/validations/properties/valid.js deleted file mode 100644 index 88ac077d25..0000000000 --- a/packages/slate-schema/test/validations/properties/valid.js +++ /dev/null @@ -1,26 +0,0 @@ -/** @jsx jsx */ - -import { jsx } from 'slate-hyperscript' - -export const schema = [ - { - for: 'node', - match: { a: true }, - validate: { - properties: { - a: true, - thing: v => v == null || v === 'valid', - }, - }, - }, -] - -export const input = ( - - - word - - -) - -export const output = input diff --git a/packages/slate-schema/test/validations/text/invalid.js b/packages/slate-schema/test/validations/text/invalid.js deleted file mode 100644 index 3b8d5f69f0..0000000000 --- a/packages/slate-schema/test/validations/text/invalid.js +++ /dev/null @@ -1,21 +0,0 @@ -/** @jsx jsx */ - -import { jsx } from 'slate-hyperscript' - -export const schema = [ - { - for: 'node', - match: { a: true }, - validate: { - text: v => v === 'valid', - }, - }, -] - -export const input = ( - - invalid - -) - -export const output = diff --git a/packages/slate-schema/test/validations/text/valid.js b/packages/slate-schema/test/validations/text/valid.js deleted file mode 100644 index f4752188a1..0000000000 --- a/packages/slate-schema/test/validations/text/valid.js +++ /dev/null @@ -1,21 +0,0 @@ -/** @jsx jsx */ - -import { jsx } from 'slate-hyperscript' - -export const schema = [ - { - for: 'node', - match: { a: true }, - validate: { - text: v => v === 'valid', - }, - }, -] - -export const input = ( - - valid - -) - -export const output = input diff --git a/packages/slate-schema/tsconfig.json b/packages/slate-schema/tsconfig.json deleted file mode 100644 index 4463c7357c..0000000000 --- a/packages/slate-schema/tsconfig.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "../../config/typescript/tsconfig.json", - "compilerOptions": { - "rootDir": "./src", - "outDir": "./lib", - "composite": true - }, - "references": [] -} diff --git a/packages/slate/src/interfaces/element.ts b/packages/slate/src/interfaces/element.ts index dadefc24cd..b63c9b4281 100755 --- a/packages/slate/src/interfaces/element.ts +++ b/packages/slate/src/interfaces/element.ts @@ -4,7 +4,7 @@ import { Editor, Node, Path } from '..' /** * `Element` objects are a type of node in a Slate document that contain other * element nodes or text nodes. They can be either "blocks" or "inlines" - * depending on the Slate editor's schema. + * depending on the Slate editor's configuration. */ export interface Element { diff --git a/packages/slate/test/normalization/block/remove-block.js b/packages/slate/test/normalization/block/remove-block.js index 6af0d8c99e..4fcf023655 100644 --- a/packages/slate/test/normalization/block/remove-block.js +++ b/packages/slate/test/normalization/block/remove-block.js @@ -2,8 +2,6 @@ import { jsx } from '../..' -export const schema = {} - export const input = ( diff --git a/packages/slate/test/normalization/inline/remove-block.js b/packages/slate/test/normalization/inline/remove-block.js index fd8035804b..67ec40cfa5 100644 --- a/packages/slate/test/normalization/inline/remove-block.js +++ b/packages/slate/test/normalization/inline/remove-block.js @@ -2,8 +2,6 @@ import { jsx } from '../..' -export const schema = {} - export const input = ( diff --git a/packages/slate/test/normalization/text/merge-adjacent-empty.js b/packages/slate/test/normalization/text/merge-adjacent-empty.js index 61c15c5a39..e878b119cf 100644 --- a/packages/slate/test/normalization/text/merge-adjacent-empty.js +++ b/packages/slate/test/normalization/text/merge-adjacent-empty.js @@ -2,8 +2,6 @@ import { jsx } from '../..' -export const schema = {} - export const input = ( diff --git a/packages/slate/test/normalization/text/merge-adjacent-match-empty.js b/packages/slate/test/normalization/text/merge-adjacent-match-empty.js index 035a189b74..e9d67895ca 100644 --- a/packages/slate/test/normalization/text/merge-adjacent-match-empty.js +++ b/packages/slate/test/normalization/text/merge-adjacent-match-empty.js @@ -2,8 +2,6 @@ import { jsx } from '../..' -export const schema = {} - export const input = ( diff --git a/packages/slate/test/normalization/text/merge-adjacent-match.js b/packages/slate/test/normalization/text/merge-adjacent-match.js index ca381551fa..f51237283d 100644 --- a/packages/slate/test/normalization/text/merge-adjacent-match.js +++ b/packages/slate/test/normalization/text/merge-adjacent-match.js @@ -2,8 +2,6 @@ import { jsx } from '../..' -export const schema = {} - export const input = ( diff --git a/site/examples/Readme.md b/site/examples/Readme.md index a4d821d54b..9dd8ccac2b 100644 --- a/site/examples/Readme.md +++ b/site/examples/Readme.md @@ -4,7 +4,7 @@ This directory contains a set of examples that give you an idea for how you migh - [**Plain text**](./plaintext.js) — showing the most basic case: a glorified `