@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,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "browser", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return browser;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const nav = typeof navigator != "undefined" ? navigator : null;
|
|
12
|
+
const doc = typeof document != "undefined" ? document : null;
|
|
13
|
+
const agent = nav && nav.userAgent || "";
|
|
14
|
+
const ie_edge = /Edge\/(\d+)/.exec(agent);
|
|
15
|
+
const ie_upto10 = /MSIE \d/.exec(agent);
|
|
16
|
+
const ie_11up = /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(agent);
|
|
17
|
+
const ie = !!(ie_upto10 || ie_11up || ie_edge);
|
|
18
|
+
const ie_version = ie_upto10 ? document.documentMode : ie_11up ? +ie_11up[1] : ie_edge ? +ie_edge[1] : 0;
|
|
19
|
+
const gecko = !ie && /gecko\/(\d+)/i.test(agent);
|
|
20
|
+
const gecko_version = gecko && +(/Firefox\/(\d+)/.exec(agent) || [
|
|
21
|
+
0,
|
|
22
|
+
0
|
|
23
|
+
])[1];
|
|
24
|
+
const _chrome = !ie && /Chrome\/(\d+)/.exec(agent);
|
|
25
|
+
const chrome = !!_chrome;
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
27
|
+
const chrome_version = _chrome ? +_chrome[1] : 0;
|
|
28
|
+
const safari = !ie && !!nav && /Apple Computer/.test(nav.vendor);
|
|
29
|
+
// Is true for both iOS and iPadOS for convenience
|
|
30
|
+
const ios = safari && (/Mobile\/\w+/.test(agent) || !!nav && nav.maxTouchPoints > 2);
|
|
31
|
+
const mac = ios || (nav ? /Mac/.test(nav.platform) : false);
|
|
32
|
+
const windows = nav ? /Win/.test(nav.platform) : false;
|
|
33
|
+
const android = /Android \d/.test(agent);
|
|
34
|
+
const webkit = !!doc && "webkitFontSmoothing" in doc.documentElement.style;
|
|
35
|
+
const webkit_version = webkit ? +(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent) || [
|
|
36
|
+
0,
|
|
37
|
+
0
|
|
38
|
+
])[1] : 0;
|
|
39
|
+
const browser = {
|
|
40
|
+
ie,
|
|
41
|
+
ie_version,
|
|
42
|
+
gecko,
|
|
43
|
+
gecko_version,
|
|
44
|
+
chrome,
|
|
45
|
+
chrome_version,
|
|
46
|
+
safari,
|
|
47
|
+
ios,
|
|
48
|
+
mac,
|
|
49
|
+
windows,
|
|
50
|
+
android,
|
|
51
|
+
webkit,
|
|
52
|
+
webkit_version
|
|
53
|
+
};
|
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
ChildNodeViews: function() {
|
|
13
|
+
return ChildNodeViews;
|
|
14
|
+
},
|
|
15
|
+
wrapInDeco: function() {
|
|
16
|
+
return wrapInDeco;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
20
|
+
const _ChildDescriptorsContext = require("../contexts/ChildDescriptorsContext.js");
|
|
21
|
+
const _EditorContext = require("../contexts/EditorContext.js");
|
|
22
|
+
const _iterDeco = require("../decorations/iterDeco.js");
|
|
23
|
+
const _useReactKeys = require("../hooks/useReactKeys.js");
|
|
24
|
+
const _props = require("../props.js");
|
|
25
|
+
const _MarkView = require("./MarkView.js");
|
|
26
|
+
const _NativeWidgetView = require("./NativeWidgetView.js");
|
|
27
|
+
const _NodeView = require("./NodeView.js");
|
|
28
|
+
const _SeparatorHackView = require("./SeparatorHackView.js");
|
|
29
|
+
const _TextNodeView = require("./TextNodeView.js");
|
|
30
|
+
const _TrailingHackView = require("./TrailingHackView.js");
|
|
31
|
+
const _WidgetView = require("./WidgetView.js");
|
|
32
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
33
|
+
if (typeof WeakMap !== "function") return null;
|
|
34
|
+
var cacheBabelInterop = new WeakMap();
|
|
35
|
+
var cacheNodeInterop = new WeakMap();
|
|
36
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
37
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
38
|
+
})(nodeInterop);
|
|
39
|
+
}
|
|
40
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
41
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
42
|
+
return obj;
|
|
43
|
+
}
|
|
44
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
45
|
+
return {
|
|
46
|
+
default: obj
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
50
|
+
if (cache && cache.has(obj)) {
|
|
51
|
+
return cache.get(obj);
|
|
52
|
+
}
|
|
53
|
+
var newObj = {
|
|
54
|
+
__proto__: null
|
|
55
|
+
};
|
|
56
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
57
|
+
for(var key in obj){
|
|
58
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
59
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
60
|
+
if (desc && (desc.get || desc.set)) {
|
|
61
|
+
Object.defineProperty(newObj, key, desc);
|
|
62
|
+
} else {
|
|
63
|
+
newObj[key] = obj[key];
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
newObj.default = obj;
|
|
68
|
+
if (cache) {
|
|
69
|
+
cache.set(obj, newObj);
|
|
70
|
+
}
|
|
71
|
+
return newObj;
|
|
72
|
+
}
|
|
73
|
+
function wrapInDeco(reactNode, deco) {
|
|
74
|
+
const { nodeName, ...attrs } = deco.type.attrs;
|
|
75
|
+
const props = (0, _props.htmlAttrsToReactProps)(attrs);
|
|
76
|
+
// We auto-wrap text nodes in spans so that we can apply attributes
|
|
77
|
+
// and styles, but we want to avoid double-wrapping the same
|
|
78
|
+
// text node
|
|
79
|
+
if (nodeName || typeof reactNode === "string") {
|
|
80
|
+
return /*#__PURE__*/ (0, _react.createElement)(nodeName ?? "span", props, reactNode);
|
|
81
|
+
}
|
|
82
|
+
return /*#__PURE__*/ (0, _react.cloneElement)(reactNode, (0, _props.mergeReactProps)(reactNode.props, props));
|
|
83
|
+
}
|
|
84
|
+
function areChildrenEqual(a, b) {
|
|
85
|
+
return a.type === b.type && a.marks.every((mark)=>mark.isInSet(b.marks)) && b.marks.every((mark)=>mark.isInSet(a.marks)) && a.key === b.key && (a.type === "node" ? a.outerDeco?.length === b.outerDeco?.length && a.outerDeco?.every((prevDeco)=>b.outerDeco?.some((nextDeco)=>prevDeco.from === nextDeco.from && prevDeco.to && nextDeco.to && prevDeco.type.eq(nextDeco.type))) && a.innerDeco.eq(b.innerDeco) : true) && a.node === b.node && a.widget === b.widget;
|
|
86
|
+
}
|
|
87
|
+
const ChildView = /*#__PURE__*/ (0, _react.memo)(function ChildView(param) {
|
|
88
|
+
let { child, getInnerPos } = param;
|
|
89
|
+
const { view } = (0, _react.useContext)(_EditorContext.EditorContext);
|
|
90
|
+
const getChildPos = (0, _react.useRef)(()=>getInnerPos.current() + child.offset);
|
|
91
|
+
getChildPos.current = ()=>getInnerPos.current() + child.offset;
|
|
92
|
+
return child.type === "widget" ? /*#__PURE__*/ _react.default.createElement(_WidgetView.WidgetView, {
|
|
93
|
+
key: child.key,
|
|
94
|
+
widget: child.widget,
|
|
95
|
+
getPos: getChildPos
|
|
96
|
+
}) : child.type === "native-widget" ? /*#__PURE__*/ _react.default.createElement(_NativeWidgetView.NativeWidgetView, {
|
|
97
|
+
key: child.key,
|
|
98
|
+
widget: child.widget,
|
|
99
|
+
getPos: getChildPos
|
|
100
|
+
}) : child.node.isText ? /*#__PURE__*/ _react.default.createElement(_ChildDescriptorsContext.ChildDescriptorsContext.Consumer, {
|
|
101
|
+
key: child.key
|
|
102
|
+
}, (param)=>{
|
|
103
|
+
let { siblingsRef, parentRef } = param;
|
|
104
|
+
return /*#__PURE__*/ _react.default.createElement(_TextNodeView.TextNodeView, {
|
|
105
|
+
view: view,
|
|
106
|
+
node: child.node,
|
|
107
|
+
getPos: getChildPos,
|
|
108
|
+
siblingsRef: siblingsRef,
|
|
109
|
+
parentRef: parentRef,
|
|
110
|
+
decorations: child.outerDeco
|
|
111
|
+
});
|
|
112
|
+
}) : /*#__PURE__*/ _react.default.createElement(_NodeView.NodeView, {
|
|
113
|
+
key: child.key,
|
|
114
|
+
node: child.node,
|
|
115
|
+
getPos: getChildPos,
|
|
116
|
+
outerDeco: child.outerDeco,
|
|
117
|
+
innerDeco: child.innerDeco
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
const InlinePartition = /*#__PURE__*/ (0, _react.memo)(function InlinePartition(param) {
|
|
121
|
+
let { childViews, getInnerPos } = param;
|
|
122
|
+
const firstChild = childViews[0];
|
|
123
|
+
const getFirstChildPos = (0, _react.useRef)(()=>getInnerPos.current() + firstChild.offset);
|
|
124
|
+
getFirstChildPos.current = ()=>getInnerPos.current() + firstChild.offset;
|
|
125
|
+
const firstMark = firstChild.marks[0];
|
|
126
|
+
if (!firstMark) {
|
|
127
|
+
return /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, childViews.map((child)=>{
|
|
128
|
+
return /*#__PURE__*/ _react.default.createElement(ChildView, {
|
|
129
|
+
key: child.key,
|
|
130
|
+
child: child,
|
|
131
|
+
getInnerPos: getInnerPos
|
|
132
|
+
});
|
|
133
|
+
}));
|
|
134
|
+
}
|
|
135
|
+
return /*#__PURE__*/ _react.default.createElement(_MarkView.MarkView, {
|
|
136
|
+
getPos: getFirstChildPos,
|
|
137
|
+
key: firstChild.key,
|
|
138
|
+
mark: firstMark
|
|
139
|
+
}, /*#__PURE__*/ _react.default.createElement(InlineView, {
|
|
140
|
+
key: firstChild.key,
|
|
141
|
+
getInnerPos: getInnerPos,
|
|
142
|
+
childViews: childViews.map((child)=>({
|
|
143
|
+
...child,
|
|
144
|
+
marks: child.marks.slice(1)
|
|
145
|
+
}))
|
|
146
|
+
}));
|
|
147
|
+
});
|
|
148
|
+
const InlineView = /*#__PURE__*/ (0, _react.memo)(function InlineView(param) {
|
|
149
|
+
let { getInnerPos, childViews } = param;
|
|
150
|
+
// const editorState = useEditorState();
|
|
151
|
+
const partitioned = childViews.reduce((acc, child)=>{
|
|
152
|
+
const lastPartition = acc[acc.length - 1];
|
|
153
|
+
if (!lastPartition) {
|
|
154
|
+
return [
|
|
155
|
+
[
|
|
156
|
+
child
|
|
157
|
+
]
|
|
158
|
+
];
|
|
159
|
+
}
|
|
160
|
+
const lastChild = lastPartition[lastPartition.length - 1];
|
|
161
|
+
if (!lastChild) {
|
|
162
|
+
return [
|
|
163
|
+
...acc.slice(0, acc.length),
|
|
164
|
+
[
|
|
165
|
+
child
|
|
166
|
+
]
|
|
167
|
+
];
|
|
168
|
+
}
|
|
169
|
+
if (!child.marks.length && !lastChild.marks.length || child.marks.length && lastChild.marks.length && // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
170
|
+
child.marks[0]?.eq(lastChild.marks[0])) {
|
|
171
|
+
return [
|
|
172
|
+
...acc.slice(0, acc.length - 1),
|
|
173
|
+
[
|
|
174
|
+
...lastPartition.slice(0, lastPartition.length),
|
|
175
|
+
child
|
|
176
|
+
]
|
|
177
|
+
];
|
|
178
|
+
}
|
|
179
|
+
return [
|
|
180
|
+
...acc,
|
|
181
|
+
[
|
|
182
|
+
child
|
|
183
|
+
]
|
|
184
|
+
];
|
|
185
|
+
}, []);
|
|
186
|
+
return /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, partitioned.map((childViews)=>{
|
|
187
|
+
const firstChild = childViews[0];
|
|
188
|
+
if (!firstChild) return null;
|
|
189
|
+
return /*#__PURE__*/ _react.default.createElement(InlinePartition, {
|
|
190
|
+
key: firstChild.key,
|
|
191
|
+
childViews: childViews,
|
|
192
|
+
getInnerPos: getInnerPos
|
|
193
|
+
});
|
|
194
|
+
}));
|
|
195
|
+
});
|
|
196
|
+
function createKey(innerPos, offset, type, posToKey, widget, index) {
|
|
197
|
+
const pos = innerPos + offset;
|
|
198
|
+
const key = posToKey?.get(pos);
|
|
199
|
+
if (type === "widget" || type === "native-widget") {
|
|
200
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
201
|
+
if (widget.type.spec.key) // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
202
|
+
return widget.type.spec.key;
|
|
203
|
+
// eslint-disable-next-line no-console
|
|
204
|
+
console.warn(`Widget at position ${pos} doesn't have a key specified. This may cause issues.`);
|
|
205
|
+
return `${key}-${index}`;
|
|
206
|
+
}
|
|
207
|
+
if (key) return key;
|
|
208
|
+
// if (!doc) return pos;
|
|
209
|
+
const parentPos = innerPos - 1;
|
|
210
|
+
const parentKey = posToKey?.get(parentPos);
|
|
211
|
+
if (parentKey) return `${parentKey}-${offset}`;
|
|
212
|
+
return pos;
|
|
213
|
+
}
|
|
214
|
+
function adjustWidgetMarksForward(lastNodeChild, widgetChild) {
|
|
215
|
+
if (!widgetChild || // Using internal Decoration property, "type"
|
|
216
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
217
|
+
widgetChild.widget.type.side >= 0) return;
|
|
218
|
+
if (!lastNodeChild || !lastNodeChild.node.isInline) return;
|
|
219
|
+
const marksToSpread = lastNodeChild.marks;
|
|
220
|
+
widgetChild.marks = widgetChild.marks.reduce((acc, mark)=>mark.addToSet(acc), marksToSpread);
|
|
221
|
+
}
|
|
222
|
+
function adjustWidgetMarksBack(widgetChildren, nodeChild) {
|
|
223
|
+
if (!nodeChild.node.isInline) return;
|
|
224
|
+
const marksToSpread = nodeChild.marks;
|
|
225
|
+
for(let i = widgetChildren.length - 1; i >= 0; i--){
|
|
226
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
227
|
+
const child = widgetChildren[i];
|
|
228
|
+
if (// Using internal Decoration property, "type"
|
|
229
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
230
|
+
child.widget.type.side < 0) {
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
child.marks = child.marks.reduce((acc, mark)=>mark.addToSet(acc), marksToSpread);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
const ChildElement = /*#__PURE__*/ (0, _react.memo)(function ChildElement(param) {
|
|
237
|
+
let { child, getInnerPos } = param;
|
|
238
|
+
const getNodePos = (0, _react.useRef)(()=>getInnerPos.current() + child.offset);
|
|
239
|
+
getNodePos.current = ()=>getInnerPos.current() + child.offset;
|
|
240
|
+
if (child.type === "node") {
|
|
241
|
+
return child.marks.reduce((element, mark)=>/*#__PURE__*/ _react.default.createElement(_MarkView.MarkView, {
|
|
242
|
+
getPos: getNodePos,
|
|
243
|
+
mark: mark
|
|
244
|
+
}, element), /*#__PURE__*/ _react.default.createElement(_NodeView.NodeView, {
|
|
245
|
+
key: child.key,
|
|
246
|
+
outerDeco: child.outerDeco,
|
|
247
|
+
node: child.node,
|
|
248
|
+
innerDeco: child.innerDeco,
|
|
249
|
+
getPos: getNodePos
|
|
250
|
+
}));
|
|
251
|
+
} else {
|
|
252
|
+
return /*#__PURE__*/ _react.default.createElement(InlineView, {
|
|
253
|
+
key: child.key,
|
|
254
|
+
childViews: [
|
|
255
|
+
child
|
|
256
|
+
],
|
|
257
|
+
getInnerPos: getInnerPos
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
function createChildElements(children, getInnerPos) {
|
|
262
|
+
if (!children.length) return [];
|
|
263
|
+
if (children.every((child)=>child.type !== "node" || child.node.isInline)) {
|
|
264
|
+
return [
|
|
265
|
+
/*#__PURE__*/ _react.default.createElement(InlineView, {
|
|
266
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
267
|
+
key: children[0].key,
|
|
268
|
+
childViews: children,
|
|
269
|
+
getInnerPos: getInnerPos
|
|
270
|
+
})
|
|
271
|
+
];
|
|
272
|
+
}
|
|
273
|
+
return children.map((child)=>{
|
|
274
|
+
return /*#__PURE__*/ _react.default.createElement(ChildElement, {
|
|
275
|
+
key: child.key,
|
|
276
|
+
child: child,
|
|
277
|
+
getInnerPos: getInnerPos
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
const ChildNodeViews = /*#__PURE__*/ (0, _react.memo)(function ChildNodeViews(param) {
|
|
282
|
+
let { getPos, node, innerDecorations } = param;
|
|
283
|
+
// const editorState = useEditorState();
|
|
284
|
+
const reactKeys = (0, _useReactKeys.useReactKeys)();
|
|
285
|
+
const getInnerPos = (0, _react.useRef)(()=>getPos.current() + 1);
|
|
286
|
+
const childMap = (0, _react.useRef)(new Map()).current;
|
|
287
|
+
if (!node) return null;
|
|
288
|
+
const keysSeen = new Set();
|
|
289
|
+
let widgetChildren = [];
|
|
290
|
+
let lastNodeChild = null;
|
|
291
|
+
(0, _iterDeco.iterDeco)(node, innerDecorations, (widget, isNative, offset, index)=>{
|
|
292
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
293
|
+
const widgetMarks = widget.type.spec.marks ?? [];
|
|
294
|
+
let key;
|
|
295
|
+
if (isNative) {
|
|
296
|
+
key = createKey(getInnerPos.current(), offset, "native-widget", reactKeys?.posToKey, widget, index);
|
|
297
|
+
const child = {
|
|
298
|
+
type: "native-widget",
|
|
299
|
+
widget,
|
|
300
|
+
marks: widgetMarks,
|
|
301
|
+
offset,
|
|
302
|
+
index,
|
|
303
|
+
key
|
|
304
|
+
};
|
|
305
|
+
const prevChild = childMap.get(key);
|
|
306
|
+
if (prevChild && areChildrenEqual(prevChild, child)) {
|
|
307
|
+
prevChild.offset = offset;
|
|
308
|
+
} else {
|
|
309
|
+
childMap.set(key, child);
|
|
310
|
+
}
|
|
311
|
+
keysSeen.add(key);
|
|
312
|
+
} else {
|
|
313
|
+
key = createKey(getInnerPos.current(), offset, "widget", reactKeys?.posToKey, widget, index);
|
|
314
|
+
const child = {
|
|
315
|
+
type: "widget",
|
|
316
|
+
widget: widget,
|
|
317
|
+
marks: widgetMarks,
|
|
318
|
+
offset,
|
|
319
|
+
index,
|
|
320
|
+
key
|
|
321
|
+
};
|
|
322
|
+
const prevChild = childMap.get(key);
|
|
323
|
+
if (prevChild && areChildrenEqual(prevChild, child)) {
|
|
324
|
+
prevChild.offset = offset;
|
|
325
|
+
} else {
|
|
326
|
+
childMap.set(key, child);
|
|
327
|
+
}
|
|
328
|
+
keysSeen.add(key);
|
|
329
|
+
}
|
|
330
|
+
const child = childMap.get(key);
|
|
331
|
+
widgetChildren.push(child);
|
|
332
|
+
adjustWidgetMarksForward(lastNodeChild, childMap.get(key));
|
|
333
|
+
}, (childNode, outerDeco, innerDeco, offset)=>{
|
|
334
|
+
const key = createKey(getInnerPos.current(), offset, "node", reactKeys?.posToKey);
|
|
335
|
+
const child = {
|
|
336
|
+
type: "node",
|
|
337
|
+
node: childNode,
|
|
338
|
+
marks: childNode.marks,
|
|
339
|
+
innerDeco,
|
|
340
|
+
outerDeco,
|
|
341
|
+
offset,
|
|
342
|
+
key
|
|
343
|
+
};
|
|
344
|
+
const prevChild = childMap.get(key);
|
|
345
|
+
if (prevChild && areChildrenEqual(prevChild, child)) {
|
|
346
|
+
prevChild.offset = offset;
|
|
347
|
+
lastNodeChild = prevChild;
|
|
348
|
+
} else {
|
|
349
|
+
childMap.set(key, child);
|
|
350
|
+
lastNodeChild = child;
|
|
351
|
+
}
|
|
352
|
+
keysSeen.add(key);
|
|
353
|
+
adjustWidgetMarksBack(widgetChildren, lastNodeChild);
|
|
354
|
+
widgetChildren = [];
|
|
355
|
+
});
|
|
356
|
+
for (const key of childMap.keys()){
|
|
357
|
+
if (!keysSeen.has(key)) {
|
|
358
|
+
childMap.delete(key);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
const children = Array.from(childMap.values()).sort((a, b)=>a.offset - b.offset);
|
|
362
|
+
const childElements = createChildElements(children, getInnerPos);
|
|
363
|
+
const lastChild = children[children.length - 1];
|
|
364
|
+
if (!lastChild || lastChild.type !== "node" || lastChild.node.isInline && !lastChild.node.isText || // RegExp.test actually handles undefined just fine
|
|
365
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
366
|
+
/\n$/.test(lastChild.node.text)) {
|
|
367
|
+
childElements.push(/*#__PURE__*/ _react.default.createElement(_SeparatorHackView.SeparatorHackView, {
|
|
368
|
+
getPos: getInnerPos,
|
|
369
|
+
key: "trailing-hack-img"
|
|
370
|
+
}), /*#__PURE__*/ _react.default.createElement(_TrailingHackView.TrailingHackView, {
|
|
371
|
+
getPos: getInnerPos,
|
|
372
|
+
key: "trailing-hack-br"
|
|
373
|
+
}));
|
|
374
|
+
}
|
|
375
|
+
return /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, childElements);
|
|
376
|
+
});
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "CursorWrapper", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return CursorWrapper;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
12
|
+
const _dom = require("../dom.js");
|
|
13
|
+
const _useEditorEffect = require("../hooks/useEditorEffect.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
|
+
const CursorWrapper = /*#__PURE__*/ (0, _react.forwardRef)(function CursorWrapper(param, ref) {
|
|
56
|
+
let { widget, getPos, ...props } = param;
|
|
57
|
+
const [shouldRender, setShouldRender] = (0, _react.useState)(true);
|
|
58
|
+
const innerRef = (0, _react.useRef)(null);
|
|
59
|
+
(0, _react.useImperativeHandle)(ref, ()=>{
|
|
60
|
+
return innerRef.current;
|
|
61
|
+
}, []);
|
|
62
|
+
(0, _useEditorEffect.useEditorEffect)((view)=>{
|
|
63
|
+
if (!view || !innerRef.current) return;
|
|
64
|
+
// @ts-expect-error Internal property - domObserver
|
|
65
|
+
view.domObserver.disconnectSelection();
|
|
66
|
+
// @ts-expect-error Internal property - domSelection
|
|
67
|
+
const domSel = view.domSelection();
|
|
68
|
+
const range = document.createRange();
|
|
69
|
+
const node = innerRef.current;
|
|
70
|
+
const img = node.nodeName == "IMG";
|
|
71
|
+
if (img && node.parentNode) {
|
|
72
|
+
range.setEnd(node.parentNode, (0, _dom.domIndex)(node) + 1);
|
|
73
|
+
} else {
|
|
74
|
+
range.setEnd(node, 0);
|
|
75
|
+
}
|
|
76
|
+
range.collapse(false);
|
|
77
|
+
domSel.removeAllRanges();
|
|
78
|
+
domSel.addRange(range);
|
|
79
|
+
setShouldRender(false);
|
|
80
|
+
// @ts-expect-error Internal property - domObserver
|
|
81
|
+
view.domObserver.connectSelection();
|
|
82
|
+
}, []);
|
|
83
|
+
return shouldRender ? /*#__PURE__*/ _react.default.createElement("img", {
|
|
84
|
+
ref: innerRef,
|
|
85
|
+
className: "ProseMirror-separator",
|
|
86
|
+
// eslint-disable-next-line react/no-unknown-property
|
|
87
|
+
"mark-placeholder": "true",
|
|
88
|
+
alt: "",
|
|
89
|
+
...props
|
|
90
|
+
}) : null;
|
|
91
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
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 _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
12
|
+
const _reactdom = require("react-dom");
|
|
13
|
+
const _EditorContext = require("../contexts/EditorContext.js");
|
|
14
|
+
const _useClientOnly = require("../hooks/useClientOnly.js");
|
|
15
|
+
const _ChildNodeViews = require("./ChildNodeViews.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
|
+
function CustomNodeView(param) {
|
|
58
|
+
let { contentDomRef, customNodeViewRef, customNodeViewRootRef, customNodeView, initialNode, node, getPos, initialOuterDeco, initialInnerDeco, innerDeco } = param;
|
|
59
|
+
const { view } = (0, _react.useContext)(_EditorContext.EditorContext);
|
|
60
|
+
const shouldRender = (0, _useClientOnly.useClientOnly)();
|
|
61
|
+
if (!shouldRender) return null;
|
|
62
|
+
if (!customNodeViewRef.current) {
|
|
63
|
+
customNodeViewRef.current = customNodeView(initialNode.current, // customNodeView will only be set if view is set, and we can only reach
|
|
64
|
+
// this line if customNodeView is set
|
|
65
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
66
|
+
view, ()=>getPos.current(), initialOuterDeco.current, initialInnerDeco.current);
|
|
67
|
+
}
|
|
68
|
+
const { contentDOM } = customNodeViewRef.current;
|
|
69
|
+
contentDomRef.current = contentDOM ?? null;
|
|
70
|
+
return /*#__PURE__*/ (0, _react.createElement)(node.isInline ? "span" : "div", {
|
|
71
|
+
ref: customNodeViewRootRef,
|
|
72
|
+
contentEditable: !!contentDOM,
|
|
73
|
+
suppressContentEditableWarning: true
|
|
74
|
+
}, contentDOM && /*#__PURE__*/ (0, _reactdom.createPortal)(/*#__PURE__*/ _react.default.createElement(_ChildNodeViews.ChildNodeViews, {
|
|
75
|
+
getPos: getPos,
|
|
76
|
+
node: node,
|
|
77
|
+
innerDecorations: innerDeco
|
|
78
|
+
}), contentDOM));
|
|
79
|
+
}
|