@handlewithcare/react-prosemirror 2.5.0 → 2.5.2
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/cjs/ReactEditorView.js +6 -6
- package/dist/cjs/components/ChildNodeViews.js +6 -6
- package/dist/cjs/components/CustomNodeView.js +77 -121
- package/dist/cjs/components/DefaultNodeView.js +67 -0
- package/dist/cjs/components/DocNodeView.js +33 -32
- package/dist/cjs/components/NodeView.js +31 -21
- package/dist/cjs/components/ProseMirror.js +20 -9
- package/dist/cjs/components/ProseMirrorDoc.js +7 -27
- package/dist/cjs/components/ReactNodeView.js +96 -58
- package/dist/cjs/hooks/useEditor.js +1 -1
- package/dist/cjs/hooks/useIgnoreMutation.js +1 -1
- package/dist/cjs/hooks/useNodeViewDescriptor.js +121 -78
- package/dist/cjs/hooks/useSelectNode.js +9 -7
- package/dist/cjs/hooks/useStopEvent.js +1 -1
- package/dist/cjs/plugins/beforeInputPlugin.js +12 -0
- package/dist/cjs/viewdesc.js +95 -17
- package/dist/esm/ReactEditorView.js +6 -6
- package/dist/esm/components/ChildNodeViews.js +6 -6
- package/dist/esm/components/CustomNodeView.js +78 -122
- package/dist/esm/components/DefaultNodeView.js +16 -0
- package/dist/esm/components/DocNodeView.js +33 -32
- package/dist/esm/components/NodeView.js +32 -22
- package/dist/esm/components/ProseMirror.js +20 -9
- package/dist/esm/components/ProseMirrorDoc.js +7 -28
- package/dist/esm/components/ReactNodeView.js +97 -59
- package/dist/esm/hooks/useEditor.js +1 -1
- package/dist/esm/hooks/useIgnoreMutation.js +1 -1
- package/dist/esm/hooks/useNodeViewDescriptor.js +123 -80
- package/dist/esm/hooks/useSelectNode.js +9 -7
- package/dist/esm/hooks/useStopEvent.js +1 -1
- package/dist/esm/plugins/beforeInputPlugin.js +12 -0
- package/dist/esm/viewdesc.js +92 -17
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/ReactEditorView.d.ts +3 -2
- package/dist/types/components/CustomNodeView.d.ts +1 -1
- package/dist/types/components/DefaultNodeView.d.ts +3 -0
- package/dist/types/components/DocNodeView.d.ts +8 -13
- package/dist/types/components/NodeView.d.ts +4 -4
- package/dist/types/components/NodeViewComponentProps.d.ts +3 -4
- package/dist/types/components/ProseMirrorDoc.d.ts +14 -8
- package/dist/types/components/ReactNodeView.d.ts +3 -1
- package/dist/types/contexts/IgnoreMutationContext.d.ts +2 -1
- package/dist/types/contexts/NodeViewContext.d.ts +3 -1
- package/dist/types/contexts/SelectNodeContext.d.ts +3 -1
- package/dist/types/contexts/StopEventContext.d.ts +2 -1
- package/dist/types/hooks/useEditor.d.ts +1 -1
- package/dist/types/hooks/useNodeViewDescriptor.d.ts +18 -10
- package/dist/types/hooks/useSelectNode.d.ts +2 -1
- package/dist/types/viewdesc.d.ts +25 -8
- package/package.json +3 -3
- package/dist/cjs/hooks/useClientOnly.js +0 -19
- package/dist/esm/hooks/useClientOnly.js +0 -9
- package/dist/types/hooks/useClientOnly.d.ts +0 -1
|
@@ -13,7 +13,7 @@ interface InputState {
|
|
|
13
13
|
compositionID: number;
|
|
14
14
|
compositionNodes: ViewDesc[];
|
|
15
15
|
compositionPendingChanges: number;
|
|
16
|
-
|
|
16
|
+
hideSelectionGuard: (() => void) | null;
|
|
17
17
|
lastClick: {
|
|
18
18
|
time: number;
|
|
19
19
|
x: number;
|
|
@@ -21,6 +21,8 @@ interface InputState {
|
|
|
21
21
|
type: string;
|
|
22
22
|
button: number;
|
|
23
23
|
};
|
|
24
|
+
lastFocus: number;
|
|
25
|
+
lastIOSEnter: number;
|
|
24
26
|
lastSelectionOrigin: string | null;
|
|
25
27
|
lastSelectionTime: number;
|
|
26
28
|
lastTouch: number;
|
|
@@ -28,7 +30,6 @@ interface InputState {
|
|
|
28
30
|
allowDefault: boolean;
|
|
29
31
|
delayedSelectionSync: boolean;
|
|
30
32
|
};
|
|
31
|
-
hideSelectionGuard: (() => void) | null;
|
|
32
33
|
}
|
|
33
34
|
/**
|
|
34
35
|
* Extends EditorView to make prop and state updates pure, remove the DOM
|
|
@@ -2,7 +2,7 @@ import { Node } from "prosemirror-model";
|
|
|
2
2
|
import { Decoration, DecorationSource, NodeViewConstructor } from "prosemirror-view";
|
|
3
3
|
import React from "react";
|
|
4
4
|
interface Props {
|
|
5
|
-
|
|
5
|
+
constructor: NodeViewConstructor;
|
|
6
6
|
node: Node;
|
|
7
7
|
getPos: () => number;
|
|
8
8
|
innerDeco: DecorationSource;
|
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
import { Node } from "prosemirror-model";
|
|
2
2
|
import { Decoration, DecorationSource } from "prosemirror-view";
|
|
3
|
-
import React, {
|
|
4
|
-
export
|
|
5
|
-
className?: string;
|
|
6
|
-
node: Node;
|
|
7
|
-
innerDeco: DecorationSource;
|
|
8
|
-
outerDeco: Decoration[];
|
|
3
|
+
import React, { HTMLProps, ReactElement } from "react";
|
|
4
|
+
export interface DocNodeViewProps extends Omit<HTMLProps<HTMLElement>, "as"> {
|
|
9
5
|
as?: ReactElement;
|
|
10
|
-
} & Omit<DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLDivElement>, "ref">;
|
|
11
|
-
export declare const DocNodeView: React.MemoExoticComponent<React.ForwardRefExoticComponent<{
|
|
12
|
-
className?: string | undefined;
|
|
13
6
|
node: Node;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
7
|
+
getPos: () => number;
|
|
8
|
+
decorations: readonly Decoration[];
|
|
9
|
+
innerDecorations: DecorationSource;
|
|
10
|
+
setMount: (mount: HTMLElement | null) => void;
|
|
11
|
+
}
|
|
12
|
+
export declare const DocNodeView: React.MemoExoticComponent<React.ForwardRefExoticComponent<Omit<DocNodeViewProps, "ref"> & React.RefAttributes<HTMLElement>>>;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Node } from "prosemirror-model";
|
|
2
2
|
import { Decoration, DecorationSource } from "prosemirror-view";
|
|
3
3
|
import React from "react";
|
|
4
|
-
type
|
|
5
|
-
outerDeco: readonly Decoration[];
|
|
6
|
-
getPos: () => number;
|
|
4
|
+
type Props = {
|
|
7
5
|
node: Node;
|
|
6
|
+
getPos: () => number;
|
|
7
|
+
outerDeco: readonly Decoration[];
|
|
8
8
|
innerDeco: DecorationSource;
|
|
9
9
|
};
|
|
10
|
-
export declare const NodeView: React.NamedExoticComponent<
|
|
10
|
+
export declare const NodeView: React.NamedExoticComponent<Props>;
|
|
11
11
|
export {};
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { Node } from "prosemirror-model";
|
|
2
2
|
import { Decoration, DecorationSource } from "prosemirror-view";
|
|
3
|
-
import {
|
|
4
|
-
export
|
|
3
|
+
import { AllHTMLAttributes, LegacyRef } from "react";
|
|
4
|
+
export interface NodeViewComponentProps extends AllHTMLAttributes<HTMLElement> {
|
|
5
5
|
nodeProps: {
|
|
6
6
|
decorations: readonly Decoration[];
|
|
7
7
|
innerDecorations: DecorationSource;
|
|
8
8
|
node: Node;
|
|
9
|
-
children?: ReactNode | ReactNode[];
|
|
10
9
|
getPos: () => number;
|
|
11
10
|
};
|
|
12
11
|
ref: LegacyRef<any>;
|
|
13
|
-
}
|
|
12
|
+
}
|
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { Node } from "prosemirror-model";
|
|
2
|
+
import { Decoration, DecorationSource } from "prosemirror-view";
|
|
3
|
+
import React, { HTMLProps, ReactElement } from "react";
|
|
4
|
+
interface DocNodeViewContextValue {
|
|
5
|
+
node: Node;
|
|
6
|
+
getPos: () => number;
|
|
7
|
+
decorations: readonly Decoration[];
|
|
8
|
+
innerDecorations: DecorationSource;
|
|
4
9
|
setMount: (mount: HTMLElement | null) => void;
|
|
5
|
-
}
|
|
10
|
+
}
|
|
6
11
|
export declare const DocNodeViewContext: React.Context<DocNodeViewContextValue>;
|
|
7
|
-
|
|
8
|
-
as?:
|
|
9
|
-
}
|
|
10
|
-
export
|
|
12
|
+
interface Props extends Omit<HTMLProps<HTMLElement>, "as"> {
|
|
13
|
+
as?: ReactElement;
|
|
14
|
+
}
|
|
15
|
+
export declare const ProseMirrorDoc: React.ForwardRefExoticComponent<Omit<Props, "ref"> & React.RefAttributes<HTMLElement>>;
|
|
16
|
+
export {};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { Node } from "prosemirror-model";
|
|
2
2
|
import { Decoration, DecorationSource } from "prosemirror-view";
|
|
3
|
-
import React from "react";
|
|
3
|
+
import React, { ComponentType } from "react";
|
|
4
|
+
import { NodeViewComponentProps } from "./NodeViewComponentProps.js";
|
|
4
5
|
type Props = {
|
|
6
|
+
component: ComponentType<NodeViewComponentProps>;
|
|
5
7
|
outerDeco: readonly Decoration[];
|
|
6
8
|
getPos: () => number;
|
|
7
9
|
node: Node;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ViewMutationRecord } from "prosemirror-view";
|
|
2
|
-
type
|
|
2
|
+
export type IgnoreMutation = (mutation: ViewMutationRecord) => boolean;
|
|
3
|
+
type IgnoreMutationtContextValue = (ignoreMutation: IgnoreMutation) => void;
|
|
3
4
|
export declare const IgnoreMutationContext: import("react").Context<IgnoreMutationtContextValue>;
|
|
4
5
|
export {};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { ComponentType } from "react";
|
|
2
|
+
import { NodeViewSet } from "../AbstractEditorView.js";
|
|
2
3
|
import { NodeViewComponentProps } from "../components/NodeViewComponentProps.js";
|
|
3
4
|
export type NodeViewContextValue = {
|
|
4
|
-
|
|
5
|
+
components: Record<string, ComponentType<NodeViewComponentProps>>;
|
|
6
|
+
constructors: NodeViewSet;
|
|
5
7
|
};
|
|
6
8
|
export declare const NodeViewContext: import("react").Context<NodeViewContextValue>;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
type
|
|
1
|
+
export type SelectNode = () => void;
|
|
2
|
+
export type DeselectNode = () => void;
|
|
3
|
+
type SelectNodeContextValue = (selectNode: SelectNode, deselectNode: DeselectNode) => void;
|
|
2
4
|
export declare const SelectNodeContext: import("react").Context<SelectNodeContextValue>;
|
|
3
5
|
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
type
|
|
1
|
+
export type StopEvent = (event: Event) => boolean;
|
|
2
|
+
type StopEventContextValue = (stopEvent: (event: Event) => boolean) => void;
|
|
2
3
|
export declare const StopEventContext: import("react").Context<StopEventContextValue>;
|
|
3
4
|
export {};
|
|
@@ -4,7 +4,7 @@ import { AbstractEditorView } from "../AbstractEditorView.js";
|
|
|
4
4
|
export interface UseEditorOptions extends EditorProps {
|
|
5
5
|
defaultState?: EditorState;
|
|
6
6
|
state?: EditorState;
|
|
7
|
-
plugins?: Plugin[];
|
|
7
|
+
plugins?: readonly Plugin[];
|
|
8
8
|
dispatchTransaction?(this: EditorView, tr: Transaction): void;
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
@@ -1,12 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { NodeViewConstructor } from "prosemirror-view";
|
|
2
|
+
import { NodeViewComponentProps } from "../components/NodeViewComponentProps.js";
|
|
3
|
+
import { DOMNode } from "../dom.js";
|
|
4
4
|
import { NodeViewDesc, ViewDesc } from "../viewdesc.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
type Props = NodeViewComponentProps["nodeProps"];
|
|
6
|
+
export declare function useNodeViewDescriptor(ref: {
|
|
7
|
+
readonly current: DOMNode | null;
|
|
8
|
+
}, constructor: NodeViewConstructor, props: Props): {
|
|
9
|
+
childContextValue: {
|
|
10
|
+
parentRef: import("react").MutableRefObject<NodeViewDesc | undefined>;
|
|
11
|
+
siblingsRef: import("react").MutableRefObject<ViewDesc[]>;
|
|
12
|
+
};
|
|
13
|
+
dom: Node | null;
|
|
14
|
+
contentDOM: HTMLElement | null;
|
|
15
|
+
nodeDOM: Node | null;
|
|
16
|
+
ref: {
|
|
17
|
+
readonly current: DOMNode | null;
|
|
18
|
+
};
|
|
12
19
|
};
|
|
20
|
+
export {};
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { EditorView } from "prosemirror-view";
|
|
2
|
+
export declare function useSelectNode(selectNode: (view: EditorView) => void, deselectNode?: (view: EditorView) => void): void;
|
package/dist/types/viewdesc.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Mark, Node, TagParseRule } from "prosemirror-model";
|
|
2
|
-
import { Decoration, DecorationSource } from "prosemirror-view";
|
|
2
|
+
import { Decoration, DecorationSource, EditorView, NodeView } from "prosemirror-view";
|
|
3
3
|
import { ReactEditorView } from "./ReactEditorView.js";
|
|
4
4
|
import { DOMNode } from "./dom.js";
|
|
5
5
|
declare global {
|
|
@@ -112,17 +112,17 @@ export declare class NodeViewDesc extends ViewDesc {
|
|
|
112
112
|
outerDeco: readonly Decoration[];
|
|
113
113
|
innerDeco: DecorationSource;
|
|
114
114
|
nodeDOM: DOMNode;
|
|
115
|
-
|
|
116
|
-
selectNode: () => void;
|
|
117
|
-
deselectNode: () => void;
|
|
118
|
-
ignoreMutation: (mutation: ViewMutationRecord) => boolean;
|
|
119
|
-
constructor(parent: ViewDesc | undefined, children: ViewDesc[], getPos: () => number, node: Node, outerDeco: readonly Decoration[], innerDeco: DecorationSource, dom: DOMNode, contentDOM: HTMLElement | null, nodeDOM: DOMNode, stopEvent: (event: Event) => boolean, selectNode: () => void, deselectNode: () => void, ignoreMutation: (mutation: ViewMutationRecord) => boolean);
|
|
120
|
-
updateOuterDeco(): void;
|
|
115
|
+
constructor(parent: ViewDesc | undefined, children: ViewDesc[], getPos: () => number, node: Node, outerDeco: readonly Decoration[], innerDeco: DecorationSource, dom: DOMNode, contentDOM: HTMLElement | null, nodeDOM: DOMNode);
|
|
121
116
|
parseRule(): Omit<TagParseRule, "tag"> | null;
|
|
122
117
|
matchesNode(node: Node, outerDeco: readonly Decoration[], innerDeco: DecorationSource): boolean;
|
|
123
118
|
get size(): number;
|
|
124
119
|
get border(): 0 | 1;
|
|
125
|
-
|
|
120
|
+
updateChildren(_view: EditorView, _pos: number): void;
|
|
121
|
+
update(node: Node, outerDeco: readonly Decoration[], innerDeco: DecorationSource, view: EditorView): boolean;
|
|
122
|
+
updateInner(node: Node, outerDeco: readonly Decoration[], innerDeco: DecorationSource, view: EditorView): void;
|
|
123
|
+
updateOuterDeco(outerDeco: readonly Decoration[]): void;
|
|
124
|
+
selectNode(): void;
|
|
125
|
+
deselectNode(): void;
|
|
126
126
|
get domAtom(): boolean;
|
|
127
127
|
}
|
|
128
128
|
export declare class TextViewDesc extends NodeViewDesc {
|
|
@@ -148,3 +148,20 @@ export declare class TrailingHackViewDesc extends ViewDesc {
|
|
|
148
148
|
get domAtom(): boolean;
|
|
149
149
|
get ignoreForCoords(): boolean;
|
|
150
150
|
}
|
|
151
|
+
declare class CustomNodeViewDesc extends NodeViewDesc {
|
|
152
|
+
readonly spec: NodeView;
|
|
153
|
+
constructor(parent: ViewDesc | undefined, children: ViewDesc[], getPos: () => number, node: Node, outerDeco: readonly Decoration[], innerDeco: DecorationSource, dom: DOMNode, contentDOM: HTMLElement | null, nodeDOM: DOMNode, spec: NodeView);
|
|
154
|
+
update(node: Node, outerDeco: readonly Decoration[], innerDeco: DecorationSource, view: EditorView): boolean;
|
|
155
|
+
selectNode(): void;
|
|
156
|
+
deselectNode(): void;
|
|
157
|
+
setSelection(anchor: number, head: number, view: ReactEditorView, force: boolean): void;
|
|
158
|
+
destroy(): void;
|
|
159
|
+
stopEvent(event: Event): boolean;
|
|
160
|
+
ignoreMutation(mutation: ViewMutationRecord): boolean;
|
|
161
|
+
}
|
|
162
|
+
export declare class ReactNodeViewDesc extends CustomNodeViewDesc {
|
|
163
|
+
updateChildren(_view: EditorView, _pos: number): void;
|
|
164
|
+
updateOuterDeco(outerDeco: readonly Decoration[]): void;
|
|
165
|
+
destroy(): void;
|
|
166
|
+
}
|
|
167
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@handlewithcare/react-prosemirror",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.2",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/cjs/index.js",
|
|
@@ -118,8 +118,8 @@
|
|
|
118
118
|
"prosemirror-model": "^1.0.0",
|
|
119
119
|
"prosemirror-state": "^1.0.0",
|
|
120
120
|
"prosemirror-view": "1.39.2",
|
|
121
|
-
"react": ">=17
|
|
122
|
-
"react-dom": ">=17
|
|
121
|
+
"react": ">=17 <20",
|
|
122
|
+
"react-dom": ">=17 <20",
|
|
123
123
|
"react-reconciler": ">=0.26.1 <=0.32.0"
|
|
124
124
|
},
|
|
125
125
|
"packageManager": "yarn@4.6.0",
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "useClientOnly", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return useClientOnly;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _react = require("react");
|
|
12
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
13
|
-
function unsubscribe() {}
|
|
14
|
-
function subscribe() {
|
|
15
|
-
return unsubscribe;
|
|
16
|
-
}
|
|
17
|
-
function useClientOnly() {
|
|
18
|
-
return (0, _react.useSyncExternalStore)(subscribe, ()=>true, ()=>false);
|
|
19
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { useSyncExternalStore } from "react";
|
|
2
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
3
|
-
function unsubscribe() {}
|
|
4
|
-
function subscribe() {
|
|
5
|
-
return unsubscribe;
|
|
6
|
-
}
|
|
7
|
-
export function useClientOnly() {
|
|
8
|
-
return useSyncExternalStore(subscribe, ()=>true, ()=>false);
|
|
9
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function useClientOnly(): boolean;
|