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