Skip to content

Commit

Permalink
feat: add ignoreMutation option to NodeViewRenderer, fix #1538
Browse files Browse the repository at this point in the history
  • Loading branch information
philippkuehn committed Jul 26, 2021
1 parent 03e4e8e commit 651e691
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions packages/core/src/NodeView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class NodeView<Component, Editor extends CoreEditor = CoreEditor> impleme
options: NodeViewRendererOptions = {
stopEvent: null,
update: null,
ignoreMutation: null,
}

constructor(component: Component, props: NodeViewRendererProps, options?: Partial<NodeViewRendererOptions>) {
Expand Down Expand Up @@ -176,6 +177,10 @@ export class NodeView<Component, Editor extends CoreEditor = CoreEditor> impleme
return true
}

if (typeof this.options.ignoreMutation === 'function') {
return this.options.ignoreMutation(mutation)
}

// a leaf/atom node is like a black box for ProseMirror
// and should be fully handled by the node view
if (this.node.isLeaf || this.node.isAtom) {
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export type NodeViewProps = {
export interface NodeViewRendererOptions {
stopEvent: ((event: Event) => boolean) | null,
update: ((node: ProseMirrorNode, decorations: Decoration[]) => boolean) | null,
ignoreMutation: ((mutation: MutationRecord | { type: 'selection', target: Element }) => boolean) | null,
}

export type NodeViewRendererProps = {
Expand Down
3 changes: 2 additions & 1 deletion packages/react/src/ReactNodeViewRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import { Editor } from './Editor'
import { ReactRenderer } from './ReactRenderer'
import { ReactNodeViewContext } from './useReactNodeView'

interface ReactNodeViewRendererOptions {
export interface ReactNodeViewRendererOptions {
stopEvent: ((event: Event) => boolean) | null,
update: ((node: ProseMirrorNode, decorations: Decoration[]) => boolean) | null,
ignoreMutation: ((mutation: MutationRecord | { type: 'selection', target: Element }) => boolean) | null,
}

class ReactNodeView extends NodeView<React.FunctionComponent, Editor> {
Expand Down
1 change: 1 addition & 0 deletions packages/vue-2/src/VueNodeViewRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const nodeViewProps = {
export interface VueNodeViewRendererOptions {
stopEvent: ((event: Event) => boolean) | null,
update: ((node: ProseMirrorNode, decorations: Decoration[]) => boolean) | null,
ignoreMutation: ((mutation: MutationRecord | { type: 'selection', target: Element }) => boolean) | null,
}

class VueNodeView extends NodeView<(Vue | VueConstructor), Editor> {
Expand Down
3 changes: 2 additions & 1 deletion packages/vue-3/src/VueNodeViewRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ export const nodeViewProps = {
},
}

interface VueNodeViewRendererOptions {
export interface VueNodeViewRendererOptions {
stopEvent: ((event: Event) => boolean) | null,
update: ((node: ProseMirrorNode, decorations: Decoration[]) => boolean) | null,
ignoreMutation: ((mutation: MutationRecord | { type: 'selection', target: Element }) => boolean) | null,
}

class VueNodeView extends NodeView<Component, Editor> {
Expand Down

0 comments on commit 651e691

Please sign in to comment.