@domternal/react 0.7.5 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -448,8 +448,8 @@ interface ReactNodeViewProps {
448
448
  node: PMNode;
449
449
  /** Whether this node is selected via NodeSelection. */
450
450
  selected: boolean;
451
- /** Get the document position of this node. */
452
- getPos: () => number;
451
+ /** Get the document position of this node. Returns `undefined` once the node is no longer in the document. */
452
+ getPos: () => number | undefined;
453
453
  /** Update the node's attributes. */
454
454
  updateAttributes: (attrs: Record<string, unknown>) => void;
455
455
  /** Delete this node from the document. */
@@ -460,7 +460,7 @@ interface ReactNodeViewProps {
460
460
  options: Record<string, unknown>;
461
461
  };
462
462
  /** ProseMirror decorations applied to this node. */
463
- decorations: unknown[];
463
+ decorations: readonly unknown[];
464
464
  }
465
465
  interface ReactNodeViewRendererOptions {
466
466
  /** Wrapper element tag. @default 'div' for block, 'span' for inline */
@@ -493,12 +493,12 @@ interface ReactNodeViewRendererOptions {
493
493
  * }
494
494
  * ```
495
495
  */
496
- declare function ReactNodeViewRenderer(component: React.ComponentType<ReactNodeViewProps>, options?: ReactNodeViewRendererOptions): (node: PMNode, view: unknown, getPos: () => number, decorations: unknown[]) => ReactNodeView;
496
+ declare function ReactNodeViewRenderer(component: React.ComponentType<ReactNodeViewProps>, options?: ReactNodeViewRendererOptions): (node: PMNode, view: unknown, getPos: () => number | undefined, decorations: readonly unknown[]) => ReactNodeView;
497
497
  interface ReactNodeViewInit {
498
498
  editor: Editor;
499
499
  node: PMNode;
500
- getPos: () => number;
501
- decorations: unknown[];
500
+ getPos: () => number | undefined;
501
+ decorations: readonly unknown[];
502
502
  extension: {
503
503
  name: string;
504
504
  options: Record<string, unknown>;
@@ -517,11 +517,14 @@ declare class ReactNodeView {
517
517
  private selected;
518
518
  constructor(component: React.ComponentType<ReactNodeViewProps>, init: ReactNodeViewInit, options: ReactNodeViewRendererOptions);
519
519
  private render;
520
- update(node: PMNode, decorations: unknown[]): boolean;
520
+ update(node: PMNode, decorations: readonly unknown[]): boolean;
521
521
  selectNode(): void;
522
522
  deselectNode(): void;
523
523
  destroy(): void;
524
- ignoreMutation(mutation: MutationRecord): boolean;
524
+ ignoreMutation(mutation: MutationRecord | {
525
+ type: 'selection';
526
+ target: Node;
527
+ }): boolean;
525
528
  stopEvent(): boolean;
526
529
  }
527
530
 
package/dist/index.js CHANGED
@@ -2621,12 +2621,14 @@ var ReactNodeView = class {
2621
2621
  decorations: this.decorations,
2622
2622
  updateAttributes: (attrs) => {
2623
2623
  const pos = this.getPos();
2624
+ if (pos === void 0) return;
2624
2625
  const { tr } = this.editor.view.state;
2625
2626
  tr.setNodeMarkup(pos, void 0, { ...this.node.attrs, ...attrs });
2626
2627
  this.editor.view.dispatch(tr);
2627
2628
  },
2628
2629
  deleteNode: () => {
2629
2630
  const pos = this.getPos();
2631
+ if (pos === void 0) return;
2630
2632
  const { tr } = this.editor.view.state;
2631
2633
  tr.delete(pos, pos + this.node.nodeSize);
2632
2634
  this.editor.view.dispatch(tr);