mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-14 11:14:04 +02:00
rename Node.text
to Node.string
(#3341)
This commit is contained in:
@@ -60,8 +60,8 @@ For example, when working with nodes:
|
|||||||
```js
|
```js
|
||||||
import { Node } from 'slate'
|
import { Node } from 'slate'
|
||||||
|
|
||||||
// Get the text content of an element node.
|
// Get the string content of an element node.
|
||||||
const text = Node.text(element)
|
const string = Node.string(element)
|
||||||
|
|
||||||
// Get the node at a specific path inside a root node.
|
// Get the node at a specific path inside a root node.
|
||||||
const descendant = Node.get(value, path)
|
const descendant = Node.get(value, path)
|
||||||
|
@@ -12,7 +12,7 @@ For example, taking the value of an editor and returning plaintext:
|
|||||||
import { Node } from 'slate'
|
import { Node } from 'slate'
|
||||||
|
|
||||||
const serialize = nodes => {
|
const serialize = nodes => {
|
||||||
return nodes.map(n => Node.text(n)).join('\n')
|
return nodes.map(n => Node.string(n)).join('\n')
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@@ -116,8 +116,8 @@ import { Node } from 'slate'
|
|||||||
const serialize = value => {
|
const serialize = value => {
|
||||||
return (
|
return (
|
||||||
value
|
value
|
||||||
// Return the text content of each paragraph in the value's children.
|
// Return the string content of each paragraph in the value's children.
|
||||||
.map(n => Node.text(n))
|
.map(n => Node.string(n))
|
||||||
// Join them all with line breaks denoting paragraphs.
|
// Join them all with line breaks denoting paragraphs.
|
||||||
.join('\n')
|
.join('\n')
|
||||||
)
|
)
|
||||||
|
@@ -393,7 +393,7 @@ export const Editable = (props: EditableProps) => {
|
|||||||
placeholder &&
|
placeholder &&
|
||||||
editor.children.length === 1 &&
|
editor.children.length === 1 &&
|
||||||
Array.from(Node.texts(editor)).length === 1 &&
|
Array.from(Node.texts(editor)).length === 1 &&
|
||||||
Node.text(editor) === ''
|
Node.string(editor) === ''
|
||||||
) {
|
) {
|
||||||
const start = Editor.start(editor, [])
|
const start = Editor.start(editor, [])
|
||||||
decorations.push({
|
decorations.push({
|
||||||
|
@@ -74,7 +74,7 @@ const Element = (props: {
|
|||||||
// If it's a block node with inline children, add the proper `dir` attribute
|
// If it's a block node with inline children, add the proper `dir` attribute
|
||||||
// for text direction.
|
// for text direction.
|
||||||
if (!isInline && Editor.hasInlines(editor, element)) {
|
if (!isInline && Editor.hasInlines(editor, element)) {
|
||||||
const text = Node.text(element)
|
const text = Node.string(element)
|
||||||
const dir = getDirection(text)
|
const dir = getDirection(text)
|
||||||
|
|
||||||
if (dir === 'rtl') {
|
if (dir === 'rtl') {
|
||||||
|
@@ -21,7 +21,7 @@ const String = (props: {
|
|||||||
// COMPAT: Render text inside void nodes with a zero-width space.
|
// COMPAT: Render text inside void nodes with a zero-width space.
|
||||||
// So the node can contain selection but the text is not visible.
|
// So the node can contain selection but the text is not visible.
|
||||||
if (editor.isVoid(parent)) {
|
if (editor.isVoid(parent)) {
|
||||||
return <ZeroWidthString length={Node.text(parent).length} />
|
return <ZeroWidthString length={Node.string(parent).length} />
|
||||||
}
|
}
|
||||||
|
|
||||||
// COMPAT: If this is the last text node in an empty block, render a zero-
|
// COMPAT: If this is the last text node in an empty block, render a zero-
|
||||||
@@ -31,7 +31,7 @@ const String = (props: {
|
|||||||
leaf.text === '' &&
|
leaf.text === '' &&
|
||||||
parent.children[parent.children.length - 1] === text &&
|
parent.children[parent.children.length - 1] === text &&
|
||||||
!editor.isInline(parent) &&
|
!editor.isInline(parent) &&
|
||||||
Editor.text(editor, parentPath) === ''
|
Editor.string(editor, parentPath) === ''
|
||||||
) {
|
) {
|
||||||
return <ZeroWidthString isLineBreak />
|
return <ZeroWidthString isLineBreak />
|
||||||
}
|
}
|
||||||
|
@@ -620,7 +620,7 @@ export const LocationQueries = {
|
|||||||
? start
|
? start
|
||||||
: Editor.start(editor, path)
|
: 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
|
string = reverse ? reverseText(text) : text
|
||||||
isNewBlock = true
|
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
|
* Note: the text of void nodes is presumed to be an empty string, regardless
|
||||||
* of what their actual content is.
|
* 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 range = Editor.range(editor, at)
|
||||||
const [start, end] = Range.edges(range)
|
const [start, end] = Range.edges(range)
|
||||||
let text = ''
|
let text = ''
|
||||||
|
@@ -464,11 +464,11 @@ export const Node = {
|
|||||||
* computations for a node.
|
* computations for a node.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
text(node: Node): string {
|
string(node: Node): string {
|
||||||
if (Text.isText(node)) {
|
if (Text.isText(node)) {
|
||||||
return node.text
|
return node.text
|
||||||
} else {
|
} else {
|
||||||
return node.children.map(Node.text).join('')
|
return node.children.map(Node.string).join('')
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@@ -17,7 +17,7 @@ export const input = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
export const test = value => {
|
export const test = value => {
|
||||||
return Node.text(value)
|
return Node.string(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const output = `onetwothreefour`
|
export const output = `onetwothreefour`
|
@@ -11,7 +11,7 @@ export const input = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
export const test = value => {
|
export const test = value => {
|
||||||
return Node.text(value, [1])
|
return Node.string(value, [1])
|
||||||
}
|
}
|
||||||
|
|
||||||
export const output = `onetwo`
|
export const output = `onetwo`
|
@@ -6,7 +6,7 @@ import { jsx } from 'slate-hyperscript'
|
|||||||
export const input = <text>one</text>
|
export const input = <text>one</text>
|
||||||
|
|
||||||
export const test = value => {
|
export const test = value => {
|
||||||
return Node.text(value)
|
return Node.string(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const output = `one`
|
export const output = `one`
|
@@ -17,7 +17,7 @@ export const input = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
export const run = editor => {
|
export const run = editor => {
|
||||||
return Editor.text(editor, [])
|
return Editor.string(editor, [])
|
||||||
}
|
}
|
||||||
|
|
||||||
export const output = `onetwothreefour`
|
export const output = `onetwothreefour`
|
@@ -13,7 +13,7 @@ export const input = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
export const run = editor => {
|
export const run = editor => {
|
||||||
return Editor.text(editor, [0])
|
return Editor.string(editor, [0])
|
||||||
}
|
}
|
||||||
|
|
||||||
export const output = ``
|
export const output = ``
|
@@ -17,7 +17,7 @@ export const input = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
export const run = editor => {
|
export const run = editor => {
|
||||||
return Editor.text(editor, [0])
|
return Editor.string(editor, [0])
|
||||||
}
|
}
|
||||||
|
|
||||||
export const output = `onetwo`
|
export const output = `onetwo`
|
@@ -12,7 +12,7 @@ export const input = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
export const run = editor => {
|
export const run = editor => {
|
||||||
return Editor.text(editor, [0, 1])
|
return Editor.string(editor, [0, 1])
|
||||||
}
|
}
|
||||||
|
|
||||||
export const output = `two`
|
export const output = `two`
|
@@ -13,7 +13,7 @@ export const input = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
export const run = editor => {
|
export const run = editor => {
|
||||||
return Editor.text(editor, [0, 0])
|
return Editor.string(editor, [0, 0])
|
||||||
}
|
}
|
||||||
|
|
||||||
export const output = `one`
|
export const output = `one`
|
@@ -104,7 +104,7 @@ const HoveringToolbar = () => {
|
|||||||
!selection ||
|
!selection ||
|
||||||
!ReactEditor.isFocused(editor) ||
|
!ReactEditor.isFocused(editor) ||
|
||||||
Range.isCollapsed(selection) ||
|
Range.isCollapsed(selection) ||
|
||||||
Editor.text(editor, selection) === ''
|
Editor.string(editor, selection) === ''
|
||||||
) {
|
) {
|
||||||
el.removeAttribute('style')
|
el.removeAttribute('style')
|
||||||
return
|
return
|
||||||
|
@@ -54,7 +54,7 @@ const withShortcuts = editor => {
|
|||||||
const path = block ? block[1] : []
|
const path = block ? block[1] : []
|
||||||
const start = Editor.start(editor, path)
|
const start = Editor.start(editor, path)
|
||||||
const range = { anchor, focus: start }
|
const range = { anchor, focus: start }
|
||||||
const beforeText = Editor.text(editor, range)
|
const beforeText = Editor.string(editor, range)
|
||||||
const type = SHORTCUTS[beforeText]
|
const type = SHORTCUTS[beforeText]
|
||||||
|
|
||||||
if (type) {
|
if (type) {
|
||||||
|
@@ -81,11 +81,11 @@ const MentionExample = () => {
|
|||||||
const wordBefore = Editor.before(editor, start, { unit: 'word' })
|
const wordBefore = Editor.before(editor, start, { unit: 'word' })
|
||||||
const before = wordBefore && Editor.before(editor, wordBefore)
|
const before = wordBefore && Editor.before(editor, wordBefore)
|
||||||
const beforeRange = before && Editor.range(editor, before, start)
|
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 beforeMatch = beforeText && beforeText.match(/^@(\w+)$/)
|
||||||
const after = Editor.after(editor, start)
|
const after = Editor.after(editor, start)
|
||||||
const afterRange = Editor.range(editor, start, after)
|
const afterRange = Editor.range(editor, start, after)
|
||||||
const afterText = Editor.text(editor, afterRange)
|
const afterText = Editor.string(editor, afterRange)
|
||||||
const afterMatch = afterText.match(/^(\s|$)/)
|
const afterMatch = afterText.match(/^(\s|$)/)
|
||||||
|
|
||||||
if (beforeMatch && afterMatch) {
|
if (beforeMatch && afterMatch) {
|
||||||
|
Reference in New Issue
Block a user