@rme-sdk/extension-diff 1.1.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/LICENSE +21 -0
- package/dist/_tsup-dts-rollup.d.cts +231 -0
- package/dist/_tsup-dts-rollup.d.ts +231 -0
- package/dist/rme-sdk-extension-diff.cjs +559 -0
- package/dist/rme-sdk-extension-diff.d.cts +4 -0
- package/dist/rme-sdk-extension-diff.d.ts +4 -0
- package/dist/rme-sdk-extension-diff.js +548 -0
- package/package.json +57 -0
|
@@ -0,0 +1,559 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
|
+
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
10
|
+
var __typeError = (msg) => {
|
|
11
|
+
throw TypeError(msg);
|
|
12
|
+
};
|
|
13
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
14
|
+
var __spreadValues = (a, b) => {
|
|
15
|
+
for (var prop in b || (b = {}))
|
|
16
|
+
if (__hasOwnProp.call(b, prop))
|
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
|
18
|
+
if (__getOwnPropSymbols)
|
|
19
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
20
|
+
if (__propIsEnum.call(b, prop))
|
|
21
|
+
__defNormalProp(a, prop, b[prop]);
|
|
22
|
+
}
|
|
23
|
+
return a;
|
|
24
|
+
};
|
|
25
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
26
|
+
var __export = (target, all) => {
|
|
27
|
+
for (var name in all)
|
|
28
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
29
|
+
};
|
|
30
|
+
var __copyProps = (to, from, except, desc) => {
|
|
31
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
32
|
+
for (let key of __getOwnPropNames(from))
|
|
33
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
34
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
35
|
+
}
|
|
36
|
+
return to;
|
|
37
|
+
};
|
|
38
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
39
|
+
var __decoratorStart = (base) => {
|
|
40
|
+
var _a2;
|
|
41
|
+
return [, , , __create((_a2 = base == null ? void 0 : base[__knownSymbol("metadata")]) != null ? _a2 : null)];
|
|
42
|
+
};
|
|
43
|
+
var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
|
|
44
|
+
var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
|
|
45
|
+
var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
|
|
46
|
+
var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
|
|
47
|
+
var __runInitializers = (array, flags, self, value) => {
|
|
48
|
+
for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) flags & 1 ? fns[i].call(self) : value = fns[i].call(self, value);
|
|
49
|
+
return value;
|
|
50
|
+
};
|
|
51
|
+
var __decorateElement = (array, flags, name, decorators, target, extra) => {
|
|
52
|
+
var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
|
|
53
|
+
var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
|
|
54
|
+
var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
|
|
55
|
+
var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : { get [name]() {
|
|
56
|
+
return __privateGet(this, extra);
|
|
57
|
+
}, set [name](x) {
|
|
58
|
+
return __privateSet(this, extra, x);
|
|
59
|
+
} }, name));
|
|
60
|
+
k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name);
|
|
61
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
62
|
+
ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
|
|
63
|
+
if (k) {
|
|
64
|
+
ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn(target, x) : (x) => name in x };
|
|
65
|
+
if (k ^ 3) access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name];
|
|
66
|
+
if (k > 2) access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
|
|
67
|
+
}
|
|
68
|
+
it = (0, decorators[i])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? void 0 : { get: desc.get, set: desc.set } : target, ctx), done._ = 1;
|
|
69
|
+
if (k ^ 4 || it === void 0) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
|
|
70
|
+
else if (typeof it !== "object" || it === null) __typeError("Object expected");
|
|
71
|
+
else __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
|
|
72
|
+
}
|
|
73
|
+
return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
|
|
74
|
+
};
|
|
75
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
76
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
77
|
+
var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
|
|
78
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
79
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
80
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
81
|
+
|
|
82
|
+
// src/index.ts
|
|
83
|
+
var src_exports = {};
|
|
84
|
+
__export(src_exports, {
|
|
85
|
+
DiffExtension: () => DiffExtension
|
|
86
|
+
});
|
|
87
|
+
module.exports = __toCommonJS(src_exports);
|
|
88
|
+
|
|
89
|
+
// src/diff-extension.ts
|
|
90
|
+
var import_core2 = require("@rme-sdk/core");
|
|
91
|
+
var import_transform = require("@rme-sdk/pm/transform");
|
|
92
|
+
var import_view = require("@rme-sdk/pm/view");
|
|
93
|
+
|
|
94
|
+
// src/diff-utils.ts
|
|
95
|
+
var import_core = require("@rme-sdk/core");
|
|
96
|
+
var Span = class {
|
|
97
|
+
constructor(props) {
|
|
98
|
+
__publicField(this, "from");
|
|
99
|
+
__publicField(this, "to");
|
|
100
|
+
__publicField(this, "commit");
|
|
101
|
+
const { from, to, commit } = props;
|
|
102
|
+
this.from = from;
|
|
103
|
+
this.to = to;
|
|
104
|
+
this.commit = commit;
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
var Commit = class {
|
|
108
|
+
constructor(props) {
|
|
109
|
+
__publicField(this, "message");
|
|
110
|
+
__publicField(this, "time");
|
|
111
|
+
__publicField(this, "steps");
|
|
112
|
+
__publicField(this, "maps");
|
|
113
|
+
__publicField(this, "hidden");
|
|
114
|
+
const { message, time, steps, maps, hidden } = props;
|
|
115
|
+
this.message = message;
|
|
116
|
+
this.time = time;
|
|
117
|
+
this.steps = steps;
|
|
118
|
+
this.maps = maps;
|
|
119
|
+
this.hidden = hidden;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
var TrackState = class _TrackState {
|
|
123
|
+
constructor(props) {
|
|
124
|
+
__publicField(this, "blameMap");
|
|
125
|
+
__publicField(this, "commits");
|
|
126
|
+
__publicField(this, "uncommittedSteps");
|
|
127
|
+
__publicField(this, "uncommittedMaps");
|
|
128
|
+
const { blameMap, commits, uncommittedSteps, uncommittedMaps } = props;
|
|
129
|
+
this.blameMap = blameMap;
|
|
130
|
+
this.commits = commits;
|
|
131
|
+
this.uncommittedSteps = uncommittedSteps;
|
|
132
|
+
this.uncommittedMaps = uncommittedMaps;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Apply a transform to this state.
|
|
136
|
+
*/
|
|
137
|
+
applyTransform(transform) {
|
|
138
|
+
const inverted = transform.steps.map(
|
|
139
|
+
(step, index) => step.invert((0, import_core.assertGet)(transform.docs, index))
|
|
140
|
+
);
|
|
141
|
+
const newBlame = updateBlameMap({ map: this.blameMap, transform, id: this.commits.length });
|
|
142
|
+
return new _TrackState({
|
|
143
|
+
blameMap: newBlame,
|
|
144
|
+
commits: this.commits,
|
|
145
|
+
uncommittedSteps: [...this.uncommittedSteps, ...inverted],
|
|
146
|
+
uncommittedMaps: [...this.uncommittedMaps, ...transform.mapping.maps]
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* When a transaction is marked as a commit, this is used to put any
|
|
151
|
+
* uncommitted steps into a new commit.
|
|
152
|
+
*/
|
|
153
|
+
applyCommit(message, time) {
|
|
154
|
+
if ((0, import_core.isEmptyArray)(this.uncommittedSteps)) {
|
|
155
|
+
return this;
|
|
156
|
+
}
|
|
157
|
+
const commit = new Commit({
|
|
158
|
+
message,
|
|
159
|
+
time,
|
|
160
|
+
steps: this.uncommittedSteps,
|
|
161
|
+
maps: this.uncommittedMaps
|
|
162
|
+
});
|
|
163
|
+
return new _TrackState({
|
|
164
|
+
blameMap: this.blameMap,
|
|
165
|
+
commits: [...this.commits, commit],
|
|
166
|
+
uncommittedSteps: [],
|
|
167
|
+
uncommittedMaps: []
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
function updateBlameMap({ map, transform, id }) {
|
|
172
|
+
const result = [];
|
|
173
|
+
const mapping = transform.mapping;
|
|
174
|
+
for (const span of map) {
|
|
175
|
+
const from = mapping.map(span.from, 1);
|
|
176
|
+
const to = mapping.map(span.to, -1);
|
|
177
|
+
if (from < to) {
|
|
178
|
+
result.push(new Span({ from, to, commit: span.commit }));
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
for (const [index, map2] of mapping.maps.entries()) {
|
|
182
|
+
const after = mapping.slice(index + 1);
|
|
183
|
+
map2.forEach((_s, _e, start, end) => {
|
|
184
|
+
insertIntoBlameMap({
|
|
185
|
+
map: result,
|
|
186
|
+
from: after.map(start, 1),
|
|
187
|
+
to: after.map(end, -1),
|
|
188
|
+
commit: id
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
return result;
|
|
193
|
+
}
|
|
194
|
+
function insertIntoBlameMap(props) {
|
|
195
|
+
let { from, to, map, commit } = props;
|
|
196
|
+
if (from >= to) {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
let pos = 0;
|
|
200
|
+
let next;
|
|
201
|
+
for (; pos < map.length; pos++) {
|
|
202
|
+
next = (0, import_core.assertGet)(map, pos);
|
|
203
|
+
if (next.commit === commit) {
|
|
204
|
+
if (next.to >= from) {
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
if (next.to <= from) {
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
if (next.from < from) {
|
|
213
|
+
const left = new Span({ from: next.from, to: from, commit: next.commit });
|
|
214
|
+
if (next.to > to) {
|
|
215
|
+
map.splice(pos++, 0, left);
|
|
216
|
+
} else {
|
|
217
|
+
map[pos++] = left;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
while (next = map[pos]) {
|
|
223
|
+
if (next.commit === commit) {
|
|
224
|
+
if (next.from > to) {
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
227
|
+
from = Math.min(from, next.from);
|
|
228
|
+
to = Math.max(to, next.to);
|
|
229
|
+
map.splice(pos, 1);
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
if (next.from >= to) {
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
if (next.to > to) {
|
|
236
|
+
map[pos] = new Span({ from: to, to: next.to, commit: next.commit });
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
map.splice(pos, 1);
|
|
240
|
+
}
|
|
241
|
+
map.splice(pos, 0, new Span({ from, to, commit }));
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// src/diff-extension.ts
|
|
245
|
+
var _getCommit_dec, _getCommits_dec, _revertCommit_dec, _commitChange_dec, _removeHighlightedCommit_dec, _highlightCommit_dec, _a, _DiffExtension_decorators, _init;
|
|
246
|
+
_DiffExtension_decorators = [(0, import_core2.extension)({
|
|
247
|
+
defaultOptions: {
|
|
248
|
+
blameMarkerClass: "blame-marker",
|
|
249
|
+
revertMessage: (message) => "Revert: '".concat(message, "'")
|
|
250
|
+
},
|
|
251
|
+
staticKeys: ["blameMarkerClass"],
|
|
252
|
+
handlerKeys: ["onMouseOverCommit", "onMouseLeaveCommit", "onSelectCommits", "onDeselectCommits"]
|
|
253
|
+
})];
|
|
254
|
+
var DiffExtension = class extends (_a = import_core2.PlainExtension, _highlightCommit_dec = [(0, import_core2.command)()], _removeHighlightedCommit_dec = [(0, import_core2.command)()], _commitChange_dec = [(0, import_core2.command)()], _revertCommit_dec = [(0, import_core2.command)()], _getCommits_dec = [(0, import_core2.helper)()], _getCommit_dec = [(0, import_core2.helper)()], _a) {
|
|
255
|
+
constructor() {
|
|
256
|
+
super(...arguments);
|
|
257
|
+
__runInitializers(_init, 5, this);
|
|
258
|
+
__publicField(this, "hovered");
|
|
259
|
+
__publicField(this, "selections");
|
|
260
|
+
}
|
|
261
|
+
get name() {
|
|
262
|
+
return "diff";
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Create the custom change tracking plugin.
|
|
266
|
+
*
|
|
267
|
+
* This has been adapted from the prosemirror website demo.
|
|
268
|
+
* https://github.com/ProseMirror/website/blob/master/example/track/index.js
|
|
269
|
+
*/
|
|
270
|
+
createPlugin() {
|
|
271
|
+
return {
|
|
272
|
+
state: {
|
|
273
|
+
init: (_, state) => this.createInitialState(state),
|
|
274
|
+
apply: (tr, pluginState, _, state) => {
|
|
275
|
+
const newState = this.applyStateUpdates(tr, pluginState, state);
|
|
276
|
+
this.handleSelection(tr, newState);
|
|
277
|
+
return newState;
|
|
278
|
+
}
|
|
279
|
+
},
|
|
280
|
+
props: {
|
|
281
|
+
decorations: (state) => this.getPluginState(state).decorations,
|
|
282
|
+
handleDOMEvents: {
|
|
283
|
+
mouseover: (view, event) => this.handlerMouseOver(view, event),
|
|
284
|
+
mouseleave: (view, event) => this.handleMouseLeave(view, event)
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
highlightCommit(commit) {
|
|
290
|
+
return (props) => {
|
|
291
|
+
const { tr, dispatch } = props;
|
|
292
|
+
if ((0, import_core2.isString)(commit)) {
|
|
293
|
+
commit = this.getIndexByName(commit);
|
|
294
|
+
}
|
|
295
|
+
if (!(0, import_core2.isNumber)(commit)) {
|
|
296
|
+
commit = this.getCommitId(commit);
|
|
297
|
+
}
|
|
298
|
+
if (dispatch) {
|
|
299
|
+
dispatch(this.setMeta(tr, { add: commit }));
|
|
300
|
+
}
|
|
301
|
+
return true;
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
removeHighlightedCommit(commit) {
|
|
305
|
+
return (props) => {
|
|
306
|
+
const { tr, dispatch } = props;
|
|
307
|
+
if ((0, import_core2.isString)(commit)) {
|
|
308
|
+
commit = this.getIndexByName(commit);
|
|
309
|
+
}
|
|
310
|
+
if (!(0, import_core2.isNumber)(commit)) {
|
|
311
|
+
commit = this.getCommitId(commit);
|
|
312
|
+
}
|
|
313
|
+
if (dispatch) {
|
|
314
|
+
dispatch(this.setMeta(tr, { clear: commit }));
|
|
315
|
+
}
|
|
316
|
+
return true;
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
commitChange(message) {
|
|
320
|
+
return (props) => {
|
|
321
|
+
const { tr, dispatch } = props;
|
|
322
|
+
if (dispatch) {
|
|
323
|
+
dispatch(this.setMeta(tr, { message }));
|
|
324
|
+
}
|
|
325
|
+
return true;
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
revertCommit(commit) {
|
|
329
|
+
return (props) => {
|
|
330
|
+
var _a2;
|
|
331
|
+
const { state, tr, dispatch } = props;
|
|
332
|
+
if (!commit) {
|
|
333
|
+
commit = this.getCommit("last");
|
|
334
|
+
}
|
|
335
|
+
const { tracked } = this.getPluginState(state);
|
|
336
|
+
const index = tracked.commits.indexOf(commit);
|
|
337
|
+
if (index === -1) {
|
|
338
|
+
return false;
|
|
339
|
+
}
|
|
340
|
+
if (!(0, import_core2.isEmptyArray)(tracked.uncommittedSteps)) {
|
|
341
|
+
return false;
|
|
342
|
+
}
|
|
343
|
+
if (!dispatch) {
|
|
344
|
+
return true;
|
|
345
|
+
}
|
|
346
|
+
const commitMaps = [];
|
|
347
|
+
for (const commit2 of tracked.commits.slice(index)) {
|
|
348
|
+
commitMaps.push(...commit2.maps);
|
|
349
|
+
}
|
|
350
|
+
const remap = new import_transform.Mapping(commitMaps);
|
|
351
|
+
for (let index2 = commit.steps.length - 1; index2 >= 0; index2--) {
|
|
352
|
+
const remapped = (_a2 = commit.steps[index2]) == null ? void 0 : _a2.map(remap.slice(index2 + 1));
|
|
353
|
+
if (!remapped) {
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
356
|
+
const result = tr.maybeStep(remapped);
|
|
357
|
+
if (result.doc) {
|
|
358
|
+
remap.appendMap(remapped.getMap(), index2);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
if (tr.docChanged) {
|
|
362
|
+
this.setMeta(tr, { message: this.options.revertMessage(commit.message) });
|
|
363
|
+
dispatch(tr);
|
|
364
|
+
}
|
|
365
|
+
return true;
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
getCommits() {
|
|
369
|
+
return this.getPluginState().tracked.commits;
|
|
370
|
+
}
|
|
371
|
+
getIndexByName(name) {
|
|
372
|
+
const length = this.getPluginState().tracked.commits.length;
|
|
373
|
+
switch (name) {
|
|
374
|
+
case "first":
|
|
375
|
+
return 0;
|
|
376
|
+
default:
|
|
377
|
+
return length - 1;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
getCommit(id) {
|
|
381
|
+
const commits = this.getPluginState().tracked.commits;
|
|
382
|
+
const commit = (0, import_core2.isString)(id) ? commits[this.getIndexByName(id)] : commits[id];
|
|
383
|
+
(0, import_core2.invariant)(commit, {});
|
|
384
|
+
return commit;
|
|
385
|
+
}
|
|
386
|
+
getCommitId(commit) {
|
|
387
|
+
const { tracked } = this.getPluginState();
|
|
388
|
+
return tracked.commits.indexOf(commit);
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Get the meta data for this custom plugin.
|
|
392
|
+
*/
|
|
393
|
+
getMeta(tr) {
|
|
394
|
+
var _a2;
|
|
395
|
+
return (_a2 = tr.getMeta(this.pluginKey)) != null ? _a2 : {};
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Set the meta data for the plugin.
|
|
399
|
+
*/
|
|
400
|
+
setMeta(tr, meta) {
|
|
401
|
+
tr.setMeta(this.pluginKey, __spreadValues(__spreadValues({}, this.getMeta(tr)), meta));
|
|
402
|
+
return tr;
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Calls the selection handlers when the selection changes the number of
|
|
406
|
+
* commit spans covered.
|
|
407
|
+
*/
|
|
408
|
+
handleSelection(tr, pluginState) {
|
|
409
|
+
if (!(0, import_core2.hasTransactionChanged)(tr)) {
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
const { from, to } = tr.selection;
|
|
413
|
+
const { blameMap, commits } = pluginState.tracked;
|
|
414
|
+
const selections = [];
|
|
415
|
+
for (const map of blameMap) {
|
|
416
|
+
const selectionIncludesSpan = map.from <= from && map.to >= from || map.from <= to && map.to >= to;
|
|
417
|
+
if (!selectionIncludesSpan || !(0, import_core2.isNumber)(map.commit) || map.commit >= commits.length) {
|
|
418
|
+
continue;
|
|
419
|
+
}
|
|
420
|
+
selections.push({ commit: this.getCommit(map.commit), from: map.from, to: map.to });
|
|
421
|
+
}
|
|
422
|
+
const selectionHasCommit = selections.length > 0;
|
|
423
|
+
if (selectionHasCommit && !(0, import_core2.isEqual)(selections, this.selections)) {
|
|
424
|
+
this.options.onSelectCommits(selections, this.selections);
|
|
425
|
+
this.selections = selections;
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
if (this.selections) {
|
|
429
|
+
this.options.onDeselectCommits(this.selections);
|
|
430
|
+
this.selections = void 0;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Transform the view and event into a commit and span.
|
|
435
|
+
*/
|
|
436
|
+
getHandlerPropsFromEvent(view, event) {
|
|
437
|
+
if (!(0, import_core2.isDomNode)(event.target)) {
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
const pos = view.posAtDOM(event.target, 0);
|
|
441
|
+
const { tracked } = this.getPluginState();
|
|
442
|
+
const span = tracked.blameMap.find((map) => map.from <= pos && map.to >= pos);
|
|
443
|
+
if (!span || !(0, import_core2.isNumber)(span.commit)) {
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
return { commit: this.getCommit(span.commit), from: span.from, to: span.to };
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Capture the mouseover event and trigger the `onMouseOverCommit` handler
|
|
450
|
+
* when it is captured.
|
|
451
|
+
*/
|
|
452
|
+
handlerMouseOver(view, event) {
|
|
453
|
+
const props = this.getHandlerPropsFromEvent(view, event);
|
|
454
|
+
if (props) {
|
|
455
|
+
this.hovered = props;
|
|
456
|
+
this.options.onMouseOverCommit(props);
|
|
457
|
+
}
|
|
458
|
+
return false;
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* Capture the mouseleave event and trigger the `onMouseLeaveCommit` handler.
|
|
462
|
+
*/
|
|
463
|
+
handleMouseLeave(view, event) {
|
|
464
|
+
if (!this.hovered) {
|
|
465
|
+
return false;
|
|
466
|
+
}
|
|
467
|
+
const commit = this.getHandlerPropsFromEvent(view, event);
|
|
468
|
+
if (commit) {
|
|
469
|
+
this.hovered = void 0;
|
|
470
|
+
this.options.onMouseLeaveCommit(commit);
|
|
471
|
+
}
|
|
472
|
+
return false;
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* Create the initial plugin state for the custom plugin.
|
|
476
|
+
*/
|
|
477
|
+
createInitialState(state) {
|
|
478
|
+
return {
|
|
479
|
+
tracked: new TrackState({
|
|
480
|
+
blameMap: [new Span({ from: 0, to: state.doc.content.size, commit: void 0 })],
|
|
481
|
+
commits: [],
|
|
482
|
+
uncommittedMaps: [],
|
|
483
|
+
uncommittedSteps: []
|
|
484
|
+
}),
|
|
485
|
+
decorations: import_view.DecorationSet.empty
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Apply state updates in response to document changes.
|
|
490
|
+
*/
|
|
491
|
+
applyStateUpdates(tr, pluginState, state) {
|
|
492
|
+
return __spreadValues(__spreadValues({}, this.updateTracked(tr, pluginState)), this.updateHighlights(tr, pluginState, state));
|
|
493
|
+
}
|
|
494
|
+
createDecorationSet(commits, pluginState, state) {
|
|
495
|
+
const { tracked } = pluginState;
|
|
496
|
+
const decorations = [];
|
|
497
|
+
for (const { commit, from, to } of tracked.blameMap) {
|
|
498
|
+
if (!(0, import_core2.isNumber)(commit) || !commits.includes(commit)) {
|
|
499
|
+
continue;
|
|
500
|
+
}
|
|
501
|
+
decorations.push(import_view.Decoration.inline(from, to, { class: this.options.blameMarkerClass }));
|
|
502
|
+
}
|
|
503
|
+
return import_view.DecorationSet.create(state.doc, decorations);
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* Apply updates to the highlight decorations.
|
|
507
|
+
*/
|
|
508
|
+
updateHighlights(tr, pluginState, state) {
|
|
509
|
+
var _a2;
|
|
510
|
+
const { add, clear } = this.getMeta(tr);
|
|
511
|
+
if ((0, import_core2.isNumber)(add) && pluginState.commits && !pluginState.commits.includes(add)) {
|
|
512
|
+
const commits = [...pluginState.commits, add];
|
|
513
|
+
const decorations = this.createDecorationSet(commits, pluginState, state);
|
|
514
|
+
return { decorations, commits };
|
|
515
|
+
}
|
|
516
|
+
if ((0, import_core2.isNumber)(clear) && pluginState.commits && pluginState.commits.includes(clear)) {
|
|
517
|
+
const commits = pluginState.commits.filter((commit) => commit !== clear);
|
|
518
|
+
const decorations = this.createDecorationSet(commits, pluginState, state);
|
|
519
|
+
return { decorations, commits };
|
|
520
|
+
}
|
|
521
|
+
if (tr.docChanged && !(0, import_core2.isEmptyArray)(pluginState.commits)) {
|
|
522
|
+
return {
|
|
523
|
+
decorations: pluginState.decorations.map(tr.mapping, tr.doc),
|
|
524
|
+
commits: pluginState.commits
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
return { decorations: pluginState.decorations, commits: (_a2 = pluginState.commits) != null ? _a2 : [] };
|
|
528
|
+
}
|
|
529
|
+
/**
|
|
530
|
+
* Apply updates for the commit tracker.
|
|
531
|
+
*
|
|
532
|
+
* Please note this isn't able to track marks and diffs. It can only
|
|
533
|
+
* track changes to content.
|
|
534
|
+
*/
|
|
535
|
+
updateTracked(tr, state) {
|
|
536
|
+
let { tracked } = state;
|
|
537
|
+
if (tr.docChanged) {
|
|
538
|
+
tracked = tracked.applyTransform(tr);
|
|
539
|
+
}
|
|
540
|
+
const { message } = this.getMeta(tr);
|
|
541
|
+
if (message) {
|
|
542
|
+
tracked = tracked.applyCommit(message, tr.time);
|
|
543
|
+
}
|
|
544
|
+
return { tracked };
|
|
545
|
+
}
|
|
546
|
+
};
|
|
547
|
+
_init = __decoratorStart(_a);
|
|
548
|
+
__decorateElement(_init, 1, "highlightCommit", _highlightCommit_dec, DiffExtension);
|
|
549
|
+
__decorateElement(_init, 1, "removeHighlightedCommit", _removeHighlightedCommit_dec, DiffExtension);
|
|
550
|
+
__decorateElement(_init, 1, "commitChange", _commitChange_dec, DiffExtension);
|
|
551
|
+
__decorateElement(_init, 1, "revertCommit", _revertCommit_dec, DiffExtension);
|
|
552
|
+
__decorateElement(_init, 1, "getCommits", _getCommits_dec, DiffExtension);
|
|
553
|
+
__decorateElement(_init, 1, "getCommit", _getCommit_dec, DiffExtension);
|
|
554
|
+
DiffExtension = __decorateElement(_init, 0, "DiffExtension", _DiffExtension_decorators, DiffExtension);
|
|
555
|
+
__runInitializers(_init, 1, DiffExtension);
|
|
556
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
557
|
+
0 && (module.exports = {
|
|
558
|
+
DiffExtension
|
|
559
|
+
});
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { DiffOptions_alias_1 as DiffOptions } from './_tsup-dts-rollup';
|
|
2
|
+
export { DiffPluginState_alias_1 as DiffPluginState } from './_tsup-dts-rollup';
|
|
3
|
+
export { HandlerProps_alias_1 as HandlerProps } from './_tsup-dts-rollup';
|
|
4
|
+
export { DiffExtension_alias_1 as DiffExtension } from './_tsup-dts-rollup';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { DiffOptions_alias_1 as DiffOptions } from './_tsup-dts-rollup';
|
|
2
|
+
export { DiffPluginState_alias_1 as DiffPluginState } from './_tsup-dts-rollup';
|
|
3
|
+
export { HandlerProps_alias_1 as HandlerProps } from './_tsup-dts-rollup';
|
|
4
|
+
export { DiffExtension_alias_1 as DiffExtension } from './_tsup-dts-rollup';
|