@handlewithcare/react-prosemirror 2.4.12 → 2.5.1

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.
Files changed (149) hide show
  1. package/dist/cjs/AbstractEditorView.js +4 -0
  2. package/dist/cjs/ReactEditorView.js +156 -0
  3. package/dist/cjs/StaticEditorView.js +86 -0
  4. package/dist/cjs/components/ChildNodeViews.js +58 -29
  5. package/dist/cjs/components/CustomNodeView.js +77 -137
  6. package/dist/cjs/{hooks/useNodePos.js → components/DefaultNodeView.js} +24 -26
  7. package/dist/cjs/components/DocNodeView.js +33 -41
  8. package/dist/cjs/components/MarkView.js +1 -2
  9. package/dist/cjs/components/NativeWidgetView.js +2 -3
  10. package/dist/cjs/components/NodeView.js +31 -21
  11. package/dist/cjs/components/ProseMirror.js +25 -17
  12. package/dist/cjs/components/ProseMirrorDoc.js +7 -27
  13. package/dist/cjs/components/ReactNodeView.js +98 -61
  14. package/dist/cjs/components/SeparatorHackView.js +1 -2
  15. package/dist/cjs/components/TextNodeView.js +4 -5
  16. package/dist/cjs/components/TrailingHackView.js +1 -2
  17. package/dist/cjs/components/WidgetView.js +2 -4
  18. package/dist/cjs/constants.js +33 -0
  19. package/dist/cjs/hooks/useEditor.js +33 -229
  20. package/dist/cjs/hooks/useEditorEffect.js +2 -2
  21. package/dist/cjs/hooks/useEditorEventCallback.js +8 -5
  22. package/dist/cjs/hooks/useIgnoreMutation.js +1 -1
  23. package/dist/cjs/hooks/useNodeViewDescriptor.js +123 -80
  24. package/dist/cjs/hooks/useReactKeys.js +1 -1
  25. package/dist/cjs/hooks/useSelectNode.js +9 -7
  26. package/dist/cjs/hooks/useStopEvent.js +1 -1
  27. package/dist/cjs/plugins/beforeInputPlugin.js +12 -0
  28. package/dist/cjs/testing/editorViewTestHelpers.js +0 -2
  29. package/dist/cjs/viewdesc.js +104 -25
  30. package/dist/esm/AbstractEditorView.js +1 -0
  31. package/dist/esm/ReactEditorView.js +156 -0
  32. package/dist/esm/StaticEditorView.js +76 -0
  33. package/dist/esm/components/ChildNodeViews.js +59 -31
  34. package/dist/esm/components/CustomNodeView.js +78 -138
  35. package/dist/esm/components/DefaultNodeView.js +16 -0
  36. package/dist/esm/components/DocNodeView.js +33 -41
  37. package/dist/esm/components/MarkView.js +1 -2
  38. package/dist/esm/components/NativeWidgetView.js +2 -3
  39. package/dist/esm/components/NodeView.js +32 -22
  40. package/dist/esm/components/ProseMirror.js +25 -17
  41. package/dist/esm/components/ProseMirrorDoc.js +7 -28
  42. package/dist/esm/components/ReactNodeView.js +99 -62
  43. package/dist/esm/components/SeparatorHackView.js +1 -2
  44. package/dist/esm/components/TextNodeView.js +4 -5
  45. package/dist/esm/components/TrailingHackView.js +1 -2
  46. package/dist/esm/components/WidgetView.js +2 -4
  47. package/dist/esm/constants.js +15 -0
  48. package/dist/esm/hooks/useEditor.js +29 -218
  49. package/dist/esm/hooks/useEditorEffect.js +2 -2
  50. package/dist/esm/hooks/useEditorEventCallback.js +8 -5
  51. package/dist/esm/hooks/useIgnoreMutation.js +1 -1
  52. package/dist/esm/hooks/useNodeViewDescriptor.js +125 -82
  53. package/dist/esm/hooks/useReactKeys.js +1 -1
  54. package/dist/esm/hooks/useSelectNode.js +9 -7
  55. package/dist/esm/hooks/useStopEvent.js +1 -1
  56. package/dist/esm/plugins/beforeInputPlugin.js +12 -0
  57. package/dist/esm/testing/editorViewTestHelpers.js +0 -2
  58. package/dist/esm/viewdesc.js +94 -18
  59. package/dist/tsconfig.tsbuildinfo +1 -1
  60. package/dist/types/AbstractEditorView.d.ts +27 -0
  61. package/dist/types/ReactEditorView.d.ts +80 -0
  62. package/dist/types/StaticEditorView.d.ts +24 -0
  63. package/dist/types/components/ChildNodeViews.d.ts +2 -2
  64. package/dist/types/components/CustomNodeView.d.ts +3 -3
  65. package/dist/types/components/DefaultNodeView.d.ts +3 -0
  66. package/dist/types/components/DocNodeView.d.ts +9 -17
  67. package/dist/types/components/MarkView.d.ts +2 -2
  68. package/dist/types/components/NativeWidgetView.d.ts +2 -2
  69. package/dist/types/components/NodeView.d.ts +5 -5
  70. package/dist/types/components/NodeViewComponentProps.d.ts +3 -4
  71. package/dist/types/components/ProseMirrorDoc.d.ts +14 -8
  72. package/dist/types/components/ReactNodeView.d.ts +4 -2
  73. package/dist/types/components/SeparatorHackView.d.ts +2 -2
  74. package/dist/types/components/TextNodeView.d.ts +4 -3
  75. package/dist/types/components/TrailingHackView.d.ts +2 -2
  76. package/dist/types/components/WidgetView.d.ts +2 -2
  77. package/dist/types/constants.d.ts +4 -0
  78. package/dist/types/contexts/EditorContext.d.ts +6 -4
  79. package/dist/types/contexts/IgnoreMutationContext.d.ts +2 -1
  80. package/dist/types/contexts/NodeViewContext.d.ts +3 -1
  81. package/dist/types/contexts/SelectNodeContext.d.ts +3 -1
  82. package/dist/types/contexts/StopEventContext.d.ts +2 -1
  83. package/dist/types/decorations/computeDocDeco.d.ts +3 -2
  84. package/dist/types/decorations/viewDecorations.d.ts +3 -2
  85. package/dist/types/hooks/useEditor.d.ts +5 -46
  86. package/dist/types/hooks/useNodeViewDescriptor.d.ts +18 -10
  87. package/dist/types/hooks/useReactKeys.d.ts +1 -1
  88. package/dist/types/hooks/useSelectNode.d.ts +2 -1
  89. package/dist/types/props.d.ts +3 -3
  90. package/dist/types/viewdesc.d.ts +29 -11
  91. package/package.json +7 -3
  92. package/dist/cjs/components/Editor.js +0 -28
  93. package/dist/cjs/components/NodeViews.js +0 -73
  94. package/dist/cjs/components/__tests__/LayoutGroup.test.js +0 -141
  95. package/dist/cjs/components/__tests__/ProseMirror.test.js +0 -255
  96. package/dist/cjs/contexts/NodeViewsContext.js +0 -10
  97. package/dist/cjs/hooks/__tests__/useEditorViewLayoutEffect.test.js +0 -107
  98. package/dist/cjs/hooks/__tests__/useNodeViews.test.js +0 -159
  99. package/dist/cjs/hooks/useClientOnly.js +0 -19
  100. package/dist/cjs/hooks/useEditorView.js +0 -100
  101. package/dist/cjs/hooks/useNodeViews.js +0 -100
  102. package/dist/cjs/nodeViews/createReactNodeViewConstructor.js +0 -244
  103. package/dist/cjs/nodeViews/phrasingContentTags.js +0 -57
  104. package/dist/cjs/plugins/__tests__/react.test.js +0 -139
  105. package/dist/cjs/plugins/react.js +0 -71
  106. package/dist/cjs/selection/SelectionDOMObserver.js +0 -171
  107. package/dist/cjs/selection/hasFocusAndSelection.js +0 -35
  108. package/dist/cjs/selection/selectionFromDOM.js +0 -77
  109. package/dist/cjs/selection/selectionToDOM.js +0 -226
  110. package/dist/cjs/ssr.js +0 -85
  111. package/dist/esm/components/Editor.js +0 -15
  112. package/dist/esm/components/NodeViews.js +0 -26
  113. package/dist/esm/components/__tests__/LayoutGroup.test.js +0 -98
  114. package/dist/esm/components/__tests__/ProseMirror.test.js +0 -207
  115. package/dist/esm/contexts/NodeViewsContext.js +0 -9
  116. package/dist/esm/hooks/__tests__/useEditorViewLayoutEffect.test.js +0 -98
  117. package/dist/esm/hooks/__tests__/useNodeViews.test.js +0 -116
  118. package/dist/esm/hooks/useClientOnly.js +0 -9
  119. package/dist/esm/hooks/useEditorView.js +0 -99
  120. package/dist/esm/hooks/useNodePos.js +0 -16
  121. package/dist/esm/hooks/useNodeViews.js +0 -53
  122. package/dist/esm/nodeViews/createReactNodeViewConstructor.js +0 -214
  123. package/dist/esm/nodeViews/phrasingContentTags.js +0 -49
  124. package/dist/esm/plugins/__tests__/react.test.js +0 -135
  125. package/dist/esm/plugins/react.js +0 -64
  126. package/dist/esm/selection/SelectionDOMObserver.js +0 -161
  127. package/dist/esm/selection/hasFocusAndSelection.js +0 -17
  128. package/dist/esm/selection/selectionFromDOM.js +0 -59
  129. package/dist/esm/selection/selectionToDOM.js +0 -196
  130. package/dist/esm/ssr.js +0 -82
  131. package/dist/types/components/Editor.d.ts +0 -7
  132. package/dist/types/components/NodeViews.d.ts +0 -6
  133. package/dist/types/components/__tests__/LayoutGroup.test.d.ts +0 -1
  134. package/dist/types/contexts/NodeViewsContext.d.ts +0 -19
  135. package/dist/types/hooks/__tests__/useEditorViewLayoutEffect.test.d.ts +0 -1
  136. package/dist/types/hooks/__tests__/useNodeViews.test.d.ts +0 -1
  137. package/dist/types/hooks/useClientOnly.d.ts +0 -1
  138. package/dist/types/hooks/useEditorView.d.ts +0 -23
  139. package/dist/types/hooks/useNodePos.d.ts +0 -9
  140. package/dist/types/hooks/useNodeViews.d.ts +0 -5
  141. package/dist/types/nodeViews/createReactNodeViewConstructor.d.ts +0 -48
  142. package/dist/types/nodeViews/phrasingContentTags.d.ts +0 -1
  143. package/dist/types/plugins/__tests__/react.test.d.ts +0 -1
  144. package/dist/types/plugins/react.d.ts +0 -21
  145. package/dist/types/selection/SelectionDOMObserver.d.ts +0 -33
  146. package/dist/types/selection/hasFocusAndSelection.d.ts +0 -3
  147. package/dist/types/selection/selectionFromDOM.d.ts +0 -4
  148. package/dist/types/selection/selectionToDOM.d.ts +0 -9
  149. package/dist/types/ssr.d.ts +0 -19
@@ -1,59 +0,0 @@
1
- import { NodeSelection, TextSelection } from "prosemirror-state";
2
- import { isOnEdge, selectionCollapsed } from "../dom.js";
3
- export function selectionBetween(view, $anchor, $head, bias) {
4
- return view.someProp("createSelectionBetween", (f)=>f(view, $anchor, $head)) || TextSelection.between($anchor, $head, bias);
5
- }
6
- export function selectionFromDOM(view) {
7
- let origin = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : null;
8
- // @ts-expect-error Internal method
9
- const domSel = view.domSelectionRange(), doc = view.state.doc;
10
- if (!domSel.focusNode) return null;
11
- // @ts-expect-error Internal method
12
- let nearestDesc = view.docView.nearestDesc(domSel.focusNode);
13
- const inWidget = nearestDesc && nearestDesc.size == 0;
14
- // @ts-expect-error Internal method
15
- let head = view.docView.posFromDOM(domSel.focusNode, domSel.focusOffset, 1);
16
- if (head < 0) return null;
17
- let $head = doc.resolve(head), anchor, selection;
18
- if (selectionCollapsed(domSel)) {
19
- anchor = head;
20
- while(nearestDesc && !nearestDesc.node)nearestDesc = nearestDesc.parent;
21
- const nearestDescNode = nearestDesc.node;
22
- if (nearestDesc && nearestDescNode.isAtom && NodeSelection.isSelectable(nearestDescNode) && nearestDesc.parent && !(nearestDescNode.isInline && isOnEdge(domSel.focusNode, domSel.focusOffset, nearestDesc.dom))) {
23
- const pos = nearestDesc.posBefore;
24
- selection = new NodeSelection(head == pos ? $head : doc.resolve(pos));
25
- }
26
- } else {
27
- if (// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
28
- domSel instanceof view.dom.ownerDocument.defaultView.Selection && domSel.rangeCount > 1) {
29
- let min = head, max = head;
30
- for(let i = 0; i < domSel.rangeCount; i++){
31
- const range = domSel.getRangeAt(i);
32
- min = Math.min(min, // @ts-expect-error Internal method
33
- view.docView.posFromDOM(range.startContainer, range.startOffset, 1));
34
- max = Math.max(max, // @ts-expect-error Internal method
35
- view.docView.posFromDOM(range.endContainer, range.endOffset, -1));
36
- }
37
- if (min < 0) return null;
38
- [anchor, head] = max == view.state.selection.anchor ? [
39
- max,
40
- min
41
- ] : [
42
- min,
43
- max
44
- ];
45
- $head = doc.resolve(head);
46
- } else {
47
- // @ts-expect-error Internal method
48
- anchor = view.docView.posFromDOM(// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
49
- domSel.anchorNode, domSel.anchorOffset, 1);
50
- }
51
- if (anchor < 0) return null;
52
- }
53
- const $anchor = doc.resolve(anchor);
54
- if (!selection) {
55
- const bias = origin == "pointer" || view.state.selection.head < $head.pos && !inWidget ? 1 : -1;
56
- selection = selectionBetween(view, $anchor, $head, bias);
57
- }
58
- return selection;
59
- }
@@ -1,196 +0,0 @@
1
- import { NodeSelection, TextSelection } from "prosemirror-state";
2
- import { browser } from "../browser.js";
3
- // Scans forward and backward through DOM positions equivalent to the
4
- // given one to see if the two are in the same place (i.e. after a
5
- // text node vs at the end of that text node)
6
- export const isEquivalentPosition = function(node, off, targetNode, targetOff) {
7
- return targetNode && (scanFor(node, off, targetNode, targetOff, -1) || scanFor(node, off, targetNode, targetOff, 1));
8
- };
9
- export function hasBlockDesc(dom) {
10
- let desc;
11
- for(let cur = dom; cur; cur = cur.parentNode)if (desc = cur.pmViewDesc) break;
12
- return desc && desc.node && desc.node.isBlock && (desc.dom == dom || desc.contentDOM == dom);
13
- }
14
- const atomElements = /^(img|br|input|textarea|hr)$/i;
15
- function scanFor(node, off, targetNode, targetOff, dir) {
16
- for(;;){
17
- if (node == targetNode && off == targetOff) return true;
18
- if (off == (dir < 0 ? 0 : nodeSize(node))) {
19
- const parent = node.parentNode;
20
- if (!parent || parent.nodeType != 1 || hasBlockDesc(node) || atomElements.test(node.nodeName) || node.contentEditable == "false") return false;
21
- off = domIndex(node) + (dir < 0 ? 0 : 1);
22
- node = parent;
23
- } else if (node.nodeType == 1) {
24
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
25
- node = node.childNodes[off + (dir < 0 ? -1 : 0)];
26
- if (node.contentEditable == "false") return false;
27
- off = dir < 0 ? nodeSize(node) : 0;
28
- } else {
29
- return false;
30
- }
31
- }
32
- }
33
- export const domIndex = function(node) {
34
- let n = node;
35
- for(let index = 0;; index++){
36
- n = n.previousSibling;
37
- if (!n) return index;
38
- }
39
- };
40
- export function nodeSize(node) {
41
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
42
- return node.nodeType == 3 ? node.nodeValue.length : node.childNodes.length;
43
- }
44
- export function syncNodeSelection(view, sel) {
45
- const v = view;
46
- if (sel instanceof NodeSelection) {
47
- const desc = v.docView.descAt(sel.from);
48
- if (desc != v.lastSelectedViewDesc) {
49
- clearNodeSelection(v);
50
- if (desc) desc.selectNode();
51
- v.lastSelectedViewDesc = desc;
52
- }
53
- } else {
54
- clearNodeSelection(v);
55
- }
56
- }
57
- // Clear all DOM statefulness of the last node selection.
58
- function clearNodeSelection(view) {
59
- const v = view;
60
- if (v.lastSelectedViewDesc) {
61
- if (v.lastSelectedViewDesc.parent) v.lastSelectedViewDesc.deselectNode();
62
- v.lastSelectedViewDesc = undefined;
63
- }
64
- }
65
- export function hasSelection(view) {
66
- const v = view;
67
- const sel = v.domSelectionRange();
68
- if (!sel.anchorNode) return false;
69
- try {
70
- // Firefox will raise 'permission denied' errors when accessing
71
- // properties of `sel.anchorNode` when it's in a generated CSS
72
- // element.
73
- return v.dom.contains(sel.anchorNode.nodeType == 3 ? sel.anchorNode.parentNode : sel.anchorNode) && (v.editable || v.dom.contains(// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
74
- sel.focusNode.nodeType == 3 ? sel.focusNode.parentNode : sel.focusNode));
75
- } catch (_) {
76
- return false;
77
- }
78
- }
79
- function editorOwnsSelection(view) {
80
- return view.editable ? view.hasFocus() : hasSelection(view) && document.activeElement && document.activeElement.contains(view.dom);
81
- }
82
- function selectCursorWrapper(view) {
83
- const v = view;
84
- const domSel = v.domSelection(), range = document.createRange();
85
- if (!domSel) return;
86
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
87
- const node = v.cursorWrapper.dom, img = node.nodeName == "IMG";
88
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
89
- if (img) range.setStart(node.parentNode, domIndex(node) + 1);
90
- else range.setStart(node, 0);
91
- range.collapse(true);
92
- domSel.removeAllRanges();
93
- domSel.addRange(range);
94
- // Kludge to kill 'control selection' in IE11 when selecting an
95
- // invisible cursor wrapper, since that would result in those weird
96
- // resize handles and a selection that considers the absolutely
97
- // positioned wrapper, rather than the root editable node, the
98
- // focused element.
99
- if (!img && !v.state.selection.visible && browser.ie && browser.ie_version <= 11) {
100
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
101
- node.disabled = true;
102
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
103
- node.disabled = false;
104
- }
105
- }
106
- function temporarilyEditableNear(view, pos) {
107
- const v = view;
108
- const { node, offset } = v.docView.domFromPos(pos, 0);
109
- const after = offset < node.childNodes.length ? node.childNodes[offset] : null;
110
- const before = offset ? node.childNodes[offset - 1] : null;
111
- if (browser.safari && after && after.contentEditable == "false") return setEditable(after);
112
- if ((!after || after.contentEditable == "false") && (!before || before.contentEditable == "false")) {
113
- if (after) return setEditable(after);
114
- else if (before) return setEditable(before);
115
- }
116
- return;
117
- }
118
- function setEditable(element) {
119
- element.contentEditable = "true";
120
- if (browser.safari && element.draggable) {
121
- element.draggable = false;
122
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
123
- element.wasDraggable = true;
124
- }
125
- return element;
126
- }
127
- function resetEditable(element) {
128
- element.contentEditable = "false";
129
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
130
- if (element.wasDraggable) {
131
- element.draggable = true;
132
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
133
- element.wasDraggable = null;
134
- }
135
- }
136
- function removeClassOnSelectionChange(view) {
137
- const v = view;
138
- const doc = v.dom.ownerDocument;
139
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
140
- doc.removeEventListener("selectionchange", v.input.hideSelectionGuard);
141
- const domSel = v.domSelectionRange();
142
- const node = domSel.anchorNode, offset = domSel.anchorOffset;
143
- doc.addEventListener("selectionchange", v.input.hideSelectionGuard = ()=>{
144
- if (domSel.anchorNode != node || domSel.anchorOffset != offset) {
145
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
146
- doc.removeEventListener("selectionchange", v.input.hideSelectionGuard);
147
- setTimeout(()=>{
148
- if (!editorOwnsSelection(v) || v.state.selection.visible) v.dom.classList.remove("ProseMirror-hideselection");
149
- }, 20);
150
- }
151
- });
152
- }
153
- const brokenSelectBetweenUneditable = browser.safari || browser.chrome && browser.chrome_version < 63;
154
- export function selectionToDOM(view) {
155
- let force = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
156
- const v = view;
157
- const sel = v.state.selection;
158
- syncNodeSelection(v, sel);
159
- if (!editorOwnsSelection(v)) return;
160
- // The delayed drag selection causes issues with Cell Selections
161
- // in Safari. And the drag selection delay is to workarond issues
162
- // which only present in Chrome.
163
- if (!force && v.input.mouseDown && v.input.mouseDown.allowDefault && browser.chrome) {
164
- const domSel = v.domSelectionRange(), curSel = v.domObserver.currentSelection;
165
- if (domSel.anchorNode && curSel.anchorNode && isEquivalentPosition(domSel.anchorNode, domSel.anchorOffset, curSel.anchorNode, curSel.anchorOffset)) {
166
- v.input.mouseDown.delayedSelectionSync = true;
167
- v.domObserver.setCurSelection();
168
- return;
169
- }
170
- }
171
- v.domObserver.disconnectSelection();
172
- if (v.cursorWrapper) {
173
- selectCursorWrapper(v);
174
- } else {
175
- const { anchor, head } = sel;
176
- let resetEditableFrom;
177
- let resetEditableTo;
178
- if (brokenSelectBetweenUneditable && !(sel instanceof TextSelection)) {
179
- if (!sel.$from.parent.inlineContent) resetEditableFrom = temporarilyEditableNear(v, sel.from);
180
- if (!sel.empty && !sel.$from.parent.inlineContent) resetEditableTo = temporarilyEditableNear(v, sel.to);
181
- }
182
- v.docView.setSelection(anchor, head, v, force);
183
- if (brokenSelectBetweenUneditable) {
184
- if (resetEditableFrom) resetEditable(resetEditableFrom);
185
- if (resetEditableTo) resetEditable(resetEditableTo);
186
- }
187
- if (sel.visible) {
188
- v.dom.classList.remove("ProseMirror-hideselection");
189
- } else {
190
- v.dom.classList.add("ProseMirror-hideselection");
191
- if ("onselectionchange" in document) removeClassOnSelectionChange(v);
192
- }
193
- }
194
- v.domObserver.setCurSelection();
195
- v.domObserver.connectSelection();
196
- }
package/dist/esm/ssr.js DELETED
@@ -1,82 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-empty-function */ /**
2
- * @fileoverview
3
- *
4
- * Stubs for ProseMirror View during SSR. These are extremely
5
- * barebones, because they _do not need to actually work_. They
6
- * just need to prevent errors from being thrown when ProseMirror
7
- * View attemps to access these APIs while constructing the
8
- * initial EditorView. None of these APIs are necessary for SSR to
9
- * work properly, so it's fine that they're all no-ops.
10
- */ let ClassList = class ClassList {
11
- add() {}
12
- remove() {}
13
- };
14
- let ElementStub = class ElementStub {
15
- get parent() {
16
- return new ElementStub();
17
- }
18
- get parentNode() {
19
- return new ElementStub();
20
- }
21
- nodeName = "div";
22
- appendChild() {
23
- return new ElementStub();
24
- }
25
- setAttribute() {}
26
- hasAttribute() {
27
- return false;
28
- }
29
- insertBefore() {}
30
- get classList() {
31
- return new ClassList();
32
- }
33
- get ownerDocument() {
34
- return new DocumentStub();
35
- }
36
- style = {};
37
- addEventListener() {}
38
- removeEventListener() {}
39
- replaceChildren() {}
40
- };
41
- let DocumentStub = class DocumentStub {
42
- createElement() {
43
- return new ElementStub();
44
- }
45
- addEventListener() {}
46
- removeEventListener() {}
47
- get documentElement() {
48
- return new ElementStub();
49
- }
50
- };
51
- /**
52
- * Sets up tiny no-op stubs for the global window and document.
53
- * These are used to prevent errors from being thrown when ProseMirror's
54
- * EditorView attempts to access the DOM in its constructor during SSR.
55
- *
56
- * Returns a cleanup function that resets the window and document back
57
- * to their original values (undefined).
58
- */ export function setSsrStubs() {
59
- const prevWindow = globalThis.window;
60
- // @ts-expect-error HACK - EditorView checks for window.MutationObserver
61
- // in its constructor, which breaks SSR. We temporarily set window
62
- // to an empty object to prevent an error from being thrown, and then
63
- // clean it up so that other isomorphic code doesn't get confused about
64
- // whether there's a functioning global window object
65
- globalThis.window ??= {
66
- visualViewport: null
67
- };
68
- const prevDocument = globalThis.document;
69
- // @ts-expect-error HACK: This is only used during SSR, and only
70
- // to prevent outright errors when ProseMirror View attempts to
71
- // access document properties either on import or when constructing
72
- // the EditorView.
73
- globalThis.document ??= new DocumentStub();
74
- return function cleanupSsrStubs() {
75
- if (globalThis.window !== prevWindow) {
76
- globalThis.window = prevWindow;
77
- }
78
- if (globalThis.document !== prevDocument) {
79
- globalThis.document = prevDocument;
80
- }
81
- };
82
- }
@@ -1,7 +0,0 @@
1
- import type { ReactNode } from "react";
2
- import type { UseEditorViewOptions } from "../hooks/useEditorView.js";
3
- export interface EditorProps extends UseEditorViewOptions {
4
- mount: HTMLElement | null;
5
- children?: ReactNode | null;
6
- }
7
- export declare function Editor({ mount, children, ...options }: EditorProps): JSX.Element;
@@ -1,6 +0,0 @@
1
- import type { NodeViewsContextValue } from "../contexts/NodeViewsContext.js";
2
- type NodeViewsProps = {
3
- portals: NodeViewsContextValue;
4
- };
5
- export declare function NodeViews({ portals }: NodeViewsProps): JSX.Element;
6
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,19 +0,0 @@
1
- import type { ReactPortal } from "react";
2
- import type { NodeKey } from "../plugins/react";
3
- type NodeViewRegistration = {
4
- getPos: () => number;
5
- portal: ReactPortal;
6
- };
7
- export interface NodeViewsContextValue {
8
- [key: NodeKey]: NodeViewRegistration[];
9
- }
10
- /**
11
- * A context containing a map of node view keys to portals.
12
- *
13
- * Each node view registers a portal under its parent's
14
- * key. Each can then retrieve the list of portals under their
15
- * key, allowing portals to be rendered with the appropriate
16
- * hierarchy.
17
- */
18
- export declare const NodeViewsContext: import("react").Context<NodeViewsContextValue>;
19
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export declare function useClientOnly(): boolean;
@@ -1,23 +0,0 @@
1
- import { EditorState } from "prosemirror-state";
2
- import type { Plugin, Transaction } from "prosemirror-state";
3
- import { EditorView } from "prosemirror-view";
4
- import type { EditorProps } from "prosemirror-view";
5
- import type { EditorContextValue } from "../contexts/EditorContext.js";
6
- import type { ReactNodeViewConstructor } from "../nodeViews/createReactNodeViewConstructor.js";
7
- export interface UseEditorViewOptions extends EditorProps {
8
- nodeViews?: Record<string, ReactNodeViewConstructor>;
9
- defaultState?: EditorState;
10
- state?: EditorState;
11
- plugins?: Plugin[];
12
- view?: EditorView | null;
13
- dispatchTransaction?(this: EditorView, tr: Transaction): void;
14
- }
15
- /**
16
- * Creates, mounts, and manages a ProseMirror `EditorView`.
17
- *
18
- * All state and props updates are executed in a layout effect.
19
- * To ensure that the EditorState and EditorView are never out of
20
- * sync, it's important that the EditorView produced by this hook
21
- * is only accessed through the provided hooks.
22
- */
23
- export declare function useEditorView<T extends HTMLElement = HTMLElement>(mount: T | null, options: UseEditorViewOptions): EditorContextValue;
@@ -1,9 +0,0 @@
1
- import type { ReactNode } from "react";
2
- import type { NodeKey } from "../plugins/react.js";
3
- type Props = {
4
- nodeKey: NodeKey;
5
- children: ReactNode;
6
- };
7
- export declare function NodePosProvider({ nodeKey, children }: Props): JSX.Element;
8
- export declare function useNodePos(): number;
9
- export {};
@@ -1,5 +0,0 @@
1
- import type { ReactNodeViewConstructor } from "../nodeViews/createReactNodeViewConstructor.js";
2
- export declare function useNodeViews(nodeViews?: Record<string, ReactNodeViewConstructor>): {
3
- nodeViews: any;
4
- nodeViewsComponent: JSX.Element;
5
- };
@@ -1,48 +0,0 @@
1
- import type { Node } from "prosemirror-model";
2
- import type { Decoration, DecorationSource, EditorView, NodeView, NodeViewConstructor } from "prosemirror-view";
3
- import type { ComponentType, ReactNode, ReactPortal } from "react";
4
- import type { NodeKey } from "../plugins/react.js";
5
- export interface NodeViewComponentProps {
6
- decorations: readonly Decoration[];
7
- node: Node;
8
- children: ReactNode;
9
- isSelected: boolean;
10
- }
11
- export type UnregisterElement = () => void;
12
- export type RegisterPortal = (view: EditorView, getPos: () => number, portal: ReactPortal) => UnregisterElement;
13
- export type ReactNodeView = NodeView & {
14
- component?: ComponentType<NodeViewComponentProps>;
15
- };
16
- export type ReactNodeViewConstructor = (...args: Parameters<NodeViewConstructor>) => ReactNodeView;
17
- /**
18
- * Identifies a node view constructor as having been created
19
- * by @nytimes/react-prosemirror
20
- */
21
- export declare const REACT_NODE_VIEW: unique symbol;
22
- /**
23
- * Searches upward for the nearest node with a node key,
24
- * returning the first node key it finds associated with
25
- * a React node view.
26
- *
27
- * Returns the root key if no ancestor nodes have node keys.
28
- */
29
- export declare function findNodeKeyUp(editorView: EditorView, pos: number): NodeKey;
30
- /**
31
- * Factory function for creating nodeViewConstructors that
32
- * render as React components.
33
- *
34
- * `NodeView` can be any React component that takes
35
- * `NodeViewComponentProps`. It will be passed all of the
36
- * arguments to the `nodeViewConstructor` except for
37
- * `editorView`. NodeView components that need access
38
- * directly to the EditorView should use the
39
- * `useEditorViewEvent` and `useEditorViewLayoutEffect`
40
- * hooks to ensure safe access.
41
- *
42
- * For contentful Nodes, the NodeView component will also
43
- * be passed a `children` prop containing an empty element.
44
- * ProseMirror will render content nodes into this element.
45
- */
46
- export declare function createReactNodeViewConstructor(nodeViewConstructor: ReactNodeViewConstructor, registerPortal: RegisterPortal): ((node: Node, editorView: EditorView, getPos: () => number, decorations: readonly Decoration[], innerDecorations: DecorationSource) => NodeView) & {
47
- [REACT_NODE_VIEW]: boolean;
48
- };
@@ -1 +0,0 @@
1
- export declare const phrasingContentTags: string[];
@@ -1 +0,0 @@
1
- export {};
@@ -1,21 +0,0 @@
1
- import { Plugin, PluginKey } from "prosemirror-state";
2
- /**
3
- * This is a stand-in for the doc node itself, which doesn't have a
4
- * unique position to map to.
5
- */
6
- export declare const ROOT_NODE_KEY: unique symbol;
7
- export type NodeKey = string | symbol;
8
- export declare function createNodeKey(): string;
9
- export type ReactPluginState = {
10
- posToKey: Map<number, string>;
11
- keyToPos: Map<NodeKey, number>;
12
- };
13
- export declare const reactPluginKey: PluginKey<ReactPluginState>;
14
- /**
15
- * Tracks a unique key for each (non-text) node in the
16
- * document, identified by its current position. Keys are
17
- * (mostly) stable across transaction applications. The
18
- * key for a given node can be accessed by that node's
19
- * current position in the document, and vice versa.
20
- */
21
- export declare function react(): Plugin<ReactPluginState>;
@@ -1,33 +0,0 @@
1
- import { EditorView } from "prosemirror-view";
2
- import { DOMSelectionRange } from "../dom.js";
3
- declare class SelectionState {
4
- anchorNode: Node | null;
5
- anchorOffset: number;
6
- focusNode: Node | null;
7
- focusOffset: number;
8
- set(sel: DOMSelectionRange): void;
9
- clear(): void;
10
- eq(sel: DOMSelectionRange): boolean;
11
- }
12
- export declare class SelectionDOMObserver {
13
- readonly view: EditorView;
14
- flushingSoon: number;
15
- currentSelection: SelectionState;
16
- suppressingSelectionUpdates: boolean;
17
- constructor(view: EditorView);
18
- connectSelection(): void;
19
- disconnectSelection(): void;
20
- stop(): void;
21
- start(): void;
22
- suppressSelectionUpdates(): void;
23
- setCurSelection(): void;
24
- ignoreSelectionChange(sel: DOMSelectionRange): true | undefined;
25
- registerMutation(): void;
26
- flushSoon(): void;
27
- updateSelection(): void;
28
- selectionToDOM(): void;
29
- flush(): void;
30
- forceFlush(): void;
31
- onSelectionChange(): void;
32
- }
33
- export {};
@@ -1,3 +0,0 @@
1
- import { EditorView } from "prosemirror-view";
2
- export declare function hasFocusAndSelection(view: EditorView): boolean;
3
- export declare function hasSelection(view: EditorView): boolean;
@@ -1,4 +0,0 @@
1
- import { ResolvedPos } from "prosemirror-model";
2
- import { EditorView } from "prosemirror-view";
3
- export declare function selectionBetween(view: EditorView, $anchor: ResolvedPos, $head: ResolvedPos, bias?: number): import("prosemirror-state").Selection;
4
- export declare function selectionFromDOM(view: EditorView, origin?: string | null): import("prosemirror-state").Selection | null;
@@ -1,9 +0,0 @@
1
- import { Selection } from "prosemirror-state";
2
- import { EditorView } from "prosemirror-view";
3
- export declare const isEquivalentPosition: (node: Node, off: number, targetNode: Node, targetOff: number) => boolean;
4
- export declare function hasBlockDesc(dom: Node): boolean | null | undefined;
5
- export declare const domIndex: (node: Node) => number;
6
- export declare function nodeSize(node: Node): number;
7
- export declare function syncNodeSelection(view: EditorView, sel: Selection): void;
8
- export declare function hasSelection(view: EditorView): boolean;
9
- export declare function selectionToDOM(view: EditorView, force?: boolean): void;
@@ -1,19 +0,0 @@
1
- /**
2
- * @fileoverview
3
- *
4
- * Stubs for ProseMirror View during SSR. These are extremely
5
- * barebones, because they _do not need to actually work_. They
6
- * just need to prevent errors from being thrown when ProseMirror
7
- * View attemps to access these APIs while constructing the
8
- * initial EditorView. None of these APIs are necessary for SSR to
9
- * work properly, so it's fine that they're all no-ops.
10
- */
11
- /**
12
- * Sets up tiny no-op stubs for the global window and document.
13
- * These are used to prevent errors from being thrown when ProseMirror's
14
- * EditorView attempts to access the DOM in its constructor during SSR.
15
- *
16
- * Returns a cleanup function that resets the window and document back
17
- * to their original values (undefined).
18
- */
19
- export declare function setSsrStubs(): () => void;