@tiptap/extension-node-range 2.24.2 → 3.0.0-beta.10

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/index.cjs CHANGED
@@ -1,319 +1,337 @@
1
- 'use strict';
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
- Object.defineProperty(exports, '__esModule', { value: true });
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
- var core = require('@tiptap/core');
6
- var state = require('@tiptap/pm/state');
7
- var view = require('@tiptap/pm/view');
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
- if (!ranges.length) {
12
- return view.DecorationSet.empty;
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
- const decorations = [];
15
- const doc = ranges[0].$from.node(0);
16
- ranges.forEach(range => {
17
- const pos = range.$from.pos;
18
- const node = range.$from.nodeAfter;
19
- if (!node) {
20
- return;
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
- const ranges = [];
31
- const doc = $from.node(0);
32
- // eslint-disable-next-line
33
- depth = (typeof depth === 'number' && depth >= 0)
34
- ? depth
35
- : $from.sameParent($to)
36
- ? Math.max(0, $from.sharedDepth($to.pos) - 1)
37
- : $from.sharedDepth($to.pos);
38
- const nodeRange = new model.NodeRange($from, $to, depth);
39
- const offset = nodeRange.depth === 0
40
- ? 0
41
- : doc.resolve(nodeRange.start).posAtIndex(0);
42
- nodeRange.parent.forEach((node, pos) => {
43
- const from = offset + pos;
44
- const to = from + node.nodeSize;
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
- class NodeRangeSelection extends state.Selection {
70
- constructor($anchor, $head, depth, bias = 1) {
71
- // if there is only a cursor we can’t calculate a direction of the selection
72
- // that’s why we adjust the head position by 1 in the desired direction
73
- const { doc } = $anchor;
74
- const isCursor = $anchor === $head;
75
- const isCursorAtEnd = $anchor.pos === doc.content.size && $head.pos === doc.content.size;
76
- const $correctedHead = isCursor && !isCursorAtEnd
77
- ? doc.resolve($head.pos + (bias > 0 ? 1 : -1))
78
- : $head;
79
- const $correctedAnchor = isCursor && isCursorAtEnd
80
- ? doc.resolve($anchor.pos - (bias > 0 ? 1 : -1))
81
- : $anchor;
82
- const ranges = getSelectionRanges($correctedAnchor.min($correctedHead), $correctedAnchor.max($correctedHead), depth);
83
- // get the smallest range start position
84
- // this will become the $anchor
85
- const $rangeFrom = ($correctedHead.pos >= $anchor.pos)
86
- ? ranges[0].$from
87
- : ranges[ranges.length - 1].$to;
88
- // get the biggest range end position
89
- // this will become the $head
90
- const $rangeTo = ($correctedHead.pos >= $anchor.pos)
91
- ? ranges[ranges.length - 1].$to
92
- : ranges[0].$from;
93
- super($rangeFrom, $rangeTo, ranges);
94
- this.depth = depth;
95
- }
96
- // we can safely ignore this TypeScript error: https://github.com/Microsoft/TypeScript/issues/338
97
- // @ts-ignore
98
- get $to() {
99
- return this.ranges[this.ranges.length - 1].$to;
100
- }
101
- eq(other) {
102
- return other instanceof NodeRangeSelection
103
- && other.$from.pos === this.$from.pos
104
- && other.$to.pos === this.$to.pos;
105
- }
106
- map(doc, mapping) {
107
- const $anchor = doc.resolve(mapping.map(this.anchor));
108
- const $head = doc.resolve(mapping.map(this.head));
109
- return new NodeRangeSelection($anchor, $head);
110
- }
111
- toJSON() {
112
- return {
113
- type: 'nodeRange',
114
- anchor: this.anchor,
115
- head: this.head,
116
- };
117
- }
118
- get isForwards() {
119
- return this.head >= this.anchor;
120
- }
121
- get isBackwards() {
122
- return !this.isForwards;
123
- }
124
- extendBackwards() {
125
- const { doc } = this.$from;
126
- if (this.isForwards && this.ranges.length > 1) {
127
- const ranges = this.ranges.slice(0, -1);
128
- const $from = ranges[0].$from;
129
- const $to = ranges[ranges.length - 1].$to;
130
- return new NodeRangeSelection($from, $to, this.depth);
131
- }
132
- const firstRange = this.ranges[0];
133
- const $from = doc.resolve(Math.max(0, firstRange.$from.pos - 1));
134
- return new NodeRangeSelection(this.$anchor, $from, this.depth);
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
- getBookmark() {
155
- return new NodeRangeBookmark(this.anchor, this.head);
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
- return value instanceof NodeRangeSelection;
182
+ return value instanceof NodeRangeSelection;
162
183
  }
163
184
 
164
- const NodeRange = core.Extension.create({
165
- name: 'nodeRange',
166
- addOptions() {
167
- return {
168
- depth: undefined,
169
- key: 'Mod',
170
- };
171
- },
172
- addKeyboardShortcuts() {
173
- return {
174
- // extend NodeRangeSelection upwards
175
- 'Shift-ArrowUp': ({ editor }) => {
176
- const { depth } = this.options;
177
- const { view, state } = editor;
178
- const { doc, selection, tr } = state;
179
- const { anchor, head } = selection;
180
- if (!isNodeRangeSelection(selection)) {
181
- const nodeRangeSelection = NodeRangeSelection.create(doc, anchor, head, depth, -1);
182
- tr.setSelection(nodeRangeSelection);
183
- view.dispatch(tr);
184
- return true;
185
- }
186
- const nodeRangeSelection = selection.extendBackwards();
187
- tr.setSelection(nodeRangeSelection);
188
- view.dispatch(tr);
189
- return true;
190
- },
191
- // extend NodeRangeSelection downwards
192
- 'Shift-ArrowDown': ({ editor }) => {
193
- const { depth } = this.options;
194
- const { view, state } = editor;
195
- const { doc, selection, tr } = state;
196
- const { anchor, head } = selection;
197
- if (!isNodeRangeSelection(selection)) {
198
- const nodeRangeSelection = NodeRangeSelection.create(doc, anchor, head, depth);
199
- tr.setSelection(nodeRangeSelection);
200
- view.dispatch(tr);
201
- return true;
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
- addProseMirrorPlugins() {
227
- let hideTextSelection = false;
228
- let activeMouseSelection = false;
229
- return [
230
- new state.Plugin({
231
- key: new state.PluginKey('nodeRange'),
232
- props: {
233
- attributes: () => {
234
- if (hideTextSelection) {
235
- return {
236
- class: 'ProseMirror-noderangeselection',
237
- };
238
- }
239
- return { class: '' };
240
- },
241
- handleDOMEvents: {
242
- mousedown: (view, event) => {
243
- const { key } = this.options;
244
- const isMac = /Mac/.test(navigator.platform);
245
- const isShift = !!event.shiftKey;
246
- const isControl = !!event.ctrlKey;
247
- const isAlt = !!event.altKey;
248
- const isMeta = !!event.metaKey;
249
- const isMod = isMac
250
- ? isMeta
251
- : isControl;
252
- if (key === null
253
- || key === undefined
254
- || (key === 'Shift' && isShift)
255
- || (key === 'Control' && isControl)
256
- || (key === 'Alt' && isAlt)
257
- || (key === 'Meta' && isMeta)
258
- || (key === 'Mod' && isMod)) {
259
- activeMouseSelection = true;
260
- }
261
- if (!activeMouseSelection) {
262
- return false;
263
- }
264
- document.addEventListener('mouseup', () => {
265
- activeMouseSelection = false;
266
- const { state } = view;
267
- const { doc, selection, tr } = state;
268
- const { $anchor, $head } = selection;
269
- if ($anchor.sameParent($head)) {
270
- return;
271
- }
272
- const nodeRangeSelection = NodeRangeSelection.create(doc, $anchor.pos, $head.pos, this.options.depth);
273
- tr.setSelection(nodeRangeSelection);
274
- view.dispatch(tr);
275
- }, { once: true });
276
- return false;
277
- },
278
- },
279
- // when selecting some text we want to render some decorations
280
- // to preview a `NodeRangeSelection`
281
- decorations: state => {
282
- const { selection } = state;
283
- const isNodeRange = isNodeRangeSelection(selection);
284
- hideTextSelection = false;
285
- if (!activeMouseSelection) {
286
- if (!isNodeRange) {
287
- return null;
288
- }
289
- hideTextSelection = true;
290
- return getNodeRangeDecorations(selection.ranges);
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
- exports.NodeRange = NodeRange;
314
- exports.NodeRangeSelection = NodeRangeSelection;
315
- exports.default = NodeRange;
316
- exports.getNodeRangeDecorations = getNodeRangeDecorations;
317
- exports.getSelectionRanges = getSelectionRanges;
318
- exports.isNodeRangeSelection = isNodeRangeSelection;
319
- //# sourceMappingURL=index.cjs.map
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