1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-20 06:01:24 +02:00

fix: Operation.isOperationList just check value[0] (#4061)

* Fix list queries.
This commit is contained in:
Jacob
2021-01-31 23:21:04 +08:00
committed by GitHub
parent 295be40039
commit 0513539ed7
10 changed files with 89 additions and 39 deletions

View File

@@ -1,3 +1,3 @@
This package contains the core logic of Slate. Feel free to poke around to learn more! This package contains the core logic of Slate. Feel free to poke around to learn more!
Note: A number of source files contain extracted types for `Interfaces` or `Transforms`. This is done currently to enable custom type extensions as found in `packages/src/interfaces/custom-types.ts`. Note: A number of source files contain extracted types for `Interfaces` or `Transforms`. This is done currently to enable custom type extensions as found in `packages/src/interfaces/custom-types.ts`.

View File

@@ -47,10 +47,7 @@ export const Element: ElementInterface = {
*/ */
isElementList(value: any): value is Element[] { isElementList(value: any): value is Element[] {
return ( return Array.isArray(value) && value.every(val => Element.isElement(val))
Array.isArray(value) &&
(value.length === 0 || Element.isElement(value[0]))
)
}, },
/** /**

View File

@@ -383,7 +383,7 @@ export const Node: NodeInterface = {
*/ */
isNodeList(value: any): value is Node[] { isNodeList(value: any): value is Node[] {
return Array.isArray(value) && (value.length === 0 || Node.isNode(value[0])) return Array.isArray(value) && value.every(val => Node.isNode(val))
}, },
/** /**

View File

@@ -219,8 +219,7 @@ export const Operation: OperationInterface = {
isOperationList(value: any): value is Operation[] { isOperationList(value: any): value is Operation[] {
return ( return (
Array.isArray(value) && Array.isArray(value) && value.every(val => Operation.isOperation(val))
(value.length === 0 || Operation.isOperation(value[0]))
) )
}, },

View File

@@ -71,7 +71,7 @@ export const Text: TextInterface = {
*/ */
isTextList(value: any): value is Text[] { isTextList(value: any): value is Text[] {
return Array.isArray(value) && (value.length === 0 || Text.isText(value[0])) return Array.isArray(value) && value.every(val => Text.isText(val))
}, },
/** /**

View File

@@ -0,0 +1,17 @@
import { Element } from 'slate'
export const input = [
{
children: [],
},
{
type: 'set_node',
path: [0],
properties: {},
newProperties: {},
},
]
export const test = value => {
return Element.isElementList(value)
}
export const output = false

View File

@@ -0,0 +1,13 @@
import { Node } from 'slate'
export const input = [
{
children: [],
selection: null,
},
'a string',
]
export const test = value => {
return Node.isNodeList(value)
}
export const output = false

View File

@@ -0,0 +1,17 @@
import { Operation } from 'slate'
export const input = [
{
type: 'set_node',
path: [0],
properties: {},
newProperties: {},
},
{
text: '',
},
]
export const test = value => {
return Operation.isOperationList(value)
}
export const output = false

View File

@@ -0,0 +1,17 @@
import { Text } from 'slate'
export const input = [
{
text: '',
},
{
type: 'set_node',
path: [0],
properties: {},
newProperties: {},
},
]
export const test = value => {
return Text.isTextList(value)
}
export const output = false

View File

@@ -1,30 +1,20 @@
{ {
"compilerOptions": { "compilerOptions": {
"target": "es5", "target": "es5",
"lib": [ "lib": ["dom", "dom.iterable", "esnext"],
"dom", "allowJs": true,
"dom.iterable", "skipLibCheck": true,
"esnext" "strict": false,
], "downlevelIteration": true,
"allowJs": true, "forceConsistentCasingInFileNames": true,
"skipLibCheck": true, "noEmit": true,
"strict": false, "esModuleInterop": true,
"downlevelIteration": true, "module": "esnext",
"forceConsistentCasingInFileNames": true, "moduleResolution": "node",
"noEmit": true, "resolveJsonModule": true,
"esModuleInterop": true, "isolatedModules": true,
"module": "esnext", "jsx": "preserve"
"moduleResolution": "node", },
"resolveJsonModule": true, "exclude": ["node_modules"],
"isolatedModules": true, "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"]
"jsx": "preserve" }
},
"exclude": [
"node_modules"
],
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx"
]
}