@handlewithcare/react-prosemirror 2.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.
- package/LICENSE.txt +12 -0
- package/README.md +705 -0
- package/dist/cjs/browser.js +53 -0
- package/dist/cjs/components/ChildNodeViews.js +376 -0
- package/dist/cjs/components/CursorWrapper.js +91 -0
- package/dist/cjs/components/CustomNodeView.js +79 -0
- package/dist/cjs/components/DocNodeView.js +104 -0
- package/dist/cjs/components/LayoutGroup.js +111 -0
- package/dist/cjs/components/MarkView.js +115 -0
- package/dist/cjs/components/NativeWidgetView.js +109 -0
- package/dist/cjs/components/NodeView.js +196 -0
- package/dist/cjs/components/NodeViewComponentProps.js +4 -0
- package/dist/cjs/components/OutputSpec.js +88 -0
- package/dist/cjs/components/ProseMirror.js +103 -0
- package/dist/cjs/components/ProseMirrorDoc.js +92 -0
- package/dist/cjs/components/SeparatorHackView.js +100 -0
- package/dist/cjs/components/TextNodeView.js +112 -0
- package/dist/cjs/components/TrailingHackView.js +90 -0
- package/dist/cjs/components/WidgetView.js +95 -0
- package/dist/cjs/components/WidgetViewComponentProps.js +4 -0
- package/dist/cjs/components/__tests__/ProseMirror.composition.test.js +398 -0
- package/dist/cjs/components/__tests__/ProseMirror.domchange.test.js +270 -0
- package/dist/cjs/components/__tests__/ProseMirror.draw-decoration.test.js +1010 -0
- package/dist/cjs/components/__tests__/ProseMirror.draw.test.js +337 -0
- package/dist/cjs/components/__tests__/ProseMirror.node-view.test.js +315 -0
- package/dist/cjs/components/__tests__/ProseMirror.selection.test.js +444 -0
- package/dist/cjs/components/__tests__/ProseMirror.test.js +382 -0
- package/dist/cjs/contexts/ChildDescriptorsContext.js +19 -0
- package/dist/cjs/contexts/EditorContext.js +12 -0
- package/dist/cjs/contexts/EditorStateContext.js +12 -0
- package/dist/cjs/contexts/LayoutGroupContext.js +12 -0
- package/dist/cjs/contexts/NodeViewContext.js +12 -0
- package/dist/cjs/contexts/SelectNodeContext.js +12 -0
- package/dist/cjs/contexts/StopEventContext.js +12 -0
- package/dist/cjs/contexts/__tests__/DeferredLayoutEffects.test.js +141 -0
- package/dist/cjs/decorations/ReactWidgetType.js +58 -0
- package/dist/cjs/decorations/computeDocDeco.js +44 -0
- package/dist/cjs/decorations/internalTypes.js +4 -0
- package/dist/cjs/decorations/iterDeco.js +79 -0
- package/dist/cjs/decorations/viewDecorations.js +163 -0
- package/dist/cjs/dom.js +142 -0
- package/dist/cjs/hooks/__tests__/useEditorViewLayoutEffect.test.js +108 -0
- package/dist/cjs/hooks/useClientOnly.js +18 -0
- package/dist/cjs/hooks/useComponentEventListeners.js +39 -0
- package/dist/cjs/hooks/useEditor.js +287 -0
- package/dist/cjs/hooks/useEditorEffect.js +35 -0
- package/dist/cjs/hooks/useEditorEventCallback.js +33 -0
- package/dist/cjs/hooks/useEditorEventListener.js +34 -0
- package/dist/cjs/hooks/useEditorState.js +16 -0
- package/dist/cjs/hooks/useForceUpdate.js +15 -0
- package/dist/cjs/hooks/useLayoutGroupEffect.js +19 -0
- package/dist/cjs/hooks/useNodeViewDescriptor.js +115 -0
- package/dist/cjs/hooks/useReactKeys.js +17 -0
- package/dist/cjs/hooks/useSelectNode.js +28 -0
- package/dist/cjs/hooks/useStopEvent.js +24 -0
- package/dist/cjs/index.js +53 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/plugins/__tests__/reactKeys.test.js +81 -0
- package/dist/cjs/plugins/beforeInputPlugin.js +143 -0
- package/dist/cjs/plugins/componentEventListeners.js +35 -0
- package/dist/cjs/plugins/componentEventListenersPlugin.js +35 -0
- package/dist/cjs/plugins/reactKeys.js +96 -0
- package/dist/cjs/props.js +269 -0
- package/dist/cjs/selection/SelectionDOMObserver.js +174 -0
- package/dist/cjs/selection/hasFocusAndSelection.js +35 -0
- package/dist/cjs/selection/selectionFromDOM.js +77 -0
- package/dist/cjs/selection/selectionToDOM.js +226 -0
- package/dist/cjs/ssr.js +85 -0
- package/dist/cjs/testing/editorViewTestHelpers.js +111 -0
- package/dist/cjs/testing/setupProseMirrorView.js +94 -0
- package/dist/cjs/viewdesc.js +664 -0
- package/dist/esm/browser.js +43 -0
- package/dist/esm/components/ChildNodeViews.js +318 -0
- package/dist/esm/components/CursorWrapper.js +40 -0
- package/dist/esm/components/CustomNodeView.js +28 -0
- package/dist/esm/components/DocNodeView.js +53 -0
- package/dist/esm/components/LayoutGroup.js +66 -0
- package/dist/esm/components/MarkView.js +64 -0
- package/dist/esm/components/NativeWidgetView.js +58 -0
- package/dist/esm/components/NodeView.js +145 -0
- package/dist/esm/components/NodeViewComponentProps.js +1 -0
- package/dist/esm/components/OutputSpec.js +38 -0
- package/dist/esm/components/ProseMirror.js +52 -0
- package/dist/esm/components/ProseMirrorDoc.js +34 -0
- package/dist/esm/components/SeparatorHackView.js +49 -0
- package/dist/esm/components/TextNodeView.js +102 -0
- package/dist/esm/components/TrailingHackView.js +39 -0
- package/dist/esm/components/WidgetView.js +44 -0
- package/dist/esm/components/WidgetViewComponentProps.js +1 -0
- package/dist/esm/components/__tests__/ProseMirror.composition.test.js +395 -0
- package/dist/esm/components/__tests__/ProseMirror.domchange.test.js +266 -0
- package/dist/esm/components/__tests__/ProseMirror.draw-decoration.test.js +967 -0
- package/dist/esm/components/__tests__/ProseMirror.draw.test.js +294 -0
- package/dist/esm/components/__tests__/ProseMirror.node-view.test.js +272 -0
- package/dist/esm/components/__tests__/ProseMirror.selection.test.js +440 -0
- package/dist/esm/components/__tests__/ProseMirror.test.js +339 -0
- package/dist/esm/contexts/ChildDescriptorsContext.js +9 -0
- package/dist/esm/contexts/EditorContext.js +7 -0
- package/dist/esm/contexts/EditorStateContext.js +2 -0
- package/dist/esm/contexts/LayoutGroupContext.js +2 -0
- package/dist/esm/contexts/NodeViewContext.js +2 -0
- package/dist/esm/contexts/SelectNodeContext.js +2 -0
- package/dist/esm/contexts/StopEventContext.js +2 -0
- package/dist/esm/contexts/__tests__/DeferredLayoutEffects.test.js +98 -0
- package/dist/esm/decorations/ReactWidgetType.js +40 -0
- package/dist/esm/decorations/computeDocDeco.js +44 -0
- package/dist/esm/decorations/internalTypes.js +1 -0
- package/dist/esm/decorations/iterDeco.js +73 -0
- package/dist/esm/decorations/viewDecorations.js +163 -0
- package/dist/esm/dom.js +105 -0
- package/dist/esm/hooks/__tests__/useEditorViewLayoutEffect.test.js +99 -0
- package/dist/esm/hooks/useClientOnly.js +8 -0
- package/dist/esm/hooks/useComponentEventListeners.js +54 -0
- package/dist/esm/hooks/useEditor.js +278 -0
- package/dist/esm/hooks/useEditorEffect.js +38 -0
- package/dist/esm/hooks/useEditorEventCallback.js +35 -0
- package/dist/esm/hooks/useEditorEventListener.js +28 -0
- package/dist/esm/hooks/useEditorState.js +8 -0
- package/dist/esm/hooks/useForceUpdate.js +8 -0
- package/dist/esm/hooks/useLayoutGroupEffect.js +9 -0
- package/dist/esm/hooks/useNodeViewDescriptor.js +105 -0
- package/dist/esm/hooks/useReactKeys.js +7 -0
- package/dist/esm/hooks/useSelectNode.js +18 -0
- package/dist/esm/hooks/useStopEvent.js +14 -0
- package/dist/esm/index.js +11 -0
- package/dist/esm/plugins/__tests__/reactKeys.test.js +77 -0
- package/dist/esm/plugins/beforeInputPlugin.js +133 -0
- package/dist/esm/plugins/componentEventListeners.js +25 -0
- package/dist/esm/plugins/componentEventListenersPlugin.js +25 -0
- package/dist/esm/plugins/reactKeys.js +81 -0
- package/dist/esm/props.js +251 -0
- package/dist/esm/selection/SelectionDOMObserver.js +164 -0
- package/dist/esm/selection/hasFocusAndSelection.js +17 -0
- package/dist/esm/selection/selectionFromDOM.js +59 -0
- package/dist/esm/selection/selectionToDOM.js +196 -0
- package/dist/esm/ssr.js +82 -0
- package/dist/esm/testing/editorViewTestHelpers.js +88 -0
- package/dist/esm/testing/setupProseMirrorView.js +76 -0
- package/dist/esm/viewdesc.js +654 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/browser.d.ts +15 -0
- package/dist/types/components/ChildNodeViews.d.ts +9 -0
- package/dist/types/components/CursorWrapper.d.ts +5 -0
- package/dist/types/components/CustomNodeView.d.ts +21 -0
- package/dist/types/components/DocNodeView.d.ts +20 -0
- package/dist/types/components/LayoutGroup.d.ts +12 -0
- package/dist/types/components/MarkView.d.ts +9 -0
- package/dist/types/components/NativeWidgetView.d.ts +8 -0
- package/dist/types/components/NodeView.d.ts +11 -0
- package/dist/types/components/NodeViewComponentProps.d.ts +12 -0
- package/dist/types/components/OutputSpec.d.ts +8 -0
- package/dist/types/components/ProseMirror.d.ts +15 -0
- package/dist/types/components/ProseMirrorDoc.d.ts +10 -0
- package/dist/types/components/SeparatorHackView.d.ts +6 -0
- package/dist/types/components/TextNodeView.d.ts +23 -0
- package/dist/types/components/TrailingHackView.d.ts +6 -0
- package/dist/types/components/WidgetView.d.ts +8 -0
- package/dist/types/components/WidgetViewComponentProps.d.ts +6 -0
- package/dist/types/components/__tests__/ProseMirror.composition.test.d.ts +1 -0
- package/dist/types/components/__tests__/ProseMirror.domchange.test.d.ts +1 -0
- package/dist/types/components/__tests__/ProseMirror.draw-decoration.test.d.ts +1 -0
- package/dist/types/components/__tests__/ProseMirror.draw.test.d.ts +1 -0
- package/dist/types/components/__tests__/ProseMirror.node-view.test.d.ts +1 -0
- package/dist/types/components/__tests__/ProseMirror.selection.test.d.ts +1 -0
- package/dist/types/components/__tests__/ProseMirror.test.d.ts +1 -0
- package/dist/types/contexts/ChildDescriptorsContext.d.ts +6 -0
- package/dist/types/contexts/EditorContext.d.ts +14 -0
- package/dist/types/contexts/EditorStateContext.d.ts +2 -0
- package/dist/types/contexts/LayoutGroupContext.d.ts +5 -0
- package/dist/types/contexts/NodeViewContext.d.ts +6 -0
- package/dist/types/contexts/SelectNodeContext.d.ts +3 -0
- package/dist/types/contexts/StopEventContext.d.ts +3 -0
- package/dist/types/contexts/__tests__/DeferredLayoutEffects.test.d.ts +1 -0
- package/dist/types/decorations/ReactWidgetType.d.ts +39 -0
- package/dist/types/decorations/computeDocDeco.d.ts +13 -0
- package/dist/types/decorations/internalTypes.d.ts +16 -0
- package/dist/types/decorations/iterDeco.d.ts +3 -0
- package/dist/types/decorations/viewDecorations.d.ts +13 -0
- package/dist/types/dom.d.ts +22 -0
- package/dist/types/hooks/__tests__/useEditorViewLayoutEffect.test.d.ts +1 -0
- package/dist/types/hooks/useClientOnly.d.ts +1 -0
- package/dist/types/hooks/useComponentEventListeners.d.ts +33 -0
- package/dist/types/hooks/useEditor.d.ts +66 -0
- package/dist/types/hooks/useEditorEffect.d.ts +17 -0
- package/dist/types/hooks/useEditorEventCallback.d.ts +15 -0
- package/dist/types/hooks/useEditorEventListener.d.ts +8 -0
- package/dist/types/hooks/useEditorState.d.ts +5 -0
- package/dist/types/hooks/useForceUpdate.d.ts +5 -0
- package/dist/types/hooks/useLayoutGroupEffect.d.ts +3 -0
- package/dist/types/hooks/useNodeViewDescriptor.d.ts +11 -0
- package/dist/types/hooks/useReactKeys.d.ts +5 -0
- package/dist/types/hooks/useSelectNode.d.ts +1 -0
- package/dist/types/hooks/useStopEvent.d.ts +2 -0
- package/dist/types/index.d.ts +12 -0
- package/dist/types/plugins/__tests__/reactKeys.test.d.ts +1 -0
- package/dist/types/plugins/beforeInputPlugin.d.ts +3 -0
- package/dist/types/plugins/componentEventListeners.d.ts +4 -0
- package/dist/types/plugins/componentEventListenersPlugin.d.ts +4 -0
- package/dist/types/plugins/reactKeys.d.ts +19 -0
- package/dist/types/props.d.ts +1174 -0
- package/dist/types/selection/SelectionDOMObserver.d.ts +34 -0
- package/dist/types/selection/hasFocusAndSelection.d.ts +3 -0
- package/dist/types/selection/selectionFromDOM.d.ts +4 -0
- package/dist/types/selection/selectionToDOM.d.ts +9 -0
- package/dist/types/ssr.d.ts +19 -0
- package/dist/types/testing/editorViewTestHelpers.d.ts +23 -0
- package/dist/types/testing/setupProseMirrorView.d.ts +2 -0
- package/dist/types/viewdesc.d.ts +131 -0
- package/package.json +113 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// TODO: I must be missing something, but I do not know why
|
|
2
|
+
// this linting rule is only broken in this file
|
|
3
|
+
/* eslint-disable react/prop-types */ "use strict";
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
Object.defineProperty(exports, "DocNodeView", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function() {
|
|
10
|
+
return DocNodeView;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
14
|
+
const _ChildDescriptorsContext = require("../contexts/ChildDescriptorsContext.js");
|
|
15
|
+
const _useNodeViewDescriptor = require("../hooks/useNodeViewDescriptor.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 getPos = {
|
|
59
|
+
current () {
|
|
60
|
+
return -1;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const DocNodeView = /*#__PURE__*/ (0, _react.memo)(/*#__PURE__*/ (0, _react.forwardRef)(function DocNodeView(param, ref) {
|
|
64
|
+
let { className, node, innerDeco, outerDeco, as, viewDesc, ...elementProps } = param;
|
|
65
|
+
const innerRef = (0, _react.useRef)(null);
|
|
66
|
+
(0, _react.useImperativeHandle)(ref, ()=>{
|
|
67
|
+
return innerRef.current;
|
|
68
|
+
}, []);
|
|
69
|
+
const { childDescriptors, nodeViewDescRef } = (0, _useNodeViewDescriptor.useNodeViewDescriptor)(node, ()=>getPos.current(), innerRef, innerRef, innerDeco, outerDeco, viewDesc);
|
|
70
|
+
const childContextValue = (0, _react.useMemo)(()=>({
|
|
71
|
+
parentRef: nodeViewDescRef,
|
|
72
|
+
siblingsRef: childDescriptors
|
|
73
|
+
}), [
|
|
74
|
+
childDescriptors,
|
|
75
|
+
nodeViewDescRef
|
|
76
|
+
]);
|
|
77
|
+
const props = {
|
|
78
|
+
...elementProps,
|
|
79
|
+
ref: innerRef,
|
|
80
|
+
className,
|
|
81
|
+
suppressContentEditableWarning: true
|
|
82
|
+
};
|
|
83
|
+
const element = as ? /*#__PURE__*/ (0, _react.cloneElement)(as, props, /*#__PURE__*/ _react.default.createElement(_ChildDescriptorsContext.ChildDescriptorsContext.Provider, {
|
|
84
|
+
value: childContextValue
|
|
85
|
+
}, /*#__PURE__*/ _react.default.createElement(_ChildNodeViews.ChildNodeViews, {
|
|
86
|
+
getPos: getPos,
|
|
87
|
+
node: node,
|
|
88
|
+
innerDecorations: innerDeco
|
|
89
|
+
}))) : /*#__PURE__*/ (0, _react.createElement)("div", props, /*#__PURE__*/ _react.default.createElement(_ChildDescriptorsContext.ChildDescriptorsContext.Provider, {
|
|
90
|
+
value: childContextValue
|
|
91
|
+
}, /*#__PURE__*/ _react.default.createElement(_ChildNodeViews.ChildNodeViews, {
|
|
92
|
+
getPos: getPos,
|
|
93
|
+
node: node,
|
|
94
|
+
innerDecorations: innerDeco
|
|
95
|
+
})));
|
|
96
|
+
if (!node) return element;
|
|
97
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
98
|
+
const nodeDecorations = outerDeco.filter((deco)=>!deco.inline);
|
|
99
|
+
if (!nodeDecorations.length) {
|
|
100
|
+
return element;
|
|
101
|
+
}
|
|
102
|
+
const wrapped = nodeDecorations.reduce(_ChildNodeViews.wrapInDeco, element);
|
|
103
|
+
return wrapped;
|
|
104
|
+
}));
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/* Copyright (c) The New York Times Company */ "use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "LayoutGroup", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return LayoutGroup;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
12
|
+
const _LayoutGroupContext = require("../contexts/LayoutGroupContext.js");
|
|
13
|
+
const _useForceUpdate = require("../hooks/useForceUpdate.js");
|
|
14
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
15
|
+
if (typeof WeakMap !== "function") return null;
|
|
16
|
+
var cacheBabelInterop = new WeakMap();
|
|
17
|
+
var cacheNodeInterop = new WeakMap();
|
|
18
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
19
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
20
|
+
})(nodeInterop);
|
|
21
|
+
}
|
|
22
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
23
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
24
|
+
return obj;
|
|
25
|
+
}
|
|
26
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
27
|
+
return {
|
|
28
|
+
default: obj
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
32
|
+
if (cache && cache.has(obj)) {
|
|
33
|
+
return cache.get(obj);
|
|
34
|
+
}
|
|
35
|
+
var newObj = {
|
|
36
|
+
__proto__: null
|
|
37
|
+
};
|
|
38
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
39
|
+
for(var key in obj){
|
|
40
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
41
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
42
|
+
if (desc && (desc.get || desc.set)) {
|
|
43
|
+
Object.defineProperty(newObj, key, desc);
|
|
44
|
+
} else {
|
|
45
|
+
newObj[key] = obj[key];
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
newObj.default = obj;
|
|
50
|
+
if (cache) {
|
|
51
|
+
cache.set(obj, newObj);
|
|
52
|
+
}
|
|
53
|
+
return newObj;
|
|
54
|
+
}
|
|
55
|
+
function LayoutGroup(param) {
|
|
56
|
+
let { children } = param;
|
|
57
|
+
const createQueue = (0, _react.useRef)(new Set()).current;
|
|
58
|
+
const destroyQueue = (0, _react.useRef)(new Set()).current;
|
|
59
|
+
const isMounted = (0, _react.useRef)(false);
|
|
60
|
+
const forceUpdate = (0, _useForceUpdate.useForceUpdate)();
|
|
61
|
+
const isUpdatePending = (0, _react.useRef)(true);
|
|
62
|
+
const ensureFlush = (0, _react.useCallback)(()=>{
|
|
63
|
+
if (!isUpdatePending.current) {
|
|
64
|
+
forceUpdate();
|
|
65
|
+
isUpdatePending.current = true;
|
|
66
|
+
}
|
|
67
|
+
}, [
|
|
68
|
+
forceUpdate
|
|
69
|
+
]);
|
|
70
|
+
const register = (0, _react.useCallback)((effect)=>{
|
|
71
|
+
let destroy;
|
|
72
|
+
const create = ()=>{
|
|
73
|
+
destroy = effect();
|
|
74
|
+
};
|
|
75
|
+
createQueue.add(create);
|
|
76
|
+
ensureFlush();
|
|
77
|
+
return ()=>{
|
|
78
|
+
createQueue.delete(create);
|
|
79
|
+
if (destroy) {
|
|
80
|
+
if (isMounted.current) {
|
|
81
|
+
destroyQueue.add(destroy);
|
|
82
|
+
ensureFlush();
|
|
83
|
+
} else {
|
|
84
|
+
destroy();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
}, [
|
|
89
|
+
createQueue,
|
|
90
|
+
destroyQueue,
|
|
91
|
+
ensureFlush
|
|
92
|
+
]);
|
|
93
|
+
(0, _react.useLayoutEffect)(()=>{
|
|
94
|
+
isUpdatePending.current = false;
|
|
95
|
+
createQueue.forEach((create)=>create());
|
|
96
|
+
createQueue.clear();
|
|
97
|
+
return ()=>{
|
|
98
|
+
destroyQueue.forEach((destroy)=>destroy());
|
|
99
|
+
destroyQueue.clear();
|
|
100
|
+
};
|
|
101
|
+
});
|
|
102
|
+
(0, _react.useLayoutEffect)(()=>{
|
|
103
|
+
isMounted.current = true;
|
|
104
|
+
return ()=>{
|
|
105
|
+
isMounted.current = false;
|
|
106
|
+
};
|
|
107
|
+
}, []);
|
|
108
|
+
return /*#__PURE__*/ _react.default.createElement(_LayoutGroupContext.LayoutGroupContext.Provider, {
|
|
109
|
+
value: register
|
|
110
|
+
}, children);
|
|
111
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
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 _viewdesc = require("../viewdesc.js");
|
|
14
|
+
const _OutputSpec = require("./OutputSpec.js");
|
|
15
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
16
|
+
if (typeof WeakMap !== "function") return null;
|
|
17
|
+
var cacheBabelInterop = new WeakMap();
|
|
18
|
+
var cacheNodeInterop = new WeakMap();
|
|
19
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
20
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
21
|
+
})(nodeInterop);
|
|
22
|
+
}
|
|
23
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
24
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
25
|
+
return obj;
|
|
26
|
+
}
|
|
27
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
28
|
+
return {
|
|
29
|
+
default: obj
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
33
|
+
if (cache && cache.has(obj)) {
|
|
34
|
+
return cache.get(obj);
|
|
35
|
+
}
|
|
36
|
+
var newObj = {
|
|
37
|
+
__proto__: null
|
|
38
|
+
};
|
|
39
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
40
|
+
for(var key in obj){
|
|
41
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
42
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
43
|
+
if (desc && (desc.get || desc.set)) {
|
|
44
|
+
Object.defineProperty(newObj, key, desc);
|
|
45
|
+
} else {
|
|
46
|
+
newObj[key] = obj[key];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
newObj.default = obj;
|
|
51
|
+
if (cache) {
|
|
52
|
+
cache.set(obj, newObj);
|
|
53
|
+
}
|
|
54
|
+
return newObj;
|
|
55
|
+
}
|
|
56
|
+
const MarkView = /*#__PURE__*/ (0, _react.memo)(/*#__PURE__*/ (0, _react.forwardRef)(function MarkView(param, ref) {
|
|
57
|
+
let { mark, getPos, children } = param;
|
|
58
|
+
const { siblingsRef, parentRef } = (0, _react.useContext)(_ChildDescriptorsContext.ChildDescriptorsContext);
|
|
59
|
+
const viewDescRef = (0, _react.useRef)(undefined);
|
|
60
|
+
const childDescriptors = (0, _react.useRef)([]);
|
|
61
|
+
const domRef = (0, _react.useRef)(null);
|
|
62
|
+
(0, _react.useImperativeHandle)(ref, ()=>{
|
|
63
|
+
return domRef.current;
|
|
64
|
+
}, []);
|
|
65
|
+
const outputSpec = (0, _react.useMemo)(()=>mark.type.spec.toDOM?.(mark, true), [
|
|
66
|
+
mark
|
|
67
|
+
]);
|
|
68
|
+
if (!outputSpec) throw new Error(`Mark spec for ${mark.type.name} is missing toDOM`);
|
|
69
|
+
(0, _react.useLayoutEffect)(()=>{
|
|
70
|
+
const siblings = siblingsRef.current;
|
|
71
|
+
return ()=>{
|
|
72
|
+
if (!viewDescRef.current) return;
|
|
73
|
+
if (siblings.includes(viewDescRef.current)) {
|
|
74
|
+
const index = siblings.indexOf(viewDescRef.current);
|
|
75
|
+
siblings.splice(index, 1);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
}, [
|
|
79
|
+
siblingsRef
|
|
80
|
+
]);
|
|
81
|
+
(0, _react.useLayoutEffect)(()=>{
|
|
82
|
+
if (!domRef.current) return;
|
|
83
|
+
const firstChildDesc = childDescriptors.current[0];
|
|
84
|
+
if (!viewDescRef.current) {
|
|
85
|
+
viewDescRef.current = new _viewdesc.MarkViewDesc(parentRef.current, childDescriptors.current, ()=>getPos.current(), mark, domRef.current, firstChildDesc?.dom.parentElement ?? domRef.current);
|
|
86
|
+
} else {
|
|
87
|
+
viewDescRef.current.parent = parentRef.current;
|
|
88
|
+
viewDescRef.current.dom = domRef.current;
|
|
89
|
+
viewDescRef.current.children = childDescriptors.current;
|
|
90
|
+
viewDescRef.current.contentDOM = firstChildDesc?.dom.parentElement ?? domRef.current;
|
|
91
|
+
viewDescRef.current.mark = mark;
|
|
92
|
+
viewDescRef.current.getPos = ()=>getPos.current();
|
|
93
|
+
}
|
|
94
|
+
if (!siblingsRef.current.includes(viewDescRef.current)) {
|
|
95
|
+
siblingsRef.current.push(viewDescRef.current);
|
|
96
|
+
}
|
|
97
|
+
siblingsRef.current.sort(_viewdesc.sortViewDescs);
|
|
98
|
+
for (const childDesc of childDescriptors.current){
|
|
99
|
+
childDesc.parent = viewDescRef.current;
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
const childContextValue = (0, _react.useMemo)(()=>({
|
|
103
|
+
parentRef: viewDescRef,
|
|
104
|
+
siblingsRef: childDescriptors
|
|
105
|
+
}), [
|
|
106
|
+
childDescriptors,
|
|
107
|
+
viewDescRef
|
|
108
|
+
]);
|
|
109
|
+
return /*#__PURE__*/ _react.default.createElement(_OutputSpec.OutputSpec, {
|
|
110
|
+
ref: domRef,
|
|
111
|
+
outputSpec: outputSpec
|
|
112
|
+
}, /*#__PURE__*/ _react.default.createElement(_ChildDescriptorsContext.ChildDescriptorsContext.Provider, {
|
|
113
|
+
value: childContextValue
|
|
114
|
+
}, children));
|
|
115
|
+
}));
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "NativeWidgetView", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return NativeWidgetView;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
12
|
+
const _ChildDescriptorsContext = require("../contexts/ChildDescriptorsContext.js");
|
|
13
|
+
const _useEditorEffect = require("../hooks/useEditorEffect.js");
|
|
14
|
+
const _viewdesc = require("../viewdesc.js");
|
|
15
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
16
|
+
if (typeof WeakMap !== "function") return null;
|
|
17
|
+
var cacheBabelInterop = new WeakMap();
|
|
18
|
+
var cacheNodeInterop = new WeakMap();
|
|
19
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
20
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
21
|
+
})(nodeInterop);
|
|
22
|
+
}
|
|
23
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
24
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
25
|
+
return obj;
|
|
26
|
+
}
|
|
27
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
28
|
+
return {
|
|
29
|
+
default: obj
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
33
|
+
if (cache && cache.has(obj)) {
|
|
34
|
+
return cache.get(obj);
|
|
35
|
+
}
|
|
36
|
+
var newObj = {
|
|
37
|
+
__proto__: null
|
|
38
|
+
};
|
|
39
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
40
|
+
for(var key in obj){
|
|
41
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
42
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
43
|
+
if (desc && (desc.get || desc.set)) {
|
|
44
|
+
Object.defineProperty(newObj, key, desc);
|
|
45
|
+
} else {
|
|
46
|
+
newObj[key] = obj[key];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
newObj.default = obj;
|
|
51
|
+
if (cache) {
|
|
52
|
+
cache.set(obj, newObj);
|
|
53
|
+
}
|
|
54
|
+
return newObj;
|
|
55
|
+
}
|
|
56
|
+
function NativeWidgetView(param) {
|
|
57
|
+
let { widget, getPos } = param;
|
|
58
|
+
const { siblingsRef, parentRef } = (0, _react.useContext)(_ChildDescriptorsContext.ChildDescriptorsContext);
|
|
59
|
+
const viewDescRef = (0, _react.useRef)(null);
|
|
60
|
+
const rootDomRef = (0, _react.useRef)(null);
|
|
61
|
+
(0, _react.useLayoutEffect)(()=>{
|
|
62
|
+
const siblings = siblingsRef.current;
|
|
63
|
+
return ()=>{
|
|
64
|
+
if (!viewDescRef.current) return;
|
|
65
|
+
if (siblings.includes(viewDescRef.current)) {
|
|
66
|
+
const index = siblings.indexOf(viewDescRef.current);
|
|
67
|
+
siblings.splice(index, 1);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}, [
|
|
71
|
+
siblingsRef
|
|
72
|
+
]);
|
|
73
|
+
(0, _useEditorEffect.useEditorEffect)((view)=>{
|
|
74
|
+
if (!rootDomRef.current) return;
|
|
75
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
76
|
+
const toDOM = widget.type.toDOM;
|
|
77
|
+
let dom = typeof toDOM === "function" ? toDOM(view, ()=>getPos.current()) : toDOM;
|
|
78
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
79
|
+
if (!widget.type.spec.raw) {
|
|
80
|
+
if (dom.nodeType != 1) {
|
|
81
|
+
const wrap = document.createElement("span");
|
|
82
|
+
wrap.appendChild(dom);
|
|
83
|
+
dom = wrap;
|
|
84
|
+
}
|
|
85
|
+
dom.contentEditable = "false";
|
|
86
|
+
dom.classList.add("ProseMirror-widget");
|
|
87
|
+
}
|
|
88
|
+
if (rootDomRef.current.firstElementChild === dom) return;
|
|
89
|
+
rootDomRef.current.replaceChildren(dom);
|
|
90
|
+
});
|
|
91
|
+
(0, _react.useLayoutEffect)(()=>{
|
|
92
|
+
if (!rootDomRef.current) return;
|
|
93
|
+
if (!viewDescRef.current) {
|
|
94
|
+
viewDescRef.current = new _viewdesc.WidgetViewDesc(parentRef.current, ()=>getPos.current(), widget, rootDomRef.current);
|
|
95
|
+
} else {
|
|
96
|
+
viewDescRef.current.parent = parentRef.current;
|
|
97
|
+
viewDescRef.current.widget = widget;
|
|
98
|
+
viewDescRef.current.getPos = ()=>getPos.current();
|
|
99
|
+
viewDescRef.current.dom = rootDomRef.current;
|
|
100
|
+
}
|
|
101
|
+
if (!siblingsRef.current.includes(viewDescRef.current)) {
|
|
102
|
+
siblingsRef.current.push(viewDescRef.current);
|
|
103
|
+
}
|
|
104
|
+
siblingsRef.current.sort(_viewdesc.sortViewDescs);
|
|
105
|
+
});
|
|
106
|
+
return /*#__PURE__*/ _react.default.createElement("span", {
|
|
107
|
+
ref: rootDomRef
|
|
108
|
+
});
|
|
109
|
+
}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "NodeView", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return NodeView;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
12
|
+
const _ChildDescriptorsContext = require("../contexts/ChildDescriptorsContext.js");
|
|
13
|
+
const _EditorContext = require("../contexts/EditorContext.js");
|
|
14
|
+
const _NodeViewContext = require("../contexts/NodeViewContext.js");
|
|
15
|
+
const _SelectNodeContext = require("../contexts/SelectNodeContext.js");
|
|
16
|
+
const _StopEventContext = require("../contexts/StopEventContext.js");
|
|
17
|
+
const _useNodeViewDescriptor = require("../hooks/useNodeViewDescriptor.js");
|
|
18
|
+
const _ChildNodeViews = require("./ChildNodeViews.js");
|
|
19
|
+
const _CustomNodeView = require("./CustomNodeView.js");
|
|
20
|
+
const _OutputSpec = require("./OutputSpec.js");
|
|
21
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
22
|
+
if (typeof WeakMap !== "function") return null;
|
|
23
|
+
var cacheBabelInterop = new WeakMap();
|
|
24
|
+
var cacheNodeInterop = new WeakMap();
|
|
25
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
26
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
27
|
+
})(nodeInterop);
|
|
28
|
+
}
|
|
29
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
30
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
31
|
+
return obj;
|
|
32
|
+
}
|
|
33
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
34
|
+
return {
|
|
35
|
+
default: obj
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
39
|
+
if (cache && cache.has(obj)) {
|
|
40
|
+
return cache.get(obj);
|
|
41
|
+
}
|
|
42
|
+
var newObj = {
|
|
43
|
+
__proto__: null
|
|
44
|
+
};
|
|
45
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
46
|
+
for(var key in obj){
|
|
47
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
48
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
49
|
+
if (desc && (desc.get || desc.set)) {
|
|
50
|
+
Object.defineProperty(newObj, key, desc);
|
|
51
|
+
} else {
|
|
52
|
+
newObj[key] = obj[key];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
newObj.default = obj;
|
|
57
|
+
if (cache) {
|
|
58
|
+
cache.set(obj, newObj);
|
|
59
|
+
}
|
|
60
|
+
return newObj;
|
|
61
|
+
}
|
|
62
|
+
const NodeView = /*#__PURE__*/ (0, _react.memo)(function NodeView(param) {
|
|
63
|
+
let { outerDeco, getPos, node, innerDeco, ...props } = param;
|
|
64
|
+
const domRef = (0, _react.useRef)(null);
|
|
65
|
+
const nodeDomRef = (0, _react.useRef)(null);
|
|
66
|
+
const contentDomRef = (0, _react.useRef)(null);
|
|
67
|
+
const getPosFunc = (0, _react.useRef)(()=>getPos.current()).current;
|
|
68
|
+
// this is ill-conceived; should revisit
|
|
69
|
+
const initialNode = (0, _react.useRef)(node);
|
|
70
|
+
const initialOuterDeco = (0, _react.useRef)(outerDeco);
|
|
71
|
+
const initialInnerDeco = (0, _react.useRef)(innerDeco);
|
|
72
|
+
const customNodeViewRootRef = (0, _react.useRef)(null);
|
|
73
|
+
const customNodeViewRef = (0, _react.useRef)(null);
|
|
74
|
+
// const state = useEditorState();
|
|
75
|
+
const { nodeViews } = (0, _react.useContext)(_NodeViewContext.NodeViewContext);
|
|
76
|
+
const { view } = (0, _react.useContext)(_EditorContext.EditorContext);
|
|
77
|
+
let element = null;
|
|
78
|
+
const Component = nodeViews[node.type.name];
|
|
79
|
+
const outputSpec = (0, _react.useMemo)(()=>node.type.spec.toDOM?.(node), [
|
|
80
|
+
node
|
|
81
|
+
]);
|
|
82
|
+
// TODO: Would be great to pull all of the custom node view stuff into
|
|
83
|
+
// a hook
|
|
84
|
+
const customNodeView = view?.someProp("nodeViews", (nodeViews)=>nodeViews?.[node.type.name]);
|
|
85
|
+
(0, _react.useLayoutEffect)(()=>{
|
|
86
|
+
if (!customNodeViewRef.current || !customNodeViewRootRef.current) return;
|
|
87
|
+
const { dom } = customNodeViewRef.current;
|
|
88
|
+
nodeDomRef.current = customNodeViewRootRef.current;
|
|
89
|
+
customNodeViewRootRef.current.appendChild(dom);
|
|
90
|
+
return ()=>{
|
|
91
|
+
customNodeViewRef.current?.destroy?.();
|
|
92
|
+
};
|
|
93
|
+
}, []);
|
|
94
|
+
(0, _react.useLayoutEffect)(()=>{
|
|
95
|
+
if (!customNodeView || !customNodeViewRef.current) return;
|
|
96
|
+
const { destroy, update } = customNodeViewRef.current;
|
|
97
|
+
const updated = update?.call(customNodeViewRef.current, node, outerDeco, innerDeco) ?? true;
|
|
98
|
+
if (updated) return;
|
|
99
|
+
destroy?.call(customNodeViewRef.current);
|
|
100
|
+
if (!customNodeViewRootRef.current) return;
|
|
101
|
+
initialNode.current = node;
|
|
102
|
+
initialOuterDeco.current = outerDeco;
|
|
103
|
+
initialInnerDeco.current = innerDeco;
|
|
104
|
+
customNodeViewRef.current = customNodeView(initialNode.current, // customNodeView will only be set if view is set, and we can only reach
|
|
105
|
+
// this line if customNodeView is set
|
|
106
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
107
|
+
view, ()=>getPos.current(), initialOuterDeco.current, initialInnerDeco.current);
|
|
108
|
+
const { dom } = customNodeViewRef.current;
|
|
109
|
+
nodeDomRef.current = customNodeViewRootRef.current;
|
|
110
|
+
customNodeViewRootRef.current.appendChild(dom);
|
|
111
|
+
}, [
|
|
112
|
+
customNodeView,
|
|
113
|
+
view,
|
|
114
|
+
innerDeco,
|
|
115
|
+
node,
|
|
116
|
+
outerDeco,
|
|
117
|
+
getPos
|
|
118
|
+
]);
|
|
119
|
+
const { hasContentDOM, childDescriptors, setStopEvent, setSelectNode, nodeViewDescRef } = (0, _useNodeViewDescriptor.useNodeViewDescriptor)(node, ()=>getPos.current(), domRef, nodeDomRef, innerDeco, outerDeco, undefined, contentDomRef);
|
|
120
|
+
const finalProps = {
|
|
121
|
+
...props,
|
|
122
|
+
...!hasContentDOM && {
|
|
123
|
+
contentEditable: false
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
const nodeProps = (0, _react.useMemo)(()=>({
|
|
127
|
+
node: node,
|
|
128
|
+
getPos: getPosFunc,
|
|
129
|
+
decorations: outerDeco,
|
|
130
|
+
innerDecorations: innerDeco
|
|
131
|
+
}), [
|
|
132
|
+
getPosFunc,
|
|
133
|
+
innerDeco,
|
|
134
|
+
node,
|
|
135
|
+
outerDeco
|
|
136
|
+
]);
|
|
137
|
+
if (Component) {
|
|
138
|
+
element = /*#__PURE__*/ _react.default.createElement(Component, {
|
|
139
|
+
...finalProps,
|
|
140
|
+
ref: nodeDomRef,
|
|
141
|
+
nodeProps: nodeProps
|
|
142
|
+
}, /*#__PURE__*/ _react.default.createElement(_ChildNodeViews.ChildNodeViews, {
|
|
143
|
+
getPos: getPos,
|
|
144
|
+
node: node,
|
|
145
|
+
innerDecorations: innerDeco
|
|
146
|
+
}));
|
|
147
|
+
} else if (customNodeView) {
|
|
148
|
+
element = /*#__PURE__*/ _react.default.createElement(_CustomNodeView.CustomNodeView, {
|
|
149
|
+
contentDomRef: contentDomRef,
|
|
150
|
+
customNodeView: customNodeView,
|
|
151
|
+
customNodeViewRef: customNodeViewRef,
|
|
152
|
+
customNodeViewRootRef: customNodeViewRootRef,
|
|
153
|
+
initialInnerDeco: initialInnerDeco,
|
|
154
|
+
initialNode: initialNode,
|
|
155
|
+
initialOuterDeco: initialOuterDeco,
|
|
156
|
+
node: node,
|
|
157
|
+
getPos: getPos,
|
|
158
|
+
innerDeco: innerDeco
|
|
159
|
+
});
|
|
160
|
+
} else {
|
|
161
|
+
if (outputSpec) {
|
|
162
|
+
element = /*#__PURE__*/ _react.default.createElement(_OutputSpec.OutputSpec, {
|
|
163
|
+
...finalProps,
|
|
164
|
+
ref: nodeDomRef,
|
|
165
|
+
outputSpec: outputSpec
|
|
166
|
+
}, /*#__PURE__*/ _react.default.createElement(_ChildNodeViews.ChildNodeViews, {
|
|
167
|
+
getPos: getPos,
|
|
168
|
+
node: node,
|
|
169
|
+
innerDecorations: innerDeco
|
|
170
|
+
}));
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
if (!element) {
|
|
174
|
+
throw new Error(`Node spec for ${node.type.name} is missing toDOM`);
|
|
175
|
+
}
|
|
176
|
+
const decoratedElement = /*#__PURE__*/ (0, _react.cloneElement)(outerDeco.reduce(_ChildNodeViews.wrapInDeco, element), // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
177
|
+
outerDeco.some((d)=>d.type.attrs.nodeName) ? {
|
|
178
|
+
ref: domRef
|
|
179
|
+
} : // we've already passed the domRef to the NodeView component
|
|
180
|
+
// as a prop
|
|
181
|
+
undefined);
|
|
182
|
+
const childContextValue = (0, _react.useMemo)(()=>({
|
|
183
|
+
parentRef: nodeViewDescRef,
|
|
184
|
+
siblingsRef: childDescriptors
|
|
185
|
+
}), [
|
|
186
|
+
childDescriptors,
|
|
187
|
+
nodeViewDescRef
|
|
188
|
+
]);
|
|
189
|
+
return /*#__PURE__*/ _react.default.createElement(_SelectNodeContext.SelectNodeContext.Provider, {
|
|
190
|
+
value: setSelectNode
|
|
191
|
+
}, /*#__PURE__*/ _react.default.createElement(_StopEventContext.StopEventContext.Provider, {
|
|
192
|
+
value: setStopEvent
|
|
193
|
+
}, /*#__PURE__*/ _react.default.createElement(_ChildDescriptorsContext.ChildDescriptorsContext.Provider, {
|
|
194
|
+
value: childContextValue
|
|
195
|
+
}, decoratedElement)));
|
|
196
|
+
});
|