@tiptap/extension-node-range 2.24.2 → 3.0.0-beta.11
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/LICENSE.md +21 -0
- package/dist/index.cjs +315 -297
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +47 -0
- package/dist/index.d.ts +47 -8
- package/dist/index.js +286 -290
- package/dist/index.js.map +1 -1
- package/package.json +12 -10
- package/src/helpers/NodeRangeBookmark.ts +2 -4
- package/src/helpers/NodeRangeSelection.ts +9 -25
- package/src/helpers/getNodeRangeDecorations.ts +1 -1
- package/src/helpers/getSelectionRanges.ts +11 -15
- package/src/node-range.ts +28 -25
- package/dist/helpers/NodeRangeBookmark.d.ts +0 -11
- package/dist/helpers/NodeRangeBookmark.d.ts.map +0 -1
- package/dist/helpers/NodeRangeSelection.d.ts +0 -24
- package/dist/helpers/NodeRangeSelection.d.ts.map +0 -1
- package/dist/helpers/getNodeRangeDecorations.d.ts +0 -4
- package/dist/helpers/getNodeRangeDecorations.d.ts.map +0 -1
- package/dist/helpers/getSelectionRanges.d.ts +0 -4
- package/dist/helpers/getSelectionRanges.d.ts.map +0 -1
- package/dist/helpers/isNodeRangeSelection.d.ts +0 -3
- package/dist/helpers/isNodeRangeSelection.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.umd.js +0 -320
- package/dist/index.umd.js.map +0 -1
- package/dist/node-range.d.ts +0 -7
- package/dist/node-range.d.ts.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,319 +1,337 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
2
19
|
|
|
3
|
-
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
NodeRange: () => NodeRange2,
|
|
24
|
+
NodeRangeSelection: () => NodeRangeSelection,
|
|
25
|
+
default: () => index_default,
|
|
26
|
+
getNodeRangeDecorations: () => getNodeRangeDecorations,
|
|
27
|
+
getSelectionRanges: () => getSelectionRanges,
|
|
28
|
+
isNodeRangeSelection: () => isNodeRangeSelection
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(index_exports);
|
|
4
31
|
|
|
5
|
-
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var model = require('@tiptap/pm/model');
|
|
32
|
+
// src/node-range.ts
|
|
33
|
+
var import_core = require("@tiptap/core");
|
|
34
|
+
var import_state3 = require("@tiptap/pm/state");
|
|
9
35
|
|
|
36
|
+
// src/helpers/getNodeRangeDecorations.ts
|
|
37
|
+
var import_view = require("@tiptap/pm/view");
|
|
10
38
|
function getNodeRangeDecorations(ranges) {
|
|
11
|
-
|
|
12
|
-
|
|
39
|
+
if (!ranges.length) {
|
|
40
|
+
return import_view.DecorationSet.empty;
|
|
41
|
+
}
|
|
42
|
+
const decorations = [];
|
|
43
|
+
const doc = ranges[0].$from.node(0);
|
|
44
|
+
ranges.forEach((range) => {
|
|
45
|
+
const pos = range.$from.pos;
|
|
46
|
+
const node = range.$from.nodeAfter;
|
|
47
|
+
if (!node) {
|
|
48
|
+
return;
|
|
13
49
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
decorations.push(view.Decoration.node(pos, pos + node.nodeSize, {
|
|
23
|
-
class: 'ProseMirror-selectednoderange',
|
|
24
|
-
}));
|
|
25
|
-
});
|
|
26
|
-
return view.DecorationSet.create(doc, decorations);
|
|
50
|
+
decorations.push(
|
|
51
|
+
import_view.Decoration.node(pos, pos + node.nodeSize, {
|
|
52
|
+
class: "ProseMirror-selectednoderange"
|
|
53
|
+
})
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
return import_view.DecorationSet.create(doc, decorations);
|
|
27
57
|
}
|
|
28
58
|
|
|
59
|
+
// src/helpers/getSelectionRanges.ts
|
|
60
|
+
var import_model = require("@tiptap/pm/model");
|
|
61
|
+
var import_state = require("@tiptap/pm/state");
|
|
29
62
|
function getSelectionRanges($from, $to, depth) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (from < nodeRange.start || from >= nodeRange.end) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
const selectionRange = new state.SelectionRange(doc.resolve(from), doc.resolve(to));
|
|
49
|
-
ranges.push(selectionRange);
|
|
50
|
-
});
|
|
51
|
-
return ranges;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
class NodeRangeBookmark {
|
|
55
|
-
constructor(anchor, head) {
|
|
56
|
-
this.anchor = anchor;
|
|
57
|
-
this.head = head;
|
|
58
|
-
}
|
|
59
|
-
map(mapping) {
|
|
60
|
-
return new NodeRangeBookmark(mapping.map(this.anchor), mapping.map(this.head));
|
|
61
|
-
}
|
|
62
|
-
resolve(doc) {
|
|
63
|
-
const $anchor = doc.resolve(this.anchor);
|
|
64
|
-
const $head = doc.resolve(this.head);
|
|
65
|
-
return new NodeRangeSelection($anchor, $head);
|
|
63
|
+
const ranges = [];
|
|
64
|
+
const doc = $from.node(0);
|
|
65
|
+
if (typeof depth === "number" && depth >= 0) {
|
|
66
|
+
} else if ($from.sameParent($to)) {
|
|
67
|
+
depth = Math.max(0, $from.sharedDepth($to.pos) - 1);
|
|
68
|
+
} else {
|
|
69
|
+
depth = $from.sharedDepth($to.pos);
|
|
70
|
+
}
|
|
71
|
+
const nodeRange = new import_model.NodeRange($from, $to, depth);
|
|
72
|
+
const offset = nodeRange.depth === 0 ? 0 : doc.resolve(nodeRange.start).posAtIndex(0);
|
|
73
|
+
nodeRange.parent.forEach((node, pos) => {
|
|
74
|
+
const from = offset + pos;
|
|
75
|
+
const to = from + node.nodeSize;
|
|
76
|
+
if (from < nodeRange.start || from >= nodeRange.end) {
|
|
77
|
+
return;
|
|
66
78
|
}
|
|
79
|
+
const selectionRange = new import_state.SelectionRange(doc.resolve(from), doc.resolve(to));
|
|
80
|
+
ranges.push(selectionRange);
|
|
81
|
+
});
|
|
82
|
+
return ranges;
|
|
67
83
|
}
|
|
68
84
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
extendForwards() {
|
|
137
|
-
const { doc } = this.$from;
|
|
138
|
-
if (this.isBackwards && this.ranges.length > 1) {
|
|
139
|
-
const ranges = this.ranges.slice(1);
|
|
140
|
-
const $from = ranges[0].$from;
|
|
141
|
-
const $to = ranges[ranges.length - 1].$to;
|
|
142
|
-
return new NodeRangeSelection($to, $from, this.depth);
|
|
143
|
-
}
|
|
144
|
-
const lastRange = this.ranges[this.ranges.length - 1];
|
|
145
|
-
const $to = doc.resolve(Math.min(doc.content.size, lastRange.$to.pos + 1));
|
|
146
|
-
return new NodeRangeSelection(this.$anchor, $to, this.depth);
|
|
147
|
-
}
|
|
148
|
-
static fromJSON(doc, json) {
|
|
149
|
-
return new NodeRangeSelection(doc.resolve(json.anchor), doc.resolve(json.head));
|
|
150
|
-
}
|
|
151
|
-
static create(doc, anchor, head, depth, bias = 1) {
|
|
152
|
-
return new this(doc.resolve(anchor), doc.resolve(head), depth, bias);
|
|
85
|
+
// src/helpers/NodeRangeSelection.ts
|
|
86
|
+
var import_state2 = require("@tiptap/pm/state");
|
|
87
|
+
|
|
88
|
+
// src/helpers/NodeRangeBookmark.ts
|
|
89
|
+
var NodeRangeBookmark = class _NodeRangeBookmark {
|
|
90
|
+
constructor(anchor, head) {
|
|
91
|
+
this.anchor = anchor;
|
|
92
|
+
this.head = head;
|
|
93
|
+
}
|
|
94
|
+
map(mapping) {
|
|
95
|
+
return new _NodeRangeBookmark(mapping.map(this.anchor), mapping.map(this.head));
|
|
96
|
+
}
|
|
97
|
+
resolve(doc) {
|
|
98
|
+
const $anchor = doc.resolve(this.anchor);
|
|
99
|
+
const $head = doc.resolve(this.head);
|
|
100
|
+
return new NodeRangeSelection($anchor, $head);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
// src/helpers/NodeRangeSelection.ts
|
|
105
|
+
var NodeRangeSelection = class _NodeRangeSelection extends import_state2.Selection {
|
|
106
|
+
constructor($anchor, $head, depth, bias = 1) {
|
|
107
|
+
const { doc } = $anchor;
|
|
108
|
+
const isCursor = $anchor === $head;
|
|
109
|
+
const isCursorAtEnd = $anchor.pos === doc.content.size && $head.pos === doc.content.size;
|
|
110
|
+
const $correctedHead = isCursor && !isCursorAtEnd ? doc.resolve($head.pos + (bias > 0 ? 1 : -1)) : $head;
|
|
111
|
+
const $correctedAnchor = isCursor && isCursorAtEnd ? doc.resolve($anchor.pos - (bias > 0 ? 1 : -1)) : $anchor;
|
|
112
|
+
const ranges = getSelectionRanges($correctedAnchor.min($correctedHead), $correctedAnchor.max($correctedHead), depth);
|
|
113
|
+
const $rangeFrom = $correctedHead.pos >= $anchor.pos ? ranges[0].$from : ranges[ranges.length - 1].$to;
|
|
114
|
+
const $rangeTo = $correctedHead.pos >= $anchor.pos ? ranges[ranges.length - 1].$to : ranges[0].$from;
|
|
115
|
+
super($rangeFrom, $rangeTo, ranges);
|
|
116
|
+
this.depth = depth;
|
|
117
|
+
}
|
|
118
|
+
// we can safely ignore this TypeScript error: https://github.com/Microsoft/TypeScript/issues/338
|
|
119
|
+
// @ts-ignore
|
|
120
|
+
get $to() {
|
|
121
|
+
return this.ranges[this.ranges.length - 1].$to;
|
|
122
|
+
}
|
|
123
|
+
eq(other) {
|
|
124
|
+
return other instanceof _NodeRangeSelection && other.$from.pos === this.$from.pos && other.$to.pos === this.$to.pos;
|
|
125
|
+
}
|
|
126
|
+
map(doc, mapping) {
|
|
127
|
+
const $anchor = doc.resolve(mapping.map(this.anchor));
|
|
128
|
+
const $head = doc.resolve(mapping.map(this.head));
|
|
129
|
+
return new _NodeRangeSelection($anchor, $head);
|
|
130
|
+
}
|
|
131
|
+
toJSON() {
|
|
132
|
+
return {
|
|
133
|
+
type: "nodeRange",
|
|
134
|
+
anchor: this.anchor,
|
|
135
|
+
head: this.head
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
get isForwards() {
|
|
139
|
+
return this.head >= this.anchor;
|
|
140
|
+
}
|
|
141
|
+
get isBackwards() {
|
|
142
|
+
return !this.isForwards;
|
|
143
|
+
}
|
|
144
|
+
extendBackwards() {
|
|
145
|
+
const { doc } = this.$from;
|
|
146
|
+
if (this.isForwards && this.ranges.length > 1) {
|
|
147
|
+
const ranges = this.ranges.slice(0, -1);
|
|
148
|
+
const $from2 = ranges[0].$from;
|
|
149
|
+
const $to = ranges[ranges.length - 1].$to;
|
|
150
|
+
return new _NodeRangeSelection($from2, $to, this.depth);
|
|
153
151
|
}
|
|
154
|
-
|
|
155
|
-
|
|
152
|
+
const firstRange = this.ranges[0];
|
|
153
|
+
const $from = doc.resolve(Math.max(0, firstRange.$from.pos - 1));
|
|
154
|
+
return new _NodeRangeSelection(this.$anchor, $from, this.depth);
|
|
155
|
+
}
|
|
156
|
+
extendForwards() {
|
|
157
|
+
const { doc } = this.$from;
|
|
158
|
+
if (this.isBackwards && this.ranges.length > 1) {
|
|
159
|
+
const ranges = this.ranges.slice(1);
|
|
160
|
+
const $from = ranges[0].$from;
|
|
161
|
+
const $to2 = ranges[ranges.length - 1].$to;
|
|
162
|
+
return new _NodeRangeSelection($to2, $from, this.depth);
|
|
156
163
|
}
|
|
157
|
-
|
|
164
|
+
const lastRange = this.ranges[this.ranges.length - 1];
|
|
165
|
+
const $to = doc.resolve(Math.min(doc.content.size, lastRange.$to.pos + 1));
|
|
166
|
+
return new _NodeRangeSelection(this.$anchor, $to, this.depth);
|
|
167
|
+
}
|
|
168
|
+
static fromJSON(doc, json) {
|
|
169
|
+
return new _NodeRangeSelection(doc.resolve(json.anchor), doc.resolve(json.head));
|
|
170
|
+
}
|
|
171
|
+
static create(doc, anchor, head, depth, bias = 1) {
|
|
172
|
+
return new this(doc.resolve(anchor), doc.resolve(head), depth, bias);
|
|
173
|
+
}
|
|
174
|
+
getBookmark() {
|
|
175
|
+
return new NodeRangeBookmark(this.anchor, this.head);
|
|
176
|
+
}
|
|
177
|
+
};
|
|
158
178
|
NodeRangeSelection.prototype.visible = false;
|
|
159
179
|
|
|
180
|
+
// src/helpers/isNodeRangeSelection.ts
|
|
160
181
|
function isNodeRangeSelection(value) {
|
|
161
|
-
|
|
182
|
+
return value instanceof NodeRangeSelection;
|
|
162
183
|
}
|
|
163
184
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
const nodeRangeSelection = selection.extendForwards();
|
|
204
|
-
tr.setSelection(nodeRangeSelection);
|
|
205
|
-
view.dispatch(tr);
|
|
206
|
-
return true;
|
|
207
|
-
},
|
|
208
|
-
// add `NodeRangeSelection` to all nodes
|
|
209
|
-
'Mod-a': ({ editor }) => {
|
|
210
|
-
const { depth } = this.options;
|
|
211
|
-
const { view, state } = editor;
|
|
212
|
-
const { doc, tr } = state;
|
|
213
|
-
const nodeRangeSelection = NodeRangeSelection.create(doc, 0, doc.content.size, depth);
|
|
214
|
-
tr.setSelection(nodeRangeSelection);
|
|
215
|
-
view.dispatch(tr);
|
|
216
|
-
return true;
|
|
217
|
-
},
|
|
218
|
-
};
|
|
219
|
-
},
|
|
220
|
-
onSelectionUpdate() {
|
|
221
|
-
const { selection } = this.editor.state;
|
|
222
|
-
if (isNodeRangeSelection(selection)) {
|
|
223
|
-
this.editor.view.dom.classList.add('ProseMirror-noderangeselection');
|
|
185
|
+
// src/node-range.ts
|
|
186
|
+
var NodeRange2 = import_core.Extension.create({
|
|
187
|
+
name: "nodeRange",
|
|
188
|
+
addOptions() {
|
|
189
|
+
return {
|
|
190
|
+
depth: void 0,
|
|
191
|
+
key: "Mod"
|
|
192
|
+
};
|
|
193
|
+
},
|
|
194
|
+
addKeyboardShortcuts() {
|
|
195
|
+
return {
|
|
196
|
+
// extend NodeRangeSelection upwards
|
|
197
|
+
"Shift-ArrowUp": ({ editor }) => {
|
|
198
|
+
const { depth } = this.options;
|
|
199
|
+
const { view, state } = editor;
|
|
200
|
+
const { doc, selection, tr } = state;
|
|
201
|
+
const { anchor, head } = selection;
|
|
202
|
+
if (!isNodeRangeSelection(selection)) {
|
|
203
|
+
const nodeRangeSelection2 = NodeRangeSelection.create(doc, anchor, head, depth, -1);
|
|
204
|
+
tr.setSelection(nodeRangeSelection2);
|
|
205
|
+
view.dispatch(tr);
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
const nodeRangeSelection = selection.extendBackwards();
|
|
209
|
+
tr.setSelection(nodeRangeSelection);
|
|
210
|
+
view.dispatch(tr);
|
|
211
|
+
return true;
|
|
212
|
+
},
|
|
213
|
+
// extend NodeRangeSelection downwards
|
|
214
|
+
"Shift-ArrowDown": ({ editor }) => {
|
|
215
|
+
const { depth } = this.options;
|
|
216
|
+
const { view, state } = editor;
|
|
217
|
+
const { doc, selection, tr } = state;
|
|
218
|
+
const { anchor, head } = selection;
|
|
219
|
+
if (!isNodeRangeSelection(selection)) {
|
|
220
|
+
const nodeRangeSelection2 = NodeRangeSelection.create(doc, anchor, head, depth);
|
|
221
|
+
tr.setSelection(nodeRangeSelection2);
|
|
222
|
+
view.dispatch(tr);
|
|
223
|
+
return true;
|
|
224
224
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
}
|
|
292
|
-
const { $from, $to } = selection;
|
|
293
|
-
// selection is probably in the same node like a paragraph
|
|
294
|
-
// so we don’t render decorations and show
|
|
295
|
-
// a simple text selection instead
|
|
296
|
-
if (!isNodeRange && $from.sameParent($to)) {
|
|
297
|
-
return null;
|
|
298
|
-
}
|
|
299
|
-
// try to calculate some node ranges
|
|
300
|
-
const nodeRanges = getSelectionRanges($from, $to, this.options.depth);
|
|
301
|
-
if (!nodeRanges.length) {
|
|
302
|
-
return null;
|
|
303
|
-
}
|
|
304
|
-
hideTextSelection = true;
|
|
305
|
-
return getNodeRangeDecorations(nodeRanges);
|
|
306
|
-
},
|
|
225
|
+
const nodeRangeSelection = selection.extendForwards();
|
|
226
|
+
tr.setSelection(nodeRangeSelection);
|
|
227
|
+
view.dispatch(tr);
|
|
228
|
+
return true;
|
|
229
|
+
},
|
|
230
|
+
// add `NodeRangeSelection` to all nodes
|
|
231
|
+
"Mod-a": ({ editor }) => {
|
|
232
|
+
const { depth } = this.options;
|
|
233
|
+
const { view, state } = editor;
|
|
234
|
+
const { doc, tr } = state;
|
|
235
|
+
const nodeRangeSelection = NodeRangeSelection.create(doc, 0, doc.content.size, depth);
|
|
236
|
+
tr.setSelection(nodeRangeSelection);
|
|
237
|
+
view.dispatch(tr);
|
|
238
|
+
return true;
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
},
|
|
242
|
+
onSelectionUpdate() {
|
|
243
|
+
const { selection } = this.editor.state;
|
|
244
|
+
if (isNodeRangeSelection(selection)) {
|
|
245
|
+
this.editor.view.dom.classList.add("ProseMirror-noderangeselection");
|
|
246
|
+
}
|
|
247
|
+
},
|
|
248
|
+
addProseMirrorPlugins() {
|
|
249
|
+
let hideTextSelection = false;
|
|
250
|
+
let activeMouseSelection = false;
|
|
251
|
+
return [
|
|
252
|
+
new import_state3.Plugin({
|
|
253
|
+
key: new import_state3.PluginKey("nodeRange"),
|
|
254
|
+
props: {
|
|
255
|
+
attributes: () => {
|
|
256
|
+
if (hideTextSelection) {
|
|
257
|
+
return {
|
|
258
|
+
class: "ProseMirror-noderangeselection"
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
return { class: "" };
|
|
262
|
+
},
|
|
263
|
+
handleDOMEvents: {
|
|
264
|
+
mousedown: (view, event) => {
|
|
265
|
+
const { key } = this.options;
|
|
266
|
+
const isMac = /Mac/.test(navigator.platform);
|
|
267
|
+
const isShift = !!event.shiftKey;
|
|
268
|
+
const isControl = !!event.ctrlKey;
|
|
269
|
+
const isAlt = !!event.altKey;
|
|
270
|
+
const isMeta = !!event.metaKey;
|
|
271
|
+
const isMod = isMac ? isMeta : isControl;
|
|
272
|
+
if (key === null || key === void 0 || key === "Shift" && isShift || key === "Control" && isControl || key === "Alt" && isAlt || key === "Meta" && isMeta || key === "Mod" && isMod) {
|
|
273
|
+
activeMouseSelection = true;
|
|
274
|
+
}
|
|
275
|
+
if (!activeMouseSelection) {
|
|
276
|
+
return false;
|
|
277
|
+
}
|
|
278
|
+
document.addEventListener(
|
|
279
|
+
"mouseup",
|
|
280
|
+
() => {
|
|
281
|
+
activeMouseSelection = false;
|
|
282
|
+
const { state } = view;
|
|
283
|
+
const { doc, selection, tr } = state;
|
|
284
|
+
const { $anchor, $head } = selection;
|
|
285
|
+
if ($anchor.sameParent($head)) {
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
const nodeRangeSelection = NodeRangeSelection.create(doc, $anchor.pos, $head.pos, this.options.depth);
|
|
289
|
+
tr.setSelection(nodeRangeSelection);
|
|
290
|
+
view.dispatch(tr);
|
|
307
291
|
},
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
292
|
+
{ once: true }
|
|
293
|
+
);
|
|
294
|
+
return false;
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
// when selecting some text we want to render some decorations
|
|
298
|
+
// to preview a `NodeRangeSelection`
|
|
299
|
+
decorations: (state) => {
|
|
300
|
+
const { selection } = state;
|
|
301
|
+
const isNodeRange = isNodeRangeSelection(selection);
|
|
302
|
+
hideTextSelection = false;
|
|
303
|
+
if (!activeMouseSelection) {
|
|
304
|
+
if (!isNodeRange) {
|
|
305
|
+
return null;
|
|
306
|
+
}
|
|
307
|
+
hideTextSelection = true;
|
|
308
|
+
return getNodeRangeDecorations(selection.ranges);
|
|
309
|
+
}
|
|
310
|
+
const { $from, $to } = selection;
|
|
311
|
+
if (!isNodeRange && $from.sameParent($to)) {
|
|
312
|
+
return null;
|
|
313
|
+
}
|
|
314
|
+
const nodeRanges = getSelectionRanges($from, $to, this.options.depth);
|
|
315
|
+
if (!nodeRanges.length) {
|
|
316
|
+
return null;
|
|
317
|
+
}
|
|
318
|
+
hideTextSelection = true;
|
|
319
|
+
return getNodeRangeDecorations(nodeRanges);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
})
|
|
323
|
+
];
|
|
324
|
+
}
|
|
311
325
|
});
|
|
312
326
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
exports
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
327
|
+
// src/index.ts
|
|
328
|
+
var index_default = NodeRange2;
|
|
329
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
330
|
+
0 && (module.exports = {
|
|
331
|
+
NodeRange,
|
|
332
|
+
NodeRangeSelection,
|
|
333
|
+
getNodeRangeDecorations,
|
|
334
|
+
getSelectionRanges,
|
|
335
|
+
isNodeRangeSelection
|
|
336
|
+
});
|
|
337
|
+
//# sourceMappingURL=index.cjs.map
|