From 0513539ed76c1074b75e7e47f26da97d14ff6d57 Mon Sep 17 00:00:00 2001 From: Jacob Date: Sun, 31 Jan 2021 23:21:04 +0800 Subject: [PATCH] fix: `Operation.isOperationList` just check value[0] (#4061) * Fix list queries. --- packages/slate/Readme.md | 2 +- packages/slate/src/interfaces/element.ts | 5 +- packages/slate/src/interfaces/node.ts | 2 +- packages/slate/src/interfaces/operation.ts | 3 +- packages/slate/src/interfaces/text.ts | 2 +- .../isElementList/not-full-element.tsx | 17 +++++++ .../Node/isNodeList/not-full-node.tsx | 13 +++++ .../isOperationList/not-full-operaion.tsx | 17 +++++++ .../Text/isTextList/not-full-text.tsx | 17 +++++++ site/tsconfig.json | 50 ++++++++----------- 10 files changed, 89 insertions(+), 39 deletions(-) create mode 100644 packages/slate/test/interfaces/Element/isElementList/not-full-element.tsx create mode 100644 packages/slate/test/interfaces/Node/isNodeList/not-full-node.tsx create mode 100644 packages/slate/test/interfaces/Operation/isOperationList/not-full-operaion.tsx create mode 100644 packages/slate/test/interfaces/Text/isTextList/not-full-text.tsx diff --git a/packages/slate/Readme.md b/packages/slate/Readme.md index 815e40311..905dea84f 100644 --- a/packages/slate/Readme.md +++ b/packages/slate/Readme.md @@ -1,3 +1,3 @@ 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`. diff --git a/packages/slate/src/interfaces/element.ts b/packages/slate/src/interfaces/element.ts index 116570dec..e3b1097c8 100755 --- a/packages/slate/src/interfaces/element.ts +++ b/packages/slate/src/interfaces/element.ts @@ -47,10 +47,7 @@ export const Element: ElementInterface = { */ isElementList(value: any): value is Element[] { - return ( - Array.isArray(value) && - (value.length === 0 || Element.isElement(value[0])) - ) + return Array.isArray(value) && value.every(val => Element.isElement(val)) }, /** diff --git a/packages/slate/src/interfaces/node.ts b/packages/slate/src/interfaces/node.ts index a43ddcd58..9d18b882f 100755 --- a/packages/slate/src/interfaces/node.ts +++ b/packages/slate/src/interfaces/node.ts @@ -383,7 +383,7 @@ export const Node: NodeInterface = { */ 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)) }, /** diff --git a/packages/slate/src/interfaces/operation.ts b/packages/slate/src/interfaces/operation.ts index ce9d3a03c..e97431af8 100755 --- a/packages/slate/src/interfaces/operation.ts +++ b/packages/slate/src/interfaces/operation.ts @@ -219,8 +219,7 @@ export const Operation: OperationInterface = { isOperationList(value: any): value is Operation[] { return ( - Array.isArray(value) && - (value.length === 0 || Operation.isOperation(value[0])) + Array.isArray(value) && value.every(val => Operation.isOperation(val)) ) }, diff --git a/packages/slate/src/interfaces/text.ts b/packages/slate/src/interfaces/text.ts index 709fb5604..ddea59864 100755 --- a/packages/slate/src/interfaces/text.ts +++ b/packages/slate/src/interfaces/text.ts @@ -71,7 +71,7 @@ export const Text: TextInterface = { */ 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)) }, /** diff --git a/packages/slate/test/interfaces/Element/isElementList/not-full-element.tsx b/packages/slate/test/interfaces/Element/isElementList/not-full-element.tsx new file mode 100644 index 000000000..074efb28e --- /dev/null +++ b/packages/slate/test/interfaces/Element/isElementList/not-full-element.tsx @@ -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 diff --git a/packages/slate/test/interfaces/Node/isNodeList/not-full-node.tsx b/packages/slate/test/interfaces/Node/isNodeList/not-full-node.tsx new file mode 100644 index 000000000..500b40555 --- /dev/null +++ b/packages/slate/test/interfaces/Node/isNodeList/not-full-node.tsx @@ -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 diff --git a/packages/slate/test/interfaces/Operation/isOperationList/not-full-operaion.tsx b/packages/slate/test/interfaces/Operation/isOperationList/not-full-operaion.tsx new file mode 100644 index 000000000..a4e1fa0f5 --- /dev/null +++ b/packages/slate/test/interfaces/Operation/isOperationList/not-full-operaion.tsx @@ -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 diff --git a/packages/slate/test/interfaces/Text/isTextList/not-full-text.tsx b/packages/slate/test/interfaces/Text/isTextList/not-full-text.tsx new file mode 100644 index 000000000..2c7d39568 --- /dev/null +++ b/packages/slate/test/interfaces/Text/isTextList/not-full-text.tsx @@ -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 diff --git a/site/tsconfig.json b/site/tsconfig.json index 63c677734..5cc4f3db5 100644 --- a/site/tsconfig.json +++ b/site/tsconfig.json @@ -1,30 +1,20 @@ -{ - "compilerOptions": { - "target": "es5", - "lib": [ - "dom", - "dom.iterable", - "esnext" - ], - "allowJs": true, - "skipLibCheck": true, - "strict": false, - "downlevelIteration": true, - "forceConsistentCasingInFileNames": true, - "noEmit": true, - "esModuleInterop": true, - "module": "esnext", - "moduleResolution": "node", - "resolveJsonModule": true, - "isolatedModules": true, - "jsx": "preserve" - }, - "exclude": [ - "node_modules" - ], - "include": [ - "next-env.d.ts", - "**/*.ts", - "**/*.tsx" - ] -} +{ + "compilerOptions": { + "target": "es5", + "lib": ["dom", "dom.iterable", "esnext"], + "allowJs": true, + "skipLibCheck": true, + "strict": false, + "downlevelIteration": true, + "forceConsistentCasingInFileNames": true, + "noEmit": true, + "esModuleInterop": true, + "module": "esnext", + "moduleResolution": "node", + "resolveJsonModule": true, + "isolatedModules": true, + "jsx": "preserve" + }, + "exclude": ["node_modules"], + "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"] +}