diff --git a/docs/Readme.md b/docs/Readme.md index 024458432..773c95958 100644 --- a/docs/Readme.md +++ b/docs/Readme.md @@ -31,7 +31,6 @@ * [Block](./reference/slate/block.md) * [Change](./reference/slate/change.md) -* [Character](./reference/slate/character.md) * [Data](./reference/slate/data.md) * [Document](./reference/slate/document.md) * [Inline](./reference/slate/inline.md) diff --git a/docs/reference/slate-prop-types/index.md b/docs/reference/slate-prop-types/index.md index 61c6c4b92..23a567f0e 100644 --- a/docs/reference/slate-prop-types/index.md +++ b/docs/reference/slate-prop-types/index.md @@ -39,14 +39,6 @@ Ensure that a value is an immutable `List` of Slate [`Block`](../slate/block.md) Ensure that a value is a Slate `Change`. -### `character` - -Ensure that a value is a Slate `Character`. - -### `characters` - -Ensure that a value is an immutable `List` of Slate [`Character`](../slate/character.md) objects. - ### `data` Ensure that a value is a Slate `Data`. diff --git a/docs/reference/slate/character.md b/docs/reference/slate/character.md deleted file mode 100644 index c110a6f01..000000000 --- a/docs/reference/slate/character.md +++ /dev/null @@ -1,70 +0,0 @@ -# `Character` - -```js -import { Character } from 'slate' -``` - -A character in a [`Text`](./text.md) node. - -Characters are how Slate associates [`Marks`](./mark.md) with a range of text, for formatting. - -## Properties - -```js -Character({ - marks: Immutable.Set, - text: String -}) -``` - -### `object` - -`String` - -A string with a value of `'character'`. - -### `marks` - -`Immutable.Set` - -A set of [`Marks`](./mark.md) attached to the character. - -### `text` - -`String` - -The text string of the character. - -## Static Methods - -### `Character.create` - -`Character.create(properties: Object) => Character` - -Create a character from a plain Javascript object of `properties`. - -### `Character.createList` - -`Character.createList(array: Array) => List` - -Create a list of characters from a plain Javascript `array`. - -### `Character.fromJSON` - -`Character.fromJSON(object: Object) => Character` - -Create a character from a JSON `object`. - -### `Character.isCharacter` - -`Character.isCharacter(maybeCharacter: Any) => Boolean` - -Returns a boolean if the passed in argument is a `Character`. - -## Instance Methods - -### `toJSON` - -`toJSON() => Object` - -Returns a JSON representation of the character. diff --git a/docs/reference/slate/mark.md b/docs/reference/slate/mark.md index 254289a62..f12b5c4b6 100644 --- a/docs/reference/slate/mark.md +++ b/docs/reference/slate/mark.md @@ -4,7 +4,7 @@ import { Mark } from 'slate' ``` -A formatting mark that can be associated with [`Characters`](./character.md). Marks are how Slate represents rich formatting like **bold** or _italic_. +A formatting mark that can be associated with characters. Marks are how Slate represents rich formatting like **bold** or _italic_. ## Properties diff --git a/docs/reference/slate/node.md b/docs/reference/slate/node.md index 894212378..7d262cf7c 100644 --- a/docs/reference/slate/node.md +++ b/docs/reference/slate/node.md @@ -73,18 +73,6 @@ Get all of the bottom-most [`Block`](./block.md) nodes in a `range`. Get all of the bottom-most [`Block`](./block.md) nodes by `type`. -### `getCharacters` - -`getCharacters() => List` - -Get a list of all of the [`Characters`](./character.md) in the node. - -### `getCharactersAtRange` - -`getCharactersAtRange(range: Range) => List` - -Get a list of all of the [`Characters`](./character.md) in a `range`. - ### `getChild` `getChild(path: List|Array) => Node|Void` diff --git a/docs/reference/slate/text.md b/docs/reference/slate/text.md index 3028a3bdc..7887d13af 100644 --- a/docs/reference/slate/text.md +++ b/docs/reference/slate/text.md @@ -10,15 +10,10 @@ A text node in a Slate [`Document`](./document.md). Text nodes are always the bo ```js Text({ - characters: Immutable.List, - key: String + key: String, }) ``` -### `characters` - -A list of [`Characters`](./character.md) with associated [`Marks`](./mark.md) that make up the text node's content. - ### `key` `String` diff --git a/docs/reference/slate/value.md b/docs/reference/slate/value.md index 837394a68..a3b1afbe9 100644 --- a/docs/reference/slate/value.md +++ b/docs/reference/slate/value.md @@ -117,12 +117,6 @@ Get a list of the lowest-depth [`Inline`](./inline.md) nodes in the current sele Get a list of the [`Text`](./text.md) nodes in the current selection. -### `characters` - -`List` - -Get a list of the [`Character`](./character.md) objects in the current selection. - ### `hasUndos` `Boolean` diff --git a/packages/slate-prop-types/src/index.js b/packages/slate-prop-types/src/index.js index 78f5208cb..ae4f83b00 100644 --- a/packages/slate-prop-types/src/index.js +++ b/packages/slate-prop-types/src/index.js @@ -1,7 +1,6 @@ import { Block, Change, - Character, Data, Document, History, @@ -59,8 +58,6 @@ const Types = { block: create('Block', v => Block.isBlock(v)), blocks: create('List', v => Block.isBlockList(v)), change: create('Change', v => Change.isChange(v)), - character: create('Character', v => Character.isCharacter(v)), - characters: create('List', v => Character.isCharacterList(v)), data: create('Data', v => Data.isData(v)), document: create('Document', v => Document.isDocument(v)), history: create('History', v => History.isHistory(v)), diff --git a/packages/slate/src/constants/model-types.js b/packages/slate/src/constants/model-types.js index e031b8f70..c401ac2db 100644 --- a/packages/slate/src/constants/model-types.js +++ b/packages/slate/src/constants/model-types.js @@ -7,7 +7,6 @@ const MODEL_TYPES = { BLOCK: '@@__SLATE_BLOCK__@@', CHANGE: '@@__SLATE_CHANGE__@@', - CHARACTER: '@@__SLATE_CHARACTER__@@', DOCUMENT: '@@__SLATE_DOCUMENT__@@', HISTORY: '@@__SLATE_HISTORY__@@', INLINE: '@@__SLATE_INLINE__@@', diff --git a/packages/slate/src/index.js b/packages/slate/src/index.js index d858c18c6..92cb99169 100644 --- a/packages/slate/src/index.js +++ b/packages/slate/src/index.js @@ -1,7 +1,6 @@ import Block from './models/block' import Change from './models/change' import Changes from './changes' -import Character from './models/character' import Data from './models/data' import Document from './models/document' import History from './models/history' @@ -33,7 +32,6 @@ export { Block, Change, Changes, - Character, Data, Document, History, @@ -61,7 +59,6 @@ export { export default { Block, Changes, - Character, Data, Document, History, diff --git a/packages/slate/src/models/character.js b/packages/slate/src/models/character.js deleted file mode 100644 index 368adc563..000000000 --- a/packages/slate/src/models/character.js +++ /dev/null @@ -1,175 +0,0 @@ -import isPlainObject from 'is-plain-object' -import logger from 'slate-dev-logger' -import { List, Record, Set } from 'immutable' - -import MODEL_TYPES, { isType } from '../constants/model-types' - -/** - * Default properties. - * - * @type {Object} - */ - -const DEFAULTS = { - marks: new Set(), - text: '', -} - -/** - * Character. - * - * @type {Character} - */ - -class Character extends Record(DEFAULTS) { - /** - * Create a `Character` with `attrs`. - * - * @param {Object|String|Character} attrs - * @return {Character} - */ - - static create(attrs = {}) { - if (Character.isCharacter(attrs)) { - return attrs - } - - if (typeof attrs == 'string') { - attrs = { text: attrs } - } - - if (isPlainObject(attrs)) { - return Character.fromJSON(attrs) - } - - throw new Error( - `\`Character.create\` only accepts objects, strings or characters, but you passed it: ${attrs}` - ) - } - - /** - * Create a list of `Characters` from `elements`. - * - * @param {String|Array|List} elements - * @return {List} - */ - - static createList(elements = []) { - if (typeof elements == 'string') { - elements = elements.split('') - } - - if (List.isList(elements) || Array.isArray(elements)) { - const list = new List(elements.map(Character.create)) - return list - } - - throw new Error( - `\`Block.createList\` only accepts strings, arrays or lists, but you passed it: ${elements}` - ) - } - - /** - * Create a `Character` from a JSON `object`. - * - * @param {Object} object - * @return {Character} - */ - - static fromJSON(object) { - const { text, marks = [] } = object - - if (typeof text != 'string') { - throw new Error('`Character.fromJSON` requires a block `text` string.') - } - - const character = new Character({ - text, - marks: new Set(marks), - }) - - return character - } - - /** - * Alias `fromJS`. - */ - - static fromJS = Character.fromJSON - - /** - * Check if `any` is a `Character`. - * - * @param {Any} any - * @return {Boolean} - */ - - static isCharacter = isType.bind(null, 'CHARACTER') - - /** - * Check if `any` is a character list. - * - * @param {Any} any - * @return {Boolean} - */ - - static isCharacterList(any) { - return List.isList(any) && any.every(item => Character.isCharacter(item)) - } - - /** - * Object. - * - * @return {String} - */ - - get object() { - return 'character' - } - - get kind() { - logger.deprecate( - 'slate@0.32.0', - 'The `kind` property of Slate objects has been renamed to `object`.' - ) - return this.object - } - - /** - * Return a JSON representation of the character. - * - * @return {Object} - */ - - toJSON() { - const object = { - object: this.object, - text: this.text, - marks: this.marks.toArray().map(m => m.toJSON()), - } - - return object - } - - /** - * Alias `toJS`. - */ - - toJS() { - return this.toJSON() - } -} - -/** - * Attach a pseudo-symbol for type checking. - */ - -Character.prototype[MODEL_TYPES.CHARACTER] = true - -/** - * Export. - * - * @type {Character} - */ - -export default Character diff --git a/packages/slate/src/models/leaf.js b/packages/slate/src/models/leaf.js index e6e371da7..14f149b1f 100644 --- a/packages/slate/src/models/leaf.js +++ b/packages/slate/src/models/leaf.js @@ -3,7 +3,6 @@ import logger from 'slate-dev-logger' import { List, Record, Set } from 'immutable' import MODEL_TYPES, { isType } from '../constants/model-types' -import Character from './character' import Mark from './mark' /** @@ -238,31 +237,6 @@ class Leaf extends Record(DEFAULTS) { return this.object } - /** - * Return leaf as a list of characters - * - * @return {List} - */ - - getCharacters() { - logger.deprecate( - 'slate@0.34.0', - 'The `characters` property of Slate objects is deprecated' - ) - - const { marks } = this - const characters = Character.createList( - this.text.split('').map(char => { - return Character.create({ - text: char, - marks, - }) - }) - ) - - return characters - } - /** * Update a `mark` at leaf, replace with newMark * diff --git a/packages/slate/src/models/node.js b/packages/slate/src/models/node.js index b72ec63a8..c8aac64bf 100644 --- a/packages/slate/src/models/node.js +++ b/packages/slate/src/models/node.js @@ -207,7 +207,6 @@ class Node { } /** -<<<<<<< HEAD * Create a point with `properties` relative to the node. * * @param {Object|Point} properties @@ -222,9 +221,6 @@ class Node { /** * Create a range with `properties` relative to the node. -======= - * Create a new range with `properties` relative to the node. ->>>>>>> master * * @param {Object|Range} properties * @return {Range} @@ -481,47 +477,6 @@ class Node { }, []) } - /** - * Get all of the characters for every text node. - * - * @return {List} - */ - - getCharacters() { - const characters = this.getTexts().flatMap(t => t.characters) - return characters - } - - /** - * Get a list of the characters in a `range`. - * - * @param {Range} range - * @return {List} - */ - - getCharactersAtRange(range) { - range = this.resolveRange(range) - if (range.isUnset) return List() - - const { start, end } = range - - if (start.key === end.key) { - const endText = this.getDescendant(end.key) - return endText.characters.slice(start.offset, end.offset) - } - - return this.getTextsAtRange(range).flatMap(t => { - if (t.key === start.key) { - return t.characters.slice(start.offset) - } - - if (t.key === end.key) { - return t.characters.slice(0, end.offset) - } - return t.characters - }) - } - /** * Get a child node. * @@ -2032,7 +1987,6 @@ class Node { } /** -<<<<<<< HEAD * Resolve a `point`, relative to the node, ensuring that the keys and * offsets in the point exist and that they are synced with the paths. * @@ -2047,8 +2001,6 @@ class Node { } /** -======= ->>>>>>> master * Resolve a `range`, relative to the node, ensuring that the keys and * offsets in the range exist and that they are synced with the paths. * diff --git a/packages/slate/src/models/text.js b/packages/slate/src/models/text.js index 4164773ed..2d97aa97a 100644 --- a/packages/slate/src/models/text.js +++ b/packages/slate/src/models/text.js @@ -191,16 +191,6 @@ class Text extends Record(DEFAULTS) { return this.leaves.reduce((string, leaf) => string + leaf.text, '') } - /** - * Get the concatenated characters of the node; - * - * @returns {String} - */ - - get characters() { - return this.leaves.flatMap(x => x.getCharacters()) - } - /** * Find the 'first' leaf at offset; By 'first' the alorighthm prefers `endOffset === offset` than `startOffset === offset` * Corner Cases: diff --git a/packages/slate/src/models/value.js b/packages/slate/src/models/value.js index eed1fe8f0..a09b20137 100644 --- a/packages/slate/src/models/value.js +++ b/packages/slate/src/models/value.js @@ -448,18 +448,6 @@ class Value extends Record(DEFAULTS) { ) } - /** - * Get the characters in the current selection. - * - * @return {List} - */ - - get characters() { - return this.selection.isUnset - ? new List() - : this.document.getCharactersAtRange(this.selection) - } - /** * Get the marks of the current selection. *