@handlewithcare/react-prosemirror 3.1.0-tiptap.40 → 3.1.0-tiptap.42
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/README.md +2 -2
- package/dist/cjs/ReactEditorView.js +71 -75
- package/dist/cjs/StaticEditorView.js +19 -22
- package/dist/cjs/browser.js +1 -3
- package/dist/cjs/commands/reorderSiblings.js +9 -13
- package/dist/cjs/components/ChildNodeViews.js +68 -71
- package/dist/cjs/components/CursorWrapper.js +26 -17
- package/dist/cjs/components/LayoutGroup.js +12 -16
- package/dist/cjs/components/NativeWidgetView.js +15 -19
- package/dist/cjs/components/OutputSpec.js +9 -13
- package/dist/cjs/components/ProseMirror.js +37 -27
- package/dist/cjs/components/ProseMirrorDoc.js +25 -18
- package/dist/cjs/components/SeparatorHackView.js +20 -21
- package/dist/cjs/components/TextNodeView.js +22 -20
- package/dist/cjs/components/TrailingHackView.js +13 -17
- package/dist/cjs/components/WidgetView.js +14 -18
- package/dist/cjs/components/marks/DefaultMarkView.js +27 -15
- package/dist/cjs/components/marks/MarkView.js +32 -23
- package/dist/cjs/components/marks/MarkViewConstructorView.js +38 -22
- package/dist/cjs/components/marks/ReactMarkView.js +27 -16
- package/dist/cjs/components/nodes/DefaultNodeView.js +27 -15
- package/dist/cjs/components/nodes/DocNodeView.js +12 -16
- package/dist/cjs/components/nodes/NodeView.js +33 -26
- package/dist/cjs/components/nodes/NodeViewConstructorView.js +45 -29
- package/dist/cjs/components/nodes/ReactNodeView.js +39 -27
- package/dist/cjs/constants.js +6 -10
- package/dist/cjs/contexts/ChildDescriptionsContext.js +1 -3
- package/dist/cjs/contexts/EditorContext.js +1 -3
- package/dist/cjs/contexts/EditorStateContext.js +1 -3
- package/dist/cjs/contexts/IgnoreMutationContext.js +1 -3
- package/dist/cjs/contexts/LayoutGroupContext.js +1 -3
- package/dist/cjs/contexts/NodeViewContext.js +1 -3
- package/dist/cjs/contexts/SelectNodeContext.js +1 -3
- package/dist/cjs/contexts/StopEventContext.js +1 -3
- package/dist/cjs/decorations/ReactWidgetType.js +13 -19
- package/dist/cjs/decorations/computeDocDeco.js +3 -5
- package/dist/cjs/decorations/iterDeco.js +17 -19
- package/dist/cjs/decorations/viewDecorations.js +12 -15
- package/dist/cjs/dom.js +13 -34
- package/dist/cjs/findDOMNode.js +5 -9
- package/dist/cjs/hooks/useClientLayoutEffect.js +1 -3
- package/dist/cjs/hooks/useComponentEventListeners.js +6 -7
- package/dist/cjs/hooks/useEditor.js +30 -28
- package/dist/cjs/hooks/useEditorEffect.js +7 -9
- package/dist/cjs/hooks/useEditorEventCallback.js +7 -9
- package/dist/cjs/hooks/useEditorEventListener.js +6 -8
- package/dist/cjs/hooks/useEditorState.js +3 -5
- package/dist/cjs/hooks/useEffectEvent.js +1 -3
- package/dist/cjs/hooks/useForceUpdate.js +1 -3
- package/dist/cjs/hooks/useIgnoreMutation.js +7 -9
- package/dist/cjs/hooks/useIsEditorStatic.js +5 -5
- package/dist/cjs/hooks/useIsNodeSelected.js +3 -5
- package/dist/cjs/hooks/useLayoutGroupEffect.js +5 -7
- package/dist/cjs/hooks/useMarkViewDescription.js +25 -24
- package/dist/cjs/hooks/useNodePos.js +5 -7
- package/dist/cjs/hooks/useNodeViewDescription.js +41 -28
- package/dist/cjs/hooks/useReactKeys.js +5 -7
- package/dist/cjs/hooks/useSelectNode.js +8 -10
- package/dist/cjs/hooks/useStopEvent.js +7 -9
- package/dist/cjs/index.js +34 -66
- package/dist/cjs/plugins/beforeInputPlugin.js +23 -20
- package/dist/cjs/plugins/componentEventListeners.js +6 -8
- package/dist/cjs/plugins/componentEventListenersPlugin.js +6 -8
- package/dist/cjs/plugins/reactKeys.js +10 -15
- package/dist/cjs/props.js +19 -23
- package/dist/cjs/refs.js +1 -3
- package/dist/cjs/testing/editorViewTestHelpers.js +47 -40
- package/dist/cjs/testing/setupProseMirrorView.js +4 -7
- package/dist/cjs/tiptap/ReactProseMirrorNodeView.js +6 -10
- package/dist/cjs/tiptap/TiptapEditor.js +14 -15
- package/dist/cjs/tiptap/TiptapEditorContent.js +28 -18
- package/dist/cjs/tiptap/TiptapEditorView.js +34 -23
- package/dist/cjs/tiptap/contexts/TiptapEditorContext.js +1 -3
- package/dist/cjs/tiptap/extensions/ReactProseMirror.js +6 -8
- package/dist/cjs/tiptap/extensions/ReactProseMirrorCommands.js +3 -5
- package/dist/cjs/tiptap/extensions/commands/updateAttributes.js +2 -4
- package/dist/cjs/tiptap/hooks/useIsInReactProseMirror.js +3 -5
- package/dist/cjs/tiptap/hooks/useTiptapEditor.js +14 -12
- package/dist/cjs/tiptap/hooks/useTiptapEditorEffect.js +10 -12
- package/dist/cjs/tiptap/hooks/useTiptapEditorEventCallback.js +4 -6
- package/dist/cjs/tiptap/index.js +18 -36
- package/dist/cjs/tiptap/tiptapNodeView.js +62 -48
- package/dist/cjs/viewdesc.js +95 -119
- package/dist/esm/ReactEditorView.js +67 -69
- package/dist/esm/StaticEditorView.js +18 -19
- package/dist/esm/commands/reorderSiblings.js +5 -5
- package/dist/esm/components/ChildNodeViews.js +36 -33
- package/dist/esm/components/CursorWrapper.js +18 -5
- package/dist/esm/components/LayoutGroup.js +1 -1
- package/dist/esm/components/NativeWidgetView.js +2 -2
- package/dist/esm/components/OutputSpec.js +1 -1
- package/dist/esm/components/ProseMirror.js +17 -3
- package/dist/esm/components/ProseMirrorDoc.js +19 -6
- package/dist/esm/components/SeparatorHackView.js +8 -5
- package/dist/esm/components/TextNodeView.js +10 -6
- package/dist/esm/components/TrailingHackView.js +2 -2
- package/dist/esm/components/WidgetView.js +3 -3
- package/dist/esm/components/marks/DefaultMarkView.js +22 -6
- package/dist/esm/components/marks/MarkView.js +24 -11
- package/dist/esm/components/marks/MarkViewConstructorView.js +27 -7
- package/dist/esm/components/marks/ReactMarkView.js +18 -3
- package/dist/esm/components/nodes/DefaultNodeView.js +22 -6
- package/dist/esm/components/nodes/DocNodeView.js +2 -2
- package/dist/esm/components/nodes/NodeView.js +24 -11
- package/dist/esm/components/nodes/NodeViewConstructorView.js +31 -11
- package/dist/esm/components/nodes/ReactNodeView.js +22 -6
- package/dist/esm/decorations/ReactWidgetType.js +8 -10
- package/dist/esm/decorations/iterDeco.js +13 -13
- package/dist/esm/decorations/viewDecorations.js +6 -7
- package/dist/esm/dom.js +2 -1
- package/dist/esm/findDOMNode.js +1 -1
- package/dist/esm/hooks/useComponentEventListeners.js +3 -2
- package/dist/esm/hooks/useEditor.js +9 -5
- package/dist/esm/hooks/useEditorEffect.js +1 -1
- package/dist/esm/hooks/useEditorEventCallback.js +1 -1
- package/dist/esm/hooks/useEditorEventListener.js +1 -1
- package/dist/esm/hooks/useIsEditorStatic.js +3 -1
- package/dist/esm/hooks/useMarkViewDescription.js +10 -7
- package/dist/esm/hooks/useNodeViewDescription.js +22 -7
- package/dist/esm/hooks/useReactKeys.js +1 -1
- package/dist/esm/plugins/beforeInputPlugin.js +17 -12
- package/dist/esm/plugins/reactKeys.js +4 -3
- package/dist/esm/props.js +15 -15
- package/dist/esm/testing/editorViewTestHelpers.js +31 -20
- package/dist/esm/testing/setupProseMirrorView.js +2 -1
- package/dist/esm/tiptap/ReactProseMirrorNodeView.js +5 -7
- package/dist/esm/tiptap/TiptapEditor.js +10 -9
- package/dist/esm/tiptap/TiptapEditorContent.js +18 -4
- package/dist/esm/tiptap/TiptapEditorView.js +23 -8
- package/dist/esm/tiptap/extensions/ReactProseMirror.js +1 -1
- package/dist/esm/tiptap/extensions/commands/updateAttributes.js +1 -1
- package/dist/esm/tiptap/hooks/useTiptapEditor.js +8 -4
- package/dist/esm/tiptap/hooks/useTiptapEditorEffect.js +4 -4
- package/dist/esm/tiptap/hooks/useTiptapEditorEventCallback.js +1 -1
- package/dist/esm/tiptap/tiptapNodeView.js +38 -20
- package/dist/esm/viewdesc.js +72 -74
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/ReactEditorView.d.ts +2 -2
- package/dist/types/StaticEditorView.d.ts +2 -1
- package/dist/types/props.d.ts +26 -26
- package/dist/types/viewdesc.d.ts +2 -0
- package/package.json +10 -6
|
@@ -4,23 +4,35 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
});
|
|
5
5
|
Object.defineProperty(exports, "tiptapNodeView", {
|
|
6
6
|
enumerable: true,
|
|
7
|
-
get:
|
|
8
|
-
return tiptapNodeView;
|
|
9
|
-
}
|
|
7
|
+
get: ()=>tiptapNodeView
|
|
10
8
|
});
|
|
11
9
|
const _core = require("@tiptap/core");
|
|
12
10
|
const _react = require("@tiptap/react");
|
|
13
|
-
const _classnames = /*#__PURE__*/
|
|
14
|
-
const _react1 = /*#__PURE__*/
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
function
|
|
11
|
+
const _classnames = /*#__PURE__*/ _interopRequireDefault(require("classnames"));
|
|
12
|
+
const _react1 = /*#__PURE__*/ _interopRequireWildcard(require("react"));
|
|
13
|
+
const _useEditorEventCallbackJs = require("../hooks/useEditorEventCallback.js");
|
|
14
|
+
const _useIgnoreMutationJs = require("../hooks/useIgnoreMutation.js");
|
|
15
|
+
const _useIsNodeSelectedJs = require("../hooks/useIsNodeSelected.js");
|
|
16
|
+
const _useStopEventJs = require("../hooks/useStopEvent.js");
|
|
17
|
+
const _propsJs = require("../props.js");
|
|
18
|
+
const _refsJs = require("../refs.js");
|
|
19
|
+
const _reactProseMirrorNodeViewJs = require("./ReactProseMirrorNodeView.js");
|
|
20
|
+
const _useTiptapEditorEventCallbackJs = require("./hooks/useTiptapEditorEventCallback.js");
|
|
21
|
+
function _extends() {
|
|
22
|
+
_extends = Object.assign || function(target) {
|
|
23
|
+
for(var i = 1; i < arguments.length; i++){
|
|
24
|
+
var source = arguments[i];
|
|
25
|
+
for(var key in source){
|
|
26
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
27
|
+
target[key] = source[key];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return target;
|
|
32
|
+
};
|
|
33
|
+
return _extends.apply(this, arguments);
|
|
34
|
+
}
|
|
35
|
+
function _interopRequireDefault(obj) {
|
|
24
36
|
return obj && obj.__esModule ? obj : {
|
|
25
37
|
default: obj
|
|
26
38
|
};
|
|
@@ -33,7 +45,7 @@ function _getRequireWildcardCache(nodeInterop) {
|
|
|
33
45
|
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
34
46
|
})(nodeInterop);
|
|
35
47
|
}
|
|
36
|
-
function
|
|
48
|
+
function _interopRequireWildcard(obj, nodeInterop) {
|
|
37
49
|
if (!nodeInterop && obj && obj.__esModule) {
|
|
38
50
|
return obj;
|
|
39
51
|
}
|
|
@@ -46,9 +58,7 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
46
58
|
if (cache && cache.has(obj)) {
|
|
47
59
|
return cache.get(obj);
|
|
48
60
|
}
|
|
49
|
-
var newObj = {
|
|
50
|
-
__proto__: null
|
|
51
|
-
};
|
|
61
|
+
var newObj = {};
|
|
52
62
|
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
53
63
|
for(var key in obj){
|
|
54
64
|
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
@@ -67,15 +77,17 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
67
77
|
return newObj;
|
|
68
78
|
}
|
|
69
79
|
function tiptapNodeView(param) {
|
|
70
|
-
let { component: WrappedComponent, extension, as, className =
|
|
80
|
+
let { component: WrappedComponent , extension , as , className ="" , attrs , contentDOMElementTag: InnerTag = "div" , stopEvent , ignoreMutation } = param;
|
|
71
81
|
const TiptapNodeView = /*#__PURE__*/ (0, _react1.memo)(/*#__PURE__*/ (0, _react1.forwardRef)(function TiptapNodeView(param, ref) {
|
|
72
|
-
let { children, nodeProps, ...props } = param;
|
|
73
|
-
const { node, getPos, decorations, innerDecorations, contentDOMRef
|
|
74
|
-
const OuterTag = as
|
|
75
|
-
const { editor
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
|
|
82
|
+
let { children , nodeProps , ...props } = param;
|
|
83
|
+
const { node , getPos , decorations , innerDecorations , contentDOMRef } = nodeProps;
|
|
84
|
+
const OuterTag = as !== null && as !== void 0 ? as : node.type.isInline ? "span" : "div";
|
|
85
|
+
const { editor } = (0, _react.useCurrentEditor)();
|
|
86
|
+
var ref1;
|
|
87
|
+
const extensionManager = (ref1 = editor === null || editor === void 0 ? void 0 : editor.extensionManager) !== null && ref1 !== void 0 ? ref1 : null;
|
|
88
|
+
var ref2;
|
|
89
|
+
const extensions = (ref2 = extensionManager === null || extensionManager === void 0 ? void 0 : extensionManager.extensions) !== null && ref2 !== void 0 ? ref2 : null;
|
|
90
|
+
const selected = (0, _useIsNodeSelectedJs.useIsNodeSelected)();
|
|
79
91
|
const isDraggingRef = (0, _react1.useRef)(false);
|
|
80
92
|
const htmlAttributes = (0, _react1.useMemo)(()=>{
|
|
81
93
|
if (!extensions) return {};
|
|
@@ -86,9 +98,9 @@ function tiptapNodeView(param) {
|
|
|
86
98
|
extensions,
|
|
87
99
|
node
|
|
88
100
|
]);
|
|
89
|
-
(0,
|
|
101
|
+
(0, _useStopEventJs.useStopEvent)(function(_, event) {
|
|
90
102
|
if (!editor || !(this.dom instanceof HTMLElement)) return false;
|
|
91
|
-
const nodeView = new
|
|
103
|
+
const nodeView = new _reactProseMirrorNodeViewJs.ReactProseMirrorNodeView(WrappedComponent, {
|
|
92
104
|
extension,
|
|
93
105
|
decorations,
|
|
94
106
|
editor,
|
|
@@ -111,11 +123,12 @@ function tiptapNodeView(param) {
|
|
|
111
123
|
isDraggingRef.current = nodeView.isDragging;
|
|
112
124
|
return result;
|
|
113
125
|
}
|
|
114
|
-
|
|
126
|
+
var ref;
|
|
127
|
+
const result1 = (ref = nodeView.stopEvent(event)) !== null && ref !== void 0 ? ref : false;
|
|
115
128
|
isDraggingRef.current = nodeView.isDragging;
|
|
116
|
-
return
|
|
129
|
+
return result1;
|
|
117
130
|
});
|
|
118
|
-
(0,
|
|
131
|
+
(0, _useIgnoreMutationJs.useIgnoreMutation)(function(_, mutation) {
|
|
119
132
|
if (ignoreMutation) {
|
|
120
133
|
return ignoreMutation.call({
|
|
121
134
|
name: extension.name,
|
|
@@ -126,7 +139,7 @@ function tiptapNodeView(param) {
|
|
|
126
139
|
});
|
|
127
140
|
}
|
|
128
141
|
if (!editor || !(this.dom instanceof HTMLElement)) return false;
|
|
129
|
-
const nodeView = new
|
|
142
|
+
const nodeView = new _reactProseMirrorNodeViewJs.ReactProseMirrorNodeView(WrappedComponent, {
|
|
130
143
|
extension,
|
|
131
144
|
decorations,
|
|
132
145
|
editor,
|
|
@@ -136,15 +149,16 @@ function tiptapNodeView(param) {
|
|
|
136
149
|
node,
|
|
137
150
|
view: editor.view
|
|
138
151
|
}, this.dom, this.contentDOM);
|
|
139
|
-
|
|
152
|
+
var ref;
|
|
153
|
+
return (ref = nodeView.ignoreMutation(mutation)) !== null && ref !== void 0 ? ref : false;
|
|
140
154
|
});
|
|
141
|
-
const { extraClassName, htmlProps
|
|
155
|
+
const { extraClassName , htmlProps } = (0, _react1.useMemo)(()=>{
|
|
142
156
|
if (!attrs) return {};
|
|
143
157
|
const resolvedAttrs = typeof attrs === "function" ? attrs({
|
|
144
158
|
node,
|
|
145
159
|
HTMLAttributes: htmlAttributes
|
|
146
160
|
}) : attrs;
|
|
147
|
-
const { className: extraClassName, ...htmlProps } = (0,
|
|
161
|
+
const { className: extraClassName , ...htmlProps } = (0, _propsJs.htmlAttrsToReactProps)(resolvedAttrs);
|
|
148
162
|
return {
|
|
149
163
|
extraClassName,
|
|
150
164
|
htmlProps
|
|
@@ -153,15 +167,15 @@ function tiptapNodeView(param) {
|
|
|
153
167
|
htmlAttributes,
|
|
154
168
|
node
|
|
155
169
|
]);
|
|
156
|
-
const finalClassName = (0, _classnames.default)("react-renderer",
|
|
170
|
+
const finalClassName = (0, _classnames.default)("react-renderer", "node-".concat(node.type.name), props.className, className, extraClassName, {
|
|
157
171
|
"ProseMirror-selectednode": selected
|
|
158
172
|
});
|
|
159
|
-
const updateAttributes = (0,
|
|
173
|
+
const updateAttributes = (0, _useEditorEventCallbackJs.useEditorEventCallback)((_, attributes)=>{
|
|
160
174
|
if (!editor) {
|
|
161
175
|
return;
|
|
162
176
|
}
|
|
163
177
|
editor.commands.command((param)=>{
|
|
164
|
-
let { tr
|
|
178
|
+
let { tr } = param;
|
|
165
179
|
const pos = getPos();
|
|
166
180
|
tr.setNodeMarkup(pos, undefined, {
|
|
167
181
|
...node.attrs,
|
|
@@ -170,7 +184,7 @@ function tiptapNodeView(param) {
|
|
|
170
184
|
return true;
|
|
171
185
|
});
|
|
172
186
|
});
|
|
173
|
-
const deleteNode = (0,
|
|
187
|
+
const deleteNode = (0, _useEditorEventCallbackJs.useEditorEventCallback)(()=>{
|
|
174
188
|
if (!editor) {
|
|
175
189
|
return;
|
|
176
190
|
}
|
|
@@ -193,13 +207,13 @@ function tiptapNodeView(param) {
|
|
|
193
207
|
node.type.name
|
|
194
208
|
]);
|
|
195
209
|
const innerRef = (0, _react1.useRef)(null);
|
|
196
|
-
const finalRef = (0,
|
|
197
|
-
const onDragStart = (0,
|
|
210
|
+
const finalRef = (0, _refsJs.useMergedDOMRefs)(ref, innerRef);
|
|
211
|
+
const onDragStart = (0, _useTiptapEditorEventCallbackJs.useTiptapEditorEventCallback)((editor, event)=>{
|
|
198
212
|
const dom = innerRef.current;
|
|
199
213
|
if (!dom) return;
|
|
200
214
|
const viewDesc = dom.pmViewDesc;
|
|
201
215
|
if (!viewDesc) return;
|
|
202
|
-
const nodeView = new
|
|
216
|
+
const nodeView = new _reactProseMirrorNodeViewJs.ReactProseMirrorNodeView(WrappedComponent, {
|
|
203
217
|
extension,
|
|
204
218
|
decorations,
|
|
205
219
|
editor,
|
|
@@ -221,12 +235,11 @@ function tiptapNodeView(param) {
|
|
|
221
235
|
if (!editor) return null;
|
|
222
236
|
return /*#__PURE__*/ _react1.default.createElement(_react.ReactNodeViewContext.Provider, {
|
|
223
237
|
value: nodeViewContext
|
|
224
|
-
}, /*#__PURE__*/ _react1.default.createElement(OuterTag, {
|
|
225
|
-
ref: finalRef
|
|
226
|
-
|
|
227
|
-
...htmlProps,
|
|
238
|
+
}, /*#__PURE__*/ _react1.default.createElement(OuterTag, _extends({
|
|
239
|
+
ref: finalRef
|
|
240
|
+
}, props, htmlProps, {
|
|
228
241
|
className: finalClassName
|
|
229
|
-
}, /*#__PURE__*/ _react1.default.createElement(WrappedComponent, {
|
|
242
|
+
}), /*#__PURE__*/ _react1.default.createElement(WrappedComponent, {
|
|
230
243
|
node: node,
|
|
231
244
|
getPos: getPos,
|
|
232
245
|
view: editor.view,
|
|
@@ -240,6 +253,7 @@ function tiptapNodeView(param) {
|
|
|
240
253
|
deleteNode: deleteNode
|
|
241
254
|
})));
|
|
242
255
|
}));
|
|
243
|
-
|
|
256
|
+
var _displayName;
|
|
257
|
+
TiptapNodeView.displayName = "TiptapNodeView(".concat((_displayName = WrappedComponent.displayName) !== null && _displayName !== void 0 ? _displayName : "Anonymous", ")");
|
|
244
258
|
return TiptapNodeView;
|
|
245
259
|
}
|
package/dist/cjs/viewdesc.js
CHANGED
|
@@ -9,43 +9,21 @@ function _export(target, all) {
|
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
_export(exports, {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
},
|
|
24
|
-
ReactNodeViewDesc: function() {
|
|
25
|
-
return ReactNodeViewDesc;
|
|
26
|
-
},
|
|
27
|
-
TextViewDesc: function() {
|
|
28
|
-
return TextViewDesc;
|
|
29
|
-
},
|
|
30
|
-
TrailingHackViewDesc: function() {
|
|
31
|
-
return TrailingHackViewDesc;
|
|
32
|
-
},
|
|
33
|
-
ViewDesc: function() {
|
|
34
|
-
return ViewDesc;
|
|
35
|
-
},
|
|
36
|
-
WidgetViewDesc: function() {
|
|
37
|
-
return WidgetViewDesc;
|
|
38
|
-
},
|
|
39
|
-
sameOuterDeco: function() {
|
|
40
|
-
return sameOuterDeco;
|
|
41
|
-
},
|
|
42
|
-
sortViewDescs: function() {
|
|
43
|
-
return sortViewDescs;
|
|
44
|
-
}
|
|
12
|
+
sortViewDescs: ()=>sortViewDescs,
|
|
13
|
+
ViewDesc: ()=>ViewDesc,
|
|
14
|
+
WidgetViewDesc: ()=>WidgetViewDesc,
|
|
15
|
+
CompositionViewDesc: ()=>CompositionViewDesc,
|
|
16
|
+
MarkViewDesc: ()=>MarkViewDesc,
|
|
17
|
+
NodeViewDesc: ()=>NodeViewDesc,
|
|
18
|
+
TextViewDesc: ()=>TextViewDesc,
|
|
19
|
+
TrailingHackViewDesc: ()=>TrailingHackViewDesc,
|
|
20
|
+
ReactMarkViewDesc: ()=>ReactMarkViewDesc,
|
|
21
|
+
ReactNodeViewDesc: ()=>ReactNodeViewDesc,
|
|
22
|
+
sameOuterDeco: ()=>sameOuterDeco
|
|
45
23
|
});
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
const
|
|
24
|
+
const _prosemirrorModel = require("prosemirror-model");
|
|
25
|
+
const _browserJs = require("./browser.js");
|
|
26
|
+
const _domJs = require("./dom.js");
|
|
49
27
|
function sortViewDescs(a, b) {
|
|
50
28
|
if (a instanceof TrailingHackViewDesc) return 1;
|
|
51
29
|
if (b instanceof TrailingHackViewDesc) return -1;
|
|
@@ -53,26 +31,6 @@ function sortViewDescs(a, b) {
|
|
|
53
31
|
}
|
|
54
32
|
const NOT_DIRTY = 0, CHILD_DIRTY = 1, CONTENT_DIRTY = 2, NODE_DIRTY = 3;
|
|
55
33
|
let ViewDesc = class ViewDesc {
|
|
56
|
-
parent;
|
|
57
|
-
children;
|
|
58
|
-
getPos;
|
|
59
|
-
dom;
|
|
60
|
-
contentDOM;
|
|
61
|
-
dirty;
|
|
62
|
-
node;
|
|
63
|
-
constructor(parent, children, getPos, dom, // This is the node that holds the child views. It may be null for
|
|
64
|
-
// descs that don't have children.
|
|
65
|
-
contentDOM){
|
|
66
|
-
this.parent = parent;
|
|
67
|
-
this.children = children;
|
|
68
|
-
this.getPos = getPos;
|
|
69
|
-
this.dom = dom;
|
|
70
|
-
this.contentDOM = contentDOM;
|
|
71
|
-
this.dirty = NOT_DIRTY;
|
|
72
|
-
// An expando property on the DOM node provides a link back to its
|
|
73
|
-
// description.
|
|
74
|
-
dom.pmViewDesc = this;
|
|
75
|
-
}
|
|
76
34
|
// Used to check whether a given description corresponds to a
|
|
77
35
|
// widget/mark/node.
|
|
78
36
|
matchesWidget(_widget) {
|
|
@@ -152,15 +110,15 @@ let ViewDesc = class ViewDesc {
|
|
|
152
110
|
while(domBefore && !((desc = domBefore.pmViewDesc) && desc.parent == this))domBefore = domBefore.previousSibling;
|
|
153
111
|
return domBefore ? this.posBeforeChild(desc) + desc.size : this.posAtStart;
|
|
154
112
|
} else {
|
|
155
|
-
let domAfter,
|
|
113
|
+
let domAfter, desc1;
|
|
156
114
|
if (dom == this.contentDOM) {
|
|
157
115
|
domAfter = dom.childNodes[offset];
|
|
158
116
|
} else {
|
|
159
117
|
while(dom.parentNode != this.contentDOM)dom = dom.parentNode;
|
|
160
118
|
domAfter = dom.nextSibling;
|
|
161
119
|
}
|
|
162
|
-
while(domAfter && !((
|
|
163
|
-
return domAfter ? this.posBeforeChild(
|
|
120
|
+
while(domAfter && !((desc1 = domAfter.pmViewDesc) && desc1.parent == this))domAfter = domAfter.nextSibling;
|
|
121
|
+
return domAfter ? this.posBeforeChild(desc1) : this.posAtEnd;
|
|
164
122
|
}
|
|
165
123
|
}
|
|
166
124
|
// Otherwise, use various heuristics, falling back on the bias
|
|
@@ -168,7 +126,7 @@ let ViewDesc = class ViewDesc {
|
|
|
168
126
|
// start or at the end of this view desc.
|
|
169
127
|
let atEnd;
|
|
170
128
|
if (dom == this.dom && this.contentDOM) {
|
|
171
|
-
atEnd = offset > (0,
|
|
129
|
+
atEnd = offset > (0, _domJs.domIndex)(this.contentDOM);
|
|
172
130
|
} else if (this.contentDOM && this.contentDOM != this.dom && this.dom.contains(this.contentDOM)) {
|
|
173
131
|
atEnd = dom.compareDocumentPosition(this.contentDOM) & 2;
|
|
174
132
|
} else if (this.dom.firstChild) {
|
|
@@ -179,12 +137,12 @@ let ViewDesc = class ViewDesc {
|
|
|
179
137
|
}
|
|
180
138
|
if (search.previousSibling) break;
|
|
181
139
|
}
|
|
182
|
-
if (atEnd == null && offset == dom.childNodes.length) for(let
|
|
183
|
-
if (
|
|
140
|
+
if (atEnd == null && offset == dom.childNodes.length) for(let search1 = dom;; search1 = search1.parentNode){
|
|
141
|
+
if (search1 == this.dom) {
|
|
184
142
|
atEnd = true;
|
|
185
143
|
break;
|
|
186
144
|
}
|
|
187
|
-
if (
|
|
145
|
+
if (search1.nextSibling) break;
|
|
188
146
|
}
|
|
189
147
|
}
|
|
190
148
|
return (atEnd == null ? bias > 0 : atEnd) ? this.posAtEnd : this.posAtStart;
|
|
@@ -222,8 +180,8 @@ let ViewDesc = class ViewDesc {
|
|
|
222
180
|
const end = offset + child.size;
|
|
223
181
|
if (offset == pos && end != offset) {
|
|
224
182
|
while(!child.border && child.children.length){
|
|
225
|
-
for(let
|
|
226
|
-
const inner = child.children[
|
|
183
|
+
for(let i1 = 0; i1 < child.children.length; i1++){
|
|
184
|
+
const inner = child.children[i1];
|
|
227
185
|
if (inner.size) {
|
|
228
186
|
child = inner;
|
|
229
187
|
break;
|
|
@@ -261,26 +219,26 @@ let ViewDesc = class ViewDesc {
|
|
|
261
219
|
}
|
|
262
220
|
// Scan towards the first useable node
|
|
263
221
|
if (side <= 0) {
|
|
264
|
-
let
|
|
222
|
+
let prev1, enter = true;
|
|
265
223
|
for(;; i--, enter = false){
|
|
266
|
-
|
|
267
|
-
if (!
|
|
224
|
+
prev1 = i ? this.children[i - 1] : null;
|
|
225
|
+
if (!prev1 || prev1.dom.parentNode == this.contentDOM) break;
|
|
268
226
|
}
|
|
269
|
-
if (
|
|
227
|
+
if (prev1 && side && enter && !prev1.border && !prev1.domAtom) return prev1.domFromPos(prev1.size, side);
|
|
270
228
|
return {
|
|
271
229
|
node: this.contentDOM,
|
|
272
|
-
offset:
|
|
230
|
+
offset: prev1 ? (0, _domJs.domIndex)(prev1.dom) + 1 : 0
|
|
273
231
|
};
|
|
274
232
|
} else {
|
|
275
|
-
let next,
|
|
276
|
-
for(;; i++,
|
|
233
|
+
let next, enter1 = true;
|
|
234
|
+
for(;; i++, enter1 = false){
|
|
277
235
|
next = i < this.children.length ? this.children[i] : null;
|
|
278
236
|
if (!next || next.dom.parentNode == this.contentDOM) break;
|
|
279
237
|
}
|
|
280
|
-
if (next &&
|
|
238
|
+
if (next && enter1 && !next.border && !next.domAtom) return next.domFromPos(0, side);
|
|
281
239
|
return {
|
|
282
240
|
node: this.contentDOM,
|
|
283
|
-
offset: next ? (0,
|
|
241
|
+
offset: next ? (0, _domJs.domIndex)(next.dom) : this.contentDOM.childNodes.length
|
|
284
242
|
};
|
|
285
243
|
}
|
|
286
244
|
}
|
|
@@ -306,7 +264,7 @@ let ViewDesc = class ViewDesc {
|
|
|
306
264
|
for(let j = i; j > 0; j--){
|
|
307
265
|
const prev = this.children[j - 1];
|
|
308
266
|
if (prev.size && prev.dom.parentNode == this.contentDOM && !prev.emptyChildAt(1)) {
|
|
309
|
-
fromOffset = (0,
|
|
267
|
+
fromOffset = (0, _domJs.domIndex)(prev.dom) + 1;
|
|
310
268
|
break;
|
|
311
269
|
}
|
|
312
270
|
from -= prev.size;
|
|
@@ -315,10 +273,10 @@ let ViewDesc = class ViewDesc {
|
|
|
315
273
|
}
|
|
316
274
|
if (fromOffset > -1 && (end > to || i == this.children.length - 1)) {
|
|
317
275
|
to = end;
|
|
318
|
-
for(let
|
|
319
|
-
const next = this.children[
|
|
276
|
+
for(let j1 = i + 1; j1 < this.children.length; j1++){
|
|
277
|
+
const next = this.children[j1];
|
|
320
278
|
if (next.size && next.dom.parentNode == this.contentDOM && !next.emptyChildAt(-1)) {
|
|
321
|
-
toOffset = (0,
|
|
279
|
+
toOffset = (0, _domJs.domIndex)(next.dom);
|
|
322
280
|
break;
|
|
323
281
|
}
|
|
324
282
|
to += next.size;
|
|
@@ -343,7 +301,7 @@ let ViewDesc = class ViewDesc {
|
|
|
343
301
|
return child.size == 0 || child.emptyChildAt(side);
|
|
344
302
|
}
|
|
345
303
|
domAfterPos(pos) {
|
|
346
|
-
const { node, offset
|
|
304
|
+
const { node , offset } = this.domFromPos(pos, 0);
|
|
347
305
|
if (node.nodeType != 1 || offset == node.childNodes.length) throw new RangeError("No node after pos " + pos);
|
|
348
306
|
// @ts-expect-error ...
|
|
349
307
|
return node.childNodes[offset];
|
|
@@ -371,17 +329,18 @@ let ViewDesc = class ViewDesc {
|
|
|
371
329
|
// BR node for some reason doesn't always work (#1073). On Safari,
|
|
372
330
|
// the cursor sometimes inexplicable visually lags behind its
|
|
373
331
|
// reported position in such situations (#1092).
|
|
374
|
-
if ((
|
|
375
|
-
const { node, offset } = anchorDOM;
|
|
332
|
+
if ((_browserJs.browser.gecko || _browserJs.browser.safari) && anchor == head) {
|
|
333
|
+
const { node , offset: offset1 } = anchorDOM;
|
|
376
334
|
if (node.nodeType == 3) {
|
|
377
|
-
|
|
335
|
+
var ref;
|
|
336
|
+
brKludge = !!(offset1 && ((ref = node.nodeValue) === null || ref === void 0 ? void 0 : ref[offset1 - 1]) == "\n");
|
|
378
337
|
// Issue #1128
|
|
379
|
-
if (brKludge &&
|
|
338
|
+
if (brKludge && offset1 == node.nodeValue.length) {
|
|
380
339
|
for(let scan = node, after; scan; scan = scan.parentNode){
|
|
381
340
|
if (after = scan.nextSibling) {
|
|
382
341
|
if (after.nodeName == "BR") anchorDOM = headDOM = {
|
|
383
342
|
node: after.parentNode,
|
|
384
|
-
offset: (0,
|
|
343
|
+
offset: (0, _domJs.domIndex)(after) + 1
|
|
385
344
|
};
|
|
386
345
|
break;
|
|
387
346
|
}
|
|
@@ -390,18 +349,18 @@ let ViewDesc = class ViewDesc {
|
|
|
390
349
|
}
|
|
391
350
|
}
|
|
392
351
|
} else {
|
|
393
|
-
const prev = node.childNodes[
|
|
352
|
+
const prev = node.childNodes[offset1 - 1];
|
|
394
353
|
// @ts-expect-error ...
|
|
395
354
|
brKludge = prev && (prev.nodeName == "BR" || prev.contentEditable == "false");
|
|
396
355
|
}
|
|
397
356
|
}
|
|
398
357
|
// Firefox can act strangely when the selection is in front of an
|
|
399
358
|
// uneditable node. See #1163 and https://bugzilla.mozilla.org/show_bug.cgi?id=1709536
|
|
400
|
-
if (
|
|
401
|
-
const
|
|
402
|
-
if (
|
|
359
|
+
if (_browserJs.browser.gecko && selRange.focusNode && selRange.focusNode != headDOM.node && selRange.focusNode.nodeType == 1) {
|
|
360
|
+
const after1 = selRange.focusNode.childNodes[selRange.focusOffset];
|
|
361
|
+
if (after1 && after1.contentEditable == "false") force = true;
|
|
403
362
|
}
|
|
404
|
-
if (!(force || brKludge &&
|
|
363
|
+
if (!(force || brKludge && _browserJs.browser.safari) && (0, _domJs.isEquivalentPosition)(anchorDOM.node, anchorDOM.offset, selRange.anchorNode, selRange.anchorOffset) && (0, _domJs.isEquivalentPosition)(headDOM.node, headDOM.offset, selRange.focusNode, selRange.focusOffset)) return;
|
|
405
364
|
// Selection.extend can be used to create an 'inverted' selection
|
|
406
365
|
// (one where the focus is before the anchor), but not all
|
|
407
366
|
// browsers support it yet.
|
|
@@ -475,13 +434,22 @@ let ViewDesc = class ViewDesc {
|
|
|
475
434
|
get ignoreForSelection() {
|
|
476
435
|
return false;
|
|
477
436
|
}
|
|
437
|
+
isText(_text) {
|
|
438
|
+
return false;
|
|
439
|
+
}
|
|
440
|
+
constructor(parent, children, getPos, dom, contentDOM){
|
|
441
|
+
this.parent = parent;
|
|
442
|
+
this.children = children;
|
|
443
|
+
this.getPos = getPos;
|
|
444
|
+
this.dom = dom;
|
|
445
|
+
this.contentDOM = contentDOM;
|
|
446
|
+
this.dirty = NOT_DIRTY;
|
|
447
|
+
// An expando property on the DOM node provides a link back to its
|
|
448
|
+
// description.
|
|
449
|
+
dom.pmViewDesc = this;
|
|
450
|
+
}
|
|
478
451
|
};
|
|
479
452
|
let WidgetViewDesc = class WidgetViewDesc extends ViewDesc {
|
|
480
|
-
widget;
|
|
481
|
-
constructor(parent, getPos, widget, dom){
|
|
482
|
-
super(parent, [], getPos, dom, null), this.widget = widget;
|
|
483
|
-
this.widget = widget;
|
|
484
|
-
}
|
|
485
453
|
matchesWidget(widget) {
|
|
486
454
|
return this.dirty == NOT_DIRTY && widget.type.eq(this.widget.type);
|
|
487
455
|
}
|
|
@@ -506,13 +474,13 @@ let WidgetViewDesc = class WidgetViewDesc extends ViewDesc {
|
|
|
506
474
|
get side() {
|
|
507
475
|
return this.widget.type.side;
|
|
508
476
|
}
|
|
477
|
+
constructor(parent, getPos, widget, dom){
|
|
478
|
+
super(parent, [], getPos, dom, null);
|
|
479
|
+
this.widget = widget;
|
|
480
|
+
this.widget = widget;
|
|
481
|
+
}
|
|
509
482
|
};
|
|
510
483
|
let CompositionViewDesc = class CompositionViewDesc extends ViewDesc {
|
|
511
|
-
textDOM;
|
|
512
|
-
text;
|
|
513
|
-
constructor(parent, getPos, dom, textDOM, text){
|
|
514
|
-
super(parent, [], getPos, dom, null), this.textDOM = textDOM, this.text = text;
|
|
515
|
-
}
|
|
516
484
|
get size() {
|
|
517
485
|
return this.text.length;
|
|
518
486
|
}
|
|
@@ -529,13 +497,13 @@ let CompositionViewDesc = class CompositionViewDesc extends ViewDesc {
|
|
|
529
497
|
ignoreMutation(mut) {
|
|
530
498
|
return mut.type === "characterData" && mut.target.nodeValue == mut.oldValue;
|
|
531
499
|
}
|
|
500
|
+
constructor(parent, getPos, dom, textDOM, text){
|
|
501
|
+
super(parent, [], getPos, dom, null);
|
|
502
|
+
this.textDOM = textDOM;
|
|
503
|
+
this.text = text;
|
|
504
|
+
}
|
|
532
505
|
};
|
|
533
506
|
let MarkViewDesc = class MarkViewDesc extends ViewDesc {
|
|
534
|
-
mark;
|
|
535
|
-
spec;
|
|
536
|
-
constructor(parent, children, getPos, mark, dom, contentDOM, spec){
|
|
537
|
-
super(parent, children, getPos, dom, contentDOM), this.mark = mark, this.spec = spec;
|
|
538
|
-
}
|
|
539
507
|
parseRule() {
|
|
540
508
|
if (this.dirty & NODE_DIRTY || this.mark.type.spec.reparseInView) return null;
|
|
541
509
|
return {
|
|
@@ -564,15 +532,13 @@ let MarkViewDesc = class MarkViewDesc extends ViewDesc {
|
|
|
564
532
|
if (this.spec.destroy) this.spec.destroy();
|
|
565
533
|
super.destroy();
|
|
566
534
|
}
|
|
535
|
+
constructor(parent, children, getPos, mark, dom, contentDOM, spec){
|
|
536
|
+
super(parent, children, getPos, dom, contentDOM);
|
|
537
|
+
this.mark = mark;
|
|
538
|
+
this.spec = spec;
|
|
539
|
+
}
|
|
567
540
|
};
|
|
568
541
|
let NodeViewDesc = class NodeViewDesc extends ViewDesc {
|
|
569
|
-
node;
|
|
570
|
-
outerDeco;
|
|
571
|
-
innerDeco;
|
|
572
|
-
nodeDOM;
|
|
573
|
-
constructor(parent, children, getPos, node, outerDeco, innerDeco, dom, contentDOM, nodeDOM){
|
|
574
|
-
super(parent, children, getPos, dom, contentDOM), this.node = node, this.outerDeco = outerDeco, this.innerDeco = innerDeco, this.nodeDOM = nodeDOM;
|
|
575
|
-
}
|
|
576
542
|
parseRule() {
|
|
577
543
|
// Experimental kludge to allow opt-in re-parsing of nodes
|
|
578
544
|
if (this.node.type.spec.reparseInView) return null;
|
|
@@ -602,7 +568,7 @@ let NodeViewDesc = class NodeViewDesc extends ViewDesc {
|
|
|
602
568
|
break;
|
|
603
569
|
}
|
|
604
570
|
}
|
|
605
|
-
if (!rule.contentElement) rule.getContent = ()=>
|
|
571
|
+
if (!rule.contentElement) rule.getContent = ()=>_prosemirrorModel.Fragment.empty;
|
|
606
572
|
}
|
|
607
573
|
return rule;
|
|
608
574
|
}
|
|
@@ -651,11 +617,15 @@ let NodeViewDesc = class NodeViewDesc extends ViewDesc {
|
|
|
651
617
|
get domAtom() {
|
|
652
618
|
return this.node.isAtom;
|
|
653
619
|
}
|
|
620
|
+
constructor(parent, children, getPos, node, outerDeco, innerDeco, dom, contentDOM, nodeDOM){
|
|
621
|
+
super(parent, children, getPos, dom, contentDOM);
|
|
622
|
+
this.node = node;
|
|
623
|
+
this.outerDeco = outerDeco;
|
|
624
|
+
this.innerDeco = innerDeco;
|
|
625
|
+
this.nodeDOM = nodeDOM;
|
|
626
|
+
}
|
|
654
627
|
};
|
|
655
628
|
let TextViewDesc = class TextViewDesc extends NodeViewDesc {
|
|
656
|
-
constructor(parent, children, getPos, node, outerDeco, innerDeco, dom, nodeDOM){
|
|
657
|
-
super(parent, children, getPos, node, outerDeco, innerDeco, dom, null, nodeDOM);
|
|
658
|
-
}
|
|
659
629
|
parseRule() {
|
|
660
630
|
let skip = this.nodeDOM.parentNode;
|
|
661
631
|
while(skip && skip != this.dom && !skip.pmIsDeco)skip = skip.parentNode;
|
|
@@ -689,6 +659,12 @@ let TextViewDesc = class TextViewDesc extends NodeViewDesc {
|
|
|
689
659
|
get domAtom() {
|
|
690
660
|
return false;
|
|
691
661
|
}
|
|
662
|
+
isText(text) {
|
|
663
|
+
return this.node.text == text;
|
|
664
|
+
}
|
|
665
|
+
constructor(parent, children, getPos, node, outerDeco, innerDeco, dom, nodeDOM){
|
|
666
|
+
super(parent, children, getPos, node, outerDeco, innerDeco, dom, null, nodeDOM);
|
|
667
|
+
}
|
|
692
668
|
};
|
|
693
669
|
let TrailingHackViewDesc = class TrailingHackViewDesc extends ViewDesc {
|
|
694
670
|
parseRule() {
|
|
@@ -710,10 +686,6 @@ let TrailingHackViewDesc = class TrailingHackViewDesc extends ViewDesc {
|
|
|
710
686
|
// extra checks only have to be made for nodes that are actually
|
|
711
687
|
// customized.
|
|
712
688
|
let CustomNodeViewDesc = class CustomNodeViewDesc extends NodeViewDesc {
|
|
713
|
-
spec;
|
|
714
|
-
constructor(parent, children, getPos, node, outerDeco, innerDeco, dom, contentDOM, nodeDOM, spec){
|
|
715
|
-
super(parent, children, getPos, node, outerDeco, innerDeco, dom, contentDOM, nodeDOM), this.spec = spec;
|
|
716
|
-
}
|
|
717
689
|
// A custom `update` method gets to decide whether the update goes
|
|
718
690
|
// through. If it does, and there's a `contentDOM` node, our logic
|
|
719
691
|
// updates the children.
|
|
@@ -748,6 +720,10 @@ let CustomNodeViewDesc = class CustomNodeViewDesc extends NodeViewDesc {
|
|
|
748
720
|
ignoreMutation(mutation) {
|
|
749
721
|
return this.spec.ignoreMutation ? this.spec.ignoreMutation.call(this, mutation) : super.ignoreMutation(mutation);
|
|
750
722
|
}
|
|
723
|
+
constructor(parent, children, getPos, node, outerDeco, innerDeco, dom, contentDOM, nodeDOM, spec){
|
|
724
|
+
super(parent, children, getPos, node, outerDeco, innerDeco, dom, contentDOM, nodeDOM);
|
|
725
|
+
this.spec = spec;
|
|
726
|
+
}
|
|
751
727
|
};
|
|
752
728
|
let ReactMarkViewDesc = class ReactMarkViewDesc extends MarkViewDesc {
|
|
753
729
|
destroy() {
|