@handlewithcare/react-prosemirror 2.9.0-tiptap.24 → 3.0.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.
Files changed (143) hide show
  1. package/README.md +140 -75
  2. package/dist/cjs/StaticEditorView.js +0 -3
  3. package/dist/cjs/components/ChildNodeViews.js +4 -4
  4. package/dist/cjs/components/NativeWidgetView.js +2 -2
  5. package/dist/cjs/components/OutputSpec.js +10 -3
  6. package/dist/cjs/components/ProseMirror.js +11 -17
  7. package/dist/cjs/components/SeparatorHackView.js +2 -2
  8. package/dist/cjs/components/TrailingHackView.js +2 -2
  9. package/dist/cjs/components/WidgetView.js +2 -2
  10. package/dist/cjs/components/marks/DefaultMarkView.js +2 -1
  11. package/dist/cjs/components/marks/MarkView.js +2 -2
  12. package/dist/cjs/components/marks/{CustomMarkView.js → MarkViewConstructorView.js} +16 -7
  13. package/dist/cjs/components/marks/ReactMarkView.js +26 -6
  14. package/dist/cjs/components/nodes/DefaultNodeView.js +3 -2
  15. package/dist/cjs/components/nodes/DocNodeView.js +7 -6
  16. package/dist/cjs/components/nodes/NodeView.js +17 -6
  17. package/dist/cjs/components/nodes/{CustomNodeView.js → NodeViewConstructorView.js} +22 -9
  18. package/dist/cjs/components/nodes/ReactNodeView.js +59 -17
  19. package/dist/cjs/contexts/{ChildDescriptorsContext.js → ChildDescriptionsContext.js} +3 -3
  20. package/dist/cjs/hooks/useEditor.js +0 -4
  21. package/dist/cjs/hooks/useEditorEventCallback.js +1 -1
  22. package/dist/cjs/hooks/useMarkViewDescription.js +24 -21
  23. package/dist/cjs/hooks/useNodePos.js +18 -0
  24. package/dist/cjs/hooks/{useNodeViewDescriptor.js → useNodeViewDescription.js} +30 -25
  25. package/dist/cjs/index.js +8 -0
  26. package/dist/cjs/refs.js +28 -0
  27. package/dist/cjs/viewdesc.js +18 -5
  28. package/dist/esm/StaticEditorView.js +0 -3
  29. package/dist/esm/components/ChildNodeViews.js +4 -4
  30. package/dist/esm/components/NativeWidgetView.js +2 -2
  31. package/dist/esm/components/OutputSpec.js +10 -3
  32. package/dist/esm/components/ProseMirror.js +11 -17
  33. package/dist/esm/components/SeparatorHackView.js +2 -2
  34. package/dist/esm/components/TrailingHackView.js +2 -2
  35. package/dist/esm/components/WidgetView.js +2 -2
  36. package/dist/esm/components/marks/DefaultMarkView.js +2 -1
  37. package/dist/esm/components/marks/MarkView.js +2 -2
  38. package/dist/esm/components/marks/{CustomMarkView.js → MarkViewConstructorView.js} +14 -5
  39. package/dist/esm/components/marks/ReactMarkView.js +26 -6
  40. package/dist/esm/components/nodes/DefaultNodeView.js +3 -2
  41. package/dist/esm/components/nodes/DocNodeView.js +8 -7
  42. package/dist/esm/components/nodes/NodeView.js +7 -4
  43. package/dist/esm/components/nodes/{CustomNodeView.js → NodeViewConstructorView.js} +20 -7
  44. package/dist/esm/components/nodes/ReactNodeView.js +59 -17
  45. package/dist/esm/contexts/{ChildDescriptorsContext.js → ChildDescriptionsContext.js} +1 -1
  46. package/dist/esm/hooks/useEditor.js +0 -4
  47. package/dist/esm/hooks/useEditorEffect.js +0 -4
  48. package/dist/esm/hooks/useEditorEventCallback.js +6 -4
  49. package/dist/esm/hooks/useMarkViewDescription.js +26 -23
  50. package/dist/esm/hooks/useNodePos.js +15 -0
  51. package/dist/esm/hooks/{useNodeViewDescriptor.js → useNodeViewDescription.js} +29 -24
  52. package/dist/esm/index.js +2 -0
  53. package/dist/esm/refs.js +18 -0
  54. package/dist/esm/viewdesc.js +13 -6
  55. package/dist/tsconfig.tsbuildinfo +1 -1
  56. package/dist/types/AbstractEditorView.d.ts +0 -1
  57. package/dist/types/StaticEditorView.d.ts +0 -1
  58. package/dist/types/components/OutputSpec.d.ts +2 -1
  59. package/dist/types/components/ProseMirror.d.ts +3 -11
  60. package/dist/types/components/ProseMirrorDoc.d.ts +2 -2
  61. package/dist/types/components/marks/DefaultMarkView.d.ts +1 -1
  62. package/dist/types/components/marks/MarkViewComponentProps.d.ts +4 -3
  63. package/dist/types/components/marks/{CustomMarkView.d.ts → MarkViewConstructorView.d.ts} +1 -1
  64. package/dist/types/components/nodes/DefaultNodeView.d.ts +1 -1
  65. package/dist/types/components/nodes/DocNodeView.d.ts +2 -2
  66. package/dist/types/components/nodes/NodeView.d.ts +1 -0
  67. package/dist/types/components/nodes/NodeViewComponentProps.d.ts +4 -3
  68. package/dist/types/components/{CustomNodeView.d.ts → nodes/NodeViewConstructorView.d.ts} +1 -1
  69. package/dist/types/constants.d.ts +1 -1
  70. package/dist/types/contexts/{ChildDescriptorsContext.d.ts → ChildDescriptionsContext.d.ts} +1 -1
  71. package/dist/types/hooks/useEditorEffect.d.ts +0 -4
  72. package/dist/types/hooks/useEditorEventCallback.d.ts +6 -4
  73. package/dist/types/hooks/useMarkViewDescription.d.ts +6 -9
  74. package/dist/types/hooks/useNodePos.d.ts +9 -0
  75. package/dist/types/hooks/{useNodeViewDescriptor.d.ts → useNodeViewDescription.d.ts} +5 -9
  76. package/dist/types/index.d.ts +2 -0
  77. package/dist/types/props.d.ts +26 -26
  78. package/dist/types/refs.d.ts +2 -0
  79. package/dist/types/viewdesc.d.ts +4 -0
  80. package/package.json +12 -20
  81. package/dist/cjs/components/CustomNodeView.js +0 -132
  82. package/dist/cjs/components/DefaultNodeView.js +0 -67
  83. package/dist/cjs/components/DocNodeView.js +0 -96
  84. package/dist/cjs/components/MarkView.js +0 -119
  85. package/dist/cjs/components/NodeView.js +0 -86
  86. package/dist/cjs/components/NodeViewComponentProps.js +0 -4
  87. package/dist/cjs/components/ReactNodeView.js +0 -174
  88. package/dist/cjs/components/marks/OldMarkView.js +0 -120
  89. package/dist/cjs/tiptap/ReactProseMirrorNodeView.js +0 -26
  90. package/dist/cjs/tiptap/TiptapEditor.js +0 -34
  91. package/dist/cjs/tiptap/TiptapEditorContent.js +0 -142
  92. package/dist/cjs/tiptap/TiptapEditorView.js +0 -118
  93. package/dist/cjs/tiptap/TiptapNodeView.js +0 -26
  94. package/dist/cjs/tiptap/contexts/TiptapEditorContext.js +0 -12
  95. package/dist/cjs/tiptap/extensions/ReactProseMirror.js +0 -40
  96. package/dist/cjs/tiptap/hooks/useIsInReactProseMirror.js +0 -15
  97. package/dist/cjs/tiptap/hooks/useTiptapEditor.js +0 -43
  98. package/dist/cjs/tiptap/hooks/useTiptapEditorEffect.js +0 -35
  99. package/dist/cjs/tiptap/hooks/useTiptapEditorEventCallback.js +0 -35
  100. package/dist/cjs/tiptap/index.js +0 -48
  101. package/dist/cjs/tiptap/tiptapNodeView.js +0 -237
  102. package/dist/esm/components/CustomNodeView.js +0 -81
  103. package/dist/esm/components/DefaultNodeView.js +0 -16
  104. package/dist/esm/components/DocNodeView.js +0 -45
  105. package/dist/esm/components/MarkView.js +0 -68
  106. package/dist/esm/components/NodeView.js +0 -35
  107. package/dist/esm/components/NodeViewComponentProps.js +0 -1
  108. package/dist/esm/components/ReactNodeView.js +0 -123
  109. package/dist/esm/components/marks/OldMarkView.js +0 -69
  110. package/dist/esm/tiptap/ReactProseMirrorNodeView.js +0 -22
  111. package/dist/esm/tiptap/TiptapEditor.js +0 -24
  112. package/dist/esm/tiptap/TiptapEditorContent.js +0 -91
  113. package/dist/esm/tiptap/TiptapEditorView.js +0 -69
  114. package/dist/esm/tiptap/TiptapNodeView.js +0 -22
  115. package/dist/esm/tiptap/contexts/TiptapEditorContext.js +0 -2
  116. package/dist/esm/tiptap/extensions/ReactProseMirror.js +0 -30
  117. package/dist/esm/tiptap/hooks/useIsInReactProseMirror.js +0 -5
  118. package/dist/esm/tiptap/hooks/useTiptapEditor.js +0 -33
  119. package/dist/esm/tiptap/hooks/useTiptapEditorEffect.js +0 -42
  120. package/dist/esm/tiptap/hooks/useTiptapEditorEventCallback.js +0 -35
  121. package/dist/esm/tiptap/index.js +0 -9
  122. package/dist/esm/tiptap/tiptapNodeView.js +0 -205
  123. package/dist/types/components/DefaultNodeView.d.ts +0 -3
  124. package/dist/types/components/DocNodeView.d.ts +0 -12
  125. package/dist/types/components/MarkView.d.ts +0 -9
  126. package/dist/types/components/NodeView.d.ts +0 -11
  127. package/dist/types/components/NodeViewComponentProps.d.ts +0 -12
  128. package/dist/types/components/ReactNodeView.d.ts +0 -13
  129. package/dist/types/components/marks/OldMarkView.d.ts +0 -10
  130. package/dist/types/components/nodes/CustomNodeView.d.ts +0 -12
  131. package/dist/types/tiptap/ReactProseMirrorNodeView.d.ts +0 -15
  132. package/dist/types/tiptap/TiptapEditor.d.ts +0 -6
  133. package/dist/types/tiptap/TiptapEditorContent.d.ts +0 -19
  134. package/dist/types/tiptap/TiptapEditorView.d.ts +0 -16
  135. package/dist/types/tiptap/TiptapNodeView.d.ts +0 -15
  136. package/dist/types/tiptap/contexts/TiptapEditorContext.d.ts +0 -6
  137. package/dist/types/tiptap/extensions/ReactProseMirror.d.ts +0 -9
  138. package/dist/types/tiptap/hooks/useIsInReactProseMirror.d.ts +0 -1
  139. package/dist/types/tiptap/hooks/useTiptapEditor.d.ts +0 -4
  140. package/dist/types/tiptap/hooks/useTiptapEditorEffect.d.ts +0 -21
  141. package/dist/types/tiptap/hooks/useTiptapEditorEventCallback.d.ts +0 -13
  142. package/dist/types/tiptap/index.d.ts +0 -9
  143. package/dist/types/tiptap/tiptapNodeView.d.ts +0 -50
@@ -1,237 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "tiptapNodeView", {
6
- enumerable: true,
7
- get: function() {
8
- return tiptapNodeView;
9
- }
10
- });
11
- const _core = require("@tiptap/core");
12
- const _react = require("@tiptap/react");
13
- const _classnames = /*#__PURE__*/ _interop_require_default(require("classnames"));
14
- const _react1 = /*#__PURE__*/ _interop_require_wildcard(require("react"));
15
- const _useEditorEventCallback = require("../hooks/useEditorEventCallback.js");
16
- const _useIgnoreMutation = require("../hooks/useIgnoreMutation.js");
17
- const _useIsNodeSelected = require("../hooks/useIsNodeSelected.js");
18
- const _useStopEvent = require("../hooks/useStopEvent.js");
19
- const _props = require("../props.js");
20
- const _ReactProseMirrorNodeView = require("./ReactProseMirrorNodeView.js");
21
- const _useTiptapEditorEventCallback = require("./hooks/useTiptapEditorEventCallback.js");
22
- function _interop_require_default(obj) {
23
- return obj && obj.__esModule ? obj : {
24
- default: obj
25
- };
26
- }
27
- function _getRequireWildcardCache(nodeInterop) {
28
- if (typeof WeakMap !== "function") return null;
29
- var cacheBabelInterop = new WeakMap();
30
- var cacheNodeInterop = new WeakMap();
31
- return (_getRequireWildcardCache = function(nodeInterop) {
32
- return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
33
- })(nodeInterop);
34
- }
35
- function _interop_require_wildcard(obj, nodeInterop) {
36
- if (!nodeInterop && obj && obj.__esModule) {
37
- return obj;
38
- }
39
- if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
40
- return {
41
- default: obj
42
- };
43
- }
44
- var cache = _getRequireWildcardCache(nodeInterop);
45
- if (cache && cache.has(obj)) {
46
- return cache.get(obj);
47
- }
48
- var newObj = {
49
- __proto__: null
50
- };
51
- var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
52
- for(var key in obj){
53
- if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
54
- var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
55
- if (desc && (desc.get || desc.set)) {
56
- Object.defineProperty(newObj, key, desc);
57
- } else {
58
- newObj[key] = obj[key];
59
- }
60
- }
61
- }
62
- newObj.default = obj;
63
- if (cache) {
64
- cache.set(obj, newObj);
65
- }
66
- return newObj;
67
- }
68
- function tiptapNodeView(param) {
69
- let { component: WrappedComponent, extension, as, className = "", attrs, contentDOMElementTag: InnerTag = "div", stopEvent, ignoreMutation } = param;
70
- const TiptapNodeView = /*#__PURE__*/ (0, _react1.memo)(/*#__PURE__*/ (0, _react1.forwardRef)(function TiptapNodeView(param, ref) {
71
- let { children, nodeProps, ...props } = param;
72
- const { node, getPos, decorations, innerDecorations } = nodeProps;
73
- const OuterTag = as ?? (node.type.isInline ? "span" : "div");
74
- const { editor } = (0, _react.useCurrentEditor)();
75
- const extensionManager = editor?.extensionManager ?? null;
76
- const extensions = extensionManager?.extensions ?? null;
77
- const selected = (0, _useIsNodeSelected.useIsNodeSelected)();
78
- const htmlAttributes = (0, _react1.useMemo)(()=>{
79
- if (!extensions) return {};
80
- const attributes = (0, _core.getAttributesFromExtensions)(extensions);
81
- const extensionAttributes = attributes.filter((attribute)=>attribute.type === extension.name);
82
- return (0, _core.getRenderedAttributes)(node, extensionAttributes);
83
- }, [
84
- extensions,
85
- node
86
- ]);
87
- (0, _useStopEvent.useStopEvent)(function(_, event) {
88
- if (stopEvent) {
89
- return stopEvent.call({
90
- name: extension.name,
91
- editor,
92
- type: node.type
93
- }, {
94
- event
95
- });
96
- }
97
- if (!editor || !(this.dom instanceof HTMLElement)) return false;
98
- const nodeView = new _ReactProseMirrorNodeView.ReactProseMirrorNodeView(WrappedComponent, {
99
- extension,
100
- decorations,
101
- editor,
102
- getPos,
103
- HTMLAttributes: htmlAttributes,
104
- innerDecorations,
105
- node,
106
- view: editor.view
107
- }, this.dom, this.contentDOM);
108
- return nodeView.stopEvent(event) ?? false;
109
- });
110
- (0, _useIgnoreMutation.useIgnoreMutation)(function(_, mutation) {
111
- if (ignoreMutation) {
112
- return ignoreMutation.call({
113
- name: extension.name,
114
- editor,
115
- type: node.type
116
- }, {
117
- mutation
118
- });
119
- }
120
- if (!editor || !(this.dom instanceof HTMLElement)) return false;
121
- const nodeView = new _ReactProseMirrorNodeView.ReactProseMirrorNodeView(WrappedComponent, {
122
- extension,
123
- decorations,
124
- editor,
125
- getPos,
126
- HTMLAttributes: htmlAttributes,
127
- innerDecorations,
128
- node,
129
- view: editor.view
130
- }, this.dom, this.contentDOM);
131
- return nodeView.ignoreMutation(mutation) ?? false;
132
- });
133
- const { extraClassName, htmlProps } = (0, _react1.useMemo)(()=>{
134
- if (!attrs) return {};
135
- const resolvedAttrs = typeof attrs === "function" ? attrs({
136
- node,
137
- HTMLAttributes: htmlAttributes
138
- }) : attrs;
139
- const { className: extraClassName, ...htmlProps } = (0, _props.htmlAttrsToReactProps)(resolvedAttrs);
140
- return {
141
- extraClassName,
142
- htmlProps
143
- };
144
- }, [
145
- htmlAttributes,
146
- node
147
- ]);
148
- const finalClassName = (0, _classnames.default)("react-renderer", `node-${node.type.name}`, props.className, className, extraClassName, {
149
- "ProseMirror-selectednode": selected
150
- });
151
- const updateAttributes = (0, _useEditorEventCallback.useEditorEventCallback)((_, attributes)=>{
152
- if (!editor) {
153
- return;
154
- }
155
- editor.commands.command((param)=>{
156
- let { tr } = param;
157
- const pos = getPos();
158
- tr.setNodeMarkup(pos, undefined, {
159
- ...node.attrs,
160
- ...attributes
161
- });
162
- return true;
163
- });
164
- });
165
- const deleteNode = (0, _useEditorEventCallback.useEditorEventCallback)(()=>{
166
- if (!editor) {
167
- return;
168
- }
169
- const from = getPos();
170
- const to = from + node.nodeSize;
171
- editor.commands.deleteRange({
172
- from,
173
- to
174
- });
175
- });
176
- const nodeViewContent = (0, _react1.useMemo)(()=>/*#__PURE__*/ _react1.default.createElement(InnerTag, {
177
- "data-node-view-content-inner": node.type.name,
178
- style: {
179
- whitespace: "inherit"
180
- }
181
- }, children), [
182
- children,
183
- node.type.name
184
- ]);
185
- const onDragStart = (0, _useTiptapEditorEventCallback.useTiptapEditorEventCallback)((editor, event)=>{
186
- // TODO: We should probably just merge this with our own
187
- // ref, I'm being lazy since we are providing this
188
- // ref in the first place (in ReactNodeView), so we know
189
- // it's an object
190
- const dom = typeof ref === "object" ? ref?.current : null;
191
- if (!dom) return;
192
- const viewDesc = dom.pmViewDesc;
193
- if (!viewDesc) return;
194
- const nodeView = new _ReactProseMirrorNodeView.ReactProseMirrorNodeView(WrappedComponent, {
195
- extension,
196
- decorations,
197
- editor,
198
- getPos,
199
- HTMLAttributes: htmlAttributes,
200
- innerDecorations,
201
- node,
202
- view: editor.view
203
- }, viewDesc.dom, viewDesc.contentDOM);
204
- return nodeView.onDragStart(event);
205
- });
206
- const nodeViewContext = (0, _react1.useMemo)(()=>({
207
- nodeViewContentChildren: nodeViewContent,
208
- onDragStart
209
- }), [
210
- nodeViewContent,
211
- onDragStart
212
- ]);
213
- if (!editor) return null;
214
- return /*#__PURE__*/ _react1.default.createElement(_react.ReactNodeViewContext.Provider, {
215
- value: nodeViewContext
216
- }, /*#__PURE__*/ _react1.default.createElement(OuterTag, {
217
- ref: ref,
218
- ...props,
219
- ...htmlProps,
220
- className: finalClassName
221
- }, /*#__PURE__*/ _react1.default.createElement(WrappedComponent, {
222
- node: node,
223
- getPos: getPos,
224
- view: editor.view,
225
- editor: editor,
226
- decorations: decorations,
227
- innerDecorations: innerDecorations,
228
- extension: extension,
229
- HTMLAttributes: htmlAttributes,
230
- selected: selected,
231
- updateAttributes: updateAttributes,
232
- deleteNode: deleteNode
233
- })));
234
- }));
235
- TiptapNodeView.displayName = `TiptapNodeView(${WrappedComponent.displayName ?? "Anonymous"})`;
236
- return TiptapNodeView;
237
- } // const defaultOnDragStart = NodeView.
@@ -1,81 +0,0 @@
1
- import { DOMSerializer } from "prosemirror-model";
2
- import React, { cloneElement, memo, useMemo, useRef } from "react";
3
- import { createPortal } from "react-dom";
4
- import { ChildDescriptorsContext } from "../contexts/ChildDescriptorsContext.js";
5
- import { useNodeViewDescriptor } from "../hooks/useNodeViewDescriptor.js";
6
- import { ChildNodeViews, wrapInDeco } from "./ChildNodeViews.js";
7
- export const CustomNodeView = /*#__PURE__*/ memo(function CustomNodeView(param) {
8
- let { constructor, node, getPos, innerDeco, outerDeco } = param;
9
- const ref = useRef(null);
10
- const innerRef = useRef(null);
11
- const nodeProps = useMemo(()=>({
12
- node,
13
- getPos,
14
- decorations: outerDeco,
15
- innerDecorations: innerDeco
16
- }), [
17
- node,
18
- getPos,
19
- outerDeco,
20
- innerDeco
21
- ]);
22
- const createNodeView = function() {
23
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
24
- args[_key] = arguments[_key];
25
- }
26
- const nodeView = constructor(...args);
27
- if (!nodeView || !nodeView.dom) {
28
- const spec = node.type.spec.toDOM?.(node);
29
- if (!spec) {
30
- throw new Error(`Node spec for ${node.type.name} is missing toDOM`);
31
- }
32
- return DOMSerializer.renderSpec(document, spec, null);
33
- }
34
- return nodeView;
35
- };
36
- const { childContextValue, contentDOM } = useNodeViewDescriptor(ref, function() {
37
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
38
- args[_key] = arguments[_key];
39
- }
40
- const nodeView = createNodeView(...args);
41
- const contentDOM = nodeView.contentDOM;
42
- const nodeDOM = nodeView.dom;
43
- const wrapperDOM = innerRef.current ?? ref.current;
44
- wrapperDOM.appendChild(nodeDOM);
45
- if (!contentDOM && nodeDOM instanceof HTMLElement && nodeDOM.tagName !== "BR") {
46
- if (!nodeDOM.hasAttribute("contenteditable")) {
47
- nodeDOM.contentEditable = "false";
48
- }
49
- if (node.type.spec.draggable) {
50
- nodeDOM.draggable = true;
51
- }
52
- }
53
- return {
54
- ...nodeView,
55
- destroy () {
56
- if (nodeView.destroy) {
57
- nodeView.destroy();
58
- }
59
- wrapperDOM.removeChild(nodeDOM);
60
- },
61
- selectNode: nodeView.selectNode?.bind(nodeView),
62
- deselectNode: nodeView.deselectNode?.bind(nodeView),
63
- stopEvent: nodeView.stopEvent?.bind(nodeView),
64
- ignoreMutation: nodeView.ignoreMutation?.bind(nodeView)
65
- };
66
- }, nodeProps);
67
- const Component = node.isInline ? "span" : "div";
68
- const props = {
69
- ref: innerRef
70
- };
71
- const children = !node.isLeaf && contentDOM ? /*#__PURE__*/ createPortal(/*#__PURE__*/ React.createElement(ChildDescriptorsContext.Provider, {
72
- value: childContextValue
73
- }, /*#__PURE__*/ React.createElement(ChildNodeViews, {
74
- getPos: getPos,
75
- node: node,
76
- innerDecorations: innerDeco
77
- })), contentDOM) : null;
78
- return /*#__PURE__*/ cloneElement(outerDeco.reduce(wrapInDeco, /*#__PURE__*/ React.createElement(Component, props, children)), {
79
- ref
80
- });
81
- });
@@ -1,16 +0,0 @@
1
- import React, { forwardRef, useMemo } from "react";
2
- import { OutputSpec } from "./OutputSpec.js";
3
- export const DefaultNodeView = /*#__PURE__*/ forwardRef(function DefaultNodeView(param, ref) {
4
- let { nodeProps: { node }, children, ...props } = param;
5
- const spec = useMemo(()=>node.type.spec.toDOM?.(node), [
6
- node
7
- ]);
8
- if (!spec) {
9
- throw new Error(`Node spec for ${node.type.name} is missing toDOM`);
10
- }
11
- return /*#__PURE__*/ React.createElement(OutputSpec, {
12
- ...props,
13
- outputSpec: spec,
14
- ref: ref
15
- }, children);
16
- });
@@ -1,45 +0,0 @@
1
- import React, { cloneElement, createElement, forwardRef, memo, useImperativeHandle, useMemo, useRef } from "react";
2
- import { ChildDescriptorsContext } from "../contexts/ChildDescriptorsContext.js";
3
- import { useNodeViewDescriptor } from "../hooks/useNodeViewDescriptor.js";
4
- import { ChildNodeViews, wrapInDeco } from "./ChildNodeViews.js";
5
- export const DocNodeView = /*#__PURE__*/ memo(/*#__PURE__*/ forwardRef(function DocNodeView(param, ref) {
6
- let { as, node, getPos, decorations, innerDecorations, setMount, ...elementProps } = param;
7
- const innerRef = useRef(null);
8
- useImperativeHandle(ref, ()=>innerRef.current);
9
- useImperativeHandle(setMount, ()=>innerRef.current);
10
- const nodeProps = useMemo(()=>({
11
- node,
12
- getPos,
13
- decorations,
14
- innerDecorations
15
- }), [
16
- node,
17
- getPos,
18
- decorations,
19
- innerDecorations
20
- ]);
21
- const { childContextValue } = useNodeViewDescriptor(innerRef, ()=>{
22
- const dom = innerRef.current;
23
- return {
24
- dom,
25
- contentDOM: dom,
26
- update () {
27
- return true;
28
- }
29
- };
30
- }, nodeProps);
31
- const children = /*#__PURE__*/ React.createElement(ChildDescriptorsContext.Provider, {
32
- value: childContextValue
33
- }, /*#__PURE__*/ React.createElement(ChildNodeViews, {
34
- getPos: getPos,
35
- node: node,
36
- innerDecorations: innerDecorations
37
- }));
38
- const props = {
39
- ...elementProps,
40
- suppressContentEditableWarning: true,
41
- ref: innerRef
42
- };
43
- const element = as ? /*#__PURE__*/ cloneElement(as, props, children) : /*#__PURE__*/ createElement("div", props, children);
44
- return nodeProps.decorations.reduce(wrapInDeco, element);
45
- }));
@@ -1,68 +0,0 @@
1
- import React, { forwardRef, memo, useContext, useImperativeHandle, useMemo, useRef } from "react";
2
- import { ChildDescriptorsContext } from "../contexts/ChildDescriptorsContext.js";
3
- import { useClientLayoutEffect } from "../hooks/useClientLayoutEffect.js";
4
- import { MarkViewDesc, sortViewDescs } from "../viewdesc.js";
5
- import { OutputSpec } from "./OutputSpec.js";
6
- export const MarkView = /*#__PURE__*/ memo(/*#__PURE__*/ forwardRef(function MarkView(param, ref) {
7
- let { mark, getPos, children } = param;
8
- const { siblingsRef, parentRef } = useContext(ChildDescriptorsContext);
9
- const viewDescRef = useRef(undefined);
10
- const childDescriptors = useRef([]);
11
- const domRef = useRef(null);
12
- useImperativeHandle(ref, ()=>{
13
- return domRef.current;
14
- }, []);
15
- const outputSpec = useMemo(()=>mark.type.spec.toDOM?.(mark, true), [
16
- mark
17
- ]);
18
- if (!outputSpec) throw new Error(`Mark spec for ${mark.type.name} is missing toDOM`);
19
- useClientLayoutEffect(()=>{
20
- const siblings = siblingsRef.current;
21
- return ()=>{
22
- if (!viewDescRef.current) return;
23
- if (siblings.includes(viewDescRef.current)) {
24
- const index = siblings.indexOf(viewDescRef.current);
25
- siblings.splice(index, 1);
26
- }
27
- };
28
- }, [
29
- siblingsRef
30
- ]);
31
- useClientLayoutEffect(()=>{
32
- if (!domRef.current) return;
33
- const firstChildDesc = childDescriptors.current[0];
34
- if (!viewDescRef.current) {
35
- viewDescRef.current = new MarkViewDesc(parentRef.current, childDescriptors.current, getPos, mark, domRef.current, firstChildDesc?.dom.parentElement ?? domRef.current, {
36
- dom: domRef.current,
37
- contentDOM: firstChildDesc?.dom.parentElement ?? domRef.current
38
- });
39
- } else {
40
- viewDescRef.current.parent = parentRef.current;
41
- viewDescRef.current.spec.dom = viewDescRef.current.dom = domRef.current;
42
- viewDescRef.current.children = childDescriptors.current;
43
- viewDescRef.current.spec.contentDOM = viewDescRef.current.contentDOM = firstChildDesc?.dom.parentElement ?? domRef.current;
44
- viewDescRef.current.mark = mark;
45
- }
46
- if (!siblingsRef.current.includes(viewDescRef.current)) {
47
- siblingsRef.current.push(viewDescRef.current);
48
- }
49
- siblingsRef.current.sort(sortViewDescs);
50
- for (const childDesc of childDescriptors.current){
51
- childDesc.parent = viewDescRef.current;
52
- }
53
- });
54
- const childContextValue = useMemo(()=>({
55
- parentRef: viewDescRef,
56
- siblingsRef: childDescriptors
57
- }), [
58
- childDescriptors,
59
- viewDescRef
60
- ]);
61
- return /*#__PURE__*/ React.createElement(OutputSpec, {
62
- ref: domRef,
63
- outputSpec: outputSpec,
64
- isMark: true
65
- }, /*#__PURE__*/ React.createElement(ChildDescriptorsContext.Provider, {
66
- value: childContextValue
67
- }, children));
68
- }));
@@ -1,35 +0,0 @@
1
- import React, { memo, useContext, useMemo } from "react";
2
- import { NodeViewContext } from "../contexts/NodeViewContext.js";
3
- import { CustomNodeView } from "./CustomNodeView.js";
4
- import { DefaultNodeView } from "./DefaultNodeView.js";
5
- import { ReactNodeView } from "./ReactNodeView.js";
6
- export const NodeView = /*#__PURE__*/ memo(function NodeView(props) {
7
- const { components, constructors } = useContext(NodeViewContext);
8
- const component = components[props.node.type.name] ?? DefaultNodeView;
9
- const constructor = constructors[props.node.type.name];
10
- // Construct a wrapper component so that the node view remounts when either
11
- // its component or constructor changes. A React node view would remount if
12
- // its underlying component changed without this wrapper, but a custom node
13
- // view otherwise uses the same React components for all custom node views.
14
- const Component = useMemo(()=>{
15
- if (constructor) {
16
- return function NodeView(props) {
17
- return /*#__PURE__*/ React.createElement(CustomNodeView, {
18
- constructor: constructor,
19
- ...props
20
- });
21
- };
22
- } else {
23
- return function NodeView(props) {
24
- return /*#__PURE__*/ React.createElement(ReactNodeView, {
25
- component: component,
26
- ...props
27
- });
28
- };
29
- }
30
- }, [
31
- constructor,
32
- component
33
- ]);
34
- return /*#__PURE__*/ React.createElement(Component, props);
35
- });
@@ -1 +0,0 @@
1
- export { };
@@ -1,123 +0,0 @@
1
- import React, { cloneElement, memo, useCallback, useMemo, useRef, useState } from "react";
2
- import { ChildDescriptorsContext } from "../contexts/ChildDescriptorsContext.js";
3
- import { IgnoreMutationContext } from "../contexts/IgnoreMutationContext.js";
4
- import { SelectNodeContext } from "../contexts/SelectNodeContext.js";
5
- import { StopEventContext } from "../contexts/StopEventContext.js";
6
- import { useNodeViewDescriptor } from "../hooks/useNodeViewDescriptor.js";
7
- import { ChildNodeViews, wrapInDeco } from "./ChildNodeViews.js";
8
- export const ReactNodeView = /*#__PURE__*/ memo(function ReactNodeView(param) {
9
- let { component: Component, outerDeco, getPos, node, innerDeco } = param;
10
- const [hasCustomSelectNode, setHasCustomSelectNode] = useState(false);
11
- const [selected, setSelected] = useState(false);
12
- const ref = useRef(null);
13
- const innerRef = useRef(null);
14
- const selectNodeRef = useRef(null);
15
- const deselectNodeRef = useRef(null);
16
- const stopEventRef = useRef(null);
17
- const ignoreMutationRef = useRef(null);
18
- const setSelectNode = useCallback((selectHandler, deselectHandler)=>{
19
- selectNodeRef.current = selectHandler;
20
- deselectNodeRef.current = deselectHandler;
21
- setHasCustomSelectNode(true);
22
- return ()=>{
23
- selectNodeRef.current = null;
24
- deselectNodeRef.current = null;
25
- setHasCustomSelectNode(false);
26
- };
27
- }, []);
28
- const setStopEvent = useCallback((handler)=>{
29
- stopEventRef.current = handler;
30
- return ()=>{
31
- stopEventRef.current = null;
32
- };
33
- }, []);
34
- const setIgnoreMutation = useCallback((handler)=>{
35
- ignoreMutationRef.current = handler;
36
- return ()=>{
37
- ignoreMutationRef.current = null;
38
- return ()=>{
39
- ignoreMutationRef.current = null;
40
- };
41
- };
42
- }, []);
43
- const nodeProps = useMemo(()=>({
44
- node: node,
45
- getPos: getPos,
46
- decorations: outerDeco,
47
- innerDecorations: innerDeco
48
- }), [
49
- getPos,
50
- innerDeco,
51
- node,
52
- outerDeco
53
- ]);
54
- const { childContextValue, contentDOM, nodeDOM } = useNodeViewDescriptor(ref, ()=>{
55
- setSelected(false);
56
- return {
57
- dom: innerRef.current ?? ref.current,
58
- update () {
59
- return true;
60
- },
61
- multiType: true,
62
- selectNode () {
63
- const selectNode = selectNodeRef.current;
64
- if (selectNode) {
65
- selectNode.call(this);
66
- }
67
- setSelected(true);
68
- },
69
- deselectNode () {
70
- const deselectNode = deselectNodeRef.current;
71
- if (deselectNode) {
72
- deselectNode.call(this);
73
- }
74
- setSelected(false);
75
- },
76
- stopEvent (event) {
77
- const stopEvent = stopEventRef.current;
78
- if (stopEvent) {
79
- return stopEvent.call(this, event);
80
- }
81
- return false;
82
- },
83
- ignoreMutation (mutation) {
84
- const ignoreMutation = ignoreMutationRef.current;
85
- if (ignoreMutation) {
86
- return ignoreMutation.call(this, mutation);
87
- }
88
- return false;
89
- }
90
- };
91
- }, nodeProps);
92
- const props = {
93
- nodeProps,
94
- ...!contentDOM && !nodeProps.node.isText && nodeDOM?.nodeName !== "BR" ? {
95
- contentEditable: false,
96
- suppressContentEditableWarning: true
97
- } : null,
98
- ...!hasCustomSelectNode && selected ? {
99
- className: "ProseMirror-selectednode"
100
- } : null,
101
- ...!hasCustomSelectNode && selected || node.type.spec.draggable ? {
102
- draggable: true
103
- } : null,
104
- ref: innerRef
105
- };
106
- const children = !node.isLeaf ? /*#__PURE__*/ React.createElement(ChildNodeViews, {
107
- getPos: getPos,
108
- node: node,
109
- innerDecorations: innerDeco
110
- }) : null;
111
- const element = /*#__PURE__*/ cloneElement(outerDeco.reduce(wrapInDeco, /*#__PURE__*/ React.createElement(Component, props, children)), {
112
- ref
113
- });
114
- return /*#__PURE__*/ React.createElement(SelectNodeContext.Provider, {
115
- value: setSelectNode
116
- }, /*#__PURE__*/ React.createElement(StopEventContext.Provider, {
117
- value: setStopEvent
118
- }, /*#__PURE__*/ React.createElement(IgnoreMutationContext.Provider, {
119
- value: setIgnoreMutation
120
- }, /*#__PURE__*/ React.createElement(ChildDescriptorsContext.Provider, {
121
- value: childContextValue
122
- }, element))));
123
- });
@@ -1,69 +0,0 @@
1
- import React, { forwardRef, memo, useContext, useImperativeHandle, useMemo, useRef } from "react";
2
- import { ChildDescriptorsContext } from "../../contexts/ChildDescriptorsContext.js";
3
- import { useClientLayoutEffect } from "../../hooks/useClientLayoutEffect.js";
4
- import { MarkViewDesc, sortViewDescs } from "../../viewdesc.js";
5
- import { OutputSpec } from "../OutputSpec.js";
6
- export const MarkView = /*#__PURE__*/ memo(/*#__PURE__*/ forwardRef(function MarkView(param, ref) {
7
- let { mark, getPos, children, inline = false } = param;
8
- const { siblingsRef, parentRef } = useContext(ChildDescriptorsContext);
9
- const viewDescRef = useRef(undefined);
10
- const childDescriptors = useRef([]);
11
- const domRef = useRef(null);
12
- useImperativeHandle(ref, ()=>{
13
- return domRef.current;
14
- }, []);
15
- const outputSpec = useMemo(()=>mark.type.spec.toDOM?.(mark, inline), [
16
- inline,
17
- mark
18
- ]);
19
- if (!outputSpec) throw new Error(`Mark spec for ${mark.type.name} is missing toDOM`);
20
- useClientLayoutEffect(()=>{
21
- const siblings = siblingsRef.current;
22
- return ()=>{
23
- if (!viewDescRef.current) return;
24
- if (siblings.includes(viewDescRef.current)) {
25
- const index = siblings.indexOf(viewDescRef.current);
26
- siblings.splice(index, 1);
27
- }
28
- };
29
- }, [
30
- siblingsRef
31
- ]);
32
- useClientLayoutEffect(()=>{
33
- if (!domRef.current) return;
34
- const firstChildDesc = childDescriptors.current[0];
35
- if (!viewDescRef.current) {
36
- viewDescRef.current = new MarkViewDesc(parentRef.current, childDescriptors.current, getPos, mark, domRef.current, firstChildDesc?.dom.parentElement ?? domRef.current, {
37
- dom: domRef.current,
38
- contentDOM: firstChildDesc?.dom.parentElement ?? domRef.current
39
- });
40
- } else {
41
- viewDescRef.current.parent = parentRef.current;
42
- viewDescRef.current.spec.dom = viewDescRef.current.dom = domRef.current;
43
- viewDescRef.current.children = childDescriptors.current;
44
- viewDescRef.current.spec.contentDOM = viewDescRef.current.contentDOM = firstChildDesc?.dom.parentElement ?? domRef.current;
45
- viewDescRef.current.mark = mark;
46
- }
47
- if (!siblingsRef.current.includes(viewDescRef.current)) {
48
- siblingsRef.current.push(viewDescRef.current);
49
- }
50
- siblingsRef.current.sort(sortViewDescs);
51
- for (const childDesc of childDescriptors.current){
52
- childDesc.parent = viewDescRef.current;
53
- }
54
- });
55
- const childContextValue = useMemo(()=>({
56
- parentRef: viewDescRef,
57
- siblingsRef: childDescriptors
58
- }), [
59
- childDescriptors,
60
- viewDescRef
61
- ]);
62
- return /*#__PURE__*/ React.createElement(OutputSpec, {
63
- ref: domRef,
64
- outputSpec: outputSpec,
65
- isMark: true
66
- }, /*#__PURE__*/ React.createElement(ChildDescriptorsContext.Provider, {
67
- value: childContextValue
68
- }, children));
69
- }));