mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-01-19 14:27:07 +01:00
Use strict equality except for null/undefined for improved performance and behavior (#2514)
* Convert Non-strict to strict equality checking Convert non-strict equality checking, using `==`, to the strict version, using `===`. * Convert Non-strict to strict equality checking Convert non-strict equality checking, using `==`, to the strict version, using `===`. * Convert Non-strict to strict equality checking Convert non-strict equality checking, using `==`, to the strict version, using `===`. * Convert Non-strict to strict equality checking Convert non-strict equality checking, using `==`, to the strict version, using `===`. * Convert Non-strict to strict equality checking Convert non-strict equality checking, using `==`, to the strict version, using `===`. * Convert Non-strict to strict equality checking Convert non-strict equality checking, using `==`, to the strict version, using `===`. * Convert Non-strict to strict equality checking Convert non-strict equality checking, using `==`, to the strict version, using `===`. * Convert Non-strict to strict equality checking Convert non-strict equality checking, using `==`, to the strict version, using `===`. * Convert Non-strict to strict equality checking Convert non-strict equality checking, using `==`, to the strict version, using `===`. * Convert Non-strict to strict equality checking Convert non-strict equality checking, using `==`, to the strict version, using `===`. * Convert Non-strict to strict equality checking Convert non-strict equality checking, using `==`, to the strict version, using `===`. * Convert Non-strict to strict equality checking Convert non-strict equality checking, using `==`, to the strict version, using `===`. * Convert Non-strict to strict equality checking Convert non-strict equality checking, using `==`, to the strict version, using `===`. * Convert Non-strict to strict equality checking Convert non-strict equality checking, using `==`, to the strict version, using `===`. * Convert Non-strict to strict equality checking Convert non-strict equality checking, using `==`, to the strict version, using `===`. * Convert Non-strict to strict equality checking Convert non-strict equality checking, using `==`, to the strict version, using `===`. * Convert Non-strict to strict equality checking Convert non-strict equality checking, using `==`, to the strict version, using `===`. * Convert Non-strict to strict equality checking Convert non-strict equality checking, using `==`, to the strict version, using `===`. * Convert Non-strict to strict equality checking Convert non-strict equality checking, using `==`, to the strict version, using `===`. * Convert Non-strict to strict equality checking Convert non-strict equality checking, using `==`, to the strict version, using `===`. * Convert Non-strict to strict equality checking Convert non-strict equality checking, using `==`, to the strict version, using `===`. * Convert Non-strict to strict equality checking Convert non-strict equality checking, using `==`, to the strict version, using `===`. * Convert Non-strict to strict equality checking Convert non-strict equality checking, using `==`, to the strict version, using `===`. * Convert Non-strict to strict equality checking Convert non-strict equality checking, using `==`, to the strict version, using `===`. * Convert Non-strict to strict equality checking Convert non-strict equality checking, using `==`, to the strict version, using `===`. * Convert Non-strict to strict equality checking Convert non-strict equality checking, using `==`, to the strict version, using `===`. * Convert Non-strict to strict equality checking Convert non-strict equality checking, using `==`, to the strict version, using `===`. * Convert Non-strict to strict equality checking Convert non-strict equality checking, using `==`, to the strict version, using `===`. * Convert Non-strict to strict equality checking Convert non-strict equality checking, using `==`, to the strict version, using `===`. * Convert Non-strict to strict equality checking Convert non-strict equality checking, using `==`, to the strict version, using `===`. * Convert Non-strict to strict equality checking Convert non-strict equality checking, using `==`, to the strict version, using `===`. * Convert Non-strict to strict equality checking Convert non-strict equality checking, using `==`, to the strict version, using `===`. * Convert Non-strict to strict equality checking Convert non-strict equality checking, using `==`, to the strict version, using `===`. * Convert Non-strict to strict equality checking Convert non-strict equality checking, using `==`, to the strict version, using `===`. * Convert Non-strict to strict equality checking Convert non-strict equality checking, using `==`, to the strict version, using `===`. * Convert Non-strict to strict equality checking Convert non-strict equality checking, using `==`, to the strict version, using `===`. * Convert Non-strict to strict equality checking Convert non-strict equality checking, using `==`, to the strict version, using `===`. * Convert Non-strict to strict equality checking Convert non-strict equality checking, using `==`, to the strict version, using `===`. * Convert Non-strict to strict equality checking Convert non-strict equality checking, using `==`, to the strict version, using `===`. * Convert Non-strict to strict equality checking Convert non-strict equality checking, using `==`, to the strict version, using `===`. * undo strict null checking * remove added semicolons * Prettier Formatting Changes * Update .eslintrc add smart strict equality rule * Convert Non-strict to strict equality checking Convert non-strict equality checking, using `==`, to the strict version, using `===`. * Convert Non-strict to strict equality checking Convert non-strict equality checking, using `==`, to the strict version, using `===`. * Convert Non-strict to strict equality checking Convert non-strict equality checking, using `==`, to the strict version, using `===`. * Convert Non-strict to strict equality checking Convert non-strict equality checking, using `==`, to the strict version, using `===`. * Convert files to use strict equality * fix prettier eslint errors * fix remaining prettier complaints * use strict null equality in serializer
This commit is contained in:
parent
bd7ee85c9b
commit
3dce916074
@ -19,6 +19,7 @@
|
||||
"rules": {
|
||||
"constructor-super": "error",
|
||||
"dot-notation": ["error", { "allowKeywords": true }],
|
||||
"eqeqeq": ["error", "smart"],
|
||||
"import/default": "error",
|
||||
"import/export": "error",
|
||||
"import/first": "error",
|
||||
|
@ -7,7 +7,7 @@ const { include } = require('./config')
|
||||
const categoryDir = resolve(__dirname)
|
||||
|
||||
const categories = readdirSync(categoryDir).filter(
|
||||
c => c[0] != '.' && c.match(/^slate/)
|
||||
c => c[0] !== '.' && c.match(/^slate/)
|
||||
)
|
||||
|
||||
categories.forEach(dir => {
|
||||
|
@ -10,14 +10,14 @@ const { Suite, Bench } = require('slate-dev-benchmark')
|
||||
module.exports.run = function(include) {
|
||||
const categoryDir = resolve(__dirname)
|
||||
const categories = readdirSync(categoryDir).filter(
|
||||
c => c[0] != '.' && c != 'index.js'
|
||||
c => c[0] !== '.' && c !== 'index.js'
|
||||
)
|
||||
|
||||
categories.forEach(category => {
|
||||
const suite = new Suite(category, { minTries: 100, minTime: 1000 })
|
||||
const benchmarkDir = resolve(categoryDir, category)
|
||||
const benchmarks = readdirSync(benchmarkDir)
|
||||
.filter(b => b[0] != '.' && !!~b.indexOf('.js'))
|
||||
.filter(b => b[0] !== '.' && !!~b.indexOf('.js'))
|
||||
.map(b => basename(b, extname(b)))
|
||||
|
||||
benchmarks.forEach(benchmark => {
|
||||
|
@ -10,7 +10,7 @@ const { Suite, Bench } = require('slate-dev-benchmark')
|
||||
module.exports.run = function(include) {
|
||||
const categoryDir = resolve(__dirname)
|
||||
const categories = readdirSync(categoryDir).filter(
|
||||
c => c[0] != '.' && c != 'index.js'
|
||||
c => c[0] !== '.' && c !== 'index.js'
|
||||
)
|
||||
|
||||
categories.forEach(category => {
|
||||
@ -20,7 +20,7 @@ module.exports.run = function(include) {
|
||||
})
|
||||
const benchmarkDir = resolve(categoryDir, category)
|
||||
const benchmarks = readdirSync(benchmarkDir)
|
||||
.filter(b => b[0] != '.' && !!~b.indexOf('.js'))
|
||||
.filter(b => b[0] !== '.' && !!~b.indexOf('.js'))
|
||||
.map(b => basename(b, extname(b)))
|
||||
|
||||
benchmarks.forEach(benchmark => {
|
||||
|
@ -10,7 +10,7 @@ const { Suite, Bench } = require('slate-dev-benchmark')
|
||||
module.exports.run = function(include) {
|
||||
const categoryDir = resolve(__dirname)
|
||||
const categories = readdirSync(categoryDir).filter(
|
||||
c => c[0] != '.' && c != 'index.js'
|
||||
c => c[0] !== '.' && c !== 'index.js'
|
||||
)
|
||||
|
||||
categories.forEach(category => {
|
||||
@ -20,7 +20,7 @@ module.exports.run = function(include) {
|
||||
})
|
||||
const benchmarkDir = resolve(categoryDir, category)
|
||||
const benchmarks = readdirSync(benchmarkDir)
|
||||
.filter(b => b[0] != '.' && !!~b.indexOf('.js'))
|
||||
.filter(b => b[0] !== '.' && !!~b.indexOf('.js'))
|
||||
.map(b => basename(b, extname(b)))
|
||||
|
||||
benchmarks.forEach(benchmark => {
|
||||
|
@ -24,7 +24,7 @@ const value = (
|
||||
<quote>
|
||||
<paragraph>
|
||||
<paragraph>
|
||||
This is editable {i == 0 ? <anchor /> : ''}rich{i == 0 ? (
|
||||
This is editable {i === 0 ? <anchor /> : ''}rich{i === 0 ? (
|
||||
<focus />
|
||||
) : (
|
||||
''
|
||||
|
@ -22,7 +22,7 @@ const value = (
|
||||
<paragraph>
|
||||
This is editable <b>rich</b> text, <i>much</i> better than a
|
||||
textarea!
|
||||
{i == 0 ? <cursor /> : ''}
|
||||
{i === 0 ? <cursor /> : ''}
|
||||
</paragraph>
|
||||
</paragraph>
|
||||
</quote>
|
||||
|
@ -20,7 +20,7 @@ const value = (
|
||||
<quote>
|
||||
<paragraph>
|
||||
<paragraph>
|
||||
{i == 0 ? <cursor /> : ''}
|
||||
{i === 0 ? <cursor /> : ''}
|
||||
This is editable <b>rich</b> text, <i>much</i> better than a
|
||||
textarea!
|
||||
</paragraph>
|
||||
|
@ -21,7 +21,7 @@ const value = (
|
||||
<paragraph>
|
||||
This is editable <b>rich</b> text, <i>much</i> better than a
|
||||
textarea!
|
||||
{i == 0 ? <cursor /> : ''}
|
||||
{i === 0 ? <cursor /> : ''}
|
||||
</paragraph>
|
||||
</quote>
|
||||
))}
|
||||
|
@ -23,7 +23,7 @@ const value = (
|
||||
<text key={`T${i}`}>
|
||||
This is editable <b>rich</b> text, <i>much</i> better than a
|
||||
textarea!
|
||||
{i == 0 ? <cursor /> : ''}
|
||||
{i === 0 ? <cursor /> : ''}
|
||||
</text>
|
||||
</paragraph>
|
||||
</paragraph>
|
||||
|
@ -24,7 +24,7 @@ const value = (
|
||||
<quote>
|
||||
<paragraph>
|
||||
<paragraph>
|
||||
{i == 0 ? <cursor /> : ''}
|
||||
{i === 0 ? <cursor /> : ''}
|
||||
This is editable <b>rich</b> text, <i>much</i> better than a
|
||||
textarea!
|
||||
</paragraph>
|
||||
|
@ -24,7 +24,7 @@ const value = (
|
||||
<quote>
|
||||
<paragraph>
|
||||
<paragraph>
|
||||
{i == 0 ? <cursor /> : ''}
|
||||
{i === 0 ? <cursor /> : ''}
|
||||
This is editable <b>rich</b> text, <i>much</i> better than a
|
||||
textarea!
|
||||
</paragraph>
|
||||
|
@ -21,7 +21,7 @@ const value = (
|
||||
<paragraph>
|
||||
<paragraph>
|
||||
<text key={`T${i}`}>
|
||||
{i == 0 ? <cursor /> : ''}
|
||||
{i === 0 ? <cursor /> : ''}
|
||||
This is editable <b>rich</b> text, <i>much</i> better than a
|
||||
textarea!
|
||||
</text>
|
||||
|
@ -22,7 +22,7 @@ const value = (
|
||||
<paragraph>
|
||||
This is editable <b>rich</b> text, <i>much</i> better than a
|
||||
textarea!
|
||||
{i == 0 ? <cursor /> : ''}
|
||||
{i === 0 ? <cursor /> : ''}
|
||||
</paragraph>
|
||||
</paragraph>
|
||||
</quote>
|
||||
|
@ -25,7 +25,7 @@ const value = (
|
||||
<paragraph>
|
||||
<paragraph>
|
||||
This
|
||||
{i == 0 ? <cursor /> : ''}
|
||||
{i === 0 ? <cursor /> : ''}
|
||||
is editable <b>rich</b> text, <i>much</i> better than a textarea!
|
||||
</paragraph>
|
||||
</paragraph>
|
||||
|
@ -10,14 +10,14 @@ const { Suite, Bench } = require('slate-dev-benchmark')
|
||||
module.exports.run = function(include) {
|
||||
const categoryDir = resolve(__dirname)
|
||||
const categories = readdirSync(categoryDir).filter(
|
||||
c => c[0] != '.' && c != 'index.js'
|
||||
c => c[0] !== '.' && c !== 'index.js'
|
||||
)
|
||||
|
||||
categories.forEach(category => {
|
||||
const suite = new Suite(category, { minTries: 100, minTime: 1000 })
|
||||
const benchmarkDir = resolve(categoryDir, category)
|
||||
const benchmarks = readdirSync(benchmarkDir)
|
||||
.filter(b => b[0] != '.' && !!~b.indexOf('.js'))
|
||||
.filter(b => b[0] !== '.' && !!~b.indexOf('.js'))
|
||||
.map(b => basename(b, extname(b)))
|
||||
|
||||
benchmarks.forEach(benchmark => {
|
||||
|
@ -147,16 +147,16 @@ class CheckLists extends React.Component {
|
||||
onKeyDown = (event, editor, next) => {
|
||||
const { value } = editor
|
||||
|
||||
if (event.key == 'Enter' && value.startBlock.type == 'check-list-item') {
|
||||
if (event.key === 'Enter' && value.startBlock.type === 'check-list-item') {
|
||||
editor.splitBlock().setBlocks({ data: { checked: false } })
|
||||
return
|
||||
}
|
||||
|
||||
if (
|
||||
event.key == 'Backspace' &&
|
||||
event.key === 'Backspace' &&
|
||||
value.isCollapsed &&
|
||||
value.startBlock.type == 'check-list-item' &&
|
||||
value.selection.startOffset == 0
|
||||
value.startBlock.type === 'check-list-item' &&
|
||||
value.selection.startOffset === 0
|
||||
) {
|
||||
editor.setBlocks('paragraph')
|
||||
return
|
||||
|
@ -59,9 +59,9 @@ function CodeBlockLine(props) {
|
||||
*/
|
||||
|
||||
function getContent(token) {
|
||||
if (typeof token == 'string') {
|
||||
if (typeof token === 'string') {
|
||||
return token
|
||||
} else if (typeof token.content == 'string') {
|
||||
} else if (typeof token.content === 'string') {
|
||||
return token.content
|
||||
} else {
|
||||
return token.content.map(getContent).join('')
|
||||
@ -181,7 +181,7 @@ class CodeHighlighting extends React.Component {
|
||||
|
||||
decorateNode = (node, editor, next) => {
|
||||
const others = next() || []
|
||||
if (node.type != 'code') return others
|
||||
if (node.type !== 'code') return others
|
||||
|
||||
const language = node.data.get('language')
|
||||
const texts = node.getTexts().toArray()
|
||||
@ -216,7 +216,7 @@ class CodeHighlighting extends React.Component {
|
||||
endOffset = remaining
|
||||
}
|
||||
|
||||
if (typeof token != 'string') {
|
||||
if (typeof token !== 'string') {
|
||||
const dec = {
|
||||
anchor: {
|
||||
key: startText.key,
|
||||
|
@ -65,7 +65,7 @@ class HoverMenu extends React.Component {
|
||||
renderMarkButton(type, icon) {
|
||||
const { editor } = this.props
|
||||
const { value } = editor
|
||||
const isActive = value.activeMarks.some(mark => mark.type == type)
|
||||
const isActive = value.activeMarks.some(mark => mark.type === type)
|
||||
return (
|
||||
<Button
|
||||
reversed
|
||||
|
@ -57,7 +57,7 @@ class Links extends React.Component {
|
||||
|
||||
hasLinks = () => {
|
||||
const { value } = this.state
|
||||
return value.inlines.some(inline => inline.type == 'link')
|
||||
return value.inlines.some(inline => inline.type === 'link')
|
||||
}
|
||||
|
||||
/**
|
||||
@ -154,7 +154,7 @@ class Links extends React.Component {
|
||||
} else if (value.selection.isExpanded) {
|
||||
const href = window.prompt('Enter the URL of the link:')
|
||||
|
||||
if (href === null) {
|
||||
if (href == null) {
|
||||
return
|
||||
}
|
||||
|
||||
@ -162,13 +162,13 @@ class Links extends React.Component {
|
||||
} else {
|
||||
const href = window.prompt('Enter the URL of the link:')
|
||||
|
||||
if (href === null) {
|
||||
if (href == null) {
|
||||
return
|
||||
}
|
||||
|
||||
const text = window.prompt('Enter the text for the link:')
|
||||
|
||||
if (text === null) {
|
||||
if (text == null) {
|
||||
return
|
||||
}
|
||||
|
||||
@ -192,7 +192,7 @@ class Links extends React.Component {
|
||||
|
||||
const transfer = getEventTransfer(event)
|
||||
const { type, text } = transfer
|
||||
if (type != 'text' && type != 'html') return next()
|
||||
if (type !== 'text' && type !== 'html') return next()
|
||||
if (!isUrl(text)) return next()
|
||||
|
||||
if (this.hasLinks()) {
|
||||
|
@ -141,7 +141,7 @@ class MarkdownPreview extends React.Component {
|
||||
|
||||
decorateNode(node, editor, next) {
|
||||
const others = next() || []
|
||||
if (node.object != 'block') return others
|
||||
if (node.object !== 'block') return others
|
||||
|
||||
const string = node.text
|
||||
const texts = node.getTexts().toArray()
|
||||
@ -155,9 +155,9 @@ class MarkdownPreview extends React.Component {
|
||||
let start = 0
|
||||
|
||||
function getLength(token) {
|
||||
if (typeof token == 'string') {
|
||||
if (typeof token === 'string') {
|
||||
return token.length
|
||||
} else if (typeof token.content == 'string') {
|
||||
} else if (typeof token.content === 'string') {
|
||||
return token.content.length
|
||||
} else {
|
||||
return token.content.reduce((l, t) => l + getLength(t), 0)
|
||||
@ -183,7 +183,7 @@ class MarkdownPreview extends React.Component {
|
||||
endOffset = remaining
|
||||
}
|
||||
|
||||
if (typeof token != 'string') {
|
||||
if (typeof token !== 'string') {
|
||||
const dec = {
|
||||
anchor: {
|
||||
key: startText.key,
|
||||
|
@ -145,12 +145,12 @@ class MarkdownShortcuts extends React.Component {
|
||||
const chars = startBlock.text.slice(0, start.offset).replace(/\s*/g, '')
|
||||
const type = this.getType(chars)
|
||||
if (!type) return next()
|
||||
if (type == 'list-item' && startBlock.type == 'list-item') return next()
|
||||
if (type === 'list-item' && startBlock.type === 'list-item') return next()
|
||||
event.preventDefault()
|
||||
|
||||
editor.setBlocks(type)
|
||||
|
||||
if (type == 'list-item') {
|
||||
if (type === 'list-item') {
|
||||
editor.wrapBlock('bulleted-list')
|
||||
}
|
||||
|
||||
@ -170,15 +170,15 @@ class MarkdownShortcuts extends React.Component {
|
||||
const { value } = editor
|
||||
const { selection } = value
|
||||
if (selection.isExpanded) return next()
|
||||
if (selection.start.offset != 0) return next()
|
||||
if (selection.start.offset !== 0) return next()
|
||||
|
||||
const { startBlock } = value
|
||||
if (startBlock.type == 'paragraph') return next()
|
||||
if (startBlock.type === 'paragraph') return next()
|
||||
|
||||
event.preventDefault()
|
||||
editor.setBlocks('paragraph')
|
||||
|
||||
if (startBlock.type == 'list-item') {
|
||||
if (startBlock.type === 'list-item') {
|
||||
editor.unwrapBlock('bulleted-list')
|
||||
}
|
||||
}
|
||||
@ -199,18 +199,18 @@ class MarkdownShortcuts extends React.Component {
|
||||
if (isExpanded) return next()
|
||||
|
||||
const { startBlock } = value
|
||||
if (start.offset == 0 && startBlock.text.length == 0)
|
||||
if (start.offset === 0 && startBlock.text.length === 0)
|
||||
return this.onBackspace(event, editor, next)
|
||||
if (end.offset != startBlock.text.length) return next()
|
||||
if (end.offset !== startBlock.text.length) return next()
|
||||
|
||||
if (
|
||||
startBlock.type != 'heading-one' &&
|
||||
startBlock.type != 'heading-two' &&
|
||||
startBlock.type != 'heading-three' &&
|
||||
startBlock.type != 'heading-four' &&
|
||||
startBlock.type != 'heading-five' &&
|
||||
startBlock.type != 'heading-six' &&
|
||||
startBlock.type != 'block-quote'
|
||||
startBlock.type !== 'heading-one' &&
|
||||
startBlock.type !== 'heading-two' &&
|
||||
startBlock.type !== 'heading-three' &&
|
||||
startBlock.type !== 'heading-four' &&
|
||||
startBlock.type !== 'heading-five' &&
|
||||
startBlock.type !== 'heading-six' &&
|
||||
startBlock.type !== 'block-quote'
|
||||
) {
|
||||
return next()
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ function getInput(value) {
|
||||
const textBefore = value.startText.text.slice(0, startOffset)
|
||||
const result = CAPTURE_REGEX.exec(textBefore)
|
||||
|
||||
return result === null ? null : result[1]
|
||||
return result == null ? null : result[1]
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -98,10 +98,10 @@ const RULES = [
|
||||
{
|
||||
// Special case for code blocks, which need to grab the nested childNodes.
|
||||
deserialize(el, next) {
|
||||
if (el.tagName.toLowerCase() == 'pre') {
|
||||
if (el.tagName.toLowerCase() === 'pre') {
|
||||
const code = el.childNodes[0]
|
||||
const childNodes =
|
||||
code && code.tagName.toLowerCase() == 'code'
|
||||
code && code.tagName.toLowerCase() === 'code'
|
||||
? code.childNodes
|
||||
: el.childNodes
|
||||
|
||||
@ -116,7 +116,7 @@ const RULES = [
|
||||
{
|
||||
// Special case for images, to grab their src.
|
||||
deserialize(el, next) {
|
||||
if (el.tagName.toLowerCase() == 'img') {
|
||||
if (el.tagName.toLowerCase() === 'img') {
|
||||
return {
|
||||
object: 'block',
|
||||
type: 'image',
|
||||
@ -131,7 +131,7 @@ const RULES = [
|
||||
{
|
||||
// Special case for links, to grab their href.
|
||||
deserialize(el, next) {
|
||||
if (el.tagName.toLowerCase() == 'a') {
|
||||
if (el.tagName.toLowerCase() === 'a') {
|
||||
return {
|
||||
object: 'inline',
|
||||
type: 'link',
|
||||
@ -283,7 +283,7 @@ class PasteHtml extends React.Component {
|
||||
|
||||
onPaste = (event, editor, next) => {
|
||||
const transfer = getEventTransfer(event)
|
||||
if (transfer.type != 'html') return next()
|
||||
if (transfer.type !== 'html') return next()
|
||||
const { document } = serializer.deserialize(transfer.html)
|
||||
editor.insertFragment(document)
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ class RichTextExample extends React.Component {
|
||||
|
||||
hasMark = type => {
|
||||
const { value } = this.state
|
||||
return value.activeMarks.some(mark => mark.type == type)
|
||||
return value.activeMarks.some(mark => mark.type === type)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -63,7 +63,7 @@ class RichTextExample extends React.Component {
|
||||
|
||||
hasBlock = type => {
|
||||
const { value } = this.state
|
||||
return value.blocks.some(node => node.type == type)
|
||||
return value.blocks.some(node => node.type === type)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -278,7 +278,7 @@ class RichTextExample extends React.Component {
|
||||
const { document } = value
|
||||
|
||||
// Handle everything but list buttons.
|
||||
if (type != 'bulleted-list' && type != 'numbered-list') {
|
||||
if (type !== 'bulleted-list' && type !== 'numbered-list') {
|
||||
const isActive = this.hasBlock(type)
|
||||
const isList = this.hasBlock('list-item')
|
||||
|
||||
@ -294,7 +294,7 @@ class RichTextExample extends React.Component {
|
||||
// Handle the extra wrapping required for list buttons.
|
||||
const isList = this.hasBlock('list-item')
|
||||
const isType = value.blocks.some(block => {
|
||||
return !!document.getClosest(block.key, parent => parent.type == type)
|
||||
return !!document.getClosest(block.key, parent => parent.type === type)
|
||||
})
|
||||
|
||||
if (isList && isType) {
|
||||
@ -305,7 +305,7 @@ class RichTextExample extends React.Component {
|
||||
} else if (isList) {
|
||||
editor
|
||||
.unwrapBlock(
|
||||
type == 'bulleted-list' ? 'numbered-list' : 'bulleted-list'
|
||||
type === 'bulleted-list' ? 'numbered-list' : 'bulleted-list'
|
||||
)
|
||||
.wrapBlock(type)
|
||||
} else {
|
||||
|
@ -62,7 +62,7 @@ class RTL extends React.Component {
|
||||
*/
|
||||
|
||||
onKeyDown = (event, editor, next) => {
|
||||
if (event.key == 'Enter' && event.shiftKey) {
|
||||
if (event.key === 'Enter' && event.shiftKey) {
|
||||
event.preventDefault()
|
||||
editor.insertText('\n')
|
||||
return
|
||||
|
@ -139,7 +139,7 @@ class SearchHighlighting extends React.Component {
|
||||
let offset = 0
|
||||
|
||||
parts.forEach((part, i) => {
|
||||
if (i != 0) {
|
||||
if (i !== 0) {
|
||||
decorations.push({
|
||||
anchor: { key, offset: offset - string.length },
|
||||
focus: { key, offset },
|
||||
|
@ -69,7 +69,7 @@ class SyncingEditor extends React.Component {
|
||||
|
||||
hasMark = type => {
|
||||
const { value } = this.state
|
||||
return value.activeMarks.some(mark => mark.type == type)
|
||||
return value.activeMarks.some(mark => mark.type === type)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -248,8 +248,8 @@ class SyncingOperationsExample extends React.Component {
|
||||
const ops = change.operations
|
||||
.filter(
|
||||
o =>
|
||||
o.type != 'set_selection' &&
|
||||
o.type != 'set_value' &&
|
||||
o.type !== 'set_selection' &&
|
||||
o.type !== 'set_value' &&
|
||||
(!o.data || !o.data.has('source'))
|
||||
)
|
||||
.toJS()
|
||||
@ -268,8 +268,8 @@ class SyncingOperationsExample extends React.Component {
|
||||
const ops = change.operations
|
||||
.filter(
|
||||
o =>
|
||||
o.type != 'set_selection' &&
|
||||
o.type != 'set_value' &&
|
||||
o.type !== 'set_selection' &&
|
||||
o.type !== 'set_value' &&
|
||||
(!o.data || !o.data.has('source'))
|
||||
)
|
||||
.toJS()
|
||||
|
@ -94,7 +94,7 @@ class Tables extends React.Component {
|
||||
onBackspace = (event, editor, next) => {
|
||||
const { value } = editor
|
||||
const { selection } = value
|
||||
if (selection.start.offset != 0) return next()
|
||||
if (selection.start.offset !== 0) return next()
|
||||
event.preventDefault()
|
||||
}
|
||||
|
||||
@ -108,7 +108,7 @@ class Tables extends React.Component {
|
||||
onDelete = (event, editor, next) => {
|
||||
const { value } = editor
|
||||
const { selection } = value
|
||||
if (selection.end.offset != value.startText.text.length) return next()
|
||||
if (selection.end.offset !== value.startText.text.length) return next()
|
||||
event.preventDefault()
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ const TEXT_RULE = {
|
||||
}
|
||||
}
|
||||
|
||||
if (el.nodeName == '#text') {
|
||||
if (el.nodeName === '#text') {
|
||||
if (el.nodeValue && el.nodeValue.match(/<!--.*?-->/)) return
|
||||
|
||||
return {
|
||||
@ -54,7 +54,7 @@ const TEXT_RULE = {
|
||||
serialize(obj, children) {
|
||||
if (obj.object === 'string') {
|
||||
return children.split('\n').reduce((array, text, i) => {
|
||||
if (i != 0) array.push(<br key={i} />)
|
||||
if (i !== 0) array.push(<br key={i} />)
|
||||
array.push(text)
|
||||
return array
|
||||
}, [])
|
||||
@ -70,7 +70,7 @@ const TEXT_RULE = {
|
||||
*/
|
||||
|
||||
function defaultParseHtml(html) {
|
||||
if (typeof DOMParser === 'undefined') {
|
||||
if (typeof DOMParser == 'undefined') {
|
||||
throw new Error(
|
||||
'The native `DOMParser` global which the `Html` serializer uses by default is not present in this environment. You must supply the `options.parseHtml` function instead.'
|
||||
)
|
||||
@ -130,12 +130,12 @@ class Html {
|
||||
|
||||
// COMPAT: ensure that all top-level inline nodes are wrapped into a block.
|
||||
nodes = nodes.reduce((memo, node, i, original) => {
|
||||
if (node.object == 'block') {
|
||||
if (node.object === 'block') {
|
||||
memo.push(node)
|
||||
return memo
|
||||
}
|
||||
|
||||
if (i > 0 && original[i - 1].object != 'block') {
|
||||
if (i > 0 && original[i - 1].object !== 'block') {
|
||||
const block = memo[memo.length - 1]
|
||||
block.nodes.push(node)
|
||||
return memo
|
||||
@ -153,7 +153,7 @@ class Html {
|
||||
}, [])
|
||||
|
||||
// TODO: pretty sure this is no longer needed.
|
||||
if (nodes.length == 0) {
|
||||
if (nodes.length === 0) {
|
||||
nodes = [
|
||||
{
|
||||
object: 'block',
|
||||
@ -229,7 +229,7 @@ class Html {
|
||||
}
|
||||
|
||||
const next = elements => {
|
||||
if (Object.prototype.toString.call(elements) == '[object NodeList]') {
|
||||
if (Object.prototype.toString.call(elements) === '[object NodeList]') {
|
||||
elements = Array.from(elements)
|
||||
}
|
||||
|
||||
@ -254,10 +254,10 @@ class Html {
|
||||
const type = typeOf(ret)
|
||||
|
||||
if (
|
||||
type != 'array' &&
|
||||
type != 'object' &&
|
||||
type != 'null' &&
|
||||
type != 'undefined'
|
||||
type !== 'array' &&
|
||||
type !== 'object' &&
|
||||
type !== 'null' &&
|
||||
type !== 'undefined'
|
||||
) {
|
||||
throw new Error(
|
||||
`A rule returned an invalid deserialized representation: "${node}".`
|
||||
@ -268,7 +268,7 @@ class Html {
|
||||
continue
|
||||
} else if (ret === null) {
|
||||
return null
|
||||
} else if (ret.object == 'mark') {
|
||||
} else if (ret.object === 'mark') {
|
||||
node = this.deserializeMark(ret)
|
||||
} else {
|
||||
node = ret
|
||||
@ -291,9 +291,9 @@ class Html {
|
||||
const { type, data } = mark
|
||||
|
||||
const applyMark = node => {
|
||||
if (node.object == 'mark') {
|
||||
if (node.object === 'mark') {
|
||||
return this.deserializeMark(node)
|
||||
} else if (node.object == 'text') {
|
||||
} else if (node.object === 'text') {
|
||||
node.leaves = node.leaves.map(leaf => {
|
||||
leaf.marks = leaf.marks || []
|
||||
leaf.marks.push({ type, data })
|
||||
@ -404,7 +404,7 @@ class Html {
|
||||
*/
|
||||
|
||||
cruftNewline = element => {
|
||||
return !(element.nodeName === '#text' && element.nodeValue == '\n')
|
||||
return !(element.nodeName === '#text' && element.nodeValue === '\n')
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ import h from '../helpers/h'
|
||||
export const rules = [
|
||||
{
|
||||
serialize(obj, children) {
|
||||
if (obj.object != 'block') return
|
||||
if (obj.object !== 'block') return
|
||||
|
||||
switch (obj.type) {
|
||||
case 'paragraph':
|
||||
|
@ -6,7 +6,7 @@ import h from '../helpers/h'
|
||||
export const rules = [
|
||||
{
|
||||
serialize(obj, children) {
|
||||
if (obj.object == 'block' && obj.type == 'paragraph') {
|
||||
if (obj.object === 'block' && obj.type === 'paragraph') {
|
||||
return React.createElement(
|
||||
'p',
|
||||
{ 'data-thing': obj.data.get('thing') },
|
||||
|
@ -6,7 +6,7 @@ import h from '../helpers/h'
|
||||
export const rules = [
|
||||
{
|
||||
serialize(obj, children) {
|
||||
if (obj.object == 'block' && obj.type == 'image') {
|
||||
if (obj.object === 'block' && obj.type === 'image') {
|
||||
return React.createElement('img')
|
||||
}
|
||||
},
|
||||
|
@ -6,11 +6,11 @@ import h from '../helpers/h'
|
||||
export const rules = [
|
||||
{
|
||||
serialize(obj, children) {
|
||||
if (obj.object == 'block' && obj.type == 'paragraph') {
|
||||
if (obj.object === 'block' && obj.type === 'paragraph') {
|
||||
return React.createElement('p', {}, children)
|
||||
}
|
||||
|
||||
if (obj.object == 'mark' && obj.type == 'bold') {
|
||||
if (obj.object === 'mark' && obj.type === 'bold') {
|
||||
return React.createElement('strong', {}, children)
|
||||
}
|
||||
},
|
||||
|
@ -6,7 +6,7 @@ import h from '../helpers/h'
|
||||
export const rules = [
|
||||
{
|
||||
serialize(obj, children) {
|
||||
if (obj.object == 'block' && obj.type == 'paragraph') {
|
||||
if (obj.object === 'block' && obj.type === 'paragraph') {
|
||||
return React.createElement('p', {}, children)
|
||||
}
|
||||
},
|
||||
|
@ -6,15 +6,15 @@ import h from '../helpers/h'
|
||||
export const rules = [
|
||||
{
|
||||
serialize(obj, children) {
|
||||
if (obj.object == 'block' && obj.type == 'paragraph') {
|
||||
if (obj.object === 'block' && obj.type === 'paragraph') {
|
||||
return React.createElement('p', {}, children)
|
||||
}
|
||||
|
||||
if (obj.object == 'inline' && obj.type == 'link') {
|
||||
if (obj.object === 'inline' && obj.type === 'link') {
|
||||
return React.createElement('a', {}, children)
|
||||
}
|
||||
|
||||
if (obj.object == 'inline' && obj.type == 'hashtag') {
|
||||
if (obj.object === 'inline' && obj.type === 'hashtag') {
|
||||
return React.createElement('span', {}, children)
|
||||
}
|
||||
},
|
||||
|
@ -6,11 +6,11 @@ import h from '../helpers/h'
|
||||
export const rules = [
|
||||
{
|
||||
serialize(obj, children) {
|
||||
if (obj.object == 'block' && obj.type == 'paragraph') {
|
||||
if (obj.object === 'block' && obj.type === 'paragraph') {
|
||||
return React.createElement('p', {}, children)
|
||||
}
|
||||
|
||||
if (obj.object == 'inline' && obj.type == 'link') {
|
||||
if (obj.object === 'inline' && obj.type === 'link') {
|
||||
return React.createElement(
|
||||
'a',
|
||||
{ href: obj.data.get('href') },
|
||||
|
@ -6,11 +6,11 @@ import h from '../helpers/h'
|
||||
export const rules = [
|
||||
{
|
||||
serialize(obj, children) {
|
||||
if (obj.object == 'block' && obj.type == 'paragraph') {
|
||||
if (obj.object === 'block' && obj.type === 'paragraph') {
|
||||
return React.createElement('p', {}, children)
|
||||
}
|
||||
|
||||
if (obj.object == 'inline' && obj.type == 'emoji') {
|
||||
if (obj.object === 'inline' && obj.type === 'emoji') {
|
||||
return React.createElement('img')
|
||||
}
|
||||
},
|
||||
|
@ -6,15 +6,15 @@ import h from '../helpers/h'
|
||||
export const rules = [
|
||||
{
|
||||
serialize(obj, children) {
|
||||
if (obj.object == 'block' && obj.type == 'paragraph') {
|
||||
if (obj.object === 'block' && obj.type === 'paragraph') {
|
||||
return React.createElement('p', {}, children)
|
||||
}
|
||||
|
||||
if (obj.object == 'inline' && obj.type == 'link') {
|
||||
if (obj.object === 'inline' && obj.type === 'link') {
|
||||
return React.createElement('a', {}, children)
|
||||
}
|
||||
|
||||
if (obj.object == 'mark' && obj.type == 'bold') {
|
||||
if (obj.object === 'mark' && obj.type === 'bold') {
|
||||
return React.createElement('strong', {}, children)
|
||||
}
|
||||
},
|
||||
|
@ -6,11 +6,11 @@ import h from '../helpers/h'
|
||||
export const rules = [
|
||||
{
|
||||
serialize(obj, children) {
|
||||
if (obj.object == 'block' && obj.type == 'paragraph') {
|
||||
if (obj.object === 'block' && obj.type === 'paragraph') {
|
||||
return React.createElement('p', {}, children)
|
||||
}
|
||||
|
||||
if (obj.object == 'inline' && obj.type == 'link') {
|
||||
if (obj.object === 'inline' && obj.type === 'link') {
|
||||
return React.createElement('a', {}, children)
|
||||
}
|
||||
},
|
||||
|
@ -10,7 +10,7 @@ export const rules = [
|
||||
},
|
||||
{
|
||||
serialize(obj, children) {
|
||||
if (obj.object == 'block' && obj.type == 'paragraph') {
|
||||
if (obj.object === 'block' && obj.type === 'paragraph') {
|
||||
return React.createElement('p', {}, children)
|
||||
}
|
||||
},
|
||||
|
@ -6,19 +6,19 @@ import h from '../helpers/h'
|
||||
export const rules = [
|
||||
{
|
||||
serialize(obj, children) {
|
||||
if (obj.object == 'block' && obj.type == 'paragraph') {
|
||||
if (obj.object === 'block' && obj.type === 'paragraph') {
|
||||
return React.createElement('p', {}, children)
|
||||
}
|
||||
|
||||
if (obj.object == 'inline' && obj.type == 'link') {
|
||||
if (obj.object === 'inline' && obj.type === 'link') {
|
||||
return React.createElement('a', {}, children)
|
||||
}
|
||||
|
||||
if (obj.object == 'inline' && obj.type == 'comment') {
|
||||
if (obj.object === 'inline' && obj.type === 'comment') {
|
||||
return null
|
||||
}
|
||||
|
||||
if (obj.object == 'block' && obj.type == 'quote') {
|
||||
if (obj.object === 'block' && obj.type === 'quote') {
|
||||
return null
|
||||
}
|
||||
},
|
||||
|
@ -93,11 +93,11 @@ function createHyperscript(options = {}) {
|
||||
*/
|
||||
|
||||
function normalizeCreator(value, creator) {
|
||||
if (typeof value == 'function') {
|
||||
if (typeof value === 'function') {
|
||||
return value
|
||||
}
|
||||
|
||||
if (typeof value == 'string') {
|
||||
if (typeof value === 'string') {
|
||||
value = { type: value }
|
||||
}
|
||||
|
||||
|
@ -80,8 +80,8 @@ function serializeNode(node, options = {}) {
|
||||
const { delimiter = '\n' } = options
|
||||
|
||||
if (
|
||||
node.object == 'document' ||
|
||||
(node.object == 'block' && Block.isBlockList(node.nodes))
|
||||
node.object === 'document' ||
|
||||
(node.object === 'block' && Block.isBlockList(node.nodes))
|
||||
) {
|
||||
return node.nodes.map(serializeNode).join(delimiter)
|
||||
} else {
|
||||
|
@ -202,14 +202,14 @@ class Content extends React.Component {
|
||||
// to check both orientations here. (2017/10/31)
|
||||
if (current) {
|
||||
if (
|
||||
(startContainer == current.startContainer &&
|
||||
startOffset == current.startOffset &&
|
||||
endContainer == current.endContainer &&
|
||||
endOffset == current.endOffset) ||
|
||||
(startContainer == current.endContainer &&
|
||||
startOffset == current.endOffset &&
|
||||
endContainer == current.startContainer &&
|
||||
endOffset == current.startOffset)
|
||||
(startContainer === current.startContainer &&
|
||||
startOffset === current.startOffset &&
|
||||
endContainer === current.endContainer &&
|
||||
endOffset === current.endOffset) ||
|
||||
(startContainer === current.endContainer &&
|
||||
startOffset === current.endOffset &&
|
||||
endContainer === current.startContainer &&
|
||||
endOffset === current.startOffset)
|
||||
) {
|
||||
return
|
||||
}
|
||||
@ -330,7 +330,7 @@ class Content extends React.Component {
|
||||
// programmatically while updating selection.
|
||||
if (
|
||||
this.tmp.isUpdatingSelection &&
|
||||
(handler == 'onSelect' || handler == 'onBlur' || handler == 'onFocus')
|
||||
(handler === 'onSelect' || handler === 'onBlur' || handler === 'onFocus')
|
||||
) {
|
||||
return
|
||||
}
|
||||
@ -340,7 +340,7 @@ class Content extends React.Component {
|
||||
// cases we don't need to trigger any changes, since our internal model is
|
||||
// already up to date, but we do want to update the native selection again
|
||||
// to make sure it is in sync. (2017/10/16)
|
||||
if (handler == 'onSelect') {
|
||||
if (handler === 'onSelect') {
|
||||
const { editor } = this.props
|
||||
const { value } = editor
|
||||
const { selection } = value
|
||||
@ -356,13 +356,13 @@ class Content extends React.Component {
|
||||
|
||||
// Don't handle drag and drop events coming from embedded editors.
|
||||
if (
|
||||
handler == 'onDragEnd' ||
|
||||
handler == 'onDragEnter' ||
|
||||
handler == 'onDragExit' ||
|
||||
handler == 'onDragLeave' ||
|
||||
handler == 'onDragOver' ||
|
||||
handler == 'onDragStart' ||
|
||||
handler == 'onDrop'
|
||||
handler === 'onDragEnd' ||
|
||||
handler === 'onDragEnter' ||
|
||||
handler === 'onDragExit' ||
|
||||
handler === 'onDragLeave' ||
|
||||
handler === 'onDragOver' ||
|
||||
handler === 'onDragStart' ||
|
||||
handler === 'onDrop'
|
||||
) {
|
||||
const closest = event.target.closest('[data-slate-editor]')
|
||||
|
||||
@ -374,18 +374,18 @@ class Content extends React.Component {
|
||||
// Some events require being in editable in the editor, so if the event
|
||||
// target isn't, ignore them.
|
||||
if (
|
||||
handler == 'onBeforeInput' ||
|
||||
handler == 'onBlur' ||
|
||||
handler == 'onCompositionEnd' ||
|
||||
handler == 'onCompositionStart' ||
|
||||
handler == 'onCopy' ||
|
||||
handler == 'onCut' ||
|
||||
handler == 'onFocus' ||
|
||||
handler == 'onInput' ||
|
||||
handler == 'onKeyDown' ||
|
||||
handler == 'onKeyUp' ||
|
||||
handler == 'onPaste' ||
|
||||
handler == 'onSelect'
|
||||
handler === 'onBeforeInput' ||
|
||||
handler === 'onBlur' ||
|
||||
handler === 'onCompositionEnd' ||
|
||||
handler === 'onCompositionStart' ||
|
||||
handler === 'onCopy' ||
|
||||
handler === 'onCut' ||
|
||||
handler === 'onFocus' ||
|
||||
handler === 'onInput' ||
|
||||
handler === 'onKeyDown' ||
|
||||
handler === 'onKeyUp' ||
|
||||
handler === 'onPaste' ||
|
||||
handler === 'onSelect'
|
||||
) {
|
||||
if (!this.isInEditor(event.target)) {
|
||||
return
|
||||
|
@ -59,10 +59,10 @@ class Leaf extends React.Component {
|
||||
shouldComponentUpdate(props) {
|
||||
// If any of the regular properties have changed, re-render.
|
||||
if (
|
||||
props.index != this.props.index ||
|
||||
props.marks != this.props.marks ||
|
||||
props.text != this.props.text ||
|
||||
props.parent != this.props.parent
|
||||
props.index !== this.props.index ||
|
||||
props.marks !== this.props.marks ||
|
||||
props.text !== this.props.text ||
|
||||
props.parent !== this.props.parent
|
||||
) {
|
||||
return true
|
||||
}
|
||||
|
@ -89,13 +89,13 @@ class Node extends React.Component {
|
||||
|
||||
// If the `readOnly` status has changed, re-render in case there is any
|
||||
// user-land logic that depends on it, like nested editable contents.
|
||||
if (n.readOnly != p.readOnly) return true
|
||||
if (n.readOnly !== p.readOnly) return true
|
||||
|
||||
// If the node has changed, update. PERF: There are cases where it will have
|
||||
// changed, but it's properties will be exactly the same (eg. copy-paste)
|
||||
// which this won't catch. But that's rare and not a drag on performance, so
|
||||
// for simplicity we just let them through.
|
||||
if (n.node != p.node) return true
|
||||
if (n.node !== p.node) return true
|
||||
|
||||
// If the selection value of the node or of some of its children has changed,
|
||||
// re-render in case there is any user-land logic depends on it to render.
|
||||
@ -152,7 +152,7 @@ class Node extends React.Component {
|
||||
// for text direction.
|
||||
if (node.isLeafBlock()) {
|
||||
const direction = node.getTextDirection()
|
||||
if (direction == 'rtl') attributes.dir = 'rtl'
|
||||
if (direction === 'rtl') attributes.dir = 'rtl'
|
||||
}
|
||||
|
||||
const props = {
|
||||
@ -189,11 +189,11 @@ class Node extends React.Component {
|
||||
|
||||
renderNode = (child, isSelected, decorations) => {
|
||||
const { block, editor, node, readOnly, isFocused } = this.props
|
||||
const Component = child.object == 'text' ? Text : Node
|
||||
const Component = child.object === 'text' ? Text : Node
|
||||
|
||||
return (
|
||||
<Component
|
||||
block={node.object == 'block' ? node : block}
|
||||
block={node.object === 'block' ? node : block}
|
||||
decorations={decorations}
|
||||
editor={editor}
|
||||
isSelected={isSelected}
|
||||
|
@ -77,14 +77,14 @@ class Text extends React.Component {
|
||||
// changed, but it's properties will be exactly the same (eg. copy-paste)
|
||||
// which this won't catch. But that's rare and not a drag on performance, so
|
||||
// for simplicity we just let them through.
|
||||
if (n.node != p.node) return true
|
||||
if (n.node !== p.node) return true
|
||||
|
||||
// If the node parent is a block node, and it was the last child of the
|
||||
// block, re-render to cleanup extra `\n`.
|
||||
if (n.parent.object == 'block') {
|
||||
if (n.parent.object === 'block') {
|
||||
const pLast = p.parent.nodes.last()
|
||||
const nLast = n.parent.nodes.last()
|
||||
if (p.node == pLast && n.node != nLast) return true
|
||||
if (p.node === pLast && n.node !== nLast) return true
|
||||
}
|
||||
|
||||
// Re-render if the current decorations have changed.
|
||||
|
@ -58,7 +58,7 @@ class Void extends React.Component {
|
||||
render() {
|
||||
const { props } = this
|
||||
const { children, node, readOnly } = props
|
||||
const Tag = node.object == 'block' ? 'div' : 'span'
|
||||
const Tag = node.object === 'block' ? 'div' : 'span'
|
||||
const style = {
|
||||
height: '0',
|
||||
color: 'transparent',
|
||||
@ -82,7 +82,7 @@ class Void extends React.Component {
|
||||
<Tag
|
||||
data-slate-void
|
||||
data-key={node.key}
|
||||
contentEditable={readOnly || node.object == 'block' ? null : false}
|
||||
contentEditable={readOnly || node.object === 'block' ? null : false}
|
||||
>
|
||||
{readOnly ? null : spacer}
|
||||
{content}
|
||||
@ -106,7 +106,7 @@ class Void extends React.Component {
|
||||
const child = node.getFirstText()
|
||||
return (
|
||||
<Text
|
||||
block={node.object == 'block' ? node : block}
|
||||
block={node.object === 'block' ? node : block}
|
||||
decorations={decorations}
|
||||
editor={editor}
|
||||
key={child.key}
|
||||
|
@ -133,7 +133,7 @@ function AfterPlugin(options = {}) {
|
||||
|
||||
// If the text was successfully inserted, and the selection had marks
|
||||
// on it, unset the selection's marks.
|
||||
if (selection.marks && value.document != editor.value.document) {
|
||||
if (selection.marks && value.document !== editor.value.document) {
|
||||
editor.select({ marks: null })
|
||||
}
|
||||
|
||||
@ -313,11 +313,11 @@ function AfterPlugin(options = {}) {
|
||||
// needs to account for the selection's content being deleted.
|
||||
if (
|
||||
isDraggingInternally &&
|
||||
selection.end.key == target.end.key &&
|
||||
selection.end.key === target.end.key &&
|
||||
selection.end.offset < target.end.offset
|
||||
) {
|
||||
target = target.moveForward(
|
||||
selection.start.key == selection.end.key
|
||||
selection.start.key === selection.end.key
|
||||
? 0 - selection.end.offset + selection.start.offset
|
||||
: 0 - selection.end.offset
|
||||
)
|
||||
@ -329,7 +329,7 @@ function AfterPlugin(options = {}) {
|
||||
|
||||
editor.select(target)
|
||||
|
||||
if (type == 'text' || type == 'html') {
|
||||
if (type === 'text' || type === 'html') {
|
||||
const { anchor } = target
|
||||
let hasVoidParent = document.hasVoidParent(anchor.key, editor)
|
||||
|
||||
@ -353,7 +353,7 @@ function AfterPlugin(options = {}) {
|
||||
}
|
||||
}
|
||||
|
||||
if (type == 'fragment') {
|
||||
if (type === 'fragment') {
|
||||
editor.insertFragment(fragment)
|
||||
}
|
||||
|
||||
@ -539,7 +539,7 @@ function AfterPlugin(options = {}) {
|
||||
const isPreviousInVoid =
|
||||
previousText && document.hasVoidParent(previousText.key, editor)
|
||||
|
||||
if (hasVoidParent || isPreviousInVoid || startText.text == '') {
|
||||
if (hasVoidParent || isPreviousInVoid || startText.text === '') {
|
||||
event.preventDefault()
|
||||
return editor.moveFocusBackward()
|
||||
}
|
||||
@ -550,7 +550,7 @@ function AfterPlugin(options = {}) {
|
||||
const isNextInVoid =
|
||||
nextText && document.hasVoidParent(nextText.key, editor)
|
||||
|
||||
if (hasVoidParent || isNextInVoid || startText.text == '') {
|
||||
if (hasVoidParent || isNextInVoid || startText.text === '') {
|
||||
event.preventDefault()
|
||||
return editor.moveFocusForward()
|
||||
}
|
||||
@ -602,11 +602,11 @@ function AfterPlugin(options = {}) {
|
||||
const transfer = getEventTransfer(event)
|
||||
const { type, fragment, text } = transfer
|
||||
|
||||
if (type == 'fragment') {
|
||||
if (type === 'fragment') {
|
||||
editor.insertFragment(fragment)
|
||||
}
|
||||
|
||||
if (type == 'text' || type == 'html') {
|
||||
if (type === 'text' || type === 'html') {
|
||||
if (!text) return next()
|
||||
const { document, selection, startBlock } = value
|
||||
if (editor.isVoid(startBlock)) return next()
|
||||
|
@ -346,7 +346,7 @@ function BeforePlugin() {
|
||||
// COMPAT: If the editor has nested editable elements, the focus can go to
|
||||
// those elements. In Firefox, this must be prevented because it results in
|
||||
// issues with keyboard navigation. (2017/03/30)
|
||||
if (IS_FIREFOX && event.target != el) {
|
||||
if (IS_FIREFOX && event.target !== el) {
|
||||
el.focus()
|
||||
return
|
||||
}
|
||||
|
4
packages/slate-react/src/plugins/react.js
vendored
4
packages/slate-react/src/plugins/react.js
vendored
@ -84,9 +84,9 @@ function ReactPlugin(options = {}) {
|
||||
function renderNode(props, editor, next) {
|
||||
const { attributes, children, node } = props
|
||||
const { object } = node
|
||||
if (object != 'block' && object != 'inline') return null
|
||||
if (object !== 'block' && object !== 'inline') return null
|
||||
|
||||
const Tag = object == 'block' ? 'div' : 'span'
|
||||
const Tag = object === 'block' ? 'div' : 'span'
|
||||
const style = { position: 'relative' }
|
||||
return (
|
||||
<Tag {...attributes} style={style}>
|
||||
|
@ -77,7 +77,7 @@ function cloneFragment(event, editor, callback = () => undefined) {
|
||||
// Set a `data-slate-fragment` attribute on a non-empty node, so it shows up
|
||||
// in the HTML, and can be used for intra-Slate pasting. If it's a text
|
||||
// node, wrap it in a `<span>` so we have something to set an attribute on.
|
||||
if (attach.nodeType == 3) {
|
||||
if (attach.nodeType === 3) {
|
||||
const span = window.document.createElement('span')
|
||||
|
||||
// COMPAT: In Chrome and Safari, if we don't add the `white-space` style
|
||||
|
@ -68,7 +68,7 @@ function findPoint(nativeNode, nativeOffset, editor) {
|
||||
// ASCII characters will be prepended to the zero-width space, so subtract 1
|
||||
// from the offset to account for the zero-width space character.
|
||||
if (
|
||||
offset == node.textContent.length &&
|
||||
offset === node.textContent.length &&
|
||||
parentNode.hasAttribute(ZERO_WIDTH_ATTRIBUTE)
|
||||
) {
|
||||
offset--
|
||||
@ -102,15 +102,15 @@ function findPoint(nativeNode, nativeOffset, editor) {
|
||||
function normalizeNodeAndOffset(node, offset) {
|
||||
// If it's an element node, its offset refers to the index of its children
|
||||
// including comment nodes, so try to find the right text child node.
|
||||
if (node.nodeType == 1 && node.childNodes.length) {
|
||||
const isLast = offset == node.childNodes.length
|
||||
if (node.nodeType === 1 && node.childNodes.length) {
|
||||
const isLast = offset === node.childNodes.length
|
||||
const direction = isLast ? 'backward' : 'forward'
|
||||
const index = isLast ? offset - 1 : offset
|
||||
node = getEditableChild(node, index, direction)
|
||||
|
||||
// If the node has children, traverse until we have a leaf node. Leaf nodes
|
||||
// can be either text nodes, or other void DOM nodes.
|
||||
while (node.nodeType == 1 && node.childNodes.length) {
|
||||
while (node.nodeType === 1 && node.childNodes.length) {
|
||||
const i = isLast ? node.childNodes.length - 1 : 0
|
||||
node = getEditableChild(node, i, direction)
|
||||
}
|
||||
@ -143,9 +143,9 @@ function getEditableChild(parent, index, direction) {
|
||||
// While the child is a comment node, or an element node with no children,
|
||||
// keep iterating to find a sibling non-void, non-comment node.
|
||||
while (
|
||||
child.nodeType == 8 ||
|
||||
(child.nodeType == 1 && child.childNodes.length == 0) ||
|
||||
(child.nodeType == 1 && child.getAttribute('contenteditable') == 'false')
|
||||
child.nodeType === 8 ||
|
||||
(child.nodeType === 1 && child.childNodes.length === 0) ||
|
||||
(child.nodeType === 1 && child.getAttribute('contenteditable') === 'false')
|
||||
) {
|
||||
if (triedForward && triedBackward) break
|
||||
|
||||
@ -164,8 +164,8 @@ function getEditableChild(parent, index, direction) {
|
||||
}
|
||||
|
||||
child = childNodes[i]
|
||||
if (direction == 'forward') i++
|
||||
if (direction == 'backward') i--
|
||||
if (direction === 'forward') i++
|
||||
if (direction === 'backward') i--
|
||||
}
|
||||
|
||||
return child || null
|
||||
|
@ -37,7 +37,7 @@ function getEventRange(event, editor) {
|
||||
if (editor.query('isVoid', node)) {
|
||||
const rect = target.getBoundingClientRect()
|
||||
const isPrevious =
|
||||
node.object == 'inline'
|
||||
node.object === 'inline'
|
||||
? x - rect.left < rect.left + rect.width - x
|
||||
: y - rect.top < rect.top + rect.height - y
|
||||
|
||||
|
@ -69,7 +69,7 @@ function getEventTransfer(event) {
|
||||
// Get and normalize files if they exist.
|
||||
if (transfer.items && transfer.items.length) {
|
||||
files = Array.from(transfer.items)
|
||||
.map(item => (item.kind == 'file' ? item.getAsFile() : null))
|
||||
.map(item => (item.kind === 'file' ? item.getAsFile() : null))
|
||||
.filter(exists => exists)
|
||||
} else if (transfer.files && transfer.files.length) {
|
||||
files = Array.from(transfer.files)
|
||||
@ -97,7 +97,7 @@ function getEventTransfer(event) {
|
||||
function getEmbeddedTypes(text) {
|
||||
const prefix = 'SLATE-DATA-EMBED::'
|
||||
|
||||
if (text.substring(0, prefix.length) != prefix) {
|
||||
if (text.substring(0, prefix.length) !== prefix) {
|
||||
return { TEXT: text }
|
||||
}
|
||||
|
||||
@ -147,7 +147,7 @@ function getType(transfer, type) {
|
||||
if (!transfer.types || !transfer.types.length) {
|
||||
// COMPAT: In IE 11, there is no `types` field but `getData('Text')`
|
||||
// is supported`. (2017/06/23)
|
||||
return type == TEXT ? transfer.getData('Text') || null : null
|
||||
return type === TEXT ? transfer.getData('Text') || null : null
|
||||
}
|
||||
|
||||
// COMPAT: In Edge, transfer.types doesn't respond to `indexOf`. (2017/10/25)
|
||||
|
@ -65,8 +65,8 @@ function scrollToSelection(selection) {
|
||||
const window = getWindow(selection.anchorNode)
|
||||
const scroller = findScrollContainer(selection.anchorNode, window)
|
||||
const isWindow =
|
||||
scroller == window.document.body ||
|
||||
scroller == window.document.documentElement
|
||||
scroller === window.document.body ||
|
||||
scroller === window.document.documentElement
|
||||
const backward = isBackward(selection)
|
||||
|
||||
const range = selection.getRangeAt(0).cloneRange()
|
||||
@ -79,8 +79,8 @@ function scrollToSelection(selection) {
|
||||
// https://bugs.webkit.org/show_bug.cgi?id=138949
|
||||
// https://bugs.chromium.org/p/chromium/issues/detail?id=435438
|
||||
if (IS_SAFARI) {
|
||||
if (range.collapsed && cursorRect.top == 0 && cursorRect.height == 0) {
|
||||
if (range.startOffset == 0) {
|
||||
if (range.collapsed && cursorRect.top === 0 && cursorRect.height === 0) {
|
||||
if (range.startOffset === 0) {
|
||||
range.setEnd(range.endContainer, 1)
|
||||
} else {
|
||||
range.setStart(range.startContainer, range.startOffset - 1)
|
||||
@ -88,7 +88,7 @@ function scrollToSelection(selection) {
|
||||
|
||||
cursorRect = range.getBoundingClientRect()
|
||||
|
||||
if (cursorRect.top == 0 && cursorRect.height == 0) {
|
||||
if (cursorRect.top === 0 && cursorRect.height === 0) {
|
||||
if (range.getClientRects().length) {
|
||||
cursorRect = range.getClientRects()[0]
|
||||
}
|
||||
|
@ -35,10 +35,10 @@ export default function setSelectionFromDOM(window, editor, domSelection) {
|
||||
if (
|
||||
anchorBlock &&
|
||||
!editor.isVoid(anchorBlock) &&
|
||||
anchor.offset == 0 &&
|
||||
anchor.offset === 0 &&
|
||||
focusBlock &&
|
||||
editor.isVoid(focusBlock) &&
|
||||
focus.offset != 0
|
||||
focus.offset !== 0
|
||||
) {
|
||||
range = range.setFocus(focus.setOffset(0))
|
||||
}
|
||||
@ -49,7 +49,7 @@ export default function setSelectionFromDOM(window, editor, domSelection) {
|
||||
if (
|
||||
anchorInline &&
|
||||
!editor.isVoid(anchorInline) &&
|
||||
anchor.offset == anchorText.text.length
|
||||
anchor.offset === anchorText.text.length
|
||||
) {
|
||||
const block = document.getClosestBlock(anchor.key)
|
||||
const nextText = block.getNextText(anchor.key)
|
||||
@ -59,7 +59,7 @@ export default function setSelectionFromDOM(window, editor, domSelection) {
|
||||
if (
|
||||
focusInline &&
|
||||
!editor.isVoid(focusInline) &&
|
||||
focus.offset == focusText.text.length
|
||||
focus.offset === focusText.text.length
|
||||
) {
|
||||
const block = document.getClosestBlock(focus.key)
|
||||
const nextText = block.getNextText(focus.key)
|
||||
|
@ -25,19 +25,19 @@ export default function setTextFromDomNode(window, editor, domNode) {
|
||||
// Get the text information.
|
||||
const { text } = leaf
|
||||
let { textContent } = domNode
|
||||
const isLastText = node == lastText
|
||||
const isLastLeaf = leaf == lastLeaf
|
||||
const isLastText = node === lastText
|
||||
const isLastLeaf = leaf === lastLeaf
|
||||
const lastChar = textContent.charAt(textContent.length - 1)
|
||||
|
||||
// COMPAT: If this is the last leaf, and the DOM text ends in a new line,
|
||||
// we will have added another new line in <Leaf>'s render method to account
|
||||
// for browsers collapsing a single trailing new lines, so remove it.
|
||||
if (isLastText && isLastLeaf && lastChar == '\n') {
|
||||
if (isLastText && isLastLeaf && lastChar === '\n') {
|
||||
textContent = textContent.slice(0, -1)
|
||||
}
|
||||
|
||||
// If the text is no different, abort.
|
||||
if (textContent == text) return
|
||||
if (textContent === text) return
|
||||
|
||||
// Determine what the selection should be after changing the text.
|
||||
// const delta = textContent.length - text.length
|
||||
|
@ -60,9 +60,10 @@ Commands.addMarkAtRange = (editor, range, mark) => {
|
||||
let index = 0
|
||||
let length = node.text.length
|
||||
|
||||
if (key == start.key) index = start.offset
|
||||
if (key == end.key) length = end.offset
|
||||
if (key == start.key && key == end.key) length = end.offset - start.offset
|
||||
if (key === start.key) index = start.offset
|
||||
if (key === end.key) length = end.offset
|
||||
if (key === start.key && key === end.key)
|
||||
length = end.offset - start.offset
|
||||
|
||||
editor.addMarkByKey(key, index, length, mark)
|
||||
})
|
||||
@ -109,11 +110,11 @@ Commands.deleteAtRange = (editor, range) => {
|
||||
// selection extends into the start of the end node, we actually want to
|
||||
// ignore that for UX reasons.
|
||||
const isHanging =
|
||||
startOffset == 0 &&
|
||||
endOffset == 0 &&
|
||||
isStartVoid == false &&
|
||||
startKey == startBlock.getFirstText().key &&
|
||||
endKey == endBlock.getFirstText().key
|
||||
startOffset === 0 &&
|
||||
endOffset === 0 &&
|
||||
isStartVoid === false &&
|
||||
startKey === startBlock.getFirstText().key &&
|
||||
endKey === endBlock.getFirstText().key
|
||||
|
||||
// If it's a hanging selection, nudge it back to end in the previous text.
|
||||
if (isHanging && isEndVoid) {
|
||||
@ -133,7 +134,7 @@ Commands.deleteAtRange = (editor, range) => {
|
||||
editor.removeNodeByKey(startVoid.key)
|
||||
|
||||
// If the start and end keys are the same, we're done.
|
||||
if (startKey == endKey) return
|
||||
if (startKey === endKey) return
|
||||
|
||||
// If there is no next text node, we're done.
|
||||
if (!nextText) return
|
||||
@ -162,10 +163,10 @@ Commands.deleteAtRange = (editor, range) => {
|
||||
|
||||
// If the start and end key are the same, and it was a hanging selection, we
|
||||
// can just remove the entire block.
|
||||
if (startKey == endKey && isHanging) {
|
||||
if (startKey === endKey && isHanging) {
|
||||
editor.removeNodeByKey(startBlock.key)
|
||||
return
|
||||
} else if (startKey == endKey) {
|
||||
} else if (startKey === endKey) {
|
||||
// Otherwise, if it wasn't hanging, we're inside a single text node, so we can
|
||||
// simply remove the text in the range.
|
||||
const index = startOffset
|
||||
@ -198,7 +199,7 @@ Commands.deleteAtRange = (editor, range) => {
|
||||
// but inside the end child, and remove them.
|
||||
child = startText
|
||||
|
||||
while (child.key != startChild.key) {
|
||||
while (child.key !== startChild.key) {
|
||||
const parent = document.getParent(child.key)
|
||||
const index = parent.nodes.indexOf(child)
|
||||
const afters = parent.nodes.slice(index + 1)
|
||||
@ -222,7 +223,7 @@ Commands.deleteAtRange = (editor, range) => {
|
||||
// Remove the nodes before the end text node in the tree.
|
||||
child = endText
|
||||
|
||||
while (child.key != endChild.key) {
|
||||
while (child.key !== endChild.key) {
|
||||
const parent = document.getParent(child.key)
|
||||
const index = parent.nodes.indexOf(child)
|
||||
const befores = parent.nodes.slice(0, index)
|
||||
@ -235,22 +236,22 @@ Commands.deleteAtRange = (editor, range) => {
|
||||
}
|
||||
|
||||
// Remove any overlapping text content from the leaf text nodes.
|
||||
if (startLength != 0) {
|
||||
if (startLength !== 0) {
|
||||
editor.removeTextByKey(startKey, startOffset, startLength)
|
||||
}
|
||||
|
||||
if (endLength != 0) {
|
||||
if (endLength !== 0) {
|
||||
editor.removeTextByKey(endKey, 0, endOffset)
|
||||
}
|
||||
|
||||
// If the start and end blocks aren't the same, move and merge the end block
|
||||
// into the start block.
|
||||
if (startBlock.key != endBlock.key) {
|
||||
if (startBlock.key !== endBlock.key) {
|
||||
document = editor.value.document
|
||||
const lonely = document.getFurthestOnlyChildAncestor(endBlock.key)
|
||||
|
||||
// Move the end block to be right after the start block.
|
||||
if (endParentIndex != startParentIndex + 1) {
|
||||
if (endParentIndex !== startParentIndex + 1) {
|
||||
editor.moveNodeByKey(
|
||||
endBlock.key,
|
||||
startParent.key,
|
||||
@ -348,7 +349,7 @@ Commands.deleteBackwardAtRange = (editor, range, n = 1) => {
|
||||
|
||||
// If we're deleting by one character and the previous text node is not
|
||||
// inside the current block, we need to merge the two blocks together.
|
||||
if (n == 1 && prevBlock != block) {
|
||||
if (n === 1 && prevBlock !== block) {
|
||||
range = range.moveAnchorTo(prev.key, prev.text.length)
|
||||
editor.deleteAtRange(range)
|
||||
return
|
||||
@ -501,7 +502,7 @@ Commands.deleteForwardAtRange = (editor, range, n = 1) => {
|
||||
|
||||
// If we're deleting by one character and the previous text node is not
|
||||
// inside the current block, we need to merge the two blocks together.
|
||||
if (n == 1 && nextBlock != block) {
|
||||
if (n === 1 && nextBlock !== block) {
|
||||
range = range.moveFocusTo(next.key, 0)
|
||||
editor.deleteAtRange(range)
|
||||
return
|
||||
@ -742,10 +743,10 @@ Commands.insertFragmentAtRange = (editor, range, fragment) => {
|
||||
|
||||
// If the first and last block aren't the same, we need to insert all of the
|
||||
// nodes after the insertion node's first block at the index.
|
||||
if (firstBlock != lastBlock) {
|
||||
if (firstBlock !== lastBlock) {
|
||||
const lonelyParent = insertionNode.getFurthest(
|
||||
firstBlock.key,
|
||||
p => p.nodes.size == 1
|
||||
p => p.nodes.size === 1
|
||||
)
|
||||
const lonelyChild = lonelyParent || firstBlock
|
||||
|
||||
@ -759,7 +760,7 @@ Commands.insertFragmentAtRange = (editor, range, fragment) => {
|
||||
}
|
||||
|
||||
// Check if we need to split the node.
|
||||
if (start.offset != 0) {
|
||||
if (start.offset !== 0) {
|
||||
editor.splitDescendantsByKey(startChild.key, start.key, start.offset)
|
||||
}
|
||||
|
||||
@ -772,12 +773,12 @@ Commands.insertFragmentAtRange = (editor, range, fragment) => {
|
||||
// If the first and last block aren't the same, we need to move any of the
|
||||
// starting block's children after the split into the last block of the
|
||||
// fragment, which has already been inserted.
|
||||
if (firstBlock != lastBlock) {
|
||||
if (firstBlock !== lastBlock) {
|
||||
const nextChild = isAtStart
|
||||
? startChild
|
||||
: startBlock.getNextSibling(startChild.key)
|
||||
const nextNodes = nextChild
|
||||
? startBlock.nodes.skipUntil(n => n.key == nextChild.key)
|
||||
? startBlock.nodes.skipUntil(n => n.key === nextChild.key)
|
||||
: List()
|
||||
const lastIndex = lastBlock.nodes.size
|
||||
|
||||
@ -803,7 +804,7 @@ Commands.insertFragmentAtRange = (editor, range, fragment) => {
|
||||
const inlineIndex = startBlock.nodes.indexOf(inlineChild)
|
||||
|
||||
firstBlock.nodes.forEach((inline, i) => {
|
||||
const o = start.offset == 0 ? 0 : 1
|
||||
const o = start.offset === 0 ? 0 : 1
|
||||
const newIndex = inlineIndex + i + o
|
||||
editor.insertNodeByKey(startBlock.key, newIndex, inline)
|
||||
})
|
||||
@ -918,9 +919,10 @@ Commands.removeMarkAtRange = (editor, range, mark) => {
|
||||
let index = 0
|
||||
let length = node.text.length
|
||||
|
||||
if (key == start.key) index = start.offset
|
||||
if (key == end.key) length = end.offset
|
||||
if (key == start.key && key == end.key) length = end.offset - start.offset
|
||||
if (key === start.key) index = start.offset
|
||||
if (key === end.key) length = end.offset
|
||||
if (key === start.key && key === end.key)
|
||||
length = end.offset - start.offset
|
||||
|
||||
editor.removeMarkByKey(key, index, length, mark)
|
||||
})
|
||||
@ -949,12 +951,12 @@ Commands.setBlocksAtRange = (editor, range, properties) => {
|
||||
// selection extends into the start of the end node, we actually want to
|
||||
// ignore that for UX reasons.
|
||||
const isHanging =
|
||||
isCollapsed == false &&
|
||||
start.offset == 0 &&
|
||||
end.offset == 0 &&
|
||||
isStartVoid == false &&
|
||||
start.key == startBlock.getFirstText().key &&
|
||||
end.key == endBlock.getFirstText().key
|
||||
isCollapsed === false &&
|
||||
start.offset === 0 &&
|
||||
end.offset === 0 &&
|
||||
isStartVoid === false &&
|
||||
start.key === startBlock.getFirstText().key &&
|
||||
end.key === endBlock.getFirstText().key
|
||||
|
||||
// If it's a hanging selection, ignore the last block.
|
||||
const sets = isHanging ? blocks.slice(0, -1) : blocks
|
||||
@ -1004,7 +1006,7 @@ Commands.splitBlockAtRange = (editor, range, height = 1) => {
|
||||
let parent = document.getClosestBlock(node.key)
|
||||
let h = 0
|
||||
|
||||
while (parent && parent.object == 'block' && h < height) {
|
||||
while (parent && parent.object === 'block' && h < height) {
|
||||
node = parent
|
||||
parent = document.getClosestBlock(parent.key)
|
||||
h++
|
||||
@ -1050,7 +1052,7 @@ Commands.splitInlineAtRange = (editor, range, height = Infinity) => {
|
||||
let parent = document.getClosestInline(node.key)
|
||||
let h = 0
|
||||
|
||||
while (parent && parent.object == 'inline' && h < height) {
|
||||
while (parent && parent.object === 'inline' && h < height) {
|
||||
node = parent
|
||||
parent = document.getClosestInline(parent.key)
|
||||
h++
|
||||
@ -1102,8 +1104,8 @@ Commands.unwrapBlockAtRange = (editor, range, properties) => {
|
||||
const wrappers = blocks
|
||||
.map(block => {
|
||||
return document.getClosest(block.key, parent => {
|
||||
if (parent.object != 'block') return false
|
||||
if (properties.type != null && parent.type != properties.type)
|
||||
if (parent.object !== 'block') return false
|
||||
if (properties.type != null && parent.type !== properties.type)
|
||||
return false
|
||||
if (properties.data != null && !parent.data.isSuperset(properties.data))
|
||||
return false
|
||||
@ -1122,25 +1124,25 @@ Commands.unwrapBlockAtRange = (editor, range, properties) => {
|
||||
const index = parent.nodes.indexOf(block)
|
||||
|
||||
const children = block.nodes.filter(child => {
|
||||
return blocks.some(b => child == b || child.hasDescendant(b.key))
|
||||
return blocks.some(b => child === b || child.hasDescendant(b.key))
|
||||
})
|
||||
|
||||
const firstMatch = children.first()
|
||||
const lastMatch = children.last()
|
||||
|
||||
if (first == firstMatch && last == lastMatch) {
|
||||
if (first === firstMatch && last === lastMatch) {
|
||||
block.nodes.forEach((child, i) => {
|
||||
editor.moveNodeByKey(child.key, parent.key, index + i)
|
||||
})
|
||||
|
||||
editor.removeNodeByKey(block.key)
|
||||
} else if (last == lastMatch) {
|
||||
block.nodes.skipUntil(n => n == firstMatch).forEach((child, i) => {
|
||||
} else if (last === lastMatch) {
|
||||
block.nodes.skipUntil(n => n === firstMatch).forEach((child, i) => {
|
||||
editor.moveNodeByKey(child.key, parent.key, index + 1 + i)
|
||||
})
|
||||
} else if (first == firstMatch) {
|
||||
} else if (first === firstMatch) {
|
||||
block.nodes
|
||||
.takeUntil(n => n == lastMatch)
|
||||
.takeUntil(n => n === lastMatch)
|
||||
.push(lastMatch)
|
||||
.forEach((child, i) => {
|
||||
editor.moveNodeByKey(child.key, parent.key, index + i)
|
||||
@ -1153,7 +1155,7 @@ Commands.unwrapBlockAtRange = (editor, range, properties) => {
|
||||
document = editor.value.document
|
||||
|
||||
children.forEach((child, i) => {
|
||||
if (i == 0) {
|
||||
if (i === 0) {
|
||||
const extra = child
|
||||
child = document.getNextBlock(child.key)
|
||||
editor.removeNodeByKey(extra.key)
|
||||
@ -1183,8 +1185,8 @@ Commands.unwrapInlineAtRange = (editor, range, properties) => {
|
||||
const inlines = texts
|
||||
.map(text => {
|
||||
return document.getClosest(text.key, parent => {
|
||||
if (parent.object != 'inline') return false
|
||||
if (properties.type != null && parent.type != properties.type)
|
||||
if (parent.object !== 'inline') return false
|
||||
if (properties.type != null && parent.type !== properties.type)
|
||||
return false
|
||||
if (properties.data != null && !parent.data.isSuperset(properties.data))
|
||||
return false
|
||||
@ -1237,7 +1239,7 @@ Commands.wrapBlockAtRange = (editor, range, block) => {
|
||||
} else {
|
||||
// Determine closest shared parent to all blocks in selection.
|
||||
parent = document.getClosest(firstblock.key, p1 => {
|
||||
return !!document.getClosest(lastblock.key, p2 => p1 == p2)
|
||||
return !!document.getClosest(lastblock.key, p2 => p1 === p2)
|
||||
})
|
||||
}
|
||||
|
||||
@ -1248,8 +1250,8 @@ Commands.wrapBlockAtRange = (editor, range, block) => {
|
||||
// selection.
|
||||
if (siblings == null) {
|
||||
const indexes = parent.nodes.reduce((ind, node, i) => {
|
||||
if (node == firstblock || node.hasDescendant(firstblock.key)) ind[0] = i
|
||||
if (node == lastblock || node.hasDescendant(lastblock.key)) ind[1] = i
|
||||
if (node === firstblock || node.hasDescendant(firstblock.key)) ind[0] = i
|
||||
if (node === lastblock || node.hasDescendant(lastblock.key)) ind[1] = i
|
||||
return ind
|
||||
}, [])
|
||||
|
||||
@ -1313,7 +1315,7 @@ Commands.wrapInlineAtRange = (editor, range, inline) => {
|
||||
let endChild = endBlock.getFurthestAncestor(end.key)
|
||||
|
||||
editor.withoutNormalizing(() => {
|
||||
if (!startInline || startInline != endInline) {
|
||||
if (!startInline || startInline !== endInline) {
|
||||
editor.splitDescendantsByKey(endChild.key, end.key, end.offset)
|
||||
editor.splitDescendantsByKey(startChild.key, start.key, start.offset)
|
||||
}
|
||||
@ -1326,7 +1328,7 @@ Commands.wrapInlineAtRange = (editor, range, inline) => {
|
||||
const startIndex = startBlock.nodes.indexOf(startChild)
|
||||
const endIndex = endBlock.nodes.indexOf(endChild)
|
||||
|
||||
if (startInline && startInline == endInline) {
|
||||
if (startInline && startInline === endInline) {
|
||||
const text = startBlock
|
||||
.getTextsAtRange(range)
|
||||
.get(0)
|
||||
@ -1349,7 +1351,7 @@ Commands.wrapInlineAtRange = (editor, range, inline) => {
|
||||
isFocused: true,
|
||||
}
|
||||
editor.select(rng)
|
||||
} else if (startBlock == endBlock) {
|
||||
} else if (startBlock === endBlock) {
|
||||
document = editor.value.document
|
||||
startBlock = document.getClosestBlock(start.key)
|
||||
startChild = startBlock.getFurthestAncestor(start.key)
|
||||
@ -1357,12 +1359,12 @@ Commands.wrapInlineAtRange = (editor, range, inline) => {
|
||||
const startInner = document.getNextSibling(startChild.key)
|
||||
const startInnerIndex = startBlock.nodes.indexOf(startInner)
|
||||
const endInner =
|
||||
start.key == end.key
|
||||
start.key === end.key
|
||||
? startInner
|
||||
: startBlock.getFurthestAncestor(end.key)
|
||||
const inlines = startBlock.nodes
|
||||
.skipUntil(n => n == startInner)
|
||||
.takeUntil(n => n == endInner)
|
||||
.skipUntil(n => n === startInner)
|
||||
.takeUntil(n => n === endInner)
|
||||
.push(endInner)
|
||||
|
||||
const node = inline.regenerateKey()
|
||||
@ -1415,7 +1417,7 @@ Commands.wrapTextAtRange = (editor, range, prefix, suffix = prefix) => {
|
||||
const startRange = range.moveToStart()
|
||||
let endRange = range.moveToEnd()
|
||||
|
||||
if (start.key == end.key) {
|
||||
if (start.key === end.key) {
|
||||
endRange = endRange.moveForward(prefix.length)
|
||||
}
|
||||
|
||||
|
@ -165,7 +165,7 @@ Commands.mergeNodeByPath = (editor, path) => {
|
||||
}
|
||||
|
||||
const position =
|
||||
previous.object == 'text' ? previous.text.length : previous.nodes.size
|
||||
previous.object === 'text' ? previous.text.length : previous.nodes.size
|
||||
|
||||
editor.applyOperation({
|
||||
type: 'merge_node',
|
||||
@ -561,7 +561,7 @@ Commands.splitDescendantsByPath = (editor, path, textPath, textOffset) => {
|
||||
const text = document.assertNode(textPath)
|
||||
const ancestors = document.getAncestors(textPath)
|
||||
const nodes = ancestors
|
||||
.skipUntil(a => a.key == node.key)
|
||||
.skipUntil(a => a.key === node.key)
|
||||
.reverse()
|
||||
.unshift(text)
|
||||
|
||||
|
@ -666,7 +666,7 @@ function pointEdgeObject(editor, point, edge, object) {
|
||||
const Edge = edge.slice(0, 1).toUpperCase() + edge.slice(1)
|
||||
const Object = object.slice(0, 1).toUpperCase() + object.slice(1)
|
||||
const method = `move${Point}To${Edge}OfNode`
|
||||
const getNode = object == 'text' ? 'getNode' : `getClosest${Object}`
|
||||
const getNode = object === 'text' ? 'getNode' : `getClosest${Object}`
|
||||
const { value } = editor
|
||||
const { document, selection } = value
|
||||
const p = selection[point]
|
||||
@ -681,7 +681,7 @@ function pointEdgeSideObject(editor, point, edge, side, object) {
|
||||
const Side = side.slice(0, 1).toUpperCase() + side.slice(1)
|
||||
const Object = object.slice(0, 1).toUpperCase() + object.slice(1)
|
||||
const method = `move${Point}To${Edge}OfNode`
|
||||
const getNode = object == 'text' ? 'getNode' : `getClosest${Object}`
|
||||
const getNode = object === 'text' ? 'getNode' : `getClosest${Object}`
|
||||
const getDirectionNode = `get${Side}${Object}`
|
||||
const { value } = editor
|
||||
const { document, selection } = value
|
||||
|
@ -320,7 +320,7 @@ Commands.insertText = (editor, text, marks) => {
|
||||
|
||||
// If the text was successfully inserted, and the selection had marks on it,
|
||||
// unset the selection's marks.
|
||||
if (selection.marks && document != editor.value.document) {
|
||||
if (selection.marks && document !== editor.value.document) {
|
||||
editor.select({ marks: null })
|
||||
}
|
||||
}
|
||||
@ -519,7 +519,7 @@ Commands.wrapText = (editor, prefix, suffix = prefix) => {
|
||||
|
||||
// There's a chance that the selection points moved "through" each other,
|
||||
// resulting in a now-incorrect selection direction.
|
||||
if (selection.isForward != editor.value.selection.isForward) {
|
||||
if (selection.isForward !== editor.value.selection.isForward) {
|
||||
editor.flip()
|
||||
}
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ class ElementInterface {
|
||||
return false
|
||||
}
|
||||
|
||||
if (child.object != 'text') {
|
||||
if (child.object !== 'text') {
|
||||
ret = child.forEachDescendant(iterator)
|
||||
return ret
|
||||
}
|
||||
@ -261,7 +261,7 @@ class ElementInterface {
|
||||
|
||||
getBlocksAsArray() {
|
||||
return this.nodes.reduce((array, child) => {
|
||||
if (child.object != 'block') return array
|
||||
if (child.object !== 'block') return array
|
||||
if (!child.isLeafBlock()) return array.concat(child.getBlocksAsArray())
|
||||
array.push(child)
|
||||
return array
|
||||
@ -321,9 +321,9 @@ class ElementInterface {
|
||||
|
||||
getBlocksByTypeAsArray(type) {
|
||||
return this.nodes.reduce((array, node) => {
|
||||
if (node.object != 'block') {
|
||||
if (node.object !== 'block') {
|
||||
return array
|
||||
} else if (node.isLeafBlock() && node.type == type) {
|
||||
} else if (node.isLeafBlock() && node.type === type) {
|
||||
array.push(node)
|
||||
return array
|
||||
} else {
|
||||
@ -622,7 +622,7 @@ class ElementInterface {
|
||||
let array = []
|
||||
|
||||
this.nodes.forEach(child => {
|
||||
if (child.object == 'text') return
|
||||
if (child.object === 'text') return
|
||||
|
||||
if (child.isLeafInline()) {
|
||||
array.push(child)
|
||||
@ -688,9 +688,9 @@ class ElementInterface {
|
||||
|
||||
getInlinesByTypeAsArray(type) {
|
||||
const array = this.nodes.reduce((inlines, node) => {
|
||||
if (node.object == 'text') {
|
||||
if (node.object === 'text') {
|
||||
return inlines
|
||||
} else if (node.isLeafInline() && node.type == type) {
|
||||
} else if (node.isLeafInline() && node.type === type) {
|
||||
inlines.push(node)
|
||||
return inlines
|
||||
} else {
|
||||
@ -887,8 +887,8 @@ class ElementInterface {
|
||||
|
||||
getMarksByTypeAsArray(type) {
|
||||
const array = this.nodes.reduce((memo, node) => {
|
||||
return node.object == 'text'
|
||||
? memo.concat(node.getMarksAsArray().filter(m => m.type == type))
|
||||
return node.object === 'text'
|
||||
? memo.concat(node.getMarksAsArray().filter(m => m.type === type))
|
||||
: memo.concat(node.getMarksByTypeAsArray(type))
|
||||
}, [])
|
||||
|
||||
@ -906,7 +906,7 @@ class ElementInterface {
|
||||
const child = this.assertDescendant(key)
|
||||
let last
|
||||
|
||||
if (child.object == 'block') {
|
||||
if (child.object === 'block') {
|
||||
last = child.getLastText()
|
||||
} else {
|
||||
const block = this.getClosestBlock(key)
|
||||
@ -1060,7 +1060,7 @@ class ElementInterface {
|
||||
// Calculate the offset of the nodes before the highest child.
|
||||
const child = this.getFurthestAncestor(key)
|
||||
const offset = this.nodes
|
||||
.takeUntil(n => n == child)
|
||||
.takeUntil(n => n === child)
|
||||
.reduce((memo, n) => memo + n.text.length, 0)
|
||||
|
||||
// Recurse if need be.
|
||||
@ -1205,7 +1205,7 @@ class ElementInterface {
|
||||
const child = this.assertDescendant(key)
|
||||
let first
|
||||
|
||||
if (child.object == 'block') {
|
||||
if (child.object === 'block') {
|
||||
first = child.getFirstText()
|
||||
} else {
|
||||
const block = this.getClosestBlock(key)
|
||||
@ -1361,7 +1361,7 @@ class ElementInterface {
|
||||
|
||||
// PERF: if the start and end keys are the same, just check for the child
|
||||
// that contains that single key.
|
||||
if (start.key == end.key) {
|
||||
if (start.key === end.key) {
|
||||
const child = this.getFurthestAncestor(start.key)
|
||||
const index = child ? this.nodes.indexOf(child) : null
|
||||
return { start: index, end: index + 1 }
|
||||
@ -1372,9 +1372,9 @@ class ElementInterface {
|
||||
let endIndex = null
|
||||
|
||||
this.nodes.forEach((child, i) => {
|
||||
if (child.object == 'text') {
|
||||
if (startIndex == null && child.key == start.key) startIndex = i
|
||||
if (endIndex == null && child.key == end.key) endIndex = i + 1
|
||||
if (child.object === 'text') {
|
||||
if (startIndex == null && child.key === start.key) startIndex = i
|
||||
if (endIndex == null && child.key === end.key) endIndex = i + 1
|
||||
} else {
|
||||
if (startIndex == null && child.hasDescendant(start.key)) startIndex = i
|
||||
if (endIndex == null && child.hasDescendant(end.key)) endIndex = i + 1
|
||||
@ -1443,7 +1443,7 @@ class ElementInterface {
|
||||
let array = []
|
||||
|
||||
this.nodes.forEach(node => {
|
||||
if (node.object == 'text') {
|
||||
if (node.object === 'text') {
|
||||
array.push(node)
|
||||
} else {
|
||||
array = array.concat(node.getTextsAsArray())
|
||||
@ -1498,7 +1498,7 @@ class ElementInterface {
|
||||
|
||||
// PERF: the most common case is when the range is in a single text node,
|
||||
// where we can avoid a lot of iterating of the tree.
|
||||
if (startKey == endKey) return [startText]
|
||||
if (startKey === endKey) return [startText]
|
||||
|
||||
const endText = this.getDescendant(endKey)
|
||||
const texts = this.getTextsAsArray()
|
||||
|
@ -95,7 +95,7 @@ class NodeInterface {
|
||||
let descendant = null
|
||||
|
||||
const found = this.nodes.findLast(node => {
|
||||
if (node.object == 'text') return true
|
||||
if (node.object === 'text') return true
|
||||
descendant = node.getLastText()
|
||||
return descendant
|
||||
})
|
||||
|
@ -36,7 +36,7 @@ class Block extends Record(DEFAULTS) {
|
||||
return attrs
|
||||
}
|
||||
|
||||
if (typeof attrs == 'string') {
|
||||
if (typeof attrs === 'string') {
|
||||
attrs = { type: attrs }
|
||||
}
|
||||
|
||||
@ -81,7 +81,7 @@ class Block extends Record(DEFAULTS) {
|
||||
|
||||
const { data = {}, key = KeyUtils.create(), nodes = [], type } = object
|
||||
|
||||
if (typeof type != 'string') {
|
||||
if (typeof type !== 'string') {
|
||||
throw new Error('`Block.fromJSON` requires a `type` string.')
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ class Inline extends Record(DEFAULTS) {
|
||||
return attrs
|
||||
}
|
||||
|
||||
if (typeof attrs == 'string') {
|
||||
if (typeof attrs === 'string') {
|
||||
attrs = { type: attrs }
|
||||
}
|
||||
|
||||
@ -81,7 +81,7 @@ class Inline extends Record(DEFAULTS) {
|
||||
|
||||
const { data = {}, key = KeyUtils.create(), nodes = [], type } = object
|
||||
|
||||
if (typeof type != 'string') {
|
||||
if (typeof type !== 'string') {
|
||||
throw new Error('`Inline.fromJS` requires a `type` string.')
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ class Leaf extends Record(DEFAULTS) {
|
||||
return attrs
|
||||
}
|
||||
|
||||
if (typeof attrs == 'string') {
|
||||
if (typeof attrs === 'string') {
|
||||
attrs = { text: attrs }
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ class Mark extends Record(DEFAULTS) {
|
||||
return attrs
|
||||
}
|
||||
|
||||
if (typeof attrs == 'string') {
|
||||
if (typeof attrs === 'string') {
|
||||
attrs = { type: attrs }
|
||||
}
|
||||
|
||||
@ -83,7 +83,7 @@ class Mark extends Record(DEFAULTS) {
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof attrs == 'string') {
|
||||
if (typeof attrs === 'string') {
|
||||
return { type: attrs }
|
||||
}
|
||||
|
||||
@ -109,7 +109,7 @@ class Mark extends Record(DEFAULTS) {
|
||||
static fromJSON(object) {
|
||||
const { data = {}, type } = object
|
||||
|
||||
if (typeof type != 'string') {
|
||||
if (typeof type !== 'string') {
|
||||
throw new Error('`Mark.fromJS` requires a `type` string.')
|
||||
}
|
||||
|
||||
|
@ -93,7 +93,7 @@ class Node {
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof attrs == 'string') {
|
||||
if (typeof attrs === 'string') {
|
||||
return { type: attrs }
|
||||
}
|
||||
|
||||
|
@ -134,10 +134,10 @@ class Operation extends Record(DEFAULTS) {
|
||||
if (v === undefined) {
|
||||
// Skip keys for objects that should not be serialized, and are only used
|
||||
// for providing the local-only invert behavior for the history stack.
|
||||
if (key == 'document') continue
|
||||
if (key == 'selection') continue
|
||||
if (key == 'value') continue
|
||||
if (key == 'node' && type != 'insert_node') continue
|
||||
if (key === 'document') continue
|
||||
if (key === 'selection') continue
|
||||
if (key === 'value') continue
|
||||
if (key === 'node' && type !== 'insert_node') continue
|
||||
|
||||
throw new Error(
|
||||
`\`Operation.fromJSON\` was passed a "${type}" operation without the required "${key}" attribute.`
|
||||
@ -254,43 +254,43 @@ class Operation extends Record(DEFAULTS) {
|
||||
|
||||
// Skip keys for objects that should not be serialized, and are only used
|
||||
// for providing the local-only invert behavior for the history stack.
|
||||
if (key == 'document') continue
|
||||
if (key == 'selection') continue
|
||||
if (key == 'value') continue
|
||||
if (key == 'node' && type != 'insert_node') continue
|
||||
if (key === 'document') continue
|
||||
if (key === 'selection') continue
|
||||
if (key === 'value') continue
|
||||
if (key === 'node' && type !== 'insert_node') continue
|
||||
|
||||
if (
|
||||
key == 'mark' ||
|
||||
key == 'marks' ||
|
||||
key == 'node' ||
|
||||
key == 'path' ||
|
||||
key == 'newPath'
|
||||
key === 'mark' ||
|
||||
key === 'marks' ||
|
||||
key === 'node' ||
|
||||
key === 'path' ||
|
||||
key === 'newPath'
|
||||
) {
|
||||
value = value.toJSON()
|
||||
}
|
||||
|
||||
if (key == 'properties' && type == 'merge_node') {
|
||||
if (key === 'properties' && type === 'merge_node') {
|
||||
const v = {}
|
||||
if ('data' in value) v.data = value.data.toJS()
|
||||
if ('type' in value) v.type = value.type
|
||||
value = v
|
||||
}
|
||||
|
||||
if (key == 'properties' && type == 'set_mark') {
|
||||
if (key === 'properties' && type === 'set_mark') {
|
||||
const v = {}
|
||||
if ('data' in value) v.data = value.data.toJS()
|
||||
if ('type' in value) v.type = value.type
|
||||
value = v
|
||||
}
|
||||
|
||||
if (key == 'properties' && type == 'set_node') {
|
||||
if (key === 'properties' && type === 'set_node') {
|
||||
const v = {}
|
||||
if ('data' in value) v.data = value.data.toJS()
|
||||
if ('type' in value) v.type = value.type
|
||||
value = v
|
||||
}
|
||||
|
||||
if (key == 'properties' && type == 'set_selection') {
|
||||
if (key === 'properties' && type === 'set_selection') {
|
||||
const v = {}
|
||||
if ('anchor' in value) v.anchor = value.anchor.toJSON()
|
||||
if ('focus' in value) v.focus = value.focus.toJSON()
|
||||
@ -299,14 +299,14 @@ class Operation extends Record(DEFAULTS) {
|
||||
value = v
|
||||
}
|
||||
|
||||
if (key == 'properties' && type == 'set_value') {
|
||||
if (key === 'properties' && type === 'set_value') {
|
||||
const v = {}
|
||||
if ('data' in value) v.data = value.data.toJS()
|
||||
if ('decorations' in value) v.decorations = value.decorations.toJS()
|
||||
value = v
|
||||
}
|
||||
|
||||
if (key == 'properties' && type == 'split_node') {
|
||||
if (key === 'properties' && type === 'split_node') {
|
||||
const v = {}
|
||||
if ('data' in value) v.data = value.data.toJS()
|
||||
if ('type' in value) v.type = value.type
|
||||
|
@ -236,7 +236,7 @@ class Point extends Record(DEFAULTS) {
|
||||
if (this.isUnset) return false
|
||||
|
||||
// PERF: Do a check for a `0` offset first since it's quickest.
|
||||
if (this.offset != 0) return false
|
||||
if (this.offset !== 0) return false
|
||||
|
||||
const first = node.getFirstText()
|
||||
const is = this.key === first.key
|
||||
@ -407,7 +407,7 @@ class Point extends Record(DEFAULTS) {
|
||||
*/
|
||||
|
||||
setKey(key) {
|
||||
if (key !== null) {
|
||||
if (key != null) {
|
||||
key = KeyUtils.create(key)
|
||||
}
|
||||
|
||||
@ -435,7 +435,7 @@ class Point extends Record(DEFAULTS) {
|
||||
*/
|
||||
|
||||
setPath(path) {
|
||||
if (path !== null) {
|
||||
if (path != null) {
|
||||
path = PathUtils.create(path)
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ class Text extends Record(DEFAULTS) {
|
||||
return attrs
|
||||
}
|
||||
|
||||
if (typeof attrs == 'string') {
|
||||
if (typeof attrs === 'string') {
|
||||
attrs = { leaves: [{ text: attrs }] }
|
||||
}
|
||||
|
||||
@ -250,8 +250,8 @@ class Text extends Record(DEFAULTS) {
|
||||
|
||||
decorations.forEach(dec => {
|
||||
const { start, end, mark } = dec
|
||||
const hasStart = start.key == key
|
||||
const hasEnd = end.key == key
|
||||
const hasStart = start.key === key
|
||||
const hasEnd = end.key === key
|
||||
|
||||
if (hasStart && hasEnd) {
|
||||
const index = hasStart ? start.offset : 0
|
||||
|
@ -576,8 +576,8 @@ class Value extends Record(DEFAULTS) {
|
||||
let value = this
|
||||
let { document } = value
|
||||
const node = document.assertNode(path)
|
||||
const first = node.object == 'text' ? node : node.getFirstText() || node
|
||||
const last = node.object == 'text' ? node : node.getLastText() || node
|
||||
const first = node.object === 'text' ? node : node.getFirstText() || node
|
||||
const last = node.object === 'text' ? node : node.getLastText() || node
|
||||
const prev = document.getPreviousText(first.key)
|
||||
const next = document.getNextText(last.key)
|
||||
|
||||
|
@ -127,7 +127,7 @@ function getIn(map, keys) {
|
||||
for (let key of keys) {
|
||||
if (key === undefined) {
|
||||
key = UNDEFINED
|
||||
} else if (key === null) {
|
||||
} else if (key == null) {
|
||||
key = NULL
|
||||
}
|
||||
|
||||
@ -158,7 +158,7 @@ function setIn(map, keys, value) {
|
||||
for (let key of keys) {
|
||||
if (key === undefined) {
|
||||
key = UNDEFINED
|
||||
} else if (key === null) {
|
||||
} else if (key == null) {
|
||||
key = NULL
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ export const schema = {
|
||||
},
|
||||
],
|
||||
normalize: (editor, { code, child }) => {
|
||||
if (code == 'child_object_invalid') {
|
||||
if (code === 'child_object_invalid') {
|
||||
editor.wrapBlockByKey(child.key, 'paragraph')
|
||||
}
|
||||
},
|
||||
|
@ -16,7 +16,7 @@ export const schema = {
|
||||
},
|
||||
],
|
||||
normalize: (editor, { code, node, index }) => {
|
||||
if (code == 'child_max_invalid') {
|
||||
if (code === 'child_max_invalid') {
|
||||
editor.mergeNodeByKey(node.nodes.get(index).key)
|
||||
}
|
||||
},
|
||||
|
@ -13,7 +13,7 @@ export const schema = {
|
||||
},
|
||||
],
|
||||
normalize: (editor, { code, node, index }) => {
|
||||
if (code == 'child_min_invalid') {
|
||||
if (code === 'child_min_invalid') {
|
||||
editor.insertNodeByKey(node.key, index, {
|
||||
object: 'block',
|
||||
type: 'paragraph',
|
||||
|
@ -17,7 +17,7 @@ export const schema = {
|
||||
},
|
||||
],
|
||||
normalize: (editor, { code, node, index }) => {
|
||||
if (code == 'child_min_invalid' && index == 0) {
|
||||
if (code === 'child_min_invalid' && index === 0) {
|
||||
editor.insertNodeByKey(node.key, index, {
|
||||
object: 'block',
|
||||
type: 'title',
|
||||
|
@ -12,7 +12,7 @@ export const schema = {
|
||||
},
|
||||
],
|
||||
normalize: (editor, { code, child }) => {
|
||||
if (code == 'child_type_invalid') {
|
||||
if (code === 'child_type_invalid') {
|
||||
editor.wrapBlockByKey(child.key, 'paragraph')
|
||||
}
|
||||
},
|
||||
|
@ -13,7 +13,7 @@ export const schema = {
|
||||
},
|
||||
],
|
||||
normalize: (editor, { code, node, child }) => {
|
||||
if (code == 'child_unknown') {
|
||||
if (code === 'child_unknown') {
|
||||
const previous = node.getPreviousSibling(child.key)
|
||||
const offset = previous.nodes.size
|
||||
|
||||
|
@ -8,7 +8,7 @@ export const schema = {
|
||||
quote: {
|
||||
first: [{ object: 'block' }],
|
||||
normalize: (editor, { code, child }) => {
|
||||
if (code == 'first_child_object_invalid') {
|
||||
if (code === 'first_child_object_invalid') {
|
||||
editor.wrapBlockByKey(child.key, 'paragraph')
|
||||
}
|
||||
},
|
||||
|
@ -8,7 +8,7 @@ export const schema = {
|
||||
quote: {
|
||||
first: [{ type: 'paragraph' }],
|
||||
normalize: (editor, { code, child }) => {
|
||||
if (code == 'first_child_type_invalid') {
|
||||
if (code === 'first_child_type_invalid') {
|
||||
editor.wrapBlockByKey(child.key, 'paragraph')
|
||||
}
|
||||
},
|
||||
|
@ -8,7 +8,7 @@ export const schema = {
|
||||
quote: {
|
||||
last: [{ object: 'block' }],
|
||||
normalize: (editor, { code, child }) => {
|
||||
if (code == 'last_child_object_invalid') {
|
||||
if (code === 'last_child_object_invalid') {
|
||||
editor.wrapBlockByKey(child.key, 'paragraph')
|
||||
}
|
||||
},
|
||||
|
@ -8,7 +8,7 @@ export const schema = {
|
||||
quote: {
|
||||
last: [{ type: 'paragraph' }],
|
||||
normalize: (editor, { code, child }) => {
|
||||
if (code == 'last_child_type_invalid') {
|
||||
if (code === 'last_child_type_invalid') {
|
||||
editor.wrapBlockByKey(child.key, 'paragraph')
|
||||
}
|
||||
},
|
||||
|
@ -7,7 +7,7 @@ export const schema = {
|
||||
{
|
||||
match: [{ object: 'block' }],
|
||||
data: {
|
||||
thing: v => v == 'value',
|
||||
thing: v => v === 'value',
|
||||
},
|
||||
},
|
||||
],
|
||||
|
@ -7,7 +7,7 @@ export const schema = {
|
||||
image: {
|
||||
next: [{ object: 'inline' }, { object: 'text' }],
|
||||
normalize: (editor, { code, next }) => {
|
||||
if (code == 'next_sibling_object_invalid') {
|
||||
if (code === 'next_sibling_object_invalid') {
|
||||
editor.unwrapBlockByKey(next.key, 'paragraph')
|
||||
}
|
||||
},
|
||||
|
@ -7,7 +7,7 @@ export const schema = {
|
||||
paragraph: {
|
||||
next: [{ type: 'paragraph' }],
|
||||
normalize: (editor, { code, next }) => {
|
||||
if (code == 'next_sibling_type_invalid') {
|
||||
if (code === 'next_sibling_type_invalid') {
|
||||
editor.wrapBlockByKey(next.key, 'paragraph')
|
||||
}
|
||||
},
|
||||
|
@ -6,10 +6,10 @@ export const schema = {
|
||||
blocks: {
|
||||
paragraph: {
|
||||
data: {
|
||||
thing: v => v == 'value',
|
||||
thing: v => v === 'value',
|
||||
},
|
||||
normalize: (editor, { code, node, key }) => {
|
||||
if (code == 'node_data_invalid') {
|
||||
if (code === 'node_data_invalid') {
|
||||
editor.setNodeByKey(node.key, { data: { thing: 'value' } })
|
||||
}
|
||||
},
|
||||
|
@ -6,7 +6,7 @@ export const schema = {
|
||||
blocks: {
|
||||
paragraph: {
|
||||
data: {
|
||||
thing: v => v == 'value',
|
||||
thing: v => v === 'value',
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -6,7 +6,7 @@ export const schema = {
|
||||
blocks: {
|
||||
paragraph: {
|
||||
data: {
|
||||
thing: v => v == null || v == 'value',
|
||||
thing: v => v == null || v === 'value',
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -7,7 +7,7 @@ export const schema = {
|
||||
paragraph: {
|
||||
marks: [{ type: 'bold' }],
|
||||
normalize: (editor, { code, node }) => {
|
||||
if (code == 'node_mark_invalid') {
|
||||
if (code === 'node_mark_invalid') {
|
||||
node.nodes.forEach(n => editor.removeNodeByKey(n.key))
|
||||
}
|
||||
},
|
||||
|
@ -7,7 +7,7 @@ export const schema = {
|
||||
paragraph: {
|
||||
text: /^\d*$/,
|
||||
normalize: (editor, { code, node }) => {
|
||||
if (code == 'node_text_invalid') {
|
||||
if (code === 'node_text_invalid') {
|
||||
node.nodes.forEach(n => editor.removeNodeByKey(n.key))
|
||||
}
|
||||
},
|
||||
|
@ -7,7 +7,7 @@ export const schema = {
|
||||
paragraph: {
|
||||
parent: { object: 'document' },
|
||||
normalize: (editor, { code, node }) => {
|
||||
if (code == 'parent_object_invalid') {
|
||||
if (code === 'parent_object_invalid') {
|
||||
editor.unwrapNodeByKey(node.key)
|
||||
}
|
||||
},
|
||||
|
@ -8,7 +8,7 @@ export const schema = {
|
||||
item: {
|
||||
parent: { type: 'list' },
|
||||
normalize: (editor, { code, node }) => {
|
||||
if (code == 'parent_type_invalid') {
|
||||
if (code === 'parent_type_invalid') {
|
||||
editor.wrapBlockByKey(node.key, 'list')
|
||||
}
|
||||
},
|
||||
|
@ -7,7 +7,7 @@ export const schema = {
|
||||
image: {
|
||||
previous: [{ object: 'inline' }, { object: 'text' }],
|
||||
normalize: (editor, { code, previous }) => {
|
||||
if (code == 'previous_sibling_object_invalid') {
|
||||
if (code === 'previous_sibling_object_invalid') {
|
||||
editor.unwrapBlockByKey(previous.key, 'paragraph')
|
||||
}
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user