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