improve types
This commit is contained in:
@@ -11,7 +11,7 @@ import {
|
||||
* Get a list of all extension attributes defined in `addAttribute` and `addGlobalAttribute`.
|
||||
* @param extensions List of extensions
|
||||
*/
|
||||
export default function getAttributesFromExtensions(extensions: Extensions) {
|
||||
export default function getAttributesFromExtensions(extensions: Extensions): ExtensionAttribute[] {
|
||||
const extensionAttributes: ExtensionAttribute[] = []
|
||||
const { nodeExtensions, markExtensions } = splitExtensions(extensions)
|
||||
const nodeAndMarkExtensions = [...nodeExtensions, ...markExtensions]
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { EditorState } from 'prosemirror-state'
|
||||
import { Mark, MarkType } from 'prosemirror-model'
|
||||
import getMarkType from './getMarkType'
|
||||
import { AnyObject } from '../types'
|
||||
|
||||
export default function getMarkAttributes(state: EditorState, typeOrName: string | MarkType) {
|
||||
export default function getMarkAttributes(state: EditorState, typeOrName: string | MarkType): AnyObject {
|
||||
const type = getMarkType(typeOrName, state.schema)
|
||||
const { from, to, empty } = state.selection
|
||||
let marks: Mark[] = []
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
import { MarkType, ResolvedPos } from 'prosemirror-model'
|
||||
|
||||
interface Range {
|
||||
from: number,
|
||||
to: number,
|
||||
}
|
||||
import { Range } from '../types'
|
||||
|
||||
export default function getMarkRange($pos: ResolvedPos, type: MarkType): Range | void {
|
||||
if (!$pos || !type) {
|
||||
|
||||
22
packages/core/src/helpers/getMarksBetween.ts
Normal file
22
packages/core/src/helpers/getMarksBetween.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { Mark } from 'prosemirror-model'
|
||||
import { EditorState } from 'prosemirror-state'
|
||||
|
||||
export type MarkPosition = {
|
||||
mark: Mark,
|
||||
start: number,
|
||||
end: number,
|
||||
}
|
||||
|
||||
export default function getMarksBetween(start: number, end: number, state: EditorState): MarkPosition[] {
|
||||
let marks: MarkPosition[] = []
|
||||
|
||||
state.doc.nodesBetween(start, end, (node, pos) => {
|
||||
marks = [...marks, ...node.marks.map(mark => ({
|
||||
start: pos,
|
||||
end: pos + node.nodeSize,
|
||||
mark,
|
||||
}))]
|
||||
})
|
||||
|
||||
return marks
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
import { EditorState } from 'prosemirror-state'
|
||||
import { Node, NodeType } from 'prosemirror-model'
|
||||
import getNodeType from './getNodeType'
|
||||
import { AnyObject } from '../types'
|
||||
|
||||
export default function getNodeAttributes(state: EditorState, typeOrName: string | NodeType) {
|
||||
export default function getNodeAttributes(state: EditorState, typeOrName: string | NodeType): AnyObject {
|
||||
const type = getNodeType(typeOrName, state.schema)
|
||||
const { from, to } = state.selection
|
||||
let nodes: Node[] = []
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Schema } from 'prosemirror-model'
|
||||
import { MarkType, NodeType, Schema } from 'prosemirror-model'
|
||||
|
||||
export default function getSchemaTypeByName(name: string, schema: Schema) {
|
||||
export default function getSchemaTypeByName(name: string, schema: Schema): NodeType | MarkType | null {
|
||||
if (schema.nodes[name]) {
|
||||
return schema.nodes[name]
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Schema } from 'prosemirror-model'
|
||||
|
||||
export default function getSchemaTypeNameByName(name: string, schema: Schema) {
|
||||
export default function getSchemaTypeNameByName(name: string, schema: Schema): 'node' | 'mark' | null {
|
||||
if (schema.nodes[name]) {
|
||||
return 'node'
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Extensions } from '../types'
|
||||
import splitExtensions from './splitExtensions'
|
||||
import callOrReturn from '../utilities/callOrReturn'
|
||||
|
||||
export default function isList(name: string, extensions: Extensions) {
|
||||
export default function isList(name: string, extensions: Extensions): boolean {
|
||||
const { nodeExtensions } = splitExtensions(extensions)
|
||||
const extension = nodeExtensions.find(item => item.config.name === name)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user