1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-22 23:12:52 +02:00

tighten linting rules

This commit is contained in:
Ian Storm Taylor
2017-02-25 10:13:21 -08:00
parent e0f59970a0
commit c3578d12ad
32 changed files with 167 additions and 150 deletions

View File

@@ -18,7 +18,10 @@
"node": true
},
"rules": {
"arrow-parens": ["error", "as-needed", { "requireForBlockBody": true }],
"arrow-spacing": "error",
"block-spacing": "error",
"capitalized-comments": ["error", "always", { "ignoreConsecutiveComments": true }],
"comma-dangle": ["error", "only-multiline"],
"comma-spacing": ["error", { "before": false, "after": true }],
"comma-style": ["error", "last"],
@@ -28,8 +31,12 @@
"dot-location": ["error", "property"],
"dot-notation": ["error", { "allowKeywords": true }],
"eol-last": "error",
"func-call-spacing": ["error", "never"],
"func-style": ["error", "declaration"],
"import/default": "error",
"import/export": "error",
"import/first": "error",
"import/named": "error",
"import/namespace": "error",
"import/newline-after-import": "error",
"import/no-deprecated": "error",
@@ -39,8 +46,11 @@
"import/no-named-as-default-member": "error",
"import/no-unresolved": "error",
"indent": ["error", 2, { "SwitchCase": 1, "MemberExpression": 1 }],
"jsx-quotes": ["error", "prefer-double"],
"key-spacing": ["error", { "beforeColon": false, "afterColon": true }],
"lines-around-comment": ["error", { "beforeBlockComment": true, "afterBlockComment": true }],
"keyword-spacing": ["error", { "before": true, "after": true }],
"linebreak-style": "error",
"lines-around-comment": ["error", { "beforeBlockComment": true, "afterBlockComment": true, "allowBlockStart": true, "allowObjectStart": true, "allowArrayStart": true }],
"new-parens": "error",
"no-array-constructor": "error",
"no-class-assign": "error",
@@ -56,8 +66,10 @@
"no-empty-pattern": "error",
"no-ex-assign": "error",
"no-extend-native": "error",
"no-extra-boolean-cast": "error",
"no-func-assign": "error",
"no-invalid-regexp": "error",
"no-lonely-if": "error",
"no-mixed-spaces-and-tabs": ["error", false],
"no-multi-spaces": "error",
"no-multiple-empty-lines": ["error", { "max": 2, "maxEOF": 1 }],
@@ -65,19 +77,24 @@
"no-negated-in-lhs": "error",
"no-new-object": "error",
"no-new-symbol": "error",
"no-path-concat": "error",
"no-redeclare": "error",
"no-regex-spaces": "error",
"no-sequences": "error",
"no-shadow": "error",
"no-shadow-restricted-names": "error",
"no-spaced-func": "error",
"no-tabs": "error",
"no-this-before-super": "error",
"no-throw-literal": "error",
"no-trailing-spaces": "error",
"no-undef": "error",
"no-unneeded-ternary": "error",
"no-unreachable": "error",
"no-unsafe-finally": "error",
"no-unsafe-negation": "error",
"no-unused-expressions": "error",
"no-unused-vars": ["warn", { "vars": "all", "args": "none" }],
"no-unused-vars": ["error", { "vars": "all", "args": "none" }],
"no-useless-call": "error",
"no-useless-computed-key": "error",
"no-useless-constructor": "error",
@@ -86,12 +103,17 @@
"no-void": "error",
"no-whitespace-before-property": "error",
"no-with": "error",
"object-curly-spacing": ["error", "always", { "objectsInObjects": false }],
"object-property-newline": ["error", { "allowMultiplePropertiesPerLine": true }],
"object-shorthand": ["error", "always"],
"operator-linebreak": ["error", "after", { "overrides": { "?": "ignore", ":": "ignore" }}],
"padded-blocks": ["error", { "blocks": "never", "classes": "always" }],
"prefer-arrow-callback": "error",
"prefer-const": ["error", { "destructuring": "all", "ignoreReadBeforeAssign": true }],
"prefer-rest-params": "error",
"prefer-spread": "error",
"prefer-template": "error",
"quotes": ["error", "single", { "allowTemplateLiterals": true }],
"radix": "error",
"react/jsx-boolean-value": ["error", "never"],
"react/jsx-closing-bracket-location": "error",
@@ -101,6 +123,7 @@
"react/jsx-key": "error",
"react/jsx-no-bind": "error",
"react/jsx-no-duplicate-props": "error",
"react/jsx-no-target-blank": "error",
"react/jsx-no-undef": "error",
"react/jsx-space-before-closing": ["error", "always"],
"react/jsx-uses-react": "error",
@@ -123,6 +146,7 @@
"space-unary-ops": ["error", { "words": true, "nonwords": false }],
"spaced-comment": ["error", "always", { "exceptions": ["-"]}],
"template-curly-spacing": "error",
"template-tag-spacing": ["error", "never"],
"unicode-bom": ["error", "never"],
"use-isnan": "error",
"valid-jsdoc": ["error", { "prefer": { "return": "returns" }, "requireReturn": false }],

View File

@@ -130,7 +130,7 @@ class AutoMarkdown extends React.Component {
if (type == 'list-item' && startBlock.type == 'list-item') return
e.preventDefault()
let transform = state
const transform = state
.transform()
.setBlock(type)
@@ -161,7 +161,7 @@ class AutoMarkdown extends React.Component {
if (startBlock.type == 'paragraph') return
e.preventDefault()
let transform = state
const transform = state
.transform()
.setBlock('paragraph')

View File

@@ -153,7 +153,7 @@ class CodeHighlighting extends React.Component {
const { startBlock } = state
if (startBlock.type != 'code') return
let transform = state.transform()
const transform = state.transform()
if (state.isExpanded) transform.delete()
transform.insertText('\n')

View File

@@ -166,7 +166,7 @@ class RichText extends React.Component {
const isActive = this.hasBlock(type)
let { state } = this.state
let transform = state
const transform = state
.transform()
.setBlock(isActive ? 'paragraph' : type)

View File

@@ -2,8 +2,8 @@
import { Editor, Raw } from '../..'
import Portal from 'react-portal'
import React from 'react'
import position from 'selection-position'
import initialState from './state.json'
import position from 'selection-position'
/**
* Define a schema.

View File

@@ -122,7 +122,7 @@ class Links extends React.Component {
if (data.type != 'text' && data.type != 'html') return
if (!isUrl(data.text)) return
let transform = state.transform()
const transform = state.transform()
if (this.hasLinks()) {
transform.unwrapInline('link')

View File

@@ -163,7 +163,7 @@ class RichText extends React.Component {
onClickBlock = (e, type) => {
e.preventDefault()
let { state } = this.state
let transform = state.transform()
const transform = state.transform()
const { document } = state
// Handle everything but list buttons.

View File

@@ -11,7 +11,7 @@ import initialState from './state.json'
const schema = {
nodes: {
'block-quote': (props) => <blockquote {...props.attributes}>{props.children}</blockquote>,
'block-quote': props => <blockquote {...props.attributes}>{props.children}</blockquote>,
}
}

View File

@@ -402,9 +402,8 @@ class Content extends React.Component {
range.setStart(nativeEvent.rangeParent, nativeEvent.rangeOffset)
}
const startNode = range.startContainer
const startOffset = range.startOffset
const point = this.getPoint(startNode, startOffset)
const { startContainer, startOffset } = range
const point = this.getPoint(startContainer, startOffset)
if (!point) return
const target = Selection.create({
@@ -616,7 +615,7 @@ class Content extends React.Component {
const window = getWindow(event.target)
const { state } = this.props
let { document, selection } = state
const { document, selection } = state
const native = window.getSelection()
const data = {}
@@ -704,7 +703,7 @@ class Content extends React.Component {
.map(node => this.renderNode(node))
.toArray()
let style = {
const style = {
// Prevent the default outline styles.
outline: 'none',
// Preserve adjacent whitespace and new lines.

View File

@@ -166,11 +166,10 @@ class Leaf extends React.Component {
}
// Otherwise we need to set the selection across two different leaves.
else {
// If the selection is forward, we can set things in sequence. In the
// first leaf to render, reset the selection and set the new start. And
// then in the second leaf to render, extend to the new end.
if (selection.isForward) {
else if (selection.isForward) {
if (hasAnchor) {
native.removeAllRanges()
const range = window.document.createRange()
@@ -186,13 +185,13 @@ class Leaf extends React.Component {
// In the first leaf to render, set a phony start anchor to store the true
// end position. And then in the second leaf to render, set the start and
// extend the end to the stored value.
else {
if (hasFocus) {
else if (hasFocus) {
native.removeAllRanges()
const range = window.document.createRange()
range.setStart(el, focusOffset)
native.addRange(range)
} else if (hasAnchor) {
}
else if (hasAnchor) {
const endNode = native.focusNode
const endOffset = native.focusOffset
native.removeAllRanges()
@@ -202,8 +201,6 @@ class Leaf extends React.Component {
native.extend(endNode, endOffset)
focus()
}
}
}
this.debug('updateSelection', { selection })
}
@@ -305,6 +302,7 @@ class Leaf extends React.Component {
)
}, children)
}
}
/**

View File

@@ -62,7 +62,7 @@ class Node extends React.Component {
debug = (message, ...args) => {
const { node } = this.props
const { key, kind, type } = node
let id = kind == 'text' ? `${key} (${kind})` : `${key} (${type})`
const id = kind == 'text' ? `${key} (${kind})` : `${key} (${type})`
debug(message, `${id}`, ...args)
}
@@ -349,8 +349,7 @@ class Node extends React.Component {
renderLeaf = (ranges, range, index, offset) => {
const { node, parent, schema, state, editor } = this.props
const text = range.text
const marks = range.marks
const { text, marks } = range
return (
<Leaf

View File

@@ -47,7 +47,7 @@ class Void extends React.Component {
debug = (message, ...args) => {
const { node } = this.props
const { key, type } = node
let id = `${key} (${type})`
const id = `${key} (${type})`
debug(message, `${id}`, ...args)
}

View File

@@ -55,7 +55,7 @@ class Character extends new Record(DEFAULTS) {
*/
static createListFromText(string, marks) {
const chars = string.split('').map(text => { return { text, marks } })
const chars = string.split('').map((text) => { return { text, marks } })
const list = Character.createList(chars)
return list
}

View File

@@ -30,7 +30,7 @@ const Node = {
getKeys() {
const keys = []
this.forEachDescendant(desc => {
this.forEachDescendant((desc) => {
keys.push(desc.key)
})
@@ -160,7 +160,7 @@ const Node = {
let descendantFound = null
this.nodes.find(node => {
this.nodes.find((node) => {
if (node.kind != 'text') {
descendantFound = node.findDescendant(iterator)
return descendantFound
@@ -182,7 +182,7 @@ const Node = {
findDescendantDeep(iterator) {
let found
this.forEachDescendant(node => {
this.forEachDescendant((node) => {
if (iterator(node)) {
found = node
return false
@@ -339,7 +339,7 @@ const Node = {
getClosest(key, iterator) {
key = Normalize.key(key)
let ancestors = this.getAncestors(key)
const ancestors = this.getAncestors(key)
if (!ancestors) {
throw new Error(`Could not find a descendant node with key "${key}".`)
}
@@ -478,7 +478,7 @@ const Node = {
_getDescendant(key) {
let descendantFound = null
const found = this.nodes.find(node => {
const found = this.nodes.find((node) => {
if (node.key === key) {
return node
} else if (node.kind !== 'text') {
@@ -526,7 +526,7 @@ const Node = {
let sorted
this.forEachDescendant(n => {
this.forEachDescendant((n) => {
if (n.key === key1) {
sorted = true
return false
@@ -606,7 +606,7 @@ const Node = {
*/
getFurthest(key, iterator) {
let ancestors = this.getAncestors(key)
const ancestors = this.getAncestors(key)
if (!ancestors) {
key = Normalize.key(key)
throw new Error(`Could not find a descendant node with key "${key}".`)
@@ -647,7 +647,7 @@ const Node = {
getHighestChild(key) {
key = Normalize.key(key)
return this.nodes.find(node => {
return this.nodes.find((node) => {
if (node.key == key) return true
if (node.kind == 'text') return false
return node.hasDescendant(key)
@@ -890,7 +890,7 @@ const Node = {
if (key == this.key) return []
let path = []
const path = []
let childKey = key
let parent
@@ -1024,11 +1024,8 @@ const Node = {
*/
getTextDirection() {
const text = this.text
const dir = direction(text)
return dir == 'neutral'
? undefined
: dir
const dir = direction(this.text)
return dir == 'neutral' ? undefined : dir
},
/**
@@ -1160,7 +1157,7 @@ const Node = {
*/
insertNode(index, node) {
let keys = this.getKeys()
const keys = this.getKeys()
if (keys.contains(node.key)) {
node = node.regenerateKey()
@@ -1220,7 +1217,7 @@ const Node = {
}
else {
const size = first.nodes.size
const { size } = first.nodes
second.nodes.forEach((child, i) => {
first = first.insertNode(size + i, child)
})
@@ -1246,10 +1243,10 @@ const Node = {
*/
mapChildren(iterator) {
let nodes = this.nodes
let { nodes } = this
nodes.forEach((node, i) => {
let ret = iterator(node, i, this.nodes)
const ret = iterator(node, i, this.nodes)
if (ret != node) nodes = nodes.set(ret.key, ret)
})
@@ -1265,7 +1262,7 @@ const Node = {
*/
mapDescendants(iterator) {
let nodes = this.nodes
let { nodes } = this
nodes.forEach((node, i) => {
let ret = node
@@ -1338,7 +1335,7 @@ const Node = {
splitNode(path, offset) {
let base = this
let node = base.assertPath(path)
const node = base.assertPath(path)
let parent = base.getParent(node.key)
const isParent = base == parent
const index = parent.nodes.indexOf(node)
@@ -1396,7 +1393,7 @@ const Node = {
splitNodeAfter(path, count) {
let base = this
let node = base.assertPath(path)
const node = base.assertPath(path)
if (node.kind === 'text') throw new Error('Cannot split text node at index. Use Node.splitNode at offset instead')
const { nodes } = node
@@ -1429,7 +1426,7 @@ const Node = {
splitBlockAtRange(range, height = 1) {
const { startKey, startOffset } = range
let base = this
const base = this
let node = base.assertDescendant(startKey)
let parent = base.getClosestBlock(node.key)
let offset = startOffset
@@ -1456,7 +1453,7 @@ const Node = {
updateDescendant(node) {
let found = false
const result = this.mapDescendants(d => {
const result = this.mapDescendants((d) => {
if (d.key == node.key) {
found = true
return node

View File

@@ -64,6 +64,7 @@ class Range extends new Record(DEFAULTS) {
})
}))
}
}
/**

View File

@@ -295,7 +295,7 @@ class Selection extends new Record(DEFAULTS) {
*/
normalize(node) {
let selection = this
const selection = this
let { anchorKey, anchorOffset, focusKey, focusOffset, isBackward } = selection
// If the selection isn't formed yet or is malformed, ensure that it is
@@ -322,8 +322,8 @@ class Selection extends new Record(DEFAULTS) {
// If the anchor node isn't a text node, match it to one.
if (anchorNode.kind != 'text') {
warn('The selection anchor was set to a Node that is not a Text node. This should not happen and can degrade performance. The node in question was:', anchorNode)
let anchorText = anchorNode.getTextAtOffset(anchorOffset)
let offset = anchorNode.getOffset(anchorText.key)
const anchorText = anchorNode.getTextAtOffset(anchorOffset)
const offset = anchorNode.getOffset(anchorText.key)
anchorOffset = anchorOffset - offset
anchorNode = anchorText
}
@@ -331,8 +331,8 @@ class Selection extends new Record(DEFAULTS) {
// If the focus node isn't a text node, match it to one.
if (focusNode.kind != 'text') {
warn('The selection focus was set to a Node that is not a Text node. This should not happen and can degrade performance. The node in question was:', focusNode)
let focusText = focusNode.getTextAtOffset(focusOffset)
let offset = focusNode.getOffset(focusText.key)
const focusText = focusNode.getTextAtOffset(focusOffset)
const offset = focusNode.getOffset(focusText.key)
focusOffset = focusOffset - offset
focusNode = focusText
}

View File

@@ -48,7 +48,7 @@ class State extends new Record(DEFAULTS) {
static create(properties = {}) {
if (properties instanceof State) return properties
let document = Document.create(properties.document)
const document = Document.create(properties.document)
let selection = Selection.create(properties.selection)
if (selection.isUnset) {

View File

@@ -212,7 +212,7 @@ class Text extends new Record(DEFAULTS) {
getRanges(decorators = []) {
const list = new List()
let characters = this.getDecorations(decorators)
const characters = this.getDecorations(decorators)
// If there are no characters, return one empty range.
if (characters.size == 0) {
@@ -327,8 +327,8 @@ class Text extends new Record(DEFAULTS) {
removeText(index, length) {
let { characters } = this
let start = index
let end = index + length
const start = index
const end = index + length
characters = characters.filterNot((char, i) => start <= i && i < end)
return this.merge({ characters })
}

View File

@@ -52,15 +52,15 @@ class Transform {
*/
apply(options = {}) {
let transform = this
const transform = this
let { merge, save, isNative = false } = options
// Ensure that the selection is normalized.
transform.normalizeSelection()
let { state, operations } = transform
let { history } = state
let { undos } = history
const { state, operations } = transform
const { history } = state
const { undos } = history
const previous = undos.peek()
// If there are no operations, abort early.

View File

@@ -317,7 +317,7 @@ function Plugin(options = {}) {
: selection.endOffset)
}
let transform = state.transform()
const transform = state.transform()
if (isInternal) transform.delete()
@@ -340,7 +340,7 @@ function Plugin(options = {}) {
debug('onDropText', { data })
const { text, target } = data
let transform = state
const transform = state
.transform()
.moveTo(target)
@@ -784,7 +784,7 @@ function Plugin(options = {}) {
function onPasteText(e, data, state) {
debug('onPasteText', { data })
let transform = state.transform()
const transform = state.transform()
data.text
.split('\n')

View File

@@ -126,7 +126,7 @@ const rules = [
transform.insertNodeByKey(node.key, index, text, OPTS)
node.nodes.forEach(child => {
node.nodes.forEach((child) => {
transform.removeNodeByKey(child.key, OPTS)
})
}

View File

@@ -43,7 +43,7 @@ const OPERATIONS = {
*/
export function applyOperation(transform, operation) {
let { state, operations } = transform
const { state, operations } = transform
const { type } = operation
const fn = OPERATIONS[type]
@@ -260,7 +260,6 @@ function removeNode(state, operation) {
selection = selection.unset()
}
}
}
// Remove the node from the document.
@@ -362,7 +361,7 @@ function setNode(state, operation) {
*/
function setSelection(state, operation) {
let properties = { ...operation.properties }
const properties = { ...operation.properties }
let { document, selection } = state
if (properties.anchorPath !== undefined) {

View File

@@ -289,8 +289,8 @@ export function setInline(transform, properties) {
*/
export function splitBlock(transform, depth = 1) {
let { state } = transform
let { selection } = state
const { state } = transform
const { selection } = state
transform
.snapshotSelection()
.splitBlockAtRange(selection, depth)
@@ -306,8 +306,8 @@ export function splitBlock(transform, depth = 1) {
*/
export function splitInline(transform, depth = Infinity) {
let { state } = transform
let { selection } = state
const { state } = transform
const { selection } = state
transform
.snapshotSelection()
.splitInlineAtRange(selection, depth)

View File

@@ -94,7 +94,7 @@ export function deleteAtRange(transform, range, options = {}) {
// Remove all of the middle nodes, between the splits.
if (middles.size) {
middles.forEach(child => {
middles.forEach((child) => {
transform.removeNodeByKey(child.key, OPTS)
})
}
@@ -940,7 +940,7 @@ export function unwrapBlockAtRange(transform, range, properties, options = {}) {
})
const firstMatch = children.first()
let lastMatch = children.last()
const lastMatch = children.last()
if (first == firstMatch && last == lastMatch) {
block.nodes.forEach((child, i) => {
@@ -1061,23 +1061,25 @@ export function wrapBlockAtRange(transform, range, block, options = {}) {
const lastblock = blocks.last()
let parent, siblings, index
// if there is only one block in the selection then we know the parent and siblings
// If there is only one block in the selection then we know the parent and
// siblings.
if (blocks.length === 1) {
parent = document.getParent(firstblock.key)
siblings = blocks
}
// determine closest shared parent to all blocks in selection
// Determine closest shared parent to all blocks in selection.
else {
parent = document.getClosest(firstblock.key, p1 => {
parent = document.getClosest(firstblock.key, (p1) => {
return !!document.getClosest(lastblock.key, p2 => p1 == p2)
})
}
// if no shared parent could be found then the parent is the document
// If no shared parent could be found then the parent is the document.
if (parent == null) parent = document
// create a list of direct children siblings of parent that fall in the selection
// Create a list of direct children siblings of parent that fall in the
// selection.
if (siblings == null) {
const indexes = parent.nodes.reduce((ind, node, i) => {
if (node == firstblock || node.hasDescendant(firstblock.key)) ind[0] = i
@@ -1089,15 +1091,15 @@ export function wrapBlockAtRange(transform, range, block, options = {}) {
siblings = parent.nodes.slice(indexes[0], indexes[1] + 1)
}
// get the index to place the new wrapped node at
// Get the index to place the new wrapped node at.
if (index == null) {
index = parent.nodes.indexOf(siblings.first())
}
// inject the new block node into the parent
// Inject the new block node into the parent.
transform.insertNodeByKey(parent.key, index, block, OPTS)
// move the sibling nodes into the new block node
// Move the sibling nodes into the new block node.
siblings.forEach((node, i) => {
transform.moveNodeByKey(node.key, block.key, i, OPTS)
})
@@ -1140,7 +1142,7 @@ export function wrapInlineAtRange(transform, range, inline, options = {}) {
let startBlock = document.getClosestBlock(startKey)
let endBlock = document.getClosestBlock(endKey)
let startChild = startBlock.getHighestChild(startKey)
let endChild = endBlock.getHighestChild(endKey)
const endChild = endBlock.getHighestChild(endKey)
const startIndex = startBlock.nodes.indexOf(startChild)
const endIndex = endBlock.nodes.indexOf(endChild)

View File

@@ -170,7 +170,7 @@ export function removeMarkByKey(transform, key, offset, length, mark, options =
export function removeNodeByKey(transform, key, options = {}) {
const { normalize = true } = options
const { state } = transform
let { document } = state
const { document } = state
const path = document.getPath(key)
transform.removeNodeOperation(path)
@@ -195,7 +195,7 @@ export function removeNodeByKey(transform, key, options = {}) {
export function removeTextByKey(transform, key, offset, length, options = {}) {
const { normalize = true } = options
const { state } = transform
let { document } = state
const { document } = state
const path = document.getPath(key)
transform.removeTextOperation(path, offset, length)
@@ -272,8 +272,8 @@ export function setNodeByKey(transform, key, properties, options = {}) {
export function splitNodeByKey(transform, key, offset, options = {}) {
const { normalize = true } = options
let { state } = transform
let { document } = state
const { state } = transform
const { document } = state
const path = document.getPath(key)
transform.splitNodeAtOffsetOperation(path, offset)
@@ -353,27 +353,26 @@ export function unwrapNodeByKey(transform, key, options = {}) {
if (parent.nodes.size === 1) {
// Remove the parent
// Remove the parent and replace it by the node itself.
transform.removeNodeByKey(parent.key, { normalize: false })
// and replace it by the node itself
transform.insertNodeByKey(parentParent.key, parentIndex, node, options)
}
else if (isFirst) {
// Just move the node before its parent
// Just move the node before its parent.
transform.moveNodeByKey(key, parentParent.key, parentIndex, options)
}
else if (isLast) {
// Just move the node after its parent
// Just move the node after its parent.
transform.moveNodeByKey(key, parentParent.key, parentIndex + 1, options)
}
else {
const parentPath = document.getPath(parent.key)
// Split the parent
// Split the parent.
transform.splitNodeOperation(parentPath, index)
// Extract the node in between the splitted parent
// Extract the node in between the splitted parent.
transform.moveNodeByKey(key, parentParent.key, parentIndex + 1, { normalize: false })
if (normalize) {

View File

@@ -132,7 +132,7 @@ function normalizeNodeAndChildren(transform, node, schema) {
node = refindNode(transform, node)
// Add any new children back onto the stack.
node.nodes.forEach(n => {
node.nodes.forEach((n) => {
if (set.has(n.key)) return
stack = stack.push(n.key)
})
@@ -171,7 +171,7 @@ function refindNode(transform, node) {
*/
function normalizeNode(transform, node, schema) {
let max = schema.rules.length
const max = schema.rules.length
let iterations = 0
function iterate(t, n) {

View File

@@ -11,7 +11,7 @@ export function redo(transform) {
let { undos, redos } = history
// If there's no next snapshot, abort.
let next = redos.peek()
const next = redos.peek()
if (!next) return
// Shift the next state into the undo stack.
@@ -19,7 +19,7 @@ export function redo(transform) {
undos = undos.push(next)
// Replay the next operations.
next.forEach(op => {
next.forEach((op) => {
transform.applyOperation(op)
})
@@ -82,7 +82,7 @@ export function undo(transform) {
let { undos, redos } = history
// If there's no previous snapshot, abort.
let previous = undos.peek()
const previous = undos.peek()
if (!previous) return
// Shift the previous operations into the redo stack.
@@ -90,8 +90,8 @@ export function undo(transform) {
redos = redos.push(previous)
// Replay the inverse of the previous operations.
previous.slice().reverse().forEach(op => {
op.inverse.forEach(inv => {
previous.slice().reverse().forEach((op) => {
op.inverse.forEach((inv) => {
transform.applyOperation(inv)
})
})

View File

@@ -440,7 +440,7 @@ export function splitNodeAtOffsetOperation(transform, path, offset) {
type: 'join_node',
path: inversePath,
withPath: path,
// we will split down to the text nodes, so we must join nodes recursively
// We will split down to the text nodes, so we must join nodes recursively.
deep: true
}]

View File

@@ -20,9 +20,9 @@ const FRAGMENT_MATCHER = /data-slate-fragment="([^\s]+)"/
function getTransferData(transfer) {
let fragment = transfer.getData(TYPES.FRAGMENT) || null
let node = transfer.getData(TYPES.NODE) || null
let html = transfer.getData('text/html') || null
let rich = transfer.getData('text/rtf') || null
let text = transfer.getData('text/plain') || null
const html = transfer.getData('text/html') || null
const rich = transfer.getData('text/rtf') || null
const text = transfer.getData('text/plain') || null
let files
// If there isn't a fragment, but there is HTML, check to see if the HTML is

View File

@@ -69,7 +69,6 @@ function findKey(rawNode, rawOffset) {
// Find the closest parent with an offset key attribute.
let closest = parentNode.closest(SELECTOR)
let offsetKey
// For void nodes, the element with the offset key will be a cousin, not an
// ancestor, so find it by going down from the nearest void parent.
@@ -81,7 +80,7 @@ function findKey(rawNode, rawOffset) {
}
// Get the string value of the offset key attribute.
offsetKey = closest.getAttribute(ATTRIBUTE)
const offsetKey = closest.getAttribute(ATTRIBUTE)
// If we still didn't find an offset key, abort.
if (!offsetKey) return null

View File

@@ -8,7 +8,7 @@ import getWindow from 'get-window'
function scrollWindow(window, cursorTop, cursorLeft, cursorHeight) {
let scrollX = window.scrollX
let scrollY = window.scrollY
let cursorBottom = cursorTop + cursorHeight
const cursorBottom = cursorTop + cursorHeight
if (cursorTop < 0 || cursorBottom > window.innerHeight) {
scrollY += cursorTop - window.innerHeight / 2 + cursorHeight / 2
@@ -22,26 +22,26 @@ function scrollWindow(window, cursorTop, cursorLeft, cursorHeight) {
}
function scrollTo(element) {
let window = getWindow(element)
let s = window.getSelection()
const window = getWindow(element)
const s = window.getSelection()
if (s.rangeCount > 0) {
let selectionRect = s.getRangeAt(0).getBoundingClientRect()
const selectionRect = s.getRangeAt(0).getBoundingClientRect()
let innerRect = selectionRect
let wrapper = element
let cursorHeight = innerRect.height
const cursorHeight = innerRect.height
let cursorTop = innerRect.top
let cursorLeft = innerRect.left
while (wrapper != window.document.body) {
let wrapperRect = wrapper.getBoundingClientRect()
let currentY = cursorTop
let cursorBottom = cursorTop + cursorHeight
const wrapperRect = wrapper.getBoundingClientRect()
const currentY = cursorTop
const cursorBottom = cursorTop + cursorHeight
if (cursorTop < wrapperRect.top || cursorBottom > wrapperRect.top + wrapper.offsetHeight) {
cursorTop = wrapperRect.top + wrapperRect.height / 2 - cursorHeight / 2
wrapper.scrollTop += currentY - cursorTop
}
let currentLeft = cursorLeft
const currentLeft = cursorLeft
if (cursorLeft < wrapperRect.left || cursorLeft > wrapperRect.right) {
cursorLeft = wrapperRect.left + wrapperRect.width / 2
wrapper.scrollLeft += currentLeft - cursorLeft