@lblod/ember-rdfa-editor 13.1.1 → 13.2.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/README.md +12 -9
- package/declarations/components/_private/common/configurable-rdfa-display.d.ts +4 -4
- package/declarations/components/editor.d.ts +2 -0
- package/declarations/components/toolbar/button.d.ts +1 -1
- package/declarations/core/say-controller.d.ts +11 -4
- package/declarations/core/say-data-factory/blank-node.d.ts +1 -1
- package/declarations/core/say-data-factory/default-graph.d.ts +1 -1
- package/declarations/core/say-data-factory/literal.d.ts +1 -1
- package/declarations/core/say-data-factory/named-node.d.ts +1 -1
- package/declarations/core/say-data-factory/prosemirror-terms/content-literal.d.ts +1 -1
- package/declarations/core/say-data-factory/prosemirror-terms/literal-node.d.ts +1 -1
- package/declarations/core/say-data-factory/prosemirror-terms/resource-node.d.ts +1 -1
- package/declarations/core/say-data-factory/quad.d.ts +1 -1
- package/declarations/core/say-data-factory/variable.d.ts +1 -1
- package/declarations/core/say-editor.d.ts +1 -0
- package/declarations/core/say-view.d.ts +7 -1
- package/declarations/utils/_private/rdfa-parser/util.d.ts +1 -1
- package/dist/commands/_private/rdfa-commands/remove-backlink.js +1 -1
- package/dist/commands/_private/rdfa-commands/select-node-by-rdfa-id.js +1 -1
- package/dist/commands/_private/rdfa-commands/select-node-by-subject.js +1 -1
- package/dist/commands/_private/rdfa-commands/wrap-inline-resource.js +1 -1
- package/dist/commands/_private/rdfa-commands/wrap-literal.js +1 -1
- package/dist/commands/_private/rdfa-commands/wrap-resource.js +1 -1
- package/dist/commands/rdfa-commands/add-property.js +1 -1
- package/dist/commands/rdfa-commands/remove-property.js +1 -1
- package/dist/components/_private/attribute-editor/index.js +1 -1
- package/dist/components/_private/attribute-editor/index.js.map +1 -1
- package/dist/components/_private/common/configurable-rdfa-display.js +1 -1
- package/dist/components/_private/common/configurable-rdfa-display.js.map +1 -1
- package/dist/components/_private/common/property-details.js +1 -1
- package/dist/components/_private/node-controls/wrapping-utils.js +2 -2
- package/dist/components/_private/node-controls/wrapping-utils.js.map +1 -1
- package/dist/components/_private/rdfa-visualiser/rdfa-explorer.js +1 -1
- package/dist/components/_private/rdfa-visualiser/resource-info.js +1 -1
- package/dist/components/_private/rdfa-visualiser/visualiser-card.js +1 -1
- package/dist/components/collapsible.js +1 -1
- package/dist/components/collapsible.js.map +1 -1
- package/dist/components/editor.js +7 -1
- package/dist/components/editor.js.map +1 -1
- package/dist/components/ember-node/embedded-editor.js +4 -1
- package/dist/components/ember-node/embedded-editor.js.map +1 -1
- package/dist/components/plugins/history/redo.js +1 -1
- package/dist/components/plugins/history/undo.js +1 -1
- package/dist/components/plugins/list/ordered.js +1 -1
- package/dist/components/plugins/list/unordered.js +1 -1
- package/dist/components/toolbar/mark.js +1 -1
- package/dist/core/keymap.js +2 -2
- package/dist/core/rdfa-types.js +1 -1
- package/dist/core/say-controller.js +41 -5
- package/dist/core/say-controller.js.map +1 -1
- package/dist/core/say-data-factory/blank-node.js +2 -2
- package/dist/core/say-data-factory/blank-node.js.map +1 -1
- package/dist/core/say-data-factory/default-graph.js +2 -2
- package/dist/core/say-data-factory/default-graph.js.map +1 -1
- package/dist/core/say-data-factory/literal.js +2 -2
- package/dist/core/say-data-factory/literal.js.map +1 -1
- package/dist/core/say-data-factory/named-node.js +2 -2
- package/dist/core/say-data-factory/named-node.js.map +1 -1
- package/dist/core/say-data-factory/prosemirror-terms/content-literal.js +2 -2
- package/dist/core/say-data-factory/prosemirror-terms/content-literal.js.map +1 -1
- package/dist/core/say-data-factory/prosemirror-terms/literal-node.js +2 -2
- package/dist/core/say-data-factory/prosemirror-terms/literal-node.js.map +1 -1
- package/dist/core/say-data-factory/prosemirror-terms/resource-node.js +2 -2
- package/dist/core/say-data-factory/prosemirror-terms/resource-node.js.map +1 -1
- package/dist/core/say-data-factory/quad.js +2 -2
- package/dist/core/say-data-factory/quad.js.map +1 -1
- package/dist/core/say-data-factory/variable.js +2 -2
- package/dist/core/say-data-factory/variable.js.map +1 -1
- package/dist/core/say-editor.js +4 -2
- package/dist/core/say-editor.js.map +1 -1
- package/dist/core/say-view.js +2 -1
- package/dist/core/say-view.js.map +1 -1
- package/dist/index-CxRqg5Kr.js +671 -0
- package/dist/index-CxRqg5Kr.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/{main-dUbkrxFL.js → main-DFf-0En3.js} +7988 -8105
- package/dist/main-DFf-0En3.js.map +1 -0
- package/dist/nodes/invisible-rdfa.js +1 -1
- package/dist/plugins/history/index.js +1 -1
- package/dist/plugins/list/commands/lift-out-of-nested-lists.js +1 -1
- package/dist/plugins/rdfa-info/index.js +1 -1
- package/dist/plugins/rdfa-info/types.js +1 -1
- package/dist/plugins/remove-properties-of-deleted-nodes/index.js +1 -1
- package/dist/utils/_private/datastore/graphy-dataset.js +1 -1
- package/dist/utils/_private/ember-node.js +0 -2
- package/dist/utils/_private/ember-node.js.map +1 -1
- package/dist/utils/_private/rdfa-parser/util.js +1 -8
- package/dist/utils/_private/rdfa-parser/util.js.map +1 -1
- package/package.json +8 -7
- package/declarations/components/toolbar.d.ts +0 -1
- package/dist/main-dUbkrxFL.js.map +0 -1
|
@@ -0,0 +1,671 @@
|
|
|
1
|
+
import { Mapping } from 'prosemirror-transform';
|
|
2
|
+
import { PluginKey, Plugin } from 'prosemirror-state';
|
|
3
|
+
|
|
4
|
+
var GOOD_LEAF_SIZE = 200;
|
|
5
|
+
|
|
6
|
+
// :: class<T> A rope sequence is a persistent sequence data structure
|
|
7
|
+
// that supports appending, prepending, and slicing without doing a
|
|
8
|
+
// full copy. It is represented as a mostly-balanced tree.
|
|
9
|
+
var RopeSequence = function RopeSequence() {};
|
|
10
|
+
RopeSequence.prototype.append = function append(other) {
|
|
11
|
+
if (!other.length) {
|
|
12
|
+
return this;
|
|
13
|
+
}
|
|
14
|
+
other = RopeSequence.from(other);
|
|
15
|
+
return !this.length && other || other.length < GOOD_LEAF_SIZE && this.leafAppend(other) || this.length < GOOD_LEAF_SIZE && other.leafPrepend(this) || this.appendInner(other);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// :: (union<[T], RopeSequence<T>>) → RopeSequence<T>
|
|
19
|
+
// Prepend an array or other rope to this one, returning a new rope.
|
|
20
|
+
RopeSequence.prototype.prepend = function prepend(other) {
|
|
21
|
+
if (!other.length) {
|
|
22
|
+
return this;
|
|
23
|
+
}
|
|
24
|
+
return RopeSequence.from(other).append(this);
|
|
25
|
+
};
|
|
26
|
+
RopeSequence.prototype.appendInner = function appendInner(other) {
|
|
27
|
+
return new Append(this, other);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// :: (?number, ?number) → RopeSequence<T>
|
|
31
|
+
// Create a rope repesenting a sub-sequence of this rope.
|
|
32
|
+
RopeSequence.prototype.slice = function slice(from, to) {
|
|
33
|
+
if (from === void 0) from = 0;
|
|
34
|
+
if (to === void 0) to = this.length;
|
|
35
|
+
if (from >= to) {
|
|
36
|
+
return RopeSequence.empty;
|
|
37
|
+
}
|
|
38
|
+
return this.sliceInner(Math.max(0, from), Math.min(this.length, to));
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// :: (number) → T
|
|
42
|
+
// Retrieve the element at the given position from this rope.
|
|
43
|
+
RopeSequence.prototype.get = function get(i) {
|
|
44
|
+
if (i < 0 || i >= this.length) {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
return this.getInner(i);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// :: ((element: T, index: number) → ?bool, ?number, ?number)
|
|
51
|
+
// Call the given function for each element between the given
|
|
52
|
+
// indices. This tends to be more efficient than looping over the
|
|
53
|
+
// indices and calling `get`, because it doesn't have to descend the
|
|
54
|
+
// tree for every element.
|
|
55
|
+
RopeSequence.prototype.forEach = function forEach(f, from, to) {
|
|
56
|
+
if (from === void 0) from = 0;
|
|
57
|
+
if (to === void 0) to = this.length;
|
|
58
|
+
if (from <= to) {
|
|
59
|
+
this.forEachInner(f, from, to, 0);
|
|
60
|
+
} else {
|
|
61
|
+
this.forEachInvertedInner(f, from, to, 0);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// :: ((element: T, index: number) → U, ?number, ?number) → [U]
|
|
66
|
+
// Map the given functions over the elements of the rope, producing
|
|
67
|
+
// a flat array.
|
|
68
|
+
RopeSequence.prototype.map = function map(f, from, to) {
|
|
69
|
+
if (from === void 0) from = 0;
|
|
70
|
+
if (to === void 0) to = this.length;
|
|
71
|
+
var result = [];
|
|
72
|
+
this.forEach(function (elt, i) {
|
|
73
|
+
return result.push(f(elt, i));
|
|
74
|
+
}, from, to);
|
|
75
|
+
return result;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// :: (?union<[T], RopeSequence<T>>) → RopeSequence<T>
|
|
79
|
+
// Create a rope representing the given array, or return the rope
|
|
80
|
+
// itself if a rope was given.
|
|
81
|
+
RopeSequence.from = function from(values) {
|
|
82
|
+
if (values instanceof RopeSequence) {
|
|
83
|
+
return values;
|
|
84
|
+
}
|
|
85
|
+
return values && values.length ? new Leaf(values) : RopeSequence.empty;
|
|
86
|
+
};
|
|
87
|
+
var Leaf = /*@__PURE__*/function (RopeSequence) {
|
|
88
|
+
function Leaf(values) {
|
|
89
|
+
RopeSequence.call(this);
|
|
90
|
+
this.values = values;
|
|
91
|
+
}
|
|
92
|
+
if (RopeSequence) Leaf.__proto__ = RopeSequence;
|
|
93
|
+
Leaf.prototype = Object.create(RopeSequence && RopeSequence.prototype);
|
|
94
|
+
Leaf.prototype.constructor = Leaf;
|
|
95
|
+
var prototypeAccessors = {
|
|
96
|
+
length: {
|
|
97
|
+
configurable: true
|
|
98
|
+
},
|
|
99
|
+
depth: {
|
|
100
|
+
configurable: true
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
Leaf.prototype.flatten = function flatten() {
|
|
104
|
+
return this.values;
|
|
105
|
+
};
|
|
106
|
+
Leaf.prototype.sliceInner = function sliceInner(from, to) {
|
|
107
|
+
if (from == 0 && to == this.length) {
|
|
108
|
+
return this;
|
|
109
|
+
}
|
|
110
|
+
return new Leaf(this.values.slice(from, to));
|
|
111
|
+
};
|
|
112
|
+
Leaf.prototype.getInner = function getInner(i) {
|
|
113
|
+
return this.values[i];
|
|
114
|
+
};
|
|
115
|
+
Leaf.prototype.forEachInner = function forEachInner(f, from, to, start) {
|
|
116
|
+
for (var i = from; i < to; i++) {
|
|
117
|
+
if (f(this.values[i], start + i) === false) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
Leaf.prototype.forEachInvertedInner = function forEachInvertedInner(f, from, to, start) {
|
|
123
|
+
for (var i = from - 1; i >= to; i--) {
|
|
124
|
+
if (f(this.values[i], start + i) === false) {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
Leaf.prototype.leafAppend = function leafAppend(other) {
|
|
130
|
+
if (this.length + other.length <= GOOD_LEAF_SIZE) {
|
|
131
|
+
return new Leaf(this.values.concat(other.flatten()));
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
Leaf.prototype.leafPrepend = function leafPrepend(other) {
|
|
135
|
+
if (this.length + other.length <= GOOD_LEAF_SIZE) {
|
|
136
|
+
return new Leaf(other.flatten().concat(this.values));
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
prototypeAccessors.length.get = function () {
|
|
140
|
+
return this.values.length;
|
|
141
|
+
};
|
|
142
|
+
prototypeAccessors.depth.get = function () {
|
|
143
|
+
return 0;
|
|
144
|
+
};
|
|
145
|
+
Object.defineProperties(Leaf.prototype, prototypeAccessors);
|
|
146
|
+
return Leaf;
|
|
147
|
+
}(RopeSequence);
|
|
148
|
+
|
|
149
|
+
// :: RopeSequence
|
|
150
|
+
// The empty rope sequence.
|
|
151
|
+
RopeSequence.empty = new Leaf([]);
|
|
152
|
+
var Append = /*@__PURE__*/function (RopeSequence) {
|
|
153
|
+
function Append(left, right) {
|
|
154
|
+
RopeSequence.call(this);
|
|
155
|
+
this.left = left;
|
|
156
|
+
this.right = right;
|
|
157
|
+
this.length = left.length + right.length;
|
|
158
|
+
this.depth = Math.max(left.depth, right.depth) + 1;
|
|
159
|
+
}
|
|
160
|
+
if (RopeSequence) Append.__proto__ = RopeSequence;
|
|
161
|
+
Append.prototype = Object.create(RopeSequence && RopeSequence.prototype);
|
|
162
|
+
Append.prototype.constructor = Append;
|
|
163
|
+
Append.prototype.flatten = function flatten() {
|
|
164
|
+
return this.left.flatten().concat(this.right.flatten());
|
|
165
|
+
};
|
|
166
|
+
Append.prototype.getInner = function getInner(i) {
|
|
167
|
+
return i < this.left.length ? this.left.get(i) : this.right.get(i - this.left.length);
|
|
168
|
+
};
|
|
169
|
+
Append.prototype.forEachInner = function forEachInner(f, from, to, start) {
|
|
170
|
+
var leftLen = this.left.length;
|
|
171
|
+
if (from < leftLen && this.left.forEachInner(f, from, Math.min(to, leftLen), start) === false) {
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
if (to > leftLen && this.right.forEachInner(f, Math.max(from - leftLen, 0), Math.min(this.length, to) - leftLen, start + leftLen) === false) {
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
Append.prototype.forEachInvertedInner = function forEachInvertedInner(f, from, to, start) {
|
|
179
|
+
var leftLen = this.left.length;
|
|
180
|
+
if (from > leftLen && this.right.forEachInvertedInner(f, from - leftLen, Math.max(to, leftLen) - leftLen, start + leftLen) === false) {
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
if (to < leftLen && this.left.forEachInvertedInner(f, Math.min(from, leftLen), to, start) === false) {
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
Append.prototype.sliceInner = function sliceInner(from, to) {
|
|
188
|
+
if (from == 0 && to == this.length) {
|
|
189
|
+
return this;
|
|
190
|
+
}
|
|
191
|
+
var leftLen = this.left.length;
|
|
192
|
+
if (to <= leftLen) {
|
|
193
|
+
return this.left.slice(from, to);
|
|
194
|
+
}
|
|
195
|
+
if (from >= leftLen) {
|
|
196
|
+
return this.right.slice(from - leftLen, to - leftLen);
|
|
197
|
+
}
|
|
198
|
+
return this.left.slice(from, leftLen).append(this.right.slice(0, to - leftLen));
|
|
199
|
+
};
|
|
200
|
+
Append.prototype.leafAppend = function leafAppend(other) {
|
|
201
|
+
var inner = this.right.leafAppend(other);
|
|
202
|
+
if (inner) {
|
|
203
|
+
return new Append(this.left, inner);
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
Append.prototype.leafPrepend = function leafPrepend(other) {
|
|
207
|
+
var inner = this.left.leafPrepend(other);
|
|
208
|
+
if (inner) {
|
|
209
|
+
return new Append(inner, this.right);
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
Append.prototype.appendInner = function appendInner(other) {
|
|
213
|
+
if (this.left.depth >= Math.max(this.right.depth, other.depth) + 1) {
|
|
214
|
+
return new Append(this.left, new Append(this.right, other));
|
|
215
|
+
}
|
|
216
|
+
return new Append(this, other);
|
|
217
|
+
};
|
|
218
|
+
return Append;
|
|
219
|
+
}(RopeSequence);
|
|
220
|
+
|
|
221
|
+
// ProseMirror's history isn't simply a way to roll back to a previous
|
|
222
|
+
// state, because ProseMirror supports applying changes without adding
|
|
223
|
+
// them to the history (for example during collaboration).
|
|
224
|
+
//
|
|
225
|
+
// To this end, each 'Branch' (one for the undo history and one for
|
|
226
|
+
// the redo history) keeps an array of 'Items', which can optionally
|
|
227
|
+
// hold a step (an actual undoable change), and always hold a position
|
|
228
|
+
// map (which is needed to move changes below them to apply to the
|
|
229
|
+
// current document).
|
|
230
|
+
//
|
|
231
|
+
// An item that has both a step and a selection bookmark is the start
|
|
232
|
+
// of an 'event' — a group of changes that will be undone or redone at
|
|
233
|
+
// once. (It stores only the bookmark, since that way we don't have to
|
|
234
|
+
// provide a document until the selection is actually applied, which
|
|
235
|
+
// is useful when compressing.)
|
|
236
|
+
// Used to schedule history compression
|
|
237
|
+
const max_empty_items = 500;
|
|
238
|
+
class Branch {
|
|
239
|
+
constructor(items, eventCount) {
|
|
240
|
+
this.items = items;
|
|
241
|
+
this.eventCount = eventCount;
|
|
242
|
+
}
|
|
243
|
+
// Pop the latest event off the branch's history and apply it
|
|
244
|
+
// to a document transform.
|
|
245
|
+
popEvent(state, preserveItems) {
|
|
246
|
+
if (this.eventCount == 0) return null;
|
|
247
|
+
let end = this.items.length;
|
|
248
|
+
for (;; end--) {
|
|
249
|
+
let next = this.items.get(end - 1);
|
|
250
|
+
if (next.selection) {
|
|
251
|
+
--end;
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
let remap, mapFrom;
|
|
256
|
+
if (preserveItems) {
|
|
257
|
+
remap = this.remapping(end, this.items.length);
|
|
258
|
+
mapFrom = remap.maps.length;
|
|
259
|
+
}
|
|
260
|
+
let transform = state.tr,
|
|
261
|
+
poppedId;
|
|
262
|
+
let selection, remaining;
|
|
263
|
+
let addAfter = [],
|
|
264
|
+
addBefore = [];
|
|
265
|
+
this.items.forEach((item, i) => {
|
|
266
|
+
if (!item.step) {
|
|
267
|
+
if (!remap) {
|
|
268
|
+
remap = this.remapping(end, i + 1);
|
|
269
|
+
mapFrom = remap.maps.length;
|
|
270
|
+
}
|
|
271
|
+
mapFrom--;
|
|
272
|
+
addBefore.push(item);
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
if (remap) {
|
|
276
|
+
addBefore.push(new Item(item.map));
|
|
277
|
+
let step = item.step.map(remap.slice(mapFrom)),
|
|
278
|
+
map;
|
|
279
|
+
if (step && transform.maybeStep(step).doc) {
|
|
280
|
+
map = transform.mapping.maps[transform.mapping.maps.length - 1];
|
|
281
|
+
addAfter.push(new Item(map, undefined, undefined, addAfter.length + addBefore.length));
|
|
282
|
+
}
|
|
283
|
+
mapFrom--;
|
|
284
|
+
if (map) remap.appendMap(map, mapFrom);
|
|
285
|
+
} else {
|
|
286
|
+
transform.maybeStep(item.step);
|
|
287
|
+
}
|
|
288
|
+
if (item.selection) {
|
|
289
|
+
selection = remap ? item.selection.map(remap.slice(mapFrom)) : item.selection;
|
|
290
|
+
remaining = new Branch(this.items.slice(0, end).append(addBefore.reverse().concat(addAfter)), this.eventCount - 1);
|
|
291
|
+
poppedId = item.id;
|
|
292
|
+
return false;
|
|
293
|
+
}
|
|
294
|
+
}, this.items.length, 0);
|
|
295
|
+
return {
|
|
296
|
+
remaining: remaining,
|
|
297
|
+
transform,
|
|
298
|
+
selection: selection,
|
|
299
|
+
itemId: poppedId
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
// Create a new branch with the given transform added.
|
|
303
|
+
addTransform(transform, selection, histOptions, preserveItems, itemId) {
|
|
304
|
+
let newItems = [],
|
|
305
|
+
eventCount = this.eventCount;
|
|
306
|
+
let oldItems = this.items,
|
|
307
|
+
lastItem = !preserveItems && oldItems.length ? oldItems.get(oldItems.length - 1) : null;
|
|
308
|
+
for (let i = 0; i < transform.steps.length; i++) {
|
|
309
|
+
let step = transform.steps[i].invert(transform.docs[i]);
|
|
310
|
+
let item = new Item(transform.mapping.maps[i], step, selection, undefined, itemId),
|
|
311
|
+
merged;
|
|
312
|
+
if (merged = lastItem && lastItem.merge(item)) {
|
|
313
|
+
item = merged;
|
|
314
|
+
if (i) newItems.pop();else oldItems = oldItems.slice(0, oldItems.length - 1);
|
|
315
|
+
}
|
|
316
|
+
newItems.push(item);
|
|
317
|
+
if (selection) {
|
|
318
|
+
eventCount++;
|
|
319
|
+
selection = undefined;
|
|
320
|
+
}
|
|
321
|
+
if (!preserveItems) lastItem = item;
|
|
322
|
+
}
|
|
323
|
+
let overflow = eventCount - histOptions.depth;
|
|
324
|
+
if (overflow > DEPTH_OVERFLOW) {
|
|
325
|
+
oldItems = cutOffEvents(oldItems, overflow);
|
|
326
|
+
eventCount -= overflow;
|
|
327
|
+
}
|
|
328
|
+
return new Branch(oldItems.append(newItems), eventCount);
|
|
329
|
+
}
|
|
330
|
+
remapping(from, to) {
|
|
331
|
+
let maps = new Mapping();
|
|
332
|
+
this.items.forEach((item, i) => {
|
|
333
|
+
let mirrorPos = item.mirrorOffset != null && i - item.mirrorOffset >= from ? maps.maps.length - item.mirrorOffset : undefined;
|
|
334
|
+
maps.appendMap(item.map, mirrorPos);
|
|
335
|
+
}, from, to);
|
|
336
|
+
return maps;
|
|
337
|
+
}
|
|
338
|
+
addMaps(array) {
|
|
339
|
+
if (this.eventCount == 0) return this;
|
|
340
|
+
return new Branch(this.items.append(array.map(map => new Item(map))), this.eventCount);
|
|
341
|
+
}
|
|
342
|
+
// When the collab module receives remote changes, the history has
|
|
343
|
+
// to know about those, so that it can adjust the steps that were
|
|
344
|
+
// rebased on top of the remote changes, and include the position
|
|
345
|
+
// maps for the remote changes in its array of items.
|
|
346
|
+
rebased(rebasedTransform, rebasedCount) {
|
|
347
|
+
if (!this.eventCount) return this;
|
|
348
|
+
let rebasedItems = [],
|
|
349
|
+
start = Math.max(0, this.items.length - rebasedCount);
|
|
350
|
+
let mapping = rebasedTransform.mapping;
|
|
351
|
+
let newUntil = rebasedTransform.steps.length;
|
|
352
|
+
let eventCount = this.eventCount;
|
|
353
|
+
this.items.forEach(item => {
|
|
354
|
+
if (item.selection) eventCount--;
|
|
355
|
+
}, start);
|
|
356
|
+
let iRebased = rebasedCount;
|
|
357
|
+
this.items.forEach(item => {
|
|
358
|
+
let pos = mapping.getMirror(--iRebased);
|
|
359
|
+
if (pos == null) return;
|
|
360
|
+
newUntil = Math.min(newUntil, pos);
|
|
361
|
+
let map = mapping.maps[pos];
|
|
362
|
+
if (item.step) {
|
|
363
|
+
let step = rebasedTransform.steps[pos].invert(rebasedTransform.docs[pos]);
|
|
364
|
+
let selection = item.selection && item.selection.map(mapping.slice(iRebased + 1, pos));
|
|
365
|
+
if (selection) eventCount++;
|
|
366
|
+
rebasedItems.push(new Item(map, step, selection));
|
|
367
|
+
} else {
|
|
368
|
+
rebasedItems.push(new Item(map));
|
|
369
|
+
}
|
|
370
|
+
}, start);
|
|
371
|
+
let newMaps = [];
|
|
372
|
+
for (let i = rebasedCount; i < newUntil; i++) newMaps.push(new Item(mapping.maps[i]));
|
|
373
|
+
let items = this.items.slice(0, start).append(newMaps).append(rebasedItems);
|
|
374
|
+
let branch = new Branch(items, eventCount);
|
|
375
|
+
if (branch.emptyItemCount() > max_empty_items) branch = branch.compress(this.items.length - rebasedItems.length);
|
|
376
|
+
return branch;
|
|
377
|
+
}
|
|
378
|
+
emptyItemCount() {
|
|
379
|
+
let count = 0;
|
|
380
|
+
this.items.forEach(item => {
|
|
381
|
+
if (!item.step) count++;
|
|
382
|
+
});
|
|
383
|
+
return count;
|
|
384
|
+
}
|
|
385
|
+
// Compressing a branch means rewriting it to push the air (map-only
|
|
386
|
+
// items) out. During collaboration, these naturally accumulate
|
|
387
|
+
// because each remote change adds one. The `upto` argument is used
|
|
388
|
+
// to ensure that only the items below a given level are compressed,
|
|
389
|
+
// because `rebased` relies on a clean, untouched set of items in
|
|
390
|
+
// order to associate old items with rebased steps.
|
|
391
|
+
compress(upto = this.items.length) {
|
|
392
|
+
let remap = this.remapping(0, upto),
|
|
393
|
+
mapFrom = remap.maps.length;
|
|
394
|
+
let items = [],
|
|
395
|
+
events = 0;
|
|
396
|
+
this.items.forEach((item, i) => {
|
|
397
|
+
if (i >= upto) {
|
|
398
|
+
items.push(item);
|
|
399
|
+
if (item.selection) events++;
|
|
400
|
+
} else if (item.step) {
|
|
401
|
+
let step = item.step.map(remap.slice(mapFrom)),
|
|
402
|
+
map = step && step.getMap();
|
|
403
|
+
mapFrom--;
|
|
404
|
+
if (map) remap.appendMap(map, mapFrom);
|
|
405
|
+
if (step) {
|
|
406
|
+
let selection = item.selection && item.selection.map(remap.slice(mapFrom));
|
|
407
|
+
if (selection) events++;
|
|
408
|
+
let newItem = new Item(map.invert(), step, selection),
|
|
409
|
+
merged,
|
|
410
|
+
last = items.length - 1;
|
|
411
|
+
if (merged = items.length && items[last].merge(newItem)) items[last] = merged;else items.push(newItem);
|
|
412
|
+
}
|
|
413
|
+
} else if (item.map) {
|
|
414
|
+
mapFrom--;
|
|
415
|
+
}
|
|
416
|
+
}, this.items.length, 0);
|
|
417
|
+
return new Branch(RopeSequence.from(items.reverse()), events);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
Branch.empty = new Branch(RopeSequence.empty, 0);
|
|
421
|
+
function cutOffEvents(items, n) {
|
|
422
|
+
let cutPoint;
|
|
423
|
+
items.forEach((item, i) => {
|
|
424
|
+
if (item.selection && n-- == 0) {
|
|
425
|
+
cutPoint = i;
|
|
426
|
+
return false;
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
return items.slice(cutPoint);
|
|
430
|
+
}
|
|
431
|
+
class Item {
|
|
432
|
+
constructor(
|
|
433
|
+
// The (forward) step map for this item.
|
|
434
|
+
map,
|
|
435
|
+
// The inverted step
|
|
436
|
+
step,
|
|
437
|
+
// If this is non-null, this item is the start of a group, and
|
|
438
|
+
// this selection is the starting selection for the group (the one
|
|
439
|
+
// that was active before the first step was applied)
|
|
440
|
+
selection,
|
|
441
|
+
// If this item is the inverse of a previous mapping on the stack,
|
|
442
|
+
// this points at the inverse's offset
|
|
443
|
+
mirrorOffset, id) {
|
|
444
|
+
this.map = map;
|
|
445
|
+
this.step = step;
|
|
446
|
+
this.selection = selection;
|
|
447
|
+
this.mirrorOffset = mirrorOffset;
|
|
448
|
+
this.id = id !== null && id !== void 0 ? id : `${Date.now()}`;
|
|
449
|
+
}
|
|
450
|
+
merge(other) {
|
|
451
|
+
if (this.step && other.step && !other.selection) {
|
|
452
|
+
let step = other.step.merge(this.step);
|
|
453
|
+
if (step) return new Item(step.getMap().invert(), step, this.selection);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
// The value of the state field that tracks undo/redo history for that
|
|
458
|
+
// state. Will be stored in the plugin state when the history plugin
|
|
459
|
+
// is active.
|
|
460
|
+
class HistoryState {
|
|
461
|
+
constructor(done, undone, prevRanges, prevTime, prevComposition) {
|
|
462
|
+
this.done = done;
|
|
463
|
+
this.undone = undone;
|
|
464
|
+
this.prevRanges = prevRanges;
|
|
465
|
+
this.prevTime = prevTime;
|
|
466
|
+
this.prevComposition = prevComposition;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
const DEPTH_OVERFLOW = 20;
|
|
470
|
+
// Record a transformation in undo history.
|
|
471
|
+
function applyTransaction(history, state, tr, options) {
|
|
472
|
+
let historyTr = tr.getMeta(historyKey),
|
|
473
|
+
rebased;
|
|
474
|
+
if (historyTr) return historyTr.historyState;
|
|
475
|
+
if (tr.getMeta(closeHistoryKey)) history = new HistoryState(history.done, history.undone, null, 0, -1);
|
|
476
|
+
let appended = tr.getMeta("appendedTransaction");
|
|
477
|
+
if (tr.steps.length == 0) {
|
|
478
|
+
return history;
|
|
479
|
+
} else if (appended && appended.getMeta(historyKey)) {
|
|
480
|
+
if (appended.getMeta(historyKey).redo) return new HistoryState(history.done.addTransform(tr, undefined, options, mustPreserveItems(state)), history.undone, rangesFor(tr.mapping.maps), history.prevTime, history.prevComposition);else return new HistoryState(history.done, history.undone.addTransform(tr, undefined, options, mustPreserveItems(state)), null, history.prevTime, history.prevComposition);
|
|
481
|
+
} else if (tr.getMeta("addToHistory") !== false && !(appended && appended.getMeta("addToHistory") === false)) {
|
|
482
|
+
// Group transforms that occur in quick succession into one event.
|
|
483
|
+
let composition = tr.getMeta("composition");
|
|
484
|
+
let newGroup = history.prevTime == 0 || !appended && history.prevComposition != composition && (history.prevTime < (tr.time || 0) - options.newGroupDelay || !isAdjacentTo(tr, history.prevRanges));
|
|
485
|
+
let prevRanges = appended ? mapRanges(history.prevRanges, tr.mapping) : rangesFor(tr.mapping.maps);
|
|
486
|
+
return new HistoryState(history.done.addTransform(tr, newGroup ? state.selection.getBookmark() : undefined, options, mustPreserveItems(state)), Branch.empty, prevRanges, tr.time, composition == null ? history.prevComposition : composition);
|
|
487
|
+
} else if (rebased = tr.getMeta("rebased")) {
|
|
488
|
+
// Used by the collab module to tell the history that some of its
|
|
489
|
+
// content has been rebased.
|
|
490
|
+
return new HistoryState(history.done.rebased(tr, rebased), history.undone.rebased(tr, rebased), mapRanges(history.prevRanges, tr.mapping), history.prevTime, history.prevComposition);
|
|
491
|
+
} else {
|
|
492
|
+
return new HistoryState(history.done.addMaps(tr.mapping.maps), history.undone.addMaps(tr.mapping.maps), mapRanges(history.prevRanges, tr.mapping), history.prevTime, history.prevComposition);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
function isAdjacentTo(transform, prevRanges) {
|
|
496
|
+
if (!prevRanges) return false;
|
|
497
|
+
if (!transform.docChanged) return true;
|
|
498
|
+
let adjacent = false;
|
|
499
|
+
transform.mapping.maps[0].forEach((start, end) => {
|
|
500
|
+
for (let i = 0; i < prevRanges.length; i += 2) if (start <= prevRanges[i + 1] && end >= prevRanges[i]) adjacent = true;
|
|
501
|
+
});
|
|
502
|
+
return adjacent;
|
|
503
|
+
}
|
|
504
|
+
function rangesFor(maps) {
|
|
505
|
+
let result = [];
|
|
506
|
+
for (let i = maps.length - 1; i >= 0 && result.length == 0; i--) maps[i].forEach((_from, _to, from, to) => result.push(from, to));
|
|
507
|
+
return result;
|
|
508
|
+
}
|
|
509
|
+
function mapRanges(ranges, mapping) {
|
|
510
|
+
if (!ranges) return null;
|
|
511
|
+
let result = [];
|
|
512
|
+
for (let i = 0; i < ranges.length; i += 2) {
|
|
513
|
+
let from = mapping.map(ranges[i], 1),
|
|
514
|
+
to = mapping.map(ranges[i + 1], -1);
|
|
515
|
+
if (from <= to) result.push(from, to);
|
|
516
|
+
}
|
|
517
|
+
return result;
|
|
518
|
+
}
|
|
519
|
+
// Apply the latest event from one branch to the document and shift the event
|
|
520
|
+
// onto the other branch.
|
|
521
|
+
function histTransaction(history, state, redo) {
|
|
522
|
+
let preserveItems = mustPreserveItems(state);
|
|
523
|
+
let histOptions = historyKey.get(state).spec.config;
|
|
524
|
+
let pop = (redo ? history.undone : history.done).popEvent(state, preserveItems);
|
|
525
|
+
if (!pop) return null;
|
|
526
|
+
let selection = pop.selection.resolve(pop.transform.doc);
|
|
527
|
+
let added = (redo ? history.done : history.undone).addTransform(pop.transform, state.selection.getBookmark(), histOptions, preserveItems, pop.itemId);
|
|
528
|
+
let newHist = new HistoryState(redo ? added : pop.remaining, redo ? pop.remaining : added, null, 0, -1);
|
|
529
|
+
return pop.transform.setSelection(selection).setMeta(historyKey, {
|
|
530
|
+
redo,
|
|
531
|
+
historyState: newHist
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
let cachedPreserveItems = false,
|
|
535
|
+
cachedPreserveItemsPlugins = null;
|
|
536
|
+
// Check whether any plugin in the given state has a
|
|
537
|
+
// `historyPreserveItems` property in its spec, in which case we must
|
|
538
|
+
// preserve steps exactly as they came in, so that they can be
|
|
539
|
+
// rebased.
|
|
540
|
+
function mustPreserveItems(state) {
|
|
541
|
+
let plugins = state.plugins;
|
|
542
|
+
if (cachedPreserveItemsPlugins != plugins) {
|
|
543
|
+
cachedPreserveItems = false;
|
|
544
|
+
cachedPreserveItemsPlugins = plugins;
|
|
545
|
+
for (let i = 0; i < plugins.length; i++) if (plugins[i].spec.historyPreserveItems) {
|
|
546
|
+
cachedPreserveItems = true;
|
|
547
|
+
break;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
return cachedPreserveItems;
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
Set a flag on the given transaction that will prevent further steps
|
|
554
|
+
from being appended to an existing history event (so that they
|
|
555
|
+
require a separate undo command to undo).
|
|
556
|
+
*/
|
|
557
|
+
function closeHistory(tr) {
|
|
558
|
+
return tr.setMeta(closeHistoryKey, true);
|
|
559
|
+
}
|
|
560
|
+
const historyKey = new PluginKey("history");
|
|
561
|
+
const closeHistoryKey = new PluginKey("closeHistory");
|
|
562
|
+
/**
|
|
563
|
+
Returns a plugin that enables the undo history for an editor. The
|
|
564
|
+
plugin will track undo and redo stacks, which can be used with the
|
|
565
|
+
[`undo`](https://prosemirror.net/docs/ref/#history.undo) and [`redo`](https://prosemirror.net/docs/ref/#history.redo) commands.
|
|
566
|
+
|
|
567
|
+
You can set an `"addToHistory"` [metadata
|
|
568
|
+
property](https://prosemirror.net/docs/ref/#state.Transaction.setMeta) of `false` on a transaction
|
|
569
|
+
to prevent it from being rolled back by undo.
|
|
570
|
+
*/
|
|
571
|
+
function history(config = {}) {
|
|
572
|
+
config = {
|
|
573
|
+
depth: config.depth || 100,
|
|
574
|
+
newGroupDelay: config.newGroupDelay || 500
|
|
575
|
+
};
|
|
576
|
+
return new Plugin({
|
|
577
|
+
key: historyKey,
|
|
578
|
+
state: {
|
|
579
|
+
init() {
|
|
580
|
+
return new HistoryState(Branch.empty, Branch.empty, null, 0, -1);
|
|
581
|
+
},
|
|
582
|
+
apply(tr, hist, state) {
|
|
583
|
+
return applyTransaction(hist, state, tr, config);
|
|
584
|
+
}
|
|
585
|
+
},
|
|
586
|
+
config,
|
|
587
|
+
props: {
|
|
588
|
+
handleDOMEvents: {
|
|
589
|
+
beforeinput(view, e) {
|
|
590
|
+
let inputType = e.inputType;
|
|
591
|
+
let command = inputType == "historyUndo" ? undo : inputType == "historyRedo" ? redo : null;
|
|
592
|
+
if (!command || !view.editable) return false;
|
|
593
|
+
e.preventDefault();
|
|
594
|
+
return command(view.state, view.dispatch);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
});
|
|
599
|
+
}
|
|
600
|
+
function buildCommand(redo, scroll) {
|
|
601
|
+
return (state, dispatch) => {
|
|
602
|
+
let hist = historyKey.getState(state);
|
|
603
|
+
if (!hist || (redo ? hist.undone : hist.done).eventCount == 0) return false;
|
|
604
|
+
if (dispatch) {
|
|
605
|
+
let tr = histTransaction(hist, state, redo);
|
|
606
|
+
if (tr) dispatch(scroll ? tr.scrollIntoView() : tr);
|
|
607
|
+
}
|
|
608
|
+
return true;
|
|
609
|
+
};
|
|
610
|
+
}
|
|
611
|
+
/**
|
|
612
|
+
A command function that undoes the last change, if any.
|
|
613
|
+
*/
|
|
614
|
+
const undo = buildCommand(false, true);
|
|
615
|
+
/**
|
|
616
|
+
A command function that redoes the last undone change, if any.
|
|
617
|
+
*/
|
|
618
|
+
const redo = buildCommand(true, true);
|
|
619
|
+
/**
|
|
620
|
+
A command function that undoes the last change. Don't scroll the
|
|
621
|
+
selection into view.
|
|
622
|
+
*/
|
|
623
|
+
const undoNoScroll = buildCommand(false, false);
|
|
624
|
+
/**
|
|
625
|
+
A command function that redoes the last undone change. Don't
|
|
626
|
+
scroll the selection into view.
|
|
627
|
+
*/
|
|
628
|
+
const redoNoScroll = buildCommand(true, false);
|
|
629
|
+
/**
|
|
630
|
+
The amount of undoable events available in a given state.
|
|
631
|
+
*/
|
|
632
|
+
function undoDepth(state) {
|
|
633
|
+
let hist = historyKey.getState(state);
|
|
634
|
+
return hist ? hist.done.eventCount : 0;
|
|
635
|
+
}
|
|
636
|
+
/**
|
|
637
|
+
The amount of redoable events available in a given editor state.
|
|
638
|
+
*/
|
|
639
|
+
function redoDepth(state) {
|
|
640
|
+
let hist = historyKey.getState(state);
|
|
641
|
+
return hist ? hist.undone.eventCount : 0;
|
|
642
|
+
}
|
|
643
|
+
/**
|
|
644
|
+
Returns true if the given transaction was generated by the history
|
|
645
|
+
plugin.
|
|
646
|
+
*/
|
|
647
|
+
function isHistoryTransaction(tr) {
|
|
648
|
+
return tr.getMeta(historyKey) != null;
|
|
649
|
+
}
|
|
650
|
+
/**
|
|
651
|
+
Returns the unique ID of the current history for a given editor state.
|
|
652
|
+
This can for example be used to compare against a saved state, to
|
|
653
|
+
determine if there are changes since then.
|
|
654
|
+
*/
|
|
655
|
+
function getHistoryStateId(state) {
|
|
656
|
+
var _a;
|
|
657
|
+
let hist = historyKey.getState(state);
|
|
658
|
+
if (!hist || hist.done.eventCount === 0) return;
|
|
659
|
+
let items = hist.done.items;
|
|
660
|
+
return (_a = items.get(items.length - 1)) === null || _a === void 0 ? void 0 : _a.id;
|
|
661
|
+
}
|
|
662
|
+
/**
|
|
663
|
+
Whether the unique IDs of the history for the given editor state matches
|
|
664
|
+
the passed ID.
|
|
665
|
+
*/
|
|
666
|
+
function matchesTaggedHistory(state, id) {
|
|
667
|
+
return getHistoryStateId(state) === id;
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
export { redoDepth as a, redoNoScroll as b, closeHistory as c, undoDepth as d, undoNoScroll as e, getHistoryStateId as g, history as h, isHistoryTransaction as i, matchesTaggedHistory as m, redo as r, undo as u };
|
|
671
|
+
//# sourceMappingURL=index-CxRqg5Kr.js.map
|