@handlewithcare/react-prosemirror 3.1.0-tiptap.49 → 3.1.0-tiptap.51
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 +2 -0
- package/dist/cjs/components/ChildNodeViews.js +14 -9
- package/dist/cjs/components/CursorWrapper.js +6 -9
- package/dist/cjs/components/TextNodeView.js +109 -38
- package/dist/cjs/components/TrailingHackView.js +29 -0
- package/dist/cjs/hooks/useComponentEventListeners.js +46 -5
- package/dist/cjs/hooks/useEditor.js +3 -6
- package/dist/cjs/hooks/useNodeViewDescription.js +37 -16
- package/dist/cjs/plugins/beforeInputPlugin.js +41 -43
- package/dist/cjs/viewdesc.js +10 -3
- package/dist/esm/ReactEditorView.js +2 -0
- package/dist/esm/components/ChildNodeViews.js +14 -9
- package/dist/esm/components/CursorWrapper.js +7 -10
- package/dist/esm/components/TextNodeView.js +109 -38
- package/dist/esm/components/TrailingHackView.js +30 -1
- package/dist/esm/hooks/useComponentEventListeners.js +53 -12
- package/dist/esm/hooks/useEditor.js +3 -6
- package/dist/esm/hooks/useNodeViewDescription.js +38 -17
- package/dist/esm/plugins/beforeInputPlugin.js +41 -43
- package/dist/esm/viewdesc.js +10 -3
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/ReactEditorView.d.ts +4 -0
- package/dist/types/components/TextNodeView.d.ts +14 -4
- package/dist/types/components/TrailingHackView.d.ts +1 -1
- package/dist/types/constants.d.ts +1 -1
- package/dist/types/contexts/EditorContext.d.ts +1 -1
- package/dist/types/hooks/useComponentEventListeners.d.ts +11 -10
- package/dist/types/hooks/useEditor.d.ts +2 -2
- package/dist/types/hooks/useEditorEventListener.d.ts +1 -1
- package/dist/types/props.d.ts +26 -26
- package/dist/types/viewdesc.d.ts +2 -2
- package/package.json +2 -1
- package/dist/cjs/tiptap/utils/ssrJSDOMPatch.js +0 -59
- package/dist/esm/tiptap/utils/ssrJSDOMPatch.js +0 -56
- package/dist/types/tiptap/utils/ssrJSDOMPatch.d.ts +0 -1
|
@@ -11,7 +11,10 @@ interface DOMObserver {
|
|
|
11
11
|
onSelectionChange(): void;
|
|
12
12
|
}
|
|
13
13
|
interface InputState {
|
|
14
|
+
composing: boolean;
|
|
14
15
|
compositionID: number;
|
|
16
|
+
compositionNode: Text | null;
|
|
17
|
+
compositionEndedAt: number;
|
|
15
18
|
compositionNodes: ViewDesc[];
|
|
16
19
|
compositionPendingChanges: number;
|
|
17
20
|
hideSelectionGuard: (() => void) | null;
|
|
@@ -58,6 +61,7 @@ export declare class ReactEditorView extends EditorView implements AbstractEdito
|
|
|
58
61
|
private nextProps;
|
|
59
62
|
private prevState;
|
|
60
63
|
private _destroyed;
|
|
64
|
+
deferPendingEffects: boolean;
|
|
61
65
|
constructor(place: {
|
|
62
66
|
mount: HTMLElement;
|
|
63
67
|
}, props: DirectEditorProps);
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Node } from "prosemirror-model";
|
|
2
|
-
import { Decoration } from "prosemirror-view";
|
|
2
|
+
import { DOMEventMap, Decoration } from "prosemirror-view";
|
|
3
3
|
import { Component, MutableRefObject } from "react";
|
|
4
4
|
import { AbstractEditorView } from "../AbstractEditorView.js";
|
|
5
|
-
import {
|
|
5
|
+
import { EventHandler } from "../hooks/useComponentEventListeners.js";
|
|
6
|
+
import { CompositionViewDesc, TextViewDesc, ViewDesc } from "../viewdesc.js";
|
|
6
7
|
type Props = {
|
|
7
8
|
view: AbstractEditorView;
|
|
8
9
|
node: Node;
|
|
@@ -10,10 +11,19 @@ type Props = {
|
|
|
10
11
|
siblingsRef: MutableRefObject<ViewDesc[]>;
|
|
11
12
|
parentRef: MutableRefObject<ViewDesc | undefined>;
|
|
12
13
|
decorations: readonly Decoration[];
|
|
14
|
+
registerEventListener<EventType extends keyof DOMEventMap>(eventType: EventType, handler: EventHandler<EventType>): void;
|
|
15
|
+
unregisterEventListener<EventType extends keyof DOMEventMap>(eventType: EventType, handler: EventHandler<EventType>): void;
|
|
13
16
|
};
|
|
14
17
|
export declare class TextNodeView extends Component<Props> {
|
|
15
|
-
|
|
16
|
-
|
|
18
|
+
viewDescRef: null | TextViewDesc | CompositionViewDesc;
|
|
19
|
+
renderRef: null | JSX.Element;
|
|
20
|
+
wasProtecting: boolean;
|
|
21
|
+
containsCompositionNodeText: boolean;
|
|
22
|
+
shouldProtect(props: Props): boolean;
|
|
23
|
+
handleCompositionEnd: () => void;
|
|
24
|
+
create(): TextViewDesc | CompositionViewDesc | null;
|
|
25
|
+
update(): boolean;
|
|
26
|
+
destroy(): void;
|
|
17
27
|
updateEffect(): void;
|
|
18
28
|
shouldComponentUpdate(nextProps: Props): boolean;
|
|
19
29
|
componentDidMount(): void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Schema } from "prosemirror-model";
|
|
2
2
|
import { EditorState } from "prosemirror-state";
|
|
3
|
-
export declare const EMPTY_SCHEMA: Schema<"
|
|
3
|
+
export declare const EMPTY_SCHEMA: Schema<"text" | "doc", any>;
|
|
4
4
|
export declare const EMPTY_STATE: EditorState;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { DOMEventMap } from "prosemirror-view";
|
|
2
2
|
import { MutableRefObject } from "react";
|
|
3
3
|
import { AbstractEditorView } from "../AbstractEditorView.js";
|
|
4
|
-
import type { EventHandler } from "../
|
|
4
|
+
import type { EventHandler } from "../hooks/useComponentEventListeners.js";
|
|
5
5
|
export interface EditorContextValue {
|
|
6
6
|
view: AbstractEditorView;
|
|
7
7
|
flushSyncRef: MutableRefObject<boolean>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { DOMEventMap } from "prosemirror-view";
|
|
2
|
-
|
|
1
|
+
import type { DOMEventMap, EditorView } from "prosemirror-view";
|
|
2
|
+
export type EventHandler<EventType extends keyof DOMEventMap = keyof DOMEventMap> = (view: EditorView, event: DOMEventMap[EventType]) => boolean | void;
|
|
3
|
+
export type HandleDOMEvents = Record<keyof DOMEventMap, EventHandler | undefined>;
|
|
3
4
|
/**
|
|
4
5
|
* Produces a plugin that can be used with ProseMirror to handle DOM
|
|
5
6
|
* events at the EditorView.dom element.
|
|
@@ -14,20 +15,20 @@ import { EventHandler } from "../plugins/componentEventListeners.js";
|
|
|
14
15
|
* @privateRemarks
|
|
15
16
|
*
|
|
16
17
|
* This hook uses a combination of mutable and immutable updates to give
|
|
17
|
-
* us precise control over when we re-create the
|
|
18
|
+
* us precise control over when we re-create the event listeners.
|
|
18
19
|
*
|
|
19
|
-
* The
|
|
20
|
+
* The hook has a mutable reference to the set of handlers for each
|
|
20
21
|
* event type, but the set of event types is static. This means that we
|
|
21
|
-
* need to produce a new
|
|
22
|
-
* registered. We avoid producing a new
|
|
23
|
-
* scenario to avoid the performance overhead of
|
|
24
|
-
* in the EditorView.
|
|
22
|
+
* need to produce a new handleDOMEVents record whenever a new event type is
|
|
23
|
+
* registered. We avoid producing a new record in any other
|
|
24
|
+
* scenario to avoid the performance overhead of re-registering the event
|
|
25
|
+
* listeners in the EditorView.
|
|
25
26
|
*
|
|
26
27
|
* To accomplish this, we shallowly clone the registry whenever a new event
|
|
27
28
|
* type is registered.
|
|
28
29
|
*/
|
|
29
|
-
export declare function useComponentEventListeners(): {
|
|
30
|
+
export declare function useComponentEventListeners(existingHandlers: HandleDOMEvents | undefined): {
|
|
30
31
|
registerEventListener: (eventType: keyof DOMEventMap, handler: EventHandler) => void;
|
|
31
32
|
unregisterEventListener: (eventType: keyof DOMEventMap, handler: EventHandler) => void;
|
|
32
|
-
|
|
33
|
+
handleDOMEvents: HandleDOMEvents;
|
|
33
34
|
};
|
|
@@ -21,8 +21,8 @@ export declare function useEditor<T extends HTMLElement = HTMLElement>(mount: T
|
|
|
21
21
|
editor: {
|
|
22
22
|
view: AbstractEditorView;
|
|
23
23
|
flushSyncRef: import("react").MutableRefObject<boolean>;
|
|
24
|
-
registerEventListener: (eventType: keyof import("prosemirror-view").DOMEventMap, handler: import("
|
|
25
|
-
unregisterEventListener: (eventType: keyof import("prosemirror-view").DOMEventMap, handler: import("
|
|
24
|
+
registerEventListener: (eventType: keyof import("prosemirror-view").DOMEventMap, handler: import("./useComponentEventListeners.js").EventHandler<keyof import("prosemirror-view").DOMEventMap>) => void;
|
|
25
|
+
unregisterEventListener: (eventType: keyof import("prosemirror-view").DOMEventMap, handler: import("./useComponentEventListeners.js").EventHandler<keyof import("prosemirror-view").DOMEventMap>) => void;
|
|
26
26
|
isStatic: boolean;
|
|
27
27
|
};
|
|
28
28
|
cursorWrapper: Decoration | null;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { DOMEventMap } from "prosemirror-view";
|
|
2
|
-
import type { EventHandler } from "
|
|
2
|
+
import type { EventHandler } from "./useComponentEventListeners.js";
|
|
3
3
|
/**
|
|
4
4
|
* Attaches an event listener at the `EditorView`'s DOM node. See
|
|
5
5
|
* [the ProseMirror docs](https://prosemirror.net/docs/ref/#view.EditorProps.handleDOMEvents)
|
package/dist/types/props.d.ts
CHANGED
|
@@ -904,19 +904,19 @@ export declare function mergeReactProps(a: HTMLProps<HTMLElement>, b: HTMLProps<
|
|
|
904
904
|
suppressContentEditableWarning?: boolean | undefined;
|
|
905
905
|
suppressHydrationWarning?: boolean | undefined;
|
|
906
906
|
accessKey?: string | undefined;
|
|
907
|
-
autoCapitalize?: "
|
|
907
|
+
autoCapitalize?: "none" | (string & {}) | "off" | "on" | "sentences" | "words" | "characters" | undefined;
|
|
908
908
|
autoFocus?: boolean | undefined;
|
|
909
|
-
contentEditable?: (boolean | "
|
|
909
|
+
contentEditable?: (boolean | "true" | "false") | "inherit" | "plaintext-only" | undefined;
|
|
910
910
|
contextMenu?: string | undefined;
|
|
911
911
|
dir?: string | undefined;
|
|
912
|
-
draggable?: (boolean | "
|
|
913
|
-
enterKeyHint?: "enter" | "done" | "go" | "next" | "previous" | "
|
|
912
|
+
draggable?: (boolean | "true" | "false") | undefined;
|
|
913
|
+
enterKeyHint?: "search" | "enter" | "done" | "go" | "next" | "previous" | "send" | undefined;
|
|
914
914
|
hidden?: boolean | undefined;
|
|
915
915
|
id?: string | undefined;
|
|
916
916
|
lang?: string | undefined;
|
|
917
917
|
nonce?: string | undefined;
|
|
918
918
|
slot?: string | undefined;
|
|
919
|
-
spellCheck?: (boolean | "
|
|
919
|
+
spellCheck?: (boolean | "true" | "false") | undefined;
|
|
920
920
|
tabIndex?: number | undefined;
|
|
921
921
|
title?: string | undefined;
|
|
922
922
|
translate?: "yes" | "no" | undefined;
|
|
@@ -944,57 +944,57 @@ 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?: "search" | "text" | "none" | "email" | "tel" | "url" | "numeric" | "decimal" | undefined;
|
|
948
948
|
is?: string | undefined;
|
|
949
949
|
exportparts?: string | undefined;
|
|
950
950
|
part?: string | undefined;
|
|
951
951
|
"aria-activedescendant"?: string | undefined;
|
|
952
|
-
"aria-atomic"?: (boolean | "
|
|
953
|
-
"aria-autocomplete"?: "
|
|
952
|
+
"aria-atomic"?: (boolean | "true" | "false") | undefined;
|
|
953
|
+
"aria-autocomplete"?: "list" | "none" | "both" | "inline" | undefined;
|
|
954
954
|
"aria-braillelabel"?: string | undefined;
|
|
955
955
|
"aria-brailleroledescription"?: string | undefined;
|
|
956
|
-
"aria-busy"?: (boolean | "
|
|
957
|
-
"aria-checked"?: boolean | "
|
|
956
|
+
"aria-busy"?: (boolean | "true" | "false") | undefined;
|
|
957
|
+
"aria-checked"?: boolean | "true" | "false" | "mixed" | undefined;
|
|
958
958
|
"aria-colcount"?: number | undefined;
|
|
959
959
|
"aria-colindex"?: number | undefined;
|
|
960
960
|
"aria-colindextext"?: string | undefined;
|
|
961
961
|
"aria-colspan"?: number | undefined;
|
|
962
962
|
"aria-controls"?: string | undefined;
|
|
963
|
-
"aria-current"?: boolean | "
|
|
963
|
+
"aria-current"?: boolean | "time" | "step" | "date" | "true" | "false" | "page" | "location" | undefined;
|
|
964
964
|
"aria-describedby"?: string | undefined;
|
|
965
965
|
"aria-description"?: string | undefined;
|
|
966
966
|
"aria-details"?: string | undefined;
|
|
967
|
-
"aria-disabled"?: (boolean | "
|
|
968
|
-
"aria-dropeffect"?: "
|
|
967
|
+
"aria-disabled"?: (boolean | "true" | "false") | undefined;
|
|
968
|
+
"aria-dropeffect"?: "copy" | "link" | "none" | "move" | "execute" | "popup" | undefined;
|
|
969
969
|
"aria-errormessage"?: string | undefined;
|
|
970
|
-
"aria-expanded"?: (boolean | "
|
|
970
|
+
"aria-expanded"?: (boolean | "true" | "false") | undefined;
|
|
971
971
|
"aria-flowto"?: string | undefined;
|
|
972
|
-
"aria-grabbed"?: (boolean | "
|
|
973
|
-
"aria-haspopup"?: boolean | "
|
|
974
|
-
"aria-hidden"?: (boolean | "
|
|
975
|
-
"aria-invalid"?: boolean | "
|
|
972
|
+
"aria-grabbed"?: (boolean | "true" | "false") | undefined;
|
|
973
|
+
"aria-haspopup"?: boolean | "dialog" | "menu" | "grid" | "listbox" | "tree" | "true" | "false" | undefined;
|
|
974
|
+
"aria-hidden"?: (boolean | "true" | "false") | undefined;
|
|
975
|
+
"aria-invalid"?: boolean | "true" | "false" | "grammar" | "spelling" | undefined;
|
|
976
976
|
"aria-keyshortcuts"?: string | undefined;
|
|
977
977
|
"aria-label"?: string | undefined;
|
|
978
978
|
"aria-labelledby"?: string | undefined;
|
|
979
979
|
"aria-level"?: number | undefined;
|
|
980
980
|
"aria-live"?: "off" | "assertive" | "polite" | undefined;
|
|
981
|
-
"aria-modal"?: (boolean | "
|
|
982
|
-
"aria-multiline"?: (boolean | "
|
|
983
|
-
"aria-multiselectable"?: (boolean | "
|
|
981
|
+
"aria-modal"?: (boolean | "true" | "false") | undefined;
|
|
982
|
+
"aria-multiline"?: (boolean | "true" | "false") | undefined;
|
|
983
|
+
"aria-multiselectable"?: (boolean | "true" | "false") | undefined;
|
|
984
984
|
"aria-orientation"?: "horizontal" | "vertical" | undefined;
|
|
985
985
|
"aria-owns"?: string | undefined;
|
|
986
986
|
"aria-placeholder"?: string | undefined;
|
|
987
987
|
"aria-posinset"?: number | undefined;
|
|
988
|
-
"aria-pressed"?: boolean | "
|
|
989
|
-
"aria-readonly"?: (boolean | "
|
|
990
|
-
"aria-relevant"?: "text" | "
|
|
991
|
-
"aria-required"?: (boolean | "
|
|
988
|
+
"aria-pressed"?: boolean | "true" | "false" | "mixed" | undefined;
|
|
989
|
+
"aria-readonly"?: (boolean | "true" | "false") | undefined;
|
|
990
|
+
"aria-relevant"?: "text" | "all" | "additions" | "additions removals" | "additions text" | "removals" | "removals additions" | "removals text" | "text additions" | "text removals" | undefined;
|
|
991
|
+
"aria-required"?: (boolean | "true" | "false") | undefined;
|
|
992
992
|
"aria-roledescription"?: string | undefined;
|
|
993
993
|
"aria-rowcount"?: number | undefined;
|
|
994
994
|
"aria-rowindex"?: number | undefined;
|
|
995
995
|
"aria-rowindextext"?: string | undefined;
|
|
996
996
|
"aria-rowspan"?: number | undefined;
|
|
997
|
-
"aria-selected"?: (boolean | "
|
|
997
|
+
"aria-selected"?: (boolean | "true" | "false") | undefined;
|
|
998
998
|
"aria-setsize"?: number | undefined;
|
|
999
999
|
"aria-sort"?: "none" | "ascending" | "descending" | "other" | undefined;
|
|
1000
1000
|
"aria-valuemax"?: number | undefined;
|
package/dist/types/viewdesc.d.ts
CHANGED
|
@@ -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;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@handlewithcare/react-prosemirror",
|
|
3
|
-
"version": "3.1.0-tiptap.
|
|
3
|
+
"version": "3.1.0-tiptap.51",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/cjs/index.js",
|
|
@@ -71,6 +71,7 @@
|
|
|
71
71
|
"@typescript-eslint/eslint-plugin": "^5.51.0",
|
|
72
72
|
"@typescript-eslint/parser": "^5.51.0",
|
|
73
73
|
"@uiw/react-codemirror": "^4.23.7",
|
|
74
|
+
"@vitejs/plugin-basic-ssl": "^2.3.0",
|
|
74
75
|
"@vitejs/plugin-react": "^4.3.1",
|
|
75
76
|
"@wdio/browser-runner": "^9.18.1",
|
|
76
77
|
"@wdio/cli": "^9.18.1",
|
|
@@ -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,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 +0,0 @@
|
|
|
1
|
-
export {};
|