@handlewithcare/react-prosemirror 3.1.0-tiptap.34 → 3.1.0-tiptap.36

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 (48) hide show
  1. package/dist/cjs/components/CustomNodeView.js +132 -0
  2. package/dist/cjs/components/DefaultNodeView.js +67 -0
  3. package/dist/cjs/components/DocNodeView.js +96 -0
  4. package/dist/cjs/components/MarkView.js +119 -0
  5. package/dist/cjs/components/NodeView.js +86 -0
  6. package/dist/cjs/components/NodeViewComponentProps.js +4 -0
  7. package/dist/cjs/components/ReactNodeView.js +174 -0
  8. package/dist/cjs/components/marks/CustomMarkView.js +110 -0
  9. package/dist/cjs/components/marks/OldMarkView.js +120 -0
  10. package/dist/cjs/components/nodes/CustomNodeView.js +135 -0
  11. package/dist/cjs/components/nodes/ReactNodeView.js +1 -1
  12. package/dist/cjs/contexts/ChildDescriptorsContext.js +19 -0
  13. package/dist/cjs/hooks/useNodeViewDescriptor.js +156 -0
  14. package/dist/cjs/package.json +3 -0
  15. package/dist/cjs/tiptap/TiptapNodeView.js +26 -0
  16. package/dist/cjs/tiptap/tiptapNodeView.js +10 -7
  17. package/dist/esm/components/CustomNodeView.js +81 -0
  18. package/dist/esm/components/DefaultNodeView.js +16 -0
  19. package/dist/esm/components/DocNodeView.js +45 -0
  20. package/dist/esm/components/MarkView.js +68 -0
  21. package/dist/esm/components/NodeView.js +35 -0
  22. package/dist/esm/components/NodeViewComponentProps.js +1 -0
  23. package/dist/esm/components/ReactNodeView.js +123 -0
  24. package/dist/esm/components/marks/CustomMarkView.js +59 -0
  25. package/dist/esm/components/marks/OldMarkView.js +69 -0
  26. package/dist/esm/components/nodes/CustomNodeView.js +84 -0
  27. package/dist/esm/components/nodes/ReactNodeView.js +1 -1
  28. package/dist/esm/contexts/ChildDescriptorsContext.js +9 -0
  29. package/dist/esm/hooks/useNodeViewDescriptor.js +146 -0
  30. package/dist/esm/tiptap/TiptapNodeView.js +22 -0
  31. package/dist/esm/tiptap/tiptapNodeView.js +11 -8
  32. package/dist/tsconfig.tsbuildinfo +1 -1
  33. package/dist/types/components/CustomNodeView.d.ts +12 -0
  34. package/dist/types/components/DefaultNodeView.d.ts +3 -0
  35. package/dist/types/components/DocNodeView.d.ts +12 -0
  36. package/dist/types/components/MarkView.d.ts +9 -0
  37. package/dist/types/components/NodeView.d.ts +11 -0
  38. package/dist/types/components/NodeViewComponentProps.d.ts +12 -0
  39. package/dist/types/components/ReactNodeView.d.ts +13 -0
  40. package/dist/types/components/marks/CustomMarkView.d.ts +12 -0
  41. package/dist/types/components/marks/OldMarkView.d.ts +10 -0
  42. package/dist/types/components/nodes/CustomNodeView.d.ts +12 -0
  43. package/dist/types/constants.d.ts +1 -1
  44. package/dist/types/contexts/ChildDescriptorsContext.d.ts +6 -0
  45. package/dist/types/hooks/useNodeViewDescriptor.d.ts +20 -0
  46. package/dist/types/props.d.ts +26 -26
  47. package/dist/types/tiptap/TiptapNodeView.d.ts +15 -0
  48. package/package.json +1 -1
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "CustomMarkView", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return CustomMarkView;
9
+ }
10
+ });
11
+ const _prosemirrormodel = require("prosemirror-model");
12
+ const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
13
+ const _reactdom = require("react-dom");
14
+ const _ChildDescriptionsContext = require("../../contexts/ChildDescriptionsContext.js");
15
+ const _useMarkViewDescription = require("../../hooks/useMarkViewDescription.js");
16
+ function _getRequireWildcardCache(nodeInterop) {
17
+ if (typeof WeakMap !== "function") return null;
18
+ var cacheBabelInterop = new WeakMap();
19
+ var cacheNodeInterop = new WeakMap();
20
+ return (_getRequireWildcardCache = function(nodeInterop) {
21
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
22
+ })(nodeInterop);
23
+ }
24
+ function _interop_require_wildcard(obj, nodeInterop) {
25
+ if (!nodeInterop && obj && obj.__esModule) {
26
+ return obj;
27
+ }
28
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
29
+ return {
30
+ default: obj
31
+ };
32
+ }
33
+ var cache = _getRequireWildcardCache(nodeInterop);
34
+ if (cache && cache.has(obj)) {
35
+ return cache.get(obj);
36
+ }
37
+ var newObj = {
38
+ __proto__: null
39
+ };
40
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
41
+ for(var key in obj){
42
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
43
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
44
+ if (desc && (desc.get || desc.set)) {
45
+ Object.defineProperty(newObj, key, desc);
46
+ } else {
47
+ newObj[key] = obj[key];
48
+ }
49
+ }
50
+ }
51
+ newObj.default = obj;
52
+ if (cache) {
53
+ cache.set(obj, newObj);
54
+ }
55
+ return newObj;
56
+ }
57
+ const CustomMarkView = /*#__PURE__*/ (0, _react.memo)(function CustomMarkView(param) {
58
+ let { constructor, mark, inline, getPos, children } = param;
59
+ const ref = (0, _react.useRef)(null);
60
+ const innerRef = (0, _react.useRef)(null);
61
+ const markProps = (0, _react.useMemo)(()=>({
62
+ mark,
63
+ inline,
64
+ getPos,
65
+ contentDOMRef: {
66
+ current: null
67
+ }
68
+ }), [
69
+ mark,
70
+ inline,
71
+ getPos
72
+ ]);
73
+ const createMarkView = function() {
74
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
75
+ args[_key] = arguments[_key];
76
+ }
77
+ const markView = constructor(...args);
78
+ if (!markView || !markView.dom) {
79
+ const spec = mark.type.spec.toDOM?.(mark, inline);
80
+ if (!spec) {
81
+ throw new Error(`Mark spec for ${mark.type.name} is missing toDOM`);
82
+ }
83
+ return _prosemirrormodel.DOMSerializer.renderSpec(document, spec, null);
84
+ }
85
+ return markView;
86
+ };
87
+ const { childContextValue, contentDOM } = (0, _useMarkViewDescription.useMarkViewDescription)(ref, function() {
88
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
89
+ args[_key] = arguments[_key];
90
+ }
91
+ const markView = createMarkView(...args);
92
+ const dom = markView.dom;
93
+ const wrapperDOM = innerRef.current ?? ref.current;
94
+ return {
95
+ ...markView,
96
+ destroy () {
97
+ markView.destroy?.();
98
+ wrapperDOM.removeChild(dom);
99
+ },
100
+ ignoreMutation: markView.ignoreMutation
101
+ };
102
+ }, (markView)=>markView?.contentDOM ?? null, markProps);
103
+ const Component = inline ? "span" : "div";
104
+ const props = {
105
+ ref: innerRef
106
+ };
107
+ return /*#__PURE__*/ _react.default.createElement(Component, props, contentDOM ? /*#__PURE__*/ (0, _reactdom.createPortal)(/*#__PURE__*/ _react.default.createElement(_ChildDescriptionsContext.ChildDescriptionsContext.Provider, {
108
+ value: childContextValue
109
+ }, children), contentDOM) : null);
110
+ });
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "MarkView", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return MarkView;
9
+ }
10
+ });
11
+ const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
12
+ const _ChildDescriptorsContext = require("../../contexts/ChildDescriptorsContext.js");
13
+ const _useClientLayoutEffect = require("../../hooks/useClientLayoutEffect.js");
14
+ const _viewdesc = require("../../viewdesc.js");
15
+ const _OutputSpec = require("../OutputSpec.js");
16
+ function _getRequireWildcardCache(nodeInterop) {
17
+ if (typeof WeakMap !== "function") return null;
18
+ var cacheBabelInterop = new WeakMap();
19
+ var cacheNodeInterop = new WeakMap();
20
+ return (_getRequireWildcardCache = function(nodeInterop) {
21
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
22
+ })(nodeInterop);
23
+ }
24
+ function _interop_require_wildcard(obj, nodeInterop) {
25
+ if (!nodeInterop && obj && obj.__esModule) {
26
+ return obj;
27
+ }
28
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
29
+ return {
30
+ default: obj
31
+ };
32
+ }
33
+ var cache = _getRequireWildcardCache(nodeInterop);
34
+ if (cache && cache.has(obj)) {
35
+ return cache.get(obj);
36
+ }
37
+ var newObj = {
38
+ __proto__: null
39
+ };
40
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
41
+ for(var key in obj){
42
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
43
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
44
+ if (desc && (desc.get || desc.set)) {
45
+ Object.defineProperty(newObj, key, desc);
46
+ } else {
47
+ newObj[key] = obj[key];
48
+ }
49
+ }
50
+ }
51
+ newObj.default = obj;
52
+ if (cache) {
53
+ cache.set(obj, newObj);
54
+ }
55
+ return newObj;
56
+ }
57
+ const MarkView = /*#__PURE__*/ (0, _react.memo)(/*#__PURE__*/ (0, _react.forwardRef)(function MarkView(param, ref) {
58
+ let { mark, getPos, children, inline = false } = param;
59
+ const { siblingsRef, parentRef } = (0, _react.useContext)(_ChildDescriptorsContext.ChildDescriptorsContext);
60
+ const viewDescRef = (0, _react.useRef)(undefined);
61
+ const childDescriptors = (0, _react.useRef)([]);
62
+ const domRef = (0, _react.useRef)(null);
63
+ (0, _react.useImperativeHandle)(ref, ()=>{
64
+ return domRef.current;
65
+ }, []);
66
+ const outputSpec = (0, _react.useMemo)(()=>mark.type.spec.toDOM?.(mark, inline), [
67
+ inline,
68
+ mark
69
+ ]);
70
+ if (!outputSpec) throw new Error(`Mark spec for ${mark.type.name} is missing toDOM`);
71
+ (0, _useClientLayoutEffect.useClientLayoutEffect)(()=>{
72
+ const siblings = siblingsRef.current;
73
+ return ()=>{
74
+ if (!viewDescRef.current) return;
75
+ if (siblings.includes(viewDescRef.current)) {
76
+ const index = siblings.indexOf(viewDescRef.current);
77
+ siblings.splice(index, 1);
78
+ }
79
+ };
80
+ }, [
81
+ siblingsRef
82
+ ]);
83
+ (0, _useClientLayoutEffect.useClientLayoutEffect)(()=>{
84
+ if (!domRef.current) return;
85
+ const firstChildDesc = childDescriptors.current[0];
86
+ if (!viewDescRef.current) {
87
+ viewDescRef.current = new _viewdesc.MarkViewDesc(parentRef.current, childDescriptors.current, getPos, mark, domRef.current, firstChildDesc?.dom.parentElement ?? domRef.current, {
88
+ dom: domRef.current,
89
+ contentDOM: firstChildDesc?.dom.parentElement ?? domRef.current
90
+ });
91
+ } else {
92
+ viewDescRef.current.parent = parentRef.current;
93
+ viewDescRef.current.spec.dom = viewDescRef.current.dom = domRef.current;
94
+ viewDescRef.current.children = childDescriptors.current;
95
+ viewDescRef.current.spec.contentDOM = viewDescRef.current.contentDOM = firstChildDesc?.dom.parentElement ?? domRef.current;
96
+ viewDescRef.current.mark = mark;
97
+ }
98
+ if (!siblingsRef.current.includes(viewDescRef.current)) {
99
+ siblingsRef.current.push(viewDescRef.current);
100
+ }
101
+ siblingsRef.current.sort(_viewdesc.sortViewDescs);
102
+ for (const childDesc of childDescriptors.current){
103
+ childDesc.parent = viewDescRef.current;
104
+ }
105
+ });
106
+ const childContextValue = (0, _react.useMemo)(()=>({
107
+ parentRef: viewDescRef,
108
+ siblingsRef: childDescriptors
109
+ }), [
110
+ childDescriptors,
111
+ viewDescRef
112
+ ]);
113
+ return /*#__PURE__*/ _react.default.createElement(_OutputSpec.OutputSpec, {
114
+ ref: domRef,
115
+ outputSpec: outputSpec,
116
+ isMark: true
117
+ }, /*#__PURE__*/ _react.default.createElement(_ChildDescriptorsContext.ChildDescriptorsContext.Provider, {
118
+ value: childContextValue
119
+ }, children));
120
+ }));
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "CustomNodeView", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return CustomNodeView;
9
+ }
10
+ });
11
+ const _prosemirrormodel = require("prosemirror-model");
12
+ const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
13
+ const _reactdom = require("react-dom");
14
+ const _ChildDescriptionsContext = require("../../contexts/ChildDescriptionsContext.js");
15
+ const _useNodeViewDescription = require("../../hooks/useNodeViewDescription.js");
16
+ const _ChildNodeViews = require("../ChildNodeViews.js");
17
+ function _getRequireWildcardCache(nodeInterop) {
18
+ if (typeof WeakMap !== "function") return null;
19
+ var cacheBabelInterop = new WeakMap();
20
+ var cacheNodeInterop = new WeakMap();
21
+ return (_getRequireWildcardCache = function(nodeInterop) {
22
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
23
+ })(nodeInterop);
24
+ }
25
+ function _interop_require_wildcard(obj, nodeInterop) {
26
+ if (!nodeInterop && obj && obj.__esModule) {
27
+ return obj;
28
+ }
29
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
30
+ return {
31
+ default: obj
32
+ };
33
+ }
34
+ var cache = _getRequireWildcardCache(nodeInterop);
35
+ if (cache && cache.has(obj)) {
36
+ return cache.get(obj);
37
+ }
38
+ var newObj = {
39
+ __proto__: null
40
+ };
41
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
42
+ for(var key in obj){
43
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
44
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
45
+ if (desc && (desc.get || desc.set)) {
46
+ Object.defineProperty(newObj, key, desc);
47
+ } else {
48
+ newObj[key] = obj[key];
49
+ }
50
+ }
51
+ }
52
+ newObj.default = obj;
53
+ if (cache) {
54
+ cache.set(obj, newObj);
55
+ }
56
+ return newObj;
57
+ }
58
+ const CustomNodeView = /*#__PURE__*/ (0, _react.memo)(function CustomNodeView(param) {
59
+ let { constructor, node, getPos, innerDeco, outerDeco } = param;
60
+ const ref = (0, _react.useRef)(null);
61
+ const innerRef = (0, _react.useRef)(null);
62
+ const nodeProps = (0, _react.useMemo)(()=>({
63
+ node,
64
+ getPos,
65
+ decorations: outerDeco,
66
+ innerDecorations: innerDeco,
67
+ contentDOMRef: {
68
+ current: null
69
+ }
70
+ }), [
71
+ node,
72
+ getPos,
73
+ outerDeco,
74
+ innerDeco
75
+ ]);
76
+ const createNodeView = function() {
77
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
78
+ args[_key] = arguments[_key];
79
+ }
80
+ const nodeView = constructor(...args);
81
+ if (!nodeView || !nodeView.dom) {
82
+ const spec = node.type.spec.toDOM?.(node);
83
+ if (!spec) {
84
+ throw new Error(`Node spec for ${node.type.name} is missing toDOM`);
85
+ }
86
+ return _prosemirrormodel.DOMSerializer.renderSpec(document, spec, null);
87
+ }
88
+ return nodeView;
89
+ };
90
+ const { childContextValue, contentDOM } = (0, _useNodeViewDescription.useNodeViewDescription)(ref, function() {
91
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
92
+ args[_key] = arguments[_key];
93
+ }
94
+ const nodeView = createNodeView(...args);
95
+ const contentDOM = nodeView.contentDOM;
96
+ const nodeDOM = nodeView.dom;
97
+ const wrapperDOM = innerRef.current ?? ref.current;
98
+ wrapperDOM.appendChild(nodeDOM);
99
+ if (!contentDOM && nodeDOM instanceof HTMLElement && nodeDOM.tagName !== "BR") {
100
+ if (!nodeDOM.hasAttribute("contenteditable")) {
101
+ nodeDOM.contentEditable = "false";
102
+ }
103
+ if (node.type.spec.draggable) {
104
+ nodeDOM.draggable = true;
105
+ }
106
+ }
107
+ return {
108
+ ...nodeView,
109
+ destroy () {
110
+ if (nodeView.destroy) {
111
+ nodeView.destroy();
112
+ }
113
+ wrapperDOM.removeChild(nodeDOM);
114
+ },
115
+ selectNode: nodeView.selectNode?.bind(nodeView),
116
+ deselectNode: nodeView.deselectNode?.bind(nodeView),
117
+ stopEvent: nodeView.stopEvent?.bind(nodeView),
118
+ ignoreMutation: nodeView.ignoreMutation?.bind(nodeView)
119
+ };
120
+ }, (source)=>source?.contentDOM ?? null, nodeProps);
121
+ const Component = node.isInline ? "span" : "div";
122
+ const props = {
123
+ ref: innerRef
124
+ };
125
+ const children = !node.isLeaf && contentDOM ? /*#__PURE__*/ (0, _reactdom.createPortal)(/*#__PURE__*/ _react.default.createElement(_ChildDescriptionsContext.ChildDescriptionsContext.Provider, {
126
+ value: childContextValue
127
+ }, /*#__PURE__*/ _react.default.createElement(_ChildNodeViews.ChildNodeViews, {
128
+ getPos: getPos,
129
+ node: node,
130
+ innerDecorations: innerDeco
131
+ })), contentDOM) : null;
132
+ return /*#__PURE__*/ (0, _react.cloneElement)(outerDeco.reduce(_ChildNodeViews.wrapInDeco, /*#__PURE__*/ _react.default.createElement(Component, props, children)), {
133
+ ref
134
+ });
135
+ });
@@ -191,7 +191,7 @@ const ReactNodeView = /*#__PURE__*/ (0, _react.memo)(function ReactNodeView(para
191
191
  ...!hasCustomSelectNode && selected ? {
192
192
  className: "ProseMirror-selectednode"
193
193
  } : null,
194
- ...!hasCustomSelectNode && selected || node.type.spec.draggable ? {
194
+ ...!hasCustomSelectNode && selected || !contentDOMRef.current && !nodeProps.node.isText && domRef.current?.nodeName !== "BR" && node.type.spec.draggable ? {
195
195
  draggable: true
196
196
  } : null,
197
197
  ref: setNodeDOM
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "ChildDescriptorsContext", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return ChildDescriptorsContext;
9
+ }
10
+ });
11
+ const _react = require("react");
12
+ const ChildDescriptorsContext = (0, _react.createContext)({
13
+ parentRef: {
14
+ current: undefined
15
+ },
16
+ siblingsRef: {
17
+ current: []
18
+ }
19
+ });
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "useNodeViewDescriptor", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return useNodeViewDescriptor;
9
+ }
10
+ });
11
+ const _react = require("react");
12
+ const _ReactEditorView = require("../ReactEditorView.js");
13
+ const _ChildDescriptorsContext = require("../contexts/ChildDescriptorsContext.js");
14
+ const _EditorContext = require("../contexts/EditorContext.js");
15
+ const _viewdesc = require("../viewdesc.js");
16
+ const _useClientLayoutEffect = require("./useClientLayoutEffect.js");
17
+ const _useEffectEvent = require("./useEffectEvent.js");
18
+ function findContentDOM(view, source, children) {
19
+ // When a composition is happening, we want to essentially freeze everything,
20
+ // so we maintain the current contentDOM.
21
+ return view.composing ? source?.contentDOM ?? null : children[0]?.dom?.parentElement ?? null;
22
+ }
23
+ function useNodeViewDescriptor(ref, constructor, props) {
24
+ const { view } = (0, _react.useContext)(_EditorContext.EditorContext);
25
+ const { parentRef, siblingsRef } = (0, _react.useContext)(_ChildDescriptorsContext.ChildDescriptorsContext);
26
+ const [dom, setDOM] = (0, _react.useState)(null);
27
+ const [nodeDOM, setNodeDOM] = (0, _react.useState)(null);
28
+ const [contentDOM, setContentDOM] = (0, _react.useState)(null);
29
+ const viewDescRef = (0, _react.useRef)();
30
+ const childrenRef = (0, _react.useRef)([]);
31
+ const create = (0, _useEffectEvent.useEffectEvent)(()=>{
32
+ if (!(view instanceof _ReactEditorView.ReactEditorView)) {
33
+ return;
34
+ }
35
+ const dom = ref.current;
36
+ if (!dom) {
37
+ return;
38
+ }
39
+ const { node, getPos, decorations, innerDecorations } = props;
40
+ const nodeView = constructor(node, view, getPos, decorations, innerDecorations);
41
+ if (!nodeView) {
42
+ return;
43
+ }
44
+ const parent = parentRef.current;
45
+ const children = childrenRef.current;
46
+ const contentDOM = findContentDOM(view, nodeView, children);
47
+ const nodeDOM = nodeView.dom;
48
+ const viewDesc = new _viewdesc.ReactNodeViewDesc(parent, children, getPos, node, decorations, innerDecorations, dom, contentDOM, nodeDOM, nodeView);
49
+ setDOM(dom);
50
+ setContentDOM(contentDOM);
51
+ setNodeDOM(nodeDOM);
52
+ return viewDesc;
53
+ });
54
+ const update = (0, _useEffectEvent.useEffectEvent)(()=>{
55
+ if (!(view instanceof _ReactEditorView.ReactEditorView)) {
56
+ return false;
57
+ }
58
+ const viewDesc = viewDescRef.current;
59
+ if (!viewDesc) {
60
+ return false;
61
+ }
62
+ const dom = ref.current;
63
+ if (!dom || dom !== viewDesc.dom) {
64
+ return false;
65
+ }
66
+ const contentDOM = findContentDOM(view, viewDesc, viewDesc.children);
67
+ if (contentDOM !== viewDesc.contentDOM) {
68
+ return false;
69
+ }
70
+ if (!dom.contains(viewDesc.nodeDOM)) {
71
+ return false;
72
+ }
73
+ const { node, decorations, innerDecorations } = props;
74
+ return viewDesc.matchesNode(node, decorations, innerDecorations) || viewDesc.update(node, decorations, innerDecorations, view);
75
+ });
76
+ const destroy = (0, _useEffectEvent.useEffectEvent)(()=>{
77
+ const viewDesc = viewDescRef.current;
78
+ if (!viewDesc) {
79
+ return;
80
+ }
81
+ viewDesc.destroy();
82
+ const siblings = siblingsRef.current;
83
+ if (siblings.includes(viewDesc)) {
84
+ const index = siblings.indexOf(viewDesc);
85
+ siblings.splice(index, 1);
86
+ }
87
+ setDOM(null);
88
+ setContentDOM(null);
89
+ setNodeDOM(null);
90
+ });
91
+ (0, _useClientLayoutEffect.useClientLayoutEffect)(()=>{
92
+ viewDescRef.current = create();
93
+ return ()=>{
94
+ destroy();
95
+ };
96
+ }, [
97
+ create,
98
+ destroy
99
+ ]);
100
+ (0, _useClientLayoutEffect.useClientLayoutEffect)(()=>{
101
+ if (!update()) {
102
+ destroy();
103
+ viewDescRef.current = create();
104
+ }
105
+ const viewDesc = viewDescRef.current;
106
+ if (!viewDesc) {
107
+ return;
108
+ }
109
+ if (view.dom === viewDesc.dom && view instanceof _ReactEditorView.ReactEditorView) {
110
+ view.docView = viewDesc;
111
+ }
112
+ const parent = parentRef.current;
113
+ const siblings = siblingsRef.current;
114
+ const children = childrenRef.current;
115
+ viewDesc.parent = parent;
116
+ if (!siblings.includes(viewDesc)) {
117
+ siblings.push(viewDesc);
118
+ }
119
+ siblings.sort(_viewdesc.sortViewDescs);
120
+ for (const child of children){
121
+ child.parent = viewDesc;
122
+ // Because TextNodeViews can't locate the DOM nodes
123
+ // for compositions, we need to override them here
124
+ if (child instanceof _viewdesc.CompositionViewDesc) {
125
+ const compositionTopDOM = viewDesc?.contentDOM?.firstChild;
126
+ if (!compositionTopDOM) throw new Error(`Started a composition but couldn't find the text node it belongs to.`);
127
+ let textDOM = compositionTopDOM;
128
+ while(textDOM.firstChild){
129
+ textDOM = textDOM.firstChild;
130
+ }
131
+ if (!textDOM || !(textDOM instanceof Text)) throw new Error(`Started a composition but couldn't find the text node it belongs to.`);
132
+ child.dom = compositionTopDOM;
133
+ child.textDOM = textDOM;
134
+ child.text = textDOM.data;
135
+ child.textDOM.pmViewDesc = child;
136
+ // It should not be possible to be in a composition because one could
137
+ // not start between the renders that switch the view type.
138
+ view.input.compositionNodes.push(child);
139
+ }
140
+ }
141
+ });
142
+ const childContextValue = (0, _react.useMemo)(()=>({
143
+ parentRef: viewDescRef,
144
+ siblingsRef: childrenRef
145
+ }), [
146
+ childrenRef,
147
+ viewDescRef
148
+ ]);
149
+ return {
150
+ childContextValue,
151
+ dom,
152
+ contentDOM,
153
+ nodeDOM,
154
+ ref
155
+ };
156
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "ReactProseMirrorNodeView", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return ReactProseMirrorNodeView;
9
+ }
10
+ });
11
+ const _core = require("@tiptap/core");
12
+ let ReactProseMirrorNodeView = class ReactProseMirrorNodeView extends _core.NodeView {
13
+ _dom;
14
+ _contentDOM;
15
+ constructor(component, props, dom, contentDOM, options){
16
+ super(component, props, options);
17
+ this._dom = dom;
18
+ this._contentDOM = contentDOM;
19
+ }
20
+ get dom() {
21
+ return this._dom;
22
+ }
23
+ get contentDOM() {
24
+ return this._contentDOM;
25
+ }
26
+ };
@@ -17,6 +17,7 @@ const _useIgnoreMutation = require("../hooks/useIgnoreMutation.js");
17
17
  const _useIsNodeSelected = require("../hooks/useIsNodeSelected.js");
18
18
  const _useStopEvent = require("../hooks/useStopEvent.js");
19
19
  const _props = require("../props.js");
20
+ const _refs = require("../refs.js");
20
21
  const _ReactProseMirrorNodeView = require("./ReactProseMirrorNodeView.js");
21
22
  const _useTiptapEditorEventCallback = require("./hooks/useTiptapEditorEventCallback.js");
22
23
  function _interop_require_default(obj) {
@@ -75,6 +76,7 @@ function tiptapNodeView(param) {
75
76
  const extensionManager = editor?.extensionManager ?? null;
76
77
  const extensions = extensionManager?.extensions ?? null;
77
78
  const selected = (0, _useIsNodeSelected.useIsNodeSelected)();
79
+ const isDraggingRef = (0, _react1.useRef)(false);
78
80
  const htmlAttributes = (0, _react1.useMemo)(()=>{
79
81
  if (!extensions) return {};
80
82
  const attributes = (0, _core.getAttributesFromExtensions)(extensions);
@@ -105,7 +107,10 @@ function tiptapNodeView(param) {
105
107
  node,
106
108
  view: editor.view
107
109
  }, this.dom, this.contentDOM);
108
- return nodeView.stopEvent(event) ?? false;
110
+ nodeView.isDragging = isDraggingRef.current;
111
+ const result = nodeView.stopEvent(event) ?? false;
112
+ isDraggingRef.current = nodeView.isDragging;
113
+ return result;
109
114
  });
110
115
  (0, _useIgnoreMutation.useIgnoreMutation)(function(_, mutation) {
111
116
  if (ignoreMutation) {
@@ -184,12 +189,10 @@ function tiptapNodeView(param) {
184
189
  contentDOMRef,
185
190
  node.type.name
186
191
  ]);
192
+ const innerRef = (0, _react1.useRef)(null);
193
+ const finalRef = (0, _refs.useMergedDOMRefs)(ref, innerRef);
187
194
  const onDragStart = (0, _useTiptapEditorEventCallback.useTiptapEditorEventCallback)((editor, event)=>{
188
- // TODO: We should probably just merge this with our own
189
- // ref, I'm being lazy since we are providing this
190
- // ref in the first place (in ReactNodeView), so we know
191
- // it's an object
192
- const dom = typeof ref === "object" ? ref?.current : null;
195
+ const dom = innerRef.current;
193
196
  if (!dom) return;
194
197
  const viewDesc = dom.pmViewDesc;
195
198
  if (!viewDesc) return;
@@ -216,7 +219,7 @@ function tiptapNodeView(param) {
216
219
  return /*#__PURE__*/ _react1.default.createElement(_react.ReactNodeViewContext.Provider, {
217
220
  value: nodeViewContext
218
221
  }, /*#__PURE__*/ _react1.default.createElement(OuterTag, {
219
- ref: ref,
222
+ ref: finalRef,
220
223
  ...props,
221
224
  ...htmlProps,
222
225
  className: finalClassName