@handlewithcare/react-prosemirror 2.4.12 → 2.5.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/cjs/AbstractEditorView.js +4 -0
- package/dist/cjs/ReactEditorView.js +156 -0
- package/dist/cjs/StaticEditorView.js +86 -0
- package/dist/cjs/components/ChildNodeViews.js +59 -30
- package/dist/cjs/components/CustomNodeView.js +9 -25
- package/dist/cjs/components/DocNodeView.js +6 -15
- package/dist/cjs/components/MarkView.js +1 -2
- package/dist/cjs/components/NativeWidgetView.js +2 -3
- package/dist/cjs/components/NodeView.js +1 -1
- package/dist/cjs/components/ProseMirror.js +11 -14
- package/dist/cjs/components/ReactNodeView.js +3 -4
- package/dist/cjs/components/SeparatorHackView.js +1 -2
- package/dist/cjs/components/TextNodeView.js +4 -5
- package/dist/cjs/components/TrailingHackView.js +1 -2
- package/dist/cjs/components/WidgetView.js +2 -4
- package/dist/cjs/constants.js +33 -0
- package/dist/cjs/hooks/useEditor.js +32 -228
- package/dist/cjs/hooks/useEditorEffect.js +2 -2
- package/dist/cjs/hooks/useEditorEventCallback.js +8 -5
- package/dist/cjs/hooks/useNodeViewDescriptor.js +10 -10
- package/dist/cjs/hooks/useReactKeys.js +1 -1
- package/dist/cjs/testing/editorViewTestHelpers.js +0 -2
- package/dist/cjs/viewdesc.js +10 -9
- package/dist/esm/AbstractEditorView.js +1 -0
- package/dist/esm/ReactEditorView.js +156 -0
- package/dist/esm/StaticEditorView.js +76 -0
- package/dist/esm/components/ChildNodeViews.js +60 -32
- package/dist/esm/components/CustomNodeView.js +9 -25
- package/dist/esm/components/DocNodeView.js +6 -15
- package/dist/esm/components/MarkView.js +1 -2
- package/dist/esm/components/NativeWidgetView.js +2 -3
- package/dist/esm/components/NodeView.js +1 -1
- package/dist/esm/components/ProseMirror.js +11 -14
- package/dist/esm/components/ReactNodeView.js +3 -4
- package/dist/esm/components/SeparatorHackView.js +1 -2
- package/dist/esm/components/TextNodeView.js +4 -5
- package/dist/esm/components/TrailingHackView.js +1 -2
- package/dist/esm/components/WidgetView.js +2 -4
- package/dist/esm/constants.js +15 -0
- package/dist/esm/hooks/useEditor.js +28 -217
- package/dist/esm/hooks/useEditorEffect.js +2 -2
- package/dist/esm/hooks/useEditorEventCallback.js +8 -5
- package/dist/esm/hooks/useNodeViewDescriptor.js +10 -10
- package/dist/esm/hooks/useReactKeys.js +1 -1
- package/dist/esm/testing/editorViewTestHelpers.js +0 -2
- package/dist/esm/viewdesc.js +3 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/AbstractEditorView.d.ts +27 -0
- package/dist/types/ReactEditorView.d.ts +79 -0
- package/dist/types/StaticEditorView.d.ts +24 -0
- package/dist/types/components/ChildNodeViews.d.ts +2 -2
- package/dist/types/components/CustomNodeView.d.ts +2 -2
- package/dist/types/components/DocNodeView.d.ts +2 -5
- package/dist/types/components/MarkView.d.ts +2 -2
- package/dist/types/components/NativeWidgetView.d.ts +2 -2
- package/dist/types/components/NodeView.d.ts +2 -2
- package/dist/types/components/ReactNodeView.d.ts +2 -2
- package/dist/types/components/SeparatorHackView.d.ts +2 -2
- package/dist/types/components/TextNodeView.d.ts +4 -3
- package/dist/types/components/TrailingHackView.d.ts +2 -2
- package/dist/types/components/WidgetView.d.ts +2 -2
- package/dist/types/constants.d.ts +4 -0
- package/dist/types/contexts/EditorContext.d.ts +6 -4
- package/dist/types/decorations/computeDocDeco.d.ts +3 -2
- package/dist/types/decorations/viewDecorations.d.ts +3 -2
- package/dist/types/hooks/useEditor.d.ts +5 -46
- package/dist/types/hooks/useNodeViewDescriptor.d.ts +1 -1
- package/dist/types/hooks/useReactKeys.d.ts +1 -1
- package/dist/types/props.d.ts +3 -3
- package/dist/types/viewdesc.d.ts +6 -5
- package/package.json +6 -2
- package/dist/cjs/components/Editor.js +0 -28
- package/dist/cjs/components/NodeViews.js +0 -73
- package/dist/cjs/components/__tests__/LayoutGroup.test.js +0 -141
- package/dist/cjs/components/__tests__/ProseMirror.test.js +0 -255
- package/dist/cjs/contexts/NodeViewsContext.js +0 -10
- package/dist/cjs/hooks/__tests__/useEditorViewLayoutEffect.test.js +0 -107
- package/dist/cjs/hooks/__tests__/useNodeViews.test.js +0 -159
- package/dist/cjs/hooks/useEditorView.js +0 -100
- package/dist/cjs/hooks/useNodePos.js +0 -69
- package/dist/cjs/hooks/useNodeViews.js +0 -100
- package/dist/cjs/nodeViews/createReactNodeViewConstructor.js +0 -244
- package/dist/cjs/nodeViews/phrasingContentTags.js +0 -57
- package/dist/cjs/plugins/__tests__/react.test.js +0 -139
- package/dist/cjs/plugins/react.js +0 -71
- package/dist/cjs/selection/SelectionDOMObserver.js +0 -171
- package/dist/cjs/selection/hasFocusAndSelection.js +0 -35
- package/dist/cjs/selection/selectionFromDOM.js +0 -77
- package/dist/cjs/selection/selectionToDOM.js +0 -226
- package/dist/cjs/ssr.js +0 -85
- package/dist/esm/components/Editor.js +0 -15
- package/dist/esm/components/NodeViews.js +0 -26
- package/dist/esm/components/__tests__/LayoutGroup.test.js +0 -98
- package/dist/esm/components/__tests__/ProseMirror.test.js +0 -207
- package/dist/esm/contexts/NodeViewsContext.js +0 -9
- package/dist/esm/hooks/__tests__/useEditorViewLayoutEffect.test.js +0 -98
- package/dist/esm/hooks/__tests__/useNodeViews.test.js +0 -116
- package/dist/esm/hooks/useEditorView.js +0 -99
- package/dist/esm/hooks/useNodePos.js +0 -16
- package/dist/esm/hooks/useNodeViews.js +0 -53
- package/dist/esm/nodeViews/createReactNodeViewConstructor.js +0 -214
- package/dist/esm/nodeViews/phrasingContentTags.js +0 -49
- package/dist/esm/plugins/__tests__/react.test.js +0 -135
- package/dist/esm/plugins/react.js +0 -64
- package/dist/esm/selection/SelectionDOMObserver.js +0 -161
- package/dist/esm/selection/hasFocusAndSelection.js +0 -17
- package/dist/esm/selection/selectionFromDOM.js +0 -59
- package/dist/esm/selection/selectionToDOM.js +0 -196
- package/dist/esm/ssr.js +0 -82
- package/dist/types/components/Editor.d.ts +0 -7
- package/dist/types/components/NodeViews.d.ts +0 -6
- package/dist/types/components/__tests__/LayoutGroup.test.d.ts +0 -1
- package/dist/types/contexts/NodeViewsContext.d.ts +0 -19
- package/dist/types/hooks/__tests__/useEditorViewLayoutEffect.test.d.ts +0 -1
- package/dist/types/hooks/__tests__/useNodeViews.test.d.ts +0 -1
- package/dist/types/hooks/useEditorView.d.ts +0 -23
- package/dist/types/hooks/useNodePos.d.ts +0 -9
- package/dist/types/hooks/useNodeViews.d.ts +0 -5
- package/dist/types/nodeViews/createReactNodeViewConstructor.d.ts +0 -48
- package/dist/types/nodeViews/phrasingContentTags.d.ts +0 -1
- package/dist/types/plugins/__tests__/react.test.d.ts +0 -1
- package/dist/types/plugins/react.d.ts +0 -21
- package/dist/types/selection/SelectionDOMObserver.d.ts +0 -33
- package/dist/types/selection/hasFocusAndSelection.d.ts +0 -3
- package/dist/types/selection/selectionFromDOM.d.ts +0 -4
- package/dist/types/selection/selectionToDOM.d.ts +0 -9
- package/dist/types/ssr.d.ts +0 -19
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { EditorState } from "prosemirror-state";
|
|
2
|
+
import { DirectEditorProps, EditorProps, MarkViewConstructor, NodeViewConstructor } from "prosemirror-view";
|
|
3
|
+
import { DOMSelection } from "./dom.js";
|
|
4
|
+
export type NodeViewSet = {
|
|
5
|
+
[name: string]: NodeViewConstructor | MarkViewConstructor;
|
|
6
|
+
};
|
|
7
|
+
export interface AbstractEditorView {
|
|
8
|
+
readonly composing: boolean;
|
|
9
|
+
readonly dom: HTMLElement | null;
|
|
10
|
+
readonly editable: boolean;
|
|
11
|
+
readonly nodeViews: NodeViewSet;
|
|
12
|
+
readonly props: DirectEditorProps;
|
|
13
|
+
readonly state: EditorState;
|
|
14
|
+
setProps(props: Partial<DirectEditorProps>): void;
|
|
15
|
+
update(props: DirectEditorProps): void;
|
|
16
|
+
updateState(state: EditorState): void;
|
|
17
|
+
someProp<PropName extends keyof EditorProps>(propName: PropName): EditorProps[PropName] | undefined;
|
|
18
|
+
someProp<PropName extends keyof EditorProps, Result>(propName: PropName, f: (value: NonNullable<EditorProps[PropName]>) => Result): Result | undefined;
|
|
19
|
+
destroy(): void;
|
|
20
|
+
domSelectionRange(): {
|
|
21
|
+
anchorNode: Node | null;
|
|
22
|
+
anchorOffset: number;
|
|
23
|
+
focusNode: Node | null;
|
|
24
|
+
focusOffset: number;
|
|
25
|
+
};
|
|
26
|
+
domSelection(): DOMSelection | null;
|
|
27
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { EditorState } from "prosemirror-state";
|
|
2
|
+
import { Decoration, DirectEditorProps, EditorProps, EditorView } from "prosemirror-view";
|
|
3
|
+
import { AbstractEditorView, NodeViewSet } from "./AbstractEditorView.js";
|
|
4
|
+
import { DOMNode, DOMSelection, DOMSelectionRange } from "./dom.js";
|
|
5
|
+
import { NodeViewDesc, ViewDesc } from "./viewdesc.js";
|
|
6
|
+
interface DOMObserver {
|
|
7
|
+
observer: MutationObserver | null;
|
|
8
|
+
queue: MutationRecord[];
|
|
9
|
+
start(): void;
|
|
10
|
+
stop(): void;
|
|
11
|
+
}
|
|
12
|
+
interface InputState {
|
|
13
|
+
compositionID: number;
|
|
14
|
+
compositionNodes: ViewDesc[];
|
|
15
|
+
compositionPendingChanges: number;
|
|
16
|
+
lastFocus: number;
|
|
17
|
+
lastClick: {
|
|
18
|
+
time: number;
|
|
19
|
+
x: number;
|
|
20
|
+
y: number;
|
|
21
|
+
type: string;
|
|
22
|
+
button: number;
|
|
23
|
+
};
|
|
24
|
+
lastSelectionOrigin: string | null;
|
|
25
|
+
lastSelectionTime: number;
|
|
26
|
+
lastTouch: number;
|
|
27
|
+
mouseDown: {
|
|
28
|
+
allowDefault: boolean;
|
|
29
|
+
delayedSelectionSync: boolean;
|
|
30
|
+
};
|
|
31
|
+
hideSelectionGuard: (() => void) | null;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Extends EditorView to make prop and state updates pure, remove the DOM
|
|
35
|
+
* Mutation Observer, and use a custom document view managed by React.
|
|
36
|
+
*
|
|
37
|
+
* @privateRemarks
|
|
38
|
+
*
|
|
39
|
+
* The implementation relies on the base class using a private member to store
|
|
40
|
+
* the committed props and having a public getter that we override to return the
|
|
41
|
+
* latest, uncommitted props. The base class can then be told to update when the
|
|
42
|
+
* React effects are commit an update, applying the pending, uncommitted props.
|
|
43
|
+
*/
|
|
44
|
+
export declare class ReactEditorView extends EditorView implements AbstractEditorView {
|
|
45
|
+
cursorWrapper: {
|
|
46
|
+
dom: DOMNode;
|
|
47
|
+
deco: Decoration;
|
|
48
|
+
} | null;
|
|
49
|
+
nodeViews: NodeViewSet;
|
|
50
|
+
lastSelectedViewDesc: ViewDesc | undefined;
|
|
51
|
+
docView: NodeViewDesc;
|
|
52
|
+
input: InputState;
|
|
53
|
+
domObserver: DOMObserver;
|
|
54
|
+
domSelectionRange: () => DOMSelectionRange;
|
|
55
|
+
domSelection: () => DOMSelection | null;
|
|
56
|
+
private nextProps;
|
|
57
|
+
private prevState;
|
|
58
|
+
constructor(place: {
|
|
59
|
+
mount: HTMLElement;
|
|
60
|
+
}, props: DirectEditorProps);
|
|
61
|
+
get props(): DirectEditorProps;
|
|
62
|
+
setProps(props: Partial<DirectEditorProps>): void;
|
|
63
|
+
update(props: DirectEditorProps): void;
|
|
64
|
+
updateState(state: EditorState): void;
|
|
65
|
+
someProp<PropName extends keyof EditorProps>(propName: PropName): EditorProps[PropName] | undefined;
|
|
66
|
+
someProp<PropName extends keyof EditorProps, Result>(propName: PropName, f?: (value: NonNullable<EditorProps[PropName]>) => Result): Result | undefined;
|
|
67
|
+
/**
|
|
68
|
+
* Commit effects by appling the pending props and state.
|
|
69
|
+
*
|
|
70
|
+
* Ensures the DOM selection is correct and updates plugin views.
|
|
71
|
+
*
|
|
72
|
+
* @privateRemarks
|
|
73
|
+
*
|
|
74
|
+
* The correctness of this depends on the pure update function ensuring that
|
|
75
|
+
* the node view set is up to date so that it does not try to redraw.
|
|
76
|
+
*/
|
|
77
|
+
commitPendingEffects(): void;
|
|
78
|
+
}
|
|
79
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { EditorState } from "prosemirror-state";
|
|
2
|
+
import { DirectEditorProps, EditorProps } from "prosemirror-view";
|
|
3
|
+
import { AbstractEditorView, NodeViewSet } from "./AbstractEditorView.js";
|
|
4
|
+
export declare class StaticEditorView implements AbstractEditorView {
|
|
5
|
+
props: DirectEditorProps;
|
|
6
|
+
readonly nodeViews: NodeViewSet;
|
|
7
|
+
constructor(props: DirectEditorProps);
|
|
8
|
+
get composing(): boolean;
|
|
9
|
+
get dom(): null;
|
|
10
|
+
get editable(): boolean;
|
|
11
|
+
get state(): EditorState;
|
|
12
|
+
setProps(props: Partial<DirectEditorProps>): void;
|
|
13
|
+
update(props: DirectEditorProps): void;
|
|
14
|
+
updateState(state: EditorState): void;
|
|
15
|
+
someProp<PropName extends keyof EditorProps>(propName: PropName): EditorProps[PropName] | undefined;
|
|
16
|
+
destroy(): void;
|
|
17
|
+
domSelectionRange(): {
|
|
18
|
+
anchorNode: null;
|
|
19
|
+
anchorOffset: number;
|
|
20
|
+
focusNode: null;
|
|
21
|
+
focusOffset: number;
|
|
22
|
+
};
|
|
23
|
+
domSelection(): null;
|
|
24
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Node } from "prosemirror-model";
|
|
2
2
|
import { Decoration, DecorationSource } from "prosemirror-view";
|
|
3
|
-
import React
|
|
3
|
+
import React from "react";
|
|
4
4
|
export declare function wrapInDeco(reactNode: JSX.Element | string, deco: Decoration): React.DetailedReactHTMLElement<React.HTMLProps<HTMLElement>, HTMLElement> | React.FunctionComponentElement<any>;
|
|
5
5
|
export declare const ChildNodeViews: React.NamedExoticComponent<{
|
|
6
|
-
getPos:
|
|
6
|
+
getPos: () => number;
|
|
7
7
|
node: Node | undefined;
|
|
8
8
|
innerDecorations: DecorationSource;
|
|
9
9
|
}>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Node } from "prosemirror-model";
|
|
2
2
|
import { Decoration, DecorationSource, NodeViewConstructor } from "prosemirror-view";
|
|
3
|
-
import React
|
|
3
|
+
import React from "react";
|
|
4
4
|
interface Props {
|
|
5
5
|
customNodeView: NodeViewConstructor;
|
|
6
6
|
node: Node;
|
|
7
|
-
getPos:
|
|
7
|
+
getPos: () => number;
|
|
8
8
|
innerDeco: DecorationSource;
|
|
9
9
|
outerDeco: readonly Decoration[];
|
|
10
10
|
}
|
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
import { Node } from "prosemirror-model";
|
|
2
2
|
import { Decoration, DecorationSource } from "prosemirror-view";
|
|
3
3
|
import React, { DetailedHTMLProps, HTMLAttributes, ReactElement } from "react";
|
|
4
|
-
import { NodeViewDesc } from "../viewdesc.js";
|
|
5
4
|
export type DocNodeViewProps = {
|
|
6
5
|
className?: string;
|
|
7
|
-
node: Node
|
|
6
|
+
node: Node;
|
|
8
7
|
innerDeco: DecorationSource;
|
|
9
8
|
outerDeco: Decoration[];
|
|
10
9
|
as?: ReactElement;
|
|
11
|
-
viewDesc?: NodeViewDesc;
|
|
12
10
|
} & Omit<DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLDivElement>, "ref">;
|
|
13
11
|
export declare const DocNodeView: React.MemoExoticComponent<React.ForwardRefExoticComponent<{
|
|
14
12
|
className?: string | undefined;
|
|
15
|
-
node: Node
|
|
13
|
+
node: Node;
|
|
16
14
|
innerDeco: DecorationSource;
|
|
17
15
|
outerDeco: Decoration[];
|
|
18
16
|
as?: React.ReactElement<any, string | React.JSXElementConstructor<any>> | undefined;
|
|
19
|
-
viewDesc?: NodeViewDesc | undefined;
|
|
20
17
|
} & Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement | null>>>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Mark } from "prosemirror-model";
|
|
2
|
-
import React, {
|
|
2
|
+
import React, { ReactNode } from "react";
|
|
3
3
|
type Props = {
|
|
4
4
|
mark: Mark;
|
|
5
|
-
getPos:
|
|
5
|
+
getPos: () => number;
|
|
6
6
|
children: ReactNode;
|
|
7
7
|
};
|
|
8
8
|
export declare const MarkView: React.MemoExoticComponent<React.ForwardRefExoticComponent<Props & React.RefAttributes<unknown>>>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Decoration } from "prosemirror-view";
|
|
2
|
-
import React
|
|
2
|
+
import React from "react";
|
|
3
3
|
type Props = {
|
|
4
4
|
widget: Decoration;
|
|
5
|
-
getPos:
|
|
5
|
+
getPos: () => number;
|
|
6
6
|
};
|
|
7
7
|
export declare function NativeWidgetView({ widget, getPos }: Props): React.JSX.Element;
|
|
8
8
|
export {};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Node } from "prosemirror-model";
|
|
2
2
|
import { Decoration, DecorationSource } from "prosemirror-view";
|
|
3
|
-
import React
|
|
3
|
+
import React from "react";
|
|
4
4
|
type NodeViewProps = {
|
|
5
5
|
outerDeco: readonly Decoration[];
|
|
6
|
-
getPos:
|
|
6
|
+
getPos: () => number;
|
|
7
7
|
node: Node;
|
|
8
8
|
innerDeco: DecorationSource;
|
|
9
9
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Node } from "prosemirror-model";
|
|
2
2
|
import { Decoration, DecorationSource } from "prosemirror-view";
|
|
3
|
-
import React
|
|
3
|
+
import React from "react";
|
|
4
4
|
type Props = {
|
|
5
5
|
outerDeco: readonly Decoration[];
|
|
6
|
-
getPos:
|
|
6
|
+
getPos: () => number;
|
|
7
7
|
node: Node;
|
|
8
8
|
innerDeco: DecorationSource;
|
|
9
9
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from "react";
|
|
2
2
|
type Props = {
|
|
3
|
-
getPos:
|
|
3
|
+
getPos: () => number;
|
|
4
4
|
};
|
|
5
5
|
export declare function SeparatorHackView({ getPos }: Props): React.JSX.Element | null;
|
|
6
6
|
export {};
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { Node } from "prosemirror-model";
|
|
2
|
-
import { Decoration
|
|
2
|
+
import { Decoration } from "prosemirror-view";
|
|
3
3
|
import { Component, MutableRefObject } from "react";
|
|
4
|
+
import { AbstractEditorView } from "../AbstractEditorView.js";
|
|
4
5
|
import { ViewDesc } from "../viewdesc.js";
|
|
5
6
|
type Props = {
|
|
6
|
-
view:
|
|
7
|
+
view: AbstractEditorView;
|
|
7
8
|
node: Node;
|
|
8
|
-
getPos:
|
|
9
|
+
getPos: () => number;
|
|
9
10
|
siblingsRef: MutableRefObject<ViewDesc[]>;
|
|
10
11
|
parentRef: MutableRefObject<ViewDesc | undefined>;
|
|
11
12
|
decorations: readonly Decoration[];
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from "react";
|
|
2
2
|
import { ReactWidgetDecoration } from "../decorations/ReactWidgetType.js";
|
|
3
3
|
type Props = {
|
|
4
4
|
widget: ReactWidgetDecoration;
|
|
5
|
-
getPos:
|
|
5
|
+
getPos: () => number;
|
|
6
6
|
};
|
|
7
7
|
export declare function WidgetView({ widget, getPos }: Props): React.JSX.Element;
|
|
8
8
|
export {};
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import type { DOMEventMap,
|
|
1
|
+
import type { DOMEventMap, Decoration } from "prosemirror-view";
|
|
2
2
|
import { MutableRefObject } from "react";
|
|
3
|
-
import
|
|
3
|
+
import { AbstractEditorView } from "../AbstractEditorView.js";
|
|
4
|
+
import type { EventHandler } from "../plugins/componentEventListeners.js";
|
|
4
5
|
export interface EditorContextValue {
|
|
5
|
-
view:
|
|
6
|
+
view: AbstractEditorView;
|
|
7
|
+
cursorWrapper: Decoration | null;
|
|
8
|
+
flushSyncRef: MutableRefObject<boolean>;
|
|
6
9
|
registerEventListener<EventType extends keyof DOMEventMap>(eventType: EventType, handler: EventHandler<EventType>): void;
|
|
7
10
|
unregisterEventListener<EventType extends keyof DOMEventMap>(eventType: EventType, handler: EventHandler<EventType>): void;
|
|
8
|
-
flushSyncRef: MutableRefObject<boolean>;
|
|
9
11
|
}
|
|
10
12
|
/**
|
|
11
13
|
* Provides the EditorView, as well as the current
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Decoration
|
|
1
|
+
import { Decoration } from "prosemirror-view";
|
|
2
|
+
import { AbstractEditorView } from "../AbstractEditorView.js";
|
|
2
3
|
/**
|
|
3
4
|
* Produces the outer decorations for the doc node, based
|
|
4
5
|
* on the attributes editor prop.
|
|
@@ -10,4 +11,4 @@ import { Decoration, EditorView } from "prosemirror-view";
|
|
|
10
11
|
* This makes it safe to call in a React render function, even
|
|
11
12
|
* if its result is used in a dependencies array for a hook.
|
|
12
13
|
*/
|
|
13
|
-
export declare function computeDocDeco(view:
|
|
14
|
+
export declare function computeDocDeco(view: AbstractEditorView): [Decoration];
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Decoration, DecorationSource
|
|
1
|
+
import { Decoration, DecorationSource } from "prosemirror-view";
|
|
2
|
+
import { AbstractEditorView } from "../AbstractEditorView.js";
|
|
2
3
|
/**
|
|
3
4
|
* Produces the DecorationSource for the current state, based
|
|
4
5
|
* on the decorations editor prop.
|
|
@@ -10,4 +11,4 @@ import { Decoration, DecorationSource, EditorView } from "prosemirror-view";
|
|
|
10
11
|
* This makes it safe to call in a React render function, even
|
|
11
12
|
* if its result is used in a dependencies array for a hook.
|
|
12
13
|
*/
|
|
13
|
-
export declare function viewDecorations(view:
|
|
14
|
+
export declare function viewDecorations(view: AbstractEditorView, cursorWrapper: Decoration | null): DecorationSource;
|
|
@@ -1,46 +1,6 @@
|
|
|
1
1
|
import { EditorState, Plugin, Transaction } from "prosemirror-state";
|
|
2
|
-
import { Decoration,
|
|
3
|
-
import {
|
|
4
|
-
export declare class ReactEditorView extends EditorView {
|
|
5
|
-
private shouldUpdatePluginViews;
|
|
6
|
-
private oldProps;
|
|
7
|
-
private _props;
|
|
8
|
-
ready: boolean;
|
|
9
|
-
constructor(place: {
|
|
10
|
-
mount: HTMLElement;
|
|
11
|
-
} | null, props: DirectEditorProps & {
|
|
12
|
-
docView: NodeViewDesc;
|
|
13
|
-
ready: boolean;
|
|
14
|
-
});
|
|
15
|
-
/**
|
|
16
|
-
* Whether the EditorView's updateStateInner method thinks that the
|
|
17
|
-
* docView needs to be blown away and redrawn.
|
|
18
|
-
*
|
|
19
|
-
* @privateremarks
|
|
20
|
-
*
|
|
21
|
-
* When ProseMirror View detects that the EditorState has been reconfigured
|
|
22
|
-
* to provide new custom node views, it calls an internal function that
|
|
23
|
-
* we can't override in order to recreate the entire editor DOM.
|
|
24
|
-
*
|
|
25
|
-
* This property mimics that check, so that we can replace the EditorView
|
|
26
|
-
* with another of our own, preventing ProseMirror View from taking over
|
|
27
|
-
* DOM management responsibility.
|
|
28
|
-
*/
|
|
29
|
-
get needsRedraw(): boolean;
|
|
30
|
-
/**
|
|
31
|
-
* Like setProps, but without executing any side effects.
|
|
32
|
-
* Safe to use in a component render method.
|
|
33
|
-
*/
|
|
34
|
-
pureSetProps(props: Partial<DirectEditorProps>): void;
|
|
35
|
-
/**
|
|
36
|
-
* Triggers any side effects that have been queued by previous
|
|
37
|
-
* calls to pureSetProps.
|
|
38
|
-
*/
|
|
39
|
-
runPendingEffects(): void;
|
|
40
|
-
update(props: DirectEditorProps): void;
|
|
41
|
-
updatePluginViews(prevState?: EditorState): void;
|
|
42
|
-
destroy(): void;
|
|
43
|
-
}
|
|
2
|
+
import { Decoration, EditorProps, EditorView } from "prosemirror-view";
|
|
3
|
+
import { AbstractEditorView } from "../AbstractEditorView.js";
|
|
44
4
|
export interface UseEditorOptions extends EditorProps {
|
|
45
5
|
defaultState?: EditorState;
|
|
46
6
|
state?: EditorState;
|
|
@@ -58,12 +18,11 @@ export interface UseEditorOptions extends EditorProps {
|
|
|
58
18
|
*/
|
|
59
19
|
export declare function useEditor<T extends HTMLElement = HTMLElement>(mount: T | null, options: UseEditorOptions): {
|
|
60
20
|
editor: {
|
|
61
|
-
view:
|
|
62
|
-
registerEventListener: (eventType: keyof import("prosemirror-view").DOMEventMap, handler: import("../plugins/componentEventListeners.js").EventHandler<keyof import("prosemirror-view").DOMEventMap>) => void;
|
|
63
|
-
unregisterEventListener: (eventType: keyof import("prosemirror-view").DOMEventMap, handler: import("../plugins/componentEventListeners.js").EventHandler<keyof import("prosemirror-view").DOMEventMap>) => void;
|
|
21
|
+
view: AbstractEditorView;
|
|
64
22
|
cursorWrapper: Decoration | null;
|
|
65
|
-
docViewDescRef: import("react").MutableRefObject<NodeViewDesc>;
|
|
66
23
|
flushSyncRef: import("react").MutableRefObject<boolean>;
|
|
24
|
+
registerEventListener: (eventType: keyof import("prosemirror-view").DOMEventMap, handler: import("../plugins/componentEventListeners.js").EventHandler<keyof import("prosemirror-view").DOMEventMap>) => void;
|
|
25
|
+
unregisterEventListener: (eventType: keyof import("prosemirror-view").DOMEventMap, handler: import("../plugins/componentEventListeners.js").EventHandler<keyof import("prosemirror-view").DOMEventMap>) => void;
|
|
67
26
|
};
|
|
68
27
|
state: EditorState;
|
|
69
28
|
};
|
|
@@ -2,7 +2,7 @@ import { Node } from "prosemirror-model";
|
|
|
2
2
|
import { Decoration, DecorationSource, ViewMutationRecord } from "prosemirror-view";
|
|
3
3
|
import { MutableRefObject } from "react";
|
|
4
4
|
import { NodeViewDesc, ViewDesc } from "../viewdesc.js";
|
|
5
|
-
export declare function useNodeViewDescriptor(node: Node
|
|
5
|
+
export declare function useNodeViewDescriptor(node: Node, getPos: () => number, domRef: undefined | MutableRefObject<HTMLElement | null>, nodeDomRef: MutableRefObject<HTMLElement | null>, innerDecorations: DecorationSource, outerDecorations: readonly Decoration[], contentDOMRef?: MutableRefObject<HTMLElement | null>): {
|
|
6
6
|
hasContentDOM: boolean;
|
|
7
7
|
childDescriptors: MutableRefObject<ViewDesc[]>;
|
|
8
8
|
nodeViewDescRef: MutableRefObject<NodeViewDesc | undefined>;
|
package/dist/types/props.d.ts
CHANGED
|
@@ -919,7 +919,7 @@ export declare function mergeReactProps(a: HTMLProps<HTMLElement>, b: HTMLProps<
|
|
|
919
919
|
spellCheck?: (boolean | "false" | "true") | undefined;
|
|
920
920
|
tabIndex?: number | undefined;
|
|
921
921
|
title?: string | undefined;
|
|
922
|
-
translate?: "
|
|
922
|
+
translate?: "yes" | "no" | undefined;
|
|
923
923
|
radioGroup?: string | undefined;
|
|
924
924
|
role?: import("react").AriaRole | undefined;
|
|
925
925
|
about?: string | undefined;
|
|
@@ -944,7 +944,7 @@ export declare function mergeReactProps(a: HTMLProps<HTMLElement>, b: HTMLProps<
|
|
|
944
944
|
results?: number | undefined;
|
|
945
945
|
security?: string | undefined;
|
|
946
946
|
unselectable?: "off" | "on" | undefined;
|
|
947
|
-
inputMode?: "
|
|
947
|
+
inputMode?: "text" | "none" | "search" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined;
|
|
948
948
|
is?: string | undefined;
|
|
949
949
|
exportparts?: string | undefined;
|
|
950
950
|
part?: string | undefined;
|
|
@@ -965,7 +965,7 @@ export declare function mergeReactProps(a: HTMLProps<HTMLElement>, b: HTMLProps<
|
|
|
965
965
|
"aria-description"?: string | undefined;
|
|
966
966
|
"aria-details"?: string | undefined;
|
|
967
967
|
"aria-disabled"?: (boolean | "false" | "true") | undefined;
|
|
968
|
-
"aria-dropeffect"?: "
|
|
968
|
+
"aria-dropeffect"?: "none" | "link" | "copy" | "execute" | "move" | "popup" | undefined;
|
|
969
969
|
"aria-errormessage"?: string | undefined;
|
|
970
970
|
"aria-expanded"?: (boolean | "false" | "true") | undefined;
|
|
971
971
|
"aria-flowto"?: string | undefined;
|
package/dist/types/viewdesc.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Mark, Node, TagParseRule } from "prosemirror-model";
|
|
2
|
-
import { Decoration, DecorationSource
|
|
2
|
+
import { Decoration, DecorationSource } from "prosemirror-view";
|
|
3
|
+
import { ReactEditorView } from "./ReactEditorView.js";
|
|
3
4
|
import { DOMNode } from "./dom.js";
|
|
4
5
|
declare global {
|
|
5
6
|
interface Node {
|
|
@@ -54,7 +55,7 @@ export declare class ViewDesc {
|
|
|
54
55
|
};
|
|
55
56
|
emptyChildAt(side: number): boolean;
|
|
56
57
|
domAfterPos(pos: number): DOMNode;
|
|
57
|
-
setSelection(anchor: number, head: number, view:
|
|
58
|
+
setSelection(anchor: number, head: number, view: ReactEditorView, force?: boolean): void;
|
|
58
59
|
ignoreMutation(mutation: ViewMutationRecord): boolean;
|
|
59
60
|
get contentLost(): boolean | null;
|
|
60
61
|
markDirty(from: number, to: number): void;
|
|
@@ -120,8 +121,8 @@ export declare class NodeViewDesc extends ViewDesc {
|
|
|
120
121
|
parseRule(): Omit<TagParseRule, "tag"> | null;
|
|
121
122
|
matchesNode(node: Node, outerDeco: readonly Decoration[], innerDeco: DecorationSource): boolean;
|
|
122
123
|
get size(): number;
|
|
123
|
-
get border():
|
|
124
|
-
update(_node: Node, _outerDeco: readonly Decoration[], _innerDeco: DecorationSource, _view:
|
|
124
|
+
get border(): 0 | 1;
|
|
125
|
+
update(_node: Node, _outerDeco: readonly Decoration[], _innerDeco: DecorationSource, _view: ReactEditorView): boolean;
|
|
125
126
|
get domAtom(): boolean;
|
|
126
127
|
}
|
|
127
128
|
export declare class TextViewDesc extends NodeViewDesc {
|
|
@@ -129,7 +130,7 @@ export declare class TextViewDesc extends NodeViewDesc {
|
|
|
129
130
|
parseRule(): {
|
|
130
131
|
skip: any;
|
|
131
132
|
};
|
|
132
|
-
update(_node: Node, _outerDeco: readonly Decoration[], _innerDeco: DecorationSource, _view:
|
|
133
|
+
update(_node: Node, _outerDeco: readonly Decoration[], _innerDeco: DecorationSource, _view: ReactEditorView): boolean;
|
|
133
134
|
inParent(): boolean;
|
|
134
135
|
domFromPos(pos: number): {
|
|
135
136
|
node: globalThis.Node;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@handlewithcare/react-prosemirror",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/cjs/index.js",
|
|
@@ -119,7 +119,8 @@
|
|
|
119
119
|
"prosemirror-state": "^1.0.0",
|
|
120
120
|
"prosemirror-view": "1.39.2",
|
|
121
121
|
"react": ">=17 <=19.1.0",
|
|
122
|
-
"react-dom": ">=17 <=19.1.0"
|
|
122
|
+
"react-dom": ">=17 <=19.1.0",
|
|
123
|
+
"react-reconciler": ">=0.26.1 <=0.32.0"
|
|
123
124
|
},
|
|
124
125
|
"packageManager": "yarn@4.6.0",
|
|
125
126
|
"engines": {
|
|
@@ -127,5 +128,8 @@
|
|
|
127
128
|
},
|
|
128
129
|
"dependencies": {
|
|
129
130
|
"classnames": "^2.3.2"
|
|
131
|
+
},
|
|
132
|
+
"publishConfig": {
|
|
133
|
+
"access": "public"
|
|
130
134
|
}
|
|
131
135
|
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "Editor", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: ()=>Editor
|
|
8
|
-
});
|
|
9
|
-
const _react = /*#__PURE__*/ _interopRequireDefault(require("react"));
|
|
10
|
-
const _editorContextJs = require("../contexts/EditorContext.js");
|
|
11
|
-
const _useEditorViewJs = require("../hooks/useEditorView.js");
|
|
12
|
-
const _useNodeViewsJs = require("../hooks/useNodeViews.js");
|
|
13
|
-
function _interopRequireDefault(obj) {
|
|
14
|
-
return obj && obj.__esModule ? obj : {
|
|
15
|
-
default: obj
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
function Editor(param) {
|
|
19
|
-
let { mount , children , ...options } = param;
|
|
20
|
-
const { nodeViews , nodeViewsComponent } = (0, _useNodeViewsJs.useNodeViews)(options.nodeViews);
|
|
21
|
-
const value = (0, _useEditorViewJs.useEditorView)(mount, {
|
|
22
|
-
...options,
|
|
23
|
-
nodeViews
|
|
24
|
-
});
|
|
25
|
-
return /*#__PURE__*/ _react.default.createElement(_editorContextJs.EditorContext.Provider, {
|
|
26
|
-
value: value
|
|
27
|
-
}, children, nodeViewsComponent);
|
|
28
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "NodeViews", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: ()=>NodeViews
|
|
8
|
-
});
|
|
9
|
-
const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
|
|
10
|
-
const _nodeViewsContextJs = require("../contexts/NodeViewsContext.js");
|
|
11
|
-
const _useEditorEffectJs = require("../hooks/useEditorEffect.js");
|
|
12
|
-
const _reactJs = require("../plugins/react.js");
|
|
13
|
-
function _getRequireWildcardCache(nodeInterop) {
|
|
14
|
-
if (typeof WeakMap !== "function") return null;
|
|
15
|
-
var cacheBabelInterop = new WeakMap();
|
|
16
|
-
var cacheNodeInterop = new WeakMap();
|
|
17
|
-
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
18
|
-
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
19
|
-
})(nodeInterop);
|
|
20
|
-
}
|
|
21
|
-
function _interopRequireWildcard(obj, nodeInterop) {
|
|
22
|
-
if (!nodeInterop && obj && obj.__esModule) {
|
|
23
|
-
return obj;
|
|
24
|
-
}
|
|
25
|
-
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
26
|
-
return {
|
|
27
|
-
default: obj
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
var cache = _getRequireWildcardCache(nodeInterop);
|
|
31
|
-
if (cache && cache.has(obj)) {
|
|
32
|
-
return cache.get(obj);
|
|
33
|
-
}
|
|
34
|
-
var newObj = {};
|
|
35
|
-
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
36
|
-
for(var key in obj){
|
|
37
|
-
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
38
|
-
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
39
|
-
if (desc && (desc.get || desc.set)) {
|
|
40
|
-
Object.defineProperty(newObj, key, desc);
|
|
41
|
-
} else {
|
|
42
|
-
newObj[key] = obj[key];
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
newObj.default = obj;
|
|
47
|
-
if (cache) {
|
|
48
|
-
cache.set(obj, newObj);
|
|
49
|
-
}
|
|
50
|
-
return newObj;
|
|
51
|
-
}
|
|
52
|
-
function NodeViews(param) {
|
|
53
|
-
let { portals } = param;
|
|
54
|
-
const rootRegisteredPortals = portals[_reactJs.ROOT_NODE_KEY];
|
|
55
|
-
const [rootPortals, setRootPortals] = (0, _react.useState)(rootRegisteredPortals?.map((param)=>{
|
|
56
|
-
let { portal } = param;
|
|
57
|
-
return portal;
|
|
58
|
-
}) ?? []);
|
|
59
|
-
// `getPos` is technically derived from the EditorView
|
|
60
|
-
// state, so it's not safe to call until after the EditorView
|
|
61
|
-
// has been updated
|
|
62
|
-
(0, _useEditorEffectJs.useEditorEffect)(()=>{
|
|
63
|
-
setRootPortals(rootRegisteredPortals?.sort((a, b)=>a.getPos() - b.getPos()).map((param)=>{
|
|
64
|
-
let { portal } = param;
|
|
65
|
-
return portal;
|
|
66
|
-
}) ?? []);
|
|
67
|
-
}, [
|
|
68
|
-
rootRegisteredPortals
|
|
69
|
-
]);
|
|
70
|
-
return /*#__PURE__*/ _react.default.createElement(_nodeViewsContextJs.NodeViewsContext.Provider, {
|
|
71
|
-
value: portals
|
|
72
|
-
}, rootPortals);
|
|
73
|
-
}
|