@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
|
@@ -9,25 +9,37 @@ function _export(target, all) {
|
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
_export(exports, {
|
|
12
|
-
ReactWidgetType: ()
|
|
13
|
-
|
|
12
|
+
ReactWidgetType: function() {
|
|
13
|
+
return ReactWidgetType;
|
|
14
|
+
},
|
|
15
|
+
widget: function() {
|
|
16
|
+
return widget;
|
|
17
|
+
}
|
|
14
18
|
});
|
|
15
|
-
const
|
|
19
|
+
const _prosemirrorview = require("prosemirror-view");
|
|
16
20
|
function compareObjs(a, b) {
|
|
17
21
|
if (a == b) return true;
|
|
18
22
|
for(const p in a)if (a[p] !== b[p]) return false;
|
|
19
|
-
for(const
|
|
23
|
+
for(const p in b)if (!(p in a)) return false;
|
|
20
24
|
return true;
|
|
21
25
|
}
|
|
22
26
|
const noSpec = {
|
|
23
27
|
side: 0
|
|
24
28
|
};
|
|
25
29
|
let ReactWidgetType = class ReactWidgetType {
|
|
30
|
+
Component;
|
|
31
|
+
side;
|
|
32
|
+
spec;
|
|
33
|
+
constructor(Component, spec){
|
|
34
|
+
this.Component = Component;
|
|
35
|
+
this.spec = spec ?? noSpec;
|
|
36
|
+
this.side = this.spec.side ?? 0;
|
|
37
|
+
}
|
|
26
38
|
map(mapping, span, offset, oldOffset) {
|
|
27
|
-
const { pos
|
|
39
|
+
const { pos, deleted } = mapping.mapResult(span.from + oldOffset, this.side < 0 ? -1 : 1);
|
|
28
40
|
// @ts-expect-error The Decoration constructor is private/internal, but
|
|
29
41
|
// we need to use it for our custom widget implementation here.
|
|
30
|
-
return deleted ? null : new
|
|
42
|
+
return deleted ? null : new _prosemirrorview.Decoration(pos - offset, pos - offset, this);
|
|
31
43
|
}
|
|
32
44
|
valid() {
|
|
33
45
|
return true;
|
|
@@ -38,15 +50,9 @@ let ReactWidgetType = class ReactWidgetType {
|
|
|
38
50
|
destroy() {
|
|
39
51
|
// Can be implemented with React effect hooks
|
|
40
52
|
}
|
|
41
|
-
constructor(Component, spec){
|
|
42
|
-
this.Component = Component;
|
|
43
|
-
this.spec = spec !== null && spec !== void 0 ? spec : noSpec;
|
|
44
|
-
var _side;
|
|
45
|
-
this.side = (_side = this.spec.side) !== null && _side !== void 0 ? _side : 0;
|
|
46
|
-
}
|
|
47
53
|
};
|
|
48
54
|
function widget(pos, component, spec) {
|
|
49
55
|
// @ts-expect-error The Decoration constructor is private/internal, but
|
|
50
56
|
// we need to use it for our custom widget implementation here.
|
|
51
|
-
return new
|
|
57
|
+
return new _prosemirrorview.Decoration(pos, pos, new ReactWidgetType(component, spec));
|
|
52
58
|
}
|
|
@@ -4,9 +4,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
});
|
|
5
5
|
Object.defineProperty(exports, "computeDocDeco", {
|
|
6
6
|
enumerable: true,
|
|
7
|
-
get: ()
|
|
7
|
+
get: function() {
|
|
8
|
+
return computeDocDeco;
|
|
9
|
+
}
|
|
8
10
|
});
|
|
9
|
-
const
|
|
11
|
+
const _prosemirrorview = require("prosemirror-view");
|
|
10
12
|
const DocDecorationsCache = new WeakMap();
|
|
11
13
|
function computeDocDeco(view) {
|
|
12
14
|
const attrs = Object.create(null);
|
|
@@ -22,7 +24,7 @@ function computeDocDeco(view) {
|
|
|
22
24
|
});
|
|
23
25
|
if (!attrs.translate) attrs.translate = "no";
|
|
24
26
|
const next = [
|
|
25
|
-
|
|
27
|
+
_prosemirrorview.Decoration.node(0, view.state.doc.content.size, attrs)
|
|
26
28
|
];
|
|
27
29
|
const previous = DocDecorationsCache.get(view);
|
|
28
30
|
if (!previous) {
|
|
@@ -4,9 +4,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
});
|
|
5
5
|
Object.defineProperty(exports, "iterDeco", {
|
|
6
6
|
enumerable: true,
|
|
7
|
-
get: ()
|
|
7
|
+
get: function() {
|
|
8
|
+
return iterDeco;
|
|
9
|
+
}
|
|
8
10
|
});
|
|
9
|
-
const
|
|
11
|
+
const _ReactWidgetType = require("./ReactWidgetType.js");
|
|
10
12
|
function compareSide(a, b) {
|
|
11
13
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
14
|
return a.type.side - b.type.side;
|
|
@@ -37,7 +39,7 @@ onWidget, onNode) {
|
|
|
37
39
|
const next = locals[decoIndex++];
|
|
38
40
|
if (next.widget || // FORK: Our custom widget type can't report itself as a widget,
|
|
39
41
|
// so we have to explicitly check
|
|
40
|
-
next.type instanceof
|
|
42
|
+
next.type instanceof _ReactWidgetType.ReactWidgetType) {
|
|
41
43
|
if (!widget) widget = next;
|
|
42
44
|
else (widgets || (widgets = [
|
|
43
45
|
widget
|
|
@@ -47,41 +49,41 @@ onWidget, onNode) {
|
|
|
47
49
|
if (widget) {
|
|
48
50
|
if (widgets) {
|
|
49
51
|
widgets.sort(compareSide);
|
|
50
|
-
for(let
|
|
51
|
-
!(widgets[
|
|
52
|
+
for(let i = 0; i < widgets.length; i++)onWidget(widgets[i], // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
53
|
+
!(widgets[i].type instanceof _ReactWidgetType.ReactWidgetType), offset, parentIndex + i, !!restNode);
|
|
52
54
|
} else {
|
|
53
55
|
onWidget(widget, // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
54
|
-
!(widget.type instanceof
|
|
56
|
+
!(widget.type instanceof _ReactWidgetType.ReactWidgetType), offset, parentIndex, !!restNode);
|
|
55
57
|
}
|
|
56
58
|
}
|
|
57
59
|
}
|
|
58
|
-
let
|
|
60
|
+
let child, index;
|
|
59
61
|
if (restNode) {
|
|
60
62
|
index = -1;
|
|
61
|
-
|
|
63
|
+
child = restNode;
|
|
62
64
|
restNode = null;
|
|
63
65
|
} else if (parentIndex < parent.childCount) {
|
|
64
66
|
index = parentIndex;
|
|
65
|
-
|
|
67
|
+
child = parent.child(parentIndex++);
|
|
66
68
|
} else {
|
|
67
69
|
break;
|
|
68
70
|
}
|
|
69
|
-
for(let
|
|
71
|
+
for(let i = 0; i < active.length; i++)if (active[i].to <= offset) active.splice(i--, 1);
|
|
70
72
|
while(decoIndex < locals.length && locals[decoIndex].from <= offset && locals[decoIndex].to > offset)active.push(locals[decoIndex++]);
|
|
71
|
-
let end = offset +
|
|
72
|
-
if (
|
|
73
|
+
let end = offset + child.nodeSize;
|
|
74
|
+
if (child.isText) {
|
|
73
75
|
let cutAt = end;
|
|
74
76
|
if (decoIndex < locals.length && locals[decoIndex].from < cutAt) cutAt = locals[decoIndex].from;
|
|
75
|
-
for(let
|
|
77
|
+
for(let i = 0; i < active.length; i++)if (active[i].to < cutAt) cutAt = active[i].to;
|
|
76
78
|
if (cutAt < end) {
|
|
77
|
-
restNode =
|
|
78
|
-
|
|
79
|
+
restNode = child.cut(cutAt - offset);
|
|
80
|
+
child = child.cut(0, cutAt - offset);
|
|
79
81
|
end = cutAt;
|
|
80
82
|
index = -1;
|
|
81
83
|
}
|
|
82
84
|
}
|
|
83
|
-
const outerDeco =
|
|
84
|
-
onNode(
|
|
85
|
+
const outerDeco = child.isInline && !child.isLeaf ? active.filter((d)=>!d.inline) : active.slice();
|
|
86
|
+
onNode(child, outerDeco, deco.forChild(offset, child), offset, index);
|
|
85
87
|
offset = end;
|
|
86
88
|
}
|
|
87
89
|
}
|
|
@@ -4,22 +4,28 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
});
|
|
5
5
|
Object.defineProperty(exports, "viewDecorations", {
|
|
6
6
|
enumerable: true,
|
|
7
|
-
get: ()
|
|
7
|
+
get: function() {
|
|
8
|
+
return viewDecorations;
|
|
9
|
+
}
|
|
8
10
|
});
|
|
9
|
-
const
|
|
11
|
+
const _prosemirrorview = require("prosemirror-view");
|
|
10
12
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
11
13
|
const none = [], noSpec = {};
|
|
12
|
-
const empty =
|
|
14
|
+
const empty = _prosemirrorview.DecorationSet.empty;
|
|
13
15
|
// An abstraction that allows the code dealing with decorations to
|
|
14
16
|
// treat multiple DecorationSet objects as if it were a single object
|
|
15
17
|
// with (a subset of) the same interface.
|
|
16
18
|
let DecorationGroup = class DecorationGroup {
|
|
19
|
+
members;
|
|
20
|
+
constructor(members){
|
|
21
|
+
this.members = members;
|
|
22
|
+
}
|
|
17
23
|
map(mapping, doc) {
|
|
18
24
|
const mappedDecos = this.members.map((member)=>member.map(mapping, doc, noSpec));
|
|
19
25
|
return DecorationGroup.from(mappedDecos);
|
|
20
26
|
}
|
|
21
27
|
forChild(offset, child) {
|
|
22
|
-
if (child.isLeaf) return
|
|
28
|
+
if (child.isLeaf) return _prosemirrorview.DecorationSet.empty;
|
|
23
29
|
let found = [];
|
|
24
30
|
for(let i = 0; i < this.members.length; i++){
|
|
25
31
|
const result = this.members[i].forChild(offset, child);
|
|
@@ -62,16 +68,13 @@ let DecorationGroup = class DecorationGroup {
|
|
|
62
68
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
63
69
|
return members[0];
|
|
64
70
|
default:
|
|
65
|
-
return new DecorationGroup(members.every((m)=>m instanceof
|
|
71
|
+
return new DecorationGroup(members.every((m)=>m instanceof _prosemirrorview.DecorationSet) ? members : members.reduce((r, m)=>r.concat(m instanceof _prosemirrorview.DecorationSet ? m : m.members), []));
|
|
66
72
|
}
|
|
67
73
|
}
|
|
68
74
|
forEachSet(f) {
|
|
69
75
|
for(let i = 0; i < this.members.length; i++)// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
70
76
|
this.members[i].forEachSet(f);
|
|
71
77
|
}
|
|
72
|
-
constructor(members){
|
|
73
|
-
this.members = members;
|
|
74
|
-
}
|
|
75
78
|
};
|
|
76
79
|
// Used to sort decorations so that ones with a low start position
|
|
77
80
|
// come first, and within a set with the same start position, those
|
|
@@ -127,7 +130,7 @@ function viewDecorations(view, cursorWrapper) {
|
|
|
127
130
|
if (result && result != empty) found.push(result);
|
|
128
131
|
});
|
|
129
132
|
if (cursorWrapper) {
|
|
130
|
-
found.push(
|
|
133
|
+
found.push(_prosemirrorview.DecorationSet.create(view.state.doc, [
|
|
131
134
|
cursorWrapper
|
|
132
135
|
]));
|
|
133
136
|
}
|
|
@@ -149,9 +152,9 @@ function viewDecorations(view, cursorWrapper) {
|
|
|
149
152
|
areSetsEqual = false;
|
|
150
153
|
}
|
|
151
154
|
if (!areSetsEqual) {
|
|
152
|
-
const
|
|
153
|
-
ViewDecorationsCache.set(view,
|
|
154
|
-
return
|
|
155
|
+
const result = DecorationGroup.from(found);
|
|
156
|
+
ViewDecorationsCache.set(view, result);
|
|
157
|
+
return result;
|
|
155
158
|
}
|
|
156
159
|
return previous;
|
|
157
160
|
}
|
package/dist/cjs/dom.js
CHANGED
|
@@ -9,17 +9,39 @@ function _export(target, all) {
|
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
_export(exports, {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
12
|
+
caretFromPoint: function() {
|
|
13
|
+
return caretFromPoint;
|
|
14
|
+
},
|
|
15
|
+
deepActiveElement: function() {
|
|
16
|
+
return deepActiveElement;
|
|
17
|
+
},
|
|
18
|
+
domIndex: function() {
|
|
19
|
+
return domIndex;
|
|
20
|
+
},
|
|
21
|
+
hasBlockDesc: function() {
|
|
22
|
+
return hasBlockDesc;
|
|
23
|
+
},
|
|
24
|
+
isEquivalentPosition: function() {
|
|
25
|
+
return isEquivalentPosition;
|
|
26
|
+
},
|
|
27
|
+
isOnEdge: function() {
|
|
28
|
+
return isOnEdge;
|
|
29
|
+
},
|
|
30
|
+
keyEvent: function() {
|
|
31
|
+
return keyEvent;
|
|
32
|
+
},
|
|
33
|
+
nodeSize: function() {
|
|
34
|
+
return nodeSize;
|
|
35
|
+
},
|
|
36
|
+
parentNode: function() {
|
|
37
|
+
return parentNode;
|
|
38
|
+
},
|
|
39
|
+
selectionCollapsed: function() {
|
|
40
|
+
return selectionCollapsed;
|
|
41
|
+
},
|
|
42
|
+
textRange: function() {
|
|
43
|
+
return textRange;
|
|
44
|
+
}
|
|
23
45
|
});
|
|
24
46
|
const domIndex = function(node) {
|
|
25
47
|
for(let index = 0;; index++){
|
|
@@ -53,8 +75,7 @@ function scanFor(node, off, targetNode, targetOff, dir) {
|
|
|
53
75
|
} else if (node.nodeType == 1) {
|
|
54
76
|
const child = node.childNodes[off + (dir < 0 ? -1 : 0)];
|
|
55
77
|
if (child.nodeType == 1 && child.contentEditable == "false") {
|
|
56
|
-
|
|
57
|
-
if ((ref = child.pmViewDesc) === null || ref === void 0 ? void 0 : ref.ignoreForSelection) off += dir;
|
|
78
|
+
if (child.pmViewDesc?.ignoreForSelection) off += dir;
|
|
58
79
|
else return false;
|
|
59
80
|
} else {
|
|
60
81
|
node = child;
|
package/dist/cjs/findDOMNode.js
CHANGED
|
@@ -9,10 +9,14 @@ function _export(target, all) {
|
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
_export(exports, {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
findDOMNode: function() {
|
|
13
|
+
return findDOMNode;
|
|
14
|
+
},
|
|
15
|
+
getInstance: function() {
|
|
16
|
+
return getInstance;
|
|
17
|
+
}
|
|
14
18
|
});
|
|
15
|
-
const
|
|
19
|
+
const _reflection = require("react-reconciler/reflection.js");
|
|
16
20
|
function getInstance(key) {
|
|
17
21
|
return key._reactInternals;
|
|
18
22
|
}
|
|
@@ -28,10 +32,10 @@ function findHostInstance(component) {
|
|
|
28
32
|
throw new Error("Unable to find node on an unmounted component.");
|
|
29
33
|
} else {
|
|
30
34
|
const keys = Object.keys(component).join(",");
|
|
31
|
-
throw new Error(
|
|
35
|
+
throw new Error(`Argument appears to not be a ReactComponent. Keys: ${keys}`);
|
|
32
36
|
}
|
|
33
37
|
}
|
|
34
|
-
const hostFiber = (0,
|
|
38
|
+
const hostFiber = (0, _reflection.findCurrentHostFiber)(fiber);
|
|
35
39
|
if (hostFiber === null) {
|
|
36
40
|
return null;
|
|
37
41
|
}
|
|
@@ -4,7 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
});
|
|
5
5
|
Object.defineProperty(exports, "useClientLayoutEffect", {
|
|
6
6
|
enumerable: true,
|
|
7
|
-
get: ()
|
|
7
|
+
get: function() {
|
|
8
|
+
return useClientLayoutEffect;
|
|
9
|
+
}
|
|
8
10
|
});
|
|
9
11
|
const _react = require("react");
|
|
10
12
|
function useClientLayoutEffect() {
|
|
@@ -4,15 +4,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
});
|
|
5
5
|
Object.defineProperty(exports, "useComponentEventListeners", {
|
|
6
6
|
enumerable: true,
|
|
7
|
-
get: ()
|
|
7
|
+
get: function() {
|
|
8
|
+
return useComponentEventListeners;
|
|
9
|
+
}
|
|
8
10
|
});
|
|
9
11
|
const _react = require("react");
|
|
10
|
-
const
|
|
12
|
+
const _componentEventListeners = require("../plugins/componentEventListeners.js");
|
|
11
13
|
function useComponentEventListeners() {
|
|
12
14
|
const [registry, setRegistry] = (0, _react.useState)(new Map());
|
|
13
15
|
const registerEventListener = (0, _react.useCallback)((eventType, handler)=>{
|
|
14
|
-
|
|
15
|
-
const handlers = (ref = registry.get(eventType)) !== null && ref !== void 0 ? ref : [];
|
|
16
|
+
const handlers = registry.get(eventType) ?? [];
|
|
16
17
|
handlers.unshift(handler);
|
|
17
18
|
if (!registry.has(eventType)) {
|
|
18
19
|
registry.set(eventType, handlers);
|
|
@@ -23,11 +24,11 @@ function useComponentEventListeners() {
|
|
|
23
24
|
]);
|
|
24
25
|
const unregisterEventListener = (0, _react.useCallback)((eventType, handler)=>{
|
|
25
26
|
const handlers = registry.get(eventType);
|
|
26
|
-
handlers
|
|
27
|
+
handlers?.splice(handlers.indexOf(handler), 1);
|
|
27
28
|
}, [
|
|
28
29
|
registry
|
|
29
30
|
]);
|
|
30
|
-
const componentEventListenersPlugin = (0, _react.useMemo)(()=>(0,
|
|
31
|
+
const componentEventListenersPlugin = (0, _react.useMemo)(()=>(0, _componentEventListeners.componentEventListeners)(registry), [
|
|
31
32
|
registry
|
|
32
33
|
]);
|
|
33
34
|
return {
|
|
@@ -4,18 +4,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
});
|
|
5
5
|
Object.defineProperty(exports, "useEditor", {
|
|
6
6
|
enumerable: true,
|
|
7
|
-
get: ()
|
|
7
|
+
get: function() {
|
|
8
|
+
return useEditor;
|
|
9
|
+
}
|
|
8
10
|
});
|
|
9
11
|
const _react = require("react");
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
12
|
+
const _reactdom = require("react-dom");
|
|
13
|
+
const _ReactEditorView = require("../ReactEditorView.js");
|
|
14
|
+
const _StaticEditorView = require("../StaticEditorView.js");
|
|
15
|
+
const _constants = require("../constants.js");
|
|
16
|
+
const _beforeInputPlugin = require("../plugins/beforeInputPlugin.js");
|
|
17
|
+
const _useClientLayoutEffect = require("./useClientLayoutEffect.js");
|
|
18
|
+
const _useComponentEventListeners = require("./useComponentEventListeners.js");
|
|
19
|
+
const _useEffectEvent = require("./useEffectEvent.js");
|
|
20
|
+
const _useForceUpdate = require("./useForceUpdate.js");
|
|
19
21
|
let didWarnValueDefaultValue = false;
|
|
20
22
|
function useEditor(mount, options) {
|
|
21
23
|
if (process.env.NODE_ENV !== "production") {
|
|
@@ -26,23 +28,20 @@ function useEditor(mount, options) {
|
|
|
26
28
|
}
|
|
27
29
|
const flushSyncRef = (0, _react.useRef)(true);
|
|
28
30
|
const [cursorWrapper, _setCursorWrapper] = (0, _react.useState)(null);
|
|
29
|
-
const forceUpdate = (0,
|
|
30
|
-
|
|
31
|
-
const defaultState = (_defaultState = options.defaultState) !== null && _defaultState !== void 0 ? _defaultState : _constantsJs.EMPTY_STATE;
|
|
31
|
+
const forceUpdate = (0, _useForceUpdate.useForceUpdate)();
|
|
32
|
+
const defaultState = options.defaultState ?? _constants.EMPTY_STATE;
|
|
32
33
|
const [_state, setState] = (0, _react.useState)(defaultState);
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
const { componentEventListenersPlugin , registerEventListener , unregisterEventListener } = (0, _useComponentEventListenersJs.useComponentEventListeners)();
|
|
34
|
+
const state = options.state ?? _state;
|
|
35
|
+
const { componentEventListenersPlugin, registerEventListener, unregisterEventListener } = (0, _useComponentEventListeners.useComponentEventListeners)();
|
|
36
36
|
const setCursorWrapper = (0, _react.useCallback)((deco)=>{
|
|
37
|
-
(0,
|
|
37
|
+
(0, _reactdom.flushSync)(()=>{
|
|
38
38
|
_setCursorWrapper(deco);
|
|
39
39
|
});
|
|
40
40
|
}, []);
|
|
41
|
-
var _plugins;
|
|
42
41
|
const plugins = (0, _react.useMemo)(()=>[
|
|
43
|
-
...
|
|
42
|
+
...options.plugins ?? [],
|
|
44
43
|
componentEventListenersPlugin,
|
|
45
|
-
(0,
|
|
44
|
+
(0, _beforeInputPlugin.beforeInputPlugin)(setCursorWrapper)
|
|
46
45
|
], [
|
|
47
46
|
options.plugins,
|
|
48
47
|
componentEventListenersPlugin,
|
|
@@ -50,7 +49,7 @@ function useEditor(mount, options) {
|
|
|
50
49
|
]);
|
|
51
50
|
const dispatchTransaction = (0, _react.useCallback)(function dispatchTransaction(tr) {
|
|
52
51
|
if (flushSyncRef.current) {
|
|
53
|
-
(0,
|
|
52
|
+
(0, _reactdom.flushSync)(()=>{
|
|
54
53
|
if (!options.state) {
|
|
55
54
|
setState((s)=>s.apply(tr));
|
|
56
55
|
}
|
|
@@ -77,19 +76,19 @@ function useEditor(mount, options) {
|
|
|
77
76
|
dispatchTransaction
|
|
78
77
|
};
|
|
79
78
|
const [view, setView] = (0, _react.useState)(()=>{
|
|
80
|
-
return new
|
|
79
|
+
return new _StaticEditorView.StaticEditorView(directEditorProps);
|
|
81
80
|
});
|
|
82
|
-
const createEditorView = (0,
|
|
81
|
+
const createEditorView = (0, _useEffectEvent.useEffectEvent)((mount)=>{
|
|
83
82
|
if (mount && !options.static) {
|
|
84
|
-
const view = new
|
|
83
|
+
const view = new _ReactEditorView.ReactEditorView({
|
|
85
84
|
mount
|
|
86
85
|
}, directEditorProps);
|
|
87
86
|
view.dom.addEventListener("compositionend", forceUpdate);
|
|
88
87
|
return view;
|
|
89
88
|
}
|
|
90
|
-
return new
|
|
89
|
+
return new _StaticEditorView.StaticEditorView(directEditorProps);
|
|
91
90
|
});
|
|
92
|
-
(0,
|
|
91
|
+
(0, _useClientLayoutEffect.useClientLayoutEffect)(()=>{
|
|
93
92
|
const view = createEditorView(mount);
|
|
94
93
|
setView(view);
|
|
95
94
|
return ()=>{
|
|
@@ -99,11 +98,11 @@ function useEditor(mount, options) {
|
|
|
99
98
|
createEditorView,
|
|
100
99
|
mount
|
|
101
100
|
]);
|
|
102
|
-
(0,
|
|
101
|
+
(0, _useClientLayoutEffect.useClientLayoutEffect)(()=>{
|
|
103
102
|
// Ensure that the EditorView hasn't been destroyed before
|
|
104
103
|
// running effects. Running effects will reattach selection
|
|
105
104
|
// change listeners if the EditorView has been destroyed.
|
|
106
|
-
if (view instanceof
|
|
105
|
+
if (view instanceof _ReactEditorView.ReactEditorView && !view.isDestroyed) {
|
|
107
106
|
// Plugins might dispatch transactions from their
|
|
108
107
|
// view update lifecycle hooks
|
|
109
108
|
flushSyncRef.current = false;
|
|
@@ -112,14 +111,13 @@ function useEditor(mount, options) {
|
|
|
112
111
|
}
|
|
113
112
|
});
|
|
114
113
|
view.update(directEditorProps);
|
|
115
|
-
var _static;
|
|
116
114
|
const editor = (0, _react.useMemo)(()=>({
|
|
117
115
|
view,
|
|
118
116
|
cursorWrapper,
|
|
119
117
|
flushSyncRef,
|
|
120
118
|
registerEventListener,
|
|
121
119
|
unregisterEventListener,
|
|
122
|
-
isStatic:
|
|
120
|
+
isStatic: options.static ?? false
|
|
123
121
|
}), [
|
|
124
122
|
cursorWrapper,
|
|
125
123
|
options.static,
|
|
@@ -4,14 +4,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
});
|
|
5
5
|
Object.defineProperty(exports, "useEditorEffect", {
|
|
6
6
|
enumerable: true,
|
|
7
|
-
get: ()
|
|
7
|
+
get: function() {
|
|
8
|
+
return useEditorEffect;
|
|
9
|
+
}
|
|
8
10
|
});
|
|
9
11
|
const _react = require("react");
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
12
|
+
const _ReactEditorView = require("../ReactEditorView.js");
|
|
13
|
+
const _EditorContext = require("../contexts/EditorContext.js");
|
|
14
|
+
const _useLayoutGroupEffect = require("./useLayoutGroupEffect.js");
|
|
13
15
|
function useEditorEffect(effect, dependencies) {
|
|
14
|
-
const { view
|
|
16
|
+
const { view, flushSyncRef } = (0, _react.useContext)(_EditorContext.EditorContext);
|
|
15
17
|
// The rules of hooks want `effect` to be included in the
|
|
16
18
|
// dependency list, but dependency issues for `effect` will
|
|
17
19
|
// be caught by the linter at the call-site for
|
|
@@ -19,8 +21,8 @@ function useEditorEffect(effect, dependencies) {
|
|
|
19
21
|
// Note: we specifically don't want to re-run the effect
|
|
20
22
|
// every time it changes, because it will most likely
|
|
21
23
|
// be defined inline and run on every re-render.
|
|
22
|
-
(0,
|
|
23
|
-
if (view instanceof
|
|
24
|
+
(0, _useLayoutGroupEffect.useLayoutGroupEffect)(()=>{
|
|
25
|
+
if (view instanceof _ReactEditorView.ReactEditorView) {
|
|
24
26
|
flushSyncRef.current = false;
|
|
25
27
|
const result = effect(view);
|
|
26
28
|
flushSyncRef.current = true;
|
|
@@ -4,22 +4,24 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
});
|
|
5
5
|
Object.defineProperty(exports, "useEditorEventCallback", {
|
|
6
6
|
enumerable: true,
|
|
7
|
-
get: ()
|
|
7
|
+
get: function() {
|
|
8
|
+
return useEditorEventCallback;
|
|
9
|
+
}
|
|
8
10
|
});
|
|
9
11
|
const _react = require("react");
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
12
|
+
const _ReactEditorView = require("../ReactEditorView.js");
|
|
13
|
+
const _EditorContext = require("../contexts/EditorContext.js");
|
|
14
|
+
const _useEditorEffect = require("./useEditorEffect.js");
|
|
13
15
|
function assertIsReactEditorView(view) {
|
|
14
|
-
if (view instanceof
|
|
16
|
+
if (view instanceof _ReactEditorView.ReactEditorView) {
|
|
15
17
|
return;
|
|
16
18
|
}
|
|
17
19
|
throw new DOMException("ProseMirror document is not mounted", "InvalidStateError");
|
|
18
20
|
}
|
|
19
21
|
function useEditorEventCallback(callback) {
|
|
20
22
|
const ref = (0, _react.useRef)(callback);
|
|
21
|
-
const { view
|
|
22
|
-
(0,
|
|
23
|
+
const { view } = (0, _react.useContext)(_EditorContext.EditorContext);
|
|
24
|
+
(0, _useEditorEffect.useEditorEffect)(()=>{
|
|
23
25
|
ref.current = callback;
|
|
24
26
|
}, [
|
|
25
27
|
callback
|
|
@@ -4,15 +4,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
});
|
|
5
5
|
Object.defineProperty(exports, "useEditorEventListener", {
|
|
6
6
|
enumerable: true,
|
|
7
|
-
get: ()
|
|
7
|
+
get: function() {
|
|
8
|
+
return useEditorEventListener;
|
|
9
|
+
}
|
|
8
10
|
});
|
|
9
11
|
const _react = require("react");
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
+
const _EditorContext = require("../contexts/EditorContext.js");
|
|
13
|
+
const _useEditorEffect = require("./useEditorEffect.js");
|
|
12
14
|
function useEditorEventListener(eventType, handler) {
|
|
13
|
-
const { registerEventListener
|
|
15
|
+
const { registerEventListener, unregisterEventListener } = (0, _react.useContext)(_EditorContext.EditorContext);
|
|
14
16
|
const ref = (0, _react.useRef)(handler);
|
|
15
|
-
(0,
|
|
17
|
+
(0, _useEditorEffect.useEditorEffect)(()=>{
|
|
16
18
|
ref.current = handler;
|
|
17
19
|
}, [
|
|
18
20
|
handler
|
|
@@ -20,7 +22,7 @@ function useEditorEventListener(eventType, handler) {
|
|
|
20
22
|
const eventHandler = (0, _react.useCallback)(function(view, event) {
|
|
21
23
|
return ref.current.call(this, view, event);
|
|
22
24
|
}, []);
|
|
23
|
-
(0,
|
|
25
|
+
(0, _useEditorEffect.useEditorEffect)(()=>{
|
|
24
26
|
registerEventListener(eventType, eventHandler);
|
|
25
27
|
return ()=>unregisterEventListener(eventType, eventHandler);
|
|
26
28
|
}, [
|
|
@@ -4,11 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
});
|
|
5
5
|
Object.defineProperty(exports, "useEditorState", {
|
|
6
6
|
enumerable: true,
|
|
7
|
-
get: ()
|
|
7
|
+
get: function() {
|
|
8
|
+
return useEditorState;
|
|
9
|
+
}
|
|
8
10
|
});
|
|
9
11
|
const _react = require("react");
|
|
10
|
-
const
|
|
12
|
+
const _EditorStateContext = require("../contexts/EditorStateContext.js");
|
|
11
13
|
function useEditorState() {
|
|
12
|
-
const editorState = (0, _react.useContext)(
|
|
14
|
+
const editorState = (0, _react.useContext)(_EditorStateContext.EditorStateContext);
|
|
13
15
|
return editorState;
|
|
14
16
|
}
|
|
@@ -4,7 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
});
|
|
5
5
|
Object.defineProperty(exports, "useEffectEvent", {
|
|
6
6
|
enumerable: true,
|
|
7
|
-
get: ()
|
|
7
|
+
get: function() {
|
|
8
|
+
return useEffectEvent;
|
|
9
|
+
}
|
|
8
10
|
});
|
|
9
11
|
const _react = require("react");
|
|
10
12
|
function useEffectEvent(fn) {
|
|
@@ -4,7 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
});
|
|
5
5
|
Object.defineProperty(exports, "useForceUpdate", {
|
|
6
6
|
enumerable: true,
|
|
7
|
-
get: ()
|
|
7
|
+
get: function() {
|
|
8
|
+
return useForceUpdate;
|
|
9
|
+
}
|
|
8
10
|
});
|
|
9
11
|
const _react = require("react");
|
|
10
12
|
function useForceUpdate() {
|