mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-29 09:59:48 +02:00
Enforce 2-spaces indentation
This commit is contained in:
@@ -38,6 +38,7 @@
|
|||||||
"import/no-named-as-default": "error",
|
"import/no-named-as-default": "error",
|
||||||
"import/no-named-as-default-member": "error",
|
"import/no-named-as-default-member": "error",
|
||||||
"import/no-unresolved": "error",
|
"import/no-unresolved": "error",
|
||||||
|
"indent": ["error", 2],
|
||||||
"key-spacing": ["error", { "beforeColon": false, "afterColon": true }],
|
"key-spacing": ["error", { "beforeColon": false, "afterColon": true }],
|
||||||
"lines-around-comment": ["error", { "beforeBlockComment": true, "afterBlockComment": true }],
|
"lines-around-comment": ["error", { "beforeBlockComment": true, "afterBlockComment": true }],
|
||||||
"new-parens": "error",
|
"new-parens": "error",
|
||||||
|
@@ -50,17 +50,17 @@ class AutoMarkdown extends React.Component {
|
|||||||
|
|
||||||
getType = (chars) => {
|
getType = (chars) => {
|
||||||
switch (chars) {
|
switch (chars) {
|
||||||
case '*':
|
case '*':
|
||||||
case '-':
|
case '-':
|
||||||
case '+': return 'list-item'
|
case '+': return 'list-item'
|
||||||
case '>': return 'block-quote'
|
case '>': return 'block-quote'
|
||||||
case '#': return 'heading-one'
|
case '#': return 'heading-one'
|
||||||
case '##': return 'heading-two'
|
case '##': return 'heading-two'
|
||||||
case '###': return 'heading-three'
|
case '###': return 'heading-three'
|
||||||
case '####': return 'heading-four'
|
case '####': return 'heading-four'
|
||||||
case '#####': return 'heading-five'
|
case '#####': return 'heading-five'
|
||||||
case '######': return 'heading-six'
|
case '######': return 'heading-six'
|
||||||
default: return null
|
default: return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,9 +105,9 @@ class AutoMarkdown extends React.Component {
|
|||||||
|
|
||||||
onKeyDown = (e, data, state) => {
|
onKeyDown = (e, data, state) => {
|
||||||
switch (data.key) {
|
switch (data.key) {
|
||||||
case 'space': return this.onSpace(e, state)
|
case 'space': return this.onSpace(e, state)
|
||||||
case 'backspace': return this.onBackspace(e, state)
|
case 'backspace': return this.onBackspace(e, state)
|
||||||
case 'enter': return this.onEnter(e, state)
|
case 'enter': return this.onEnter(e, state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -109,20 +109,20 @@ class RichText extends React.Component {
|
|||||||
let mark
|
let mark
|
||||||
|
|
||||||
switch (data.key) {
|
switch (data.key) {
|
||||||
case 'b':
|
case 'b':
|
||||||
mark = 'bold'
|
mark = 'bold'
|
||||||
break
|
break
|
||||||
case 'i':
|
case 'i':
|
||||||
mark = 'italic'
|
mark = 'italic'
|
||||||
break
|
break
|
||||||
case 'u':
|
case 'u':
|
||||||
mark = 'underlined'
|
mark = 'underlined'
|
||||||
break
|
break
|
||||||
case '`':
|
case '`':
|
||||||
mark = 'code'
|
mark = 'code'
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
state = state
|
state = state
|
||||||
|
@@ -104,14 +104,14 @@ class Iframes extends React.Component {
|
|||||||
let mark
|
let mark
|
||||||
|
|
||||||
switch (data.key) {
|
switch (data.key) {
|
||||||
case 'b':
|
case 'b':
|
||||||
mark = 'bold'
|
mark = 'bold'
|
||||||
break
|
break
|
||||||
case 'i':
|
case 'i':
|
||||||
mark = 'italic'
|
mark = 'italic'
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
state = state
|
state = state
|
||||||
|
@@ -160,8 +160,8 @@ class Images extends React.Component {
|
|||||||
|
|
||||||
onDrop = (e, data, state, editor) => {
|
onDrop = (e, data, state, editor) => {
|
||||||
switch (data.type) {
|
switch (data.type) {
|
||||||
case 'files': return this.onDropOrPasteFiles(e, data, state, editor)
|
case 'files': return this.onDropOrPasteFiles(e, data, state, editor)
|
||||||
case 'node': return this.onDropNode(e, data, state)
|
case 'node': return this.onDropNode(e, data, state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,8 +222,8 @@ class Images extends React.Component {
|
|||||||
|
|
||||||
onPaste = (e, data, state, editor) => {
|
onPaste = (e, data, state, editor) => {
|
||||||
switch (data.type) {
|
switch (data.type) {
|
||||||
case 'files': return this.onDropOrPasteFiles(e, data, state, editor)
|
case 'files': return this.onDropOrPasteFiles(e, data, state, editor)
|
||||||
case 'text': return this.onPasteText(e, data, state)
|
case 'text': return this.onPasteText(e, data, state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -109,20 +109,20 @@ class RichText extends React.Component {
|
|||||||
let mark
|
let mark
|
||||||
|
|
||||||
switch (data.key) {
|
switch (data.key) {
|
||||||
case 'b':
|
case 'b':
|
||||||
mark = 'bold'
|
mark = 'bold'
|
||||||
break
|
break
|
||||||
case 'i':
|
case 'i':
|
||||||
mark = 'italic'
|
mark = 'italic'
|
||||||
break
|
break
|
||||||
case 'u':
|
case 'u':
|
||||||
mark = 'underlined'
|
mark = 'underlined'
|
||||||
break
|
break
|
||||||
case '`':
|
case '`':
|
||||||
mark = 'code'
|
mark = 'code'
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
state = state
|
state = state
|
||||||
|
@@ -115,9 +115,9 @@ class Tables extends React.Component {
|
|||||||
|
|
||||||
if (state.startBlock.type != 'table-cell') return
|
if (state.startBlock.type != 'table-cell') return
|
||||||
switch (data.key) {
|
switch (data.key) {
|
||||||
case 'backspace': return this.onBackspace(e, state)
|
case 'backspace': return this.onBackspace(e, state)
|
||||||
case 'delete': return this.onDelete(e, state)
|
case 'delete': return this.onDelete(e, state)
|
||||||
case 'enter': return this.onEnter(e, state)
|
case 'enter': return this.onEnter(e, state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -94,18 +94,18 @@ class Void extends React.Component {
|
|||||||
if (node.kind == 'block') {
|
if (node.kind == 'block') {
|
||||||
style = IS_FIREFOX
|
style = IS_FIREFOX
|
||||||
? {
|
? {
|
||||||
pointerEvents: 'none',
|
pointerEvents: 'none',
|
||||||
width: '0px',
|
width: '0px',
|
||||||
height: '0px',
|
height: '0px',
|
||||||
lineHeight: '0px',
|
lineHeight: '0px',
|
||||||
visibility: 'hidden'
|
visibility: 'hidden'
|
||||||
}
|
}
|
||||||
: {
|
: {
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
top: '0px',
|
top: '0px',
|
||||||
left: '-9999px',
|
left: '-9999px',
|
||||||
textIndent: '-9999px'
|
textIndent: '-9999px'
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
style = {
|
style = {
|
||||||
position: 'relative',
|
position: 'relative',
|
||||||
|
@@ -226,12 +226,12 @@ function normalizeMarkComponent(render) {
|
|||||||
if (isReactComponent(render)) return render
|
if (isReactComponent(render)) return render
|
||||||
|
|
||||||
switch (typeOf(render)) {
|
switch (typeOf(render)) {
|
||||||
case 'function':
|
case 'function':
|
||||||
return render
|
return render
|
||||||
case 'object':
|
case 'object':
|
||||||
return props => <span style={render}>{props.children}</span>
|
return props => <span style={render}>{props.children}</span>
|
||||||
case 'string':
|
case 'string':
|
||||||
return props => <span className={render}>{props.children}</span>
|
return props => <span className={render}>{props.children}</span>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -594,9 +594,9 @@ class Selection extends new Record(DEFAULTS) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
moveEndOffset(n = 1) {
|
moveEndOffset(n = 1) {
|
||||||
return this.isBackward
|
return this.isBackward
|
||||||
? this.merge({ anchorOffset: this.anchorOffset + n })
|
? this.merge({ anchorOffset: this.anchorOffset + n })
|
||||||
: this.merge({ focusOffset: this.focusOffset + n })
|
: this.merge({ focusOffset: this.focusOffset + n })
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -425,8 +425,8 @@ class State extends new Record(DEFAULTS) {
|
|||||||
transform(properties = {}) {
|
transform(properties = {}) {
|
||||||
const state = this
|
const state = this
|
||||||
return new Transform({
|
return new Transform({
|
||||||
...properties,
|
...properties,
|
||||||
state
|
state
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -44,9 +44,9 @@ class Text extends new Record(DEFAULTS) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static createFromString(text, marks = Set()) {
|
static createFromString(text, marks = Set()) {
|
||||||
return Text.createFromRanges([
|
return Text.createFromRanges([
|
||||||
Range.create({ text, marks })
|
Range.create({ text, marks })
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -57,12 +57,12 @@ class Text extends new Record(DEFAULTS) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static createFromRanges(ranges) {
|
static createFromRanges(ranges) {
|
||||||
return Text.create({
|
return Text.create({
|
||||||
characters: ranges.reduce((characters, range) => {
|
characters: ranges.reduce((characters, range) => {
|
||||||
range = Range.create(range)
|
range = Range.create(range)
|
||||||
return characters.concat(range.getCharacters())
|
return characters.concat(range.getCharacters())
|
||||||
}, Character.createList())
|
}, Character.createList())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -261,11 +261,11 @@ function Plugin(options = {}) {
|
|||||||
debug('onDrop', { data })
|
debug('onDrop', { data })
|
||||||
|
|
||||||
switch (data.type) {
|
switch (data.type) {
|
||||||
case 'text':
|
case 'text':
|
||||||
case 'html':
|
case 'html':
|
||||||
return onDropText(e, data, state)
|
return onDropText(e, data, state)
|
||||||
case 'fragment':
|
case 'fragment':
|
||||||
return onDropFragment(e, data, state)
|
return onDropFragment(e, data, state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -346,14 +346,14 @@ function Plugin(options = {}) {
|
|||||||
debug('onKeyDown', { data })
|
debug('onKeyDown', { data })
|
||||||
|
|
||||||
switch (data.key) {
|
switch (data.key) {
|
||||||
case 'enter': return onKeyDownEnter(e, data, state)
|
case 'enter': return onKeyDownEnter(e, data, state)
|
||||||
case 'backspace': return onKeyDownBackspace(e, data, state)
|
case 'backspace': return onKeyDownBackspace(e, data, state)
|
||||||
case 'delete': return onKeyDownDelete(e, data, state)
|
case 'delete': return onKeyDownDelete(e, data, state)
|
||||||
case 'left': return onKeyDownLeft(e, data, state)
|
case 'left': return onKeyDownLeft(e, data, state)
|
||||||
case 'right': return onKeyDownRight(e, data, state)
|
case 'right': return onKeyDownRight(e, data, state)
|
||||||
case 'y': return onKeyDownY(e, data, state)
|
case 'y': return onKeyDownY(e, data, state)
|
||||||
case 'z': return onKeyDownZ(e, data, state)
|
case 'z': return onKeyDownZ(e, data, state)
|
||||||
case 'k': return onKeyDownK(e, data, state)
|
case 'k': return onKeyDownK(e, data, state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -625,11 +625,11 @@ function Plugin(options = {}) {
|
|||||||
debug('onPaste', { data })
|
debug('onPaste', { data })
|
||||||
|
|
||||||
switch (data.type) {
|
switch (data.type) {
|
||||||
case 'fragment':
|
case 'fragment':
|
||||||
return onPasteFragment(e, data, state)
|
return onPasteFragment(e, data, state)
|
||||||
case 'text':
|
case 'text':
|
||||||
case 'html':
|
case 'html':
|
||||||
return onPasteText(e, data, state)
|
return onPasteText(e, data, state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -701,60 +701,60 @@ function Plugin(options = {}) {
|
|||||||
* Extend core schema with rendering
|
* Extend core schema with rendering
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A default schema rule to render block nodes.
|
* A default schema rule to render block nodes.
|
||||||
*
|
*
|
||||||
* @type {Object}
|
* @type {Object}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const BLOCK_RENDER_RULE = {
|
const BLOCK_RENDER_RULE = {
|
||||||
match: (node) => {
|
match: (node) => {
|
||||||
return node.kind == 'block'
|
return node.kind == 'block'
|
||||||
},
|
},
|
||||||
render: (props) => {
|
render: (props) => {
|
||||||
return (
|
return (
|
||||||
<div {...props.attributes} style={{ position: 'relative' }}>
|
<div {...props.attributes} style={{ position: 'relative' }}>
|
||||||
{props.children}
|
{props.children}
|
||||||
{placeholder
|
{placeholder
|
||||||
? <Placeholder
|
? <Placeholder
|
||||||
className={placeholderClassName}
|
className={placeholderClassName}
|
||||||
node={props.node}
|
node={props.node}
|
||||||
parent={props.state.document}
|
parent={props.state.document}
|
||||||
state={props.state}
|
state={props.state}
|
||||||
style={placeholderStyle}
|
style={placeholderStyle}
|
||||||
>
|
>
|
||||||
{placeholder}
|
{placeholder}
|
||||||
</Placeholder>
|
</Placeholder>
|
||||||
: null}
|
: null}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A default schema rule to render inline nodes.
|
* A default schema rule to render inline nodes.
|
||||||
*
|
*
|
||||||
* @type {Object}
|
* @type {Object}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const INLINE_RENDER_RULE = {
|
const INLINE_RENDER_RULE = {
|
||||||
match: (node) => {
|
match: (node) => {
|
||||||
return node.kind == 'inline'
|
return node.kind == 'inline'
|
||||||
},
|
},
|
||||||
render: (props) => {
|
render: (props) => {
|
||||||
return (
|
return (
|
||||||
<span {...props.attributes} style={{ position: 'relative' }}>
|
<span {...props.attributes} style={{ position: 'relative' }}>
|
||||||
{props.children}
|
{props.children}
|
||||||
</span>
|
</span>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const schema = {
|
const schema = {
|
||||||
rules: [
|
rules: [
|
||||||
BLOCK_RENDER_RULE,
|
BLOCK_RENDER_RULE,
|
||||||
INLINE_RENDER_RULE
|
INLINE_RENDER_RULE
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -57,16 +57,16 @@ const BLOCK_CHILDREN_RULE = {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
const MIN_TEXT_RULE = {
|
const MIN_TEXT_RULE = {
|
||||||
match: (object) => {
|
match: (object) => {
|
||||||
return object.kind == 'block' || object.kind == 'inline'
|
return object.kind == 'block' || object.kind == 'inline'
|
||||||
},
|
},
|
||||||
validate: (node) => {
|
validate: (node) => {
|
||||||
const { nodes } = node
|
const { nodes } = node
|
||||||
return nodes.size === 0 ? true : null
|
return nodes.size === 0 ? true : null
|
||||||
},
|
},
|
||||||
normalize: (transform, node) => {
|
normalize: (transform, node) => {
|
||||||
return transform.insertNodeByKey(node.key, 0, Text.create(), { normalize: false })
|
return transform.insertNodeByKey(node.key, 0, Text.create(), { normalize: false })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -83,7 +83,7 @@ const INLINE_CHILDREN_RULE = {
|
|||||||
const { nodes } = inline
|
const { nodes } = inline
|
||||||
const invalids = nodes.filter(n => n.kind != 'inline' && n.kind != 'text')
|
const invalids = nodes.filter(n => n.kind != 'inline' && n.kind != 'text')
|
||||||
return invalids.size ? invalids : null
|
return invalids.size ? invalids : null
|
||||||
},
|
},
|
||||||
normalize: (transform, inline, invalids) => {
|
normalize: (transform, inline, invalids) => {
|
||||||
return invalids.reduce((t, n) => t.removeNodeByKey(n.key, { normalize: false }), transform)
|
return invalids.reduce((t, n) => t.removeNodeByKey(n.key, { normalize: false }), transform)
|
||||||
}
|
}
|
||||||
@@ -131,11 +131,11 @@ const INLINE_VOID_TEXT_RULE = {
|
|||||||
return node.text !== ' ' || node.nodes.size !== 1
|
return node.text !== ' ' || node.nodes.size !== 1
|
||||||
},
|
},
|
||||||
normalize: (transform, node, result) => {
|
normalize: (transform, node, result) => {
|
||||||
transform = node.nodes.reduce((t, child) => {
|
transform = node.nodes.reduce((t, child) => {
|
||||||
return t.removeNodeByKey(child.key, { normalize: false })
|
return t.removeNodeByKey(child.key, { normalize: false })
|
||||||
}, transform)
|
}, transform)
|
||||||
|
|
||||||
return transform.insertNodeByKey(node.key, 0, Text.createFromString(' '), { normalize: false })
|
return transform.insertNodeByKey(node.key, 0, Text.createFromString(' '), { normalize: false })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -240,43 +240,43 @@ const NO_EMPTY_TEXT_RULE = {
|
|||||||
const { nodes } = node
|
const { nodes } = node
|
||||||
|
|
||||||
if (nodes.size <= 1) {
|
if (nodes.size <= 1) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const invalids = nodes
|
const invalids = nodes
|
||||||
.filter((desc, i) => {
|
.filter((desc, i) => {
|
||||||
if (desc.kind != 'text' || desc.length > 0) {
|
if (desc.kind != 'text' || desc.length > 0) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Empty text nodes are only allowed near inline void node
|
// Empty text nodes are only allowed near inline void node
|
||||||
const next = nodes.get(i + 1)
|
const next = nodes.get(i + 1)
|
||||||
const prev = i > 0 ? nodes.get(i - 1) : null
|
const prev = i > 0 ? nodes.get(i - 1) : null
|
||||||
|
|
||||||
// If last one and previous is an inline void, we need to preserve it
|
// If last one and previous is an inline void, we need to preserve it
|
||||||
if (!next && isInlineVoid(prev)) {
|
if (!next && isInlineVoid(prev)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// If first one and next one is an inline, we preserve it
|
// If first one and next one is an inline, we preserve it
|
||||||
if (!prev && isInlineVoid(next)) {
|
if (!prev && isInlineVoid(next)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// If surrounded by inline void, we preserve it
|
// If surrounded by inline void, we preserve it
|
||||||
if (next && prev && isInlineVoid(next) && isInlineVoid(prev)) {
|
if (next && prev && isInlineVoid(next) && isInlineVoid(prev)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise we remove it
|
// Otherwise we remove it
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
|
||||||
return invalids.size ? invalids : null
|
return invalids.size ? invalids : null
|
||||||
},
|
},
|
||||||
normalize: (transform, node, invalids) => {
|
normalize: (transform, node, invalids) => {
|
||||||
return invalids.reduce((t, text) => {
|
return invalids.reduce((t, text) => {
|
||||||
return t.removeNodeByKey(text.key, { normalize: false })
|
return t.removeNodeByKey(text.key, { normalize: false })
|
||||||
}, transform)
|
}, transform)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -129,17 +129,17 @@ class Html {
|
|||||||
elements.forEach((element) => {
|
elements.forEach((element) => {
|
||||||
const node = this.deserializeElement(element)
|
const node = this.deserializeElement(element)
|
||||||
switch (typeOf(node)) {
|
switch (typeOf(node)) {
|
||||||
case 'array':
|
case 'array':
|
||||||
nodes = nodes.concat(node)
|
nodes = nodes.concat(node)
|
||||||
break
|
break
|
||||||
case 'object':
|
case 'object':
|
||||||
nodes.push(node)
|
nodes.push(node)
|
||||||
break
|
break
|
||||||
case 'null':
|
case 'null':
|
||||||
case 'undefined':
|
case 'undefined':
|
||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
throw new Error(`A rule returned an invalid deserialized representation: "${node}".`)
|
throw new Error(`A rule returned an invalid deserialized representation: "${node}".`)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -158,15 +158,15 @@ class Html {
|
|||||||
|
|
||||||
const next = (elements) => {
|
const next = (elements) => {
|
||||||
switch (typeOf(elements)) {
|
switch (typeOf(elements)) {
|
||||||
case 'array':
|
case 'array':
|
||||||
return this.deserializeElements(elements)
|
return this.deserializeElements(elements)
|
||||||
case 'object':
|
case 'object':
|
||||||
return this.deserializeElement(elements)
|
return this.deserializeElement(elements)
|
||||||
case 'null':
|
case 'null':
|
||||||
case 'undefined':
|
case 'undefined':
|
||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
throw new Error(`The \`next\` argument was called with invalid children: "${elements}".`)
|
throw new Error(`The \`next\` argument was called with invalid children: "${elements}".`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -110,13 +110,13 @@ const Raw = {
|
|||||||
|
|
||||||
deserializeNode(object, options) {
|
deserializeNode(object, options) {
|
||||||
switch (object.kind) {
|
switch (object.kind) {
|
||||||
case 'block': return Raw.deserializeBlock(object, options)
|
case 'block': return Raw.deserializeBlock(object, options)
|
||||||
case 'document': return Raw.deserializeDocument(object, options)
|
case 'document': return Raw.deserializeDocument(object, options)
|
||||||
case 'inline': return Raw.deserializeInline(object, options)
|
case 'inline': return Raw.deserializeInline(object, options)
|
||||||
case 'text': return Raw.deserializeText(object, options)
|
case 'text': return Raw.deserializeText(object, options)
|
||||||
default: {
|
default: {
|
||||||
throw new Error(`Unrecognized node kind "${object.kind}".`)
|
throw new Error(`Unrecognized node kind "${object.kind}".`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -291,13 +291,13 @@ const Raw = {
|
|||||||
|
|
||||||
serializeNode(node, options) {
|
serializeNode(node, options) {
|
||||||
switch (node.kind) {
|
switch (node.kind) {
|
||||||
case 'block': return Raw.serializeBlock(node, options)
|
case 'block': return Raw.serializeBlock(node, options)
|
||||||
case 'document': return Raw.serializeDocument(node, options)
|
case 'document': return Raw.serializeDocument(node, options)
|
||||||
case 'inline': return Raw.serializeInline(node, options)
|
case 'inline': return Raw.serializeInline(node, options)
|
||||||
case 'text': return Raw.serializeText(node, options)
|
case 'text': return Raw.serializeText(node, options)
|
||||||
default: {
|
default: {
|
||||||
throw new Error(`Unrecognized node kind "${node.kind}".`)
|
throw new Error(`Unrecognized node kind "${node.kind}".`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@@ -193,10 +193,10 @@ export function normalizeWith(transform, schema, prevDocument) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export function normalize(transform) {
|
export function normalize(transform) {
|
||||||
transform = transform
|
transform = transform
|
||||||
.normalizeDocument()
|
.normalizeDocument()
|
||||||
.normalizeSelection()
|
.normalizeSelection()
|
||||||
return transform
|
return transform
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -272,15 +272,15 @@ export function normalizeSelection(transform) {
|
|||||||
!document.hasDescendant(selection.anchorKey) ||
|
!document.hasDescendant(selection.anchorKey) ||
|
||||||
!document.hasDescendant(selection.focusKey)
|
!document.hasDescendant(selection.focusKey)
|
||||||
) {
|
) {
|
||||||
warning('Selection was invalid and reset to start of the document')
|
warning('Selection was invalid and reset to start of the document')
|
||||||
const firstText = document.getTexts().first()
|
const firstText = document.getTexts().first()
|
||||||
selection = selection.merge({
|
selection = selection.merge({
|
||||||
anchorKey: firstText.key,
|
anchorKey: firstText.key,
|
||||||
anchorOffset: 0,
|
anchorOffset: 0,
|
||||||
focusKey: firstText.key,
|
focusKey: firstText.key,
|
||||||
focusOffset: 0,
|
focusOffset: 0,
|
||||||
isBackward: false
|
isBackward: false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
state = state.merge({ selection })
|
state = state.merge({ selection })
|
||||||
|
@@ -380,10 +380,10 @@ export function setSelectionOperation(transform, properties) {
|
|||||||
// If the selection moves, clear any marks, unless the new selection
|
// If the selection moves, clear any marks, unless the new selection
|
||||||
// does change the marks in some way
|
// does change the marks in some way
|
||||||
const moved = [
|
const moved = [
|
||||||
'anchorKey',
|
'anchorKey',
|
||||||
'anchorOffset',
|
'anchorOffset',
|
||||||
'focusKey',
|
'focusKey',
|
||||||
'focusOffset',
|
'focusOffset',
|
||||||
].some(p => props.hasOwnProperty(p))
|
].some(p => props.hasOwnProperty(p))
|
||||||
|
|
||||||
if (selection.marks
|
if (selection.marks
|
||||||
|
@@ -20,13 +20,12 @@ function block(value) {
|
|||||||
if (value instanceof Block) return value
|
if (value instanceof Block) return value
|
||||||
|
|
||||||
switch (typeOf(value)) {
|
switch (typeOf(value)) {
|
||||||
case 'string':
|
case 'string':
|
||||||
case 'object': {
|
case 'object':
|
||||||
return Block.create(nodeProperties(value))
|
return Block.create(nodeProperties(value))
|
||||||
}
|
|
||||||
default: {
|
default:
|
||||||
throw new Error(`Invalid \`block\` argument! It must be a block, an object, or a string. You passed: "${value}".`)
|
throw new Error(`Invalid \`block\` argument! It must be a block, an object, or a string. You passed: "${value}".`)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,13 +40,12 @@ function inline(value) {
|
|||||||
if (value instanceof Inline) return value
|
if (value instanceof Inline) return value
|
||||||
|
|
||||||
switch (typeOf(value)) {
|
switch (typeOf(value)) {
|
||||||
case 'string':
|
case 'string':
|
||||||
case 'object': {
|
case 'object':
|
||||||
return Inline.create(nodeProperties(value))
|
return Inline.create(nodeProperties(value))
|
||||||
}
|
|
||||||
default: {
|
default:
|
||||||
throw new Error(`Invalid \`inline\` argument! It must be an inline, an object, or a string. You passed: "${value}".`)
|
throw new Error(`Invalid \`inline\` argument! It must be an inline, an object, or a string. You passed: "${value}".`)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,13 +79,12 @@ function mark(value) {
|
|||||||
if (value instanceof Mark) return value
|
if (value instanceof Mark) return value
|
||||||
|
|
||||||
switch (typeOf(value)) {
|
switch (typeOf(value)) {
|
||||||
case 'string':
|
case 'string':
|
||||||
case 'object': {
|
case 'object':
|
||||||
return Mark.create(markProperties(value))
|
return Mark.create(markProperties(value))
|
||||||
}
|
|
||||||
default: {
|
default:
|
||||||
throw new Error(`Invalid \`mark\` argument! It must be a mark, an object, or a string. You passed: "${value}".`)
|
throw new Error(`Invalid \`mark\` argument! It must be a mark, an object, or a string. You passed: "${value}".`)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,23 +99,22 @@ function markProperties(value = {}) {
|
|||||||
const ret = {}
|
const ret = {}
|
||||||
|
|
||||||
switch (typeOf(value)) {
|
switch (typeOf(value)) {
|
||||||
case 'string': {
|
case 'string':
|
||||||
ret.type = value
|
ret.type = value
|
||||||
break
|
break
|
||||||
}
|
|
||||||
case 'object': {
|
case 'object':
|
||||||
for (const k in value) {
|
for (const k in value) {
|
||||||
if (k == 'data') {
|
if (k == 'data') {
|
||||||
if (value[k] !== undefined) ret[k] = Data.create(value[k])
|
if (value[k] !== undefined) ret[k] = Data.create(value[k])
|
||||||
} else {
|
} else {
|
||||||
ret[k] = value[k]
|
ret[k] = value[k]
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
throw new Error(`Invalid mark \`properties\` argument! It must be an object, a string or a mark. You passed: "${value}".`)
|
|
||||||
}
|
}
|
||||||
|
break
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new Error(`Invalid mark \`properties\` argument! It must be an object, a string or a mark. You passed: "${value}".`)
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
@@ -135,24 +131,23 @@ function nodeProperties(value = {}) {
|
|||||||
const ret = {}
|
const ret = {}
|
||||||
|
|
||||||
switch (typeOf(value)) {
|
switch (typeOf(value)) {
|
||||||
case 'string': {
|
case 'string':
|
||||||
ret.type = value
|
ret.type = value
|
||||||
break
|
break
|
||||||
}
|
|
||||||
case 'object': {
|
case 'object':
|
||||||
if (value.isVoid !== undefined) ret.isVoid = !!value.isVoid
|
if (value.isVoid !== undefined) ret.isVoid = !!value.isVoid
|
||||||
for (const k in value) {
|
for (const k in value) {
|
||||||
if (k == 'data') {
|
if (k == 'data') {
|
||||||
if (value[k] !== undefined) ret[k] = Data.create(value[k])
|
if (value[k] !== undefined) ret[k] = Data.create(value[k])
|
||||||
} else {
|
} else {
|
||||||
ret[k] = value[k]
|
ret[k] = value[k]
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
throw new Error(`Invalid node \`properties\` argument! It must be an object, a string or a node. You passed: "${value}".`)
|
|
||||||
}
|
}
|
||||||
|
break
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new Error(`Invalid node \`properties\` argument! It must be an object, a string or a node. You passed: "${value}".`)
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
@@ -169,12 +164,11 @@ function selection(value) {
|
|||||||
if (value instanceof Selection) return value
|
if (value instanceof Selection) return value
|
||||||
|
|
||||||
switch (typeOf(value)) {
|
switch (typeOf(value)) {
|
||||||
case 'object': {
|
case 'object':
|
||||||
return Selection.create(value)
|
return Selection.create(value)
|
||||||
}
|
|
||||||
default: {
|
default:
|
||||||
throw new Error(`Invalid \`selection\` argument! It must be a selection or an object. You passed: "${value}".`)
|
throw new Error(`Invalid \`selection\` argument! It must be a selection or an object. You passed: "${value}".`)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,19 +183,18 @@ function selectionProperties(value = {}) {
|
|||||||
const ret = {}
|
const ret = {}
|
||||||
|
|
||||||
switch (typeOf(value)) {
|
switch (typeOf(value)) {
|
||||||
case 'object': {
|
case 'object':
|
||||||
if (value.anchorKey !== undefined) ret.anchorKey = value.anchorKey
|
if (value.anchorKey !== undefined) ret.anchorKey = value.anchorKey
|
||||||
if (value.anchorOffset !== undefined) ret.anchorOffset = value.anchorOffset
|
if (value.anchorOffset !== undefined) ret.anchorOffset = value.anchorOffset
|
||||||
if (value.focusKey !== undefined) ret.focusKey = value.focusKey
|
if (value.focusKey !== undefined) ret.focusKey = value.focusKey
|
||||||
if (value.focusOffset !== undefined) ret.focusOffset = value.focusOffset
|
if (value.focusOffset !== undefined) ret.focusOffset = value.focusOffset
|
||||||
if (value.isBackward !== undefined) ret.isBackward = !!value.isBackward
|
if (value.isBackward !== undefined) ret.isBackward = !!value.isBackward
|
||||||
if (value.isFocused !== undefined) ret.isFocused = !!value.isFocused
|
if (value.isFocused !== undefined) ret.isFocused = !!value.isFocused
|
||||||
if (value.marks !== undefined) ret.marks = value.marks
|
if (value.marks !== undefined) ret.marks = value.marks
|
||||||
break
|
break
|
||||||
}
|
|
||||||
default: {
|
default:
|
||||||
throw new Error(`Invalid selection \`properties\` argument! It must be an object or a selection. You passed: "${value}".`)
|
throw new Error(`Invalid selection \`properties\` argument! It must be an object or a selection. You passed: "${value}".`)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
@@ -41,22 +41,22 @@ class Transfer {
|
|||||||
data.type = type
|
data.type = type
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'files':
|
case 'files':
|
||||||
data.files = this.getFiles()
|
data.files = this.getFiles()
|
||||||
break
|
break
|
||||||
case 'fragment':
|
case 'fragment':
|
||||||
data.fragment = this.getFragment()
|
data.fragment = this.getFragment()
|
||||||
break
|
break
|
||||||
case 'html':
|
case 'html':
|
||||||
data.html = this.getHtml()
|
data.html = this.getHtml()
|
||||||
data.text = this.getText()
|
data.text = this.getText()
|
||||||
break
|
break
|
||||||
case 'node':
|
case 'node':
|
||||||
data.node = this.getNode()
|
data.node = this.getNode()
|
||||||
break
|
break
|
||||||
case 'text':
|
case 'text':
|
||||||
data.text = this.getText()
|
data.text = this.getText()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
return data
|
return data
|
||||||
@@ -76,8 +76,8 @@ class Transfer {
|
|||||||
|
|
||||||
if (data.items && data.items.length) {
|
if (data.items && data.items.length) {
|
||||||
const fileItems = Array.from(data.items)
|
const fileItems = Array.from(data.items)
|
||||||
.map(item => item.kind == 'file' ? item.getAsFile() : null)
|
.map(item => item.kind == 'file' ? item.getAsFile() : null)
|
||||||
.filter(exists => exists)
|
.filter(exists => exists)
|
||||||
|
|
||||||
if (fileItems.length) files = fileItems
|
if (fileItems.length) files = fileItems
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user