@handlewithcare/react-prosemirror 2.8.0 → 2.9.0-tiptap.24
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/dist/cjs/StaticEditorView.js +3 -0
- package/dist/cjs/commands/reorderSiblings.js +60 -45
- package/dist/cjs/components/CustomNodeView.js +132 -0
- package/dist/cjs/components/DefaultNodeView.js +67 -0
- package/dist/cjs/components/DocNodeView.js +96 -0
- package/dist/cjs/components/MarkView.js +119 -0
- package/dist/cjs/components/NodeView.js +86 -0
- package/dist/cjs/components/NodeViewComponentProps.js +4 -0
- package/dist/cjs/components/ReactNodeView.js +174 -0
- package/dist/cjs/components/nodes/ReactNodeView.js +4 -4
- package/dist/cjs/hooks/useEditor.js +4 -0
- package/dist/cjs/hooks/useEditorEventCallback.js +1 -1
- package/dist/cjs/tiptap/ReactProseMirrorNodeView.js +26 -0
- package/dist/cjs/tiptap/TiptapEditor.js +34 -0
- package/dist/cjs/tiptap/TiptapEditorContent.js +142 -0
- package/dist/cjs/tiptap/TiptapEditorView.js +118 -0
- package/dist/cjs/tiptap/TiptapNodeView.js +26 -0
- package/dist/cjs/tiptap/contexts/TiptapEditorContext.js +12 -0
- package/dist/cjs/tiptap/extensions/ReactProseMirror.js +40 -0
- package/dist/cjs/tiptap/hooks/useIsInReactProseMirror.js +15 -0
- package/dist/cjs/tiptap/hooks/useTiptapEditor.js +43 -0
- package/dist/cjs/tiptap/hooks/useTiptapEditorEffect.js +35 -0
- package/dist/cjs/tiptap/hooks/useTiptapEditorEventCallback.js +35 -0
- package/dist/cjs/tiptap/index.js +48 -0
- package/dist/cjs/tiptap/tiptapNodeView.js +237 -0
- package/dist/cjs/viewdesc.js +5 -5
- package/dist/esm/StaticEditorView.js +3 -0
- package/dist/esm/commands/reorderSiblings.js +49 -42
- package/dist/esm/components/CustomNodeView.js +81 -0
- package/dist/esm/components/DefaultNodeView.js +16 -0
- package/dist/esm/components/DocNodeView.js +45 -0
- package/dist/esm/components/MarkView.js +68 -0
- package/dist/esm/components/NodeView.js +35 -0
- package/dist/esm/components/NodeViewComponentProps.js +1 -0
- package/dist/esm/components/ReactNodeView.js +123 -0
- package/dist/esm/components/nodes/ReactNodeView.js +4 -4
- package/dist/esm/hooks/useEditor.js +4 -0
- package/dist/esm/hooks/useEditorEffect.js +4 -0
- package/dist/esm/hooks/useEditorEventCallback.js +4 -6
- package/dist/esm/tiptap/ReactProseMirrorNodeView.js +22 -0
- package/dist/esm/tiptap/TiptapEditor.js +24 -0
- package/dist/esm/tiptap/TiptapEditorContent.js +91 -0
- package/dist/esm/tiptap/TiptapEditorView.js +69 -0
- package/dist/esm/tiptap/TiptapNodeView.js +22 -0
- package/dist/esm/tiptap/contexts/TiptapEditorContext.js +2 -0
- package/dist/esm/tiptap/extensions/ReactProseMirror.js +30 -0
- package/dist/esm/tiptap/hooks/useIsInReactProseMirror.js +5 -0
- package/dist/esm/tiptap/hooks/useTiptapEditor.js +33 -0
- package/dist/esm/tiptap/hooks/useTiptapEditorEffect.js +42 -0
- package/dist/esm/tiptap/hooks/useTiptapEditorEventCallback.js +35 -0
- package/dist/esm/tiptap/index.js +9 -0
- package/dist/esm/tiptap/tiptapNodeView.js +205 -0
- package/dist/esm/viewdesc.js +5 -5
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/AbstractEditorView.d.ts +1 -0
- package/dist/types/StaticEditorView.d.ts +1 -0
- package/dist/types/commands/__tests__/reorderSiblings.test.d.ts +1 -0
- package/dist/types/commands/reorderSiblings.d.ts +3 -1
- package/dist/types/components/CustomNodeView.d.ts +12 -0
- package/dist/types/components/DefaultNodeView.d.ts +3 -0
- package/dist/types/components/DocNodeView.d.ts +12 -0
- package/dist/types/components/MarkView.d.ts +9 -0
- package/dist/types/components/NodeView.d.ts +11 -0
- package/dist/types/components/NodeViewComponentProps.d.ts +12 -0
- package/dist/types/components/ReactNodeView.d.ts +13 -0
- package/dist/types/constants.d.ts +1 -1
- package/dist/types/hooks/useEditorEffect.d.ts +4 -0
- package/dist/types/hooks/useEditorEventCallback.d.ts +4 -6
- package/dist/types/props.d.ts +26 -26
- package/dist/types/tiptap/ReactProseMirrorNodeView.d.ts +15 -0
- package/dist/types/tiptap/TiptapEditor.d.ts +6 -0
- package/dist/types/tiptap/TiptapEditorContent.d.ts +19 -0
- package/dist/types/tiptap/TiptapEditorView.d.ts +16 -0
- package/dist/types/tiptap/TiptapNodeView.d.ts +15 -0
- package/dist/types/tiptap/contexts/TiptapEditorContext.d.ts +6 -0
- package/dist/types/tiptap/extensions/ReactProseMirror.d.ts +9 -0
- package/dist/types/tiptap/hooks/useIsInReactProseMirror.d.ts +1 -0
- package/dist/types/tiptap/hooks/useTiptapEditor.d.ts +4 -0
- package/dist/types/tiptap/hooks/useTiptapEditorEffect.d.ts +21 -0
- package/dist/types/tiptap/hooks/useTiptapEditorEventCallback.d.ts +13 -0
- package/dist/types/tiptap/index.d.ts +9 -0
- package/dist/types/tiptap/tiptapNodeView.d.ts +50 -0
- package/package.json +19 -11
|
@@ -1,57 +1,72 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */ "use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
+
reorderSiblings: function() {
|
|
8
13
|
return reorderSiblings;
|
|
14
|
+
},
|
|
15
|
+
reorderSiblingsOnTransaction: function() {
|
|
16
|
+
return reorderSiblingsOnTransaction;
|
|
9
17
|
}
|
|
10
18
|
});
|
|
11
19
|
const _reactKeys = require("../plugins/reactKeys.js");
|
|
12
20
|
function reorderSiblings(pos, order) {
|
|
13
21
|
return function reorderSiblingsCommand(state, dispatch) {
|
|
14
|
-
const $pos = state.doc.resolve(pos);
|
|
15
|
-
if ($pos.start() !== pos) {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
if (!dispatch) return true;
|
|
19
|
-
const nodes = $pos.parent.children;
|
|
20
|
-
const reordered = nodes.map((node, i)=>[
|
|
21
|
-
node,
|
|
22
|
-
i
|
|
23
|
-
]).sort((param, param1)=>{
|
|
24
|
-
let [, a] = param, [, b] = param1;
|
|
25
|
-
return order[a] - order[b];
|
|
26
|
-
}).map((param)=>{
|
|
27
|
-
let [node] = param;
|
|
28
|
-
return node;
|
|
29
|
-
});
|
|
30
22
|
const tr = state.tr;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
23
|
+
return reorderSiblingsOnTransaction(pos, order, tr, state, dispatch);
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function reorderSiblingsOnTransaction(pos, order, tr, state, dispatch) {
|
|
27
|
+
const orderLookup = order.reduce((acc, oldIndex, newIndex)=>{
|
|
28
|
+
acc[oldIndex] = newIndex;
|
|
29
|
+
return acc;
|
|
30
|
+
}, []);
|
|
31
|
+
const $pos = state.doc.resolve(pos);
|
|
32
|
+
if ($pos.start() !== pos) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
if (!dispatch) return true;
|
|
36
|
+
const nodes = $pos.parent.children;
|
|
37
|
+
const reordered = nodes.map((node, i)=>[
|
|
38
|
+
node,
|
|
39
|
+
i
|
|
40
|
+
]).sort((param, param1)=>{
|
|
41
|
+
let [, a] = param, [, b] = param1;
|
|
42
|
+
return orderLookup[a] - orderLookup[b];
|
|
43
|
+
}).map((param)=>{
|
|
44
|
+
let [node] = param;
|
|
45
|
+
return node;
|
|
46
|
+
});
|
|
47
|
+
tr.replaceWith(pos, $pos.parent.content.size + pos, reordered);
|
|
48
|
+
const meta = {
|
|
49
|
+
overrides: {}
|
|
56
50
|
};
|
|
51
|
+
const oldPositions = [];
|
|
52
|
+
let start = pos;
|
|
53
|
+
for (const node of nodes){
|
|
54
|
+
oldPositions.push(start);
|
|
55
|
+
start += node.nodeSize;
|
|
56
|
+
}
|
|
57
|
+
start = pos;
|
|
58
|
+
const newPositions = [];
|
|
59
|
+
for(let i = 0; i < reordered.length; i++){
|
|
60
|
+
const node = reordered[i];
|
|
61
|
+
newPositions[order[i]] = start;
|
|
62
|
+
start += node.nodeSize;
|
|
63
|
+
}
|
|
64
|
+
for(let i = 0; i < oldPositions.length; i++){
|
|
65
|
+
const oldPosition = oldPositions[i];
|
|
66
|
+
const newPosition = newPositions[i];
|
|
67
|
+
meta.overrides[oldPosition] = newPosition;
|
|
68
|
+
}
|
|
69
|
+
tr.setMeta(_reactKeys.reactKeysPluginKey, meta);
|
|
70
|
+
dispatch(tr);
|
|
71
|
+
return true;
|
|
57
72
|
}
|
|
@@ -0,0 +1,132 @@
|
|
|
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 _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 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
|
+
}), [
|
|
68
|
+
node,
|
|
69
|
+
getPos,
|
|
70
|
+
outerDeco,
|
|
71
|
+
innerDeco
|
|
72
|
+
]);
|
|
73
|
+
const createNodeView = function() {
|
|
74
|
+
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
75
|
+
args[_key] = arguments[_key];
|
|
76
|
+
}
|
|
77
|
+
const nodeView = constructor(...args);
|
|
78
|
+
if (!nodeView || !nodeView.dom) {
|
|
79
|
+
const spec = node.type.spec.toDOM?.(node);
|
|
80
|
+
if (!spec) {
|
|
81
|
+
throw new Error(`Node spec for ${node.type.name} is missing toDOM`);
|
|
82
|
+
}
|
|
83
|
+
return _prosemirrormodel.DOMSerializer.renderSpec(document, spec, null);
|
|
84
|
+
}
|
|
85
|
+
return nodeView;
|
|
86
|
+
};
|
|
87
|
+
const { childContextValue, contentDOM } = (0, _useNodeViewDescriptor.useNodeViewDescriptor)(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 nodeView = createNodeView(...args);
|
|
92
|
+
const contentDOM = nodeView.contentDOM;
|
|
93
|
+
const nodeDOM = nodeView.dom;
|
|
94
|
+
const wrapperDOM = innerRef.current ?? ref.current;
|
|
95
|
+
wrapperDOM.appendChild(nodeDOM);
|
|
96
|
+
if (!contentDOM && nodeDOM instanceof HTMLElement && nodeDOM.tagName !== "BR") {
|
|
97
|
+
if (!nodeDOM.hasAttribute("contenteditable")) {
|
|
98
|
+
nodeDOM.contentEditable = "false";
|
|
99
|
+
}
|
|
100
|
+
if (node.type.spec.draggable) {
|
|
101
|
+
nodeDOM.draggable = true;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
...nodeView,
|
|
106
|
+
destroy () {
|
|
107
|
+
if (nodeView.destroy) {
|
|
108
|
+
nodeView.destroy();
|
|
109
|
+
}
|
|
110
|
+
wrapperDOM.removeChild(nodeDOM);
|
|
111
|
+
},
|
|
112
|
+
selectNode: nodeView.selectNode?.bind(nodeView),
|
|
113
|
+
deselectNode: nodeView.deselectNode?.bind(nodeView),
|
|
114
|
+
stopEvent: nodeView.stopEvent?.bind(nodeView),
|
|
115
|
+
ignoreMutation: nodeView.ignoreMutation?.bind(nodeView)
|
|
116
|
+
};
|
|
117
|
+
}, nodeProps);
|
|
118
|
+
const Component = node.isInline ? "span" : "div";
|
|
119
|
+
const props = {
|
|
120
|
+
ref: innerRef
|
|
121
|
+
};
|
|
122
|
+
const children = !node.isLeaf && contentDOM ? /*#__PURE__*/ (0, _reactdom.createPortal)(/*#__PURE__*/ _react.default.createElement(_ChildDescriptorsContext.ChildDescriptorsContext.Provider, {
|
|
123
|
+
value: childContextValue
|
|
124
|
+
}, /*#__PURE__*/ _react.default.createElement(_ChildNodeViews.ChildNodeViews, {
|
|
125
|
+
getPos: getPos,
|
|
126
|
+
node: node,
|
|
127
|
+
innerDecorations: innerDeco
|
|
128
|
+
})), contentDOM) : null;
|
|
129
|
+
return /*#__PURE__*/ (0, _react.cloneElement)(outerDeco.reduce(_ChildNodeViews.wrapInDeco, /*#__PURE__*/ _react.default.createElement(Component, props, children)), {
|
|
130
|
+
ref
|
|
131
|
+
});
|
|
132
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "DefaultNodeView", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return DefaultNodeView;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
12
|
+
const _OutputSpec = require("./OutputSpec.js");
|
|
13
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
14
|
+
if (typeof WeakMap !== "function") return null;
|
|
15
|
+
var cacheBabelInterop = new WeakMap();
|
|
16
|
+
var cacheNodeInterop = new WeakMap();
|
|
17
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
18
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
19
|
+
})(nodeInterop);
|
|
20
|
+
}
|
|
21
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
22
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
23
|
+
return obj;
|
|
24
|
+
}
|
|
25
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
26
|
+
return {
|
|
27
|
+
default: obj
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
31
|
+
if (cache && cache.has(obj)) {
|
|
32
|
+
return cache.get(obj);
|
|
33
|
+
}
|
|
34
|
+
var newObj = {
|
|
35
|
+
__proto__: null
|
|
36
|
+
};
|
|
37
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
38
|
+
for(var key in obj){
|
|
39
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
40
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
41
|
+
if (desc && (desc.get || desc.set)) {
|
|
42
|
+
Object.defineProperty(newObj, key, desc);
|
|
43
|
+
} else {
|
|
44
|
+
newObj[key] = obj[key];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
newObj.default = obj;
|
|
49
|
+
if (cache) {
|
|
50
|
+
cache.set(obj, newObj);
|
|
51
|
+
}
|
|
52
|
+
return newObj;
|
|
53
|
+
}
|
|
54
|
+
const DefaultNodeView = /*#__PURE__*/ (0, _react.forwardRef)(function DefaultNodeView(param, ref) {
|
|
55
|
+
let { nodeProps: { node }, children, ...props } = param;
|
|
56
|
+
const spec = (0, _react.useMemo)(()=>node.type.spec.toDOM?.(node), [
|
|
57
|
+
node
|
|
58
|
+
]);
|
|
59
|
+
if (!spec) {
|
|
60
|
+
throw new Error(`Node spec for ${node.type.name} is missing toDOM`);
|
|
61
|
+
}
|
|
62
|
+
return /*#__PURE__*/ _react.default.createElement(_OutputSpec.OutputSpec, {
|
|
63
|
+
...props,
|
|
64
|
+
outputSpec: spec,
|
|
65
|
+
ref: ref
|
|
66
|
+
}, children);
|
|
67
|
+
});
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "DocNodeView", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return DocNodeView;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
12
|
+
const _ChildDescriptorsContext = require("../contexts/ChildDescriptorsContext.js");
|
|
13
|
+
const _useNodeViewDescriptor = require("../hooks/useNodeViewDescriptor.js");
|
|
14
|
+
const _ChildNodeViews = require("./ChildNodeViews.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 DocNodeView = /*#__PURE__*/ (0, _react.memo)(/*#__PURE__*/ (0, _react.forwardRef)(function DocNodeView(param, ref) {
|
|
57
|
+
let { as, node, getPos, decorations, innerDecorations, setMount, ...elementProps } = param;
|
|
58
|
+
const innerRef = (0, _react.useRef)(null);
|
|
59
|
+
(0, _react.useImperativeHandle)(ref, ()=>innerRef.current);
|
|
60
|
+
(0, _react.useImperativeHandle)(setMount, ()=>innerRef.current);
|
|
61
|
+
const nodeProps = (0, _react.useMemo)(()=>({
|
|
62
|
+
node,
|
|
63
|
+
getPos,
|
|
64
|
+
decorations,
|
|
65
|
+
innerDecorations
|
|
66
|
+
}), [
|
|
67
|
+
node,
|
|
68
|
+
getPos,
|
|
69
|
+
decorations,
|
|
70
|
+
innerDecorations
|
|
71
|
+
]);
|
|
72
|
+
const { childContextValue } = (0, _useNodeViewDescriptor.useNodeViewDescriptor)(innerRef, ()=>{
|
|
73
|
+
const dom = innerRef.current;
|
|
74
|
+
return {
|
|
75
|
+
dom,
|
|
76
|
+
contentDOM: dom,
|
|
77
|
+
update () {
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}, nodeProps);
|
|
82
|
+
const children = /*#__PURE__*/ _react.default.createElement(_ChildDescriptorsContext.ChildDescriptorsContext.Provider, {
|
|
83
|
+
value: childContextValue
|
|
84
|
+
}, /*#__PURE__*/ _react.default.createElement(_ChildNodeViews.ChildNodeViews, {
|
|
85
|
+
getPos: getPos,
|
|
86
|
+
node: node,
|
|
87
|
+
innerDecorations: innerDecorations
|
|
88
|
+
}));
|
|
89
|
+
const props = {
|
|
90
|
+
...elementProps,
|
|
91
|
+
suppressContentEditableWarning: true,
|
|
92
|
+
ref: innerRef
|
|
93
|
+
};
|
|
94
|
+
const element = as ? /*#__PURE__*/ (0, _react.cloneElement)(as, props, children) : /*#__PURE__*/ (0, _react.createElement)("div", props, children);
|
|
95
|
+
return nodeProps.decorations.reduce(_ChildNodeViews.wrapInDeco, element);
|
|
96
|
+
}));
|
|
@@ -0,0 +1,119 @@
|
|
|
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 } = 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, true), [
|
|
67
|
+
mark
|
|
68
|
+
]);
|
|
69
|
+
if (!outputSpec) throw new Error(`Mark spec for ${mark.type.name} is missing toDOM`);
|
|
70
|
+
(0, _useClientLayoutEffect.useClientLayoutEffect)(()=>{
|
|
71
|
+
const siblings = siblingsRef.current;
|
|
72
|
+
return ()=>{
|
|
73
|
+
if (!viewDescRef.current) return;
|
|
74
|
+
if (siblings.includes(viewDescRef.current)) {
|
|
75
|
+
const index = siblings.indexOf(viewDescRef.current);
|
|
76
|
+
siblings.splice(index, 1);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}, [
|
|
80
|
+
siblingsRef
|
|
81
|
+
]);
|
|
82
|
+
(0, _useClientLayoutEffect.useClientLayoutEffect)(()=>{
|
|
83
|
+
if (!domRef.current) return;
|
|
84
|
+
const firstChildDesc = childDescriptors.current[0];
|
|
85
|
+
if (!viewDescRef.current) {
|
|
86
|
+
viewDescRef.current = new _viewdesc.MarkViewDesc(parentRef.current, childDescriptors.current, getPos, mark, domRef.current, firstChildDesc?.dom.parentElement ?? domRef.current, {
|
|
87
|
+
dom: domRef.current,
|
|
88
|
+
contentDOM: firstChildDesc?.dom.parentElement ?? domRef.current
|
|
89
|
+
});
|
|
90
|
+
} else {
|
|
91
|
+
viewDescRef.current.parent = parentRef.current;
|
|
92
|
+
viewDescRef.current.spec.dom = viewDescRef.current.dom = domRef.current;
|
|
93
|
+
viewDescRef.current.children = childDescriptors.current;
|
|
94
|
+
viewDescRef.current.spec.contentDOM = viewDescRef.current.contentDOM = firstChildDesc?.dom.parentElement ?? domRef.current;
|
|
95
|
+
viewDescRef.current.mark = mark;
|
|
96
|
+
}
|
|
97
|
+
if (!siblingsRef.current.includes(viewDescRef.current)) {
|
|
98
|
+
siblingsRef.current.push(viewDescRef.current);
|
|
99
|
+
}
|
|
100
|
+
siblingsRef.current.sort(_viewdesc.sortViewDescs);
|
|
101
|
+
for (const childDesc of childDescriptors.current){
|
|
102
|
+
childDesc.parent = viewDescRef.current;
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
const childContextValue = (0, _react.useMemo)(()=>({
|
|
106
|
+
parentRef: viewDescRef,
|
|
107
|
+
siblingsRef: childDescriptors
|
|
108
|
+
}), [
|
|
109
|
+
childDescriptors,
|
|
110
|
+
viewDescRef
|
|
111
|
+
]);
|
|
112
|
+
return /*#__PURE__*/ _react.default.createElement(_OutputSpec.OutputSpec, {
|
|
113
|
+
ref: domRef,
|
|
114
|
+
outputSpec: outputSpec,
|
|
115
|
+
isMark: true
|
|
116
|
+
}, /*#__PURE__*/ _react.default.createElement(_ChildDescriptorsContext.ChildDescriptorsContext.Provider, {
|
|
117
|
+
value: childContextValue
|
|
118
|
+
}, children));
|
|
119
|
+
}));
|
|
@@ -0,0 +1,86 @@
|
|
|
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 _NodeViewContext = require("../contexts/NodeViewContext.js");
|
|
13
|
+
const _CustomNodeView = require("./CustomNodeView.js");
|
|
14
|
+
const _DefaultNodeView = require("./DefaultNodeView.js");
|
|
15
|
+
const _ReactNodeView = require("./ReactNodeView.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 NodeView = /*#__PURE__*/ (0, _react.memo)(function NodeView(props) {
|
|
58
|
+
const { components, constructors } = (0, _react.useContext)(_NodeViewContext.NodeViewContext);
|
|
59
|
+
const component = components[props.node.type.name] ?? _DefaultNodeView.DefaultNodeView;
|
|
60
|
+
const constructor = constructors[props.node.type.name];
|
|
61
|
+
// Construct a wrapper component so that the node view remounts when either
|
|
62
|
+
// its component or constructor changes. A React node view would remount if
|
|
63
|
+
// its underlying component changed without this wrapper, but a custom node
|
|
64
|
+
// view otherwise uses the same React components for all custom node views.
|
|
65
|
+
const Component = (0, _react.useMemo)(()=>{
|
|
66
|
+
if (constructor) {
|
|
67
|
+
return function NodeView(props) {
|
|
68
|
+
return /*#__PURE__*/ _react.default.createElement(_CustomNodeView.CustomNodeView, {
|
|
69
|
+
constructor: constructor,
|
|
70
|
+
...props
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
} else {
|
|
74
|
+
return function NodeView(props) {
|
|
75
|
+
return /*#__PURE__*/ _react.default.createElement(_ReactNodeView.ReactNodeView, {
|
|
76
|
+
component: component,
|
|
77
|
+
...props
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}, [
|
|
82
|
+
constructor,
|
|
83
|
+
component
|
|
84
|
+
]);
|
|
85
|
+
return /*#__PURE__*/ _react.default.createElement(Component, props);
|
|
86
|
+
});
|