@tiptap/core
Advanced tools
Comparing version 2.0.0-alpha.12 to 2.0.0-alpha.13
@@ -6,2 +6,10 @@ # Change Log | ||
# [2.0.0-alpha.13](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/core@2.0.0-alpha.12...@tiptap/core@2.0.0-alpha.13) (2021-01-29) | ||
**Note:** Version bump only for package @tiptap/core | ||
# [2.0.0-alpha.12](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/core@2.0.0-alpha.11...@tiptap/core@2.0.0-alpha.12) (2021-01-28) | ||
@@ -8,0 +16,0 @@ |
import { EditorState, Transaction } from 'prosemirror-state'; | ||
import { Editor } from './Editor'; | ||
import { SingleCommands, ChainedCommands, CanCommands, CommandSpec } from './types'; | ||
import { SingleCommands, ChainedCommands, CanCommands, CommandSpec, CommandProps } from './types'; | ||
export default class CommandManager { | ||
@@ -21,15 +21,4 @@ editor: Editor; | ||
createCan(startTr?: Transaction): CanCommands; | ||
buildProps(tr: Transaction, shouldDispatch?: boolean): { | ||
tr: Transaction<any>; | ||
editor: Editor; | ||
view: import("prosemirror-view").EditorView<any>; | ||
state: EditorState<any>; | ||
dispatch: (() => undefined) | undefined; | ||
chain: () => ChainedCommands; | ||
can: () => CanCommands; | ||
readonly commands: { | ||
[k: string]: (...args: any[]) => any; | ||
}; | ||
}; | ||
buildProps(tr: Transaction, shouldDispatch?: boolean): CommandProps; | ||
chainableState(tr: Transaction, state: EditorState): EditorState; | ||
} |
import { Command } from '../types'; | ||
export interface SplitBlockOptions { | ||
withAttributes: boolean; | ||
withMarks: boolean; | ||
keepMarks: boolean; | ||
} | ||
@@ -6,0 +5,0 @@ /** |
@@ -12,2 +12,3 @@ import { Schema, Node as ProsemirrorNode } from 'prosemirror-model'; | ||
get plugins(): Plugin[]; | ||
get attributes(): import("./types").ExtensionAttribute[]; | ||
get nodeViews(): { | ||
@@ -14,0 +15,0 @@ [k: string]: (node: ProsemirrorNode, view: EditorView, getPos: (() => number) | boolean, decorations: Decoration[]) => {} | import("prosemirror-view").NodeView<any>; |
@@ -37,12 +37,3 @@ import { Extension } from '../Extension'; | ||
focus: (position?: import("@tiptap/core").FocusPosition) => import("@tiptap/core").Command; | ||
first: (commands: import("@tiptap/core").Command[] | ((props: { | ||
editor: import("@tiptap/core").Editor; | ||
tr: import("prosemirror-state").Transaction<any>; | ||
commands: import("@tiptap/core").SingleCommands; | ||
can: () => import("@tiptap/core").CanCommands; | ||
chain: () => import("@tiptap/core").ChainedCommands; | ||
state: import("prosemirror-state").EditorState<any>; | ||
view: import("prosemirror-view").EditorView<any>; | ||
dispatch: ((args?: any) => any) | undefined; | ||
}) => import("@tiptap/core").Command[])) => import("@tiptap/core").Command; | ||
first: (commands: import("@tiptap/core").Command[] | ((props: import("@tiptap/core").CommandProps) => import("@tiptap/core").Command[])) => import("@tiptap/core").Command; | ||
extendMarkRange: (typeOrName: string | import("prosemirror-model").MarkType<any>) => import("@tiptap/core").Command; | ||
@@ -53,12 +44,3 @@ exitCode: () => import("@tiptap/core").Command; | ||
createParagraphNear: () => import("@tiptap/core").Command; | ||
command: (fn: (props: { | ||
editor: import("@tiptap/core").Editor; | ||
tr: import("prosemirror-state").Transaction<any>; | ||
commands: import("@tiptap/core").SingleCommands; | ||
can: () => import("@tiptap/core").CanCommands; | ||
chain: () => import("@tiptap/core").ChainedCommands; | ||
state: import("prosemirror-state").EditorState<any>; | ||
view: import("prosemirror-view").EditorView<any>; | ||
dispatch: ((args?: any) => any) | undefined; | ||
}) => boolean) => import("@tiptap/core").Command; | ||
command: (fn: (props: import("@tiptap/core").CommandProps) => boolean) => import("@tiptap/core").Command; | ||
clearNodes: () => import("@tiptap/core").Command; | ||
@@ -65,0 +47,0 @@ clearContent: (emitUpdate?: Boolean) => import("@tiptap/core").Command; |
import { EditorState } from 'prosemirror-state'; | ||
import { MarkType } from 'prosemirror-model'; | ||
export default function getMarkAttributes(state: EditorState, typeOrName: string | MarkType): { | ||
[x: string]: any; | ||
}; | ||
import { AnyObject } from '../types'; | ||
export default function getMarkAttributes(state: EditorState, typeOrName: string | MarkType): AnyObject; |
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; | ||
export {}; |
import { EditorState } from 'prosemirror-state'; | ||
import { NodeType } from 'prosemirror-model'; | ||
export default function getNodeAttributes(state: EditorState, typeOrName: string | NodeType): { | ||
[x: string]: any; | ||
}; | ||
import { AnyObject } from '../types'; | ||
export default function getNodeAttributes(state: EditorState, typeOrName: string | NodeType): AnyObject; |
@@ -1,2 +0,2 @@ | ||
import { Schema } from 'prosemirror-model'; | ||
export default function getSchemaTypeByName(name: string, schema: Schema): import("prosemirror-model").NodeType<Schema<any, any>> | import("prosemirror-model").MarkType<Schema<any, any>> | null; | ||
import { MarkType, NodeType, Schema } from 'prosemirror-model'; | ||
export default function getSchemaTypeByName(name: string, schema: Schema): NodeType | MarkType | null; |
import { Schema } from 'prosemirror-model'; | ||
export default function getSchemaTypeNameByName(name: string, schema: Schema): "node" | "mark" | null; | ||
export default function getSchemaTypeNameByName(name: string, schema: Schema): 'node' | 'mark' | null; |
import { EditorState } from 'prosemirror-state'; | ||
import { Mark, MarkType } from 'prosemirror-model'; | ||
import { MarkType } from 'prosemirror-model'; | ||
import { AnyObject } from '../types'; | ||
export declare type MarkRange = { | ||
mark: Mark; | ||
from: number; | ||
to: number; | ||
}; | ||
export default function isMarkActive(state: EditorState, typeOrName: MarkType | string | null, attributes?: AnyObject): boolean; |
import { EditorState } from 'prosemirror-state'; | ||
import { Node, NodeType } from 'prosemirror-model'; | ||
import { NodeType } from 'prosemirror-model'; | ||
import { AnyObject } from '../types'; | ||
export declare type NodeRange = { | ||
node: Node; | ||
from: number; | ||
to: number; | ||
}; | ||
export default function isNodeActive(state: EditorState, typeOrName: NodeType | string | null, attributes?: AnyObject): boolean; |
import { InputRule } from 'prosemirror-inputrules'; | ||
import { MarkType } from 'prosemirror-model'; | ||
export default function (regexp: RegExp, markType: MarkType, getAttributes?: Function): InputRule<any>; | ||
export default function (regexp: RegExp, markType: MarkType, getAttributes?: Function): InputRule; |
@@ -1,2 +0,2 @@ | ||
import { Node as ProseMirrorNode, ParseOptions } from 'prosemirror-model'; | ||
import { Node as ProseMirrorNode, Mark as ProseMirrorMark, ParseOptions } from 'prosemirror-model'; | ||
import { EditorView, Decoration, NodeView, EditorProps } from 'prosemirror-view'; | ||
@@ -36,3 +36,3 @@ import { EditorState, Transaction } from 'prosemirror-state'; | ||
export declare type EditorContent = string | JSON | null; | ||
export declare type Command = (props: { | ||
export declare type CommandProps = { | ||
editor: Editor; | ||
@@ -46,3 +46,4 @@ tr: Transaction; | ||
dispatch: ((args?: any) => any) | undefined; | ||
}) => boolean; | ||
}; | ||
export declare type Command = (props: CommandProps) => boolean; | ||
export declare type CommandSpec = (...args: any[]) => Command; | ||
@@ -60,2 +61,3 @@ export declare type Attribute = { | ||
} | null) | null; | ||
keepOnSplit: boolean; | ||
}; | ||
@@ -124,2 +126,12 @@ export declare type Attributes = { | ||
}; | ||
export declare type NodeRange = { | ||
node: ProseMirrorNode; | ||
from: number; | ||
to: number; | ||
}; | ||
export declare type MarkRange = { | ||
mark: ProseMirrorMark; | ||
from: number; | ||
to: number; | ||
}; | ||
export declare type Predicate = (node: ProseMirrorNode) => boolean; |
import { AnyObject } from '../types'; | ||
export default function mergeDeep(target: AnyObject, source: AnyObject): { | ||
[x: string]: any; | ||
}; | ||
export default function mergeDeep(target: AnyObject, source: AnyObject): AnyObject; |
{ | ||
"name": "@tiptap/core", | ||
"description": "headless rich text editor", | ||
"version": "2.0.0-alpha.12", | ||
"version": "2.0.0-alpha.13", | ||
"homepage": "https://tiptap.dev", | ||
@@ -46,3 +46,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "a9c14fbddd6b419b045e3494f89f6f1cf206bc42" | ||
"gitHead": "17c8c8365100c996a1749bd5bb0e3145bad028f0" | ||
} |
@@ -8,2 +8,3 @@ import { EditorState, Transaction } from 'prosemirror-state' | ||
CommandSpec, | ||
CommandProps, | ||
} from './types' | ||
@@ -45,3 +46,3 @@ import getAllMethodNames from './utilities/getAllMethodNames' | ||
public createCommands() { | ||
public createCommands(): SingleCommands { | ||
const { commands, editor } = this | ||
@@ -69,3 +70,3 @@ const { state, view } = editor | ||
public createChain(startTr?: Transaction, shouldDispatch = true) { | ||
public createChain(startTr?: Transaction, shouldDispatch = true): ChainedCommands { | ||
const { commands, editor } = this | ||
@@ -105,3 +106,3 @@ const { state, view } = editor | ||
public createCan(startTr?: Transaction) { | ||
public createCan(startTr?: Transaction): CanCommands { | ||
const { commands, editor } = this | ||
@@ -124,3 +125,3 @@ const { state } = editor | ||
public buildProps(tr: Transaction, shouldDispatch = true) { | ||
public buildProps(tr: Transaction, shouldDispatch = true): CommandProps { | ||
const { editor, commands } = this | ||
@@ -148,3 +149,3 @@ const { state, view } = editor | ||
return [name, (...args: any[]) => command(...args)(props)] | ||
})) | ||
})) as SingleCommands | ||
}, | ||
@@ -151,0 +152,0 @@ } |
@@ -21,3 +21,3 @@ import { liftTarget } from 'prosemirror-transform' | ||
if (node.type.isTextblock && dispatch) { | ||
tr.setNodeMarkup(nodeRange.start, state.schema.nodes.paragraph) | ||
tr.setNodeMarkup(nodeRange.start, state.doc.type.contentMatch.defaultType) | ||
} | ||
@@ -24,0 +24,0 @@ |
@@ -5,2 +5,3 @@ import { canSplit } from 'prosemirror-transform' | ||
import { Command } from '../types' | ||
import getSplittedAttributes from '../helpers/getSplittedAttributes' | ||
@@ -19,4 +20,3 @@ function defaultBlockAt(match: ContentMatch) { | ||
export interface SplitBlockOptions { | ||
withAttributes: boolean, | ||
withMarks: boolean, | ||
keepMarks: boolean, | ||
} | ||
@@ -36,6 +36,10 @@ | ||
*/ | ||
export const splitBlock = (options: Partial<SplitBlockOptions> = {}): Command => ({ tr, state, dispatch }) => { | ||
export const splitBlock = (options: Partial<SplitBlockOptions> = {}): Command => ({ | ||
tr, | ||
state, | ||
dispatch, | ||
editor, | ||
}) => { | ||
const defaultOptions: SplitBlockOptions = { | ||
withAttributes: false, | ||
withMarks: true, | ||
keepMarks: true, | ||
} | ||
@@ -45,2 +49,8 @@ const config = { ...defaultOptions, ...options } | ||
const { $from, $to } = selection | ||
const extensionAttributes = editor.extensionManager.attributes | ||
const newAttributes = getSplittedAttributes( | ||
extensionAttributes, | ||
$from.node().type.name, | ||
$from.node().attrs, | ||
) | ||
@@ -53,3 +63,3 @@ if (selection instanceof NodeSelection && selection.node.isBlock) { | ||
if (dispatch) { | ||
if (config.withMarks) { | ||
if (config.keepMarks) { | ||
keepMarks(state) | ||
@@ -82,5 +92,3 @@ } | ||
type: deflt, | ||
attrs: config.withAttributes | ||
? $from.node().attrs | ||
: {}, | ||
attrs: newAttributes, | ||
}] | ||
@@ -100,5 +108,3 @@ : undefined | ||
type: deflt, | ||
attrs: config.withAttributes | ||
? $from.node().attrs | ||
: {}, | ||
attrs: newAttributes, | ||
}] | ||
@@ -121,3 +127,3 @@ : undefined | ||
if (config.withMarks) { | ||
if (config.keepMarks) { | ||
keepMarks(state) | ||
@@ -124,0 +130,0 @@ } |
@@ -1,5 +0,12 @@ | ||
import { splitListItem as originalSplitListItem } from 'prosemirror-schema-list' | ||
import { NodeType } from 'prosemirror-model' | ||
import { | ||
NodeType, | ||
Node as ProseMirrorNode, | ||
Fragment, | ||
Slice, | ||
} from 'prosemirror-model' | ||
import { canSplit } from 'prosemirror-transform' | ||
import { TextSelection } from 'prosemirror-state' | ||
import { Command } from '../types' | ||
import getNodeType from '../helpers/getNodeType' | ||
import getSplittedAttributes from '../helpers/getSplittedAttributes' | ||
@@ -9,6 +16,98 @@ /** | ||
*/ | ||
export const splitListItem = (typeOrName: string | NodeType): Command => ({ state, dispatch }) => { | ||
export const splitListItem = (typeOrName: string | NodeType): Command => ({ | ||
tr, state, dispatch, editor, | ||
}) => { | ||
const type = getNodeType(typeOrName, state.schema) | ||
const { $from, $to } = state.selection | ||
return originalSplitListItem(type)(state, dispatch) | ||
// @ts-ignore | ||
// eslint-disable-next-line | ||
const node: ProseMirrorNode = state.selection.node | ||
if ((node && node.isBlock) || $from.depth < 2 || !$from.sameParent($to)) { | ||
return false | ||
} | ||
const grandParent = $from.node(-1) | ||
if (grandParent.type !== type) { | ||
return false | ||
} | ||
const extensionAttributes = editor.extensionManager.attributes | ||
if ($from.parent.content.size === 0 && $from.node(-1).childCount === $from.indexAfter(-1)) { | ||
// In an empty block. If this is a nested list, the wrapping | ||
// list item should be split. Otherwise, bail out and let next | ||
// command handle lifting. | ||
if ( | ||
$from.depth === 2 | ||
|| $from.node(-3).type !== type | ||
|| $from.index(-2) !== $from.node(-2).childCount - 1 | ||
) { | ||
return false | ||
} | ||
if (dispatch) { | ||
let wrap = Fragment.empty | ||
const keepItem = $from.index(-1) > 0 | ||
// Build a fragment containing empty versions of the structure | ||
// from the outer list item to the parent node of the cursor | ||
for (let d = $from.depth - (keepItem ? 1 : 2); d >= $from.depth - 3; d -= 1) { | ||
wrap = Fragment.from($from.node(d).copy(wrap)) | ||
} | ||
// Add a second list item with an empty default start node | ||
const newNextTypeAttributes = getSplittedAttributes( | ||
extensionAttributes, | ||
$from.node().type.name, | ||
$from.node().attrs, | ||
) | ||
const nextType = type.contentMatch.defaultType?.createAndFill(newNextTypeAttributes) || undefined | ||
wrap = wrap.append(Fragment.from(type.createAndFill(null, nextType) || undefined)) | ||
tr | ||
.replace( | ||
$from.before(keepItem ? undefined : -1), | ||
$from.after(-3), | ||
new Slice(wrap, keepItem ? 3 : 2, 2), | ||
) | ||
.setSelection(TextSelection.near(tr.doc.resolve($from.pos + (keepItem ? 3 : 2)))) | ||
.scrollIntoView() | ||
} | ||
return true | ||
} | ||
const nextType = $to.pos === $from.end() | ||
? grandParent.contentMatchAt(0).defaultType | ||
: null | ||
const newTypeAttributes = getSplittedAttributes( | ||
extensionAttributes, | ||
grandParent.type.name, | ||
grandParent.attrs, | ||
) | ||
const newNextTypeAttributes = getSplittedAttributes( | ||
extensionAttributes, | ||
$from.node().type.name, | ||
$from.node().attrs, | ||
) | ||
tr.delete($from.pos, $to.pos) | ||
const types = nextType | ||
? [{ type, attrs: newTypeAttributes }, { type: nextType, attrs: newNextTypeAttributes }] | ||
: [{ type, attrs: newTypeAttributes }] | ||
if (!canSplit(tr.doc, $from.pos, 2)) { | ||
return false | ||
} | ||
if (dispatch) { | ||
tr.split($from.pos, 2, types).scrollIntoView() | ||
} | ||
return true | ||
} |
@@ -198,3 +198,3 @@ import { EditorState, Plugin, Transaction } from 'prosemirror-state' | ||
? handlePlugins(plugin, this.state.plugins) | ||
: [plugin, ...this.state.plugins] | ||
: [...this.state.plugins, plugin] | ||
@@ -225,3 +225,3 @@ const state = this.state.reconfigure({ plugins }) | ||
const coreExtensions = Object.entries(extensions).map(([, extension]) => extension) | ||
const allExtensions = [...this.options.extensions, ...coreExtensions].filter(extension => { | ||
const allExtensions = [...coreExtensions, ...this.options.extensions].filter(extension => { | ||
return ['extension', 'node', 'mark'].includes(extension?.type) | ||
@@ -228,0 +228,0 @@ }) |
@@ -5,3 +5,3 @@ export default class EventEmitter { | ||
public on(event: string, fn: Function) { | ||
public on(event: string, fn: Function): this { | ||
if (!this.callbacks[event]) { | ||
@@ -16,3 +16,3 @@ this.callbacks[event] = [] | ||
protected emit(event: string, ...args: any) { | ||
protected emit(event: string, ...args: any): this { | ||
const callbacks = this.callbacks[event] | ||
@@ -27,3 +27,3 @@ | ||
public off(event: string, fn?: Function) { | ||
public off(event: string, fn?: Function): this { | ||
const callbacks = this.callbacks[event] | ||
@@ -42,5 +42,5 @@ | ||
protected removeAllListeners() { | ||
protected removeAllListeners(): void { | ||
this.callbacks = {} | ||
} | ||
} |
@@ -70,3 +70,4 @@ import { keymap } from 'prosemirror-keymap' | ||
get plugins(): Plugin[] { | ||
return this.extensions | ||
return [...this.extensions] | ||
.reverse() | ||
.map(extension => { | ||
@@ -99,6 +100,9 @@ const context = { | ||
get attributes() { | ||
return getAttributesFromExtensions(this.extensions) | ||
} | ||
get nodeViews() { | ||
const { editor } = this | ||
const { nodeExtensions } = splitExtensions(this.extensions) | ||
const allAttributes = getAttributesFromExtensions(this.extensions) | ||
@@ -108,3 +112,3 @@ return Object.fromEntries(nodeExtensions | ||
.map(extension => { | ||
const extensionAttributes = allAttributes.filter(attribute => attribute.type === extension.config.name) | ||
const extensionAttributes = this.attributes.filter(attribute => attribute.type === extension.config.name) | ||
const context = { | ||
@@ -111,0 +115,0 @@ options: extension.options, |
@@ -14,3 +14,3 @@ import splitExtensions from './splitExtensions' | ||
*/ | ||
export default function getAttributesFromExtensions(extensions: Extensions) { | ||
export default function getAttributesFromExtensions(extensions: Extensions): ExtensionAttribute[] { | ||
const extensionAttributes: ExtensionAttribute[] = [] | ||
@@ -24,2 +24,3 @@ const { nodeExtensions, markExtensions } = splitExtensions(extensions) | ||
parseHTML: null, | ||
keepOnSplit: true, | ||
} | ||
@@ -26,0 +27,0 @@ |
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) | ||
@@ -7,0 +8,0 @@ const { from, to, empty } = state.selection |
import { MarkType, ResolvedPos } from 'prosemirror-model' | ||
import { Range } from '../types' | ||
interface Range { | ||
from: number, | ||
to: number, | ||
} | ||
export default function getMarkRange($pos: ResolvedPos, type: MarkType): Range | void { | ||
@@ -9,0 +5,0 @@ if (!$pos || !type) { |
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) | ||
@@ -7,0 +8,0 @@ const { from, to } = state.selection |
@@ -1,4 +0,4 @@ | ||
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]) { | ||
@@ -5,0 +5,0 @@ return schema.nodes[name] |
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]) { | ||
@@ -5,0 +5,0 @@ return 'node' |
@@ -5,3 +5,3 @@ import { Extensions } from '../types' | ||
export default function isList(name: string, extensions: Extensions) { | ||
export default function isList(name: string, extensions: Extensions): boolean { | ||
const { nodeExtensions } = splitExtensions(extensions) | ||
@@ -8,0 +8,0 @@ const extension = nodeExtensions.find(item => item.config.name === name) |
import { EditorState } from 'prosemirror-state' | ||
import { Mark, MarkType } from 'prosemirror-model' | ||
import { MarkType } from 'prosemirror-model' | ||
import objectIncludes from '../utilities/objectIncludes' | ||
import getMarkType from './getMarkType' | ||
import { AnyObject } from '../types' | ||
import { AnyObject, MarkRange } from '../types' | ||
export type MarkRange = { | ||
mark: Mark, | ||
from: number, | ||
to: number, | ||
} | ||
export default function isMarkActive( | ||
@@ -14,0 +8,0 @@ state: EditorState, |
import { EditorState } from 'prosemirror-state' | ||
import { Node, NodeType } from 'prosemirror-model' | ||
import { NodeType } from 'prosemirror-model' | ||
import objectIncludes from '../utilities/objectIncludes' | ||
import getNodeType from './getNodeType' | ||
import { AnyObject } from '../types' | ||
import { AnyObject, NodeRange } from '../types' | ||
export type NodeRange = { | ||
node: Node, | ||
from: number, | ||
to: number, | ||
} | ||
export default function isNodeActive( | ||
@@ -14,0 +8,0 @@ state: EditorState, |
import { InputRule } from 'prosemirror-inputrules' | ||
import { EditorState } from 'prosemirror-state' | ||
import { MarkType } from 'prosemirror-model' | ||
import getMarksBetween from '../helpers/getMarksBetween' | ||
function getMarksBetween(start: number, end: number, state: EditorState) { | ||
let marks: any[] = [] | ||
state.doc.nodesBetween(start, end, (node, pos) => { | ||
marks = [...marks, ...node.marks.map(mark => ({ | ||
start: pos, | ||
end: pos + node.nodeSize, | ||
mark, | ||
}))] | ||
}) | ||
return marks | ||
} | ||
export default function (regexp: RegExp, markType: MarkType, getAttributes?: Function) { | ||
export default function (regexp: RegExp, markType: MarkType, getAttributes?: Function): InputRule { | ||
return new InputRule(regexp, (state, match, start, end) => { | ||
@@ -36,6 +22,8 @@ const attributes = getAttributes instanceof Function | ||
.filter(item => { | ||
// TODO: PR to add excluded to MarkType | ||
// @ts-ignore | ||
const { excluded } = item.mark.type | ||
return excluded.find((type: MarkType) => type.name === markType.name) | ||
}) | ||
.filter(item => item.end > textStart) | ||
.filter(item => item.to > textStart) | ||
@@ -42,0 +30,0 @@ if (excludedMarks.length) { |
@@ -1,3 +0,7 @@ | ||
import { Node as ProseMirrorNode, ParseOptions } from 'prosemirror-model' | ||
import { | ||
Node as ProseMirrorNode, | ||
Mark as ProseMirrorMark, | ||
ParseOptions, | ||
} from 'prosemirror-model' | ||
import { | ||
EditorView, | ||
@@ -39,3 +43,3 @@ Decoration, | ||
export type Command = (props: { | ||
export type CommandProps = { | ||
editor: Editor, | ||
@@ -49,4 +53,6 @@ tr: Transaction, | ||
dispatch: ((args?: any) => any) | undefined, | ||
}) => boolean | ||
} | ||
export type Command = (props: CommandProps) => boolean | ||
export type CommandSpec = (...args: any[]) => Command | ||
@@ -59,2 +65,3 @@ | ||
parseHTML?: ((element: HTMLElement) => { [key: string]: any } | null) | null, | ||
keepOnSplit: boolean, | ||
} | ||
@@ -142,2 +149,14 @@ | ||
export type NodeRange = { | ||
node: ProseMirrorNode, | ||
from: number, | ||
to: number, | ||
} | ||
export type MarkRange = { | ||
mark: ProseMirrorMark, | ||
from: number, | ||
to: number, | ||
} | ||
export type Predicate = (node: ProseMirrorNode) => boolean |
@@ -7,3 +7,3 @@ /** | ||
*/ | ||
export default function callOrReturn(value: any, context?: any) { | ||
export default function callOrReturn(value: any, context?: any): any { | ||
if (typeof value === 'function') { | ||
@@ -10,0 +10,0 @@ if (context) { |
@@ -8,3 +8,3 @@ import { AnyObject } from '../types' | ||
*/ | ||
export default function deleteProps(obj: AnyObject, propOrProps: string | string[]) { | ||
export default function deleteProps(obj: AnyObject, propOrProps: string | string[]): AnyObject { | ||
const props = typeof propOrProps === 'string' | ||
@@ -11,0 +11,0 @@ ? [propOrProps] |
@@ -1,2 +0,2 @@ | ||
export default function fromString(value: any) { | ||
export default function fromString(value: any): any { | ||
if (typeof value !== 'string') { | ||
@@ -3,0 +3,0 @@ return value |
@@ -1,3 +0,3 @@ | ||
export default function isEmptyObject(object = {}) { | ||
export default function isEmptyObject(object = {}): boolean { | ||
return Object.keys(object).length === 0 && object.constructor === Object | ||
} |
@@ -1,2 +0,2 @@ | ||
export default function magicMethods(Clazz: any) { | ||
export default function magicMethods(Clazz: any): any { | ||
const classHandler = Object.create(null) | ||
@@ -3,0 +3,0 @@ |
import { AnyObject } from '../types' | ||
export default function mergeAttributes(...objects: AnyObject[]) { | ||
export default function mergeAttributes(...objects: AnyObject[]): AnyObject { | ||
return objects | ||
@@ -5,0 +5,0 @@ .filter(item => !!item) |
import { AnyObject } from '../types' | ||
import isObject from './isObject' | ||
export default function mergeDeep(target: AnyObject, source: AnyObject) { | ||
export default function mergeDeep(target: AnyObject, source: AnyObject): AnyObject { | ||
const output = { ...target } | ||
@@ -6,0 +6,0 @@ |
@@ -1,2 +0,2 @@ | ||
export default function removeElement(element: HTMLElement) { | ||
export default function removeElement(element: HTMLElement): void { | ||
if (element && element.parentNode) { | ||
@@ -3,0 +3,0 @@ element.parentNode.removeChild(element) |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
2374918
216
13788
0