diff --git a/docs/concepts/01-interfaces.md b/docs/concepts/01-interfaces.md index bc3d1ccec..e77443cfc 100644 --- a/docs/concepts/01-interfaces.md +++ b/docs/concepts/01-interfaces.md @@ -60,8 +60,8 @@ For example, when working with nodes: ```js import { Node } from 'slate' -// Get the text content of an element node. -const text = Node.text(element) +// Get the string content of an element node. +const string = Node.string(element) // Get the node at a specific path inside a root node. const descendant = Node.get(value, path) diff --git a/docs/concepts/09-serializing.md b/docs/concepts/09-serializing.md index 733b9fdad..2050754ba 100644 --- a/docs/concepts/09-serializing.md +++ b/docs/concepts/09-serializing.md @@ -12,7 +12,7 @@ For example, taking the value of an editor and returning plaintext: import { Node } from 'slate' const serialize = nodes => { - return nodes.map(n => Node.text(n)).join('\n') + return nodes.map(n => Node.string(n)).join('\n') } ``` diff --git a/docs/walkthroughs/06-saving-to-a-database.md b/docs/walkthroughs/06-saving-to-a-database.md index ba90334b4..52712f390 100644 --- a/docs/walkthroughs/06-saving-to-a-database.md +++ b/docs/walkthroughs/06-saving-to-a-database.md @@ -116,8 +116,8 @@ import { Node } from 'slate' const serialize = value => { return ( value - // Return the text content of each paragraph in the value's children. - .map(n => Node.text(n)) + // Return the string content of each paragraph in the value's children. + .map(n => Node.string(n)) // Join them all with line breaks denoting paragraphs. .join('\n') ) diff --git a/packages/slate-react/src/components/editable.tsx b/packages/slate-react/src/components/editable.tsx index 87e647998..84dd2ec3a 100644 --- a/packages/slate-react/src/components/editable.tsx +++ b/packages/slate-react/src/components/editable.tsx @@ -393,7 +393,7 @@ export const Editable = (props: EditableProps) => { placeholder && editor.children.length === 1 && Array.from(Node.texts(editor)).length === 1 && - Node.text(editor) === '' + Node.string(editor) === '' ) { const start = Editor.start(editor, []) decorations.push({ diff --git a/packages/slate-react/src/components/element.tsx b/packages/slate-react/src/components/element.tsx index 5a17cf3ad..bbbc27fdb 100644 --- a/packages/slate-react/src/components/element.tsx +++ b/packages/slate-react/src/components/element.tsx @@ -74,7 +74,7 @@ const Element = (props: { // If it's a block node with inline children, add the proper `dir` attribute // for text direction. if (!isInline && Editor.hasInlines(editor, element)) { - const text = Node.text(element) + const text = Node.string(element) const dir = getDirection(text) if (dir === 'rtl') { diff --git a/packages/slate-react/src/components/string.tsx b/packages/slate-react/src/components/string.tsx index b28edfdba..307ec39a8 100644 --- a/packages/slate-react/src/components/string.tsx +++ b/packages/slate-react/src/components/string.tsx @@ -21,7 +21,7 @@ const String = (props: { // COMPAT: Render text inside void nodes with a zero-width space. // So the node can contain selection but the text is not visible. if (editor.isVoid(parent)) { - return + return } // COMPAT: If this is the last text node in an empty block, render a zero- @@ -31,7 +31,7 @@ const String = (props: { leaf.text === '' && parent.children[parent.children.length - 1] === text && !editor.isInline(parent) && - Editor.text(editor, parentPath) === '' + Editor.string(editor, parentPath) === '' ) { return } diff --git a/packages/slate/src/interfaces/editor/queries/location.ts b/packages/slate/src/interfaces/editor/queries/location.ts index 5e99a1385..a00254b2f 100644 --- a/packages/slate/src/interfaces/editor/queries/location.ts +++ b/packages/slate/src/interfaces/editor/queries/location.ts @@ -620,7 +620,7 @@ export const LocationQueries = { ? start : Editor.start(editor, path) - const text = Editor.text(editor, { anchor: s, focus: e }) + const text = Editor.string(editor, { anchor: s, focus: e }) string = reverse ? reverseText(text) : text isNewBlock = true } @@ -733,13 +733,13 @@ export const LocationQueries = { }, /** - * Get the text content of a location. + * Get the text string content of a location. * * Note: the text of void nodes is presumed to be an empty string, regardless * of what their actual content is. */ - text(editor: Editor, at: Location): string { + string(editor: Editor, at: Location): string { const range = Editor.range(editor, at) const [start, end] = Range.edges(range) let text = '' diff --git a/packages/slate/src/interfaces/node.ts b/packages/slate/src/interfaces/node.ts index ccdbac64d..e6b754814 100755 --- a/packages/slate/src/interfaces/node.ts +++ b/packages/slate/src/interfaces/node.ts @@ -464,11 +464,11 @@ export const Node = { * computations for a node. */ - text(node: Node): string { + string(node: Node): string { if (Text.isText(node)) { return node.text } else { - return node.children.map(Node.text).join('') + return node.children.map(Node.string).join('') } }, diff --git a/packages/slate/test/interfaces/Node/text/across-elements.js b/packages/slate/test/interfaces/Node/string/across-elements.js similarity index 92% rename from packages/slate/test/interfaces/Node/text/across-elements.js rename to packages/slate/test/interfaces/Node/string/across-elements.js index 314260e40..30f63c361 100644 --- a/packages/slate/test/interfaces/Node/text/across-elements.js +++ b/packages/slate/test/interfaces/Node/string/across-elements.js @@ -17,7 +17,7 @@ export const input = ( ) export const test = value => { - return Node.text(value) + return Node.string(value) } export const output = `onetwothreefour` diff --git a/packages/slate/test/interfaces/Node/text/element.js b/packages/slate/test/interfaces/Node/string/element.js similarity index 88% rename from packages/slate/test/interfaces/Node/text/element.js rename to packages/slate/test/interfaces/Node/string/element.js index 7a39e4c39..3fbf4c362 100644 --- a/packages/slate/test/interfaces/Node/text/element.js +++ b/packages/slate/test/interfaces/Node/string/element.js @@ -11,7 +11,7 @@ export const input = ( ) export const test = value => { - return Node.text(value, [1]) + return Node.string(value, [1]) } export const output = `onetwo` diff --git a/packages/slate/test/interfaces/Node/text/text.js b/packages/slate/test/interfaces/Node/string/text.js similarity index 87% rename from packages/slate/test/interfaces/Node/text/text.js rename to packages/slate/test/interfaces/Node/string/text.js index 7505d7162..a2000f132 100644 --- a/packages/slate/test/interfaces/Node/text/text.js +++ b/packages/slate/test/interfaces/Node/string/text.js @@ -6,7 +6,7 @@ import { jsx } from 'slate-hyperscript' export const input = one export const test = value => { - return Node.text(value) + return Node.string(value) } export const output = `one` diff --git a/packages/slate/test/queries/text/block-across.js b/packages/slate/test/queries/string/block-across.js similarity index 90% rename from packages/slate/test/queries/text/block-across.js rename to packages/slate/test/queries/string/block-across.js index d16859837..293ea0a31 100644 --- a/packages/slate/test/queries/text/block-across.js +++ b/packages/slate/test/queries/string/block-across.js @@ -17,7 +17,7 @@ export const input = ( ) export const run = editor => { - return Editor.text(editor, []) + return Editor.string(editor, []) } export const output = `onetwothreefour` diff --git a/packages/slate/test/queries/text/block-void.js b/packages/slate/test/queries/string/block-void.js similarity index 87% rename from packages/slate/test/queries/text/block-void.js rename to packages/slate/test/queries/string/block-void.js index 338d15aaf..5fbe9ee70 100644 --- a/packages/slate/test/queries/text/block-void.js +++ b/packages/slate/test/queries/string/block-void.js @@ -13,7 +13,7 @@ export const input = ( ) export const run = editor => { - return Editor.text(editor, [0]) + return Editor.string(editor, [0]) } export const output = `` diff --git a/packages/slate/test/queries/text/block.js b/packages/slate/test/queries/string/block.js similarity index 90% rename from packages/slate/test/queries/text/block.js rename to packages/slate/test/queries/string/block.js index 30347ec23..cd1a0f7e2 100644 --- a/packages/slate/test/queries/text/block.js +++ b/packages/slate/test/queries/string/block.js @@ -17,7 +17,7 @@ export const input = ( ) export const run = editor => { - return Editor.text(editor, [0]) + return Editor.string(editor, [0]) } export const output = `onetwo` diff --git a/packages/slate/test/queries/text/inline.js b/packages/slate/test/queries/string/inline.js similarity index 86% rename from packages/slate/test/queries/text/inline.js rename to packages/slate/test/queries/string/inline.js index 818e2e831..8707bdd15 100644 --- a/packages/slate/test/queries/text/inline.js +++ b/packages/slate/test/queries/string/inline.js @@ -12,7 +12,7 @@ export const input = ( ) export const run = editor => { - return Editor.text(editor, [0, 1]) + return Editor.string(editor, [0, 1]) } export const output = `two` diff --git a/packages/slate/test/queries/text/text.js b/packages/slate/test/queries/string/text.js similarity index 86% rename from packages/slate/test/queries/text/text.js rename to packages/slate/test/queries/string/text.js index fcc333524..79aaa402c 100644 --- a/packages/slate/test/queries/text/text.js +++ b/packages/slate/test/queries/string/text.js @@ -13,7 +13,7 @@ export const input = ( ) export const run = editor => { - return Editor.text(editor, [0, 0]) + return Editor.string(editor, [0, 0]) } export const output = `one` diff --git a/site/examples/hovering-toolbar.js b/site/examples/hovering-toolbar.js index ddecbfc4d..b65c0e96c 100644 --- a/site/examples/hovering-toolbar.js +++ b/site/examples/hovering-toolbar.js @@ -104,7 +104,7 @@ const HoveringToolbar = () => { !selection || !ReactEditor.isFocused(editor) || Range.isCollapsed(selection) || - Editor.text(editor, selection) === '' + Editor.string(editor, selection) === '' ) { el.removeAttribute('style') return diff --git a/site/examples/markdown-shortcuts.js b/site/examples/markdown-shortcuts.js index 6ca251588..21229afa1 100644 --- a/site/examples/markdown-shortcuts.js +++ b/site/examples/markdown-shortcuts.js @@ -54,7 +54,7 @@ const withShortcuts = editor => { const path = block ? block[1] : [] const start = Editor.start(editor, path) const range = { anchor, focus: start } - const beforeText = Editor.text(editor, range) + const beforeText = Editor.string(editor, range) const type = SHORTCUTS[beforeText] if (type) { diff --git a/site/examples/mentions.js b/site/examples/mentions.js index 129604077..b96cd062f 100644 --- a/site/examples/mentions.js +++ b/site/examples/mentions.js @@ -81,11 +81,11 @@ const MentionExample = () => { const wordBefore = Editor.before(editor, start, { unit: 'word' }) const before = wordBefore && Editor.before(editor, wordBefore) const beforeRange = before && Editor.range(editor, before, start) - const beforeText = beforeRange && Editor.text(editor, beforeRange) + const beforeText = beforeRange && Editor.string(editor, beforeRange) const beforeMatch = beforeText && beforeText.match(/^@(\w+)$/) const after = Editor.after(editor, start) const afterRange = Editor.range(editor, start, after) - const afterText = Editor.text(editor, afterRange) + const afterText = Editor.string(editor, afterRange) const afterMatch = afterText.match(/^(\s|$)/) if (beforeMatch && afterMatch) {