mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-24 19:59:02 +08:00
refactoring
This commit is contained in:
parent
bc39e922ca
commit
fe9f74ebdf
@ -2,8 +2,9 @@ import { EditorState } from 'prosemirror-state'
|
||||
import isNodeActive from './isNodeActive'
|
||||
import isMarkActive from './isMarkActive'
|
||||
import getSchemaTypeNameByName from './getSchemaTypeNameByName'
|
||||
import { AnyObject } from '../types'
|
||||
|
||||
export default function isActive(state: EditorState, name: string | null, attributes: { [key: string ]: any } = {}): boolean {
|
||||
export default function isActive(state: EditorState, name: string | null, attributes: AnyObject = {}): boolean {
|
||||
if (!name) {
|
||||
return isNodeActive(state, null, attributes) || isMarkActive(state, null, attributes)
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ import { EditorState } from 'prosemirror-state'
|
||||
import { Mark, MarkType } from 'prosemirror-model'
|
||||
import objectIncludes from '../utilities/objectIncludes'
|
||||
import getMarkType from './getMarkType'
|
||||
import { AnyObject } from '../types'
|
||||
|
||||
export type MarkRange = {
|
||||
mark: Mark,
|
||||
@ -12,7 +13,7 @@ export type MarkRange = {
|
||||
export default function isMarkActive(
|
||||
state: EditorState,
|
||||
typeOrName: MarkType | string | null,
|
||||
attributes = {},
|
||||
attributes: AnyObject = {},
|
||||
): boolean {
|
||||
const { from, to, empty } = state.selection
|
||||
const type = typeOrName
|
||||
|
@ -2,6 +2,7 @@ import { EditorState } from 'prosemirror-state'
|
||||
import { Node, NodeType } from 'prosemirror-model'
|
||||
import objectIncludes from '../utilities/objectIncludes'
|
||||
import getNodeType from './getNodeType'
|
||||
import { AnyObject } from '../types'
|
||||
|
||||
export type NodeRange = {
|
||||
node: Node,
|
||||
@ -12,7 +13,7 @@ export type NodeRange = {
|
||||
export default function isNodeActive(
|
||||
state: EditorState,
|
||||
typeOrName: NodeType | string | null,
|
||||
attributes = {},
|
||||
attributes: AnyObject = {},
|
||||
): boolean {
|
||||
const { from, to, empty } = state.selection
|
||||
const type = typeOrName
|
||||
|
@ -1,16 +1,18 @@
|
||||
import { AnyObject } from '../types'
|
||||
|
||||
/**
|
||||
* Remove a property or an array of properties from an object
|
||||
* @param obj Object
|
||||
* @param key Key to remove
|
||||
*/
|
||||
export default function deleteProps(obj: { [key: string ]: any }, propOrProps: string | string[]) {
|
||||
export default function deleteProps(obj: AnyObject, propOrProps: string | string[]) {
|
||||
const props = typeof propOrProps === 'string'
|
||||
? [propOrProps]
|
||||
: propOrProps
|
||||
|
||||
return Object
|
||||
.keys(obj)
|
||||
.reduce((newObj: { [key: string ]: any }, prop) => {
|
||||
.reduce((newObj: AnyObject, prop) => {
|
||||
if (!props.includes(prop)) {
|
||||
newObj[prop] = obj[prop]
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
import { AnyObject } from '../types'
|
||||
|
||||
/**
|
||||
* Check if object1 includes object2
|
||||
* @param object1 Object
|
||||
* @param object2 Object
|
||||
*/
|
||||
export default function objectIncludes(object1: { [key: string ]: any }, object2: { [key: string ]: any }): boolean {
|
||||
export default function objectIncludes(object1: AnyObject, object2: AnyObject): boolean {
|
||||
const keys = Object.keys(object2)
|
||||
|
||||
if (!keys.length) {
|
||||
|
Loading…
Reference in New Issue
Block a user