@handlewithcare/react-prosemirror 3.1.0-tiptap.52 → 3.1.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/README.md +3 -0
- package/dist/cjs/ReactEditorView.js +18 -1
- package/dist/cjs/components/ChildNodeViews.js +4 -4
- package/dist/cjs/components/CursorWrapper.js +9 -11
- package/dist/cjs/components/ProseMirror.js +13 -3
- package/dist/cjs/components/TextNodeView.js +54 -50
- package/dist/cjs/components/WidgetView.js +3 -1
- package/dist/cjs/components/nodes/NodeView.js +40 -4
- package/dist/cjs/contexts/CompositionContext.js +14 -0
- package/dist/cjs/decorations/viewDecorations.js +1 -6
- package/dist/cjs/hooks/useEditor.js +2 -10
- package/dist/cjs/hooks/useMarkViewDescription.js +1 -4
- package/dist/cjs/hooks/useNodeViewDescription.js +1 -22
- package/dist/cjs/plugins/beforeInputPlugin.js +162 -50
- package/dist/cjs/plugins/reactKeys.js +34 -15
- package/dist/cjs/tiptap/tiptapNodeView.js +10 -9
- package/dist/cjs/viewdesc.js +55 -4
- package/dist/esm/ReactEditorView.js +18 -1
- package/dist/esm/components/ChildNodeViews.js +5 -5
- package/dist/esm/components/CursorWrapper.js +9 -11
- package/dist/esm/components/ProseMirror.js +13 -3
- package/dist/esm/components/TextNodeView.js +56 -52
- package/dist/esm/components/WidgetView.js +3 -1
- package/dist/esm/components/nodes/NodeView.js +38 -5
- package/dist/esm/contexts/CompositionContext.js +4 -0
- package/dist/esm/decorations/viewDecorations.js +1 -6
- package/dist/esm/hooks/useEditor.js +2 -10
- package/dist/esm/hooks/useIsEditorStatic.js +4 -1
- package/dist/esm/hooks/useMarkViewDescription.js +1 -4
- package/dist/esm/hooks/useNodeViewDescription.js +2 -23
- package/dist/esm/plugins/beforeInputPlugin.js +162 -50
- package/dist/esm/plugins/reactKeys.js +34 -15
- package/dist/esm/tiptap/ReactProseMirrorNodeView.js +1 -1
- package/dist/esm/tiptap/TiptapEditorContent.js +8 -1
- package/dist/esm/tiptap/hooks/useIsInReactProseMirror.js +5 -1
- package/dist/esm/tiptap/tiptapNodeView.js +13 -14
- package/dist/esm/viewdesc.js +54 -4
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/ReactEditorView.d.ts +10 -1
- package/dist/types/components/ChildNodeViews.d.ts +2 -2
- package/dist/types/components/CursorWrapper.d.ts +1 -1
- package/dist/types/components/TextNodeView.d.ts +7 -4
- package/dist/types/components/__tests__/ProseMirror.composition.test.d.ts +17 -1
- package/dist/types/components/marks/DefaultMarkView.d.ts +1 -1
- package/dist/types/components/marks/MarkView.d.ts +1 -1
- package/dist/types/components/marks/MarkViewConstructorView.d.ts +1 -1
- package/dist/types/components/marks/ReactMarkView.d.ts +1 -1
- package/dist/types/components/nodes/DefaultNodeView.d.ts +1 -1
- package/dist/types/components/nodes/NodeView.d.ts +3 -1
- package/dist/types/components/nodes/NodeViewConstructorView.d.ts +1 -1
- package/dist/types/components/nodes/ReactNodeView.d.ts +1 -1
- package/dist/types/contexts/ChildDescriptionsContext.d.ts +3 -2
- package/dist/types/contexts/CompositionContext.d.ts +4 -0
- package/dist/types/decorations/viewDecorations.d.ts +2 -2
- package/dist/types/hooks/useEditor.d.ts +3 -4
- package/dist/types/hooks/useIsEditorStatic.d.ts +4 -0
- package/dist/types/hooks/useReactKeys.d.ts +2 -5
- package/dist/types/plugins/beforeInputPlugin.d.ts +1 -2
- package/dist/types/plugins/reactKeys.d.ts +10 -9
- package/dist/types/props.d.ts +225 -225
- package/dist/types/tiptap/ReactProseMirrorNodeView.d.ts +1 -1
- package/dist/types/tiptap/TiptapEditorContent.d.ts +10 -1
- package/dist/types/tiptap/hooks/useIsInReactProseMirror.d.ts +5 -0
- package/dist/types/tiptap/tiptapNodeView.d.ts +5 -6
- package/dist/types/viewdesc.d.ts +5 -3
- package/package.json +22 -6
- package/dist/cjs/plugins/componentEventListeners.js +0 -28
- package/dist/cjs/plugins/componentEventListenersPlugin.js +0 -35
- package/dist/cjs/tiptap/utils/ssrJSDOMPatch.js +0 -59
- package/dist/esm/plugins/componentEventListeners.js +0 -18
- package/dist/esm/plugins/componentEventListenersPlugin.js +0 -25
- package/dist/esm/tiptap/utils/ssrJSDOMPatch.js +0 -56
- package/dist/types/plugins/componentEventListeners.d.ts +0 -3
- package/dist/types/plugins/componentEventListenersPlugin.d.ts +0 -4
- package/dist/types/tiptap/utils/ssrJSDOMPatch.d.ts +0 -1
|
@@ -2,7 +2,7 @@ import { Editor, NodeView, NodeViewRendererOptions, NodeViewRendererProps } from
|
|
|
2
2
|
/**
|
|
3
3
|
* Subclass of Tiptap's NodeView to be used in tiptapNodeView.
|
|
4
4
|
*
|
|
5
|
-
* Allows us to pass in an existing dom and
|
|
5
|
+
* Allows us to pass in an existing dom and contentDOM from React ProseMirror's
|
|
6
6
|
* ViewDesc, so that we can call Tiptap's default stopEvent and ignoreMutation
|
|
7
7
|
* methods
|
|
8
8
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Editor } from "@tiptap/core";
|
|
2
2
|
import { ReactRenderer } from "@tiptap/react";
|
|
3
|
-
import React, { ForwardedRef, HTMLProps, ReactPortal } from "react";
|
|
3
|
+
import React, { ElementType, ForwardedRef, HTMLProps, ReactPortal } from "react";
|
|
4
4
|
export type ContentComponent = {
|
|
5
5
|
setRenderer(id: string, renderer: ReactRenderer): void;
|
|
6
6
|
removeRenderer(id: string): void;
|
|
@@ -14,6 +14,15 @@ export interface EditorContentProps extends HTMLProps<HTMLDivElement> {
|
|
|
14
14
|
}
|
|
15
15
|
interface Props extends Omit<HTMLProps<HTMLElement>, "as"> {
|
|
16
16
|
editor: Editor;
|
|
17
|
+
as?: ElementType;
|
|
17
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Renders the actual editable ProseMirror document.
|
|
21
|
+
*
|
|
22
|
+
* This **must** be passed as a child to the `TiptapEditorView`
|
|
23
|
+
* component. It may be wrapped in other components, and other
|
|
24
|
+
* childern may be passed before or after. It must be passed the
|
|
25
|
+
* same `editor` as is passed to the `TiptapEditorView`.
|
|
26
|
+
*/
|
|
18
27
|
export declare function TiptapEditorContent({ editor: editorProp, ...props }: Props): React.JSX.Element;
|
|
19
28
|
export {};
|
|
@@ -20,6 +20,7 @@ export interface TiptapNodeViewProps {
|
|
|
20
20
|
}) => boolean) | null;
|
|
21
21
|
ignoreMutation?: ((props: {
|
|
22
22
|
mutation: ViewMutationRecord;
|
|
23
|
+
defaultIgnoreMutation: (mutation: ViewMutationRecord) => boolean;
|
|
23
24
|
}) => boolean) | null;
|
|
24
25
|
contentDOMElementTag?: ElementType | undefined;
|
|
25
26
|
}
|
|
@@ -36,11 +37,9 @@ export interface TiptapNodeViewProps {
|
|
|
36
37
|
* codeBlock: nodeView({
|
|
37
38
|
* component: function CodeBlock(nodeViewProps) {
|
|
38
39
|
* return (
|
|
39
|
-
* <
|
|
40
|
-
* <
|
|
41
|
-
*
|
|
42
|
-
* </pre>
|
|
43
|
-
* </AnnotatableNodeViewWrapper>
|
|
40
|
+
* <pre>
|
|
41
|
+
* <NodeViewContent as="code" />
|
|
42
|
+
* </pre>
|
|
44
43
|
* )
|
|
45
44
|
* },
|
|
46
45
|
* extension: CodeBlockExtension,
|
|
@@ -48,4 +47,4 @@ export interface TiptapNodeViewProps {
|
|
|
48
47
|
* }
|
|
49
48
|
* ```
|
|
50
49
|
*/
|
|
51
|
-
export declare function tiptapNodeView({ component: WrappedComponent, extension, as, className, attrs, contentDOMElementTag: InnerTag, stopEvent, ignoreMutation, }: TiptapNodeViewProps): React.MemoExoticComponent<React.ForwardRefExoticComponent<Omit<NodeViewComponentProps
|
|
50
|
+
export declare function tiptapNodeView({ component: WrappedComponent, extension, as, className, attrs, contentDOMElementTag: InnerTag, stopEvent, ignoreMutation, }: TiptapNodeViewProps): React.MemoExoticComponent<React.ForwardRefExoticComponent<Omit<NodeViewComponentProps, "ref"> & React.RefAttributes<HTMLElement | null>>>;
|
package/dist/types/viewdesc.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Mark, Node, TagParseRule } from "prosemirror-model";
|
|
1
|
+
import { Fragment, Mark, Node, TagParseRule } from "prosemirror-model";
|
|
2
2
|
import { Decoration, DecorationSource, EditorView, NodeView } from "prosemirror-view";
|
|
3
3
|
import { ReactEditorView } from "./ReactEditorView.js";
|
|
4
4
|
import { DOMNode } from "./dom.js";
|
|
@@ -119,7 +119,7 @@ export declare class NodeViewDesc extends ViewDesc {
|
|
|
119
119
|
parseRule(): Omit<TagParseRule, "tag"> | null;
|
|
120
120
|
matchesNode(node: Node, outerDeco: readonly Decoration[], innerDeco: DecorationSource): boolean;
|
|
121
121
|
get size(): number;
|
|
122
|
-
get border():
|
|
122
|
+
get border(): 0 | 1;
|
|
123
123
|
updateChildren(_view: EditorView, _pos: number): void;
|
|
124
124
|
update(node: Node, outerDeco: readonly Decoration[], innerDeco: DecorationSource, view: EditorView): boolean;
|
|
125
125
|
updateInner(node: Node, outerDeco: readonly Decoration[], innerDeco: DecorationSource, view: EditorView): void;
|
|
@@ -133,7 +133,7 @@ export declare class TextViewDesc extends NodeViewDesc {
|
|
|
133
133
|
parseRule(): {
|
|
134
134
|
skip: any;
|
|
135
135
|
};
|
|
136
|
-
update(
|
|
136
|
+
update(node: Node, outerDeco: readonly Decoration[], _innerDeco: DecorationSource, _view: ReactEditorView): boolean;
|
|
137
137
|
inParent(): boolean;
|
|
138
138
|
domFromPos(pos: number): {
|
|
139
139
|
node: globalThis.Node;
|
|
@@ -143,6 +143,7 @@ export declare class TextViewDesc extends NodeViewDesc {
|
|
|
143
143
|
markDirty(from: number, to: number): void;
|
|
144
144
|
get domAtom(): boolean;
|
|
145
145
|
isText(text: string): boolean;
|
|
146
|
+
ignoreMutation(mutation: ViewMutationRecord): boolean;
|
|
146
147
|
}
|
|
147
148
|
export declare class TrailingHackViewDesc extends ViewDesc {
|
|
148
149
|
parseRule(): {
|
|
@@ -172,4 +173,5 @@ export declare class ReactNodeViewDesc extends CustomNodeViewDesc {
|
|
|
172
173
|
destroy(): void;
|
|
173
174
|
}
|
|
174
175
|
export declare function sameOuterDeco(a: readonly Decoration[], b: readonly Decoration[]): boolean;
|
|
176
|
+
export declare function findTextInFragment(frag: Fragment, text: string, from: number, to: number): number;
|
|
175
177
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@handlewithcare/react-prosemirror",
|
|
3
|
-
"version": "3.1.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/cjs/index.js",
|
|
@@ -63,6 +63,9 @@
|
|
|
63
63
|
"@testing-library/dom": "^10.4.0",
|
|
64
64
|
"@testing-library/react": "^16.3.0",
|
|
65
65
|
"@testing-library/user-event": "^14.6.1",
|
|
66
|
+
"@tiptap/core": "^3.15.3",
|
|
67
|
+
"@tiptap/pm": "^3.15.3",
|
|
68
|
+
"@tiptap/react": "^3.15.3",
|
|
66
69
|
"@types/css-tree": "^2.3.10",
|
|
67
70
|
"@types/jest": "^27.0.0",
|
|
68
71
|
"@types/react": "^18.2.0",
|
|
@@ -71,6 +74,7 @@
|
|
|
71
74
|
"@typescript-eslint/eslint-plugin": "^5.51.0",
|
|
72
75
|
"@typescript-eslint/parser": "^5.51.0",
|
|
73
76
|
"@uiw/react-codemirror": "^4.23.7",
|
|
77
|
+
"@vitejs/plugin-basic-ssl": "^2.3.0",
|
|
74
78
|
"@vitejs/plugin-react": "^4.3.1",
|
|
75
79
|
"@wdio/browser-runner": "^9.18.1",
|
|
76
80
|
"@wdio/cli": "^9.18.1",
|
|
@@ -104,20 +108,21 @@
|
|
|
104
108
|
"prosemirror-history": "^1.5.0",
|
|
105
109
|
"prosemirror-inputrules": "^1.5.1",
|
|
106
110
|
"prosemirror-keymap": "^1.2.3",
|
|
107
|
-
"prosemirror-model": "^1.25.
|
|
111
|
+
"prosemirror-model": "^1.25.7",
|
|
108
112
|
"prosemirror-schema-list": "^1.5.1",
|
|
109
113
|
"prosemirror-state": "^1.4.4",
|
|
110
114
|
"prosemirror-tables": "^1.8.5",
|
|
111
115
|
"prosemirror-test-builder": "^1.1.1",
|
|
112
116
|
"prosemirror-transform": "^1.12.0",
|
|
113
117
|
"prosemirror-view": "1.41.7",
|
|
118
|
+
"puppeteer-core": "^25.0.4",
|
|
114
119
|
"react": "^18.2.0",
|
|
115
120
|
"react-dom": "^18.2.0",
|
|
116
121
|
"react-reconciler": "^0.29.0",
|
|
117
122
|
"remark-parse": "^11.0.0",
|
|
118
123
|
"rimraf": "^3.0.2",
|
|
119
124
|
"tsx": "^4.20.3",
|
|
120
|
-
"typescript": "^
|
|
125
|
+
"typescript": "^6.0.3",
|
|
121
126
|
"unified": "^11.0.5",
|
|
122
127
|
"vite": "^5.4.5",
|
|
123
128
|
"webdriver": "^9.18.0",
|
|
@@ -127,6 +132,9 @@
|
|
|
127
132
|
"prosemirror-view": "1.41.7"
|
|
128
133
|
},
|
|
129
134
|
"peerDependencies": {
|
|
135
|
+
"@tiptap/core": "^3.15.3",
|
|
136
|
+
"@tiptap/pm": "^3.15.3",
|
|
137
|
+
"@tiptap/react": "^3.15.3",
|
|
130
138
|
"prosemirror-model": "^1.0.0",
|
|
131
139
|
"prosemirror-state": "^1.0.0",
|
|
132
140
|
"prosemirror-view": "1.41.7",
|
|
@@ -138,10 +146,18 @@
|
|
|
138
146
|
"engines": {
|
|
139
147
|
"node": ">=16.9"
|
|
140
148
|
},
|
|
149
|
+
"peerDependenciesMeta": {
|
|
150
|
+
"@tiptap/core": {
|
|
151
|
+
"optional": true
|
|
152
|
+
},
|
|
153
|
+
"@tiptap/pm": {
|
|
154
|
+
"optional": true
|
|
155
|
+
},
|
|
156
|
+
"@tiptap/react": {
|
|
157
|
+
"optional": true
|
|
158
|
+
}
|
|
159
|
+
},
|
|
141
160
|
"dependencies": {
|
|
142
|
-
"@tiptap/core": "^3.15.3",
|
|
143
|
-
"@tiptap/pm": "^3.15.3",
|
|
144
|
-
"@tiptap/react": "^3.15.3",
|
|
145
161
|
"classnames": "^2.5.1"
|
|
146
162
|
},
|
|
147
163
|
"publishConfig": {
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "componentEventListeners", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return componentEventListeners;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _reactdom = require("react-dom");
|
|
12
|
-
function componentEventListeners(eventHandlerRegistry) {
|
|
13
|
-
const domEventHandlers = {};
|
|
14
|
-
for (const [eventType, handlers] of eventHandlerRegistry.entries()){
|
|
15
|
-
function handleEvent(view, event) {
|
|
16
|
-
for (const handler of handlers){
|
|
17
|
-
let handled = false;
|
|
18
|
-
(0, _reactdom.unstable_batchedUpdates)(()=>{
|
|
19
|
-
handled = !!handler(view, event);
|
|
20
|
-
});
|
|
21
|
-
if (handled || event.defaultPrevented) return true;
|
|
22
|
-
}
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
domEventHandlers[eventType] = handleEvent;
|
|
26
|
-
}
|
|
27
|
-
return domEventHandlers;
|
|
28
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/* Copyright (c) The New York Times Company */ "use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "createComponentEventListenersPlugin", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return createComponentEventListenersPlugin;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _prosemirrorstate = require("prosemirror-state");
|
|
12
|
-
const _reactdom = require("react-dom");
|
|
13
|
-
function createComponentEventListenersPlugin(eventHandlerRegistry) {
|
|
14
|
-
const domEventHandlers = {};
|
|
15
|
-
for (const [eventType, handlers] of eventHandlerRegistry.entries()){
|
|
16
|
-
function handleEvent(view, event) {
|
|
17
|
-
for (const handler of handlers){
|
|
18
|
-
let handled = false;
|
|
19
|
-
(0, _reactdom.unstable_batchedUpdates)(()=>{
|
|
20
|
-
handled = !!handler.call(this, view, event);
|
|
21
|
-
});
|
|
22
|
-
if (handled || event.defaultPrevented) return true;
|
|
23
|
-
}
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
domEventHandlers[eventType] = handleEvent;
|
|
27
|
-
}
|
|
28
|
-
const plugin = new _prosemirrorstate.Plugin({
|
|
29
|
-
key: new _prosemirrorstate.PluginKey("componentEventListeners"),
|
|
30
|
-
props: {
|
|
31
|
-
handleDOMEvents: domEventHandlers
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
return plugin;
|
|
35
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is used to patch global DOM variables in a NodeJS environment.
|
|
3
|
-
* This is needed for ProseMirror to work in a NodeJS environment.
|
|
4
|
-
*/ "use strict";
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
if (typeof window === "undefined") {
|
|
9
|
-
// Make sure to import JSDOM only in a NodeJS environment.
|
|
10
|
-
// The magic comments prevent bundlers from statically analyzing this require:
|
|
11
|
-
// - webpackIgnore: true → webpack / Next.js
|
|
12
|
-
// - @vite-ignore → Vite
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
14
|
-
const jsdom = require(/* webpackIgnore: true */ /* @vite-ignore */ "jsdom");
|
|
15
|
-
const html = `
|
|
16
|
-
<!DOCTYPE html>
|
|
17
|
-
<html>
|
|
18
|
-
<head>
|
|
19
|
-
<title>Testing</title>
|
|
20
|
-
</head>
|
|
21
|
-
<body></body>
|
|
22
|
-
</html>
|
|
23
|
-
`;
|
|
24
|
-
const { window: window1 } = new jsdom.JSDOM(html);
|
|
25
|
-
global.window = window1;
|
|
26
|
-
global.document = window1.document;
|
|
27
|
-
// Use Object.defineProperty for navigator since it's read-only in Node.js 22+
|
|
28
|
-
Object.defineProperty(global, "navigator", {
|
|
29
|
-
value: window1.navigator,
|
|
30
|
-
writable: true,
|
|
31
|
-
configurable: true
|
|
32
|
-
});
|
|
33
|
-
global.innerHeight = 0;
|
|
34
|
-
global.SVGElement = window1.SVGElement;
|
|
35
|
-
// @ts-expect-error stub getSelection for SSR
|
|
36
|
-
document.getSelection = ()=>({});
|
|
37
|
-
document.createRange = ()=>({
|
|
38
|
-
setStart () {},
|
|
39
|
-
setEnd () {},
|
|
40
|
-
// @ts-expect-error stub getBoundingClientRect for SSR
|
|
41
|
-
getClientRects () {
|
|
42
|
-
return {
|
|
43
|
-
left: 0,
|
|
44
|
-
top: 0,
|
|
45
|
-
right: 0,
|
|
46
|
-
bottom: 0
|
|
47
|
-
};
|
|
48
|
-
},
|
|
49
|
-
// @ts-expect-error stub getBoundingClientRect for SSR
|
|
50
|
-
getBoundingClientRect () {
|
|
51
|
-
return {
|
|
52
|
-
left: 0,
|
|
53
|
-
top: 0,
|
|
54
|
-
right: 0,
|
|
55
|
-
bottom: 0
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { unstable_batchedUpdates as batch } from "react-dom";
|
|
2
|
-
export function componentEventListeners(eventHandlerRegistry) {
|
|
3
|
-
const domEventHandlers = {};
|
|
4
|
-
for (const [eventType, handlers] of eventHandlerRegistry.entries()){
|
|
5
|
-
function handleEvent(view, event) {
|
|
6
|
-
for (const handler of handlers){
|
|
7
|
-
let handled = false;
|
|
8
|
-
batch(()=>{
|
|
9
|
-
handled = !!handler(view, event);
|
|
10
|
-
});
|
|
11
|
-
if (handled || event.defaultPrevented) return true;
|
|
12
|
-
}
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
domEventHandlers[eventType] = handleEvent;
|
|
16
|
-
}
|
|
17
|
-
return domEventHandlers;
|
|
18
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/* Copyright (c) The New York Times Company */ import { Plugin, PluginKey } from "prosemirror-state";
|
|
2
|
-
import { unstable_batchedUpdates as batch } from "react-dom";
|
|
3
|
-
export function createComponentEventListenersPlugin(eventHandlerRegistry) {
|
|
4
|
-
const domEventHandlers = {};
|
|
5
|
-
for (const [eventType, handlers] of eventHandlerRegistry.entries()){
|
|
6
|
-
function handleEvent(view, event) {
|
|
7
|
-
for (const handler of handlers){
|
|
8
|
-
let handled = false;
|
|
9
|
-
batch(()=>{
|
|
10
|
-
handled = !!handler.call(this, view, event);
|
|
11
|
-
});
|
|
12
|
-
if (handled || event.defaultPrevented) return true;
|
|
13
|
-
}
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
domEventHandlers[eventType] = handleEvent;
|
|
17
|
-
}
|
|
18
|
-
const plugin = new Plugin({
|
|
19
|
-
key: new PluginKey("componentEventListeners"),
|
|
20
|
-
props: {
|
|
21
|
-
handleDOMEvents: domEventHandlers
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
return plugin;
|
|
25
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is used to patch global DOM variables in a NodeJS environment.
|
|
3
|
-
* This is needed for ProseMirror to work in a NodeJS environment.
|
|
4
|
-
*/ if (typeof window === "undefined") {
|
|
5
|
-
// Make sure to import JSDOM only in a NodeJS environment.
|
|
6
|
-
// The magic comments prevent bundlers from statically analyzing this require:
|
|
7
|
-
// - webpackIgnore: true → webpack / Next.js
|
|
8
|
-
// - @vite-ignore → Vite
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
10
|
-
const jsdom = require(/* webpackIgnore: true */ /* @vite-ignore */ "jsdom");
|
|
11
|
-
const html = `
|
|
12
|
-
<!DOCTYPE html>
|
|
13
|
-
<html>
|
|
14
|
-
<head>
|
|
15
|
-
<title>Testing</title>
|
|
16
|
-
</head>
|
|
17
|
-
<body></body>
|
|
18
|
-
</html>
|
|
19
|
-
`;
|
|
20
|
-
const { window: window1 } = new jsdom.JSDOM(html);
|
|
21
|
-
global.window = window1;
|
|
22
|
-
global.document = window1.document;
|
|
23
|
-
// Use Object.defineProperty for navigator since it's read-only in Node.js 22+
|
|
24
|
-
Object.defineProperty(global, "navigator", {
|
|
25
|
-
value: window1.navigator,
|
|
26
|
-
writable: true,
|
|
27
|
-
configurable: true
|
|
28
|
-
});
|
|
29
|
-
global.innerHeight = 0;
|
|
30
|
-
global.SVGElement = window1.SVGElement;
|
|
31
|
-
// @ts-expect-error stub getSelection for SSR
|
|
32
|
-
document.getSelection = ()=>({});
|
|
33
|
-
document.createRange = ()=>({
|
|
34
|
-
setStart () {},
|
|
35
|
-
setEnd () {},
|
|
36
|
-
// @ts-expect-error stub getBoundingClientRect for SSR
|
|
37
|
-
getClientRects () {
|
|
38
|
-
return {
|
|
39
|
-
left: 0,
|
|
40
|
-
top: 0,
|
|
41
|
-
right: 0,
|
|
42
|
-
bottom: 0
|
|
43
|
-
};
|
|
44
|
-
},
|
|
45
|
-
// @ts-expect-error stub getBoundingClientRect for SSR
|
|
46
|
-
getBoundingClientRect () {
|
|
47
|
-
return {
|
|
48
|
-
left: 0,
|
|
49
|
-
top: 0,
|
|
50
|
-
right: 0,
|
|
51
|
-
bottom: 0
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
export { };
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { DOMEventMap, EditorView } from "prosemirror-view";
|
|
2
|
-
export type EventHandler<EventType extends keyof DOMEventMap = keyof DOMEventMap> = (view: EditorView, event: DOMEventMap[EventType]) => boolean | void;
|
|
3
|
-
export declare function componentEventListeners(eventHandlerRegistry: Map<keyof DOMEventMap, Iterable<EventHandler>>): Record<keyof DOMEventMap, EventHandler<keyof DOMEventMap>>;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { Plugin } from "prosemirror-state";
|
|
2
|
-
import { DOMEventMap, EditorView } from "prosemirror-view";
|
|
3
|
-
export type EventHandler<EventType extends keyof DOMEventMap = keyof DOMEventMap> = (this: Plugin, view: EditorView, event: DOMEventMap[EventType]) => boolean | void;
|
|
4
|
-
export declare function createComponentEventListenersPlugin(eventHandlerRegistry: Map<keyof DOMEventMap, Set<EventHandler>>): Plugin<any>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|