@tiptap/core
Advanced tools
Comparing version 2.5.5 to 2.5.6
@@ -157,5 +157,3 @@ import { Mark as ProseMirrorMark, Node as ProseMirrorNode, NodeType, ParseOptions } from '@tiptap/pm/model'; | ||
*/ | ||
attributes: { | ||
[key: string]: Attribute; | ||
}; | ||
attributes: Record<string, Attribute | undefined>; | ||
}[]; | ||
@@ -162,0 +160,0 @@ export type PickValue<T, K extends keyof T> = T[K]; |
{ | ||
"name": "@tiptap/core", | ||
"description": "headless rich text editor", | ||
"version": "2.5.5", | ||
"version": "2.5.6", | ||
"homepage": "https://tiptap.dev", | ||
@@ -35,6 +35,6 @@ "keywords": [ | ||
"devDependencies": { | ||
"@tiptap/pm": "^2.5.5" | ||
"@tiptap/pm": "^2.5.6" | ||
}, | ||
"peerDependencies": { | ||
"@tiptap/pm": "^2.5.5" | ||
"@tiptap/pm": "^2.5.6" | ||
}, | ||
@@ -41,0 +41,0 @@ "repository": { |
@@ -64,14 +64,26 @@ import { EditorState, NodeSelection, TextSelection } from '@tiptap/pm/state' | ||
if (dispatch) { | ||
const atEnd = $to.parentOffset === $to.parent.content.size | ||
const atEnd = $to.parentOffset === $to.parent.content.size | ||
if (selection instanceof TextSelection) { | ||
tr.deleteSelection() | ||
} | ||
const deflt = $from.depth === 0 | ||
? undefined | ||
: defaultBlockAt($from.node(-1).contentMatchAt($from.indexAfter(-1))) | ||
const deflt = $from.depth === 0 | ||
? undefined | ||
: defaultBlockAt($from.node(-1).contentMatchAt($from.indexAfter(-1))) | ||
let types = atEnd && deflt | ||
? [ | ||
{ | ||
type: deflt, | ||
attrs: newAttributes, | ||
}, | ||
] | ||
: undefined | ||
let types = atEnd && deflt | ||
let can = canSplit(tr.doc, tr.mapping.map($from.pos), 1, types) | ||
if ( | ||
!types | ||
&& !can | ||
&& canSplit(tr.doc, tr.mapping.map($from.pos), 1, deflt ? [{ type: deflt }] : undefined) | ||
) { | ||
can = true | ||
types = deflt | ||
? [ | ||
@@ -84,22 +96,10 @@ { | ||
: undefined | ||
} | ||
let can = canSplit(tr.doc, tr.mapping.map($from.pos), 1, types) | ||
if (dispatch) { | ||
if (can) { | ||
if (selection instanceof TextSelection) { | ||
tr.deleteSelection() | ||
} | ||
if ( | ||
!types | ||
&& !can | ||
&& canSplit(tr.doc, tr.mapping.map($from.pos), 1, deflt ? [{ type: deflt }] : undefined) | ||
) { | ||
can = true | ||
types = deflt | ||
? [ | ||
{ | ||
type: deflt, | ||
attrs: newAttributes, | ||
}, | ||
] | ||
: undefined | ||
} | ||
if (can) { | ||
tr.split(tr.mapping.map($from.pos), 1, types) | ||
@@ -124,3 +124,3 @@ | ||
return true | ||
return can | ||
} |
@@ -352,2 +352,6 @@ import { | ||
public createNodeViews(): void { | ||
if (this.view.isDestroyed) { | ||
return | ||
} | ||
this.view.setProps({ | ||
@@ -354,0 +358,0 @@ nodeViews: this.extensionManager.nodeViews, |
import { Node as ProseMirrorNode } from '@tiptap/pm/model' | ||
export function isNodeEmpty(node: ProseMirrorNode): boolean { | ||
const defaultContent = node.type.createAndFill() | ||
const defaultContent = node.type.createAndFill(node.attrs) | ||
@@ -6,0 +6,0 @@ if (!defaultContent) { |
313
src/types.ts
import { | ||
Mark as ProseMirrorMark, Node as ProseMirrorNode, NodeType, ParseOptions, | ||
Mark as ProseMirrorMark, | ||
Node as ProseMirrorNode, | ||
NodeType, | ||
ParseOptions, | ||
} from '@tiptap/pm/model' | ||
@@ -17,5 +20,5 @@ import { EditorState, Transaction } from '@tiptap/pm/state' | ||
export type AnyConfig = ExtensionConfig | NodeConfig | MarkConfig | ||
export type AnyExtension = Extension | Node | Mark | ||
export type Extensions = AnyExtension[] | ||
export type AnyConfig = ExtensionConfig | NodeConfig | MarkConfig; | ||
export type AnyExtension = Extension | Node | Mark; | ||
export type Extensions = AnyExtension[]; | ||
@@ -25,23 +28,23 @@ export type ParentConfig<T> = Partial<{ | ||
? (...args: Parameters<Required<T>[P]>) => ReturnType<Required<T>[P]> | ||
: T[P] | ||
}> | ||
: T[P]; | ||
}>; | ||
export type Primitive = null | undefined | string | number | boolean | symbol | bigint | ||
export type Primitive = null | undefined | string | number | boolean | symbol | bigint; | ||
export type RemoveThis<T> = T extends (...args: any) => any | ||
? (...args: Parameters<T>) => ReturnType<T> | ||
: T | ||
: T; | ||
export type MaybeReturnType<T> = T extends (...args: any) => any ? ReturnType<T> : T | ||
export type MaybeReturnType<T> = T extends (...args: any) => any ? ReturnType<T> : T; | ||
export type MaybeThisParameterType<T> = Exclude<T, Primitive> extends (...args: any) => any | ||
? ThisParameterType<Exclude<T, Primitive>> | ||
: any | ||
: any; | ||
export interface EditorEvents { | ||
beforeCreate: { editor: Editor } | ||
create: { editor: Editor } | ||
beforeCreate: { editor: Editor }; | ||
create: { editor: Editor }; | ||
contentError: { | ||
editor: Editor, | ||
error: Error, | ||
editor: Editor; | ||
error: Error; | ||
/** | ||
@@ -51,33 +54,33 @@ * If called, will re-initialize the editor with the collaboration extension removed. | ||
*/ | ||
disableCollaboration: () => void | ||
} | ||
update: { editor: Editor; transaction: Transaction } | ||
selectionUpdate: { editor: Editor; transaction: Transaction } | ||
beforeTransaction: { editor: Editor; transaction: Transaction, nextState: EditorState } | ||
transaction: { editor: Editor; transaction: Transaction } | ||
focus: { editor: Editor; event: FocusEvent; transaction: Transaction } | ||
blur: { editor: Editor; event: FocusEvent; transaction: Transaction } | ||
destroy: void | ||
disableCollaboration: () => void; | ||
}; | ||
update: { editor: Editor; transaction: Transaction }; | ||
selectionUpdate: { editor: Editor; transaction: Transaction }; | ||
beforeTransaction: { editor: Editor; transaction: Transaction; nextState: EditorState }; | ||
transaction: { editor: Editor; transaction: Transaction }; | ||
focus: { editor: Editor; event: FocusEvent; transaction: Transaction }; | ||
blur: { editor: Editor; event: FocusEvent; transaction: Transaction }; | ||
destroy: void; | ||
} | ||
export type EnableRules = (AnyExtension | string)[] | boolean | ||
export type EnableRules = (AnyExtension | string)[] | boolean; | ||
export interface EditorOptions { | ||
element: Element | ||
content: Content | ||
extensions: Extensions | ||
injectCSS: boolean | ||
injectNonce: string | undefined | ||
autofocus: FocusPosition | ||
editable: boolean | ||
editorProps: EditorProps | ||
parseOptions: ParseOptions | ||
element: Element; | ||
content: Content; | ||
extensions: Extensions; | ||
injectCSS: boolean; | ||
injectNonce: string | undefined; | ||
autofocus: FocusPosition; | ||
editable: boolean; | ||
editorProps: EditorProps; | ||
parseOptions: ParseOptions; | ||
coreExtensionOptions?: { | ||
clipboardTextSerializer?: { | ||
blockSeparator?: string | ||
} | ||
} | ||
enableInputRules: EnableRules | ||
enablePasteRules: EnableRules | ||
enableCoreExtensions: boolean | ||
blockSeparator?: string; | ||
}; | ||
}; | ||
enableInputRules: EnableRules; | ||
enablePasteRules: EnableRules; | ||
enableCoreExtensions: boolean; | ||
/** | ||
@@ -89,5 +92,5 @@ * If `true`, the editor will check the content for errors on initialization. | ||
*/ | ||
enableContentCheck: boolean | ||
onBeforeCreate: (props: EditorEvents['beforeCreate']) => void | ||
onCreate: (props: EditorEvents['create']) => void | ||
enableContentCheck: boolean; | ||
onBeforeCreate: (props: EditorEvents['beforeCreate']) => void; | ||
onCreate: (props: EditorEvents['create']) => void; | ||
/** | ||
@@ -97,63 +100,63 @@ * Called when the editor encounters an error while parsing the content. | ||
*/ | ||
onContentError: (props: EditorEvents['contentError']) => void | ||
onUpdate: (props: EditorEvents['update']) => void | ||
onSelectionUpdate: (props: EditorEvents['selectionUpdate']) => void | ||
onTransaction: (props: EditorEvents['transaction']) => void | ||
onFocus: (props: EditorEvents['focus']) => void | ||
onBlur: (props: EditorEvents['blur']) => void | ||
onDestroy: (props: EditorEvents['destroy']) => void | ||
onContentError: (props: EditorEvents['contentError']) => void; | ||
onUpdate: (props: EditorEvents['update']) => void; | ||
onSelectionUpdate: (props: EditorEvents['selectionUpdate']) => void; | ||
onTransaction: (props: EditorEvents['transaction']) => void; | ||
onFocus: (props: EditorEvents['focus']) => void; | ||
onBlur: (props: EditorEvents['blur']) => void; | ||
onDestroy: (props: EditorEvents['destroy']) => void; | ||
} | ||
export type HTMLContent = string | ||
export type HTMLContent = string; | ||
export type JSONContent = { | ||
type?: string | ||
attrs?: Record<string, any> | ||
content?: JSONContent[] | ||
type?: string; | ||
attrs?: Record<string, any>; | ||
content?: JSONContent[]; | ||
marks?: { | ||
type: string | ||
attrs?: Record<string, any> | ||
[key: string]: any | ||
}[] | ||
text?: string | ||
[key: string]: any | ||
} | ||
type: string; | ||
attrs?: Record<string, any>; | ||
[key: string]: any; | ||
}[]; | ||
text?: string; | ||
[key: string]: any; | ||
}; | ||
export type Content = HTMLContent | JSONContent | JSONContent[] | null | ||
export type Content = HTMLContent | JSONContent | JSONContent[] | null; | ||
export type CommandProps = { | ||
editor: Editor | ||
tr: Transaction | ||
commands: SingleCommands | ||
can: () => CanCommands | ||
chain: () => ChainedCommands | ||
state: EditorState | ||
view: EditorView | ||
dispatch: ((args?: any) => any) | undefined | ||
} | ||
editor: Editor; | ||
tr: Transaction; | ||
commands: SingleCommands; | ||
can: () => CanCommands; | ||
chain: () => ChainedCommands; | ||
state: EditorState; | ||
view: EditorView; | ||
dispatch: ((args?: any) => any) | undefined; | ||
}; | ||
export type Command = (props: CommandProps) => boolean | ||
export type Command = (props: CommandProps) => boolean; | ||
export type CommandSpec = (...args: any[]) => Command | ||
export type CommandSpec = (...args: any[]) => Command; | ||
export type KeyboardShortcutCommand = (props: { editor: Editor }) => boolean | ||
export type KeyboardShortcutCommand = (props: { editor: Editor }) => boolean; | ||
export type Attribute = { | ||
default?: any | ||
rendered?: boolean | ||
renderHTML?: ((attributes: Record<string, any>) => Record<string, any> | null) | null | ||
parseHTML?: ((element: HTMLElement) => any | null) | null | ||
keepOnSplit?: boolean | ||
isRequired?: boolean | ||
} | ||
default?: any; | ||
rendered?: boolean; | ||
renderHTML?: ((attributes: Record<string, any>) => Record<string, any> | null) | null; | ||
parseHTML?: ((element: HTMLElement) => any | null) | null; | ||
keepOnSplit?: boolean; | ||
isRequired?: boolean; | ||
}; | ||
export type Attributes = { | ||
[key: string]: Attribute | ||
} | ||
[key: string]: Attribute; | ||
}; | ||
export type ExtensionAttribute = { | ||
type: string | ||
name: string | ||
attribute: Required<Attribute> | ||
} | ||
type: string; | ||
name: string; | ||
attribute: Required<Attribute>; | ||
}; | ||
@@ -164,123 +167,121 @@ export type GlobalAttributes = { | ||
*/ | ||
types: string[] | ||
types: string[]; | ||
/** | ||
* The attributes to add to the node or mark types. | ||
*/ | ||
attributes: { | ||
[key: string]: Attribute | ||
} | ||
}[] | ||
attributes: Record<string, Attribute | undefined>; | ||
}[]; | ||
export type PickValue<T, K extends keyof T> = T[K] | ||
export type PickValue<T, K extends keyof T> = T[K]; | ||
export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ( | ||
k: infer I, | ||
k: infer I | ||
) => void | ||
? I | ||
: never | ||
: never; | ||
export type Diff<T extends keyof any, U extends keyof any> = ({ [P in T]: P } & { | ||
[P in U]: never | ||
} & { [x: string]: never })[T] | ||
[P in U]: never; | ||
} & { [x: string]: never })[T]; | ||
export type Overwrite<T, U> = Pick<T, Diff<keyof T, keyof U>> & U | ||
export type Overwrite<T, U> = Pick<T, Diff<keyof T, keyof U>> & U; | ||
export type ValuesOf<T> = T[keyof T] | ||
export type ValuesOf<T> = T[keyof T]; | ||
export type KeysWithTypeOf<T, Type> = { [P in keyof T]: T[P] extends Type ? P : never }[keyof T] | ||
export type KeysWithTypeOf<T, Type> = { [P in keyof T]: T[P] extends Type ? P : never }[keyof T]; | ||
export type DecorationWithType = Decoration & { | ||
type: NodeType | ||
} | ||
type: NodeType; | ||
}; | ||
export type NodeViewProps = { | ||
editor: Editor | ||
node: ProseMirrorNode | ||
decorations: DecorationWithType[] | ||
selected: boolean | ||
extension: Node | ||
getPos: () => number | ||
updateAttributes: (attributes: Record<string, any>) => void | ||
deleteNode: () => void | ||
} | ||
editor: Editor; | ||
node: ProseMirrorNode; | ||
decorations: DecorationWithType[]; | ||
selected: boolean; | ||
extension: Node; | ||
getPos: () => number; | ||
updateAttributes: (attributes: Record<string, any>) => void; | ||
deleteNode: () => void; | ||
}; | ||
export interface NodeViewRendererOptions { | ||
stopEvent: ((props: { event: Event }) => boolean) | null | ||
stopEvent: ((props: { event: Event }) => boolean) | null; | ||
ignoreMutation: | ||
| ((props: { mutation: MutationRecord | { type: 'selection'; target: Element } }) => boolean) | ||
| null | ||
contentDOMElementTag: string | ||
| null; | ||
contentDOMElementTag: string; | ||
} | ||
export type NodeViewRendererProps = { | ||
editor: Editor | ||
node: ProseMirrorNode | ||
getPos: (() => number) | boolean | ||
HTMLAttributes: Record<string, any> | ||
decorations: Decoration[] | ||
extension: Node | ||
} | ||
editor: Editor; | ||
node: ProseMirrorNode; | ||
getPos: (() => number) | boolean; | ||
HTMLAttributes: Record<string, any>; | ||
decorations: Decoration[]; | ||
extension: Node; | ||
}; | ||
export type NodeViewRenderer = (props: NodeViewRendererProps) => NodeView | {} | ||
export type NodeViewRenderer = (props: NodeViewRendererProps) => NodeView | {}; | ||
export type AnyCommands = Record<string, (...args: any[]) => Command> | ||
export type AnyCommands = Record<string, (...args: any[]) => Command>; | ||
export type UnionCommands<T = Command> = UnionToIntersection< | ||
ValuesOf<Pick<Commands<T>, KeysWithTypeOf<Commands<T>, {}>>> | ||
> | ||
>; | ||
export type RawCommands = { | ||
[Item in keyof UnionCommands]: UnionCommands<Command>[Item] | ||
} | ||
[Item in keyof UnionCommands]: UnionCommands<Command>[Item]; | ||
}; | ||
export type SingleCommands = { | ||
[Item in keyof UnionCommands]: UnionCommands<boolean>[Item] | ||
} | ||
[Item in keyof UnionCommands]: UnionCommands<boolean>[Item]; | ||
}; | ||
export type ChainedCommands = { | ||
[Item in keyof UnionCommands]: UnionCommands<ChainedCommands>[Item] | ||
[Item in keyof UnionCommands]: UnionCommands<ChainedCommands>[Item]; | ||
} & { | ||
run: () => boolean | ||
} | ||
run: () => boolean; | ||
}; | ||
export type CanCommands = SingleCommands & { chain: () => ChainedCommands } | ||
export type CanCommands = SingleCommands & { chain: () => ChainedCommands }; | ||
export type FocusPosition = 'start' | 'end' | 'all' | number | boolean | null | ||
export type FocusPosition = 'start' | 'end' | 'all' | number | boolean | null; | ||
export type Range = { | ||
from: number | ||
to: number | ||
} | ||
from: number; | ||
to: number; | ||
}; | ||
export type NodeRange = { | ||
node: ProseMirrorNode | ||
from: number | ||
to: number | ||
} | ||
node: ProseMirrorNode; | ||
from: number; | ||
to: number; | ||
}; | ||
export type MarkRange = { | ||
mark: ProseMirrorMark | ||
from: number | ||
to: number | ||
} | ||
mark: ProseMirrorMark; | ||
from: number; | ||
to: number; | ||
}; | ||
export type Predicate = (node: ProseMirrorNode) => boolean | ||
export type Predicate = (node: ProseMirrorNode) => boolean; | ||
export type NodeWithPos = { | ||
node: ProseMirrorNode | ||
pos: number | ||
} | ||
node: ProseMirrorNode; | ||
pos: number; | ||
}; | ||
export type TextSerializer = (props: { | ||
node: ProseMirrorNode | ||
pos: number | ||
parent: ProseMirrorNode | ||
index: number | ||
range: Range | ||
}) => string | ||
node: ProseMirrorNode; | ||
pos: number; | ||
parent: ProseMirrorNode; | ||
index: number; | ||
range: Range; | ||
}) => string; | ||
export type ExtendedRegExpMatchArray = RegExpMatchArray & { | ||
data?: Record<string, any> | ||
} | ||
data?: Record<string, any>; | ||
}; | ||
export type Dispatch = ((args?: any) => any) | undefined | ||
export type Dispatch = ((args?: any) => any) | undefined; |
Sorry, the diff of this file is not supported yet
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2291657
27058