fix(core): isNodeSelection, isTextSelection not always false (#3089)

Fixes #2979.  Since the ProseMirror TypeScript upgrade, these have
always returned false, since the Selection type tree are all classes
now.
This commit is contained in:
Asherah Connor 2022-08-22 21:05:53 +10:00 committed by GitHub
parent 2ca1a7b9bd
commit 574cd69e06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 2 additions and 42 deletions

View File

@ -1,7 +1,5 @@
import { NodeSelection } from 'prosemirror-state'
import { isObject } from '../utilities/isObject'
export function isNodeSelection(value: unknown): value is NodeSelection {
return isObject(value) && value instanceof NodeSelection
return value instanceof NodeSelection
}

View File

@ -1,7 +1,5 @@
import { TextSelection } from 'prosemirror-state'
import { isObject } from '../utilities/isObject'
export function isTextSelection(value: unknown): value is TextSelection {
return isObject(value) && value instanceof TextSelection
return value instanceof TextSelection
}

View File

@ -1,7 +0,0 @@
export function isClass(value: any): boolean {
if (value.constructor?.toString().substring(0, 5) !== 'class') {
return false
}
return true
}

View File

@ -1,10 +0,0 @@
import { isClass } from './isClass'
export function isObject(value: any): boolean {
return (
value
&& typeof value === 'object'
&& !Array.isArray(value)
&& !isClass(value)
)
}

View File

@ -1,19 +0,0 @@
/// <reference types="cypress" />
import { isClass } from '@tiptap/core/src/utilities/isClass'
describe('isClass', () => {
it('returns true for classes', () => {
const instance = new (class {
public foo = 'bar'
})()
expect(isClass(instance)).to.eq(true)
})
it('return false for objects', () => {
const instance = {}
expect(isClass(instance)).to.eq(false)
})
})