mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-27 14:59:27 +08:00
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:
parent
2ca1a7b9bd
commit
574cd69e06
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -1,7 +0,0 @@
|
||||
export function isClass(value: any): boolean {
|
||||
if (value.constructor?.toString().substring(0, 5) !== 'class') {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
import { isClass } from './isClass'
|
||||
|
||||
export function isObject(value: any): boolean {
|
||||
return (
|
||||
value
|
||||
&& typeof value === 'object'
|
||||
&& !Array.isArray(value)
|
||||
&& !isClass(value)
|
||||
)
|
||||
}
|
@ -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)
|
||||
})
|
||||
})
|
Loading…
Reference in New Issue
Block a user