@handlewithcare/react-prosemirror 2.4.12 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/AbstractEditorView.js +4 -0
- package/dist/cjs/ReactEditorView.js +156 -0
- package/dist/cjs/StaticEditorView.js +86 -0
- package/dist/cjs/components/ChildNodeViews.js +59 -30
- package/dist/cjs/components/CustomNodeView.js +9 -25
- package/dist/cjs/components/DocNodeView.js +6 -15
- package/dist/cjs/components/MarkView.js +1 -2
- package/dist/cjs/components/NativeWidgetView.js +2 -3
- package/dist/cjs/components/NodeView.js +1 -1
- package/dist/cjs/components/ProseMirror.js +11 -14
- package/dist/cjs/components/ReactNodeView.js +3 -4
- package/dist/cjs/components/SeparatorHackView.js +1 -2
- package/dist/cjs/components/TextNodeView.js +4 -5
- package/dist/cjs/components/TrailingHackView.js +1 -2
- package/dist/cjs/components/WidgetView.js +2 -4
- package/dist/cjs/constants.js +33 -0
- package/dist/cjs/hooks/useEditor.js +32 -228
- package/dist/cjs/hooks/useEditorEffect.js +2 -2
- package/dist/cjs/hooks/useEditorEventCallback.js +8 -5
- package/dist/cjs/hooks/useNodeViewDescriptor.js +10 -10
- package/dist/cjs/hooks/useReactKeys.js +1 -1
- package/dist/cjs/testing/editorViewTestHelpers.js +0 -2
- package/dist/cjs/viewdesc.js +10 -9
- package/dist/esm/AbstractEditorView.js +1 -0
- package/dist/esm/ReactEditorView.js +156 -0
- package/dist/esm/StaticEditorView.js +76 -0
- package/dist/esm/components/ChildNodeViews.js +60 -32
- package/dist/esm/components/CustomNodeView.js +9 -25
- package/dist/esm/components/DocNodeView.js +6 -15
- package/dist/esm/components/MarkView.js +1 -2
- package/dist/esm/components/NativeWidgetView.js +2 -3
- package/dist/esm/components/NodeView.js +1 -1
- package/dist/esm/components/ProseMirror.js +11 -14
- package/dist/esm/components/ReactNodeView.js +3 -4
- package/dist/esm/components/SeparatorHackView.js +1 -2
- package/dist/esm/components/TextNodeView.js +4 -5
- package/dist/esm/components/TrailingHackView.js +1 -2
- package/dist/esm/components/WidgetView.js +2 -4
- package/dist/esm/constants.js +15 -0
- package/dist/esm/hooks/useEditor.js +28 -217
- package/dist/esm/hooks/useEditorEffect.js +2 -2
- package/dist/esm/hooks/useEditorEventCallback.js +8 -5
- package/dist/esm/hooks/useNodeViewDescriptor.js +10 -10
- package/dist/esm/hooks/useReactKeys.js +1 -1
- package/dist/esm/testing/editorViewTestHelpers.js +0 -2
- package/dist/esm/viewdesc.js +3 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/AbstractEditorView.d.ts +27 -0
- package/dist/types/ReactEditorView.d.ts +79 -0
- package/dist/types/StaticEditorView.d.ts +24 -0
- package/dist/types/components/ChildNodeViews.d.ts +2 -2
- package/dist/types/components/CustomNodeView.d.ts +2 -2
- package/dist/types/components/DocNodeView.d.ts +2 -5
- package/dist/types/components/MarkView.d.ts +2 -2
- package/dist/types/components/NativeWidgetView.d.ts +2 -2
- package/dist/types/components/NodeView.d.ts +2 -2
- package/dist/types/components/ReactNodeView.d.ts +2 -2
- package/dist/types/components/SeparatorHackView.d.ts +2 -2
- package/dist/types/components/TextNodeView.d.ts +4 -3
- package/dist/types/components/TrailingHackView.d.ts +2 -2
- package/dist/types/components/WidgetView.d.ts +2 -2
- package/dist/types/constants.d.ts +4 -0
- package/dist/types/contexts/EditorContext.d.ts +6 -4
- package/dist/types/decorations/computeDocDeco.d.ts +3 -2
- package/dist/types/decorations/viewDecorations.d.ts +3 -2
- package/dist/types/hooks/useEditor.d.ts +5 -46
- package/dist/types/hooks/useNodeViewDescriptor.d.ts +1 -1
- package/dist/types/hooks/useReactKeys.d.ts +1 -1
- package/dist/types/props.d.ts +3 -3
- package/dist/types/viewdesc.d.ts +6 -5
- package/package.json +6 -2
- package/dist/cjs/components/Editor.js +0 -28
- package/dist/cjs/components/NodeViews.js +0 -73
- package/dist/cjs/components/__tests__/LayoutGroup.test.js +0 -141
- package/dist/cjs/components/__tests__/ProseMirror.test.js +0 -255
- package/dist/cjs/contexts/NodeViewsContext.js +0 -10
- package/dist/cjs/hooks/__tests__/useEditorViewLayoutEffect.test.js +0 -107
- package/dist/cjs/hooks/__tests__/useNodeViews.test.js +0 -159
- package/dist/cjs/hooks/useEditorView.js +0 -100
- package/dist/cjs/hooks/useNodePos.js +0 -69
- package/dist/cjs/hooks/useNodeViews.js +0 -100
- package/dist/cjs/nodeViews/createReactNodeViewConstructor.js +0 -244
- package/dist/cjs/nodeViews/phrasingContentTags.js +0 -57
- package/dist/cjs/plugins/__tests__/react.test.js +0 -139
- package/dist/cjs/plugins/react.js +0 -71
- package/dist/cjs/selection/SelectionDOMObserver.js +0 -171
- package/dist/cjs/selection/hasFocusAndSelection.js +0 -35
- package/dist/cjs/selection/selectionFromDOM.js +0 -77
- package/dist/cjs/selection/selectionToDOM.js +0 -226
- package/dist/cjs/ssr.js +0 -85
- package/dist/esm/components/Editor.js +0 -15
- package/dist/esm/components/NodeViews.js +0 -26
- package/dist/esm/components/__tests__/LayoutGroup.test.js +0 -98
- package/dist/esm/components/__tests__/ProseMirror.test.js +0 -207
- package/dist/esm/contexts/NodeViewsContext.js +0 -9
- package/dist/esm/hooks/__tests__/useEditorViewLayoutEffect.test.js +0 -98
- package/dist/esm/hooks/__tests__/useNodeViews.test.js +0 -116
- package/dist/esm/hooks/useEditorView.js +0 -99
- package/dist/esm/hooks/useNodePos.js +0 -16
- package/dist/esm/hooks/useNodeViews.js +0 -53
- package/dist/esm/nodeViews/createReactNodeViewConstructor.js +0 -214
- package/dist/esm/nodeViews/phrasingContentTags.js +0 -49
- package/dist/esm/plugins/__tests__/react.test.js +0 -135
- package/dist/esm/plugins/react.js +0 -64
- package/dist/esm/selection/SelectionDOMObserver.js +0 -161
- package/dist/esm/selection/hasFocusAndSelection.js +0 -17
- package/dist/esm/selection/selectionFromDOM.js +0 -59
- package/dist/esm/selection/selectionToDOM.js +0 -196
- package/dist/esm/ssr.js +0 -82
- package/dist/types/components/Editor.d.ts +0 -7
- package/dist/types/components/NodeViews.d.ts +0 -6
- package/dist/types/components/__tests__/LayoutGroup.test.d.ts +0 -1
- package/dist/types/contexts/NodeViewsContext.d.ts +0 -19
- package/dist/types/hooks/__tests__/useEditorViewLayoutEffect.test.d.ts +0 -1
- package/dist/types/hooks/__tests__/useNodeViews.test.d.ts +0 -1
- package/dist/types/hooks/useEditorView.d.ts +0 -23
- package/dist/types/hooks/useNodePos.d.ts +0 -9
- package/dist/types/hooks/useNodeViews.d.ts +0 -5
- package/dist/types/nodeViews/createReactNodeViewConstructor.d.ts +0 -48
- package/dist/types/nodeViews/phrasingContentTags.d.ts +0 -1
- package/dist/types/plugins/__tests__/react.test.d.ts +0 -1
- package/dist/types/plugins/react.d.ts +0 -21
- package/dist/types/selection/SelectionDOMObserver.d.ts +0 -33
- package/dist/types/selection/hasFocusAndSelection.d.ts +0 -3
- package/dist/types/selection/selectionFromDOM.d.ts +0 -4
- package/dist/types/selection/selectionToDOM.d.ts +0 -9
- package/dist/types/ssr.d.ts +0 -19
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-non-null-assertion */ "use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
const _prosemirrorModel = require("prosemirror-model");
|
|
6
|
-
const _prosemirrorState = require("prosemirror-state");
|
|
7
|
-
const _prosemirrorTransform = require("prosemirror-transform");
|
|
8
|
-
const _reactJs = require("../react.js");
|
|
9
|
-
const schema = new _prosemirrorModel.Schema({
|
|
10
|
-
nodes: {
|
|
11
|
-
doc: {
|
|
12
|
-
content: "block+"
|
|
13
|
-
},
|
|
14
|
-
paragraph: {
|
|
15
|
-
group: "block",
|
|
16
|
-
content: "inline*"
|
|
17
|
-
},
|
|
18
|
-
list: {
|
|
19
|
-
group: "block",
|
|
20
|
-
content: "list_item+"
|
|
21
|
-
},
|
|
22
|
-
list_item: {
|
|
23
|
-
content: "paragraph+"
|
|
24
|
-
},
|
|
25
|
-
text: {
|
|
26
|
-
group: "inline"
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
describe("reactNodeViewPlugin", ()=>{
|
|
31
|
-
it("should create a unique key for each node", ()=>{
|
|
32
|
-
const editorState = _prosemirrorState.EditorState.create({
|
|
33
|
-
doc: schema.topNodeType.create(null, [
|
|
34
|
-
schema.nodes.paragraph.create(),
|
|
35
|
-
schema.nodes.paragraph.create(),
|
|
36
|
-
schema.nodes.paragraph.create()
|
|
37
|
-
]),
|
|
38
|
-
plugins: [
|
|
39
|
-
(0, _reactJs.react)()
|
|
40
|
-
]
|
|
41
|
-
});
|
|
42
|
-
const pluginState = _reactJs.reactPluginKey.getState(editorState);
|
|
43
|
-
expect(pluginState.posToKey.size).toBe(3);
|
|
44
|
-
});
|
|
45
|
-
it("should maintain key stability when possible", ()=>{
|
|
46
|
-
const initialEditorState = _prosemirrorState.EditorState.create({
|
|
47
|
-
doc: schema.topNodeType.create(null, [
|
|
48
|
-
schema.nodes.paragraph.create(),
|
|
49
|
-
schema.nodes.paragraph.create(),
|
|
50
|
-
schema.nodes.paragraph.create()
|
|
51
|
-
]),
|
|
52
|
-
plugins: [
|
|
53
|
-
(0, _reactJs.react)()
|
|
54
|
-
]
|
|
55
|
-
});
|
|
56
|
-
const initialPluginState = _reactJs.reactPluginKey.getState(initialEditorState);
|
|
57
|
-
const nextEditorState = initialEditorState.apply(initialEditorState.tr.insertText("Hello, world!", 1));
|
|
58
|
-
const nextPluginState = _reactJs.reactPluginKey.getState(nextEditorState);
|
|
59
|
-
expect(Array.from(nextPluginState.keyToPos.keys())).toEqual(Array.from(initialPluginState.keyToPos.keys()));
|
|
60
|
-
});
|
|
61
|
-
it("should create unique keys for new nodes", ()=>{
|
|
62
|
-
const initialEditorState = _prosemirrorState.EditorState.create({
|
|
63
|
-
doc: schema.topNodeType.create(null, [
|
|
64
|
-
schema.nodes.paragraph.create(),
|
|
65
|
-
schema.nodes.paragraph.create(),
|
|
66
|
-
schema.nodes.paragraph.create()
|
|
67
|
-
]),
|
|
68
|
-
plugins: [
|
|
69
|
-
(0, _reactJs.react)()
|
|
70
|
-
]
|
|
71
|
-
});
|
|
72
|
-
const initialPluginState = _reactJs.reactPluginKey.getState(initialEditorState);
|
|
73
|
-
const nextEditorState = initialEditorState.apply(initialEditorState.tr.insert(0, schema.nodes.list.createAndFill()));
|
|
74
|
-
const nextPluginState = _reactJs.reactPluginKey.getState(nextEditorState);
|
|
75
|
-
// Adds new keys for new nodes
|
|
76
|
-
expect(nextPluginState.keyToPos.size).toBe(6);
|
|
77
|
-
// Maintains keys for previous nodes that are still there
|
|
78
|
-
Array.from(initialPluginState.keyToPos.keys()).forEach((key)=>{
|
|
79
|
-
expect(Array.from(nextPluginState.keyToPos.keys())).toContain(key);
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
it("should maintain key stability when splitting a node", ()=>{
|
|
83
|
-
const initialEditorState = _prosemirrorState.EditorState.create({
|
|
84
|
-
doc: schema.topNodeType.create(null, [
|
|
85
|
-
schema.nodes.list.create(null, [
|
|
86
|
-
schema.nodes.list_item.create(null, [
|
|
87
|
-
schema.nodes.paragraph.create(null, [
|
|
88
|
-
schema.text("first")
|
|
89
|
-
])
|
|
90
|
-
])
|
|
91
|
-
])
|
|
92
|
-
]),
|
|
93
|
-
plugins: [
|
|
94
|
-
(0, _reactJs.react)()
|
|
95
|
-
]
|
|
96
|
-
});
|
|
97
|
-
const initialPluginState = _reactJs.reactPluginKey.getState(initialEditorState);
|
|
98
|
-
const nextEditorState = initialEditorState.apply(initialEditorState.tr.insert(1, schema.nodes.list_item.create(null, [
|
|
99
|
-
schema.nodes.paragraph.create(null, [
|
|
100
|
-
schema.text("second")
|
|
101
|
-
])
|
|
102
|
-
])));
|
|
103
|
-
const nextPluginState = _reactJs.reactPluginKey.getState(nextEditorState);
|
|
104
|
-
// The new list item was inserted before the original one,
|
|
105
|
-
// pushing it further into the document. The original list
|
|
106
|
-
// item should keep its original key, and the new list item
|
|
107
|
-
// should be assigned a new one
|
|
108
|
-
expect(nextPluginState.posToKey.get(11)).toBe(initialPluginState.posToKey.get(1));
|
|
109
|
-
expect(nextPluginState.posToKey.get(1)).not.toBe(initialPluginState.posToKey.get(1));
|
|
110
|
-
});
|
|
111
|
-
it("should maintain key stability when wrapping a node", ()=>{
|
|
112
|
-
const initialEditorState = _prosemirrorState.EditorState.create({
|
|
113
|
-
doc: schema.topNodeType.create(null, [
|
|
114
|
-
schema.nodes.paragraph.create(null, [
|
|
115
|
-
schema.text("content")
|
|
116
|
-
])
|
|
117
|
-
]),
|
|
118
|
-
plugins: [
|
|
119
|
-
(0, _reactJs.react)()
|
|
120
|
-
]
|
|
121
|
-
});
|
|
122
|
-
const initialPluginState = _reactJs.reactPluginKey.getState(initialEditorState);
|
|
123
|
-
const start = 1;
|
|
124
|
-
const end = 9;
|
|
125
|
-
const tr = initialEditorState.tr.delete(start, end);
|
|
126
|
-
const $start = tr.doc.resolve(start);
|
|
127
|
-
const range = $start.blockRange();
|
|
128
|
-
const wrapping = range && (0, _prosemirrorTransform.findWrapping)(range, schema.nodes.list, null);
|
|
129
|
-
tr.wrap(range, wrapping);
|
|
130
|
-
const nextEditorState = initialEditorState.apply(tr);
|
|
131
|
-
const nextPluginState = _reactJs.reactPluginKey.getState(nextEditorState);
|
|
132
|
-
// The new list and list item nodes were wrapped around the
|
|
133
|
-
// paragraph, pushing it further into the document. The paragraph
|
|
134
|
-
// should keep its original key, and the new nodes
|
|
135
|
-
// should be assigned a new one
|
|
136
|
-
expect(nextPluginState.posToKey.get(2)).toBe(initialPluginState.posToKey.get(0));
|
|
137
|
-
expect(nextPluginState.posToKey.get(0)).not.toBe(initialPluginState.posToKey.get(0));
|
|
138
|
-
});
|
|
139
|
-
});
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
ROOT_NODE_KEY: ()=>ROOT_NODE_KEY,
|
|
13
|
-
createNodeKey: ()=>createNodeKey,
|
|
14
|
-
reactPluginKey: ()=>reactPluginKey,
|
|
15
|
-
react: ()=>react
|
|
16
|
-
});
|
|
17
|
-
const _prosemirrorState = require("prosemirror-state");
|
|
18
|
-
const ROOT_NODE_KEY = Symbol("@nytimes/react-prosemirror/root-node-key");
|
|
19
|
-
function createNodeKey() {
|
|
20
|
-
return Math.floor(Math.random() * 0xffffff).toString(16);
|
|
21
|
-
}
|
|
22
|
-
const reactPluginKey = new _prosemirrorState.PluginKey("@nytimes/react-prosemirror/react");
|
|
23
|
-
function react() {
|
|
24
|
-
return new _prosemirrorState.Plugin({
|
|
25
|
-
key: reactPluginKey,
|
|
26
|
-
state: {
|
|
27
|
-
init (_, state) {
|
|
28
|
-
const next = {
|
|
29
|
-
posToKey: new Map(),
|
|
30
|
-
keyToPos: new Map()
|
|
31
|
-
};
|
|
32
|
-
state.doc.descendants((node, pos)=>{
|
|
33
|
-
if (node.isText) return false;
|
|
34
|
-
const key = createNodeKey();
|
|
35
|
-
next.posToKey.set(pos, key);
|
|
36
|
-
next.keyToPos.set(key, pos);
|
|
37
|
-
return true;
|
|
38
|
-
});
|
|
39
|
-
return next;
|
|
40
|
-
},
|
|
41
|
-
/**
|
|
42
|
-
* Keeps node keys (mostly) stable across transactions.
|
|
43
|
-
*
|
|
44
|
-
* To accomplish this, we map each node position backwards
|
|
45
|
-
* through the transaction to identify its previous position,
|
|
46
|
-
* and thereby retrieve its previous key.
|
|
47
|
-
*/ apply (tr, value, _, newState) {
|
|
48
|
-
if (!tr.docChanged) return value;
|
|
49
|
-
const next = {
|
|
50
|
-
posToKey: new Map(),
|
|
51
|
-
keyToPos: new Map()
|
|
52
|
-
};
|
|
53
|
-
for (const [pos, key] of value.posToKey.entries()){
|
|
54
|
-
const { pos: newPos , deleted } = tr.mapping.mapResult(pos);
|
|
55
|
-
if (deleted) continue;
|
|
56
|
-
next.posToKey.set(newPos, key);
|
|
57
|
-
next.keyToPos.set(key, newPos);
|
|
58
|
-
}
|
|
59
|
-
newState.doc.descendants((node, pos)=>{
|
|
60
|
-
if (node.isText) return false;
|
|
61
|
-
if (next.posToKey.has(pos)) return true;
|
|
62
|
-
const key = createNodeKey();
|
|
63
|
-
next.posToKey.set(pos, key);
|
|
64
|
-
next.keyToPos.set(key, pos);
|
|
65
|
-
return true;
|
|
66
|
-
});
|
|
67
|
-
return next;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
}
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "SelectionDOMObserver", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return SelectionDOMObserver;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _prosemirrorstate = require("prosemirror-state");
|
|
12
|
-
const _browser = require("../browser.js");
|
|
13
|
-
const _dom = require("../dom.js");
|
|
14
|
-
const _hasFocusAndSelection = require("./hasFocusAndSelection.js");
|
|
15
|
-
const _selectionFromDOM = require("./selectionFromDOM.js");
|
|
16
|
-
const _selectionToDOM = require("./selectionToDOM.js");
|
|
17
|
-
let SelectionState = class SelectionState {
|
|
18
|
-
anchorNode = null;
|
|
19
|
-
anchorOffset = 0;
|
|
20
|
-
focusNode = null;
|
|
21
|
-
focusOffset = 0;
|
|
22
|
-
set(sel) {
|
|
23
|
-
this.anchorNode = sel.anchorNode;
|
|
24
|
-
this.anchorOffset = sel.anchorOffset;
|
|
25
|
-
this.focusNode = sel.focusNode;
|
|
26
|
-
this.focusOffset = sel.focusOffset;
|
|
27
|
-
}
|
|
28
|
-
clear() {
|
|
29
|
-
this.anchorNode = this.focusNode = null;
|
|
30
|
-
}
|
|
31
|
-
eq(sel) {
|
|
32
|
-
return sel.anchorNode == this.anchorNode && sel.anchorOffset == this.anchorOffset && sel.focusNode == this.focusNode && sel.focusOffset == this.focusOffset;
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
let SelectionDOMObserver = class SelectionDOMObserver {
|
|
36
|
-
view;
|
|
37
|
-
flushingSoon;
|
|
38
|
-
currentSelection;
|
|
39
|
-
suppressingSelectionUpdates;
|
|
40
|
-
constructor(view){
|
|
41
|
-
this.view = view;
|
|
42
|
-
this.flushingSoon = -1;
|
|
43
|
-
this.currentSelection = new SelectionState();
|
|
44
|
-
this.suppressingSelectionUpdates = false;
|
|
45
|
-
this.view = view;
|
|
46
|
-
this.onSelectionChange = this.onSelectionChange.bind(this);
|
|
47
|
-
}
|
|
48
|
-
connectSelection() {
|
|
49
|
-
this.view.dom.ownerDocument.addEventListener("selectionchange", this.onSelectionChange);
|
|
50
|
-
}
|
|
51
|
-
disconnectSelection() {
|
|
52
|
-
this.view.dom.ownerDocument.removeEventListener("selectionchange", this.onSelectionChange);
|
|
53
|
-
}
|
|
54
|
-
stop() {
|
|
55
|
-
this.disconnectSelection();
|
|
56
|
-
}
|
|
57
|
-
start() {
|
|
58
|
-
this.connectSelection();
|
|
59
|
-
}
|
|
60
|
-
suppressSelectionUpdates() {
|
|
61
|
-
this.suppressingSelectionUpdates = true;
|
|
62
|
-
setTimeout(()=>this.suppressingSelectionUpdates = false, 50);
|
|
63
|
-
}
|
|
64
|
-
setCurSelection() {
|
|
65
|
-
// @ts-expect-error Internal method
|
|
66
|
-
this.currentSelection.set(this.view.domSelectionRange());
|
|
67
|
-
}
|
|
68
|
-
ignoreSelectionChange(sel) {
|
|
69
|
-
if (!sel.focusNode) return true;
|
|
70
|
-
const ancestors = new Set();
|
|
71
|
-
let container;
|
|
72
|
-
for(let scan = sel.focusNode; scan; scan = (0, _dom.parentNode)(scan))ancestors.add(scan);
|
|
73
|
-
for(let scan = sel.anchorNode; scan; scan = (0, _dom.parentNode)(scan))if (ancestors.has(scan)) {
|
|
74
|
-
container = scan;
|
|
75
|
-
break;
|
|
76
|
-
}
|
|
77
|
-
// @ts-expect-error Internal property (docView)
|
|
78
|
-
const desc = container && this.view.docView.nearestDesc(container);
|
|
79
|
-
if (desc && desc.ignoreMutation({
|
|
80
|
-
type: "selection",
|
|
81
|
-
target: container?.nodeType == 3 ? container?.parentNode : container
|
|
82
|
-
})) {
|
|
83
|
-
this.setCurSelection();
|
|
84
|
-
return true;
|
|
85
|
-
}
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
registerMutation() {
|
|
89
|
-
// pass
|
|
90
|
-
}
|
|
91
|
-
flushSoon() {
|
|
92
|
-
if (this.flushingSoon < 0) this.flushingSoon = window.setTimeout(()=>{
|
|
93
|
-
this.flushingSoon = -1;
|
|
94
|
-
this.flush();
|
|
95
|
-
}, 20);
|
|
96
|
-
}
|
|
97
|
-
updateSelection() {
|
|
98
|
-
const { view } = this;
|
|
99
|
-
const compositionID = // @ts-expect-error Internal property (input)
|
|
100
|
-
view.input.compositionPendingChanges || // @ts-expect-error Internal property (input)
|
|
101
|
-
(view.composing ? view.input.compositionID : 0);
|
|
102
|
-
// @ts-expect-error Internal property (input)
|
|
103
|
-
view.input.compositionPendingChanges = 0;
|
|
104
|
-
const origin = // @ts-expect-error Internal property (input)
|
|
105
|
-
view.input.lastSelectionTime > Date.now() - 50 ? view.input.lastSelectionOrigin : null;
|
|
106
|
-
const newSel = (0, _selectionFromDOM.selectionFromDOM)(view, origin);
|
|
107
|
-
if (newSel && !view.state.selection.eq(newSel)) {
|
|
108
|
-
const tr = view.state.tr.setSelection(newSel);
|
|
109
|
-
if (origin == "pointer") tr.setMeta("pointer", true);
|
|
110
|
-
else if (origin == "key") tr.scrollIntoView();
|
|
111
|
-
if (compositionID) tr.setMeta("composition", compositionID);
|
|
112
|
-
view.dispatch(tr);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
selectionToDOM() {
|
|
116
|
-
const { view } = this;
|
|
117
|
-
(0, _selectionToDOM.selectionToDOM)(view);
|
|
118
|
-
// @ts-expect-error Internal property (domSelectionRange)
|
|
119
|
-
const sel = view.domSelectionRange();
|
|
120
|
-
this.currentSelection.set(sel);
|
|
121
|
-
}
|
|
122
|
-
flush() {
|
|
123
|
-
const { view } = this;
|
|
124
|
-
// @ts-expect-error Internal property (docView)
|
|
125
|
-
if (!view.docView || this.flushingSoon > -1) return;
|
|
126
|
-
// @ts-expect-error Internal property (domSelectionRange)
|
|
127
|
-
const sel = view.domSelectionRange();
|
|
128
|
-
const newSel = !this.suppressingSelectionUpdates && !this.currentSelection.eq(sel) && (0, _hasFocusAndSelection.hasFocusAndSelection)(view) && !this.ignoreSelectionChange(sel);
|
|
129
|
-
let readSel = null;
|
|
130
|
-
// If it looks like the browser has reset the selection to the
|
|
131
|
-
// start of the document after focus, restore the selection from
|
|
132
|
-
// the state
|
|
133
|
-
if (newSel && // @ts-expect-error Internal property (input)
|
|
134
|
-
view.input.lastFocus > Date.now() - 200 && // @ts-expect-error Internal property (input)
|
|
135
|
-
Math.max(view.input.lastTouch, view.input.lastClick.time) < Date.now() - 300 && (0, _dom.selectionCollapsed)(sel) && (readSel = (0, _selectionFromDOM.selectionFromDOM)(view)) && readSel.eq(_prosemirrorstate.Selection.near(view.state.doc.resolve(0), 1))) {
|
|
136
|
-
// @ts-expect-error Internal property (input)
|
|
137
|
-
view.input.lastFocus = 0;
|
|
138
|
-
(0, _selectionToDOM.selectionToDOM)(view);
|
|
139
|
-
this.currentSelection.set(sel);
|
|
140
|
-
// @ts-expect-error Internal property (scrollToSelection)
|
|
141
|
-
view.scrollToSelection();
|
|
142
|
-
} else if (newSel) {
|
|
143
|
-
this.updateSelection();
|
|
144
|
-
if (!this.currentSelection.eq(sel)) (0, _selectionToDOM.selectionToDOM)(view);
|
|
145
|
-
this.currentSelection.set(sel);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
forceFlush() {
|
|
149
|
-
if (this.flushingSoon > -1) {
|
|
150
|
-
window.clearTimeout(this.flushingSoon);
|
|
151
|
-
this.flushingSoon = -1;
|
|
152
|
-
this.flush();
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
onSelectionChange() {
|
|
156
|
-
if (!(0, _hasFocusAndSelection.hasFocusAndSelection)(this.view)) return;
|
|
157
|
-
if (this.view.composing) return;
|
|
158
|
-
if (this.suppressingSelectionUpdates) return (0, _selectionToDOM.selectionToDOM)(this.view);
|
|
159
|
-
// Deletions on IE11 fire their events in the wrong order, giving
|
|
160
|
-
// us a selection change event before the DOM changes are
|
|
161
|
-
// reported.
|
|
162
|
-
if (_browser.browser.ie && _browser.browser.ie_version <= 11 && !this.view.state.selection.empty) {
|
|
163
|
-
// @ts-expect-error Internal method
|
|
164
|
-
const sel = this.view.domSelectionRange();
|
|
165
|
-
// Selection.isCollapsed isn't reliable on IE
|
|
166
|
-
if (sel.focusNode && (0, _selectionToDOM.isEquivalentPosition)(sel.focusNode, sel.focusOffset, // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
167
|
-
sel.anchorNode, sel.anchorOffset)) return this.flushSoon();
|
|
168
|
-
}
|
|
169
|
-
this.flush();
|
|
170
|
-
}
|
|
171
|
-
};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
hasFocusAndSelection: function() {
|
|
13
|
-
return hasFocusAndSelection;
|
|
14
|
-
},
|
|
15
|
-
hasSelection: function() {
|
|
16
|
-
return hasSelection;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
function hasFocusAndSelection(view) {
|
|
20
|
-
if (view.editable && !view.hasFocus()) return false;
|
|
21
|
-
return hasSelection(view);
|
|
22
|
-
}
|
|
23
|
-
function hasSelection(view) {
|
|
24
|
-
// @ts-expect-error Internal method
|
|
25
|
-
const sel = view.domSelectionRange();
|
|
26
|
-
if (!sel.anchorNode) return false;
|
|
27
|
-
try {
|
|
28
|
-
// Firefox will raise 'permission denied' errors when accessing
|
|
29
|
-
// properties of `sel.anchorNode` when it's in a generated CSS
|
|
30
|
-
// element.
|
|
31
|
-
return view.dom.contains(sel.anchorNode.nodeType == 3 ? sel.anchorNode.parentNode : sel.anchorNode) && (view.editable || view.dom.contains(sel.focusNode?.nodeType == 3 ? sel.focusNode?.parentNode : sel.focusNode));
|
|
32
|
-
} catch (_) {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
selectionBetween: function() {
|
|
13
|
-
return selectionBetween;
|
|
14
|
-
},
|
|
15
|
-
selectionFromDOM: function() {
|
|
16
|
-
return selectionFromDOM;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
const _prosemirrorstate = require("prosemirror-state");
|
|
20
|
-
const _dom = require("../dom.js");
|
|
21
|
-
function selectionBetween(view, $anchor, $head, bias) {
|
|
22
|
-
return view.someProp("createSelectionBetween", (f)=>f(view, $anchor, $head)) || _prosemirrorstate.TextSelection.between($anchor, $head, bias);
|
|
23
|
-
}
|
|
24
|
-
function selectionFromDOM(view) {
|
|
25
|
-
let origin = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : null;
|
|
26
|
-
// @ts-expect-error Internal method
|
|
27
|
-
const domSel = view.domSelectionRange(), doc = view.state.doc;
|
|
28
|
-
if (!domSel.focusNode) return null;
|
|
29
|
-
// @ts-expect-error Internal method
|
|
30
|
-
let nearestDesc = view.docView.nearestDesc(domSel.focusNode);
|
|
31
|
-
const inWidget = nearestDesc && nearestDesc.size == 0;
|
|
32
|
-
// @ts-expect-error Internal method
|
|
33
|
-
let head = view.docView.posFromDOM(domSel.focusNode, domSel.focusOffset, 1);
|
|
34
|
-
if (head < 0) return null;
|
|
35
|
-
let $head = doc.resolve(head), anchor, selection;
|
|
36
|
-
if ((0, _dom.selectionCollapsed)(domSel)) {
|
|
37
|
-
anchor = head;
|
|
38
|
-
while(nearestDesc && !nearestDesc.node)nearestDesc = nearestDesc.parent;
|
|
39
|
-
const nearestDescNode = nearestDesc.node;
|
|
40
|
-
if (nearestDesc && nearestDescNode.isAtom && _prosemirrorstate.NodeSelection.isSelectable(nearestDescNode) && nearestDesc.parent && !(nearestDescNode.isInline && (0, _dom.isOnEdge)(domSel.focusNode, domSel.focusOffset, nearestDesc.dom))) {
|
|
41
|
-
const pos = nearestDesc.posBefore;
|
|
42
|
-
selection = new _prosemirrorstate.NodeSelection(head == pos ? $head : doc.resolve(pos));
|
|
43
|
-
}
|
|
44
|
-
} else {
|
|
45
|
-
if (// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
46
|
-
domSel instanceof view.dom.ownerDocument.defaultView.Selection && domSel.rangeCount > 1) {
|
|
47
|
-
let min = head, max = head;
|
|
48
|
-
for(let i = 0; i < domSel.rangeCount; i++){
|
|
49
|
-
const range = domSel.getRangeAt(i);
|
|
50
|
-
min = Math.min(min, // @ts-expect-error Internal method
|
|
51
|
-
view.docView.posFromDOM(range.startContainer, range.startOffset, 1));
|
|
52
|
-
max = Math.max(max, // @ts-expect-error Internal method
|
|
53
|
-
view.docView.posFromDOM(range.endContainer, range.endOffset, -1));
|
|
54
|
-
}
|
|
55
|
-
if (min < 0) return null;
|
|
56
|
-
[anchor, head] = max == view.state.selection.anchor ? [
|
|
57
|
-
max,
|
|
58
|
-
min
|
|
59
|
-
] : [
|
|
60
|
-
min,
|
|
61
|
-
max
|
|
62
|
-
];
|
|
63
|
-
$head = doc.resolve(head);
|
|
64
|
-
} else {
|
|
65
|
-
// @ts-expect-error Internal method
|
|
66
|
-
anchor = view.docView.posFromDOM(// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
67
|
-
domSel.anchorNode, domSel.anchorOffset, 1);
|
|
68
|
-
}
|
|
69
|
-
if (anchor < 0) return null;
|
|
70
|
-
}
|
|
71
|
-
const $anchor = doc.resolve(anchor);
|
|
72
|
-
if (!selection) {
|
|
73
|
-
const bias = origin == "pointer" || view.state.selection.head < $head.pos && !inWidget ? 1 : -1;
|
|
74
|
-
selection = selectionBetween(view, $anchor, $head, bias);
|
|
75
|
-
}
|
|
76
|
-
return selection;
|
|
77
|
-
}
|