@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
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "ReactNodeView", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return ReactNodeView;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
12
|
+
const _ChildDescriptorsContext = require("../contexts/ChildDescriptorsContext.js");
|
|
13
|
+
const _IgnoreMutationContext = require("../contexts/IgnoreMutationContext.js");
|
|
14
|
+
const _SelectNodeContext = require("../contexts/SelectNodeContext.js");
|
|
15
|
+
const _StopEventContext = require("../contexts/StopEventContext.js");
|
|
16
|
+
const _useNodeViewDescriptor = require("../hooks/useNodeViewDescriptor.js");
|
|
17
|
+
const _ChildNodeViews = require("./ChildNodeViews.js");
|
|
18
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
19
|
+
if (typeof WeakMap !== "function") return null;
|
|
20
|
+
var cacheBabelInterop = new WeakMap();
|
|
21
|
+
var cacheNodeInterop = new WeakMap();
|
|
22
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
23
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
24
|
+
})(nodeInterop);
|
|
25
|
+
}
|
|
26
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
27
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
28
|
+
return obj;
|
|
29
|
+
}
|
|
30
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
31
|
+
return {
|
|
32
|
+
default: obj
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
36
|
+
if (cache && cache.has(obj)) {
|
|
37
|
+
return cache.get(obj);
|
|
38
|
+
}
|
|
39
|
+
var newObj = {
|
|
40
|
+
__proto__: null
|
|
41
|
+
};
|
|
42
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
43
|
+
for(var key in obj){
|
|
44
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
45
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
46
|
+
if (desc && (desc.get || desc.set)) {
|
|
47
|
+
Object.defineProperty(newObj, key, desc);
|
|
48
|
+
} else {
|
|
49
|
+
newObj[key] = obj[key];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
newObj.default = obj;
|
|
54
|
+
if (cache) {
|
|
55
|
+
cache.set(obj, newObj);
|
|
56
|
+
}
|
|
57
|
+
return newObj;
|
|
58
|
+
}
|
|
59
|
+
const ReactNodeView = /*#__PURE__*/ (0, _react.memo)(function ReactNodeView(param) {
|
|
60
|
+
let { component: Component, outerDeco, getPos, node, innerDeco } = param;
|
|
61
|
+
const [hasCustomSelectNode, setHasCustomSelectNode] = (0, _react.useState)(false);
|
|
62
|
+
const [selected, setSelected] = (0, _react.useState)(false);
|
|
63
|
+
const ref = (0, _react.useRef)(null);
|
|
64
|
+
const innerRef = (0, _react.useRef)(null);
|
|
65
|
+
const selectNodeRef = (0, _react.useRef)(null);
|
|
66
|
+
const deselectNodeRef = (0, _react.useRef)(null);
|
|
67
|
+
const stopEventRef = (0, _react.useRef)(null);
|
|
68
|
+
const ignoreMutationRef = (0, _react.useRef)(null);
|
|
69
|
+
const setSelectNode = (0, _react.useCallback)((selectHandler, deselectHandler)=>{
|
|
70
|
+
selectNodeRef.current = selectHandler;
|
|
71
|
+
deselectNodeRef.current = deselectHandler;
|
|
72
|
+
setHasCustomSelectNode(true);
|
|
73
|
+
return ()=>{
|
|
74
|
+
selectNodeRef.current = null;
|
|
75
|
+
deselectNodeRef.current = null;
|
|
76
|
+
setHasCustomSelectNode(false);
|
|
77
|
+
};
|
|
78
|
+
}, []);
|
|
79
|
+
const setStopEvent = (0, _react.useCallback)((handler)=>{
|
|
80
|
+
stopEventRef.current = handler;
|
|
81
|
+
return ()=>{
|
|
82
|
+
stopEventRef.current = null;
|
|
83
|
+
};
|
|
84
|
+
}, []);
|
|
85
|
+
const setIgnoreMutation = (0, _react.useCallback)((handler)=>{
|
|
86
|
+
ignoreMutationRef.current = handler;
|
|
87
|
+
return ()=>{
|
|
88
|
+
ignoreMutationRef.current = null;
|
|
89
|
+
return ()=>{
|
|
90
|
+
ignoreMutationRef.current = null;
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
}, []);
|
|
94
|
+
const nodeProps = (0, _react.useMemo)(()=>({
|
|
95
|
+
node: node,
|
|
96
|
+
getPos: getPos,
|
|
97
|
+
decorations: outerDeco,
|
|
98
|
+
innerDecorations: innerDeco
|
|
99
|
+
}), [
|
|
100
|
+
getPos,
|
|
101
|
+
innerDeco,
|
|
102
|
+
node,
|
|
103
|
+
outerDeco
|
|
104
|
+
]);
|
|
105
|
+
const { childContextValue, contentDOM, nodeDOM } = (0, _useNodeViewDescriptor.useNodeViewDescriptor)(ref, ()=>{
|
|
106
|
+
setSelected(false);
|
|
107
|
+
return {
|
|
108
|
+
dom: innerRef.current ?? ref.current,
|
|
109
|
+
update () {
|
|
110
|
+
return true;
|
|
111
|
+
},
|
|
112
|
+
multiType: true,
|
|
113
|
+
selectNode () {
|
|
114
|
+
const selectNode = selectNodeRef.current;
|
|
115
|
+
if (selectNode) {
|
|
116
|
+
selectNode.call(this);
|
|
117
|
+
}
|
|
118
|
+
setSelected(true);
|
|
119
|
+
},
|
|
120
|
+
deselectNode () {
|
|
121
|
+
const deselectNode = deselectNodeRef.current;
|
|
122
|
+
if (deselectNode) {
|
|
123
|
+
deselectNode.call(this);
|
|
124
|
+
}
|
|
125
|
+
setSelected(false);
|
|
126
|
+
},
|
|
127
|
+
stopEvent (event) {
|
|
128
|
+
const stopEvent = stopEventRef.current;
|
|
129
|
+
if (stopEvent) {
|
|
130
|
+
return stopEvent.call(this, event);
|
|
131
|
+
}
|
|
132
|
+
return false;
|
|
133
|
+
},
|
|
134
|
+
ignoreMutation (mutation) {
|
|
135
|
+
const ignoreMutation = ignoreMutationRef.current;
|
|
136
|
+
if (ignoreMutation) {
|
|
137
|
+
return ignoreMutation.call(this, mutation);
|
|
138
|
+
}
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
}, nodeProps);
|
|
143
|
+
const props = {
|
|
144
|
+
nodeProps,
|
|
145
|
+
...!contentDOM && !nodeProps.node.isText && nodeDOM?.nodeName !== "BR" ? {
|
|
146
|
+
contentEditable: false,
|
|
147
|
+
suppressContentEditableWarning: true
|
|
148
|
+
} : null,
|
|
149
|
+
...!hasCustomSelectNode && selected ? {
|
|
150
|
+
className: "ProseMirror-selectednode"
|
|
151
|
+
} : null,
|
|
152
|
+
...!hasCustomSelectNode && selected || node.type.spec.draggable ? {
|
|
153
|
+
draggable: true
|
|
154
|
+
} : null,
|
|
155
|
+
ref: innerRef
|
|
156
|
+
};
|
|
157
|
+
const children = !node.isLeaf ? /*#__PURE__*/ _react.default.createElement(_ChildNodeViews.ChildNodeViews, {
|
|
158
|
+
getPos: getPos,
|
|
159
|
+
node: node,
|
|
160
|
+
innerDecorations: innerDeco
|
|
161
|
+
}) : null;
|
|
162
|
+
const element = /*#__PURE__*/ (0, _react.cloneElement)(outerDeco.reduce(_ChildNodeViews.wrapInDeco, /*#__PURE__*/ _react.default.createElement(Component, props, children)), {
|
|
163
|
+
ref
|
|
164
|
+
});
|
|
165
|
+
return /*#__PURE__*/ _react.default.createElement(_SelectNodeContext.SelectNodeContext.Provider, {
|
|
166
|
+
value: setSelectNode
|
|
167
|
+
}, /*#__PURE__*/ _react.default.createElement(_StopEventContext.StopEventContext.Provider, {
|
|
168
|
+
value: setStopEvent
|
|
169
|
+
}, /*#__PURE__*/ _react.default.createElement(_IgnoreMutationContext.IgnoreMutationContext.Provider, {
|
|
170
|
+
value: setIgnoreMutation
|
|
171
|
+
}, /*#__PURE__*/ _react.default.createElement(_ChildDescriptorsContext.ChildDescriptorsContext.Provider, {
|
|
172
|
+
value: childContextValue
|
|
173
|
+
}, element))));
|
|
174
|
+
});
|
|
@@ -113,28 +113,28 @@ const ReactNodeView = /*#__PURE__*/ (0, _react.memo)(function ReactNodeView(para
|
|
|
113
113
|
selectNode () {
|
|
114
114
|
const selectNode = selectNodeRef.current;
|
|
115
115
|
if (selectNode) {
|
|
116
|
-
selectNode();
|
|
116
|
+
selectNode.call(this);
|
|
117
117
|
}
|
|
118
118
|
setSelected(true);
|
|
119
119
|
},
|
|
120
120
|
deselectNode () {
|
|
121
121
|
const deselectNode = deselectNodeRef.current;
|
|
122
122
|
if (deselectNode) {
|
|
123
|
-
deselectNode();
|
|
123
|
+
deselectNode.call(this);
|
|
124
124
|
}
|
|
125
125
|
setSelected(false);
|
|
126
126
|
},
|
|
127
127
|
stopEvent (event) {
|
|
128
128
|
const stopEvent = stopEventRef.current;
|
|
129
129
|
if (stopEvent) {
|
|
130
|
-
return stopEvent(event);
|
|
130
|
+
return stopEvent.call(this, event);
|
|
131
131
|
}
|
|
132
132
|
return false;
|
|
133
133
|
},
|
|
134
134
|
ignoreMutation (mutation) {
|
|
135
135
|
const ignoreMutation = ignoreMutationRef.current;
|
|
136
136
|
if (ignoreMutation) {
|
|
137
|
-
return ignoreMutation(mutation);
|
|
137
|
+
return ignoreMutation.call(this, mutation);
|
|
138
138
|
}
|
|
139
139
|
return false;
|
|
140
140
|
}
|
|
@@ -103,7 +103,11 @@ function useEditor(mount, options) {
|
|
|
103
103
|
// running effects. Running effects will reattach selection
|
|
104
104
|
// change listeners if the EditorView has been destroyed.
|
|
105
105
|
if (view instanceof _ReactEditorView.ReactEditorView && !view.isDestroyed) {
|
|
106
|
+
// Plugins might dispatch transactions from their
|
|
107
|
+
// view update lifecycle hooks
|
|
108
|
+
flushSyncRef.current = false;
|
|
106
109
|
view.commitPendingEffects();
|
|
110
|
+
flushSyncRef.current = true;
|
|
107
111
|
}
|
|
108
112
|
});
|
|
109
113
|
view.update(directEditorProps);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "ReactProseMirrorNodeView", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return ReactProseMirrorNodeView;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _core = require("@tiptap/core");
|
|
12
|
+
let ReactProseMirrorNodeView = class ReactProseMirrorNodeView extends _core.NodeView {
|
|
13
|
+
_dom;
|
|
14
|
+
_contentDOM;
|
|
15
|
+
constructor(component, props, dom, contentDOM, options){
|
|
16
|
+
super(component, props, options);
|
|
17
|
+
this._dom = dom;
|
|
18
|
+
this._contentDOM = contentDOM;
|
|
19
|
+
}
|
|
20
|
+
get dom() {
|
|
21
|
+
return this._dom;
|
|
22
|
+
}
|
|
23
|
+
get contentDOM() {
|
|
24
|
+
return this._contentDOM;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "TiptapEditor", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return TiptapEditor;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _core = require("@tiptap/core");
|
|
12
|
+
const _prosemirrorstate = require("prosemirror-state");
|
|
13
|
+
const _StaticEditorView = require("../StaticEditorView.js");
|
|
14
|
+
let TiptapEditor = class TiptapEditor extends _core.Editor {
|
|
15
|
+
constructor(options = {}){
|
|
16
|
+
super({
|
|
17
|
+
...options,
|
|
18
|
+
element: null
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
get view() {
|
|
22
|
+
return(// @ts-expect-error private property
|
|
23
|
+
this.editorView ?? new _StaticEditorView.StaticEditorView({
|
|
24
|
+
state: _prosemirrorstate.EditorState.create({
|
|
25
|
+
schema: this.extensionManager.schema
|
|
26
|
+
}),
|
|
27
|
+
...this.options.editorProps,
|
|
28
|
+
attributes: {
|
|
29
|
+
role: "textbox",
|
|
30
|
+
...this.options.editorProps.attributes
|
|
31
|
+
}
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
};
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "TiptapEditorContent", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return TiptapEditorContent;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
12
|
+
const _reactdom = require("react-dom");
|
|
13
|
+
const _ProseMirrorDoc = require("../components/ProseMirrorDoc.js");
|
|
14
|
+
const _useEditorEffect = require("../hooks/useEditorEffect.js");
|
|
15
|
+
const _TiptapEditorContext = require("./contexts/TiptapEditorContext.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
|
+
/**
|
|
58
|
+
* This component renders all of the editor's registered "React renderers".
|
|
59
|
+
*/ const Portals = (param)=>{
|
|
60
|
+
let { contentComponent } = param;
|
|
61
|
+
const renderers = (0, _react.useSyncExternalStore)(contentComponent.subscribe, contentComponent.getSnapshot, contentComponent.getServerSnapshot);
|
|
62
|
+
return /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, Object.values(renderers));
|
|
63
|
+
};
|
|
64
|
+
function getInstance() {
|
|
65
|
+
const subscribers = new Set();
|
|
66
|
+
let renderers = {};
|
|
67
|
+
return {
|
|
68
|
+
/**
|
|
69
|
+
* Subscribe to the editor instance's changes.
|
|
70
|
+
*/ subscribe (callback) {
|
|
71
|
+
subscribers.add(callback);
|
|
72
|
+
return ()=>{
|
|
73
|
+
subscribers.delete(callback);
|
|
74
|
+
};
|
|
75
|
+
},
|
|
76
|
+
getSnapshot () {
|
|
77
|
+
return renderers;
|
|
78
|
+
},
|
|
79
|
+
getServerSnapshot () {
|
|
80
|
+
return renderers;
|
|
81
|
+
},
|
|
82
|
+
/**
|
|
83
|
+
* Adds a new React Renderer to the editor.
|
|
84
|
+
*/ setRenderer (id, renderer) {
|
|
85
|
+
renderers = {
|
|
86
|
+
...renderers,
|
|
87
|
+
[id]: /*#__PURE__*/ (0, _reactdom.createPortal)(renderer.reactElement, renderer.element, id)
|
|
88
|
+
};
|
|
89
|
+
subscribers.forEach((subscriber)=>subscriber());
|
|
90
|
+
},
|
|
91
|
+
/**
|
|
92
|
+
* Removes a React Renderer from the editor.
|
|
93
|
+
*/ removeRenderer (id) {
|
|
94
|
+
const nextRenderers = {
|
|
95
|
+
...renderers
|
|
96
|
+
};
|
|
97
|
+
delete nextRenderers[id];
|
|
98
|
+
renderers = nextRenderers;
|
|
99
|
+
subscribers.forEach((subscriber)=>subscriber());
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function TiptapEditorContent(param) {
|
|
104
|
+
let { editor: editorProp, ...props } = param;
|
|
105
|
+
const editor = editorProp;
|
|
106
|
+
const { onEditorInitialize, onEditorDeinitialize } = (0, _react.useContext)(_TiptapEditorContext.TiptapEditorContext);
|
|
107
|
+
(0, _useEditorEffect.useEditorEffect)((view)=>{
|
|
108
|
+
if (editor.view === view) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
// @ts-expect-error private property
|
|
112
|
+
editor.editorView = view;
|
|
113
|
+
editor.contentComponent = getInstance();
|
|
114
|
+
// @ts-expect-error private method
|
|
115
|
+
editor.injectCSS();
|
|
116
|
+
const dom = view.dom;
|
|
117
|
+
dom.editor = editor;
|
|
118
|
+
setTimeout(()=>{
|
|
119
|
+
if (editor.isDestroyed) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
editor.commands.focus(editor.options.autofocus);
|
|
123
|
+
editor.emit("create", {
|
|
124
|
+
editor
|
|
125
|
+
});
|
|
126
|
+
editor.isInitialized = true;
|
|
127
|
+
onEditorInitialize();
|
|
128
|
+
});
|
|
129
|
+
return ()=>{
|
|
130
|
+
editor.isInitialized = false;
|
|
131
|
+
editor.contentComponent = null;
|
|
132
|
+
onEditorDeinitialize();
|
|
133
|
+
};
|
|
134
|
+
}, [
|
|
135
|
+
editor,
|
|
136
|
+
onEditorDeinitialize,
|
|
137
|
+
onEditorInitialize
|
|
138
|
+
]);
|
|
139
|
+
return /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/ _react.default.createElement(_ProseMirrorDoc.ProseMirrorDoc, props), editor?.contentComponent && /*#__PURE__*/ _react.default.createElement(Portals, {
|
|
140
|
+
contentComponent: editor.contentComponent
|
|
141
|
+
}));
|
|
142
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "TiptapEditorView", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return TiptapEditorView;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _react = require("@tiptap/react");
|
|
12
|
+
const _react1 = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
13
|
+
const _ProseMirror = require("../components/ProseMirror.js");
|
|
14
|
+
const _useForceUpdate = require("../hooks/useForceUpdate.js");
|
|
15
|
+
const _TiptapEditorContext = require("./contexts/TiptapEditorContext.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 TiptapEditorView(param) {
|
|
58
|
+
let { editor, nodeViews, markViews, children, static: isStatic = false } = param;
|
|
59
|
+
const [isEditorInitialized, setIsEditorInitialized] = (0, _react1.useState)(editor.isInitialized);
|
|
60
|
+
const forceUpdate = (0, _useForceUpdate.useForceUpdate)();
|
|
61
|
+
const dispatchTransaction = (0, _react1.useCallback)((tr)=>{
|
|
62
|
+
// @ts-expect-error calling private method
|
|
63
|
+
editor.dispatchTransaction(tr);
|
|
64
|
+
// Tiptap's dispatchTransaction doesn't trigger
|
|
65
|
+
// a re-render, so we need to manually force
|
|
66
|
+
// one to ensure that React stays in sync.
|
|
67
|
+
forceUpdate();
|
|
68
|
+
}, [
|
|
69
|
+
editor,
|
|
70
|
+
forceUpdate
|
|
71
|
+
]);
|
|
72
|
+
const initialEditorProps = {
|
|
73
|
+
...editor.options.editorProps,
|
|
74
|
+
attributes: {
|
|
75
|
+
role: "textbox",
|
|
76
|
+
...editor.options.editorProps?.attributes
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
const { nodeViews: customNodeViews, markViews: customMarkViews } = editor.isDestroyed ? {
|
|
80
|
+
nodeViews: undefined,
|
|
81
|
+
markViews: undefined
|
|
82
|
+
} : editor.view.props;
|
|
83
|
+
const contextValue = (0, _react1.useMemo)(()=>({
|
|
84
|
+
editor
|
|
85
|
+
}), [
|
|
86
|
+
editor
|
|
87
|
+
]);
|
|
88
|
+
const onEditorInitialize = (0, _react1.useCallback)(()=>{
|
|
89
|
+
setIsEditorInitialized(true);
|
|
90
|
+
}, []);
|
|
91
|
+
const onEditorDeinitialize = (0, _react1.useCallback)(()=>{
|
|
92
|
+
setIsEditorInitialized(false);
|
|
93
|
+
}, []);
|
|
94
|
+
const tiptapEditorContextValue = (0, _react1.useMemo)(()=>({
|
|
95
|
+
isEditorInitialized,
|
|
96
|
+
onEditorInitialize,
|
|
97
|
+
onEditorDeinitialize
|
|
98
|
+
}), [
|
|
99
|
+
isEditorInitialized,
|
|
100
|
+
onEditorDeinitialize,
|
|
101
|
+
onEditorInitialize
|
|
102
|
+
]);
|
|
103
|
+
return /*#__PURE__*/ _react1.default.createElement(_ProseMirror.ProseMirror, {
|
|
104
|
+
static: isStatic,
|
|
105
|
+
className: "tiptap",
|
|
106
|
+
...initialEditorProps,
|
|
107
|
+
markViews: markViews,
|
|
108
|
+
customMarkViews: customMarkViews,
|
|
109
|
+
nodeViews: nodeViews,
|
|
110
|
+
customNodeViews: customNodeViews,
|
|
111
|
+
state: editor.state,
|
|
112
|
+
dispatchTransaction: dispatchTransaction
|
|
113
|
+
}, /*#__PURE__*/ _react1.default.createElement(_react.EditorContext.Provider, {
|
|
114
|
+
value: contextValue
|
|
115
|
+
}, /*#__PURE__*/ _react1.default.createElement(_TiptapEditorContext.TiptapEditorContext.Provider, {
|
|
116
|
+
value: tiptapEditorContextValue
|
|
117
|
+
}, children)));
|
|
118
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "ReactProseMirrorNodeView", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return ReactProseMirrorNodeView;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _core = require("@tiptap/core");
|
|
12
|
+
let ReactProseMirrorNodeView = class ReactProseMirrorNodeView extends _core.NodeView {
|
|
13
|
+
_dom;
|
|
14
|
+
_contentDOM;
|
|
15
|
+
constructor(component, props, dom, contentDOM, options){
|
|
16
|
+
super(component, props, options);
|
|
17
|
+
this._dom = dom;
|
|
18
|
+
this._contentDOM = contentDOM;
|
|
19
|
+
}
|
|
20
|
+
get dom() {
|
|
21
|
+
return this._dom;
|
|
22
|
+
}
|
|
23
|
+
get contentDOM() {
|
|
24
|
+
return this._contentDOM;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "TiptapEditorContext", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return TiptapEditorContext;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _react = require("react");
|
|
12
|
+
const TiptapEditorContext = (0, _react.createContext)(null);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "ReactProseMirror", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return ReactProseMirror;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _core = require("@tiptap/core");
|
|
12
|
+
const _reorderSiblings = require("../../commands/reorderSiblings.js");
|
|
13
|
+
const _reactKeys = require("../../plugins/reactKeys.js");
|
|
14
|
+
const ReactProseMirror = _core.Extension.create({
|
|
15
|
+
name: "@handlewithcare/react-prosemirror/reactKeys",
|
|
16
|
+
addProseMirrorPlugins () {
|
|
17
|
+
return [
|
|
18
|
+
(0, _reactKeys.reactKeys)()
|
|
19
|
+
];
|
|
20
|
+
},
|
|
21
|
+
addCommands () {
|
|
22
|
+
return {
|
|
23
|
+
/**
|
|
24
|
+
* Command that reorders the adjacent nodes starting
|
|
25
|
+
* at the provided position.
|
|
26
|
+
*
|
|
27
|
+
* @param pos - The `start` position of the parent of the nodes being reordered
|
|
28
|
+
* @param order - The new order for the nodes, expressed as an array of indices. For
|
|
29
|
+
* example, to swap the first two nodes in a set of three, `order`
|
|
30
|
+
* would be set to `[1, 0, 2]`. To move the first node to the end,
|
|
31
|
+
* and keep the other two in relative order, set `order` to `[1, 2, 0]`.
|
|
32
|
+
*/ reorderSiblings (initialPos, order) {
|
|
33
|
+
return function reorderSiblingsCommand(param) {
|
|
34
|
+
let { tr, state, dispatch } = param;
|
|
35
|
+
return (0, _reorderSiblings.reorderSiblingsOnTransaction)(initialPos, order, tr, state, dispatch);
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "useIsInReactProseMirror", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return useIsInReactProseMirror;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _react = require("react");
|
|
12
|
+
const _EditorContext = require("../../contexts/EditorContext.js");
|
|
13
|
+
function useIsInReactProseMirror() {
|
|
14
|
+
return (0, _react.useContext)(_EditorContext.EditorContext) !== null;
|
|
15
|
+
}
|