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