@git-diff-view/react 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.development.js +1107 -2413
- package/dist/cjs/index.development.js.map +1 -1
- package/dist/cjs/index.production.js +1084 -2403
- package/dist/cjs/index.production.js.map +1 -1
- package/dist/esm/index.mjs +1059 -2387
- package/dist/esm/index.mjs.map +1 -1
- package/dist/types/components/DiffSplitHunkLineNormal.d.ts.map +1 -1
- package/dist/types/components/DiffSplitHunkLineWrap.d.ts.map +1 -1
- package/dist/types/components/DiffUnifiedHunkLine.d.ts.map +1 -1
- package/dist/types/components/DiffView.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.withStyle.d.ts +1 -0
- package/dist/types/index.withStyle.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -25,1446 +25,114 @@ function _interopNamespaceDefault(e) {
|
|
|
25
25
|
|
|
26
26
|
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
28
|
+
/******************************************************************************
|
|
29
|
+
Copyright (c) Microsoft Corporation.
|
|
30
|
+
|
|
31
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
32
|
+
purpose with or without fee is hereby granted.
|
|
33
|
+
|
|
34
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
35
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
36
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
37
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
38
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
39
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
40
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
41
|
+
***************************************************************************** */
|
|
42
|
+
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
function __rest(s, e) {
|
|
46
|
+
var t = {};
|
|
47
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
48
|
+
t[p] = s[p];
|
|
49
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
50
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
51
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
52
|
+
t[p[i]] = s[p[i]];
|
|
53
|
+
}
|
|
54
|
+
return t;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function __classPrivateFieldGet$1(receiver, state, kind, f) {
|
|
58
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
59
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
60
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function __classPrivateFieldSet$1(receiver, state, value, kind, f) {
|
|
64
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
65
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
66
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
67
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
71
|
+
var e = new Error(message);
|
|
72
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
44
73
|
};
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
'provided for use by LRUCache.fetch(), but it should not be ' +
|
|
88
|
-
'relied upon in other contexts (eg, passing it to other APIs that ' +
|
|
89
|
-
'use AbortController/AbortSignal might have undesirable effects). ' +
|
|
90
|
-
'You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.', 'NO_ABORT_CONTROLLER', 'ENOTSUP', warnACPolyfill);
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
/* c8 ignore stop */
|
|
94
|
-
const shouldWarn = (code) => !warned.has(code);
|
|
95
|
-
const isPosInt = (n) => n && n === Math.floor(n) && n > 0 && isFinite(n);
|
|
96
|
-
/* c8 ignore start */
|
|
97
|
-
// This is a little bit ridiculous, tbh.
|
|
98
|
-
// The maximum array length is 2^32-1 or thereabouts on most JS impls.
|
|
99
|
-
// And well before that point, you're caching the entire world, I mean,
|
|
100
|
-
// that's ~32GB of just integers for the next/prev links, plus whatever
|
|
101
|
-
// else to hold that many keys and values. Just filling the memory with
|
|
102
|
-
// zeroes at init time is brutal when you get that big.
|
|
103
|
-
// But why not be complete?
|
|
104
|
-
// Maybe in the future, these limits will have expanded.
|
|
105
|
-
const getUintArray = (max) => !isPosInt(max)
|
|
106
|
-
? null
|
|
107
|
-
: max <= Math.pow(2, 8)
|
|
108
|
-
? Uint8Array
|
|
109
|
-
: max <= Math.pow(2, 16)
|
|
110
|
-
? Uint16Array
|
|
111
|
-
: max <= Math.pow(2, 32)
|
|
112
|
-
? Uint32Array
|
|
113
|
-
: max <= Number.MAX_SAFE_INTEGER
|
|
114
|
-
? ZeroArray
|
|
115
|
-
: null;
|
|
116
|
-
/* c8 ignore stop */
|
|
117
|
-
class ZeroArray extends Array {
|
|
118
|
-
constructor(size) {
|
|
119
|
-
super(size);
|
|
120
|
-
this.fill(0);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
class Stack {
|
|
124
|
-
heap;
|
|
125
|
-
length;
|
|
126
|
-
// private constructor
|
|
127
|
-
static #constructing = false;
|
|
128
|
-
static create(max) {
|
|
129
|
-
const HeapCls = getUintArray(max);
|
|
130
|
-
if (!HeapCls)
|
|
131
|
-
return [];
|
|
132
|
-
Stack.#constructing = true;
|
|
133
|
-
const s = new Stack(max, HeapCls);
|
|
134
|
-
Stack.#constructing = false;
|
|
135
|
-
return s;
|
|
136
|
-
}
|
|
137
|
-
constructor(max, HeapCls) {
|
|
138
|
-
/* c8 ignore start */
|
|
139
|
-
if (!Stack.#constructing) {
|
|
140
|
-
throw new TypeError('instantiate Stack using Stack.create(n)');
|
|
141
|
-
}
|
|
142
|
-
/* c8 ignore stop */
|
|
143
|
-
this.heap = new HeapCls(max);
|
|
144
|
-
this.length = 0;
|
|
145
|
-
}
|
|
146
|
-
push(n) {
|
|
147
|
-
this.heap[this.length++] = n;
|
|
148
|
-
}
|
|
149
|
-
pop() {
|
|
150
|
-
return this.heap[--this.length];
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Default export, the thing you're using this module to get.
|
|
155
|
-
*
|
|
156
|
-
* All properties from the options object (with the exception of
|
|
157
|
-
* {@link OptionsBase.max} and {@link OptionsBase.maxSize}) are added as
|
|
158
|
-
* normal public members. (`max` and `maxBase` are read-only getters.)
|
|
159
|
-
* Changing any of these will alter the defaults for subsequent method calls,
|
|
160
|
-
* but is otherwise safe.
|
|
161
|
-
*/
|
|
162
|
-
class LRUCache {
|
|
163
|
-
// properties coming in from the options of these, only max and maxSize
|
|
164
|
-
// really *need* to be protected. The rest can be modified, as they just
|
|
165
|
-
// set defaults for various methods.
|
|
166
|
-
#max;
|
|
167
|
-
#maxSize;
|
|
168
|
-
#dispose;
|
|
169
|
-
#disposeAfter;
|
|
170
|
-
#fetchMethod;
|
|
171
|
-
/**
|
|
172
|
-
* {@link LRUCache.OptionsBase.ttl}
|
|
173
|
-
*/
|
|
174
|
-
ttl;
|
|
175
|
-
/**
|
|
176
|
-
* {@link LRUCache.OptionsBase.ttlResolution}
|
|
177
|
-
*/
|
|
178
|
-
ttlResolution;
|
|
179
|
-
/**
|
|
180
|
-
* {@link LRUCache.OptionsBase.ttlAutopurge}
|
|
181
|
-
*/
|
|
182
|
-
ttlAutopurge;
|
|
183
|
-
/**
|
|
184
|
-
* {@link LRUCache.OptionsBase.updateAgeOnGet}
|
|
185
|
-
*/
|
|
186
|
-
updateAgeOnGet;
|
|
187
|
-
/**
|
|
188
|
-
* {@link LRUCache.OptionsBase.updateAgeOnHas}
|
|
189
|
-
*/
|
|
190
|
-
updateAgeOnHas;
|
|
191
|
-
/**
|
|
192
|
-
* {@link LRUCache.OptionsBase.allowStale}
|
|
193
|
-
*/
|
|
194
|
-
allowStale;
|
|
195
|
-
/**
|
|
196
|
-
* {@link LRUCache.OptionsBase.noDisposeOnSet}
|
|
197
|
-
*/
|
|
198
|
-
noDisposeOnSet;
|
|
199
|
-
/**
|
|
200
|
-
* {@link LRUCache.OptionsBase.noUpdateTTL}
|
|
201
|
-
*/
|
|
202
|
-
noUpdateTTL;
|
|
203
|
-
/**
|
|
204
|
-
* {@link LRUCache.OptionsBase.maxEntrySize}
|
|
205
|
-
*/
|
|
206
|
-
maxEntrySize;
|
|
207
|
-
/**
|
|
208
|
-
* {@link LRUCache.OptionsBase.sizeCalculation}
|
|
209
|
-
*/
|
|
210
|
-
sizeCalculation;
|
|
211
|
-
/**
|
|
212
|
-
* {@link LRUCache.OptionsBase.noDeleteOnFetchRejection}
|
|
213
|
-
*/
|
|
214
|
-
noDeleteOnFetchRejection;
|
|
215
|
-
/**
|
|
216
|
-
* {@link LRUCache.OptionsBase.noDeleteOnStaleGet}
|
|
217
|
-
*/
|
|
218
|
-
noDeleteOnStaleGet;
|
|
219
|
-
/**
|
|
220
|
-
* {@link LRUCache.OptionsBase.allowStaleOnFetchAbort}
|
|
221
|
-
*/
|
|
222
|
-
allowStaleOnFetchAbort;
|
|
223
|
-
/**
|
|
224
|
-
* {@link LRUCache.OptionsBase.allowStaleOnFetchRejection}
|
|
225
|
-
*/
|
|
226
|
-
allowStaleOnFetchRejection;
|
|
227
|
-
/**
|
|
228
|
-
* {@link LRUCache.OptionsBase.ignoreFetchAbort}
|
|
229
|
-
*/
|
|
230
|
-
ignoreFetchAbort;
|
|
231
|
-
// computed properties
|
|
232
|
-
#size;
|
|
233
|
-
#calculatedSize;
|
|
234
|
-
#keyMap;
|
|
235
|
-
#keyList;
|
|
236
|
-
#valList;
|
|
237
|
-
#next;
|
|
238
|
-
#prev;
|
|
239
|
-
#head;
|
|
240
|
-
#tail;
|
|
241
|
-
#free;
|
|
242
|
-
#disposed;
|
|
243
|
-
#sizes;
|
|
244
|
-
#starts;
|
|
245
|
-
#ttls;
|
|
246
|
-
#hasDispose;
|
|
247
|
-
#hasFetchMethod;
|
|
248
|
-
#hasDisposeAfter;
|
|
249
|
-
/**
|
|
250
|
-
* Do not call this method unless you need to inspect the
|
|
251
|
-
* inner workings of the cache. If anything returned by this
|
|
252
|
-
* object is modified in any way, strange breakage may occur.
|
|
253
|
-
*
|
|
254
|
-
* These fields are private for a reason!
|
|
255
|
-
*
|
|
256
|
-
* @internal
|
|
257
|
-
*/
|
|
258
|
-
static unsafeExposeInternals(c) {
|
|
259
|
-
return {
|
|
260
|
-
// properties
|
|
261
|
-
starts: c.#starts,
|
|
262
|
-
ttls: c.#ttls,
|
|
263
|
-
sizes: c.#sizes,
|
|
264
|
-
keyMap: c.#keyMap,
|
|
265
|
-
keyList: c.#keyList,
|
|
266
|
-
valList: c.#valList,
|
|
267
|
-
next: c.#next,
|
|
268
|
-
prev: c.#prev,
|
|
269
|
-
get head() {
|
|
270
|
-
return c.#head;
|
|
271
|
-
},
|
|
272
|
-
get tail() {
|
|
273
|
-
return c.#tail;
|
|
274
|
-
},
|
|
275
|
-
free: c.#free,
|
|
276
|
-
// methods
|
|
277
|
-
isBackgroundFetch: (p) => c.#isBackgroundFetch(p),
|
|
278
|
-
backgroundFetch: (k, index, options, context) => c.#backgroundFetch(k, index, options, context),
|
|
279
|
-
moveToTail: (index) => c.#moveToTail(index),
|
|
280
|
-
indexes: (options) => c.#indexes(options),
|
|
281
|
-
rindexes: (options) => c.#rindexes(options),
|
|
282
|
-
isStale: (index) => c.#isStale(index),
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
// Protected read-only members
|
|
286
|
-
/**
|
|
287
|
-
* {@link LRUCache.OptionsBase.max} (read-only)
|
|
288
|
-
*/
|
|
289
|
-
get max() {
|
|
290
|
-
return this.#max;
|
|
291
|
-
}
|
|
292
|
-
/**
|
|
293
|
-
* {@link LRUCache.OptionsBase.maxSize} (read-only)
|
|
294
|
-
*/
|
|
295
|
-
get maxSize() {
|
|
296
|
-
return this.#maxSize;
|
|
297
|
-
}
|
|
298
|
-
/**
|
|
299
|
-
* The total computed size of items in the cache (read-only)
|
|
300
|
-
*/
|
|
301
|
-
get calculatedSize() {
|
|
302
|
-
return this.#calculatedSize;
|
|
303
|
-
}
|
|
304
|
-
/**
|
|
305
|
-
* The number of items stored in the cache (read-only)
|
|
306
|
-
*/
|
|
307
|
-
get size() {
|
|
308
|
-
return this.#size;
|
|
309
|
-
}
|
|
310
|
-
/**
|
|
311
|
-
* {@link LRUCache.OptionsBase.fetchMethod} (read-only)
|
|
312
|
-
*/
|
|
313
|
-
get fetchMethod() {
|
|
314
|
-
return this.#fetchMethod;
|
|
315
|
-
}
|
|
316
|
-
/**
|
|
317
|
-
* {@link LRUCache.OptionsBase.dispose} (read-only)
|
|
318
|
-
*/
|
|
319
|
-
get dispose() {
|
|
320
|
-
return this.#dispose;
|
|
321
|
-
}
|
|
322
|
-
/**
|
|
323
|
-
* {@link LRUCache.OptionsBase.disposeAfter} (read-only)
|
|
324
|
-
*/
|
|
325
|
-
get disposeAfter() {
|
|
326
|
-
return this.#disposeAfter;
|
|
327
|
-
}
|
|
328
|
-
constructor(options) {
|
|
329
|
-
const { max = 0, ttl, ttlResolution = 1, ttlAutopurge, updateAgeOnGet, updateAgeOnHas, allowStale, dispose, disposeAfter, noDisposeOnSet, noUpdateTTL, maxSize = 0, maxEntrySize = 0, sizeCalculation, fetchMethod, noDeleteOnFetchRejection, noDeleteOnStaleGet, allowStaleOnFetchRejection, allowStaleOnFetchAbort, ignoreFetchAbort, } = options;
|
|
330
|
-
if (max !== 0 && !isPosInt(max)) {
|
|
331
|
-
throw new TypeError('max option must be a nonnegative integer');
|
|
332
|
-
}
|
|
333
|
-
const UintArray = max ? getUintArray(max) : Array;
|
|
334
|
-
if (!UintArray) {
|
|
335
|
-
throw new Error('invalid max value: ' + max);
|
|
336
|
-
}
|
|
337
|
-
this.#max = max;
|
|
338
|
-
this.#maxSize = maxSize;
|
|
339
|
-
this.maxEntrySize = maxEntrySize || this.#maxSize;
|
|
340
|
-
this.sizeCalculation = sizeCalculation;
|
|
341
|
-
if (this.sizeCalculation) {
|
|
342
|
-
if (!this.#maxSize && !this.maxEntrySize) {
|
|
343
|
-
throw new TypeError('cannot set sizeCalculation without setting maxSize or maxEntrySize');
|
|
344
|
-
}
|
|
345
|
-
if (typeof this.sizeCalculation !== 'function') {
|
|
346
|
-
throw new TypeError('sizeCalculation set to non-function');
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
if (fetchMethod !== undefined &&
|
|
350
|
-
typeof fetchMethod !== 'function') {
|
|
351
|
-
throw new TypeError('fetchMethod must be a function if specified');
|
|
352
|
-
}
|
|
353
|
-
this.#fetchMethod = fetchMethod;
|
|
354
|
-
this.#hasFetchMethod = !!fetchMethod;
|
|
355
|
-
this.#keyMap = new Map();
|
|
356
|
-
this.#keyList = new Array(max).fill(undefined);
|
|
357
|
-
this.#valList = new Array(max).fill(undefined);
|
|
358
|
-
this.#next = new UintArray(max);
|
|
359
|
-
this.#prev = new UintArray(max);
|
|
360
|
-
this.#head = 0;
|
|
361
|
-
this.#tail = 0;
|
|
362
|
-
this.#free = Stack.create(max);
|
|
363
|
-
this.#size = 0;
|
|
364
|
-
this.#calculatedSize = 0;
|
|
365
|
-
if (typeof dispose === 'function') {
|
|
366
|
-
this.#dispose = dispose;
|
|
367
|
-
}
|
|
368
|
-
if (typeof disposeAfter === 'function') {
|
|
369
|
-
this.#disposeAfter = disposeAfter;
|
|
370
|
-
this.#disposed = [];
|
|
371
|
-
}
|
|
372
|
-
else {
|
|
373
|
-
this.#disposeAfter = undefined;
|
|
374
|
-
this.#disposed = undefined;
|
|
375
|
-
}
|
|
376
|
-
this.#hasDispose = !!this.#dispose;
|
|
377
|
-
this.#hasDisposeAfter = !!this.#disposeAfter;
|
|
378
|
-
this.noDisposeOnSet = !!noDisposeOnSet;
|
|
379
|
-
this.noUpdateTTL = !!noUpdateTTL;
|
|
380
|
-
this.noDeleteOnFetchRejection = !!noDeleteOnFetchRejection;
|
|
381
|
-
this.allowStaleOnFetchRejection = !!allowStaleOnFetchRejection;
|
|
382
|
-
this.allowStaleOnFetchAbort = !!allowStaleOnFetchAbort;
|
|
383
|
-
this.ignoreFetchAbort = !!ignoreFetchAbort;
|
|
384
|
-
// NB: maxEntrySize is set to maxSize if it's set
|
|
385
|
-
if (this.maxEntrySize !== 0) {
|
|
386
|
-
if (this.#maxSize !== 0) {
|
|
387
|
-
if (!isPosInt(this.#maxSize)) {
|
|
388
|
-
throw new TypeError('maxSize must be a positive integer if specified');
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
if (!isPosInt(this.maxEntrySize)) {
|
|
392
|
-
throw new TypeError('maxEntrySize must be a positive integer if specified');
|
|
393
|
-
}
|
|
394
|
-
this.#initializeSizeTracking();
|
|
395
|
-
}
|
|
396
|
-
this.allowStale = !!allowStale;
|
|
397
|
-
this.noDeleteOnStaleGet = !!noDeleteOnStaleGet;
|
|
398
|
-
this.updateAgeOnGet = !!updateAgeOnGet;
|
|
399
|
-
this.updateAgeOnHas = !!updateAgeOnHas;
|
|
400
|
-
this.ttlResolution =
|
|
401
|
-
isPosInt(ttlResolution) || ttlResolution === 0
|
|
402
|
-
? ttlResolution
|
|
403
|
-
: 1;
|
|
404
|
-
this.ttlAutopurge = !!ttlAutopurge;
|
|
405
|
-
this.ttl = ttl || 0;
|
|
406
|
-
if (this.ttl) {
|
|
407
|
-
if (!isPosInt(this.ttl)) {
|
|
408
|
-
throw new TypeError('ttl must be a positive integer if specified');
|
|
409
|
-
}
|
|
410
|
-
this.#initializeTTLTracking();
|
|
411
|
-
}
|
|
412
|
-
// do not allow completely unbounded caches
|
|
413
|
-
if (this.#max === 0 && this.ttl === 0 && this.#maxSize === 0) {
|
|
414
|
-
throw new TypeError('At least one of max, maxSize, or ttl is required');
|
|
415
|
-
}
|
|
416
|
-
if (!this.ttlAutopurge && !this.#max && !this.#maxSize) {
|
|
417
|
-
const code = 'LRU_CACHE_UNBOUNDED';
|
|
418
|
-
if (shouldWarn(code)) {
|
|
419
|
-
warned.add(code);
|
|
420
|
-
const msg = 'TTL caching without ttlAutopurge, max, or maxSize can ' +
|
|
421
|
-
'result in unbounded memory consumption.';
|
|
422
|
-
emitWarning(msg, 'UnboundedCacheWarning', code, LRUCache);
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
/**
|
|
427
|
-
* Return the remaining TTL time for a given entry key
|
|
428
|
-
*/
|
|
429
|
-
getRemainingTTL(key) {
|
|
430
|
-
return this.#keyMap.has(key) ? Infinity : 0;
|
|
431
|
-
}
|
|
432
|
-
#initializeTTLTracking() {
|
|
433
|
-
const ttls = new ZeroArray(this.#max);
|
|
434
|
-
const starts = new ZeroArray(this.#max);
|
|
435
|
-
this.#ttls = ttls;
|
|
436
|
-
this.#starts = starts;
|
|
437
|
-
this.#setItemTTL = (index, ttl, start = perf.now()) => {
|
|
438
|
-
starts[index] = ttl !== 0 ? start : 0;
|
|
439
|
-
ttls[index] = ttl;
|
|
440
|
-
if (ttl !== 0 && this.ttlAutopurge) {
|
|
441
|
-
const t = setTimeout(() => {
|
|
442
|
-
if (this.#isStale(index)) {
|
|
443
|
-
this.delete(this.#keyList[index]);
|
|
444
|
-
}
|
|
445
|
-
}, ttl + 1);
|
|
446
|
-
// unref() not supported on all platforms
|
|
447
|
-
/* c8 ignore start */
|
|
448
|
-
if (t.unref) {
|
|
449
|
-
t.unref();
|
|
450
|
-
}
|
|
451
|
-
/* c8 ignore stop */
|
|
452
|
-
}
|
|
453
|
-
};
|
|
454
|
-
this.#updateItemAge = index => {
|
|
455
|
-
starts[index] = ttls[index] !== 0 ? perf.now() : 0;
|
|
456
|
-
};
|
|
457
|
-
this.#statusTTL = (status, index) => {
|
|
458
|
-
if (ttls[index]) {
|
|
459
|
-
const ttl = ttls[index];
|
|
460
|
-
const start = starts[index];
|
|
461
|
-
/* c8 ignore next */
|
|
462
|
-
if (!ttl || !start)
|
|
463
|
-
return;
|
|
464
|
-
status.ttl = ttl;
|
|
465
|
-
status.start = start;
|
|
466
|
-
status.now = cachedNow || getNow();
|
|
467
|
-
const age = status.now - start;
|
|
468
|
-
status.remainingTTL = ttl - age;
|
|
469
|
-
}
|
|
470
|
-
};
|
|
471
|
-
// debounce calls to perf.now() to 1s so we're not hitting
|
|
472
|
-
// that costly call repeatedly.
|
|
473
|
-
let cachedNow = 0;
|
|
474
|
-
const getNow = () => {
|
|
475
|
-
const n = perf.now();
|
|
476
|
-
if (this.ttlResolution > 0) {
|
|
477
|
-
cachedNow = n;
|
|
478
|
-
const t = setTimeout(() => (cachedNow = 0), this.ttlResolution);
|
|
479
|
-
// not available on all platforms
|
|
480
|
-
/* c8 ignore start */
|
|
481
|
-
if (t.unref) {
|
|
482
|
-
t.unref();
|
|
483
|
-
}
|
|
484
|
-
/* c8 ignore stop */
|
|
485
|
-
}
|
|
486
|
-
return n;
|
|
487
|
-
};
|
|
488
|
-
this.getRemainingTTL = key => {
|
|
489
|
-
const index = this.#keyMap.get(key);
|
|
490
|
-
if (index === undefined) {
|
|
491
|
-
return 0;
|
|
492
|
-
}
|
|
493
|
-
const ttl = ttls[index];
|
|
494
|
-
const start = starts[index];
|
|
495
|
-
if (!ttl || !start) {
|
|
496
|
-
return Infinity;
|
|
497
|
-
}
|
|
498
|
-
const age = (cachedNow || getNow()) - start;
|
|
499
|
-
return ttl - age;
|
|
500
|
-
};
|
|
501
|
-
this.#isStale = index => {
|
|
502
|
-
const s = starts[index];
|
|
503
|
-
const t = ttls[index];
|
|
504
|
-
return !!t && !!s && (cachedNow || getNow()) - s > t;
|
|
505
|
-
};
|
|
506
|
-
}
|
|
507
|
-
// conditionally set private methods related to TTL
|
|
508
|
-
#updateItemAge = () => { };
|
|
509
|
-
#statusTTL = () => { };
|
|
510
|
-
#setItemTTL = () => { };
|
|
511
|
-
/* c8 ignore stop */
|
|
512
|
-
#isStale = () => false;
|
|
513
|
-
#initializeSizeTracking() {
|
|
514
|
-
const sizes = new ZeroArray(this.#max);
|
|
515
|
-
this.#calculatedSize = 0;
|
|
516
|
-
this.#sizes = sizes;
|
|
517
|
-
this.#removeItemSize = index => {
|
|
518
|
-
this.#calculatedSize -= sizes[index];
|
|
519
|
-
sizes[index] = 0;
|
|
520
|
-
};
|
|
521
|
-
this.#requireSize = (k, v, size, sizeCalculation) => {
|
|
522
|
-
// provisionally accept background fetches.
|
|
523
|
-
// actual value size will be checked when they return.
|
|
524
|
-
if (this.#isBackgroundFetch(v)) {
|
|
525
|
-
return 0;
|
|
526
|
-
}
|
|
527
|
-
if (!isPosInt(size)) {
|
|
528
|
-
if (sizeCalculation) {
|
|
529
|
-
if (typeof sizeCalculation !== 'function') {
|
|
530
|
-
throw new TypeError('sizeCalculation must be a function');
|
|
531
|
-
}
|
|
532
|
-
size = sizeCalculation(v, k);
|
|
533
|
-
if (!isPosInt(size)) {
|
|
534
|
-
throw new TypeError('sizeCalculation return invalid (expect positive integer)');
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
else {
|
|
538
|
-
throw new TypeError('invalid size value (must be positive integer). ' +
|
|
539
|
-
'When maxSize or maxEntrySize is used, sizeCalculation ' +
|
|
540
|
-
'or size must be set.');
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
return size;
|
|
544
|
-
};
|
|
545
|
-
this.#addItemSize = (index, size, status) => {
|
|
546
|
-
sizes[index] = size;
|
|
547
|
-
if (this.#maxSize) {
|
|
548
|
-
const maxSize = this.#maxSize - sizes[index];
|
|
549
|
-
while (this.#calculatedSize > maxSize) {
|
|
550
|
-
this.#evict(true);
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
this.#calculatedSize += sizes[index];
|
|
554
|
-
if (status) {
|
|
555
|
-
status.entrySize = size;
|
|
556
|
-
status.totalCalculatedSize = this.#calculatedSize;
|
|
557
|
-
}
|
|
558
|
-
};
|
|
559
|
-
}
|
|
560
|
-
#removeItemSize = _i => { };
|
|
561
|
-
#addItemSize = (_i, _s, _st) => { };
|
|
562
|
-
#requireSize = (_k, _v, size, sizeCalculation) => {
|
|
563
|
-
if (size || sizeCalculation) {
|
|
564
|
-
throw new TypeError('cannot set size without setting maxSize or maxEntrySize on cache');
|
|
565
|
-
}
|
|
566
|
-
return 0;
|
|
567
|
-
};
|
|
568
|
-
*#indexes({ allowStale = this.allowStale } = {}) {
|
|
569
|
-
if (this.#size) {
|
|
570
|
-
for (let i = this.#tail; true;) {
|
|
571
|
-
if (!this.#isValidIndex(i)) {
|
|
572
|
-
break;
|
|
573
|
-
}
|
|
574
|
-
if (allowStale || !this.#isStale(i)) {
|
|
575
|
-
yield i;
|
|
576
|
-
}
|
|
577
|
-
if (i === this.#head) {
|
|
578
|
-
break;
|
|
579
|
-
}
|
|
580
|
-
else {
|
|
581
|
-
i = this.#prev[i];
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
*#rindexes({ allowStale = this.allowStale } = {}) {
|
|
587
|
-
if (this.#size) {
|
|
588
|
-
for (let i = this.#head; true;) {
|
|
589
|
-
if (!this.#isValidIndex(i)) {
|
|
590
|
-
break;
|
|
591
|
-
}
|
|
592
|
-
if (allowStale || !this.#isStale(i)) {
|
|
593
|
-
yield i;
|
|
594
|
-
}
|
|
595
|
-
if (i === this.#tail) {
|
|
596
|
-
break;
|
|
597
|
-
}
|
|
598
|
-
else {
|
|
599
|
-
i = this.#next[i];
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
#isValidIndex(index) {
|
|
605
|
-
return (index !== undefined &&
|
|
606
|
-
this.#keyMap.get(this.#keyList[index]) === index);
|
|
607
|
-
}
|
|
608
|
-
/**
|
|
609
|
-
* Return a generator yielding `[key, value]` pairs,
|
|
610
|
-
* in order from most recently used to least recently used.
|
|
611
|
-
*/
|
|
612
|
-
*entries() {
|
|
613
|
-
for (const i of this.#indexes()) {
|
|
614
|
-
if (this.#valList[i] !== undefined &&
|
|
615
|
-
this.#keyList[i] !== undefined &&
|
|
616
|
-
!this.#isBackgroundFetch(this.#valList[i])) {
|
|
617
|
-
yield [this.#keyList[i], this.#valList[i]];
|
|
618
|
-
}
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
/**
|
|
622
|
-
* Inverse order version of {@link LRUCache.entries}
|
|
623
|
-
*
|
|
624
|
-
* Return a generator yielding `[key, value]` pairs,
|
|
625
|
-
* in order from least recently used to most recently used.
|
|
626
|
-
*/
|
|
627
|
-
*rentries() {
|
|
628
|
-
for (const i of this.#rindexes()) {
|
|
629
|
-
if (this.#valList[i] !== undefined &&
|
|
630
|
-
this.#keyList[i] !== undefined &&
|
|
631
|
-
!this.#isBackgroundFetch(this.#valList[i])) {
|
|
632
|
-
yield [this.#keyList[i], this.#valList[i]];
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
/**
|
|
637
|
-
* Return a generator yielding the keys in the cache,
|
|
638
|
-
* in order from most recently used to least recently used.
|
|
639
|
-
*/
|
|
640
|
-
*keys() {
|
|
641
|
-
for (const i of this.#indexes()) {
|
|
642
|
-
const k = this.#keyList[i];
|
|
643
|
-
if (k !== undefined &&
|
|
644
|
-
!this.#isBackgroundFetch(this.#valList[i])) {
|
|
645
|
-
yield k;
|
|
646
|
-
}
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
/**
|
|
650
|
-
* Inverse order version of {@link LRUCache.keys}
|
|
651
|
-
*
|
|
652
|
-
* Return a generator yielding the keys in the cache,
|
|
653
|
-
* in order from least recently used to most recently used.
|
|
654
|
-
*/
|
|
655
|
-
*rkeys() {
|
|
656
|
-
for (const i of this.#rindexes()) {
|
|
657
|
-
const k = this.#keyList[i];
|
|
658
|
-
if (k !== undefined &&
|
|
659
|
-
!this.#isBackgroundFetch(this.#valList[i])) {
|
|
660
|
-
yield k;
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
/**
|
|
665
|
-
* Return a generator yielding the values in the cache,
|
|
666
|
-
* in order from most recently used to least recently used.
|
|
667
|
-
*/
|
|
668
|
-
*values() {
|
|
669
|
-
for (const i of this.#indexes()) {
|
|
670
|
-
const v = this.#valList[i];
|
|
671
|
-
if (v !== undefined &&
|
|
672
|
-
!this.#isBackgroundFetch(this.#valList[i])) {
|
|
673
|
-
yield this.#valList[i];
|
|
674
|
-
}
|
|
675
|
-
}
|
|
676
|
-
}
|
|
677
|
-
/**
|
|
678
|
-
* Inverse order version of {@link LRUCache.values}
|
|
679
|
-
*
|
|
680
|
-
* Return a generator yielding the values in the cache,
|
|
681
|
-
* in order from least recently used to most recently used.
|
|
682
|
-
*/
|
|
683
|
-
*rvalues() {
|
|
684
|
-
for (const i of this.#rindexes()) {
|
|
685
|
-
const v = this.#valList[i];
|
|
686
|
-
if (v !== undefined &&
|
|
687
|
-
!this.#isBackgroundFetch(this.#valList[i])) {
|
|
688
|
-
yield this.#valList[i];
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
/**
|
|
693
|
-
* Iterating over the cache itself yields the same results as
|
|
694
|
-
* {@link LRUCache.entries}
|
|
695
|
-
*/
|
|
696
|
-
[Symbol.iterator]() {
|
|
697
|
-
return this.entries();
|
|
698
|
-
}
|
|
699
|
-
/**
|
|
700
|
-
* A String value that is used in the creation of the default string description of an object.
|
|
701
|
-
* Called by the built-in method Object.prototype.toString.
|
|
702
|
-
*/
|
|
703
|
-
[Symbol.toStringTag] = 'LRUCache';
|
|
704
|
-
/**
|
|
705
|
-
* Find a value for which the supplied fn method returns a truthy value,
|
|
706
|
-
* similar to Array.find(). fn is called as fn(value, key, cache).
|
|
707
|
-
*/
|
|
708
|
-
find(fn, getOptions = {}) {
|
|
709
|
-
for (const i of this.#indexes()) {
|
|
710
|
-
const v = this.#valList[i];
|
|
711
|
-
const value = this.#isBackgroundFetch(v)
|
|
712
|
-
? v.__staleWhileFetching
|
|
713
|
-
: v;
|
|
714
|
-
if (value === undefined)
|
|
715
|
-
continue;
|
|
716
|
-
if (fn(value, this.#keyList[i], this)) {
|
|
717
|
-
return this.get(this.#keyList[i], getOptions);
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
}
|
|
721
|
-
/**
|
|
722
|
-
* Call the supplied function on each item in the cache, in order from
|
|
723
|
-
* most recently used to least recently used. fn is called as
|
|
724
|
-
* fn(value, key, cache). Does not update age or recenty of use.
|
|
725
|
-
* Does not iterate over stale values.
|
|
726
|
-
*/
|
|
727
|
-
forEach(fn, thisp = this) {
|
|
728
|
-
for (const i of this.#indexes()) {
|
|
729
|
-
const v = this.#valList[i];
|
|
730
|
-
const value = this.#isBackgroundFetch(v)
|
|
731
|
-
? v.__staleWhileFetching
|
|
732
|
-
: v;
|
|
733
|
-
if (value === undefined)
|
|
734
|
-
continue;
|
|
735
|
-
fn.call(thisp, value, this.#keyList[i], this);
|
|
736
|
-
}
|
|
737
|
-
}
|
|
738
|
-
/**
|
|
739
|
-
* The same as {@link LRUCache.forEach} but items are iterated over in
|
|
740
|
-
* reverse order. (ie, less recently used items are iterated over first.)
|
|
741
|
-
*/
|
|
742
|
-
rforEach(fn, thisp = this) {
|
|
743
|
-
for (const i of this.#rindexes()) {
|
|
744
|
-
const v = this.#valList[i];
|
|
745
|
-
const value = this.#isBackgroundFetch(v)
|
|
746
|
-
? v.__staleWhileFetching
|
|
747
|
-
: v;
|
|
748
|
-
if (value === undefined)
|
|
749
|
-
continue;
|
|
750
|
-
fn.call(thisp, value, this.#keyList[i], this);
|
|
751
|
-
}
|
|
752
|
-
}
|
|
753
|
-
/**
|
|
754
|
-
* Delete any stale entries. Returns true if anything was removed,
|
|
755
|
-
* false otherwise.
|
|
756
|
-
*/
|
|
757
|
-
purgeStale() {
|
|
758
|
-
let deleted = false;
|
|
759
|
-
for (const i of this.#rindexes({ allowStale: true })) {
|
|
760
|
-
if (this.#isStale(i)) {
|
|
761
|
-
this.delete(this.#keyList[i]);
|
|
762
|
-
deleted = true;
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
|
-
return deleted;
|
|
766
|
-
}
|
|
767
|
-
/**
|
|
768
|
-
* Get the extended info about a given entry, to get its value, size, and
|
|
769
|
-
* TTL info simultaneously. Like {@link LRUCache#dump}, but just for a
|
|
770
|
-
* single key. Always returns stale values, if their info is found in the
|
|
771
|
-
* cache, so be sure to check for expired TTLs if relevant.
|
|
772
|
-
*/
|
|
773
|
-
info(key) {
|
|
774
|
-
const i = this.#keyMap.get(key);
|
|
775
|
-
if (i === undefined)
|
|
776
|
-
return undefined;
|
|
777
|
-
const v = this.#valList[i];
|
|
778
|
-
const value = this.#isBackgroundFetch(v)
|
|
779
|
-
? v.__staleWhileFetching
|
|
780
|
-
: v;
|
|
781
|
-
if (value === undefined)
|
|
782
|
-
return undefined;
|
|
783
|
-
const entry = { value };
|
|
784
|
-
if (this.#ttls && this.#starts) {
|
|
785
|
-
const ttl = this.#ttls[i];
|
|
786
|
-
const start = this.#starts[i];
|
|
787
|
-
if (ttl && start) {
|
|
788
|
-
const remain = ttl - (perf.now() - start);
|
|
789
|
-
entry.ttl = remain;
|
|
790
|
-
entry.start = Date.now();
|
|
791
|
-
}
|
|
792
|
-
}
|
|
793
|
-
if (this.#sizes) {
|
|
794
|
-
entry.size = this.#sizes[i];
|
|
795
|
-
}
|
|
796
|
-
return entry;
|
|
797
|
-
}
|
|
798
|
-
/**
|
|
799
|
-
* Return an array of [key, {@link LRUCache.Entry}] tuples which can be
|
|
800
|
-
* passed to cache.load()
|
|
801
|
-
*/
|
|
802
|
-
dump() {
|
|
803
|
-
const arr = [];
|
|
804
|
-
for (const i of this.#indexes({ allowStale: true })) {
|
|
805
|
-
const key = this.#keyList[i];
|
|
806
|
-
const v = this.#valList[i];
|
|
807
|
-
const value = this.#isBackgroundFetch(v)
|
|
808
|
-
? v.__staleWhileFetching
|
|
809
|
-
: v;
|
|
810
|
-
if (value === undefined || key === undefined)
|
|
811
|
-
continue;
|
|
812
|
-
const entry = { value };
|
|
813
|
-
if (this.#ttls && this.#starts) {
|
|
814
|
-
entry.ttl = this.#ttls[i];
|
|
815
|
-
// always dump the start relative to a portable timestamp
|
|
816
|
-
// it's ok for this to be a bit slow, it's a rare operation.
|
|
817
|
-
const age = perf.now() - this.#starts[i];
|
|
818
|
-
entry.start = Math.floor(Date.now() - age);
|
|
819
|
-
}
|
|
820
|
-
if (this.#sizes) {
|
|
821
|
-
entry.size = this.#sizes[i];
|
|
822
|
-
}
|
|
823
|
-
arr.unshift([key, entry]);
|
|
824
|
-
}
|
|
825
|
-
return arr;
|
|
74
|
+
|
|
75
|
+
/******************************************************************************
|
|
76
|
+
Copyright (c) Microsoft Corporation.
|
|
77
|
+
|
|
78
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
79
|
+
purpose with or without fee is hereby granted.
|
|
80
|
+
|
|
81
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
82
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
83
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
84
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
85
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
86
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
87
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
88
|
+
***************************************************************************** */
|
|
89
|
+
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
93
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
94
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
95
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
99
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
100
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
101
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
102
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
106
|
+
var e = new Error(message);
|
|
107
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
var _Cache_keyArray, _Cache_maxLength;
|
|
111
|
+
class Cache extends Map {
|
|
112
|
+
constructor() {
|
|
113
|
+
super(...arguments);
|
|
114
|
+
_Cache_keyArray.set(this, []);
|
|
115
|
+
_Cache_maxLength.set(this, 30);
|
|
826
116
|
}
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
* same options are not used in both caches.
|
|
831
|
-
*/
|
|
832
|
-
load(arr) {
|
|
833
|
-
this.clear();
|
|
834
|
-
for (const [key, entry] of arr) {
|
|
835
|
-
if (entry.start) {
|
|
836
|
-
// entry.start is a portable timestamp, but we may be using
|
|
837
|
-
// node's performance.now(), so calculate the offset, so that
|
|
838
|
-
// we get the intended remaining TTL, no matter how long it's
|
|
839
|
-
// been on ice.
|
|
840
|
-
//
|
|
841
|
-
// it's ok for this to be a bit slow, it's a rare operation.
|
|
842
|
-
const age = Date.now() - entry.start;
|
|
843
|
-
entry.start = perf.now() - age;
|
|
844
|
-
}
|
|
845
|
-
this.set(key, entry.value, entry);
|
|
846
|
-
}
|
|
117
|
+
setMaxLength(length) {
|
|
118
|
+
__classPrivateFieldSet(this, _Cache_maxLength, length, "f");
|
|
119
|
+
this._checkLength();
|
|
847
120
|
}
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
*
|
|
851
|
-
* Note: if `undefined` is specified as a value, this is an alias for
|
|
852
|
-
* {@link LRUCache#delete}
|
|
853
|
-
*/
|
|
854
|
-
set(k, v, setOptions = {}) {
|
|
855
|
-
if (v === undefined) {
|
|
856
|
-
this.delete(k);
|
|
121
|
+
set(key, value) {
|
|
122
|
+
if (this.has(key))
|
|
857
123
|
return this;
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
const size = this.#requireSize(k, v, setOptions.size || 0, sizeCalculation);
|
|
862
|
-
// if the item doesn't fit, don't do anything
|
|
863
|
-
// NB: maxEntrySize set to maxSize by default
|
|
864
|
-
if (this.maxEntrySize && size > this.maxEntrySize) {
|
|
865
|
-
if (status) {
|
|
866
|
-
status.set = 'miss';
|
|
867
|
-
status.maxEntrySizeExceeded = true;
|
|
868
|
-
}
|
|
869
|
-
// have to delete, in case something is there already.
|
|
870
|
-
this.delete(k);
|
|
871
|
-
return this;
|
|
872
|
-
}
|
|
873
|
-
let index = this.#size === 0 ? undefined : this.#keyMap.get(k);
|
|
874
|
-
if (index === undefined) {
|
|
875
|
-
// addition
|
|
876
|
-
index = (this.#size === 0
|
|
877
|
-
? this.#tail
|
|
878
|
-
: this.#free.length !== 0
|
|
879
|
-
? this.#free.pop()
|
|
880
|
-
: this.#size === this.#max
|
|
881
|
-
? this.#evict(false)
|
|
882
|
-
: this.#size);
|
|
883
|
-
this.#keyList[index] = k;
|
|
884
|
-
this.#valList[index] = v;
|
|
885
|
-
this.#keyMap.set(k, index);
|
|
886
|
-
this.#next[this.#tail] = index;
|
|
887
|
-
this.#prev[index] = this.#tail;
|
|
888
|
-
this.#tail = index;
|
|
889
|
-
this.#size++;
|
|
890
|
-
this.#addItemSize(index, size, status);
|
|
891
|
-
if (status)
|
|
892
|
-
status.set = 'add';
|
|
893
|
-
noUpdateTTL = false;
|
|
894
|
-
}
|
|
895
|
-
else {
|
|
896
|
-
// update
|
|
897
|
-
this.#moveToTail(index);
|
|
898
|
-
const oldVal = this.#valList[index];
|
|
899
|
-
if (v !== oldVal) {
|
|
900
|
-
if (this.#hasFetchMethod && this.#isBackgroundFetch(oldVal)) {
|
|
901
|
-
oldVal.__abortController.abort(new Error('replaced'));
|
|
902
|
-
const { __staleWhileFetching: s } = oldVal;
|
|
903
|
-
if (s !== undefined && !noDisposeOnSet) {
|
|
904
|
-
if (this.#hasDispose) {
|
|
905
|
-
this.#dispose?.(s, k, 'set');
|
|
906
|
-
}
|
|
907
|
-
if (this.#hasDisposeAfter) {
|
|
908
|
-
this.#disposed?.push([s, k, 'set']);
|
|
909
|
-
}
|
|
910
|
-
}
|
|
911
|
-
}
|
|
912
|
-
else if (!noDisposeOnSet) {
|
|
913
|
-
if (this.#hasDispose) {
|
|
914
|
-
this.#dispose?.(oldVal, k, 'set');
|
|
915
|
-
}
|
|
916
|
-
if (this.#hasDisposeAfter) {
|
|
917
|
-
this.#disposed?.push([oldVal, k, 'set']);
|
|
918
|
-
}
|
|
919
|
-
}
|
|
920
|
-
this.#removeItemSize(index);
|
|
921
|
-
this.#addItemSize(index, size, status);
|
|
922
|
-
this.#valList[index] = v;
|
|
923
|
-
if (status) {
|
|
924
|
-
status.set = 'replace';
|
|
925
|
-
const oldValue = oldVal && this.#isBackgroundFetch(oldVal)
|
|
926
|
-
? oldVal.__staleWhileFetching
|
|
927
|
-
: oldVal;
|
|
928
|
-
if (oldValue !== undefined)
|
|
929
|
-
status.oldValue = oldValue;
|
|
930
|
-
}
|
|
931
|
-
}
|
|
932
|
-
else if (status) {
|
|
933
|
-
status.set = 'update';
|
|
934
|
-
}
|
|
935
|
-
}
|
|
936
|
-
if (ttl !== 0 && !this.#ttls) {
|
|
937
|
-
this.#initializeTTLTracking();
|
|
938
|
-
}
|
|
939
|
-
if (this.#ttls) {
|
|
940
|
-
if (!noUpdateTTL) {
|
|
941
|
-
this.#setItemTTL(index, ttl, start);
|
|
942
|
-
}
|
|
943
|
-
if (status)
|
|
944
|
-
this.#statusTTL(status, index);
|
|
945
|
-
}
|
|
946
|
-
if (!noDisposeOnSet && this.#hasDisposeAfter && this.#disposed) {
|
|
947
|
-
const dt = this.#disposed;
|
|
948
|
-
let task;
|
|
949
|
-
while ((task = dt?.shift())) {
|
|
950
|
-
this.#disposeAfter?.(...task);
|
|
951
|
-
}
|
|
952
|
-
}
|
|
953
|
-
return this;
|
|
954
|
-
}
|
|
955
|
-
/**
|
|
956
|
-
* Evict the least recently used item, returning its value or
|
|
957
|
-
* `undefined` if cache is empty.
|
|
958
|
-
*/
|
|
959
|
-
pop() {
|
|
960
|
-
try {
|
|
961
|
-
while (this.#size) {
|
|
962
|
-
const val = this.#valList[this.#head];
|
|
963
|
-
this.#evict(true);
|
|
964
|
-
if (this.#isBackgroundFetch(val)) {
|
|
965
|
-
if (val.__staleWhileFetching) {
|
|
966
|
-
return val.__staleWhileFetching;
|
|
967
|
-
}
|
|
968
|
-
}
|
|
969
|
-
else if (val !== undefined) {
|
|
970
|
-
return val;
|
|
971
|
-
}
|
|
972
|
-
}
|
|
973
|
-
}
|
|
974
|
-
finally {
|
|
975
|
-
if (this.#hasDisposeAfter && this.#disposed) {
|
|
976
|
-
const dt = this.#disposed;
|
|
977
|
-
let task;
|
|
978
|
-
while ((task = dt?.shift())) {
|
|
979
|
-
this.#disposeAfter?.(...task);
|
|
980
|
-
}
|
|
981
|
-
}
|
|
982
|
-
}
|
|
983
|
-
}
|
|
984
|
-
#evict(free) {
|
|
985
|
-
const head = this.#head;
|
|
986
|
-
const k = this.#keyList[head];
|
|
987
|
-
const v = this.#valList[head];
|
|
988
|
-
if (this.#hasFetchMethod && this.#isBackgroundFetch(v)) {
|
|
989
|
-
v.__abortController.abort(new Error('evicted'));
|
|
990
|
-
}
|
|
991
|
-
else if (this.#hasDispose || this.#hasDisposeAfter) {
|
|
992
|
-
if (this.#hasDispose) {
|
|
993
|
-
this.#dispose?.(v, k, 'evict');
|
|
994
|
-
}
|
|
995
|
-
if (this.#hasDisposeAfter) {
|
|
996
|
-
this.#disposed?.push([v, k, 'evict']);
|
|
997
|
-
}
|
|
998
|
-
}
|
|
999
|
-
this.#removeItemSize(head);
|
|
1000
|
-
// if we aren't about to use the index, then null these out
|
|
1001
|
-
if (free) {
|
|
1002
|
-
this.#keyList[head] = undefined;
|
|
1003
|
-
this.#valList[head] = undefined;
|
|
1004
|
-
this.#free.push(head);
|
|
1005
|
-
}
|
|
1006
|
-
if (this.#size === 1) {
|
|
1007
|
-
this.#head = this.#tail = 0;
|
|
1008
|
-
this.#free.length = 0;
|
|
1009
|
-
}
|
|
1010
|
-
else {
|
|
1011
|
-
this.#head = this.#next[head];
|
|
1012
|
-
}
|
|
1013
|
-
this.#keyMap.delete(k);
|
|
1014
|
-
this.#size--;
|
|
1015
|
-
return head;
|
|
1016
|
-
}
|
|
1017
|
-
/**
|
|
1018
|
-
* Check if a key is in the cache, without updating the recency of use.
|
|
1019
|
-
* Will return false if the item is stale, even though it is technically
|
|
1020
|
-
* in the cache.
|
|
1021
|
-
*
|
|
1022
|
-
* Will not update item age unless
|
|
1023
|
-
* {@link LRUCache.OptionsBase.updateAgeOnHas} is set.
|
|
1024
|
-
*/
|
|
1025
|
-
has(k, hasOptions = {}) {
|
|
1026
|
-
const { updateAgeOnHas = this.updateAgeOnHas, status } = hasOptions;
|
|
1027
|
-
const index = this.#keyMap.get(k);
|
|
1028
|
-
if (index !== undefined) {
|
|
1029
|
-
const v = this.#valList[index];
|
|
1030
|
-
if (this.#isBackgroundFetch(v) &&
|
|
1031
|
-
v.__staleWhileFetching === undefined) {
|
|
1032
|
-
return false;
|
|
1033
|
-
}
|
|
1034
|
-
if (!this.#isStale(index)) {
|
|
1035
|
-
if (updateAgeOnHas) {
|
|
1036
|
-
this.#updateItemAge(index);
|
|
1037
|
-
}
|
|
1038
|
-
if (status) {
|
|
1039
|
-
status.has = 'hit';
|
|
1040
|
-
this.#statusTTL(status, index);
|
|
1041
|
-
}
|
|
1042
|
-
return true;
|
|
1043
|
-
}
|
|
1044
|
-
else if (status) {
|
|
1045
|
-
status.has = 'stale';
|
|
1046
|
-
this.#statusTTL(status, index);
|
|
1047
|
-
}
|
|
1048
|
-
}
|
|
1049
|
-
else if (status) {
|
|
1050
|
-
status.has = 'miss';
|
|
1051
|
-
}
|
|
1052
|
-
return false;
|
|
124
|
+
__classPrivateFieldGet(this, _Cache_keyArray, "f").push(key);
|
|
125
|
+
this._checkLength();
|
|
126
|
+
return super.set(key, value);
|
|
1053
127
|
}
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
* Returns `undefined` if the item is stale, unless
|
|
1059
|
-
* {@link LRUCache.OptionsBase.allowStale} is set.
|
|
1060
|
-
*/
|
|
1061
|
-
peek(k, peekOptions = {}) {
|
|
1062
|
-
const { allowStale = this.allowStale } = peekOptions;
|
|
1063
|
-
const index = this.#keyMap.get(k);
|
|
1064
|
-
if (index === undefined ||
|
|
1065
|
-
(!allowStale && this.#isStale(index))) {
|
|
1066
|
-
return;
|
|
1067
|
-
}
|
|
1068
|
-
const v = this.#valList[index];
|
|
1069
|
-
// either stale and allowed, or forcing a refresh of non-stale value
|
|
1070
|
-
return this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
|
|
1071
|
-
}
|
|
1072
|
-
#backgroundFetch(k, index, options, context) {
|
|
1073
|
-
const v = index === undefined ? undefined : this.#valList[index];
|
|
1074
|
-
if (this.#isBackgroundFetch(v)) {
|
|
1075
|
-
return v;
|
|
1076
|
-
}
|
|
1077
|
-
const ac = new AC();
|
|
1078
|
-
const { signal } = options;
|
|
1079
|
-
// when/if our AC signals, then stop listening to theirs.
|
|
1080
|
-
signal?.addEventListener('abort', () => ac.abort(signal.reason), {
|
|
1081
|
-
signal: ac.signal,
|
|
1082
|
-
});
|
|
1083
|
-
const fetchOpts = {
|
|
1084
|
-
signal: ac.signal,
|
|
1085
|
-
options,
|
|
1086
|
-
context,
|
|
1087
|
-
};
|
|
1088
|
-
const cb = (v, updateCache = false) => {
|
|
1089
|
-
const { aborted } = ac.signal;
|
|
1090
|
-
const ignoreAbort = options.ignoreFetchAbort && v !== undefined;
|
|
1091
|
-
if (options.status) {
|
|
1092
|
-
if (aborted && !updateCache) {
|
|
1093
|
-
options.status.fetchAborted = true;
|
|
1094
|
-
options.status.fetchError = ac.signal.reason;
|
|
1095
|
-
if (ignoreAbort)
|
|
1096
|
-
options.status.fetchAbortIgnored = true;
|
|
1097
|
-
}
|
|
1098
|
-
else {
|
|
1099
|
-
options.status.fetchResolved = true;
|
|
1100
|
-
}
|
|
1101
|
-
}
|
|
1102
|
-
if (aborted && !ignoreAbort && !updateCache) {
|
|
1103
|
-
return fetchFail(ac.signal.reason);
|
|
1104
|
-
}
|
|
1105
|
-
// either we didn't abort, and are still here, or we did, and ignored
|
|
1106
|
-
const bf = p;
|
|
1107
|
-
if (this.#valList[index] === p) {
|
|
1108
|
-
if (v === undefined) {
|
|
1109
|
-
if (bf.__staleWhileFetching) {
|
|
1110
|
-
this.#valList[index] = bf.__staleWhileFetching;
|
|
1111
|
-
}
|
|
1112
|
-
else {
|
|
1113
|
-
this.delete(k);
|
|
1114
|
-
}
|
|
1115
|
-
}
|
|
1116
|
-
else {
|
|
1117
|
-
if (options.status)
|
|
1118
|
-
options.status.fetchUpdated = true;
|
|
1119
|
-
this.set(k, v, fetchOpts.options);
|
|
1120
|
-
}
|
|
1121
|
-
}
|
|
1122
|
-
return v;
|
|
1123
|
-
};
|
|
1124
|
-
const eb = (er) => {
|
|
1125
|
-
if (options.status) {
|
|
1126
|
-
options.status.fetchRejected = true;
|
|
1127
|
-
options.status.fetchError = er;
|
|
1128
|
-
}
|
|
1129
|
-
return fetchFail(er);
|
|
1130
|
-
};
|
|
1131
|
-
const fetchFail = (er) => {
|
|
1132
|
-
const { aborted } = ac.signal;
|
|
1133
|
-
const allowStaleAborted = aborted && options.allowStaleOnFetchAbort;
|
|
1134
|
-
const allowStale = allowStaleAborted || options.allowStaleOnFetchRejection;
|
|
1135
|
-
const noDelete = allowStale || options.noDeleteOnFetchRejection;
|
|
1136
|
-
const bf = p;
|
|
1137
|
-
if (this.#valList[index] === p) {
|
|
1138
|
-
// if we allow stale on fetch rejections, then we need to ensure that
|
|
1139
|
-
// the stale value is not removed from the cache when the fetch fails.
|
|
1140
|
-
const del = !noDelete || bf.__staleWhileFetching === undefined;
|
|
1141
|
-
if (del) {
|
|
1142
|
-
this.delete(k);
|
|
1143
|
-
}
|
|
1144
|
-
else if (!allowStaleAborted) {
|
|
1145
|
-
// still replace the *promise* with the stale value,
|
|
1146
|
-
// since we are done with the promise at this point.
|
|
1147
|
-
// leave it untouched if we're still waiting for an
|
|
1148
|
-
// aborted background fetch that hasn't yet returned.
|
|
1149
|
-
this.#valList[index] = bf.__staleWhileFetching;
|
|
1150
|
-
}
|
|
1151
|
-
}
|
|
1152
|
-
if (allowStale) {
|
|
1153
|
-
if (options.status && bf.__staleWhileFetching !== undefined) {
|
|
1154
|
-
options.status.returnedStale = true;
|
|
1155
|
-
}
|
|
1156
|
-
return bf.__staleWhileFetching;
|
|
1157
|
-
}
|
|
1158
|
-
else if (bf.__returned === bf) {
|
|
1159
|
-
throw er;
|
|
1160
|
-
}
|
|
1161
|
-
};
|
|
1162
|
-
const pcall = (res, rej) => {
|
|
1163
|
-
const fmp = this.#fetchMethod?.(k, v, fetchOpts);
|
|
1164
|
-
if (fmp && fmp instanceof Promise) {
|
|
1165
|
-
fmp.then(v => res(v === undefined ? undefined : v), rej);
|
|
1166
|
-
}
|
|
1167
|
-
// ignored, we go until we finish, regardless.
|
|
1168
|
-
// defer check until we are actually aborting,
|
|
1169
|
-
// so fetchMethod can override.
|
|
1170
|
-
ac.signal.addEventListener('abort', () => {
|
|
1171
|
-
if (!options.ignoreFetchAbort ||
|
|
1172
|
-
options.allowStaleOnFetchAbort) {
|
|
1173
|
-
res(undefined);
|
|
1174
|
-
// when it eventually resolves, update the cache.
|
|
1175
|
-
if (options.allowStaleOnFetchAbort) {
|
|
1176
|
-
res = v => cb(v, true);
|
|
1177
|
-
}
|
|
1178
|
-
}
|
|
1179
|
-
});
|
|
1180
|
-
};
|
|
1181
|
-
if (options.status)
|
|
1182
|
-
options.status.fetchDispatched = true;
|
|
1183
|
-
const p = new Promise(pcall).then(cb, eb);
|
|
1184
|
-
const bf = Object.assign(p, {
|
|
1185
|
-
__abortController: ac,
|
|
1186
|
-
__staleWhileFetching: v,
|
|
1187
|
-
__returned: undefined,
|
|
1188
|
-
});
|
|
1189
|
-
if (index === undefined) {
|
|
1190
|
-
// internal, don't expose status.
|
|
1191
|
-
this.set(k, bf, { ...fetchOpts.options, status: undefined });
|
|
1192
|
-
index = this.#keyMap.get(k);
|
|
1193
|
-
}
|
|
1194
|
-
else {
|
|
1195
|
-
this.#valList[index] = bf;
|
|
1196
|
-
}
|
|
1197
|
-
return bf;
|
|
1198
|
-
}
|
|
1199
|
-
#isBackgroundFetch(p) {
|
|
1200
|
-
if (!this.#hasFetchMethod)
|
|
1201
|
-
return false;
|
|
1202
|
-
const b = p;
|
|
1203
|
-
return (!!b &&
|
|
1204
|
-
b instanceof Promise &&
|
|
1205
|
-
b.hasOwnProperty('__staleWhileFetching') &&
|
|
1206
|
-
b.__abortController instanceof AC);
|
|
1207
|
-
}
|
|
1208
|
-
async fetch(k, fetchOptions = {}) {
|
|
1209
|
-
const {
|
|
1210
|
-
// get options
|
|
1211
|
-
allowStale = this.allowStale, updateAgeOnGet = this.updateAgeOnGet, noDeleteOnStaleGet = this.noDeleteOnStaleGet,
|
|
1212
|
-
// set options
|
|
1213
|
-
ttl = this.ttl, noDisposeOnSet = this.noDisposeOnSet, size = 0, sizeCalculation = this.sizeCalculation, noUpdateTTL = this.noUpdateTTL,
|
|
1214
|
-
// fetch exclusive options
|
|
1215
|
-
noDeleteOnFetchRejection = this.noDeleteOnFetchRejection, allowStaleOnFetchRejection = this.allowStaleOnFetchRejection, ignoreFetchAbort = this.ignoreFetchAbort, allowStaleOnFetchAbort = this.allowStaleOnFetchAbort, context, forceRefresh = false, status, signal, } = fetchOptions;
|
|
1216
|
-
if (!this.#hasFetchMethod) {
|
|
1217
|
-
if (status)
|
|
1218
|
-
status.fetch = 'get';
|
|
1219
|
-
return this.get(k, {
|
|
1220
|
-
allowStale,
|
|
1221
|
-
updateAgeOnGet,
|
|
1222
|
-
noDeleteOnStaleGet,
|
|
1223
|
-
status,
|
|
1224
|
-
});
|
|
1225
|
-
}
|
|
1226
|
-
const options = {
|
|
1227
|
-
allowStale,
|
|
1228
|
-
updateAgeOnGet,
|
|
1229
|
-
noDeleteOnStaleGet,
|
|
1230
|
-
ttl,
|
|
1231
|
-
noDisposeOnSet,
|
|
1232
|
-
size,
|
|
1233
|
-
sizeCalculation,
|
|
1234
|
-
noUpdateTTL,
|
|
1235
|
-
noDeleteOnFetchRejection,
|
|
1236
|
-
allowStaleOnFetchRejection,
|
|
1237
|
-
allowStaleOnFetchAbort,
|
|
1238
|
-
ignoreFetchAbort,
|
|
1239
|
-
status,
|
|
1240
|
-
signal,
|
|
1241
|
-
};
|
|
1242
|
-
let index = this.#keyMap.get(k);
|
|
1243
|
-
if (index === undefined) {
|
|
1244
|
-
if (status)
|
|
1245
|
-
status.fetch = 'miss';
|
|
1246
|
-
const p = this.#backgroundFetch(k, index, options, context);
|
|
1247
|
-
return (p.__returned = p);
|
|
1248
|
-
}
|
|
1249
|
-
else {
|
|
1250
|
-
// in cache, maybe already fetching
|
|
1251
|
-
const v = this.#valList[index];
|
|
1252
|
-
if (this.#isBackgroundFetch(v)) {
|
|
1253
|
-
const stale = allowStale && v.__staleWhileFetching !== undefined;
|
|
1254
|
-
if (status) {
|
|
1255
|
-
status.fetch = 'inflight';
|
|
1256
|
-
if (stale)
|
|
1257
|
-
status.returnedStale = true;
|
|
1258
|
-
}
|
|
1259
|
-
return stale ? v.__staleWhileFetching : (v.__returned = v);
|
|
1260
|
-
}
|
|
1261
|
-
// if we force a refresh, that means do NOT serve the cached value,
|
|
1262
|
-
// unless we are already in the process of refreshing the cache.
|
|
1263
|
-
const isStale = this.#isStale(index);
|
|
1264
|
-
if (!forceRefresh && !isStale) {
|
|
1265
|
-
if (status)
|
|
1266
|
-
status.fetch = 'hit';
|
|
1267
|
-
this.#moveToTail(index);
|
|
1268
|
-
if (updateAgeOnGet) {
|
|
1269
|
-
this.#updateItemAge(index);
|
|
1270
|
-
}
|
|
1271
|
-
if (status)
|
|
1272
|
-
this.#statusTTL(status, index);
|
|
1273
|
-
return v;
|
|
1274
|
-
}
|
|
1275
|
-
// ok, it is stale or a forced refresh, and not already fetching.
|
|
1276
|
-
// refresh the cache.
|
|
1277
|
-
const p = this.#backgroundFetch(k, index, options, context);
|
|
1278
|
-
const hasStale = p.__staleWhileFetching !== undefined;
|
|
1279
|
-
const staleVal = hasStale && allowStale;
|
|
1280
|
-
if (status) {
|
|
1281
|
-
status.fetch = isStale ? 'stale' : 'refresh';
|
|
1282
|
-
if (staleVal && isStale)
|
|
1283
|
-
status.returnedStale = true;
|
|
1284
|
-
}
|
|
1285
|
-
return staleVal ? p.__staleWhileFetching : (p.__returned = p);
|
|
1286
|
-
}
|
|
1287
|
-
}
|
|
1288
|
-
/**
|
|
1289
|
-
* Return a value from the cache. Will update the recency of the cache
|
|
1290
|
-
* entry found.
|
|
1291
|
-
*
|
|
1292
|
-
* If the key is not found, get() will return `undefined`.
|
|
1293
|
-
*/
|
|
1294
|
-
get(k, getOptions = {}) {
|
|
1295
|
-
const { allowStale = this.allowStale, updateAgeOnGet = this.updateAgeOnGet, noDeleteOnStaleGet = this.noDeleteOnStaleGet, status, } = getOptions;
|
|
1296
|
-
const index = this.#keyMap.get(k);
|
|
1297
|
-
if (index !== undefined) {
|
|
1298
|
-
const value = this.#valList[index];
|
|
1299
|
-
const fetching = this.#isBackgroundFetch(value);
|
|
1300
|
-
if (status)
|
|
1301
|
-
this.#statusTTL(status, index);
|
|
1302
|
-
if (this.#isStale(index)) {
|
|
1303
|
-
if (status)
|
|
1304
|
-
status.get = 'stale';
|
|
1305
|
-
// delete only if not an in-flight background fetch
|
|
1306
|
-
if (!fetching) {
|
|
1307
|
-
if (!noDeleteOnStaleGet) {
|
|
1308
|
-
this.delete(k);
|
|
1309
|
-
}
|
|
1310
|
-
if (status && allowStale)
|
|
1311
|
-
status.returnedStale = true;
|
|
1312
|
-
return allowStale ? value : undefined;
|
|
1313
|
-
}
|
|
1314
|
-
else {
|
|
1315
|
-
if (status &&
|
|
1316
|
-
allowStale &&
|
|
1317
|
-
value.__staleWhileFetching !== undefined) {
|
|
1318
|
-
status.returnedStale = true;
|
|
1319
|
-
}
|
|
1320
|
-
return allowStale ? value.__staleWhileFetching : undefined;
|
|
1321
|
-
}
|
|
1322
|
-
}
|
|
1323
|
-
else {
|
|
1324
|
-
if (status)
|
|
1325
|
-
status.get = 'hit';
|
|
1326
|
-
// if we're currently fetching it, we don't actually have it yet
|
|
1327
|
-
// it's not stale, which means this isn't a staleWhileRefetching.
|
|
1328
|
-
// If it's not stale, and fetching, AND has a __staleWhileFetching
|
|
1329
|
-
// value, then that means the user fetched with {forceRefresh:true},
|
|
1330
|
-
// so it's safe to return that value.
|
|
1331
|
-
if (fetching) {
|
|
1332
|
-
return value.__staleWhileFetching;
|
|
1333
|
-
}
|
|
1334
|
-
this.#moveToTail(index);
|
|
1335
|
-
if (updateAgeOnGet) {
|
|
1336
|
-
this.#updateItemAge(index);
|
|
1337
|
-
}
|
|
1338
|
-
return value;
|
|
1339
|
-
}
|
|
1340
|
-
}
|
|
1341
|
-
else if (status) {
|
|
1342
|
-
status.get = 'miss';
|
|
1343
|
-
}
|
|
1344
|
-
}
|
|
1345
|
-
#connect(p, n) {
|
|
1346
|
-
this.#prev[n] = p;
|
|
1347
|
-
this.#next[p] = n;
|
|
1348
|
-
}
|
|
1349
|
-
#moveToTail(index) {
|
|
1350
|
-
// if tail already, nothing to do
|
|
1351
|
-
// if head, move head to next[index]
|
|
1352
|
-
// else
|
|
1353
|
-
// move next[prev[index]] to next[index] (head has no prev)
|
|
1354
|
-
// move prev[next[index]] to prev[index]
|
|
1355
|
-
// prev[index] = tail
|
|
1356
|
-
// next[tail] = index
|
|
1357
|
-
// tail = index
|
|
1358
|
-
if (index !== this.#tail) {
|
|
1359
|
-
if (index === this.#head) {
|
|
1360
|
-
this.#head = this.#next[index];
|
|
1361
|
-
}
|
|
1362
|
-
else {
|
|
1363
|
-
this.#connect(this.#prev[index], this.#next[index]);
|
|
1364
|
-
}
|
|
1365
|
-
this.#connect(this.#tail, index);
|
|
1366
|
-
this.#tail = index;
|
|
1367
|
-
}
|
|
1368
|
-
}
|
|
1369
|
-
/**
|
|
1370
|
-
* Deletes a key out of the cache.
|
|
1371
|
-
* Returns true if the key was deleted, false otherwise.
|
|
1372
|
-
*/
|
|
1373
|
-
delete(k) {
|
|
1374
|
-
let deleted = false;
|
|
1375
|
-
if (this.#size !== 0) {
|
|
1376
|
-
const index = this.#keyMap.get(k);
|
|
1377
|
-
if (index !== undefined) {
|
|
1378
|
-
deleted = true;
|
|
1379
|
-
if (this.#size === 1) {
|
|
1380
|
-
this.clear();
|
|
1381
|
-
}
|
|
1382
|
-
else {
|
|
1383
|
-
this.#removeItemSize(index);
|
|
1384
|
-
const v = this.#valList[index];
|
|
1385
|
-
if (this.#isBackgroundFetch(v)) {
|
|
1386
|
-
v.__abortController.abort(new Error('deleted'));
|
|
1387
|
-
}
|
|
1388
|
-
else if (this.#hasDispose || this.#hasDisposeAfter) {
|
|
1389
|
-
if (this.#hasDispose) {
|
|
1390
|
-
this.#dispose?.(v, k, 'delete');
|
|
1391
|
-
}
|
|
1392
|
-
if (this.#hasDisposeAfter) {
|
|
1393
|
-
this.#disposed?.push([v, k, 'delete']);
|
|
1394
|
-
}
|
|
1395
|
-
}
|
|
1396
|
-
this.#keyMap.delete(k);
|
|
1397
|
-
this.#keyList[index] = undefined;
|
|
1398
|
-
this.#valList[index] = undefined;
|
|
1399
|
-
if (index === this.#tail) {
|
|
1400
|
-
this.#tail = this.#prev[index];
|
|
1401
|
-
}
|
|
1402
|
-
else if (index === this.#head) {
|
|
1403
|
-
this.#head = this.#next[index];
|
|
1404
|
-
}
|
|
1405
|
-
else {
|
|
1406
|
-
const pi = this.#prev[index];
|
|
1407
|
-
this.#next[pi] = this.#next[index];
|
|
1408
|
-
const ni = this.#next[index];
|
|
1409
|
-
this.#prev[ni] = this.#prev[index];
|
|
1410
|
-
}
|
|
1411
|
-
this.#size--;
|
|
1412
|
-
this.#free.push(index);
|
|
1413
|
-
}
|
|
1414
|
-
}
|
|
1415
|
-
}
|
|
1416
|
-
if (this.#hasDisposeAfter && this.#disposed?.length) {
|
|
1417
|
-
const dt = this.#disposed;
|
|
1418
|
-
let task;
|
|
1419
|
-
while ((task = dt?.shift())) {
|
|
1420
|
-
this.#disposeAfter?.(...task);
|
|
1421
|
-
}
|
|
1422
|
-
}
|
|
1423
|
-
return deleted;
|
|
1424
|
-
}
|
|
1425
|
-
/**
|
|
1426
|
-
* Clear the cache entirely, throwing away all values.
|
|
1427
|
-
*/
|
|
1428
|
-
clear() {
|
|
1429
|
-
for (const index of this.#rindexes({ allowStale: true })) {
|
|
1430
|
-
const v = this.#valList[index];
|
|
1431
|
-
if (this.#isBackgroundFetch(v)) {
|
|
1432
|
-
v.__abortController.abort(new Error('deleted'));
|
|
1433
|
-
}
|
|
1434
|
-
else {
|
|
1435
|
-
const k = this.#keyList[index];
|
|
1436
|
-
if (this.#hasDispose) {
|
|
1437
|
-
this.#dispose?.(v, k, 'delete');
|
|
1438
|
-
}
|
|
1439
|
-
if (this.#hasDisposeAfter) {
|
|
1440
|
-
this.#disposed?.push([v, k, 'delete']);
|
|
1441
|
-
}
|
|
1442
|
-
}
|
|
1443
|
-
}
|
|
1444
|
-
this.#keyMap.clear();
|
|
1445
|
-
this.#valList.fill(undefined);
|
|
1446
|
-
this.#keyList.fill(undefined);
|
|
1447
|
-
if (this.#ttls && this.#starts) {
|
|
1448
|
-
this.#ttls.fill(0);
|
|
1449
|
-
this.#starts.fill(0);
|
|
1450
|
-
}
|
|
1451
|
-
if (this.#sizes) {
|
|
1452
|
-
this.#sizes.fill(0);
|
|
1453
|
-
}
|
|
1454
|
-
this.#head = 0;
|
|
1455
|
-
this.#tail = 0;
|
|
1456
|
-
this.#free.length = 0;
|
|
1457
|
-
this.#calculatedSize = 0;
|
|
1458
|
-
this.#size = 0;
|
|
1459
|
-
if (this.#hasDisposeAfter && this.#disposed) {
|
|
1460
|
-
const dt = this.#disposed;
|
|
1461
|
-
let task;
|
|
1462
|
-
while ((task = dt?.shift())) {
|
|
1463
|
-
this.#disposeAfter?.(...task);
|
|
1464
|
-
}
|
|
128
|
+
_checkLength() {
|
|
129
|
+
while (__classPrivateFieldGet(this, _Cache_keyArray, "f").length > __classPrivateFieldGet(this, _Cache_maxLength, "f")) {
|
|
130
|
+
const key = __classPrivateFieldGet(this, _Cache_keyArray, "f").shift();
|
|
131
|
+
this.delete(key);
|
|
1465
132
|
}
|
|
1466
133
|
}
|
|
1467
134
|
}
|
|
135
|
+
_Cache_keyArray = new WeakMap(), _Cache_maxLength = new WeakMap();
|
|
1468
136
|
|
|
1469
137
|
const lowlight = lowlight$1.createLowlight(lowlight$1.all);
|
|
1470
138
|
lowlight.register("vue", function hljsDefineVue(hljs) {
|
|
@@ -1542,23 +210,33 @@ Object.defineProperty(highlighter, "setIgnoreSyntaxHighlightList", {
|
|
|
1542
210
|
},
|
|
1543
211
|
});
|
|
1544
212
|
|
|
1545
|
-
|
|
213
|
+
var _File_instances, _File_doAST, _File_doCheck;
|
|
214
|
+
const map = new Cache();
|
|
215
|
+
map.setMaxLength(50);
|
|
216
|
+
map.name = "@git-diff-view/core";
|
|
217
|
+
if (typeof globalThis !== "undefined") {
|
|
218
|
+
if (Array.isArray(globalThis.__diff_cache__)) {
|
|
219
|
+
globalThis.__diff_cache__ = globalThis.__diff_cache__.filter((i) => i !== map);
|
|
220
|
+
if (globalThis.__diff_cache__.length > 0) {
|
|
221
|
+
console.warn("there are multiple instance of @git-diff-view/core in the one environment!");
|
|
222
|
+
}
|
|
223
|
+
globalThis.__diff_cache__.push(map);
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
globalThis.__diff_cache__ = [map];
|
|
227
|
+
}
|
|
228
|
+
}
|
|
1546
229
|
class File {
|
|
1547
|
-
raw;
|
|
1548
|
-
lang;
|
|
1549
|
-
fileName;
|
|
1550
|
-
ast;
|
|
1551
|
-
rawFile = {};
|
|
1552
|
-
hasDoRaw = false;
|
|
1553
|
-
rawLength;
|
|
1554
|
-
syntaxFile = {};
|
|
1555
|
-
hasDoSyntax = false;
|
|
1556
|
-
syntaxLength;
|
|
1557
|
-
maxLineNumber = 0;
|
|
1558
230
|
constructor(raw, lang, fileName) {
|
|
231
|
+
_File_instances.add(this);
|
|
1559
232
|
this.raw = raw;
|
|
1560
233
|
this.lang = lang;
|
|
1561
234
|
this.fileName = fileName;
|
|
235
|
+
this.rawFile = {};
|
|
236
|
+
this.hasDoRaw = false;
|
|
237
|
+
this.syntaxFile = {};
|
|
238
|
+
this.hasDoSyntax = false;
|
|
239
|
+
this.maxLineNumber = 0;
|
|
1562
240
|
Object.defineProperty(this, "__v_skip", { value: true });
|
|
1563
241
|
}
|
|
1564
242
|
doSyntax({ autoDetectLang, registerHighlighter, }) {
|
|
@@ -1592,9 +270,9 @@ class File {
|
|
|
1592
270
|
else {
|
|
1593
271
|
this.ast = _highlighter.highlightAuto(this.raw);
|
|
1594
272
|
}
|
|
1595
|
-
this
|
|
273
|
+
__classPrivateFieldGet(this, _File_instances, "m", _File_doAST).call(this);
|
|
1596
274
|
{
|
|
1597
|
-
this
|
|
275
|
+
__classPrivateFieldGet(this, _File_instances, "m", _File_doCheck).call(this);
|
|
1598
276
|
}
|
|
1599
277
|
this.hasDoSyntax = true;
|
|
1600
278
|
}
|
|
@@ -1619,102 +297,102 @@ class File {
|
|
|
1619
297
|
// );
|
|
1620
298
|
this.hasDoRaw = true;
|
|
1621
299
|
}
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
}
|
|
1640
|
-
syntaxObj[lineNumber] = item;
|
|
1641
|
-
}
|
|
1642
|
-
else {
|
|
1643
|
-
node.startIndex = syntaxObj[lineNumber].valueLength;
|
|
1644
|
-
node.endIndex = node.startIndex + valueLength - 1;
|
|
1645
|
-
syntaxObj[lineNumber].value += node.value;
|
|
1646
|
-
syntaxObj[lineNumber].valueLength += valueLength;
|
|
1647
|
-
syntaxObj[lineNumber].nodeList.push({ node, wrapper });
|
|
1648
|
-
}
|
|
1649
|
-
node.lineNumber = lineNumber;
|
|
1650
|
-
return;
|
|
1651
|
-
}
|
|
1652
|
-
const lines = node.value.split("\n");
|
|
1653
|
-
node.children = node.children || [];
|
|
1654
|
-
for (let i = 0; i < lines.length; i++) {
|
|
1655
|
-
const _value = i === lines.length - 1 ? lines[i] : lines[i] + "\n";
|
|
1656
|
-
const _lineNumber = i === 0 ? lineNumber : ++lineNumber;
|
|
1657
|
-
const _valueLength = _value.length;
|
|
1658
|
-
const _node = {
|
|
1659
|
-
type: "text",
|
|
1660
|
-
value: _value,
|
|
1661
|
-
startIndex: Infinity,
|
|
1662
|
-
endIndex: Infinity,
|
|
1663
|
-
lineNumber: _lineNumber,
|
|
300
|
+
}
|
|
301
|
+
_File_instances = new WeakSet(), _File_doAST = function _File_doAST() {
|
|
302
|
+
const ast = this.ast;
|
|
303
|
+
let lineNumber = 1;
|
|
304
|
+
const syntaxObj = this.syntaxFile;
|
|
305
|
+
const loopAST = (nodes, wrapper) => {
|
|
306
|
+
nodes.forEach((node) => {
|
|
307
|
+
if (node.type === "text") {
|
|
308
|
+
if (node.value.indexOf("\n") === -1) {
|
|
309
|
+
const valueLength = node.value.length;
|
|
310
|
+
if (!syntaxObj[lineNumber]) {
|
|
311
|
+
node.startIndex = 0;
|
|
312
|
+
node.endIndex = valueLength - 1;
|
|
313
|
+
const item = {
|
|
314
|
+
value: node.value,
|
|
315
|
+
lineNumber,
|
|
316
|
+
valueLength,
|
|
317
|
+
nodeList: [{ node, wrapper }],
|
|
1664
318
|
};
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
};
|
|
1674
|
-
syntaxObj[_lineNumber] = item;
|
|
1675
|
-
}
|
|
1676
|
-
else {
|
|
1677
|
-
_node.startIndex = syntaxObj[_lineNumber].valueLength;
|
|
1678
|
-
_node.endIndex = _node.startIndex + _valueLength - 1;
|
|
1679
|
-
syntaxObj[_lineNumber].value += _value;
|
|
1680
|
-
syntaxObj[_lineNumber].valueLength += _valueLength;
|
|
1681
|
-
syntaxObj[_lineNumber].nodeList.push({ node: _node, wrapper });
|
|
1682
|
-
}
|
|
1683
|
-
node.children.push(_node);
|
|
319
|
+
syntaxObj[lineNumber] = item;
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
node.startIndex = syntaxObj[lineNumber].valueLength;
|
|
323
|
+
node.endIndex = node.startIndex + valueLength - 1;
|
|
324
|
+
syntaxObj[lineNumber].value += node.value;
|
|
325
|
+
syntaxObj[lineNumber].valueLength += valueLength;
|
|
326
|
+
syntaxObj[lineNumber].nodeList.push({ node, wrapper });
|
|
1684
327
|
}
|
|
1685
328
|
node.lineNumber = lineNumber;
|
|
1686
329
|
return;
|
|
1687
330
|
}
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
331
|
+
const lines = node.value.split("\n");
|
|
332
|
+
node.children = node.children || [];
|
|
333
|
+
for (let i = 0; i < lines.length; i++) {
|
|
334
|
+
const _value = i === lines.length - 1 ? lines[i] : lines[i] + "\n";
|
|
335
|
+
const _lineNumber = i === 0 ? lineNumber : ++lineNumber;
|
|
336
|
+
const _valueLength = _value.length;
|
|
337
|
+
const _node = {
|
|
338
|
+
type: "text",
|
|
339
|
+
value: _value,
|
|
340
|
+
startIndex: Infinity,
|
|
341
|
+
endIndex: Infinity,
|
|
342
|
+
lineNumber: _lineNumber,
|
|
343
|
+
};
|
|
344
|
+
if (!syntaxObj[_lineNumber]) {
|
|
345
|
+
_node.startIndex = 0;
|
|
346
|
+
_node.endIndex = _valueLength - 1;
|
|
347
|
+
const item = {
|
|
348
|
+
value: _value,
|
|
349
|
+
lineNumber: _lineNumber,
|
|
350
|
+
valueLength: _valueLength,
|
|
351
|
+
nodeList: [{ node: _node, wrapper }],
|
|
352
|
+
};
|
|
353
|
+
syntaxObj[_lineNumber] = item;
|
|
354
|
+
}
|
|
355
|
+
else {
|
|
356
|
+
_node.startIndex = syntaxObj[_lineNumber].valueLength;
|
|
357
|
+
_node.endIndex = _node.startIndex + _valueLength - 1;
|
|
358
|
+
syntaxObj[_lineNumber].value += _value;
|
|
359
|
+
syntaxObj[_lineNumber].valueLength += _valueLength;
|
|
360
|
+
syntaxObj[_lineNumber].nodeList.push({ node: _node, wrapper });
|
|
361
|
+
}
|
|
362
|
+
node.children.push(_node);
|
|
1691
363
|
}
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
loopAST(ast.children);
|
|
1695
|
-
this.syntaxLength = lineNumber;
|
|
1696
|
-
}
|
|
1697
|
-
#doCheck() {
|
|
1698
|
-
if (this.rawLength && this.syntaxLength) {
|
|
1699
|
-
if (this.rawLength !== this.syntaxLength) {
|
|
1700
|
-
console.warn("the rawLength not match for the syntaxLength");
|
|
364
|
+
node.lineNumber = lineNumber;
|
|
365
|
+
return;
|
|
1701
366
|
}
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
367
|
+
if (node.children) {
|
|
368
|
+
loopAST(node.children, node);
|
|
369
|
+
node.lineNumber = lineNumber;
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
};
|
|
373
|
+
loopAST(ast.children);
|
|
374
|
+
this.syntaxLength = lineNumber;
|
|
375
|
+
}, _File_doCheck = function _File_doCheck() {
|
|
376
|
+
if (this.rawLength && this.syntaxLength) {
|
|
377
|
+
if (this.rawLength !== this.syntaxLength) {
|
|
378
|
+
console.warn("the rawLength not match for the syntaxLength");
|
|
1707
379
|
}
|
|
380
|
+
Object.values(this.syntaxFile).forEach(({ value, lineNumber }) => {
|
|
381
|
+
if (value !== this.rawFile[lineNumber]) {
|
|
382
|
+
console.log("some line not match:" + value + " __ " + this.rawFile[lineNumber] + " __ at: " + lineNumber + " lineNumber");
|
|
383
|
+
}
|
|
384
|
+
});
|
|
1708
385
|
}
|
|
1709
|
-
}
|
|
386
|
+
};
|
|
1710
387
|
const getFile = (raw, lang, fileName) => {
|
|
1711
|
-
const key = raw + "--" + "0.0.
|
|
388
|
+
const key = raw + "--" + "0.0.7" + "--" + lang;
|
|
1712
389
|
if (map.has(key))
|
|
1713
390
|
return map.get(key);
|
|
1714
391
|
const file = new File(raw, lang, fileName);
|
|
1715
392
|
map.set(key, file);
|
|
1716
393
|
return file;
|
|
1717
394
|
};
|
|
395
|
+
const _cacheMap = map;
|
|
1718
396
|
|
|
1719
397
|
const maxLength = 1000;
|
|
1720
398
|
/** Get the maximum position in the range. */
|
|
@@ -1792,23 +470,15 @@ function hasRelativeChange(stringA, stringB) {
|
|
|
1792
470
|
}
|
|
1793
471
|
|
|
1794
472
|
/** indicate what a line in the diff represents */
|
|
1795
|
-
|
|
473
|
+
exports.DiffLineType = void 0;
|
|
1796
474
|
(function (DiffLineType) {
|
|
1797
475
|
DiffLineType[DiffLineType["Context"] = 0] = "Context";
|
|
1798
476
|
DiffLineType[DiffLineType["Add"] = 1] = "Add";
|
|
1799
477
|
DiffLineType[DiffLineType["Delete"] = 2] = "Delete";
|
|
1800
478
|
DiffLineType[DiffLineType["Hunk"] = 3] = "Hunk";
|
|
1801
|
-
})(DiffLineType || (DiffLineType = {}));
|
|
479
|
+
})(exports.DiffLineType || (exports.DiffLineType = {}));
|
|
1802
480
|
/** track details related to each line in the diff */
|
|
1803
481
|
class DiffLine {
|
|
1804
|
-
text;
|
|
1805
|
-
type;
|
|
1806
|
-
originalLineNumber;
|
|
1807
|
-
oldLineNumber;
|
|
1808
|
-
newLineNumber;
|
|
1809
|
-
noTrailingNewLine;
|
|
1810
|
-
needRematch;
|
|
1811
|
-
range;
|
|
1812
482
|
constructor(text, type,
|
|
1813
483
|
// Line number in the original diff patch (before expanding it), or null if
|
|
1814
484
|
// it was added as part of a diff expansion action.
|
|
@@ -1826,7 +496,7 @@ class DiffLine {
|
|
|
1826
496
|
return new DiffLine(this.text, this.type, this.originalLineNumber, this.oldLineNumber, this.newLineNumber, noTrailingNewLine);
|
|
1827
497
|
}
|
|
1828
498
|
isIncludeableLine() {
|
|
1829
|
-
return this.type === DiffLineType.Add || this.type === DiffLineType.Delete;
|
|
499
|
+
return this.type === exports.DiffLineType.Add || this.type === exports.DiffLineType.Delete;
|
|
1830
500
|
}
|
|
1831
501
|
/** The content of the line, i.e., without the line type marker. */
|
|
1832
502
|
get content() {
|
|
@@ -1844,7 +514,7 @@ class DiffLine {
|
|
|
1844
514
|
const checkDiffLineIncludeChange = (diffLine) => {
|
|
1845
515
|
if (!diffLine)
|
|
1846
516
|
return false;
|
|
1847
|
-
return diffLine.type === DiffLineType.Add || diffLine.type === DiffLineType.Delete;
|
|
517
|
+
return diffLine.type === exports.DiffLineType.Add || diffLine.type === exports.DiffLineType.Delete;
|
|
1848
518
|
};
|
|
1849
519
|
|
|
1850
520
|
var DiffHunkExpansionType;
|
|
@@ -1871,11 +541,6 @@ var DiffHunkExpansionType;
|
|
|
1871
541
|
})(DiffHunkExpansionType || (DiffHunkExpansionType = {}));
|
|
1872
542
|
/** each diff is made up of a number of hunks */
|
|
1873
543
|
class DiffHunk {
|
|
1874
|
-
header;
|
|
1875
|
-
lines;
|
|
1876
|
-
unifiedDiffStart;
|
|
1877
|
-
unifiedDiffEnd;
|
|
1878
|
-
expansionType;
|
|
1879
544
|
/**
|
|
1880
545
|
* @param header The details from the diff hunk header about the line start and patch length.
|
|
1881
546
|
* @param lines The contents - context and changes - of the diff section.
|
|
@@ -1903,10 +568,6 @@ class DiffHunk {
|
|
|
1903
568
|
}
|
|
1904
569
|
/** details about the start and end of a diff hunk */
|
|
1905
570
|
class DiffHunkHeader {
|
|
1906
|
-
oldStartLine;
|
|
1907
|
-
oldLineCount;
|
|
1908
|
-
newStartLine;
|
|
1909
|
-
newLineCount;
|
|
1910
571
|
/**
|
|
1911
572
|
* @param oldStartLine The line in the old (or original) file where this diff hunk starts.
|
|
1912
573
|
* @param oldLineCount The number of lines in the old (or original) file that this diff hunk covers
|
|
@@ -1937,6 +598,7 @@ function assertNever(_, message) {
|
|
|
1937
598
|
}
|
|
1938
599
|
/** Utility function for getting the digit count of the largest line number in an array of diff hunks */
|
|
1939
600
|
function getLargestLineNumber(hunks) {
|
|
601
|
+
var _a, _b;
|
|
1940
602
|
if (hunks.length === 0) {
|
|
1941
603
|
return 0;
|
|
1942
604
|
}
|
|
@@ -1944,11 +606,11 @@ function getLargestLineNumber(hunks) {
|
|
|
1944
606
|
const hunk = hunks[i];
|
|
1945
607
|
for (let j = hunk.lines.length - 1; j >= 0; j--) {
|
|
1946
608
|
const line = hunk.lines[j];
|
|
1947
|
-
if (line.type === DiffLineType.Hunk) {
|
|
609
|
+
if (line.type === exports.DiffLineType.Hunk) {
|
|
1948
610
|
continue;
|
|
1949
611
|
}
|
|
1950
|
-
const newLineNumber = line.newLineNumber
|
|
1951
|
-
const oldLineNumber = line.oldLineNumber
|
|
612
|
+
const newLineNumber = (_a = line.newLineNumber) !== null && _a !== void 0 ? _a : 0;
|
|
613
|
+
const oldLineNumber = (_b = line.oldLineNumber) !== null && _b !== void 0 ? _b : 0;
|
|
1952
614
|
return newLineNumber > oldLineNumber ? newLineNumber : oldLineNumber;
|
|
1953
615
|
}
|
|
1954
616
|
}
|
|
@@ -2056,24 +718,6 @@ const DiffLinePrefixChars = new Set([
|
|
|
2056
718
|
* See https://www.gnu.org/software/diffutils/manual/html_node/Detailed-Unified.html
|
|
2057
719
|
*/
|
|
2058
720
|
class DiffParser {
|
|
2059
|
-
/**
|
|
2060
|
-
* Line start pointer.
|
|
2061
|
-
*
|
|
2062
|
-
* The offset into the text property where the current line starts (ie either zero
|
|
2063
|
-
* or one character ahead of the last newline character).
|
|
2064
|
-
*/
|
|
2065
|
-
ls;
|
|
2066
|
-
/**
|
|
2067
|
-
* Line end pointer.
|
|
2068
|
-
*
|
|
2069
|
-
* The offset into the text property where the current line ends (ie it points to
|
|
2070
|
-
* the newline character) or -1 if the line boundary hasn't been determined yet
|
|
2071
|
-
*/
|
|
2072
|
-
le;
|
|
2073
|
-
/**
|
|
2074
|
-
* The text buffer containing the raw, unified diff output to be parsed
|
|
2075
|
-
*/
|
|
2076
|
-
text;
|
|
2077
721
|
constructor() {
|
|
2078
722
|
Object.defineProperty(this, "__v_skip", { value: true });
|
|
2079
723
|
this.reset();
|
|
@@ -2257,7 +901,7 @@ class DiffParser {
|
|
|
2257
901
|
}
|
|
2258
902
|
const header = this.parseHunkHeader(headerLine);
|
|
2259
903
|
const lines = new Array();
|
|
2260
|
-
lines.push(new DiffLine(headerLine, DiffLineType.Hunk, 1, null, null));
|
|
904
|
+
lines.push(new DiffLine(headerLine, exports.DiffLineType.Hunk, 1, null, null));
|
|
2261
905
|
let c;
|
|
2262
906
|
let rollingDiffBeforeCounter = header.oldStartLine;
|
|
2263
907
|
let rollingDiffAfterCounter = header.newStartLine;
|
|
@@ -2286,13 +930,13 @@ class DiffParser {
|
|
|
2286
930
|
}
|
|
2287
931
|
let diffLine;
|
|
2288
932
|
if (c === DiffPrefixAdd) {
|
|
2289
|
-
diffLine = new DiffLine(line, DiffLineType.Add, diffLineNumber, null, rollingDiffAfterCounter++);
|
|
933
|
+
diffLine = new DiffLine(line, exports.DiffLineType.Add, diffLineNumber, null, rollingDiffAfterCounter++);
|
|
2290
934
|
}
|
|
2291
935
|
else if (c === DiffPrefixDelete) {
|
|
2292
|
-
diffLine = new DiffLine(line, DiffLineType.Delete, diffLineNumber, rollingDiffBeforeCounter++, null);
|
|
936
|
+
diffLine = new DiffLine(line, exports.DiffLineType.Delete, diffLineNumber, rollingDiffBeforeCounter++, null);
|
|
2293
937
|
}
|
|
2294
938
|
else if (c === DiffPrefixContext) {
|
|
2295
|
-
diffLine = new DiffLine(line, DiffLineType.Context, diffLineNumber, rollingDiffBeforeCounter++, rollingDiffAfterCounter++);
|
|
939
|
+
diffLine = new DiffLine(line, exports.DiffLineType.Context, diffLineNumber, rollingDiffBeforeCounter++, rollingDiffAfterCounter++);
|
|
2296
940
|
}
|
|
2297
941
|
else {
|
|
2298
942
|
return assertNever(c, `Unknown DiffLinePrefix: ${c}`);
|
|
@@ -2369,288 +1013,437 @@ class DiffParser {
|
|
|
2369
1013
|
}
|
|
2370
1014
|
const parseInstance = new DiffParser();
|
|
2371
1015
|
|
|
2372
|
-
|
|
2373
|
-
/* eslint-disable max-lines */
|
|
1016
|
+
var _DiffFile_instances, _DiffFile_oldFileResult, _DiffFile_newFileResult, _DiffFile_diffListResults, _DiffFile_diffLines, _DiffFile_oldFileDiffLines, _DiffFile_newFileDiffLines, _DiffFile_oldFileLines, _DiffFile_newFileLines, _DiffFile_oldFileSyntaxLines, _DiffFile_newFileSyntaxLines, _DiffFile_oldFilePlaceholderLines, _DiffFile_newFilePlaceholderLines, _DiffFile_splitLeftLines, _DiffFile_splitRightLines, _DiffFile_splitHunksLines, _DiffFile_unifiedLines, _DiffFile_unifiedHunksLines, _DiffFile_listeners, _DiffFile_hasInitRaw, _DiffFile_hasInitSyntax, _DiffFile_hasBuildSplit, _DiffFile_hasBuildUnified, _DiffFile_updateCount, _DiffFile_composeByDiff, _DiffFile_id, _DiffFile_clonedInstance, _DiffFile_doDiff, _DiffFile_doFile, _DiffFile_composeRaw, _DiffFile_composeFile, _DiffFile_composeDiff, _DiffFile_composeSyntax, _DiffFile_getOldDiffLine, _DiffFile_getNewDiffLine, _DiffFile_getOldRawLine, _DiffFile_getNewRawLine;
|
|
2374
1017
|
const composeLen = 40;
|
|
2375
|
-
const idSet = new Set();
|
|
2376
|
-
class DiffFile {
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
#diffListResults;
|
|
2383
|
-
#diffLines;
|
|
2384
|
-
#oldFileDiffLines;
|
|
2385
|
-
#newFileDiffLines;
|
|
2386
|
-
#oldFileLines;
|
|
2387
|
-
#newFileLines;
|
|
2388
|
-
#oldFileSyntaxLines;
|
|
2389
|
-
#newFileSyntaxLines;
|
|
2390
|
-
#splitLeftLines = [];
|
|
2391
|
-
#splitRightLines = [];
|
|
2392
|
-
#splitHunksLines;
|
|
2393
|
-
#unifiedLines = [];
|
|
2394
|
-
#unifiedHunksLines;
|
|
2395
|
-
#listeners = [];
|
|
2396
|
-
#hasInitRaw = false;
|
|
2397
|
-
#hasInitSyntax = false;
|
|
2398
|
-
#hasBuildSplit = false;
|
|
2399
|
-
#hasBuildUnified = false;
|
|
2400
|
-
#updateCount = 0;
|
|
2401
|
-
#composeByDiff = false;
|
|
2402
|
-
_version_ = "0.0.6";
|
|
2403
|
-
_oldFileContent = "";
|
|
2404
|
-
_oldFileLang = "";
|
|
2405
|
-
_newFileContent = "";
|
|
2406
|
-
_newFileLang = "";
|
|
2407
|
-
diffLineLength = 0;
|
|
2408
|
-
splitLineLength = 0;
|
|
2409
|
-
unifiedLineLength = 0;
|
|
2410
|
-
#id = "";
|
|
2411
|
-
#clonedInstance = new Map();
|
|
2412
|
-
static createInstance(data, bundle) {
|
|
2413
|
-
const instance = new DiffFile(data?.oldFile?.fileName || "", data?.oldFile?.content || "", data?.newFile?.fileName || "", data?.newFile?.content || "", data?.hunks || [], data?.oldFile?.fileLang || "", data?.newFile?.fileLang || "");
|
|
2414
|
-
if (bundle) {
|
|
2415
|
-
instance.mergeBundle(bundle);
|
|
2416
|
-
}
|
|
2417
|
-
return instance;
|
|
2418
|
-
}
|
|
2419
|
-
constructor(_oldFileName, _oldFileContent, _newFileName, _newFileContent, _diffList, _oldFileLang, _newFileLang) {
|
|
2420
|
-
this._oldFileName = _oldFileName;
|
|
2421
|
-
this._newFileName = _newFileName;
|
|
2422
|
-
this._diffList = _diffList;
|
|
2423
|
-
Object.defineProperty(this, "__v_skip", { value: true });
|
|
2424
|
-
let oldContent = _oldFileContent;
|
|
2425
|
-
let newContent = _newFileContent;
|
|
2426
|
-
const diffList = Array.from(new Set(_diffList));
|
|
2427
|
-
Object.defineProperties(this, {
|
|
2428
|
-
_oldFileName: { get: () => _oldFileName },
|
|
2429
|
-
_newFileName: { get: () => _newFileName },
|
|
2430
|
-
_oldFileLang: { get: () => getLang(_oldFileLang || _oldFileName || _newFileLang || _newFileName) || "txt" },
|
|
2431
|
-
_newFileLang: { get: () => getLang(_newFileLang || _newFileName || _oldFileLang || _oldFileName) || "txt" },
|
|
2432
|
-
_oldFileContent: {
|
|
2433
|
-
get: () => oldContent,
|
|
2434
|
-
set: (v) => (oldContent = v),
|
|
2435
|
-
},
|
|
2436
|
-
_newFileContent: {
|
|
2437
|
-
get: () => newContent,
|
|
2438
|
-
set: (v) => (newContent = v),
|
|
2439
|
-
},
|
|
2440
|
-
_diffList: { get: () => diffList },
|
|
2441
|
-
});
|
|
2442
|
-
this.initId();
|
|
2443
|
-
}
|
|
2444
|
-
#doDiff() {
|
|
2445
|
-
if (!this._diffList)
|
|
2446
|
-
return;
|
|
2447
|
-
this.#diffListResults = this._diffList.map((s) => parseInstance.parse(s));
|
|
2448
|
-
}
|
|
2449
|
-
#doFile() {
|
|
2450
|
-
if (!this._oldFileContent && !this._newFileContent)
|
|
2451
|
-
return;
|
|
2452
|
-
if (this._oldFileContent) {
|
|
2453
|
-
this.#oldFileResult = getFile(this._oldFileContent, this._oldFileLang, this._oldFileName);
|
|
2454
|
-
}
|
|
2455
|
-
if (this._newFileContent) {
|
|
2456
|
-
this.#newFileResult = getFile(this._newFileContent, this._newFileLang, this._newFileName);
|
|
1018
|
+
const idSet = new Set();
|
|
1019
|
+
class DiffFile {
|
|
1020
|
+
static createInstance(data, bundle) {
|
|
1021
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1022
|
+
const instance = new DiffFile(((_a = data === null || data === void 0 ? void 0 : data.oldFile) === null || _a === void 0 ? void 0 : _a.fileName) || "", ((_b = data === null || data === void 0 ? void 0 : data.oldFile) === null || _b === void 0 ? void 0 : _b.content) || "", ((_c = data === null || data === void 0 ? void 0 : data.newFile) === null || _c === void 0 ? void 0 : _c.fileName) || "", ((_d = data === null || data === void 0 ? void 0 : data.newFile) === null || _d === void 0 ? void 0 : _d.content) || "", (data === null || data === void 0 ? void 0 : data.hunks) || [], ((_e = data === null || data === void 0 ? void 0 : data.oldFile) === null || _e === void 0 ? void 0 : _e.fileLang) || "", ((_f = data === null || data === void 0 ? void 0 : data.newFile) === null || _f === void 0 ? void 0 : _f.fileLang) || "");
|
|
1023
|
+
if (bundle) {
|
|
1024
|
+
instance.mergeBundle(bundle);
|
|
2457
1025
|
}
|
|
1026
|
+
return instance;
|
|
2458
1027
|
}
|
|
2459
|
-
|
|
2460
|
-
this
|
|
2461
|
-
this
|
|
2462
|
-
this
|
|
2463
|
-
this
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
1028
|
+
constructor(_oldFileName, _oldFileContent, _newFileName, _newFileContent, _diffList, _oldFileLang, _newFileLang) {
|
|
1029
|
+
_DiffFile_instances.add(this);
|
|
1030
|
+
this._oldFileName = _oldFileName;
|
|
1031
|
+
this._newFileName = _newFileName;
|
|
1032
|
+
this._diffList = _diffList;
|
|
1033
|
+
_DiffFile_oldFileResult.set(this, void 0);
|
|
1034
|
+
_DiffFile_newFileResult.set(this, void 0);
|
|
1035
|
+
_DiffFile_diffListResults.set(this, void 0);
|
|
1036
|
+
_DiffFile_diffLines.set(this, void 0);
|
|
1037
|
+
_DiffFile_oldFileDiffLines.set(this, void 0);
|
|
1038
|
+
_DiffFile_newFileDiffLines.set(this, void 0);
|
|
1039
|
+
_DiffFile_oldFileLines.set(this, void 0);
|
|
1040
|
+
_DiffFile_newFileLines.set(this, void 0);
|
|
1041
|
+
_DiffFile_oldFileSyntaxLines.set(this, void 0);
|
|
1042
|
+
_DiffFile_newFileSyntaxLines.set(this, void 0);
|
|
1043
|
+
_DiffFile_oldFilePlaceholderLines.set(this, void 0);
|
|
1044
|
+
_DiffFile_newFilePlaceholderLines.set(this, void 0);
|
|
1045
|
+
_DiffFile_splitLeftLines.set(this, []);
|
|
1046
|
+
_DiffFile_splitRightLines.set(this, []);
|
|
1047
|
+
_DiffFile_splitHunksLines.set(this, void 0);
|
|
1048
|
+
_DiffFile_unifiedLines.set(this, []);
|
|
1049
|
+
_DiffFile_unifiedHunksLines.set(this, void 0);
|
|
1050
|
+
_DiffFile_listeners.set(this, []);
|
|
1051
|
+
_DiffFile_hasInitRaw.set(this, false);
|
|
1052
|
+
_DiffFile_hasInitSyntax.set(this, false);
|
|
1053
|
+
_DiffFile_hasBuildSplit.set(this, false);
|
|
1054
|
+
_DiffFile_hasBuildUnified.set(this, false);
|
|
1055
|
+
_DiffFile_updateCount.set(this, 0);
|
|
1056
|
+
_DiffFile_composeByDiff.set(this, false);
|
|
1057
|
+
this._version_ = "0.0.7";
|
|
1058
|
+
this._oldFileContent = "";
|
|
1059
|
+
this._oldFileLang = "";
|
|
1060
|
+
this._newFileContent = "";
|
|
1061
|
+
this._newFileLang = "";
|
|
1062
|
+
this.diffLineLength = 0;
|
|
1063
|
+
this.splitLineLength = 0;
|
|
1064
|
+
this.unifiedLineLength = 0;
|
|
1065
|
+
_DiffFile_id.set(this, "");
|
|
1066
|
+
_DiffFile_clonedInstance.set(this, new Map());
|
|
1067
|
+
this.getSplitLeftLine = (index) => {
|
|
1068
|
+
return __classPrivateFieldGet(this, _DiffFile_splitLeftLines, "f")[index];
|
|
1069
|
+
};
|
|
1070
|
+
this.getSplitRightLine = (index) => {
|
|
1071
|
+
return __classPrivateFieldGet(this, _DiffFile_splitRightLines, "f")[index];
|
|
1072
|
+
};
|
|
1073
|
+
this.getSplitHunkLine = (index) => {
|
|
1074
|
+
var _a;
|
|
1075
|
+
return (_a = __classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f")) === null || _a === void 0 ? void 0 : _a[index];
|
|
1076
|
+
};
|
|
1077
|
+
this.onSplitHunkExpand = (dir, index, needTrigger = true) => {
|
|
1078
|
+
var _a, _b;
|
|
1079
|
+
const current = (_a = __classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f")) === null || _a === void 0 ? void 0 : _a[index];
|
|
1080
|
+
if (!current || !current.splitInfo)
|
|
1081
|
+
return;
|
|
1082
|
+
if (__classPrivateFieldGet(this, _DiffFile_composeByDiff, "f"))
|
|
1083
|
+
return;
|
|
1084
|
+
if (dir === "all") {
|
|
1085
|
+
for (let i = current.splitInfo.startHiddenIndex; i < current.splitInfo.endHiddenIndex; i++) {
|
|
1086
|
+
const leftLine = __classPrivateFieldGet(this, _DiffFile_splitLeftLines, "f")[i];
|
|
1087
|
+
const rightLine = __classPrivateFieldGet(this, _DiffFile_splitRightLines, "f")[i];
|
|
1088
|
+
if (leftLine === null || leftLine === void 0 ? void 0 : leftLine.isHidden)
|
|
1089
|
+
leftLine.isHidden = false;
|
|
1090
|
+
if (rightLine === null || rightLine === void 0 ? void 0 : rightLine.isHidden)
|
|
1091
|
+
rightLine.isHidden = false;
|
|
1092
|
+
}
|
|
1093
|
+
current.splitInfo = Object.assign(Object.assign(Object.assign({}, current.splitInfo), current.hunkInfo), { plainText: current.text, startHiddenIndex: current.splitInfo.endHiddenIndex });
|
|
1094
|
+
}
|
|
1095
|
+
else if (dir === "down") {
|
|
1096
|
+
for (let i = current.splitInfo.startHiddenIndex; i < current.splitInfo.startHiddenIndex + composeLen; i++) {
|
|
1097
|
+
const leftLine = __classPrivateFieldGet(this, _DiffFile_splitLeftLines, "f")[i];
|
|
1098
|
+
const rightLine = __classPrivateFieldGet(this, _DiffFile_splitRightLines, "f")[i];
|
|
1099
|
+
if (leftLine === null || leftLine === void 0 ? void 0 : leftLine.isHidden)
|
|
1100
|
+
leftLine.isHidden = false;
|
|
1101
|
+
if (rightLine === null || rightLine === void 0 ? void 0 : rightLine.isHidden)
|
|
1102
|
+
rightLine.isHidden = false;
|
|
1103
|
+
}
|
|
1104
|
+
if (current.isLast) {
|
|
1105
|
+
current.splitInfo = Object.assign(Object.assign({}, current.splitInfo), { startHiddenIndex: current.splitInfo.startHiddenIndex + composeLen });
|
|
2478
1106
|
}
|
|
2479
1107
|
else {
|
|
2480
|
-
|
|
2481
|
-
oldFileContent += "\n";
|
|
1108
|
+
current.splitInfo = Object.assign(Object.assign({}, current.splitInfo), { startHiddenIndex: current.splitInfo.startHiddenIndex + composeLen, plainText: `@@ -${current.splitInfo.oldStartIndex},${current.splitInfo.oldLength} +${current.splitInfo.newStartIndex},${current.splitInfo.newLength}` });
|
|
2482
1109
|
}
|
|
2483
1110
|
}
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
1111
|
+
else {
|
|
1112
|
+
if (current.isLast) {
|
|
1113
|
+
console.error("the last hunk can not expand up!");
|
|
1114
|
+
return;
|
|
2488
1115
|
}
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
1116
|
+
for (let i = current.splitInfo.endHiddenIndex - composeLen; i < current.splitInfo.endHiddenIndex; i++) {
|
|
1117
|
+
const leftLine = __classPrivateFieldGet(this, _DiffFile_splitLeftLines, "f")[i];
|
|
1118
|
+
const rightLine = __classPrivateFieldGet(this, _DiffFile_splitRightLines, "f")[i];
|
|
1119
|
+
if (leftLine === null || leftLine === void 0 ? void 0 : leftLine.isHidden)
|
|
1120
|
+
leftLine.isHidden = false;
|
|
1121
|
+
if (rightLine === null || rightLine === void 0 ? void 0 : rightLine.isHidden)
|
|
1122
|
+
rightLine.isHidden = false;
|
|
1123
|
+
}
|
|
1124
|
+
const oldStartIndex = current.splitInfo.oldStartIndex - composeLen;
|
|
1125
|
+
const oldLength = current.splitInfo.oldLength + composeLen;
|
|
1126
|
+
const newStartIndex = current.splitInfo.newStartIndex - composeLen;
|
|
1127
|
+
const newLength = current.splitInfo.newLength + composeLen;
|
|
1128
|
+
current.splitInfo = Object.assign(Object.assign({}, current.splitInfo), { endHiddenIndex: current.splitInfo.endHiddenIndex - composeLen, oldStartIndex,
|
|
1129
|
+
oldLength,
|
|
1130
|
+
newStartIndex,
|
|
1131
|
+
newLength, plainText: `@@ -${oldStartIndex},${oldLength} +${newStartIndex},${newLength}` });
|
|
1132
|
+
(_b = __classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f")) === null || _b === void 0 ? true : delete _b[index];
|
|
1133
|
+
__classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f")[current.splitInfo.endHiddenIndex] = current;
|
|
1134
|
+
}
|
|
1135
|
+
needTrigger && this.notifyAll();
|
|
1136
|
+
};
|
|
1137
|
+
this.getUnifiedLine = (index) => {
|
|
1138
|
+
return __classPrivateFieldGet(this, _DiffFile_unifiedLines, "f")[index];
|
|
1139
|
+
};
|
|
1140
|
+
this.getUnifiedHunkLine = (index) => {
|
|
1141
|
+
var _a;
|
|
1142
|
+
return (_a = __classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f")) === null || _a === void 0 ? void 0 : _a[index];
|
|
1143
|
+
};
|
|
1144
|
+
this.onUnifiedHunkExpand = (dir, index, needTrigger = true) => {
|
|
1145
|
+
var _a, _b, _c;
|
|
1146
|
+
const current = (_a = __classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f")) === null || _a === void 0 ? void 0 : _a[index];
|
|
1147
|
+
if (!current || !current.unifiedInfo)
|
|
1148
|
+
return;
|
|
1149
|
+
if (__classPrivateFieldGet(this, _DiffFile_composeByDiff, "f"))
|
|
1150
|
+
return;
|
|
1151
|
+
if (dir === "all") {
|
|
1152
|
+
for (let i = current.unifiedInfo.startHiddenIndex; i < current.unifiedInfo.endHiddenIndex; i++) {
|
|
1153
|
+
const unifiedLine = (_b = __classPrivateFieldGet(this, _DiffFile_unifiedLines, "f")) === null || _b === void 0 ? void 0 : _b[i];
|
|
1154
|
+
if (unifiedLine === null || unifiedLine === void 0 ? void 0 : unifiedLine.isHidden) {
|
|
1155
|
+
unifiedLine.isHidden = false;
|
|
1156
|
+
}
|
|
2492
1157
|
}
|
|
1158
|
+
current.unifiedInfo = Object.assign(Object.assign(Object.assign({}, current.unifiedInfo), current.hunkInfo), { plainText: current.text, startHiddenIndex: current.unifiedInfo.endHiddenIndex });
|
|
2493
1159
|
}
|
|
2494
|
-
if (
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
}
|
|
2503
|
-
else if (this.#oldFileResult) {
|
|
2504
|
-
let newLineNumber = 1;
|
|
2505
|
-
let oldLineNumber = 1;
|
|
2506
|
-
let newFileContent = "";
|
|
2507
|
-
while (oldLineNumber <= this.#oldFileResult.maxLineNumber) {
|
|
2508
|
-
const newDiffLine = this.#getNewDiffLine(newLineNumber++);
|
|
2509
|
-
if (newDiffLine) {
|
|
2510
|
-
newFileContent += newDiffLine.text;
|
|
2511
|
-
oldLineNumber = newDiffLine.oldLineNumber ? newDiffLine.oldLineNumber + 1 : oldLineNumber;
|
|
1160
|
+
else if (dir === "down") {
|
|
1161
|
+
for (let i = current.unifiedInfo.startHiddenIndex; i < current.unifiedInfo.startHiddenIndex + composeLen; i++) {
|
|
1162
|
+
const unifiedLine = __classPrivateFieldGet(this, _DiffFile_unifiedLines, "f")[i];
|
|
1163
|
+
if (unifiedLine === null || unifiedLine === void 0 ? void 0 : unifiedLine.isHidden)
|
|
1164
|
+
unifiedLine.isHidden = false;
|
|
1165
|
+
}
|
|
1166
|
+
if (current.isLast) {
|
|
1167
|
+
current.unifiedInfo = Object.assign(Object.assign({}, current.unifiedInfo), { startHiddenIndex: current.unifiedInfo.startHiddenIndex + composeLen });
|
|
2512
1168
|
}
|
|
2513
1169
|
else {
|
|
2514
|
-
|
|
1170
|
+
current.unifiedInfo = Object.assign(Object.assign({}, current.unifiedInfo), { startHiddenIndex: current.unifiedInfo.startHiddenIndex + composeLen, plainText: `@@ -${current.unifiedInfo.oldStartIndex},${current.unifiedInfo.oldLength} +${current.unifiedInfo.newStartIndex},${current.unifiedInfo.newLength}` });
|
|
2515
1171
|
}
|
|
2516
1172
|
}
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
}
|
|
2522
|
-
else if (this.#newFileResult) {
|
|
2523
|
-
let oldLineNumber = 1;
|
|
2524
|
-
let newLineNumber = 1;
|
|
2525
|
-
let oldFileContent = "";
|
|
2526
|
-
while (newLineNumber <= this.#newFileResult.maxLineNumber) {
|
|
2527
|
-
const oldDiffLine = this.#getOldDiffLine(oldLineNumber++);
|
|
2528
|
-
if (oldDiffLine) {
|
|
2529
|
-
oldFileContent += oldDiffLine.text;
|
|
2530
|
-
newLineNumber = oldDiffLine.newLineNumber ? oldDiffLine.newLineNumber + 1 : newLineNumber;
|
|
2531
|
-
}
|
|
2532
|
-
else {
|
|
2533
|
-
oldFileContent += this.#getNewRawLine(newLineNumber++);
|
|
1173
|
+
else {
|
|
1174
|
+
if (current.isLast) {
|
|
1175
|
+
console.error("the last hunk can not expand up!");
|
|
1176
|
+
return;
|
|
2534
1177
|
}
|
|
1178
|
+
for (let i = current.unifiedInfo.endHiddenIndex - composeLen; i < current.unifiedInfo.endHiddenIndex; i++) {
|
|
1179
|
+
const unifiedLine = __classPrivateFieldGet(this, _DiffFile_unifiedLines, "f")[i];
|
|
1180
|
+
if (unifiedLine === null || unifiedLine === void 0 ? void 0 : unifiedLine.isHidden)
|
|
1181
|
+
unifiedLine.isHidden = false;
|
|
1182
|
+
}
|
|
1183
|
+
const oldStartIndex = current.unifiedInfo.oldStartIndex - composeLen;
|
|
1184
|
+
const oldLength = current.unifiedInfo.oldLength + composeLen;
|
|
1185
|
+
const newStartIndex = current.unifiedInfo.newStartIndex - composeLen;
|
|
1186
|
+
const newLength = current.unifiedInfo.newLength + composeLen;
|
|
1187
|
+
current.unifiedInfo = Object.assign(Object.assign({}, current.unifiedInfo), { endHiddenIndex: current.unifiedInfo.endHiddenIndex - composeLen, oldStartIndex,
|
|
1188
|
+
oldLength,
|
|
1189
|
+
newStartIndex,
|
|
1190
|
+
newLength, plainText: `@@ -${oldStartIndex},${oldLength} +${newStartIndex},${newLength}` });
|
|
1191
|
+
(_c = __classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f")) === null || _c === void 0 ? true : delete _c[index];
|
|
1192
|
+
__classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f")[current.unifiedInfo.endHiddenIndex] = current;
|
|
1193
|
+
}
|
|
1194
|
+
needTrigger && this.notifyAll();
|
|
1195
|
+
};
|
|
1196
|
+
this.onAllExpand = (mode) => {
|
|
1197
|
+
if (__classPrivateFieldGet(this, _DiffFile_composeByDiff, "f"))
|
|
1198
|
+
return;
|
|
1199
|
+
if (mode === "split") {
|
|
1200
|
+
Object.keys(__classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f") || {}).forEach((key) => {
|
|
1201
|
+
this.onSplitHunkExpand("all", +key, false);
|
|
1202
|
+
});
|
|
1203
|
+
}
|
|
1204
|
+
else {
|
|
1205
|
+
Object.keys(__classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f") || {}).forEach((key) => {
|
|
1206
|
+
this.onUnifiedHunkExpand("all", +key, false);
|
|
1207
|
+
});
|
|
2535
1208
|
}
|
|
2536
|
-
|
|
1209
|
+
this.notifyAll();
|
|
1210
|
+
};
|
|
1211
|
+
this.onAllCollapse = (mode) => {
|
|
1212
|
+
if (__classPrivateFieldGet(this, _DiffFile_composeByDiff, "f"))
|
|
2537
1213
|
return;
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
}
|
|
2543
|
-
#composeDiff() {
|
|
2544
|
-
if (!this.#diffListResults?.length)
|
|
2545
|
-
return;
|
|
2546
|
-
this.#diffListResults.forEach((item) => {
|
|
2547
|
-
const hunks = item.hunks;
|
|
2548
|
-
hunks.forEach((hunk) => {
|
|
2549
|
-
let additions = [];
|
|
2550
|
-
let deletions = [];
|
|
2551
|
-
hunk.lines.forEach((line) => {
|
|
2552
|
-
if (line.type === DiffLineType.Add) {
|
|
2553
|
-
additions.push(line);
|
|
1214
|
+
if (mode === "split") {
|
|
1215
|
+
Object.values(__classPrivateFieldGet(this, _DiffFile_splitLeftLines, "f") || {}).forEach((item) => {
|
|
1216
|
+
if (!item.isHidden && item._isHidden) {
|
|
1217
|
+
item.isHidden = item._isHidden;
|
|
2554
1218
|
}
|
|
2555
|
-
|
|
2556
|
-
|
|
1219
|
+
});
|
|
1220
|
+
Object.values(__classPrivateFieldGet(this, _DiffFile_splitRightLines, "f") || {}).forEach((item) => {
|
|
1221
|
+
if (!item.isHidden && item._isHidden) {
|
|
1222
|
+
item.isHidden = item._isHidden;
|
|
2557
1223
|
}
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
1224
|
+
});
|
|
1225
|
+
Object.values(__classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f") || {}).forEach((item) => {
|
|
1226
|
+
if (!item.splitInfo)
|
|
1227
|
+
return;
|
|
1228
|
+
item.splitInfo = Object.assign(Object.assign({}, item.splitInfo), { oldStartIndex: item.splitInfo._oldStartIndex, oldLength: item.splitInfo._oldLength, newStartIndex: item.splitInfo._newStartIndex, newLength: item.splitInfo._newLength, startHiddenIndex: item.splitInfo._startHiddenIndex, endHiddenIndex: item.splitInfo._endHiddenIndex, plainText: item.splitInfo._plainText });
|
|
1229
|
+
});
|
|
1230
|
+
Object.keys(__classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f") || {}).forEach((key) => {
|
|
1231
|
+
const item = __classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f")[key];
|
|
1232
|
+
if (!item.splitInfo)
|
|
1233
|
+
return;
|
|
1234
|
+
if (item.splitInfo.endHiddenIndex !== +key) {
|
|
1235
|
+
delete __classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f")[key];
|
|
1236
|
+
__classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f")[item.splitInfo.endHiddenIndex] = item;
|
|
2562
1237
|
}
|
|
2563
1238
|
});
|
|
2564
|
-
getDiffRange(additions, deletions);
|
|
2565
|
-
});
|
|
2566
|
-
});
|
|
2567
|
-
this.#diffLines = [];
|
|
2568
|
-
const tmp = [];
|
|
2569
|
-
this.#diffListResults.forEach((item) => {
|
|
2570
|
-
item.hunks.forEach((_item) => {
|
|
2571
|
-
tmp.push(..._item.lines);
|
|
2572
|
-
});
|
|
2573
|
-
});
|
|
2574
|
-
this.#diffLines = tmp.map((i, index) => {
|
|
2575
|
-
const typedI = i;
|
|
2576
|
-
typedI.index = index;
|
|
2577
|
-
if (typedI.type === DiffLineType.Hunk) {
|
|
2578
|
-
const numInfo = typedI.text.split("@@")?.[1].split(" ").filter(Boolean);
|
|
2579
|
-
const oldNumInfo = numInfo?.[0] || "";
|
|
2580
|
-
const newNumInfo = numInfo?.[1] || "";
|
|
2581
|
-
const [oldNumStartIndex, oldNumLength] = oldNumInfo.split(",");
|
|
2582
|
-
const [newNumStartIndex, newNumLength] = newNumInfo.split(",");
|
|
2583
|
-
const typedTypeI = typedI;
|
|
2584
|
-
typedTypeI.hunkInfo = {
|
|
2585
|
-
oldStartIndex: -Number(oldNumStartIndex),
|
|
2586
|
-
oldLength: Number(oldNumLength),
|
|
2587
|
-
newStartIndex: +Number(newNumStartIndex),
|
|
2588
|
-
newLength: Number(newNumLength),
|
|
2589
|
-
_oldStartIndex: -Number(oldNumStartIndex),
|
|
2590
|
-
_oldLength: Number(oldNumLength),
|
|
2591
|
-
_newStartIndex: +Number(newNumStartIndex),
|
|
2592
|
-
_newLength: Number(newNumLength),
|
|
2593
|
-
};
|
|
2594
1239
|
}
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
// }
|
|
2616
|
-
// return typedI;
|
|
2617
|
-
// });
|
|
2618
|
-
this.#oldFileDiffLines = {};
|
|
2619
|
-
this.#diffLines.forEach((item) => {
|
|
2620
|
-
if (item.oldLineNumber) {
|
|
2621
|
-
this.diffLineLength = Math.max(this.diffLineLength, item.oldLineNumber);
|
|
2622
|
-
this.#oldFileDiffLines[item.oldLineNumber] = item;
|
|
2623
|
-
}
|
|
2624
|
-
});
|
|
2625
|
-
this.#newFileDiffLines = {};
|
|
2626
|
-
this.#diffLines.forEach((item) => {
|
|
2627
|
-
if (item.newLineNumber) {
|
|
2628
|
-
this.diffLineLength = Math.max(this.diffLineLength, item.newLineNumber);
|
|
2629
|
-
this.#newFileDiffLines[item.newLineNumber] = item;
|
|
1240
|
+
else {
|
|
1241
|
+
Object.values(__classPrivateFieldGet(this, _DiffFile_unifiedLines, "f") || {}).forEach((item) => {
|
|
1242
|
+
if (!item.isHidden && item._isHidden) {
|
|
1243
|
+
item.isHidden = item._isHidden;
|
|
1244
|
+
}
|
|
1245
|
+
});
|
|
1246
|
+
Object.values(__classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f") || {}).forEach((item) => {
|
|
1247
|
+
if (!item.unifiedInfo)
|
|
1248
|
+
return;
|
|
1249
|
+
item.unifiedInfo = Object.assign(Object.assign({}, item.unifiedInfo), { oldStartIndex: item.unifiedInfo._oldStartIndex, oldLength: item.unifiedInfo._oldLength, newStartIndex: item.unifiedInfo._newStartIndex, newLength: item.unifiedInfo._newLength, startHiddenIndex: item.unifiedInfo._startHiddenIndex, endHiddenIndex: item.unifiedInfo._endHiddenIndex, plainText: item.unifiedInfo._plainText });
|
|
1250
|
+
});
|
|
1251
|
+
Object.keys(__classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f") || {}).forEach((key) => {
|
|
1252
|
+
const item = __classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f")[key];
|
|
1253
|
+
if (!item.unifiedInfo)
|
|
1254
|
+
return;
|
|
1255
|
+
if (item.unifiedInfo.endHiddenIndex !== +key) {
|
|
1256
|
+
delete __classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f")[key];
|
|
1257
|
+
__classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f")[item.unifiedInfo.endHiddenIndex] = item;
|
|
1258
|
+
}
|
|
1259
|
+
});
|
|
2630
1260
|
}
|
|
1261
|
+
this.notifyAll();
|
|
1262
|
+
};
|
|
1263
|
+
this.getOldSyntaxLine = (lineNumber) => {
|
|
1264
|
+
var _a;
|
|
1265
|
+
return (_a = __classPrivateFieldGet(this, _DiffFile_oldFileSyntaxLines, "f")) === null || _a === void 0 ? void 0 : _a[lineNumber];
|
|
1266
|
+
};
|
|
1267
|
+
this.getNewSyntaxLine = (lineNumber) => {
|
|
1268
|
+
var _a;
|
|
1269
|
+
return (_a = __classPrivateFieldGet(this, _DiffFile_newFileSyntaxLines, "f")) === null || _a === void 0 ? void 0 : _a[lineNumber];
|
|
1270
|
+
};
|
|
1271
|
+
this.subscribe = (listener) => {
|
|
1272
|
+
__classPrivateFieldGet(this, _DiffFile_listeners, "f").push(listener);
|
|
1273
|
+
return () => {
|
|
1274
|
+
__classPrivateFieldGet(this, _DiffFile_listeners, "f").filter((i) => i !== listener);
|
|
1275
|
+
};
|
|
1276
|
+
};
|
|
1277
|
+
this.notifyAll = (skipSyncExternal) => {
|
|
1278
|
+
var _a;
|
|
1279
|
+
__classPrivateFieldSet(this, _DiffFile_updateCount, (_a = __classPrivateFieldGet(this, _DiffFile_updateCount, "f"), _a++, _a), "f");
|
|
1280
|
+
__classPrivateFieldGet(this, _DiffFile_listeners, "f").forEach((f) => {
|
|
1281
|
+
if (skipSyncExternal && f.isSyncExternal) {
|
|
1282
|
+
return;
|
|
1283
|
+
}
|
|
1284
|
+
f();
|
|
1285
|
+
});
|
|
1286
|
+
};
|
|
1287
|
+
this.getUpdateCount = () => __classPrivateFieldGet(this, _DiffFile_updateCount, "f");
|
|
1288
|
+
this.getExpandEnabled = () => !__classPrivateFieldGet(this, _DiffFile_composeByDiff, "f");
|
|
1289
|
+
this.getBundle = () => {
|
|
1290
|
+
// common
|
|
1291
|
+
const hasInitRaw = __classPrivateFieldGet(this, _DiffFile_hasInitRaw, "f");
|
|
1292
|
+
const hasInitSyntax = __classPrivateFieldGet(this, _DiffFile_hasInitSyntax, "f");
|
|
1293
|
+
const hasBuildSplit = __classPrivateFieldGet(this, _DiffFile_hasBuildSplit, "f");
|
|
1294
|
+
const hasBuildUnified = __classPrivateFieldGet(this, _DiffFile_hasBuildUnified, "f");
|
|
1295
|
+
const oldFileLines = __classPrivateFieldGet(this, _DiffFile_oldFileLines, "f");
|
|
1296
|
+
const oldFileDiffLines = __classPrivateFieldGet(this, _DiffFile_oldFileDiffLines, "f");
|
|
1297
|
+
const oldFileSyntaxLines = __classPrivateFieldGet(this, _DiffFile_oldFileSyntaxLines, "f");
|
|
1298
|
+
const oldFilePlaceholderLines = __classPrivateFieldGet(this, _DiffFile_oldFilePlaceholderLines, "f");
|
|
1299
|
+
const newFileLines = __classPrivateFieldGet(this, _DiffFile_newFileLines, "f");
|
|
1300
|
+
const newFileDiffLines = __classPrivateFieldGet(this, _DiffFile_newFileDiffLines, "f");
|
|
1301
|
+
const newFileSyntaxLines = __classPrivateFieldGet(this, _DiffFile_newFileSyntaxLines, "f");
|
|
1302
|
+
const newFilePlaceholderLines = __classPrivateFieldGet(this, _DiffFile_newFilePlaceholderLines, "f");
|
|
1303
|
+
const splitLineLength = this.splitLineLength;
|
|
1304
|
+
const unifiedLineLength = this.unifiedLineLength;
|
|
1305
|
+
const composeByDiff = __classPrivateFieldGet(this, _DiffFile_composeByDiff, "f");
|
|
1306
|
+
// split
|
|
1307
|
+
const splitLeftLines = __classPrivateFieldGet(this, _DiffFile_splitLeftLines, "f");
|
|
1308
|
+
const splitRightLines = __classPrivateFieldGet(this, _DiffFile_splitRightLines, "f");
|
|
1309
|
+
const splitHunkLines = __classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f");
|
|
1310
|
+
// unified
|
|
1311
|
+
const unifiedLines = __classPrivateFieldGet(this, _DiffFile_unifiedLines, "f");
|
|
1312
|
+
const unifiedHunkLines = __classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f");
|
|
1313
|
+
const version = this._version_;
|
|
1314
|
+
return {
|
|
1315
|
+
hasInitRaw,
|
|
1316
|
+
hasInitSyntax,
|
|
1317
|
+
hasBuildSplit,
|
|
1318
|
+
hasBuildUnified,
|
|
1319
|
+
oldFileLines,
|
|
1320
|
+
oldFileDiffLines,
|
|
1321
|
+
oldFileSyntaxLines,
|
|
1322
|
+
oldFilePlaceholderLines,
|
|
1323
|
+
newFileLines,
|
|
1324
|
+
newFileDiffLines,
|
|
1325
|
+
newFileSyntaxLines,
|
|
1326
|
+
newFilePlaceholderLines,
|
|
1327
|
+
splitLineLength,
|
|
1328
|
+
unifiedLineLength,
|
|
1329
|
+
splitLeftLines,
|
|
1330
|
+
splitRightLines,
|
|
1331
|
+
splitHunkLines,
|
|
1332
|
+
unifiedLines,
|
|
1333
|
+
unifiedHunkLines,
|
|
1334
|
+
composeByDiff,
|
|
1335
|
+
version,
|
|
1336
|
+
};
|
|
1337
|
+
};
|
|
1338
|
+
this.mergeBundle = (data) => {
|
|
1339
|
+
__classPrivateFieldSet(this, _DiffFile_hasInitRaw, data.hasInitRaw, "f");
|
|
1340
|
+
__classPrivateFieldSet(this, _DiffFile_hasInitSyntax, data.hasInitSyntax, "f");
|
|
1341
|
+
__classPrivateFieldSet(this, _DiffFile_hasBuildSplit, data.hasBuildSplit, "f");
|
|
1342
|
+
__classPrivateFieldSet(this, _DiffFile_hasBuildUnified, data.hasBuildUnified, "f");
|
|
1343
|
+
__classPrivateFieldSet(this, _DiffFile_composeByDiff, data.composeByDiff, "f");
|
|
1344
|
+
__classPrivateFieldSet(this, _DiffFile_oldFileLines, data.oldFileLines, "f");
|
|
1345
|
+
__classPrivateFieldSet(this, _DiffFile_oldFileDiffLines, data.oldFileDiffLines, "f");
|
|
1346
|
+
__classPrivateFieldSet(this, _DiffFile_oldFileSyntaxLines, data.oldFileSyntaxLines, "f");
|
|
1347
|
+
__classPrivateFieldSet(this, _DiffFile_oldFilePlaceholderLines, data.oldFilePlaceholderLines, "f");
|
|
1348
|
+
__classPrivateFieldSet(this, _DiffFile_newFileLines, data.newFileLines, "f");
|
|
1349
|
+
__classPrivateFieldSet(this, _DiffFile_newFileDiffLines, data.newFileDiffLines, "f");
|
|
1350
|
+
__classPrivateFieldSet(this, _DiffFile_newFileSyntaxLines, data.newFileSyntaxLines, "f");
|
|
1351
|
+
__classPrivateFieldSet(this, _DiffFile_newFilePlaceholderLines, data.newFilePlaceholderLines, "f");
|
|
1352
|
+
this.splitLineLength = data.splitLineLength;
|
|
1353
|
+
this.unifiedLineLength = data.unifiedLineLength;
|
|
1354
|
+
__classPrivateFieldSet(this, _DiffFile_splitLeftLines, data.splitLeftLines, "f");
|
|
1355
|
+
__classPrivateFieldSet(this, _DiffFile_splitRightLines, data.splitRightLines, "f");
|
|
1356
|
+
__classPrivateFieldSet(this, _DiffFile_splitHunksLines, data.splitHunkLines, "f");
|
|
1357
|
+
__classPrivateFieldSet(this, _DiffFile_unifiedLines, data.unifiedLines, "f");
|
|
1358
|
+
__classPrivateFieldSet(this, _DiffFile_unifiedHunksLines, data.unifiedHunkLines, "f");
|
|
1359
|
+
if (this._version_ !== data.version) {
|
|
1360
|
+
console.error("the version of the `diffInstance` is not match, some error may happen!");
|
|
1361
|
+
}
|
|
1362
|
+
this.notifyAll();
|
|
1363
|
+
};
|
|
1364
|
+
this._getIsPureDiffRender = () => __classPrivateFieldGet(this, _DiffFile_composeByDiff, "f");
|
|
1365
|
+
this._addClonedInstance = (instance) => {
|
|
1366
|
+
const updateFunc = () => {
|
|
1367
|
+
this._notifyOthers(instance);
|
|
1368
|
+
};
|
|
1369
|
+
updateFunc.isSyncExternal = true;
|
|
1370
|
+
const unsubscribe = instance.subscribe(updateFunc);
|
|
1371
|
+
__classPrivateFieldGet(this, _DiffFile_clonedInstance, "f").set(instance, unsubscribe);
|
|
1372
|
+
};
|
|
1373
|
+
this._notifyOthers = (instance) => {
|
|
1374
|
+
__classPrivateFieldGet(this, _DiffFile_clonedInstance, "f").forEach((_, i) => {
|
|
1375
|
+
if (i !== instance) {
|
|
1376
|
+
i.notifyAll(true);
|
|
1377
|
+
}
|
|
1378
|
+
});
|
|
1379
|
+
};
|
|
1380
|
+
this._delClonedInstance = (instance) => {
|
|
1381
|
+
const unsubscribe = __classPrivateFieldGet(this, _DiffFile_clonedInstance, "f").get(instance);
|
|
1382
|
+
unsubscribe && unsubscribe();
|
|
1383
|
+
__classPrivateFieldGet(this, _DiffFile_clonedInstance, "f").delete(instance);
|
|
1384
|
+
};
|
|
1385
|
+
this._getFullBundle = () => {
|
|
1386
|
+
const bundle = this.getBundle();
|
|
1387
|
+
const oldFileResult = __classPrivateFieldGet(this, _DiffFile_oldFileResult, "f");
|
|
1388
|
+
const newFileResult = __classPrivateFieldGet(this, _DiffFile_newFileResult, "f");
|
|
1389
|
+
const diffLines = __classPrivateFieldGet(this, _DiffFile_diffLines, "f");
|
|
1390
|
+
const diffListResults = __classPrivateFieldGet(this, _DiffFile_diffListResults, "f");
|
|
1391
|
+
return Object.assign(Object.assign({}, bundle), { oldFileResult,
|
|
1392
|
+
newFileResult,
|
|
1393
|
+
diffLines,
|
|
1394
|
+
diffListResults });
|
|
1395
|
+
};
|
|
1396
|
+
this._mergeFullBundle = (data) => {
|
|
1397
|
+
this.mergeBundle(data);
|
|
1398
|
+
__classPrivateFieldSet(this, _DiffFile_oldFileResult, data.oldFileResult, "f");
|
|
1399
|
+
__classPrivateFieldSet(this, _DiffFile_newFileResult, data.newFileResult, "f");
|
|
1400
|
+
__classPrivateFieldSet(this, _DiffFile_diffLines, data.diffLines, "f");
|
|
1401
|
+
__classPrivateFieldSet(this, _DiffFile_diffListResults, data.diffListResults, "f");
|
|
1402
|
+
};
|
|
1403
|
+
this._destroy = () => {
|
|
1404
|
+
this.clearId();
|
|
1405
|
+
__classPrivateFieldGet(this, _DiffFile_listeners, "f").splice(0, __classPrivateFieldGet(this, _DiffFile_listeners, "f").length);
|
|
1406
|
+
__classPrivateFieldGet(this, _DiffFile_clonedInstance, "f").forEach((v) => v());
|
|
1407
|
+
__classPrivateFieldGet(this, _DiffFile_clonedInstance, "f").clear();
|
|
1408
|
+
};
|
|
1409
|
+
this.clear = () => {
|
|
1410
|
+
this._destroy();
|
|
1411
|
+
__classPrivateFieldSet(this, _DiffFile_oldFileResult, null, "f");
|
|
1412
|
+
__classPrivateFieldSet(this, _DiffFile_newFileResult, null, "f");
|
|
1413
|
+
__classPrivateFieldSet(this, _DiffFile_diffLines, null, "f");
|
|
1414
|
+
__classPrivateFieldSet(this, _DiffFile_diffListResults, null, "f");
|
|
1415
|
+
__classPrivateFieldSet(this, _DiffFile_newFileDiffLines, null, "f");
|
|
1416
|
+
__classPrivateFieldSet(this, _DiffFile_oldFileDiffLines, null, "f");
|
|
1417
|
+
__classPrivateFieldSet(this, _DiffFile_newFileLines, null, "f");
|
|
1418
|
+
__classPrivateFieldSet(this, _DiffFile_oldFileLines, null, "f");
|
|
1419
|
+
__classPrivateFieldSet(this, _DiffFile_newFileSyntaxLines, null, "f");
|
|
1420
|
+
__classPrivateFieldSet(this, _DiffFile_oldFileSyntaxLines, null, "f");
|
|
1421
|
+
__classPrivateFieldSet(this, _DiffFile_splitHunksLines, null, "f");
|
|
1422
|
+
__classPrivateFieldSet(this, _DiffFile_splitLeftLines, null, "f");
|
|
1423
|
+
__classPrivateFieldSet(this, _DiffFile_splitRightLines, null, "f");
|
|
1424
|
+
__classPrivateFieldSet(this, _DiffFile_unifiedHunksLines, null, "f");
|
|
1425
|
+
__classPrivateFieldSet(this, _DiffFile_unifiedLines, null, "f");
|
|
1426
|
+
};
|
|
1427
|
+
Object.defineProperty(this, "__v_skip", { value: true });
|
|
1428
|
+
let oldContent = _oldFileContent;
|
|
1429
|
+
let newContent = _newFileContent;
|
|
1430
|
+
const diffList = Array.from(new Set(_diffList));
|
|
1431
|
+
Object.defineProperties(this, {
|
|
1432
|
+
_oldFileName: { get: () => _oldFileName },
|
|
1433
|
+
_newFileName: { get: () => _newFileName },
|
|
1434
|
+
_oldFileLang: { get: () => getLang(_oldFileLang || _oldFileName || _newFileLang || _newFileName) || "txt" },
|
|
1435
|
+
_newFileLang: { get: () => getLang(_newFileLang || _newFileName || _oldFileLang || _oldFileName) || "txt" },
|
|
1436
|
+
_oldFileContent: {
|
|
1437
|
+
get: () => oldContent,
|
|
1438
|
+
set: (v) => (oldContent = v),
|
|
1439
|
+
},
|
|
1440
|
+
_newFileContent: {
|
|
1441
|
+
get: () => newContent,
|
|
1442
|
+
set: (v) => (newContent = v),
|
|
1443
|
+
},
|
|
1444
|
+
_diffList: { get: () => diffList },
|
|
2631
1445
|
});
|
|
2632
|
-
|
|
2633
|
-
#composeSyntax({ autoDetectLang, registerHighlighter, }) {
|
|
2634
|
-
this.#oldFileResult?.doSyntax({ autoDetectLang, registerHighlighter });
|
|
2635
|
-
this.#oldFileSyntaxLines = this.#oldFileResult?.syntaxFile;
|
|
2636
|
-
this.#newFileResult?.doSyntax({ autoDetectLang, registerHighlighter });
|
|
2637
|
-
this.#newFileSyntaxLines = this.#newFileResult?.syntaxFile;
|
|
2638
|
-
}
|
|
2639
|
-
#getOldDiffLine(lineNumber) {
|
|
2640
|
-
if (!lineNumber)
|
|
2641
|
-
return;
|
|
2642
|
-
return this.#oldFileDiffLines?.[lineNumber];
|
|
2643
|
-
}
|
|
2644
|
-
#getNewDiffLine(lineNumber) {
|
|
2645
|
-
if (!lineNumber)
|
|
2646
|
-
return;
|
|
2647
|
-
return this.#newFileDiffLines?.[lineNumber];
|
|
2648
|
-
}
|
|
2649
|
-
#getOldRawLine(lineNumber) {
|
|
2650
|
-
return this.#oldFileLines?.[lineNumber];
|
|
2651
|
-
}
|
|
2652
|
-
#getNewRawLine(lineNumber) {
|
|
2653
|
-
return this.#newFileLines?.[lineNumber];
|
|
1446
|
+
this.initId();
|
|
2654
1447
|
}
|
|
2655
1448
|
initId() {
|
|
2656
1449
|
let id = "--" + Math.random().toString().slice(2);
|
|
@@ -2658,76 +1451,97 @@ class DiffFile {
|
|
|
2658
1451
|
id = "--" + Math.random().toString().slice(2);
|
|
2659
1452
|
}
|
|
2660
1453
|
idSet.add(id);
|
|
2661
|
-
this
|
|
1454
|
+
__classPrivateFieldSet(this, _DiffFile_id, id, "f");
|
|
2662
1455
|
}
|
|
2663
1456
|
getId() {
|
|
2664
|
-
return this
|
|
1457
|
+
return __classPrivateFieldGet(this, _DiffFile_id, "f");
|
|
2665
1458
|
}
|
|
2666
1459
|
clearId() {
|
|
2667
|
-
idSet.delete(this
|
|
1460
|
+
idSet.delete(__classPrivateFieldGet(this, _DiffFile_id, "f"));
|
|
2668
1461
|
}
|
|
2669
1462
|
initRaw() {
|
|
2670
|
-
if (this
|
|
1463
|
+
if (__classPrivateFieldGet(this, _DiffFile_hasInitRaw, "f"))
|
|
2671
1464
|
return;
|
|
2672
|
-
this
|
|
2673
|
-
this
|
|
2674
|
-
this
|
|
2675
|
-
this
|
|
2676
|
-
this
|
|
2677
|
-
this
|
|
1465
|
+
__classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_doDiff).call(this);
|
|
1466
|
+
__classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_composeDiff).call(this);
|
|
1467
|
+
__classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_doFile).call(this);
|
|
1468
|
+
__classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_composeRaw).call(this);
|
|
1469
|
+
__classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_composeFile).call(this);
|
|
1470
|
+
__classPrivateFieldSet(this, _DiffFile_hasInitRaw, true, "f");
|
|
2678
1471
|
}
|
|
2679
1472
|
initSyntax({ autoDetectLang, registerHighlighter, } = {}) {
|
|
2680
|
-
if (this
|
|
1473
|
+
if (__classPrivateFieldGet(this, _DiffFile_hasInitSyntax, "f"))
|
|
2681
1474
|
return;
|
|
2682
|
-
this
|
|
2683
|
-
this
|
|
1475
|
+
__classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_composeSyntax).call(this, { registerHighlighter, autoDetectLang });
|
|
1476
|
+
__classPrivateFieldSet(this, _DiffFile_hasInitSyntax, true, "f");
|
|
2684
1477
|
}
|
|
2685
1478
|
init() {
|
|
2686
1479
|
this.initRaw();
|
|
2687
1480
|
this.initSyntax();
|
|
2688
1481
|
}
|
|
2689
1482
|
buildSplitDiffLines() {
|
|
2690
|
-
|
|
1483
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1484
|
+
if (__classPrivateFieldGet(this, _DiffFile_hasBuildSplit, "f"))
|
|
2691
1485
|
return;
|
|
2692
1486
|
let oldFileLineNumber = 1;
|
|
2693
1487
|
let newFileLineNumber = 1;
|
|
2694
1488
|
let prevIsHidden = false;
|
|
2695
1489
|
let hideStart = Infinity;
|
|
2696
|
-
const maxOldFileLineNumber = this
|
|
2697
|
-
const maxNewFileLineNumber = this
|
|
1490
|
+
const maxOldFileLineNumber = ((_a = __classPrivateFieldGet(this, _DiffFile_oldFileResult, "f")) === null || _a === void 0 ? void 0 : _a.maxLineNumber) || 0;
|
|
1491
|
+
const maxNewFileLineNumber = ((_b = __classPrivateFieldGet(this, _DiffFile_newFileResult, "f")) === null || _b === void 0 ? void 0 : _b.maxLineNumber) || 0;
|
|
2698
1492
|
while (oldFileLineNumber <= maxOldFileLineNumber || newFileLineNumber <= maxNewFileLineNumber) {
|
|
2699
|
-
const oldDiffLine = this
|
|
2700
|
-
const newDiffLine = this
|
|
2701
|
-
const oldRawLine = this
|
|
2702
|
-
const newRawLine = this
|
|
2703
|
-
const oldLineHasChange = oldDiffLine
|
|
2704
|
-
const newLineHasChange = newDiffLine
|
|
2705
|
-
const len = this
|
|
1493
|
+
const oldDiffLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getOldDiffLine).call(this, oldFileLineNumber);
|
|
1494
|
+
const newDiffLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getNewDiffLine).call(this, newFileLineNumber);
|
|
1495
|
+
const oldRawLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getOldRawLine).call(this, oldFileLineNumber);
|
|
1496
|
+
const newRawLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getNewRawLine).call(this, newFileLineNumber);
|
|
1497
|
+
const oldLineHasChange = oldDiffLine === null || oldDiffLine === void 0 ? void 0 : oldDiffLine.isIncludeableLine();
|
|
1498
|
+
const newLineHasChange = newDiffLine === null || newDiffLine === void 0 ? void 0 : newDiffLine.isIncludeableLine();
|
|
1499
|
+
const len = __classPrivateFieldGet(this, _DiffFile_splitRightLines, "f").length;
|
|
2706
1500
|
const isHidden = !oldDiffLine && !newDiffLine;
|
|
2707
|
-
if (
|
|
2708
|
-
(
|
|
2709
|
-
|
|
2710
|
-
oldDiffLine && newFileLineNumber++;
|
|
2711
|
-
newDiffLine && oldFileLineNumber++;
|
|
1501
|
+
if (oldDiffLine && !newDiffLine) {
|
|
1502
|
+
if (oldDiffLine.newLineNumber && oldDiffLine.newLineNumber > newFileLineNumber) {
|
|
1503
|
+
newFileLineNumber++;
|
|
2712
1504
|
continue;
|
|
2713
1505
|
}
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
1506
|
+
if (oldDiffLine.newLineNumber === null || oldDiffLine.newLineNumber === undefined) {
|
|
1507
|
+
newFileLineNumber++;
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
if (newDiffLine && !oldDiffLine) {
|
|
1511
|
+
if (newDiffLine.oldLineNumber && newDiffLine.oldLineNumber > oldFileLineNumber) {
|
|
1512
|
+
oldFileLineNumber++;
|
|
1513
|
+
continue;
|
|
1514
|
+
}
|
|
1515
|
+
if (newDiffLine.oldLineNumber === null || newDiffLine.oldLineNumber === undefined) {
|
|
1516
|
+
oldFileLineNumber++;
|
|
2718
1517
|
}
|
|
2719
1518
|
}
|
|
2720
|
-
if (!oldDiffLine && !
|
|
1519
|
+
if (!oldDiffLine && !oldRawLine && !newDiffLine && !newRawLine)
|
|
2721
1520
|
break;
|
|
1521
|
+
if (!oldDiffLine && !newDiffLine) {
|
|
1522
|
+
if (((_c = __classPrivateFieldGet(this, _DiffFile_oldFilePlaceholderLines, "f")) === null || _c === void 0 ? void 0 : _c[oldFileLineNumber]) && ((_d = __classPrivateFieldGet(this, _DiffFile_newFilePlaceholderLines, "f")) === null || _d === void 0 ? void 0 : _d[newFileLineNumber])) {
|
|
1523
|
+
oldFileLineNumber++;
|
|
1524
|
+
newFileLineNumber++;
|
|
1525
|
+
continue;
|
|
1526
|
+
}
|
|
1527
|
+
if (!oldRawLine && ((_e = __classPrivateFieldGet(this, _DiffFile_newFilePlaceholderLines, "f")) === null || _e === void 0 ? void 0 : _e[newFileLineNumber])) {
|
|
1528
|
+
newFileLineNumber++;
|
|
1529
|
+
continue;
|
|
1530
|
+
}
|
|
1531
|
+
if (!newRawLine && ((_f = __classPrivateFieldGet(this, _DiffFile_oldFilePlaceholderLines, "f")) === null || _f === void 0 ? void 0 : _f[oldFileLineNumber])) {
|
|
1532
|
+
oldFileLineNumber++;
|
|
1533
|
+
continue;
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
2722
1536
|
if ((oldLineHasChange && newLineHasChange) || (!oldLineHasChange && !newLineHasChange)) {
|
|
2723
|
-
this
|
|
1537
|
+
__classPrivateFieldGet(this, _DiffFile_splitLeftLines, "f").push({
|
|
2724
1538
|
lineNumber: oldFileLineNumber++,
|
|
2725
1539
|
value: oldRawLine,
|
|
2726
1540
|
diff: oldDiffLine,
|
|
2727
1541
|
isHidden,
|
|
2728
1542
|
_isHidden: isHidden,
|
|
2729
1543
|
});
|
|
2730
|
-
this
|
|
1544
|
+
__classPrivateFieldGet(this, _DiffFile_splitRightLines, "f").push({
|
|
2731
1545
|
lineNumber: newFileLineNumber++,
|
|
2732
1546
|
value: newRawLine,
|
|
2733
1547
|
diff: newDiffLine,
|
|
@@ -2736,18 +1550,18 @@ class DiffFile {
|
|
|
2736
1550
|
});
|
|
2737
1551
|
}
|
|
2738
1552
|
else if (oldLineHasChange) {
|
|
2739
|
-
this
|
|
1553
|
+
__classPrivateFieldGet(this, _DiffFile_splitLeftLines, "f").push({
|
|
2740
1554
|
lineNumber: oldFileLineNumber++,
|
|
2741
1555
|
value: oldRawLine,
|
|
2742
1556
|
diff: oldDiffLine,
|
|
2743
1557
|
isHidden,
|
|
2744
1558
|
_isHidden: isHidden,
|
|
2745
1559
|
});
|
|
2746
|
-
this
|
|
1560
|
+
__classPrivateFieldGet(this, _DiffFile_splitRightLines, "f").push({});
|
|
2747
1561
|
}
|
|
2748
1562
|
else if (newLineHasChange) {
|
|
2749
|
-
this
|
|
2750
|
-
this
|
|
1563
|
+
__classPrivateFieldGet(this, _DiffFile_splitLeftLines, "f").push({});
|
|
1564
|
+
__classPrivateFieldGet(this, _DiffFile_splitRightLines, "f").push({
|
|
2751
1565
|
lineNumber: newFileLineNumber++,
|
|
2752
1566
|
value: newRawLine,
|
|
2753
1567
|
diff: newDiffLine,
|
|
@@ -2761,38 +1575,27 @@ class DiffFile {
|
|
|
2761
1575
|
prevIsHidden = isHidden;
|
|
2762
1576
|
if (oldDiffLine && newDiffLine && !oldLineHasChange && !newLineHasChange) {
|
|
2763
1577
|
const current = newDiffLine;
|
|
2764
|
-
const previous = newDiffLine.index ? this
|
|
2765
|
-
if (previous && previous.type === DiffLineType.Hunk) {
|
|
1578
|
+
const previous = newDiffLine.index ? (_g = __classPrivateFieldGet(this, _DiffFile_diffLines, "f")) === null || _g === void 0 ? void 0 : _g[current.index - 1] : undefined;
|
|
1579
|
+
if (previous && previous.type === exports.DiffLineType.Hunk) {
|
|
2766
1580
|
const typedPrevious = previous;
|
|
2767
1581
|
if (Number.isFinite(hideStart)) {
|
|
2768
|
-
typedPrevious.splitInfo = {
|
|
2769
|
-
...typedPrevious.hunkInfo,
|
|
2770
|
-
startHiddenIndex: hideStart,
|
|
2771
|
-
endHiddenIndex: len,
|
|
2772
|
-
plainText: typedPrevious.text,
|
|
2773
|
-
_startHiddenIndex: hideStart,
|
|
2774
|
-
_endHiddenIndex: len,
|
|
2775
|
-
_plainText: typedPrevious.text,
|
|
2776
|
-
};
|
|
1582
|
+
typedPrevious.splitInfo = Object.assign(Object.assign({}, typedPrevious.hunkInfo), { startHiddenIndex: hideStart, endHiddenIndex: len, plainText: typedPrevious.text, _startHiddenIndex: hideStart, _endHiddenIndex: len, _plainText: typedPrevious.text });
|
|
2777
1583
|
hideStart = Infinity;
|
|
2778
1584
|
}
|
|
2779
|
-
this
|
|
2780
|
-
...this.#splitHunksLines,
|
|
2781
|
-
[len]: typedPrevious,
|
|
2782
|
-
};
|
|
1585
|
+
__classPrivateFieldSet(this, _DiffFile_splitHunksLines, Object.assign(Object.assign({}, __classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f")), { [len]: typedPrevious }), "f");
|
|
2783
1586
|
}
|
|
2784
1587
|
}
|
|
2785
1588
|
}
|
|
2786
1589
|
// have last hunk
|
|
2787
1590
|
if (Number.isFinite(hideStart)) {
|
|
2788
|
-
const lastDiff = new DiffLine("", DiffLineType.Hunk, null, null, null);
|
|
1591
|
+
const lastDiff = new DiffLine("", exports.DiffLineType.Hunk, null, null, null);
|
|
2789
1592
|
const lastHunk = lastDiff;
|
|
2790
1593
|
lastHunk.isLast = true;
|
|
2791
1594
|
lastHunk.splitInfo = {
|
|
2792
1595
|
startHiddenIndex: hideStart,
|
|
2793
|
-
endHiddenIndex: this
|
|
1596
|
+
endHiddenIndex: __classPrivateFieldGet(this, _DiffFile_splitRightLines, "f").length,
|
|
2794
1597
|
_startHiddenIndex: hideStart,
|
|
2795
|
-
_endHiddenIndex: this
|
|
1598
|
+
_endHiddenIndex: __classPrivateFieldGet(this, _DiffFile_splitRightLines, "f").length,
|
|
2796
1599
|
// just for placeholder
|
|
2797
1600
|
plainText: "",
|
|
2798
1601
|
oldStartIndex: 0,
|
|
@@ -2805,51 +1608,69 @@ class DiffFile {
|
|
|
2805
1608
|
_oldLength: 0,
|
|
2806
1609
|
_newLength: 0,
|
|
2807
1610
|
};
|
|
2808
|
-
this
|
|
2809
|
-
...this.#splitHunksLines,
|
|
2810
|
-
[this.#splitRightLines.length]: lastHunk,
|
|
2811
|
-
};
|
|
1611
|
+
__classPrivateFieldSet(this, _DiffFile_splitHunksLines, Object.assign(Object.assign({}, __classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f")), { [__classPrivateFieldGet(this, _DiffFile_splitRightLines, "f").length]: lastHunk }), "f");
|
|
2812
1612
|
hideStart = Infinity;
|
|
2813
1613
|
}
|
|
2814
|
-
this.splitLineLength = this
|
|
2815
|
-
this
|
|
1614
|
+
this.splitLineLength = __classPrivateFieldGet(this, _DiffFile_splitRightLines, "f").length;
|
|
1615
|
+
__classPrivateFieldSet(this, _DiffFile_hasBuildSplit, true, "f");
|
|
2816
1616
|
this.notifyAll();
|
|
2817
1617
|
}
|
|
2818
1618
|
buildUnifiedDiffLines() {
|
|
2819
|
-
|
|
1619
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1620
|
+
if (__classPrivateFieldGet(this, _DiffFile_hasBuildUnified, "f"))
|
|
2820
1621
|
return;
|
|
2821
1622
|
let oldFileLineNumber = 1;
|
|
2822
1623
|
let newFileLineNumber = 1;
|
|
2823
1624
|
let prevIsHidden = false;
|
|
2824
1625
|
let hideStart = Infinity;
|
|
2825
|
-
const maxOldFileLineNumber = this
|
|
2826
|
-
const maxNewFileLineNumber = this
|
|
1626
|
+
const maxOldFileLineNumber = ((_a = __classPrivateFieldGet(this, _DiffFile_oldFileResult, "f")) === null || _a === void 0 ? void 0 : _a.maxLineNumber) || 0;
|
|
1627
|
+
const maxNewFileLineNumber = ((_b = __classPrivateFieldGet(this, _DiffFile_newFileResult, "f")) === null || _b === void 0 ? void 0 : _b.maxLineNumber) || 0;
|
|
2827
1628
|
while (oldFileLineNumber <= maxOldFileLineNumber || newFileLineNumber <= maxNewFileLineNumber) {
|
|
2828
|
-
const oldRawLine = this
|
|
2829
|
-
const oldDiffLine = this
|
|
2830
|
-
const newRawLine = this
|
|
2831
|
-
const newDiffLine = this
|
|
2832
|
-
const oldLineHasChange = oldDiffLine
|
|
2833
|
-
const newLineHasChange = newDiffLine
|
|
2834
|
-
const len = this
|
|
1629
|
+
const oldRawLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getOldRawLine).call(this, oldFileLineNumber);
|
|
1630
|
+
const oldDiffLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getOldDiffLine).call(this, oldFileLineNumber);
|
|
1631
|
+
const newRawLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getNewRawLine).call(this, newFileLineNumber);
|
|
1632
|
+
const newDiffLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getNewDiffLine).call(this, newFileLineNumber);
|
|
1633
|
+
const oldLineHasChange = oldDiffLine === null || oldDiffLine === void 0 ? void 0 : oldDiffLine.isIncludeableLine();
|
|
1634
|
+
const newLineHasChange = newDiffLine === null || newDiffLine === void 0 ? void 0 : newDiffLine.isIncludeableLine();
|
|
1635
|
+
const len = __classPrivateFieldGet(this, _DiffFile_unifiedLines, "f").length;
|
|
2835
1636
|
const isHidden = !oldDiffLine && !newDiffLine;
|
|
2836
|
-
if (
|
|
2837
|
-
(
|
|
2838
|
-
|
|
2839
|
-
oldDiffLine && newFileLineNumber++;
|
|
2840
|
-
newDiffLine && oldFileLineNumber++;
|
|
1637
|
+
if (oldDiffLine && !newDiffLine) {
|
|
1638
|
+
if (oldDiffLine.newLineNumber && oldDiffLine.newLineNumber > newFileLineNumber) {
|
|
1639
|
+
newFileLineNumber++;
|
|
2841
1640
|
continue;
|
|
2842
1641
|
}
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
1642
|
+
if (oldDiffLine.newLineNumber === null || oldDiffLine.newLineNumber === undefined) {
|
|
1643
|
+
newFileLineNumber++;
|
|
1644
|
+
}
|
|
1645
|
+
}
|
|
1646
|
+
if (newDiffLine && !oldDiffLine) {
|
|
1647
|
+
if (newDiffLine.oldLineNumber && newDiffLine.oldLineNumber > oldFileLineNumber) {
|
|
1648
|
+
oldFileLineNumber++;
|
|
1649
|
+
continue;
|
|
1650
|
+
}
|
|
1651
|
+
if (newDiffLine.oldLineNumber === null || newDiffLine.oldLineNumber === undefined) {
|
|
1652
|
+
oldFileLineNumber++;
|
|
2847
1653
|
}
|
|
2848
1654
|
}
|
|
2849
1655
|
if (!oldRawLine && !newRawLine && !newDiffLine && !oldDiffLine)
|
|
2850
1656
|
break;
|
|
1657
|
+
if (!oldDiffLine && !newDiffLine) {
|
|
1658
|
+
if (((_c = __classPrivateFieldGet(this, _DiffFile_oldFilePlaceholderLines, "f")) === null || _c === void 0 ? void 0 : _c[oldFileLineNumber]) && ((_d = __classPrivateFieldGet(this, _DiffFile_newFilePlaceholderLines, "f")) === null || _d === void 0 ? void 0 : _d[newFileLineNumber])) {
|
|
1659
|
+
oldFileLineNumber++;
|
|
1660
|
+
newFileLineNumber++;
|
|
1661
|
+
continue;
|
|
1662
|
+
}
|
|
1663
|
+
if (!oldRawLine && ((_e = __classPrivateFieldGet(this, _DiffFile_newFilePlaceholderLines, "f")) === null || _e === void 0 ? void 0 : _e[newFileLineNumber])) {
|
|
1664
|
+
newFileLineNumber++;
|
|
1665
|
+
continue;
|
|
1666
|
+
}
|
|
1667
|
+
if (!newRawLine && ((_f = __classPrivateFieldGet(this, _DiffFile_oldFilePlaceholderLines, "f")) === null || _f === void 0 ? void 0 : _f[oldFileLineNumber])) {
|
|
1668
|
+
oldFileLineNumber++;
|
|
1669
|
+
continue;
|
|
1670
|
+
}
|
|
1671
|
+
}
|
|
2851
1672
|
if (!oldLineHasChange && !newLineHasChange) {
|
|
2852
|
-
this
|
|
1673
|
+
__classPrivateFieldGet(this, _DiffFile_unifiedLines, "f").push({
|
|
2853
1674
|
oldLineNumber: oldFileLineNumber++,
|
|
2854
1675
|
newLineNumber: newFileLineNumber++,
|
|
2855
1676
|
value: newRawLine,
|
|
@@ -2859,7 +1680,7 @@ class DiffFile {
|
|
|
2859
1680
|
});
|
|
2860
1681
|
}
|
|
2861
1682
|
else if (oldLineHasChange) {
|
|
2862
|
-
this
|
|
1683
|
+
__classPrivateFieldGet(this, _DiffFile_unifiedLines, "f").push({
|
|
2863
1684
|
oldLineNumber: oldFileLineNumber++,
|
|
2864
1685
|
value: oldRawLine,
|
|
2865
1686
|
diff: oldDiffLine,
|
|
@@ -2868,7 +1689,7 @@ class DiffFile {
|
|
|
2868
1689
|
});
|
|
2869
1690
|
}
|
|
2870
1691
|
else if (newLineHasChange) {
|
|
2871
|
-
this
|
|
1692
|
+
__classPrivateFieldGet(this, _DiffFile_unifiedLines, "f").push({
|
|
2872
1693
|
newLineNumber: newFileLineNumber++,
|
|
2873
1694
|
value: newRawLine,
|
|
2874
1695
|
diff: newDiffLine,
|
|
@@ -2882,38 +1703,27 @@ class DiffFile {
|
|
|
2882
1703
|
prevIsHidden = isHidden;
|
|
2883
1704
|
if (oldDiffLine && newDiffLine && !oldLineHasChange && !newLineHasChange) {
|
|
2884
1705
|
const current = newDiffLine;
|
|
2885
|
-
const previous = current.index ? this
|
|
2886
|
-
if (previous && previous.type === DiffLineType.Hunk) {
|
|
1706
|
+
const previous = current.index ? (_g = __classPrivateFieldGet(this, _DiffFile_diffLines, "f")) === null || _g === void 0 ? void 0 : _g[current.index - 1] : undefined;
|
|
1707
|
+
if (previous && previous.type === exports.DiffLineType.Hunk) {
|
|
2887
1708
|
const typedPrevious = previous;
|
|
2888
1709
|
if (Number.isFinite(hideStart)) {
|
|
2889
|
-
typedPrevious.unifiedInfo = {
|
|
2890
|
-
...typedPrevious.hunkInfo,
|
|
2891
|
-
startHiddenIndex: hideStart,
|
|
2892
|
-
endHiddenIndex: len,
|
|
2893
|
-
plainText: typedPrevious.text,
|
|
2894
|
-
_startHiddenIndex: hideStart,
|
|
2895
|
-
_endHiddenIndex: len,
|
|
2896
|
-
_plainText: typedPrevious.text,
|
|
2897
|
-
};
|
|
1710
|
+
typedPrevious.unifiedInfo = Object.assign(Object.assign({}, typedPrevious.hunkInfo), { startHiddenIndex: hideStart, endHiddenIndex: len, plainText: typedPrevious.text, _startHiddenIndex: hideStart, _endHiddenIndex: len, _plainText: typedPrevious.text });
|
|
2898
1711
|
hideStart = Infinity;
|
|
2899
1712
|
}
|
|
2900
|
-
this
|
|
2901
|
-
...this.#unifiedHunksLines,
|
|
2902
|
-
[len]: typedPrevious,
|
|
2903
|
-
};
|
|
1713
|
+
__classPrivateFieldSet(this, _DiffFile_unifiedHunksLines, Object.assign(Object.assign({}, __classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f")), { [len]: typedPrevious }), "f");
|
|
2904
1714
|
}
|
|
2905
1715
|
}
|
|
2906
1716
|
}
|
|
2907
1717
|
// have last hunk
|
|
2908
1718
|
if (Number.isFinite(hideStart)) {
|
|
2909
|
-
const lastDiff = new DiffLine("", DiffLineType.Hunk, null, null, null);
|
|
1719
|
+
const lastDiff = new DiffLine("", exports.DiffLineType.Hunk, null, null, null);
|
|
2910
1720
|
const lastHunk = lastDiff;
|
|
2911
1721
|
lastHunk.isLast = true;
|
|
2912
1722
|
lastHunk.unifiedInfo = {
|
|
2913
1723
|
startHiddenIndex: hideStart,
|
|
2914
|
-
endHiddenIndex: this
|
|
1724
|
+
endHiddenIndex: __classPrivateFieldGet(this, _DiffFile_unifiedLines, "f").length,
|
|
2915
1725
|
_startHiddenIndex: hideStart,
|
|
2916
|
-
_endHiddenIndex: this
|
|
1726
|
+
_endHiddenIndex: __classPrivateFieldGet(this, _DiffFile_unifiedLines, "f").length,
|
|
2917
1727
|
// just for placeholder
|
|
2918
1728
|
plainText: "",
|
|
2919
1729
|
oldStartIndex: 0,
|
|
@@ -2926,476 +1736,312 @@ class DiffFile {
|
|
|
2926
1736
|
_oldLength: 0,
|
|
2927
1737
|
_newLength: 0,
|
|
2928
1738
|
};
|
|
2929
|
-
this
|
|
2930
|
-
...this.#unifiedHunksLines,
|
|
2931
|
-
[this.#unifiedLines.length]: lastHunk,
|
|
2932
|
-
};
|
|
1739
|
+
__classPrivateFieldSet(this, _DiffFile_unifiedHunksLines, Object.assign(Object.assign({}, __classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f")), { [__classPrivateFieldGet(this, _DiffFile_unifiedLines, "f").length]: lastHunk }), "f");
|
|
2933
1740
|
hideStart = Infinity;
|
|
2934
1741
|
}
|
|
2935
|
-
this.unifiedLineLength = this
|
|
2936
|
-
this
|
|
1742
|
+
this.unifiedLineLength = __classPrivateFieldGet(this, _DiffFile_unifiedLines, "f").length;
|
|
1743
|
+
__classPrivateFieldSet(this, _DiffFile_hasBuildUnified, true, "f");
|
|
2937
1744
|
this.notifyAll();
|
|
2938
1745
|
}
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
return
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
rightLine.isHidden = false;
|
|
2976
|
-
}
|
|
2977
|
-
if (current.isLast) {
|
|
2978
|
-
current.splitInfo = {
|
|
2979
|
-
...current.splitInfo,
|
|
2980
|
-
startHiddenIndex: current.splitInfo.startHiddenIndex + composeLen,
|
|
2981
|
-
};
|
|
1746
|
+
}
|
|
1747
|
+
_DiffFile_oldFileResult = new WeakMap(), _DiffFile_newFileResult = new WeakMap(), _DiffFile_diffListResults = new WeakMap(), _DiffFile_diffLines = new WeakMap(), _DiffFile_oldFileDiffLines = new WeakMap(), _DiffFile_newFileDiffLines = new WeakMap(), _DiffFile_oldFileLines = new WeakMap(), _DiffFile_newFileLines = new WeakMap(), _DiffFile_oldFileSyntaxLines = new WeakMap(), _DiffFile_newFileSyntaxLines = new WeakMap(), _DiffFile_oldFilePlaceholderLines = new WeakMap(), _DiffFile_newFilePlaceholderLines = new WeakMap(), _DiffFile_splitLeftLines = new WeakMap(), _DiffFile_splitRightLines = new WeakMap(), _DiffFile_splitHunksLines = new WeakMap(), _DiffFile_unifiedLines = new WeakMap(), _DiffFile_unifiedHunksLines = new WeakMap(), _DiffFile_listeners = new WeakMap(), _DiffFile_hasInitRaw = new WeakMap(), _DiffFile_hasInitSyntax = new WeakMap(), _DiffFile_hasBuildSplit = new WeakMap(), _DiffFile_hasBuildUnified = new WeakMap(), _DiffFile_updateCount = new WeakMap(), _DiffFile_composeByDiff = new WeakMap(), _DiffFile_id = new WeakMap(), _DiffFile_clonedInstance = new WeakMap(), _DiffFile_instances = new WeakSet(), _DiffFile_doDiff = function _DiffFile_doDiff() {
|
|
1748
|
+
if (!this._diffList)
|
|
1749
|
+
return;
|
|
1750
|
+
__classPrivateFieldSet(this, _DiffFile_diffListResults, this._diffList.map((s) => parseInstance.parse(s)), "f");
|
|
1751
|
+
}, _DiffFile_doFile = function _DiffFile_doFile() {
|
|
1752
|
+
if (!this._oldFileContent && !this._newFileContent)
|
|
1753
|
+
return;
|
|
1754
|
+
if (this._oldFileContent) {
|
|
1755
|
+
__classPrivateFieldSet(this, _DiffFile_oldFileResult, getFile(this._oldFileContent, this._oldFileLang, this._oldFileName), "f");
|
|
1756
|
+
}
|
|
1757
|
+
if (this._newFileContent) {
|
|
1758
|
+
__classPrivateFieldSet(this, _DiffFile_newFileResult, getFile(this._newFileContent, this._newFileLang, this._newFileName), "f");
|
|
1759
|
+
}
|
|
1760
|
+
}, _DiffFile_composeRaw = function _DiffFile_composeRaw() {
|
|
1761
|
+
var _a, _b, _c, _d;
|
|
1762
|
+
(_a = __classPrivateFieldGet(this, _DiffFile_oldFileResult, "f")) === null || _a === void 0 ? void 0 : _a.doRaw();
|
|
1763
|
+
__classPrivateFieldSet(this, _DiffFile_oldFileLines, (_b = __classPrivateFieldGet(this, _DiffFile_oldFileResult, "f")) === null || _b === void 0 ? void 0 : _b.rawFile, "f");
|
|
1764
|
+
(_c = __classPrivateFieldGet(this, _DiffFile_newFileResult, "f")) === null || _c === void 0 ? void 0 : _c.doRaw();
|
|
1765
|
+
__classPrivateFieldSet(this, _DiffFile_newFileLines, (_d = __classPrivateFieldGet(this, _DiffFile_newFileResult, "f")) === null || _d === void 0 ? void 0 : _d.rawFile, "f");
|
|
1766
|
+
}, _DiffFile_composeFile = function _DiffFile_composeFile() {
|
|
1767
|
+
if (this._oldFileContent && this._newFileContent)
|
|
1768
|
+
return;
|
|
1769
|
+
const oldFilePlaceholderLines = {};
|
|
1770
|
+
const newFilePlaceholderLines = {};
|
|
1771
|
+
// all of the file content not exist, try to use diff result to compose
|
|
1772
|
+
if (!this._oldFileContent && !this._newFileContent) {
|
|
1773
|
+
let newLineNumber = 1;
|
|
1774
|
+
let oldLineNumber = 1;
|
|
1775
|
+
let oldFileContent = "";
|
|
1776
|
+
let newFileContent = "";
|
|
1777
|
+
while (oldLineNumber <= this.diffLineLength) {
|
|
1778
|
+
const index = oldLineNumber++;
|
|
1779
|
+
const diffLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getOldDiffLine).call(this, index);
|
|
1780
|
+
if (diffLine) {
|
|
1781
|
+
oldFileContent += diffLine.text;
|
|
2982
1782
|
}
|
|
2983
1783
|
else {
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
plainText: `@@ -${current.splitInfo.oldStartIndex},${current.splitInfo.oldLength} +${current.splitInfo.newStartIndex},${current.splitInfo.newLength}`,
|
|
2988
|
-
};
|
|
1784
|
+
// empty line for placeholder
|
|
1785
|
+
oldFileContent += "\n";
|
|
1786
|
+
oldFilePlaceholderLines[index] = true;
|
|
2989
1787
|
}
|
|
2990
1788
|
}
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
1789
|
+
while (newLineNumber <= this.diffLineLength) {
|
|
1790
|
+
const index = newLineNumber++;
|
|
1791
|
+
const diffLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getNewDiffLine).call(this, index);
|
|
1792
|
+
if (diffLine) {
|
|
1793
|
+
newFileContent += diffLine.text;
|
|
2995
1794
|
}
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
leftLine.isHidden = false;
|
|
3001
|
-
if (rightLine?.isHidden)
|
|
3002
|
-
rightLine.isHidden = false;
|
|
1795
|
+
else {
|
|
1796
|
+
// empty line for placeholder
|
|
1797
|
+
newFileContent += "\n";
|
|
1798
|
+
newFilePlaceholderLines[index] = true;
|
|
3003
1799
|
}
|
|
3004
|
-
const oldStartIndex = current.splitInfo.oldStartIndex - composeLen;
|
|
3005
|
-
const oldLength = current.splitInfo.oldLength + composeLen;
|
|
3006
|
-
const newStartIndex = current.splitInfo.newStartIndex - composeLen;
|
|
3007
|
-
const newLength = current.splitInfo.newLength + composeLen;
|
|
3008
|
-
current.splitInfo = {
|
|
3009
|
-
...current.splitInfo,
|
|
3010
|
-
endHiddenIndex: current.splitInfo.endHiddenIndex - composeLen,
|
|
3011
|
-
oldStartIndex,
|
|
3012
|
-
oldLength,
|
|
3013
|
-
newStartIndex,
|
|
3014
|
-
newLength,
|
|
3015
|
-
plainText: `@@ -${oldStartIndex},${oldLength} +${newStartIndex},${newLength}`,
|
|
3016
|
-
};
|
|
3017
|
-
delete this.#splitHunksLines?.[index];
|
|
3018
|
-
this.#splitHunksLines[current.splitInfo.endHiddenIndex] = current;
|
|
3019
1800
|
}
|
|
3020
|
-
|
|
3021
|
-
};
|
|
3022
|
-
getUnifiedLine = (index) => {
|
|
3023
|
-
return this.#unifiedLines[index];
|
|
3024
|
-
};
|
|
3025
|
-
getUnifiedHunkLine = (index) => {
|
|
3026
|
-
return this.#unifiedHunksLines?.[index];
|
|
3027
|
-
};
|
|
3028
|
-
onUnifiedHunkExpand = (dir, index, needTrigger = true) => {
|
|
3029
|
-
const current = this.#unifiedHunksLines?.[index];
|
|
3030
|
-
if (!current || !current.unifiedInfo)
|
|
1801
|
+
if (oldFileContent === newFileContent)
|
|
3031
1802
|
return;
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
unifiedLine.isHidden = false;
|
|
3051
|
-
}
|
|
3052
|
-
if (current.isLast) {
|
|
3053
|
-
current.unifiedInfo = {
|
|
3054
|
-
...current.unifiedInfo,
|
|
3055
|
-
startHiddenIndex: current.unifiedInfo.startHiddenIndex + composeLen,
|
|
3056
|
-
};
|
|
1803
|
+
this._oldFileContent = oldFileContent;
|
|
1804
|
+
this._newFileContent = newFileContent;
|
|
1805
|
+
__classPrivateFieldSet(this, _DiffFile_oldFileResult, getFile(this._oldFileContent, this._oldFileLang, this._oldFileName), "f");
|
|
1806
|
+
__classPrivateFieldSet(this, _DiffFile_newFileResult, getFile(this._newFileContent, this._newFileLang, this._newFileName), "f");
|
|
1807
|
+
__classPrivateFieldSet(this, _DiffFile_oldFilePlaceholderLines, oldFilePlaceholderLines, "f");
|
|
1808
|
+
__classPrivateFieldSet(this, _DiffFile_newFilePlaceholderLines, newFilePlaceholderLines, "f");
|
|
1809
|
+
// all of the file just compose by diff, so we can not do the expand action
|
|
1810
|
+
__classPrivateFieldSet(this, _DiffFile_composeByDiff, true, "f");
|
|
1811
|
+
}
|
|
1812
|
+
else if (__classPrivateFieldGet(this, _DiffFile_oldFileResult, "f")) {
|
|
1813
|
+
let newLineNumber = 1;
|
|
1814
|
+
let oldLineNumber = 1;
|
|
1815
|
+
let newFileContent = "";
|
|
1816
|
+
while (oldLineNumber <= __classPrivateFieldGet(this, _DiffFile_oldFileResult, "f").maxLineNumber) {
|
|
1817
|
+
const newDiffLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getNewDiffLine).call(this, newLineNumber++);
|
|
1818
|
+
if (newDiffLine) {
|
|
1819
|
+
newFileContent += newDiffLine.text;
|
|
1820
|
+
oldLineNumber = newDiffLine.oldLineNumber ? newDiffLine.oldLineNumber + 1 : oldLineNumber;
|
|
3057
1821
|
}
|
|
3058
1822
|
else {
|
|
3059
|
-
|
|
3060
|
-
...current.unifiedInfo,
|
|
3061
|
-
startHiddenIndex: current.unifiedInfo.startHiddenIndex + composeLen,
|
|
3062
|
-
plainText: `@@ -${current.unifiedInfo.oldStartIndex},${current.unifiedInfo.oldLength} +${current.unifiedInfo.newStartIndex},${current.unifiedInfo.newLength}`,
|
|
3063
|
-
};
|
|
1823
|
+
newFileContent += __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getOldRawLine).call(this, oldLineNumber++);
|
|
3064
1824
|
}
|
|
3065
1825
|
}
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
1826
|
+
if (newFileContent === this._oldFileContent)
|
|
1827
|
+
return;
|
|
1828
|
+
this._newFileContent = newFileContent;
|
|
1829
|
+
__classPrivateFieldSet(this, _DiffFile_newFileResult, getFile(this._newFileContent, this._newFileLang, this._newFileName), "f");
|
|
1830
|
+
}
|
|
1831
|
+
else if (__classPrivateFieldGet(this, _DiffFile_newFileResult, "f")) {
|
|
1832
|
+
let oldLineNumber = 1;
|
|
1833
|
+
let newLineNumber = 1;
|
|
1834
|
+
let oldFileContent = "";
|
|
1835
|
+
while (newLineNumber <= __classPrivateFieldGet(this, _DiffFile_newFileResult, "f").maxLineNumber) {
|
|
1836
|
+
const oldDiffLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getOldDiffLine).call(this, oldLineNumber++);
|
|
1837
|
+
if (oldDiffLine) {
|
|
1838
|
+
oldFileContent += oldDiffLine.text;
|
|
1839
|
+
newLineNumber = oldDiffLine.newLineNumber ? oldDiffLine.newLineNumber + 1 : newLineNumber;
|
|
3070
1840
|
}
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
if (unifiedLine?.isHidden)
|
|
3074
|
-
unifiedLine.isHidden = false;
|
|
1841
|
+
else {
|
|
1842
|
+
oldFileContent += __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getNewRawLine).call(this, newLineNumber++);
|
|
3075
1843
|
}
|
|
3076
|
-
const oldStartIndex = current.unifiedInfo.oldStartIndex - composeLen;
|
|
3077
|
-
const oldLength = current.unifiedInfo.oldLength + composeLen;
|
|
3078
|
-
const newStartIndex = current.unifiedInfo.newStartIndex - composeLen;
|
|
3079
|
-
const newLength = current.unifiedInfo.newLength + composeLen;
|
|
3080
|
-
current.unifiedInfo = {
|
|
3081
|
-
...current.unifiedInfo,
|
|
3082
|
-
endHiddenIndex: current.unifiedInfo.endHiddenIndex - composeLen,
|
|
3083
|
-
oldStartIndex,
|
|
3084
|
-
oldLength,
|
|
3085
|
-
newStartIndex,
|
|
3086
|
-
newLength,
|
|
3087
|
-
plainText: `@@ -${oldStartIndex},${oldLength} +${newStartIndex},${newLength}`,
|
|
3088
|
-
};
|
|
3089
|
-
delete this.#unifiedHunksLines?.[index];
|
|
3090
|
-
this.#unifiedHunksLines[current.unifiedInfo.endHiddenIndex] = current;
|
|
3091
|
-
}
|
|
3092
|
-
needTrigger && this.notifyAll();
|
|
3093
|
-
};
|
|
3094
|
-
onAllExpand = (mode) => {
|
|
3095
|
-
if (mode === "split") {
|
|
3096
|
-
Object.keys(this.#splitHunksLines || {}).forEach((key) => {
|
|
3097
|
-
this.onSplitHunkExpand("all", +key, false);
|
|
3098
|
-
});
|
|
3099
|
-
}
|
|
3100
|
-
else {
|
|
3101
|
-
Object.keys(this.#unifiedHunksLines || {}).forEach((key) => {
|
|
3102
|
-
this.onUnifiedHunkExpand("all", +key, false);
|
|
3103
|
-
});
|
|
3104
1844
|
}
|
|
3105
|
-
this.
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
1845
|
+
if (oldFileContent === this._newFileContent)
|
|
1846
|
+
return;
|
|
1847
|
+
this._oldFileContent = oldFileContent;
|
|
1848
|
+
__classPrivateFieldSet(this, _DiffFile_oldFileResult, getFile(this._oldFileContent, this._oldFileLang, this._oldFileName), "f");
|
|
1849
|
+
}
|
|
1850
|
+
__classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_composeRaw).call(this);
|
|
1851
|
+
}, _DiffFile_composeDiff = function _DiffFile_composeDiff() {
|
|
1852
|
+
var _a;
|
|
1853
|
+
if (!((_a = __classPrivateFieldGet(this, _DiffFile_diffListResults, "f")) === null || _a === void 0 ? void 0 : _a.length))
|
|
1854
|
+
return;
|
|
1855
|
+
__classPrivateFieldGet(this, _DiffFile_diffListResults, "f").forEach((item) => {
|
|
1856
|
+
const hunks = item.hunks;
|
|
1857
|
+
hunks.forEach((hunk) => {
|
|
1858
|
+
let additions = [];
|
|
1859
|
+
let deletions = [];
|
|
1860
|
+
hunk.lines.forEach((line) => {
|
|
1861
|
+
if (line.type === exports.DiffLineType.Add) {
|
|
1862
|
+
additions.push(line);
|
|
1863
|
+
}
|
|
1864
|
+
else if (line.type === exports.DiffLineType.Delete) {
|
|
1865
|
+
deletions.push(line);
|
|
3117
1866
|
}
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
item.splitInfo = {
|
|
3123
|
-
...item.splitInfo,
|
|
3124
|
-
oldStartIndex: item.splitInfo._oldStartIndex,
|
|
3125
|
-
oldLength: item.splitInfo._oldLength,
|
|
3126
|
-
newStartIndex: item.splitInfo._newStartIndex,
|
|
3127
|
-
newLength: item.splitInfo._newLength,
|
|
3128
|
-
startHiddenIndex: item.splitInfo._startHiddenIndex,
|
|
3129
|
-
endHiddenIndex: item.splitInfo._endHiddenIndex,
|
|
3130
|
-
plainText: item.splitInfo._plainText,
|
|
3131
|
-
};
|
|
3132
|
-
});
|
|
3133
|
-
Object.keys(this.#splitHunksLines || {}).forEach((key) => {
|
|
3134
|
-
const item = this.#splitHunksLines[key];
|
|
3135
|
-
if (!item.splitInfo)
|
|
3136
|
-
return;
|
|
3137
|
-
if (item.splitInfo.endHiddenIndex !== +key) {
|
|
3138
|
-
delete this.#splitHunksLines[key];
|
|
3139
|
-
this.#splitHunksLines[item.splitInfo.endHiddenIndex] = item;
|
|
1867
|
+
else {
|
|
1868
|
+
getDiffRange(additions, deletions);
|
|
1869
|
+
additions = [];
|
|
1870
|
+
deletions = [];
|
|
3140
1871
|
}
|
|
3141
1872
|
});
|
|
1873
|
+
getDiffRange(additions, deletions);
|
|
1874
|
+
});
|
|
1875
|
+
});
|
|
1876
|
+
__classPrivateFieldSet(this, _DiffFile_diffLines, [], "f");
|
|
1877
|
+
const tmp = [];
|
|
1878
|
+
__classPrivateFieldGet(this, _DiffFile_diffListResults, "f").forEach((item) => {
|
|
1879
|
+
item.hunks.forEach((_item) => {
|
|
1880
|
+
tmp.push(..._item.lines);
|
|
1881
|
+
});
|
|
1882
|
+
});
|
|
1883
|
+
__classPrivateFieldSet(this, _DiffFile_diffLines, tmp.map((i, index) => {
|
|
1884
|
+
var _a;
|
|
1885
|
+
const typedI = i;
|
|
1886
|
+
typedI.index = index;
|
|
1887
|
+
if (typedI.type === exports.DiffLineType.Hunk) {
|
|
1888
|
+
const numInfo = (_a = typedI.text.split("@@")) === null || _a === void 0 ? void 0 : _a[1].split(" ").filter(Boolean);
|
|
1889
|
+
const oldNumInfo = (numInfo === null || numInfo === void 0 ? void 0 : numInfo[0]) || "";
|
|
1890
|
+
const newNumInfo = (numInfo === null || numInfo === void 0 ? void 0 : numInfo[1]) || "";
|
|
1891
|
+
const [oldNumStartIndex, oldNumLength] = oldNumInfo.split(",");
|
|
1892
|
+
const [newNumStartIndex, newNumLength] = newNumInfo.split(",");
|
|
1893
|
+
const typedTypeI = typedI;
|
|
1894
|
+
typedTypeI.hunkInfo = {
|
|
1895
|
+
oldStartIndex: -Number(oldNumStartIndex),
|
|
1896
|
+
oldLength: Number(oldNumLength),
|
|
1897
|
+
newStartIndex: +Number(newNumStartIndex),
|
|
1898
|
+
newLength: Number(newNumLength),
|
|
1899
|
+
_oldStartIndex: -Number(oldNumStartIndex),
|
|
1900
|
+
_oldLength: Number(oldNumLength),
|
|
1901
|
+
_newStartIndex: +Number(newNumStartIndex),
|
|
1902
|
+
_newLength: Number(newNumLength),
|
|
1903
|
+
};
|
|
3142
1904
|
}
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
});
|
|
1905
|
+
return typedI;
|
|
1906
|
+
}), "f");
|
|
1907
|
+
// this.#diffLines = this.#diffListResults
|
|
1908
|
+
// .reduce<DiffLine[]>((p, c) => p.concat(...c.hunks.reduce<DiffLine[]>((_p, _c) => _p.concat(..._c.lines), [])), [])
|
|
1909
|
+
// .map<DiffLineItem>((i, index) => {
|
|
1910
|
+
// const typedI = i as DiffLineItem;
|
|
1911
|
+
// typedI.index = index;
|
|
1912
|
+
// if (typedI.type === DiffLineType.Hunk) {
|
|
1913
|
+
// const numInfo = typedI.text.split("@@")?.[1].split(" ").filter(Boolean);
|
|
1914
|
+
// const oldNumInfo = numInfo?.[0] || "";
|
|
1915
|
+
// const newNumInfo = numInfo?.[1] || "";
|
|
1916
|
+
// const [oldNumStartIndex, oldNumLength] = oldNumInfo.split(",");
|
|
1917
|
+
// const [newNumStartIndex, newNumLength] = newNumInfo.split(",");
|
|
1918
|
+
// const typedTypeI = typedI as DiffHunkItem;
|
|
1919
|
+
// typedTypeI.hunkInfo = {
|
|
1920
|
+
// oldStartIndex: -Number(oldNumStartIndex),
|
|
1921
|
+
// oldLength: Number(oldNumLength),
|
|
1922
|
+
// newStartIndex: +Number(newNumStartIndex),
|
|
1923
|
+
// newLength: Number(newNumLength),
|
|
1924
|
+
// };
|
|
1925
|
+
// }
|
|
1926
|
+
// return typedI;
|
|
1927
|
+
// });
|
|
1928
|
+
__classPrivateFieldSet(this, _DiffFile_oldFileDiffLines, {}, "f");
|
|
1929
|
+
__classPrivateFieldGet(this, _DiffFile_diffLines, "f").forEach((item) => {
|
|
1930
|
+
if (item.oldLineNumber) {
|
|
1931
|
+
this.diffLineLength = Math.max(this.diffLineLength, item.oldLineNumber);
|
|
1932
|
+
__classPrivateFieldGet(this, _DiffFile_oldFileDiffLines, "f")[item.oldLineNumber] = item;
|
|
3172
1933
|
}
|
|
3173
|
-
|
|
3174
|
-
};
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
return this.#newFileSyntaxLines?.[lineNumber];
|
|
3180
|
-
};
|
|
3181
|
-
subscribe = (listener) => {
|
|
3182
|
-
this.#listeners.push(listener);
|
|
3183
|
-
return () => {
|
|
3184
|
-
this.#listeners.filter((i) => i !== listener);
|
|
3185
|
-
};
|
|
3186
|
-
};
|
|
3187
|
-
notifyAll = (skipSyncExternal) => {
|
|
3188
|
-
this.#updateCount++;
|
|
3189
|
-
this.#listeners.forEach((f) => {
|
|
3190
|
-
if (skipSyncExternal && f.isSyncExternal) {
|
|
3191
|
-
return;
|
|
3192
|
-
}
|
|
3193
|
-
f();
|
|
3194
|
-
});
|
|
3195
|
-
};
|
|
3196
|
-
getUpdateCount = () => this.#updateCount;
|
|
3197
|
-
getExpandEnabled = () => !this.#composeByDiff;
|
|
3198
|
-
getBundle = () => {
|
|
3199
|
-
// common
|
|
3200
|
-
const hasInitRaw = this.#hasInitRaw;
|
|
3201
|
-
const hasInitSyntax = this.#hasInitSyntax;
|
|
3202
|
-
const hasBuildSplit = this.#hasBuildSplit;
|
|
3203
|
-
const hasBuildUnified = this.#hasBuildUnified;
|
|
3204
|
-
const oldFileLines = this.#oldFileLines;
|
|
3205
|
-
const oldFileDiffLines = this.#oldFileDiffLines;
|
|
3206
|
-
const oldFileSyntaxLines = this.#oldFileSyntaxLines;
|
|
3207
|
-
const newFileLines = this.#newFileLines;
|
|
3208
|
-
const newFileDiffLines = this.#newFileDiffLines;
|
|
3209
|
-
const newFileSyntaxLines = this.#newFileSyntaxLines;
|
|
3210
|
-
const splitLineLength = this.splitLineLength;
|
|
3211
|
-
const unifiedLineLength = this.unifiedLineLength;
|
|
3212
|
-
const composeByDiff = this.#composeByDiff;
|
|
3213
|
-
// split
|
|
3214
|
-
const splitLeftLines = this.#splitLeftLines;
|
|
3215
|
-
const splitRightLines = this.#splitRightLines;
|
|
3216
|
-
const splitHunkLines = this.#splitHunksLines;
|
|
3217
|
-
// unified
|
|
3218
|
-
const unifiedLines = this.#unifiedLines;
|
|
3219
|
-
const unifiedHunkLines = this.#unifiedHunksLines;
|
|
3220
|
-
const version = this._version_;
|
|
3221
|
-
return {
|
|
3222
|
-
hasInitRaw,
|
|
3223
|
-
hasInitSyntax,
|
|
3224
|
-
hasBuildSplit,
|
|
3225
|
-
hasBuildUnified,
|
|
3226
|
-
oldFileLines,
|
|
3227
|
-
oldFileDiffLines,
|
|
3228
|
-
oldFileSyntaxLines,
|
|
3229
|
-
newFileLines,
|
|
3230
|
-
newFileDiffLines,
|
|
3231
|
-
newFileSyntaxLines,
|
|
3232
|
-
splitLineLength,
|
|
3233
|
-
unifiedLineLength,
|
|
3234
|
-
splitLeftLines,
|
|
3235
|
-
splitRightLines,
|
|
3236
|
-
splitHunkLines,
|
|
3237
|
-
unifiedLines,
|
|
3238
|
-
unifiedHunkLines,
|
|
3239
|
-
composeByDiff,
|
|
3240
|
-
version
|
|
3241
|
-
};
|
|
3242
|
-
};
|
|
3243
|
-
mergeBundle = (data) => {
|
|
3244
|
-
this.#hasInitRaw = data.hasInitRaw;
|
|
3245
|
-
this.#hasInitSyntax = data.hasInitSyntax;
|
|
3246
|
-
this.#hasBuildSplit = data.hasBuildSplit;
|
|
3247
|
-
this.#hasBuildUnified = data.hasBuildUnified;
|
|
3248
|
-
this.#composeByDiff = data.composeByDiff;
|
|
3249
|
-
this.#oldFileLines = data.oldFileLines;
|
|
3250
|
-
this.#oldFileDiffLines = data.oldFileDiffLines;
|
|
3251
|
-
this.#oldFileSyntaxLines = data.oldFileSyntaxLines;
|
|
3252
|
-
this.#newFileLines = data.newFileLines;
|
|
3253
|
-
this.#newFileDiffLines = data.newFileDiffLines;
|
|
3254
|
-
this.#newFileSyntaxLines = data.newFileSyntaxLines;
|
|
3255
|
-
this.splitLineLength = data.splitLineLength;
|
|
3256
|
-
this.unifiedLineLength = data.unifiedLineLength;
|
|
3257
|
-
this.#splitLeftLines = data.splitLeftLines;
|
|
3258
|
-
this.#splitRightLines = data.splitRightLines;
|
|
3259
|
-
this.#splitHunksLines = data.splitHunkLines;
|
|
3260
|
-
this.#unifiedLines = data.unifiedLines;
|
|
3261
|
-
this.#unifiedHunksLines = data.unifiedHunkLines;
|
|
3262
|
-
if (this._version_ !== data.version) {
|
|
3263
|
-
console.error('the version of the `diffInstance` is not match, some error may happen!');
|
|
1934
|
+
});
|
|
1935
|
+
__classPrivateFieldSet(this, _DiffFile_newFileDiffLines, {}, "f");
|
|
1936
|
+
__classPrivateFieldGet(this, _DiffFile_diffLines, "f").forEach((item) => {
|
|
1937
|
+
if (item.newLineNumber) {
|
|
1938
|
+
this.diffLineLength = Math.max(this.diffLineLength, item.newLineNumber);
|
|
1939
|
+
__classPrivateFieldGet(this, _DiffFile_newFileDiffLines, "f")[item.newLineNumber] = item;
|
|
3264
1940
|
}
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
|
|
3289
|
-
const oldFileResult = this.#oldFileResult;
|
|
3290
|
-
const newFileResult = this.#newFileResult;
|
|
3291
|
-
const diffLines = this.#diffLines;
|
|
3292
|
-
const diffListResults = this.#diffListResults;
|
|
3293
|
-
return {
|
|
3294
|
-
...bundle,
|
|
3295
|
-
oldFileResult,
|
|
3296
|
-
newFileResult,
|
|
3297
|
-
diffLines,
|
|
3298
|
-
diffListResults,
|
|
3299
|
-
};
|
|
3300
|
-
};
|
|
3301
|
-
_mergeFullBundle = (data) => {
|
|
3302
|
-
this.mergeBundle(data);
|
|
3303
|
-
this.#oldFileResult = data.oldFileResult;
|
|
3304
|
-
this.#newFileResult = data.newFileResult;
|
|
3305
|
-
this.#diffLines = data.diffLines;
|
|
3306
|
-
this.#diffListResults = data.diffListResults;
|
|
3307
|
-
};
|
|
3308
|
-
_destroy = () => {
|
|
3309
|
-
this.clearId();
|
|
3310
|
-
this.#listeners.splice(0, this.#listeners.length);
|
|
3311
|
-
this.#clonedInstance.forEach((v) => v());
|
|
3312
|
-
this.#clonedInstance.clear();
|
|
3313
|
-
};
|
|
3314
|
-
clear = () => {
|
|
3315
|
-
this._destroy();
|
|
3316
|
-
this.#oldFileResult = null;
|
|
3317
|
-
this.#newFileResult = null;
|
|
3318
|
-
this.#diffLines = null;
|
|
3319
|
-
this.#diffListResults = null;
|
|
3320
|
-
this.#newFileDiffLines = null;
|
|
3321
|
-
this.#oldFileDiffLines = null;
|
|
3322
|
-
this.#newFileLines = null;
|
|
3323
|
-
this.#oldFileLines = null;
|
|
3324
|
-
this.#newFileSyntaxLines = null;
|
|
3325
|
-
this.#oldFileSyntaxLines = null;
|
|
3326
|
-
this.#splitHunksLines = null;
|
|
3327
|
-
this.#splitLeftLines = null;
|
|
3328
|
-
this.#splitRightLines = null;
|
|
3329
|
-
this.#unifiedHunksLines = null;
|
|
3330
|
-
this.#unifiedLines = null;
|
|
3331
|
-
};
|
|
3332
|
-
}
|
|
1941
|
+
});
|
|
1942
|
+
}, _DiffFile_composeSyntax = function _DiffFile_composeSyntax({ autoDetectLang, registerHighlighter, }) {
|
|
1943
|
+
var _a, _b, _c, _d;
|
|
1944
|
+
(_a = __classPrivateFieldGet(this, _DiffFile_oldFileResult, "f")) === null || _a === void 0 ? void 0 : _a.doSyntax({ autoDetectLang, registerHighlighter });
|
|
1945
|
+
__classPrivateFieldSet(this, _DiffFile_oldFileSyntaxLines, (_b = __classPrivateFieldGet(this, _DiffFile_oldFileResult, "f")) === null || _b === void 0 ? void 0 : _b.syntaxFile, "f");
|
|
1946
|
+
(_c = __classPrivateFieldGet(this, _DiffFile_newFileResult, "f")) === null || _c === void 0 ? void 0 : _c.doSyntax({ autoDetectLang, registerHighlighter });
|
|
1947
|
+
__classPrivateFieldSet(this, _DiffFile_newFileSyntaxLines, (_d = __classPrivateFieldGet(this, _DiffFile_newFileResult, "f")) === null || _d === void 0 ? void 0 : _d.syntaxFile, "f");
|
|
1948
|
+
}, _DiffFile_getOldDiffLine = function _DiffFile_getOldDiffLine(lineNumber) {
|
|
1949
|
+
var _a;
|
|
1950
|
+
if (!lineNumber)
|
|
1951
|
+
return;
|
|
1952
|
+
return (_a = __classPrivateFieldGet(this, _DiffFile_oldFileDiffLines, "f")) === null || _a === void 0 ? void 0 : _a[lineNumber];
|
|
1953
|
+
}, _DiffFile_getNewDiffLine = function _DiffFile_getNewDiffLine(lineNumber) {
|
|
1954
|
+
var _a;
|
|
1955
|
+
if (!lineNumber)
|
|
1956
|
+
return;
|
|
1957
|
+
return (_a = __classPrivateFieldGet(this, _DiffFile_newFileDiffLines, "f")) === null || _a === void 0 ? void 0 : _a[lineNumber];
|
|
1958
|
+
}, _DiffFile_getOldRawLine = function _DiffFile_getOldRawLine(lineNumber) {
|
|
1959
|
+
var _a;
|
|
1960
|
+
return (_a = __classPrivateFieldGet(this, _DiffFile_oldFileLines, "f")) === null || _a === void 0 ? void 0 : _a[lineNumber];
|
|
1961
|
+
}, _DiffFile_getNewRawLine = function _DiffFile_getNewRawLine(lineNumber) {
|
|
1962
|
+
var _a;
|
|
1963
|
+
return (_a = __classPrivateFieldGet(this, _DiffFile_newFileLines, "f")) === null || _a === void 0 ? void 0 : _a[lineNumber];
|
|
1964
|
+
};
|
|
3333
1965
|
|
|
3334
|
-
|
|
1966
|
+
exports.DiffFileLineType = void 0;
|
|
3335
1967
|
(function (DiffFileLineType) {
|
|
3336
1968
|
DiffFileLineType[DiffFileLineType["hunk"] = 1] = "hunk";
|
|
3337
1969
|
DiffFileLineType[DiffFileLineType["content"] = 2] = "content";
|
|
3338
1970
|
DiffFileLineType[DiffFileLineType["widget"] = 3] = "widget";
|
|
3339
1971
|
DiffFileLineType[DiffFileLineType["extend"] = 4] = "extend";
|
|
3340
|
-
})(DiffFileLineType || (DiffFileLineType = {}));
|
|
1972
|
+
})(exports.DiffFileLineType || (exports.DiffFileLineType = {}));
|
|
3341
1973
|
const getSplitLines = (diffFile, options) => {
|
|
3342
1974
|
const splitLineLength = diffFile.splitLineLength;
|
|
3343
1975
|
const splitLines = [];
|
|
3344
1976
|
numIterator(splitLineLength, (index) => {
|
|
1977
|
+
var _a, _b;
|
|
3345
1978
|
const hunkLine = diffFile.getSplitHunkLine(index);
|
|
3346
1979
|
const splitLeftLine = diffFile.getSplitLeftLine(index);
|
|
3347
1980
|
const splitRightLine = diffFile.getSplitRightLine(index);
|
|
3348
|
-
const widgetLine = options
|
|
3349
|
-
const extendLine = options
|
|
1981
|
+
const widgetLine = (options === null || options === void 0 ? void 0 : options.hasRenderWidget) && ((_a = options.widgetData) === null || _a === void 0 ? void 0 : _a[index + 1]);
|
|
1982
|
+
const extendLine = (options === null || options === void 0 ? void 0 : options.hasRenderExtend) && ((_b = options.extendData) === null || _b === void 0 ? void 0 : _b[index + 1]);
|
|
3350
1983
|
hunkLine &&
|
|
3351
1984
|
hunkLine.splitInfo &&
|
|
3352
1985
|
hunkLine.splitInfo.startHiddenIndex < hunkLine.splitInfo.endHiddenIndex &&
|
|
3353
|
-
splitLines.push({ type: DiffFileLineType.hunk, index, lineNumber: index + 1, hunkLine: hunkLine });
|
|
3354
|
-
|
|
3355
|
-
!
|
|
1986
|
+
splitLines.push({ type: exports.DiffFileLineType.hunk, index, lineNumber: index + 1, hunkLine: hunkLine });
|
|
1987
|
+
hunkLine &&
|
|
1988
|
+
!hunkLine.splitInfo &&
|
|
1989
|
+
!hunkLine.unifiedInfo &&
|
|
1990
|
+
hunkLine.type === exports.DiffLineType.Hunk &&
|
|
1991
|
+
splitLines.push({ type: exports.DiffFileLineType.hunk, index, lineNumber: index + 1, hunkLine: hunkLine });
|
|
1992
|
+
!(splitLeftLine === null || splitLeftLine === void 0 ? void 0 : splitLeftLine.isHidden) &&
|
|
1993
|
+
!(splitRightLine === null || splitRightLine === void 0 ? void 0 : splitRightLine.isHidden) &&
|
|
3356
1994
|
splitLines.push({
|
|
3357
|
-
type: DiffFileLineType.content,
|
|
1995
|
+
type: exports.DiffFileLineType.content,
|
|
3358
1996
|
index,
|
|
3359
1997
|
lineNumber: index + 1,
|
|
3360
1998
|
splitLine: { left: splitLeftLine, right: splitRightLine },
|
|
3361
1999
|
});
|
|
3362
2000
|
widgetLine &&
|
|
3363
|
-
splitLines.push({ type: DiffFileLineType.widget, index, lineNumber: index + 1, widgetLine: widgetLine });
|
|
2001
|
+
splitLines.push({ type: exports.DiffFileLineType.widget, index, lineNumber: index + 1, widgetLine: widgetLine });
|
|
3364
2002
|
extendLine &&
|
|
3365
|
-
splitLines.push({ type: DiffFileLineType.extend, index, lineNumber: index + 1, extendLine: extendLine });
|
|
2003
|
+
splitLines.push({ type: exports.DiffFileLineType.extend, index, lineNumber: index + 1, extendLine: extendLine });
|
|
3366
2004
|
});
|
|
3367
2005
|
return splitLines;
|
|
3368
2006
|
};
|
|
3369
2007
|
const getSplitContentLines = (diffFile) => {
|
|
3370
2008
|
const lines = getSplitLines(diffFile, {});
|
|
3371
|
-
return lines.filter((line) => line.type === DiffFileLineType.content);
|
|
2009
|
+
return lines.filter((line) => line.type === exports.DiffFileLineType.content);
|
|
3372
2010
|
};
|
|
3373
2011
|
const getUnifiedLines = (diffFile, options) => {
|
|
3374
2012
|
const unifiedLineLength = diffFile.unifiedLineLength;
|
|
3375
2013
|
const unifiedLines = [];
|
|
3376
2014
|
numIterator(unifiedLineLength, (index) => {
|
|
2015
|
+
var _a, _b;
|
|
3377
2016
|
const hunkLine = diffFile.getUnifiedHunkLine(index);
|
|
3378
2017
|
const unifiedLine = diffFile.getUnifiedLine(index);
|
|
3379
|
-
const widgetLine = options
|
|
3380
|
-
const extendLine = options
|
|
2018
|
+
const widgetLine = (options === null || options === void 0 ? void 0 : options.hasRenderWidget) && ((_a = options.widgetData) === null || _a === void 0 ? void 0 : _a[index + 1]);
|
|
2019
|
+
const extendLine = (options === null || options === void 0 ? void 0 : options.hasRenderExtend) && ((_b = options.extendData) === null || _b === void 0 ? void 0 : _b[index + 1]);
|
|
3381
2020
|
hunkLine &&
|
|
3382
2021
|
hunkLine.unifiedInfo &&
|
|
3383
2022
|
hunkLine.unifiedInfo.startHiddenIndex < hunkLine.unifiedInfo.endHiddenIndex &&
|
|
3384
|
-
unifiedLines.push({ type: DiffFileLineType.hunk, index, lineNumber: index + 1, hunkLine: hunkLine });
|
|
2023
|
+
unifiedLines.push({ type: exports.DiffFileLineType.hunk, index, lineNumber: index + 1, hunkLine: hunkLine });
|
|
2024
|
+
hunkLine &&
|
|
2025
|
+
!hunkLine.splitInfo &&
|
|
2026
|
+
!hunkLine.unifiedInfo &&
|
|
2027
|
+
hunkLine.type === exports.DiffLineType.Hunk &&
|
|
2028
|
+
unifiedLines.push({ type: exports.DiffFileLineType.hunk, index, lineNumber: index + 1, hunkLine: hunkLine });
|
|
3385
2029
|
!unifiedLine.isHidden &&
|
|
3386
|
-
unifiedLines.push({ type: DiffFileLineType.content, index, lineNumber: index + 1, unifiedLine: unifiedLine });
|
|
2030
|
+
unifiedLines.push({ type: exports.DiffFileLineType.content, index, lineNumber: index + 1, unifiedLine: unifiedLine });
|
|
3387
2031
|
widgetLine &&
|
|
3388
|
-
unifiedLines.push({ type: DiffFileLineType.widget, index, lineNumber: index + 1, widgetLine: widgetLine });
|
|
2032
|
+
unifiedLines.push({ type: exports.DiffFileLineType.widget, index, lineNumber: index + 1, widgetLine: widgetLine });
|
|
3389
2033
|
extendLine &&
|
|
3390
|
-
unifiedLines.push({ type: DiffFileLineType.extend, index, lineNumber: index + 1, extendLine: extendLine });
|
|
2034
|
+
unifiedLines.push({ type: exports.DiffFileLineType.extend, index, lineNumber: index + 1, extendLine: extendLine });
|
|
3391
2035
|
});
|
|
3392
2036
|
return unifiedLines;
|
|
3393
2037
|
};
|
|
3394
2038
|
const getUnifiedContentLine = (diffFile) => {
|
|
3395
2039
|
const lines = getUnifiedLines(diffFile, {});
|
|
3396
|
-
return lines.filter((line) => line.type === DiffFileLineType.content);
|
|
2040
|
+
return lines.filter((line) => line.type === exports.DiffFileLineType.content);
|
|
3397
2041
|
};
|
|
3398
2042
|
|
|
2043
|
+
const versions = "0.0.7";
|
|
2044
|
+
|
|
3399
2045
|
const useUnmount = (cb, deps) => {
|
|
3400
2046
|
const ref = React.useRef(cb);
|
|
3401
2047
|
ref.current = cb;
|
|
@@ -3405,24 +2051,24 @@ const useUnmount = (cb, deps) => {
|
|
|
3405
2051
|
const isClient = typeof window !== "undefined";
|
|
3406
2052
|
const useSafeLayout = isClient ? React.useLayoutEffect : React.useEffect;
|
|
3407
2053
|
|
|
2054
|
+
var _TextMeasure_instances, _TextMeasure_key, _TextMeasure_map, _TextMeasure_getInstance;
|
|
3408
2055
|
let canvasCtx = null;
|
|
3409
2056
|
class TextMeasure {
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
return canvasCtx;
|
|
2057
|
+
constructor() {
|
|
2058
|
+
_TextMeasure_instances.add(this);
|
|
2059
|
+
_TextMeasure_key.set(this, "");
|
|
2060
|
+
_TextMeasure_map.set(this, {});
|
|
3415
2061
|
}
|
|
3416
2062
|
measure(text, font) {
|
|
3417
|
-
const currentKey = `${font
|
|
3418
|
-
if (this
|
|
3419
|
-
return this
|
|
2063
|
+
const currentKey = `${font === null || font === void 0 ? void 0 : font.fontFamily}-${font === null || font === void 0 ? void 0 : font.fontStyle}-${font === null || font === void 0 ? void 0 : font.fontSize}-${text}`;
|
|
2064
|
+
if (__classPrivateFieldGet$1(this, _TextMeasure_map, "f")[currentKey]) {
|
|
2065
|
+
return __classPrivateFieldGet$1(this, _TextMeasure_map, "f")[currentKey];
|
|
3420
2066
|
}
|
|
3421
|
-
const instance = this
|
|
2067
|
+
const instance = __classPrivateFieldGet$1(this, _TextMeasure_instances, "m", _TextMeasure_getInstance).call(this);
|
|
3422
2068
|
if (font) {
|
|
3423
2069
|
const currentFontKey = `${font.fontFamily}-${font.fontStyle}-${font.fontSize}`;
|
|
3424
|
-
if (this
|
|
3425
|
-
this
|
|
2070
|
+
if (__classPrivateFieldGet$1(this, _TextMeasure_key, "f") !== currentFontKey) {
|
|
2071
|
+
__classPrivateFieldSet$1(this, _TextMeasure_key, currentFontKey, "f");
|
|
3426
2072
|
instance.font = `${font.fontStyle || ""} ${font.fontSize || ""} ${font.fontFamily || ""}`;
|
|
3427
2073
|
}
|
|
3428
2074
|
}
|
|
@@ -3433,6 +2079,10 @@ class TextMeasure {
|
|
|
3433
2079
|
return textWidth;
|
|
3434
2080
|
}
|
|
3435
2081
|
}
|
|
2082
|
+
_TextMeasure_key = new WeakMap(), _TextMeasure_map = new WeakMap(), _TextMeasure_instances = new WeakSet(), _TextMeasure_getInstance = function _TextMeasure_getInstance() {
|
|
2083
|
+
canvasCtx = canvasCtx || document.createElement("canvas").getContext("2d");
|
|
2084
|
+
return canvasCtx;
|
|
2085
|
+
};
|
|
3436
2086
|
const measureInstance = new TextMeasure();
|
|
3437
2087
|
const useTextWidth = ({ text, font, }) => {
|
|
3438
2088
|
const [width, setWidth] = React.useState(0);
|
|
@@ -3450,19 +2100,21 @@ const useDomWidth = ({ selector, enable }) => {
|
|
|
3450
2100
|
React.useEffect(() => {
|
|
3451
2101
|
if (enable) {
|
|
3452
2102
|
const container = document.querySelector(`#diff-root${id}`);
|
|
3453
|
-
const wrapper = container
|
|
2103
|
+
const wrapper = container === null || container === void 0 ? void 0 : container.querySelector(selector);
|
|
3454
2104
|
if (!wrapper)
|
|
3455
2105
|
return;
|
|
3456
2106
|
const typedWrapper = wrapper;
|
|
3457
2107
|
const cb = () => {
|
|
3458
|
-
|
|
3459
|
-
|
|
2108
|
+
var _a;
|
|
2109
|
+
const rect = wrapper === null || wrapper === void 0 ? void 0 : wrapper.getBoundingClientRect();
|
|
2110
|
+
setWidth((_a = rect === null || rect === void 0 ? void 0 : rect.width) !== null && _a !== void 0 ? _a : 0);
|
|
3460
2111
|
};
|
|
3461
2112
|
cb();
|
|
3462
2113
|
const cleanCb = () => {
|
|
2114
|
+
var _a;
|
|
3463
2115
|
typedWrapper.__observeCallback.delete(cb);
|
|
3464
2116
|
if (typedWrapper.__observeCallback.size === 0) {
|
|
3465
|
-
typedWrapper.__observeInstance
|
|
2117
|
+
(_a = typedWrapper.__observeInstance) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
3466
2118
|
typedWrapper.removeAttribute("data-observe");
|
|
3467
2119
|
delete typedWrapper.__observeCallback;
|
|
3468
2120
|
delete typedWrapper.__observeInstance;
|
|
@@ -3499,7 +2151,7 @@ const useSyncHeight = ({ selector, side, enable, }) => {
|
|
|
3499
2151
|
useSafeLayout(() => {
|
|
3500
2152
|
if (enable) {
|
|
3501
2153
|
const container = document.querySelector(`#diff-root${id}`);
|
|
3502
|
-
const elements = Array.from(container
|
|
2154
|
+
const elements = Array.from((container === null || container === void 0 ? void 0 : container.querySelectorAll(selector)) || []);
|
|
3503
2155
|
if (elements.length === 2) {
|
|
3504
2156
|
const ele1 = elements[0];
|
|
3505
2157
|
const ele2 = elements[1];
|
|
@@ -3527,7 +2179,7 @@ const useSyncHeight = ({ selector, side, enable, }) => {
|
|
|
3527
2179
|
target.setAttribute("data-observe", "height");
|
|
3528
2180
|
return () => {
|
|
3529
2181
|
observer.disconnect();
|
|
3530
|
-
target
|
|
2182
|
+
target === null || target === void 0 ? void 0 : target.removeAttribute("data-observe");
|
|
3531
2183
|
};
|
|
3532
2184
|
}
|
|
3533
2185
|
}
|
|
@@ -3570,12 +2222,13 @@ const getLineNumberBG = (isAdded, isDelete, hasDiff) => {
|
|
|
3570
2222
|
};
|
|
3571
2223
|
|
|
3572
2224
|
const _DiffSplitExtendLine$1 = ({ index, diffFile, side, lineNumber, }) => {
|
|
2225
|
+
var _a, _b;
|
|
3573
2226
|
const { useDiffContext } = useDiffViewContext();
|
|
3574
2227
|
const { extendData, renderExtendLine } = useDiffContext(React__namespace.useCallback((s) => ({ extendData: s.extendData, renderExtendLine: s.renderExtendLine }), []));
|
|
3575
2228
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
3576
2229
|
const newLine = diffFile.getSplitRightLine(index);
|
|
3577
|
-
const oldLineExtend = extendData
|
|
3578
|
-
const newLineExtend = extendData
|
|
2230
|
+
const oldLineExtend = (_a = extendData === null || extendData === void 0 ? void 0 : extendData.oldFile) === null || _a === void 0 ? void 0 : _a[oldLine === null || oldLine === void 0 ? void 0 : oldLine.lineNumber];
|
|
2231
|
+
const newLineExtend = (_b = extendData === null || extendData === void 0 ? void 0 : extendData.newFile) === null || _b === void 0 ? void 0 : _b[newLine === null || newLine === void 0 ? void 0 : newLine.lineNumber];
|
|
3579
2232
|
const currentExtend = side === exports.SplitSide.old ? oldLineExtend : newLineExtend;
|
|
3580
2233
|
const currentLineNumber = side === exports.SplitSide.old ? oldLine.lineNumber : newLine.lineNumber;
|
|
3581
2234
|
const otherSide = side === exports.SplitSide.old ? exports.SplitSide.new : exports.SplitSide.old;
|
|
@@ -3592,20 +2245,20 @@ const _DiffSplitExtendLine$1 = ({ index, diffFile, side, lineNumber, }) => {
|
|
|
3592
2245
|
return null;
|
|
3593
2246
|
return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-extend`, "data-state": "extend", "data-side": exports.SplitSide[side], className: "diff-line diff-line-extend" }, currentExtend ? (React__namespace.createElement("td", { className: `diff-line-extend-${exports.SplitSide[side]}-content p-0`, colSpan: 2 },
|
|
3594
2247
|
React__namespace.createElement("div", { className: "diff-line-extend-wrapper sticky left-0", style: { width } }, width > 0 &&
|
|
3595
|
-
renderExtendLine
|
|
2248
|
+
(renderExtendLine === null || renderExtendLine === void 0 ? void 0 : renderExtendLine({
|
|
3596
2249
|
diffFile,
|
|
3597
2250
|
side,
|
|
3598
2251
|
lineNumber: currentLineNumber,
|
|
3599
2252
|
data: currentExtend.data,
|
|
3600
2253
|
onUpdate: diffFile.notifyAll,
|
|
3601
|
-
})))) : (React__namespace.createElement("td", { className: `diff-line-extend-${exports.SplitSide[side]}-placeholder p-0 select-none`, style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
|
|
2254
|
+
}))))) : (React__namespace.createElement("td", { className: `diff-line-extend-${exports.SplitSide[side]}-placeholder p-0 select-none`, style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
|
|
3602
2255
|
React__namespace.createElement("span", null, "\u2002")))));
|
|
3603
2256
|
};
|
|
3604
2257
|
const DiffSplitExtendLine$1 = ({ index, diffFile, side, lineNumber, }) => {
|
|
3605
2258
|
const { useDiffContext } = useDiffViewContext();
|
|
3606
2259
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
3607
2260
|
const newLine = diffFile.getSplitRightLine(index);
|
|
3608
|
-
const hasExtend = useDiffContext(React__namespace.useCallback((s) => s.extendData
|
|
2261
|
+
const hasExtend = useDiffContext(React__namespace.useCallback((s) => { var _a, _b, _c, _d; return ((_b = (_a = s.extendData) === null || _a === void 0 ? void 0 : _a.oldFile) === null || _b === void 0 ? void 0 : _b[oldLine === null || oldLine === void 0 ? void 0 : oldLine.lineNumber]) || ((_d = (_c = s.extendData) === null || _c === void 0 ? void 0 : _c.newFile) === null || _d === void 0 ? void 0 : _d[newLine === null || newLine === void 0 ? void 0 : newLine.lineNumber]); }, [oldLine === null || oldLine === void 0 ? void 0 : oldLine.lineNumber, newLine === null || newLine === void 0 ? void 0 : newLine.lineNumber]));
|
|
3609
2262
|
// if the expand action not enabled, the `isHidden` property will never change
|
|
3610
2263
|
const enableExpand = diffFile.getExpandEnabled();
|
|
3611
2264
|
const currentLine = side === exports.SplitSide.old ? oldLine : newLine;
|
|
@@ -3629,6 +2282,7 @@ const ExpandAll = ({ className }) => {
|
|
|
3629
2282
|
};
|
|
3630
2283
|
|
|
3631
2284
|
const _DiffSplitHunkLine = ({ index, diffFile, side, lineNumber, }) => {
|
|
2285
|
+
var _a;
|
|
3632
2286
|
const currentHunk = diffFile.getSplitHunkLine(index);
|
|
3633
2287
|
const expandEnabled = diffFile.getExpandEnabled();
|
|
3634
2288
|
useSyncHeight({
|
|
@@ -3637,6 +2291,7 @@ const _DiffSplitHunkLine = ({ index, diffFile, side, lineNumber, }) => {
|
|
|
3637
2291
|
enable: side === exports.SplitSide.new,
|
|
3638
2292
|
});
|
|
3639
2293
|
const enableHunkAction = side === exports.SplitSide.old;
|
|
2294
|
+
const couldExpand = expandEnabled && currentHunk && currentHunk.splitInfo;
|
|
3640
2295
|
const isExpandAll = currentHunk &&
|
|
3641
2296
|
currentHunk.splitInfo &&
|
|
3642
2297
|
currentHunk.splitInfo.endHiddenIndex - currentHunk.splitInfo.startHiddenIndex < composeLen;
|
|
@@ -3646,7 +2301,7 @@ const _DiffSplitHunkLine = ({ index, diffFile, side, lineNumber, }) => {
|
|
|
3646
2301
|
React__namespace.createElement("td", { className: "diff-line-hunk-action sticky left-0 p-[1px] w-[1%] min-w-[40px] select-none", style: {
|
|
3647
2302
|
backgroundColor: `var(${hunkLineNumberBGName})`,
|
|
3648
2303
|
color: `var(${plainLineNumberColorName})`,
|
|
3649
|
-
} },
|
|
2304
|
+
} }, couldExpand ? (isFirstLine ? (React__namespace.createElement("button", { className: "w-full diff-widget-tooltip hover:bg-blue-300 flex justify-center items-center py-[6px] cursor-pointer rounded-[2px]", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onSplitHunkExpand("up", index) },
|
|
3650
2305
|
React__namespace.createElement(ExpandUp, { className: "fill-current" }))) : isLastLine ? (React__namespace.createElement("button", { className: "w-full diff-widget-tooltip hover:bg-blue-300 flex justify-center items-center py-[6px] cursor-pointer rounded-[2px] relative", title: "Expand Down", "data-title": "Expand Down", onClick: () => {
|
|
3651
2306
|
diffFile.onSplitHunkExpand("down", index);
|
|
3652
2307
|
} },
|
|
@@ -3659,7 +2314,7 @@ const _DiffSplitHunkLine = ({ index, diffFile, side, lineNumber, }) => {
|
|
|
3659
2314
|
React__namespace.createElement("td", { className: "diff-line-hunk-content pr-[10px] align-middle", style: { backgroundColor: `var(${hunkContentBGName})` } },
|
|
3660
2315
|
React__namespace.createElement("div", { className: "pl-[1.5em]", style: {
|
|
3661
2316
|
color: `var(${hunkContentColorName})`,
|
|
3662
|
-
} }, currentHunk.splitInfo.plainText)))) : (React__namespace.createElement("td", { className: "diff-line-hunk-placeholder select-none", colSpan: 2, style: { backgroundColor: `var(${hunkContentBGName})` } },
|
|
2317
|
+
} }, ((_a = currentHunk.splitInfo) === null || _a === void 0 ? void 0 : _a.plainText) || currentHunk.text)))) : (React__namespace.createElement("td", { className: "diff-line-hunk-placeholder select-none", colSpan: 2, style: { backgroundColor: `var(${hunkContentBGName})` } },
|
|
3663
2318
|
React__namespace.createElement("div", { className: "min-h-[28px]" }, "\u2002")))));
|
|
3664
2319
|
};
|
|
3665
2320
|
const DiffSplitHunkLine$1 = ({ index, diffFile, side, lineNumber, }) => {
|
|
@@ -3667,7 +2322,8 @@ const DiffSplitHunkLine$1 = ({ index, diffFile, side, lineNumber, }) => {
|
|
|
3667
2322
|
const currentIsShow = currentHunk &&
|
|
3668
2323
|
currentHunk.splitInfo &&
|
|
3669
2324
|
currentHunk.splitInfo.startHiddenIndex < currentHunk.splitInfo.endHiddenIndex;
|
|
3670
|
-
|
|
2325
|
+
const currentIsPureHunk = currentHunk && diffFile._getIsPureDiffRender() && !currentHunk.splitInfo;
|
|
2326
|
+
if (!currentIsShow && !currentIsPureHunk)
|
|
3671
2327
|
return null;
|
|
3672
2328
|
return React__namespace.createElement(_DiffSplitHunkLine, { index: index, diffFile: diffFile, side: side, lineNumber: lineNumber });
|
|
3673
2329
|
};
|
|
@@ -3684,7 +2340,7 @@ const DiffSplitAddWidget = ({ side, className, lineNumber, onWidgetClick, onOpen
|
|
|
3684
2340
|
backgroundColor: `var(${addWidgetBGName})`,
|
|
3685
2341
|
}, onClick: () => {
|
|
3686
2342
|
onOpenAddWidget(lineNumber, side);
|
|
3687
|
-
onWidgetClick
|
|
2343
|
+
onWidgetClick === null || onWidgetClick === void 0 ? void 0 : onWidgetClick(lineNumber, side);
|
|
3688
2344
|
} }, "+")));
|
|
3689
2345
|
};
|
|
3690
2346
|
const DiffUnifiedAddWidget = ({ lineNumber, side, onWidgetClick, onOpenAddWidget, }) => {
|
|
@@ -3699,12 +2355,12 @@ const DiffUnifiedAddWidget = ({ lineNumber, side, onWidgetClick, onOpenAddWidget
|
|
|
3699
2355
|
backgroundColor: `var(${addWidgetBGName})`,
|
|
3700
2356
|
}, onClick: () => {
|
|
3701
2357
|
onOpenAddWidget(lineNumber, side);
|
|
3702
|
-
onWidgetClick
|
|
2358
|
+
onWidgetClick === null || onWidgetClick === void 0 ? void 0 : onWidgetClick(lineNumber, side);
|
|
3703
2359
|
} }, "+")));
|
|
3704
2360
|
};
|
|
3705
2361
|
|
|
3706
2362
|
const DiffString = ({ rawLine, diffLine, operator, }) => {
|
|
3707
|
-
const range = diffLine
|
|
2363
|
+
const range = diffLine === null || diffLine === void 0 ? void 0 : diffLine.range;
|
|
3708
2364
|
if (range) {
|
|
3709
2365
|
const str1 = rawLine.slice(0, range.location);
|
|
3710
2366
|
const str2 = rawLine.slice(range.location, range.location + range.length);
|
|
@@ -3729,15 +2385,17 @@ const DiffString = ({ rawLine, diffLine, operator, }) => {
|
|
|
3729
2385
|
return React__namespace.createElement("span", { className: "diff-line-content-raw" }, rawLine);
|
|
3730
2386
|
};
|
|
3731
2387
|
const DiffSyntax = ({ rawLine, diffLine, operator, syntaxLine, }) => {
|
|
2388
|
+
var _a, _b;
|
|
3732
2389
|
if (!syntaxLine) {
|
|
3733
2390
|
return React__namespace.createElement(DiffString, { rawLine: rawLine, diffLine: diffLine, operator: operator });
|
|
3734
2391
|
}
|
|
3735
|
-
const range = diffLine
|
|
2392
|
+
const range = diffLine === null || diffLine === void 0 ? void 0 : diffLine.range;
|
|
3736
2393
|
if (range) {
|
|
3737
2394
|
return (React__namespace.createElement("span", { className: "diff-line-syntax-raw" },
|
|
3738
|
-
React__namespace.createElement("span", { "data-range-start": range.location, "data-range-end": range.location + range.length }, syntaxLine.nodeList
|
|
2395
|
+
React__namespace.createElement("span", { "data-range-start": range.location, "data-range-end": range.location + range.length }, (_a = syntaxLine.nodeList) === null || _a === void 0 ? void 0 : _a.map(({ node, wrapper }, index) => {
|
|
2396
|
+
var _a, _b, _c, _d;
|
|
3739
2397
|
if (node.endIndex < range.location || range.location + range.length < node.startIndex) {
|
|
3740
|
-
return (React__namespace.createElement("span", { key: index, "data-start": node.startIndex, "data-end": node.endIndex, className: wrapper
|
|
2398
|
+
return (React__namespace.createElement("span", { key: index, "data-start": node.startIndex, "data-end": node.endIndex, className: (_b = (_a = wrapper === null || wrapper === void 0 ? void 0 : wrapper.properties) === null || _a === void 0 ? void 0 : _a.className) === null || _b === void 0 ? void 0 : _b.join(" ") }, node.value));
|
|
3741
2399
|
}
|
|
3742
2400
|
else {
|
|
3743
2401
|
const index1 = range.location - node.startIndex;
|
|
@@ -3748,7 +2406,7 @@ const DiffSyntax = ({ rawLine, diffLine, operator, syntaxLine, }) => {
|
|
|
3748
2406
|
const isStart = str1.length || range.location === node.startIndex;
|
|
3749
2407
|
const isEnd = str3.length || node.endIndex === range.location + range.length - 1;
|
|
3750
2408
|
const isNewLineSymbolChanged = range.isNewLineSymbolChanged;
|
|
3751
|
-
return (React__namespace.createElement("span", { key: index, "data-start": node.startIndex, "data-end": node.endIndex, className: wrapper
|
|
2409
|
+
return (React__namespace.createElement("span", { key: index, "data-start": node.startIndex, "data-end": node.endIndex, className: (_d = (_c = wrapper === null || wrapper === void 0 ? void 0 : wrapper.properties) === null || _c === void 0 ? void 0 : _c.className) === null || _d === void 0 ? void 0 : _d.join(" ") },
|
|
3752
2410
|
str1,
|
|
3753
2411
|
React__namespace.createElement("span", { "data-diff-highlight": true, style: {
|
|
3754
2412
|
backgroundColor: operator === "add" ? `var(${addContentHighlightBGName})` : `var(${delContentHighlightBGName})`,
|
|
@@ -3769,12 +2427,16 @@ const DiffSyntax = ({ rawLine, diffLine, operator, syntaxLine, }) => {
|
|
|
3769
2427
|
}
|
|
3770
2428
|
}))));
|
|
3771
2429
|
}
|
|
3772
|
-
return (React__namespace.createElement("span", { className: "diff-line-syntax-raw" },
|
|
2430
|
+
return (React__namespace.createElement("span", { className: "diff-line-syntax-raw" }, (_b = syntaxLine === null || syntaxLine === void 0 ? void 0 : syntaxLine.nodeList) === null || _b === void 0 ? void 0 : _b.map(({ node, wrapper }, index) => {
|
|
2431
|
+
var _a, _b;
|
|
2432
|
+
return (React__namespace.createElement("span", { key: index, "data-start": node.startIndex, "data-end": node.endIndex, className: (_b = (_a = wrapper === null || wrapper === void 0 ? void 0 : wrapper.properties) === null || _a === void 0 ? void 0 : _a.className) === null || _b === void 0 ? void 0 : _b.join(" ") }, node.value));
|
|
2433
|
+
})));
|
|
3773
2434
|
};
|
|
3774
2435
|
const DiffContent = ({ diffLine, rawLine, syntaxLine, enableWrap, enableHighlight, }) => {
|
|
3775
|
-
|
|
3776
|
-
const
|
|
3777
|
-
const
|
|
2436
|
+
var _a;
|
|
2437
|
+
const isAdded = (diffLine === null || diffLine === void 0 ? void 0 : diffLine.type) === exports.DiffLineType.Add;
|
|
2438
|
+
const isDelete = (diffLine === null || diffLine === void 0 ? void 0 : diffLine.type) === exports.DiffLineType.Delete;
|
|
2439
|
+
const isMaxLineLengthToIgnoreSyntax = ((_a = syntaxLine === null || syntaxLine === void 0 ? void 0 : syntaxLine.nodeList) === null || _a === void 0 ? void 0 : _a.length) > 150;
|
|
3778
2440
|
return (React__namespace.createElement("div", { className: "diff-line-content-item pl-[2.0em]", "data-val": rawLine, style: {
|
|
3779
2441
|
whiteSpace: enableWrap ? "pre-wrap" : "pre",
|
|
3780
2442
|
wordBreak: enableWrap ? "break-all" : "initial",
|
|
@@ -3788,15 +2450,16 @@ DiffWidgetContext.displayName = "DiffWidgetContext";
|
|
|
3788
2450
|
const useDiffWidgetContext = () => React.useContext(DiffWidgetContext);
|
|
3789
2451
|
|
|
3790
2452
|
const _DiffSplitLine$1 = ({ index, diffFile, lineNumber, side, }) => {
|
|
2453
|
+
var _a, _b;
|
|
3791
2454
|
const getCurrentSyntaxLine = side === exports.SplitSide.old ? diffFile.getOldSyntaxLine : diffFile.getNewSyntaxLine;
|
|
3792
2455
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
3793
2456
|
const newLine = diffFile.getSplitRightLine(index);
|
|
3794
2457
|
const currentLine = side === exports.SplitSide.old ? oldLine : newLine;
|
|
3795
|
-
const hasDiff = !!currentLine
|
|
2458
|
+
const hasDiff = !!(currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff);
|
|
3796
2459
|
const hasContent = !!currentLine.lineNumber;
|
|
3797
|
-
const hasChange = checkDiffLineIncludeChange(currentLine
|
|
3798
|
-
const isAdded = currentLine
|
|
3799
|
-
const isDelete = currentLine
|
|
2460
|
+
const hasChange = checkDiffLineIncludeChange(currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff);
|
|
2461
|
+
const isAdded = ((_a = currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff) === null || _a === void 0 ? void 0 : _a.type) === exports.DiffLineType.Add;
|
|
2462
|
+
const isDelete = ((_b = currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff) === null || _b === void 0 ? void 0 : _b.type) === exports.DiffLineType.Delete;
|
|
3800
2463
|
const { useDiffContext } = useDiffViewContext();
|
|
3801
2464
|
const { enableHighlight, enableAddWidget, onAddWidgetClick } = useDiffContext(React__namespace.useCallback((s) => ({
|
|
3802
2465
|
enableHighlight: s.enableHighlight,
|
|
@@ -3822,7 +2485,7 @@ const _DiffSplitLine$1 = ({ index, diffFile, lineNumber, side, }) => {
|
|
|
3822
2485
|
const DiffSplitLine$1 = ({ index, diffFile, lineNumber, side, }) => {
|
|
3823
2486
|
const getCurrentLine = side === exports.SplitSide.old ? diffFile.getSplitLeftLine : diffFile.getSplitRightLine;
|
|
3824
2487
|
const currentLine = getCurrentLine(index);
|
|
3825
|
-
if (currentLine
|
|
2488
|
+
if (currentLine === null || currentLine === void 0 ? void 0 : currentLine.isHidden)
|
|
3826
2489
|
return null;
|
|
3827
2490
|
return React__namespace.createElement(_DiffSplitLine$1, { index: index, diffFile: diffFile, lineNumber: lineNumber, side: side });
|
|
3828
2491
|
};
|
|
@@ -3844,12 +2507,12 @@ const _DiffSplitWidgetLine$1 = ({ diffFile, side, lineNumber, currentLine, setWi
|
|
|
3844
2507
|
return null;
|
|
3845
2508
|
return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-widget`, "data-state": "widget", "data-side": exports.SplitSide[side], className: "diff-line diff-line-widget" }, currentWidget ? (React__namespace.createElement("td", { className: `diff-line-widget-${exports.SplitSide[side]}-content p-0`, colSpan: 2 },
|
|
3846
2509
|
React__namespace.createElement("div", { className: "diff-line-widget-wrapper sticky left-0", style: { width } }, width > 0 &&
|
|
3847
|
-
renderWidgetLine
|
|
2510
|
+
(renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({
|
|
3848
2511
|
diffFile,
|
|
3849
2512
|
side,
|
|
3850
2513
|
lineNumber: currentLine.lineNumber,
|
|
3851
2514
|
onClose: () => setWidget({}),
|
|
3852
|
-
})))) : (React__namespace.createElement("td", { className: `diff-line-widget-${exports.SplitSide[side]}-placeholder p-0`, style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
|
|
2515
|
+
}))))) : (React__namespace.createElement("td", { className: `diff-line-widget-${exports.SplitSide[side]}-placeholder p-0`, style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
|
|
3853
2516
|
React__namespace.createElement("span", null, "\u2002")))));
|
|
3854
2517
|
};
|
|
3855
2518
|
const DiffSplitWidgetLine$1 = ({ index, diffFile, side, lineNumber, }) => {
|
|
@@ -3965,18 +2628,19 @@ const DiffSplitViewNormal = React.memo(({ diffFile }) => {
|
|
|
3965
2628
|
DiffSplitViewNormal.displayName = "DiffSplitViewNormal";
|
|
3966
2629
|
|
|
3967
2630
|
const _DiffSplitExtendLine = ({ index, diffFile, lineNumber, }) => {
|
|
2631
|
+
var _a, _b;
|
|
3968
2632
|
const { useDiffContext } = useDiffViewContext();
|
|
3969
2633
|
// 需要显示的时候才进行方法订阅,可以大幅度提高性能
|
|
3970
2634
|
const { extendData, renderExtendLine } = useDiffContext(React__namespace.useCallback((s) => ({ extendData: s.extendData, renderExtendLine: s.renderExtendLine }), []));
|
|
3971
2635
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
3972
2636
|
const newLine = diffFile.getSplitRightLine(index);
|
|
3973
|
-
const oldLineExtend = extendData
|
|
3974
|
-
const newLineExtend = extendData
|
|
2637
|
+
const oldLineExtend = (_a = extendData === null || extendData === void 0 ? void 0 : extendData.oldFile) === null || _a === void 0 ? void 0 : _a[oldLine === null || oldLine === void 0 ? void 0 : oldLine.lineNumber];
|
|
2638
|
+
const newLineExtend = (_b = extendData === null || extendData === void 0 ? void 0 : extendData.newFile) === null || _b === void 0 ? void 0 : _b[newLine === null || newLine === void 0 ? void 0 : newLine.lineNumber];
|
|
3975
2639
|
if (!renderExtendLine)
|
|
3976
2640
|
return null;
|
|
3977
2641
|
return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-extend`, "data-state": "extend", className: "diff-line diff-line-extend" },
|
|
3978
2642
|
oldLineExtend ? (React__namespace.createElement("td", { className: "diff-line-extend-old-content p-0", colSpan: 2 },
|
|
3979
|
-
React__namespace.createElement("div", { className: "diff-line-extend-wrapper" }, renderExtendLine
|
|
2643
|
+
React__namespace.createElement("div", { className: "diff-line-extend-wrapper" }, renderExtendLine === null || renderExtendLine === void 0 ? void 0 : renderExtendLine({
|
|
3980
2644
|
diffFile,
|
|
3981
2645
|
side: exports.SplitSide.old,
|
|
3982
2646
|
lineNumber: oldLine.lineNumber,
|
|
@@ -3985,7 +2649,7 @@ const _DiffSplitExtendLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
3985
2649
|
})))) : (React__namespace.createElement("td", { className: "diff-line-extend-old-placeholder p-0 select-none", style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
|
|
3986
2650
|
React__namespace.createElement("span", null, "\u2002"))),
|
|
3987
2651
|
newLineExtend ? (React__namespace.createElement("td", { className: "diff-line-extend-new-content p-0 border-l-[1px] border-l-[#ccc]", colSpan: 2 },
|
|
3988
|
-
React__namespace.createElement("div", { className: "diff-line-extend-wrapper" }, renderExtendLine
|
|
2652
|
+
React__namespace.createElement("div", { className: "diff-line-extend-wrapper" }, renderExtendLine === null || renderExtendLine === void 0 ? void 0 : renderExtendLine({
|
|
3989
2653
|
diffFile,
|
|
3990
2654
|
side: exports.SplitSide.new,
|
|
3991
2655
|
lineNumber: newLine.lineNumber,
|
|
@@ -3998,33 +2662,36 @@ const DiffSplitExtendLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
3998
2662
|
const { useDiffContext } = useDiffViewContext();
|
|
3999
2663
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
4000
2664
|
const newLine = diffFile.getSplitRightLine(index);
|
|
4001
|
-
const hasExtend = useDiffContext(React__namespace.useCallback((s) => s.extendData
|
|
2665
|
+
const hasExtend = useDiffContext(React__namespace.useCallback((s) => { var _a, _b, _c, _d; return ((_b = (_a = s.extendData) === null || _a === void 0 ? void 0 : _a.oldFile) === null || _b === void 0 ? void 0 : _b[oldLine === null || oldLine === void 0 ? void 0 : oldLine.lineNumber]) || ((_d = (_c = s.extendData) === null || _c === void 0 ? void 0 : _c.newFile) === null || _d === void 0 ? void 0 : _d[newLine === null || newLine === void 0 ? void 0 : newLine.lineNumber]); }, [oldLine === null || oldLine === void 0 ? void 0 : oldLine.lineNumber, newLine === null || newLine === void 0 ? void 0 : newLine.lineNumber]));
|
|
4002
2666
|
// if the expand action not enabled, the `isHidden` property will never change
|
|
4003
2667
|
const enableExpand = diffFile.getExpandEnabled();
|
|
4004
|
-
const currentIsShow = hasExtend && ((!oldLine
|
|
2668
|
+
const currentIsShow = hasExtend && ((!(oldLine === null || oldLine === void 0 ? void 0 : oldLine.isHidden) && !(newLine === null || newLine === void 0 ? void 0 : newLine.isHidden)) || !enableExpand);
|
|
4005
2669
|
if (!currentIsShow)
|
|
4006
2670
|
return null;
|
|
4007
2671
|
return React__namespace.createElement(_DiffSplitExtendLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
4008
2672
|
};
|
|
4009
2673
|
|
|
4010
2674
|
const DiffSplitHunkLine = ({ index, diffFile, lineNumber, }) => {
|
|
2675
|
+
var _a;
|
|
4011
2676
|
const currentHunk = diffFile.getSplitHunkLine(index);
|
|
4012
2677
|
const expandEnabled = diffFile.getExpandEnabled();
|
|
2678
|
+
const couldExpand = expandEnabled && currentHunk && currentHunk.splitInfo;
|
|
4013
2679
|
const isExpandAll = currentHunk &&
|
|
4014
2680
|
currentHunk.splitInfo &&
|
|
4015
2681
|
currentHunk.splitInfo.endHiddenIndex - currentHunk.splitInfo.startHiddenIndex < composeLen;
|
|
4016
2682
|
const currentIsShow = currentHunk &&
|
|
4017
2683
|
currentHunk.splitInfo &&
|
|
4018
2684
|
currentHunk.splitInfo.startHiddenIndex < currentHunk.splitInfo.endHiddenIndex;
|
|
2685
|
+
const currentIsPureHunk = currentHunk && diffFile._getIsPureDiffRender() && !currentHunk.splitInfo;
|
|
4019
2686
|
const isFirstLine = currentHunk && currentHunk.index === 0;
|
|
4020
2687
|
const isLastLine = currentHunk && currentHunk.isLast;
|
|
4021
|
-
if (!currentIsShow)
|
|
2688
|
+
if (!currentIsShow && !currentIsPureHunk)
|
|
4022
2689
|
return null;
|
|
4023
2690
|
return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-hunk`, "data-state": "hunk", className: "diff-line diff-line-hunk" },
|
|
4024
2691
|
React__namespace.createElement("td", { className: "diff-line-hunk-action p-[1px] w-[1%] min-w-[40px] select-none", style: {
|
|
4025
2692
|
backgroundColor: `var(${hunkLineNumberBGName})`,
|
|
4026
2693
|
color: `var(${plainLineNumberColorName})`,
|
|
4027
|
-
} },
|
|
2694
|
+
} }, couldExpand ? (isFirstLine ? (React__namespace.createElement("button", { className: "w-full diff-widget-tooltip hover:bg-blue-300 flex justify-center items-center py-[6px] cursor-pointer rounded-[2px]", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onSplitHunkExpand("up", index) },
|
|
4028
2695
|
React__namespace.createElement(ExpandUp, { className: "fill-current" }))) : isLastLine ? (React__namespace.createElement("button", { className: "w-full diff-widget-tooltip hover:bg-blue-300 flex justify-center items-center py-[6px] cursor-pointer rounded-[2px]", title: "Expand Down", "data-title": "Expand Down", onClick: () => diffFile.onSplitHunkExpand("down", index) },
|
|
4029
2696
|
React__namespace.createElement(ExpandDown, { className: "fill-current" }))) : isExpandAll ? (React__namespace.createElement("button", { className: "w-full diff-widget-tooltip hover:bg-blue-300 flex justify-center items-center py-[6px] cursor-pointer rounded-[2px]", title: "Expand All", "data-title": "Expand All", onClick: () => diffFile.onSplitHunkExpand("all", index) },
|
|
4030
2697
|
React__namespace.createElement(ExpandAll, { className: "fill-current" }))) : (React__namespace.createElement(React__namespace.Fragment, null,
|
|
@@ -4035,18 +2702,19 @@ const DiffSplitHunkLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
4035
2702
|
React__namespace.createElement("td", { className: "diff-line-hunk-content pr-[10px] align-middle", style: { backgroundColor: `var(${hunkContentBGName})` }, colSpan: 3 },
|
|
4036
2703
|
React__namespace.createElement("div", { className: "pl-[1.5em]", style: {
|
|
4037
2704
|
color: `var(${hunkContentColorName})`,
|
|
4038
|
-
} }, currentHunk.splitInfo.plainText))));
|
|
2705
|
+
} }, ((_a = currentHunk.splitInfo) === null || _a === void 0 ? void 0 : _a.plainText) || currentHunk.text))));
|
|
4039
2706
|
};
|
|
4040
2707
|
|
|
4041
2708
|
const _DiffSplitLine = ({ index, diffFile, lineNumber }) => {
|
|
2709
|
+
var _a, _b;
|
|
4042
2710
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
4043
2711
|
const newLine = diffFile.getSplitRightLine(index);
|
|
4044
|
-
const oldSyntaxLine = diffFile.getOldSyntaxLine(oldLine
|
|
4045
|
-
const newSyntaxLine = diffFile.getNewSyntaxLine(newLine
|
|
4046
|
-
const hasDiff = !!oldLine
|
|
4047
|
-
const hasChange = checkDiffLineIncludeChange(oldLine
|
|
4048
|
-
const oldLineIsDelete = oldLine
|
|
4049
|
-
const newLineIsAdded = newLine
|
|
2712
|
+
const oldSyntaxLine = diffFile.getOldSyntaxLine(oldLine === null || oldLine === void 0 ? void 0 : oldLine.lineNumber);
|
|
2713
|
+
const newSyntaxLine = diffFile.getNewSyntaxLine(newLine === null || newLine === void 0 ? void 0 : newLine.lineNumber);
|
|
2714
|
+
const hasDiff = !!(oldLine === null || oldLine === void 0 ? void 0 : oldLine.diff) || !!(newLine === null || newLine === void 0 ? void 0 : newLine.diff);
|
|
2715
|
+
const hasChange = checkDiffLineIncludeChange(oldLine === null || oldLine === void 0 ? void 0 : oldLine.diff) || checkDiffLineIncludeChange(newLine === null || newLine === void 0 ? void 0 : newLine.diff);
|
|
2716
|
+
const oldLineIsDelete = ((_a = oldLine === null || oldLine === void 0 ? void 0 : oldLine.diff) === null || _a === void 0 ? void 0 : _a.type) === exports.DiffLineType.Delete;
|
|
2717
|
+
const newLineIsAdded = ((_b = newLine === null || newLine === void 0 ? void 0 : newLine.diff) === null || _b === void 0 ? void 0 : _b.type) === exports.DiffLineType.Add;
|
|
4050
2718
|
const { useDiffContext } = useDiffViewContext();
|
|
4051
2719
|
const { enableHighlight, enableAddWidget, onAddWidgetClick } = useDiffContext(React__namespace.useCallback((s) => ({
|
|
4052
2720
|
enableHighlight: s.enableHighlight,
|
|
@@ -4082,7 +2750,7 @@ const _DiffSplitLine = ({ index, diffFile, lineNumber }) => {
|
|
|
4082
2750
|
const DiffSplitLine = ({ index, diffFile, lineNumber, }) => {
|
|
4083
2751
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
4084
2752
|
const newLine = diffFile.getSplitRightLine(index);
|
|
4085
|
-
if (oldLine
|
|
2753
|
+
if ((oldLine === null || oldLine === void 0 ? void 0 : oldLine.isHidden) && (newLine === null || newLine === void 0 ? void 0 : newLine.isHidden))
|
|
4086
2754
|
return null;
|
|
4087
2755
|
return React__namespace.createElement(_DiffSplitLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
4088
2756
|
};
|
|
@@ -4100,7 +2768,7 @@ const _DiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
4100
2768
|
return null;
|
|
4101
2769
|
return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-widget`, "data-state": "widget", className: "diff-line diff-line-widget" },
|
|
4102
2770
|
oldLineWidget ? (React__namespace.createElement("td", { className: "diff-line-widget-old-content p-0", colSpan: 2 },
|
|
4103
|
-
React__namespace.createElement("div", { className: "diff-line-widget-wrapper" }, renderWidgetLine
|
|
2771
|
+
React__namespace.createElement("div", { className: "diff-line-widget-wrapper" }, renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({
|
|
4104
2772
|
diffFile,
|
|
4105
2773
|
side: exports.SplitSide.old,
|
|
4106
2774
|
lineNumber: oldLine.lineNumber,
|
|
@@ -4108,7 +2776,7 @@ const _DiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
4108
2776
|
})))) : (React__namespace.createElement("td", { className: "diff-line-widget-old-placeholder p-0 select-none", style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
|
|
4109
2777
|
React__namespace.createElement("span", null, "\u2002"))),
|
|
4110
2778
|
newLineWidget ? (React__namespace.createElement("td", { className: "diff-line-widget-new-content p-0 border-l-[1px] border-l-[#ccc]", colSpan: 2 },
|
|
4111
|
-
React__namespace.createElement("div", { className: "diff-line-widget-wrapper" }, renderWidgetLine
|
|
2779
|
+
React__namespace.createElement("div", { className: "diff-line-widget-wrapper" }, renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({
|
|
4112
2780
|
diffFile,
|
|
4113
2781
|
side: exports.SplitSide.new,
|
|
4114
2782
|
lineNumber: newLine.lineNumber,
|
|
@@ -4233,8 +2901,8 @@ const _DiffUnifiedExtendLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
4233
2901
|
const { useDiffContext } = useDiffViewContext();
|
|
4234
2902
|
const renderExtendLine = useDiffContext(React.useCallback((s) => s.renderExtendLine, []));
|
|
4235
2903
|
const unifiedItem = diffFile.getUnifiedLine(index);
|
|
4236
|
-
const oldExtend = useDiffContext(React.useCallback((s) => s.extendData
|
|
4237
|
-
const newExtend = useDiffContext(React.useCallback((s) => s.extendData
|
|
2904
|
+
const oldExtend = useDiffContext(React.useCallback((s) => { var _a, _b; return (_b = (_a = s.extendData) === null || _a === void 0 ? void 0 : _a.oldFile) === null || _b === void 0 ? void 0 : _b[unifiedItem === null || unifiedItem === void 0 ? void 0 : unifiedItem.oldLineNumber]; }, [unifiedItem === null || unifiedItem === void 0 ? void 0 : unifiedItem.oldLineNumber]));
|
|
2905
|
+
const newExtend = useDiffContext(React.useCallback((s) => { var _a, _b; return (_b = (_a = s.extendData) === null || _a === void 0 ? void 0 : _a.newFile) === null || _b === void 0 ? void 0 : _b[unifiedItem === null || unifiedItem === void 0 ? void 0 : unifiedItem.newLineNumber]; }, [unifiedItem === null || unifiedItem === void 0 ? void 0 : unifiedItem.newLineNumber]));
|
|
4238
2906
|
const width = useDomWidth({
|
|
4239
2907
|
selector: ".unified-diff-table-wrapper",
|
|
4240
2908
|
enable: typeof renderExtendLine === "function",
|
|
@@ -4246,37 +2914,39 @@ const _DiffUnifiedExtendLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
4246
2914
|
React__namespace.createElement("div", { className: "diff-line-extend-wrapper sticky left-0", style: { width } },
|
|
4247
2915
|
width > 0 &&
|
|
4248
2916
|
oldExtend &&
|
|
4249
|
-
renderExtendLine
|
|
2917
|
+
(renderExtendLine === null || renderExtendLine === void 0 ? void 0 : renderExtendLine({
|
|
4250
2918
|
diffFile,
|
|
4251
2919
|
side: exports.SplitSide.old,
|
|
4252
2920
|
lineNumber: unifiedItem.oldLineNumber,
|
|
4253
2921
|
data: oldExtend.data,
|
|
4254
2922
|
onUpdate: diffFile.notifyAll,
|
|
4255
|
-
}),
|
|
2923
|
+
})),
|
|
4256
2924
|
width > 0 &&
|
|
4257
2925
|
newExtend &&
|
|
4258
|
-
renderExtendLine
|
|
2926
|
+
(renderExtendLine === null || renderExtendLine === void 0 ? void 0 : renderExtendLine({
|
|
4259
2927
|
diffFile,
|
|
4260
2928
|
side: exports.SplitSide.new,
|
|
4261
2929
|
lineNumber: unifiedItem.newLineNumber,
|
|
4262
2930
|
data: newExtend.data,
|
|
4263
2931
|
onUpdate: diffFile.notifyAll,
|
|
4264
|
-
})))));
|
|
2932
|
+
}))))));
|
|
4265
2933
|
};
|
|
4266
2934
|
const DiffUnifiedExtendLine = ({ index, diffFile, lineNumber, }) => {
|
|
4267
2935
|
const { useDiffContext } = useDiffViewContext();
|
|
4268
2936
|
const unifiedItem = diffFile.getUnifiedLine(index);
|
|
4269
|
-
const hasExtend = useDiffContext(React.useCallback((s) => s.extendData
|
|
2937
|
+
const hasExtend = useDiffContext(React.useCallback((s) => { var _a, _b, _c, _d; return ((_b = (_a = s.extendData) === null || _a === void 0 ? void 0 : _a.oldFile) === null || _b === void 0 ? void 0 : _b[unifiedItem === null || unifiedItem === void 0 ? void 0 : unifiedItem.oldLineNumber]) || ((_d = (_c = s.extendData) === null || _c === void 0 ? void 0 : _c.newFile) === null || _d === void 0 ? void 0 : _d[unifiedItem === null || unifiedItem === void 0 ? void 0 : unifiedItem.newLineNumber]); }, [unifiedItem.oldLineNumber, unifiedItem.newLineNumber]));
|
|
4270
2938
|
if (!hasExtend || !unifiedItem || unifiedItem.isHidden || !unifiedItem.diff)
|
|
4271
2939
|
return null;
|
|
4272
2940
|
return React__namespace.createElement(_DiffUnifiedExtendLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
4273
2941
|
};
|
|
4274
2942
|
|
|
4275
2943
|
const _DiffUnifiedHunkLine = ({ index, diffFile, lineNumber, }) => {
|
|
2944
|
+
var _a;
|
|
4276
2945
|
const currentHunk = diffFile.getUnifiedHunkLine(index);
|
|
4277
2946
|
const expandEnabled = diffFile.getExpandEnabled();
|
|
4278
2947
|
const { useDiffContext } = useDiffViewContext();
|
|
4279
2948
|
const enableWrap = useDiffContext(React.useCallback((s) => s.enableWrap, []));
|
|
2949
|
+
const couldExpand = expandEnabled && currentHunk && currentHunk.unifiedInfo;
|
|
4280
2950
|
const isExpandAll = currentHunk &&
|
|
4281
2951
|
currentHunk.unifiedInfo &&
|
|
4282
2952
|
currentHunk.unifiedInfo.endHiddenIndex - currentHunk.unifiedInfo.startHiddenIndex < composeLen;
|
|
@@ -4286,7 +2956,7 @@ const _DiffUnifiedHunkLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
4286
2956
|
React__namespace.createElement("td", { className: "diff-line-hunk-action sticky left-0 p-[1px] w-[1%] min-w-[100px] select-none", style: {
|
|
4287
2957
|
backgroundColor: `var(${hunkLineNumberBGName})`,
|
|
4288
2958
|
color: `var(${plainLineNumberColorName})`,
|
|
4289
|
-
} },
|
|
2959
|
+
} }, couldExpand ? (isFirstLine ? (React__namespace.createElement("button", { className: "w-full diff-widget-tooltip hover:bg-blue-300 flex justify-center items-center py-[6px] cursor-pointer rounded-[2px]", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onUnifiedHunkExpand("up", index) },
|
|
4290
2960
|
React__namespace.createElement(ExpandUp, { className: "fill-current" }))) : isLastLine ? (React__namespace.createElement("button", { className: "w-full diff-widget-tooltip hover:bg-blue-300 flex justify-center items-center py-[6px] cursor-pointer rounded-[2px]", title: "Expand Down", "data-title": "Expand Down", onClick: () => diffFile.onUnifiedHunkExpand("down", index) },
|
|
4291
2961
|
React__namespace.createElement(ExpandDown, { className: "fill-current" }))) : isExpandAll ? (React__namespace.createElement("button", { className: "w-full diff-widget-tooltip hover:bg-blue-300 flex justify-center items-center py-[6px] cursor-pointer rounded-[2px]", title: "Expand All", "data-title": "Expand All", onClick: () => diffFile.onUnifiedHunkExpand("all", index) },
|
|
4292
2962
|
React__namespace.createElement(ExpandAll, { className: "fill-current" }))) : (React__namespace.createElement(React__namespace.Fragment, null,
|
|
@@ -4299,14 +2969,15 @@ const _DiffUnifiedHunkLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
4299
2969
|
whiteSpace: enableWrap ? "pre-wrap" : "pre",
|
|
4300
2970
|
wordBreak: enableWrap ? "break-all" : "initial",
|
|
4301
2971
|
color: `var(${hunkContentColorName})`,
|
|
4302
|
-
} }, currentHunk.unifiedInfo.plainText))));
|
|
2972
|
+
} }, ((_a = currentHunk.unifiedInfo) === null || _a === void 0 ? void 0 : _a.plainText) || currentHunk.text))));
|
|
4303
2973
|
};
|
|
4304
2974
|
const DiffUnifiedHunkLine = ({ index, diffFile, lineNumber, }) => {
|
|
4305
2975
|
const currentHunk = diffFile.getUnifiedHunkLine(index);
|
|
4306
2976
|
const currentIsShow = currentHunk &&
|
|
4307
2977
|
currentHunk.unifiedInfo &&
|
|
4308
2978
|
currentHunk.unifiedInfo.startHiddenIndex < currentHunk.unifiedInfo.endHiddenIndex;
|
|
4309
|
-
|
|
2979
|
+
const currentIsPureHunk = currentHunk && diffFile._getIsPureDiffRender() && !currentHunk.unifiedInfo;
|
|
2980
|
+
if (!currentIsShow && !currentIsPureHunk)
|
|
4310
2981
|
return null;
|
|
4311
2982
|
return React__namespace.createElement(_DiffUnifiedHunkLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
4312
2983
|
};
|
|
@@ -4389,7 +3060,7 @@ const _DiffUnifiedLine = React.memo(({ index, diffFile, lineNumber }) => {
|
|
|
4389
3060
|
_DiffUnifiedLine.displayName = "_DiffUnifiedLine";
|
|
4390
3061
|
const DiffUnifiedLine = ({ index, diffFile, lineNumber, }) => {
|
|
4391
3062
|
const unifiedLine = diffFile.getUnifiedLine(index);
|
|
4392
|
-
if (unifiedLine
|
|
3063
|
+
if (unifiedLine === null || unifiedLine === void 0 ? void 0 : unifiedLine.isHidden)
|
|
4393
3064
|
return null;
|
|
4394
3065
|
return React__namespace.createElement(_DiffUnifiedLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
4395
3066
|
};
|
|
@@ -4411,10 +3082,10 @@ const _DiffUnifiedWidgetLine = ({ index, diffFile, oldWidget, newWidget, lineNum
|
|
|
4411
3082
|
React__namespace.createElement("div", { className: "diff-line-widget-wrapper sticky left-0", style: { width } },
|
|
4412
3083
|
width > 0 &&
|
|
4413
3084
|
oldWidget &&
|
|
4414
|
-
renderWidgetLine
|
|
3085
|
+
(renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({ diffFile, side: exports.SplitSide.old, lineNumber: unifiedItem.oldLineNumber, onClose })),
|
|
4415
3086
|
width > 0 &&
|
|
4416
3087
|
newWidget &&
|
|
4417
|
-
renderWidgetLine
|
|
3088
|
+
(renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({ diffFile, side: exports.SplitSide.new, lineNumber: unifiedItem.newLineNumber, onClose }))))));
|
|
4418
3089
|
};
|
|
4419
3090
|
const DiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
4420
3091
|
const { useWidget } = useDiffWidgetContext();
|
|
@@ -4479,9 +3150,8 @@ const DiffUnifiedView = React.memo(({ diffFile }) => {
|
|
|
4479
3150
|
});
|
|
4480
3151
|
DiffUnifiedView.displayName = "DiffUnifiedView";
|
|
4481
3152
|
|
|
4482
|
-
/* eslint-disable @typescript-eslint/no-unnecessary-type-constraint */
|
|
4483
|
-
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
4484
3153
|
const diffFontSizeName = "--diff-font-size--";
|
|
3154
|
+
_cacheMap.name = "@git-diff-view/react";
|
|
4485
3155
|
exports.SplitSide = void 0;
|
|
4486
3156
|
(function (SplitSide) {
|
|
4487
3157
|
SplitSide[SplitSide["old"] = 1] = "old";
|
|
@@ -4492,6 +3162,7 @@ const _InternalDiffView = (props) => {
|
|
|
4492
3162
|
const diffFileId = React.useMemo(() => diffFile.getId(), [diffFile]);
|
|
4493
3163
|
// performance optimization
|
|
4494
3164
|
const useDiffContext = React.useMemo(() => reactivityStore.createStore(() => {
|
|
3165
|
+
var _a, _b;
|
|
4495
3166
|
const id = reactivityStore.ref(diffFileId);
|
|
4496
3167
|
const setId = (_id) => (id.value = _id);
|
|
4497
3168
|
const mode = reactivityStore.ref(props.diffViewMode);
|
|
@@ -4505,8 +3176,8 @@ const _InternalDiffView = (props) => {
|
|
|
4505
3176
|
const fontSize = reactivityStore.ref(props.diffViewFontSize);
|
|
4506
3177
|
const setFontSize = (_fontSize) => (fontSize.value = _fontSize);
|
|
4507
3178
|
const extendData = reactivityStore.ref({
|
|
4508
|
-
oldFile: {
|
|
4509
|
-
newFile: {
|
|
3179
|
+
oldFile: Object.assign({}, (_a = props.extendData) === null || _a === void 0 ? void 0 : _a.oldFile),
|
|
3180
|
+
newFile: Object.assign({}, (_b = props.extendData) === null || _b === void 0 ? void 0 : _b.newFile),
|
|
4510
3181
|
});
|
|
4511
3182
|
const setExtendData = (_extendData) => {
|
|
4512
3183
|
const existOldKeys = Object.keys(extendData.value.oldFile || {});
|
|
@@ -4588,7 +3259,7 @@ const _InternalDiffView = (props) => {
|
|
|
4588
3259
|
]);
|
|
4589
3260
|
const value = React.useMemo(() => ({ useDiffContext }), [useDiffContext]);
|
|
4590
3261
|
return (React__namespace.createElement(DiffViewContext.Provider, { value: value },
|
|
4591
|
-
React__namespace.createElement("div", { className: "diff-tailwindcss-wrapper", "data-component": "git-diff-view", "data-version": `${"0.0.
|
|
3262
|
+
React__namespace.createElement("div", { className: "diff-tailwindcss-wrapper", "data-component": "git-diff-view", "data-version": `${"0.0.7"}` },
|
|
4592
3263
|
React__namespace.createElement("div", { className: "diff-style-root", style: {
|
|
4593
3264
|
// @ts-ignore
|
|
4594
3265
|
[diffFontSizeName]: diffViewFontSize + "px",
|
|
@@ -4597,15 +3268,16 @@ const _InternalDiffView = (props) => {
|
|
|
4597
3268
|
};
|
|
4598
3269
|
const InternalDiffView = React.memo(_InternalDiffView);
|
|
4599
3270
|
const DiffViewWithRef = (props, ref) => {
|
|
4600
|
-
const { registerHighlighter, autoDetectLang, data, diffFile: _diffFile,
|
|
3271
|
+
const { registerHighlighter, autoDetectLang, data, diffFile: _diffFile } = props, restProps = __rest(props, ["registerHighlighter", "autoDetectLang", "data", "diffFile"]);
|
|
4601
3272
|
const diffFile = React.useMemo(() => {
|
|
3273
|
+
var _a, _b, _c, _d, _e, _f;
|
|
4602
3274
|
if (_diffFile) {
|
|
4603
3275
|
const diffFile = DiffFile.createInstance({});
|
|
4604
3276
|
diffFile._mergeFullBundle(_diffFile._getFullBundle());
|
|
4605
3277
|
return diffFile;
|
|
4606
3278
|
}
|
|
4607
3279
|
else if (data) {
|
|
4608
|
-
return new DiffFile(data
|
|
3280
|
+
return new DiffFile(((_a = data === null || data === void 0 ? void 0 : data.oldFile) === null || _a === void 0 ? void 0 : _a.fileName) || "", ((_b = data === null || data === void 0 ? void 0 : data.oldFile) === null || _b === void 0 ? void 0 : _b.content) || "", ((_c = data === null || data === void 0 ? void 0 : data.newFile) === null || _c === void 0 ? void 0 : _c.fileName) || "", ((_d = data === null || data === void 0 ? void 0 : data.newFile) === null || _d === void 0 ? void 0 : _d.content) || "", (data === null || data === void 0 ? void 0 : data.hunks) || [], ((_e = data === null || data === void 0 ? void 0 : data.oldFile) === null || _e === void 0 ? void 0 : _e.fileLang) || "", ((_f = data === null || data === void 0 ? void 0 : data.newFile) === null || _f === void 0 ? void 0 : _f.fileLang) || "");
|
|
4609
3281
|
}
|
|
4610
3282
|
return null;
|
|
4611
3283
|
}, [data, _diffFile]);
|
|
@@ -4636,14 +3308,36 @@ const DiffViewWithRef = (props, ref) => {
|
|
|
4636
3308
|
React.useImperativeHandle(ref, () => ({ getDiffFileInstance: () => diffFile }), [diffFile]);
|
|
4637
3309
|
if (!diffFile)
|
|
4638
3310
|
return null;
|
|
4639
|
-
return (React__namespace.createElement(InternalDiffView, { key: diffFile.getId(),
|
|
3311
|
+
return (React__namespace.createElement(InternalDiffView, Object.assign({ key: diffFile.getId() }, restProps, { diffFile: diffFile, diffViewFontSize: restProps.diffViewFontSize || 14 })));
|
|
4640
3312
|
};
|
|
4641
3313
|
const DiffView = React.forwardRef(DiffViewWithRef);
|
|
4642
3314
|
DiffView.displayName = "DiffView";
|
|
4643
|
-
const version = "0.0.
|
|
3315
|
+
const version = "0.0.7";
|
|
4644
3316
|
|
|
3317
|
+
exports.DefaultDiffExpansionStep = DefaultDiffExpansionStep;
|
|
3318
|
+
exports.DiffFile = DiffFile;
|
|
3319
|
+
exports.DiffLine = DiffLine;
|
|
4645
3320
|
exports.DiffView = DiffView;
|
|
4646
3321
|
exports.DiffViewContext = DiffViewContext;
|
|
3322
|
+
exports.File = File;
|
|
3323
|
+
exports._cacheMap = _cacheMap;
|
|
3324
|
+
exports.assertNever = assertNever;
|
|
3325
|
+
exports.checkDiffLineIncludeChange = checkDiffLineIncludeChange;
|
|
3326
|
+
exports.composeLen = composeLen;
|
|
3327
|
+
exports.getDiffRange = getDiffRange;
|
|
3328
|
+
exports.getFile = getFile;
|
|
3329
|
+
exports.getHunkHeaderExpansionType = getHunkHeaderExpansionType;
|
|
3330
|
+
exports.getLang = getLang;
|
|
3331
|
+
exports.getLargestLineNumber = getLargestLineNumber;
|
|
3332
|
+
exports.getSplitContentLines = getSplitContentLines;
|
|
3333
|
+
exports.getSplitLines = getSplitLines;
|
|
3334
|
+
exports.getUnifiedContentLine = getUnifiedContentLine;
|
|
3335
|
+
exports.getUnifiedLines = getUnifiedLines;
|
|
3336
|
+
exports.hasRelativeChange = hasRelativeChange;
|
|
3337
|
+
exports.highlighter = highlighter;
|
|
3338
|
+
exports.numIterator = numIterator;
|
|
3339
|
+
exports.relativeChanges = relativeChanges;
|
|
4647
3340
|
exports.useDiffViewContext = useDiffViewContext;
|
|
4648
3341
|
exports.version = version;
|
|
3342
|
+
exports.versions = versions;
|
|
4649
3343
|
//# sourceMappingURL=index.development.js.map
|