@git-diff-view/react 0.0.5 → 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 +1284 -2408
- package/dist/cjs/index.development.js.map +1 -1
- package/dist/cjs/index.production.js +1256 -2412
- package/dist/cjs/index.production.js.map +1 -1
- package/dist/css/diff-view.css +1 -1
- package/dist/esm/index.mjs +1245 -2390
- package/dist/esm/index.mjs.map +1 -1
- package/dist/types/components/DiffContent.d.ts.map +1 -1
- package/dist/types/components/DiffSplitHunkLineNormal.d.ts +0 -4
- package/dist/types/components/DiffSplitHunkLineNormal.d.ts.map +1 -1
- package/dist/types/components/DiffSplitHunkLineWrap.d.ts +0 -3
- package/dist/types/components/DiffSplitHunkLineWrap.d.ts.map +1 -1
- package/dist/types/components/DiffSplitView.d.ts.map +1 -1
- package/dist/types/components/DiffSplitViewLineNormal.d.ts +9 -0
- package/dist/types/components/DiffSplitViewLineNormal.d.ts.map +1 -0
- package/dist/types/components/DiffSplitViewLineWrap.d.ts +7 -0
- package/dist/types/components/DiffSplitViewLineWrap.d.ts.map +1 -0
- package/dist/types/components/DiffSplitViewNormal.d.ts +1 -1
- package/dist/types/components/DiffSplitViewNormal.d.ts.map +1 -1
- package/dist/types/components/DiffSplitViewWrap.d.ts.map +1 -1
- package/dist/types/components/DiffUnifiedHunkLine.d.ts +0 -3
- package/dist/types/components/DiffUnifiedHunkLine.d.ts.map +1 -1
- package/dist/types/components/DiffUnifiedView.d.ts.map +1 -1
- package/dist/types/components/DiffView.d.ts +9 -3
- 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 +3 -3
- package/readme.md +68 -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);
|
|
857
|
-
return this;
|
|
858
|
-
}
|
|
859
|
-
const { ttl = this.ttl, start, noDisposeOnSet = this.noDisposeOnSet, sizeCalculation = this.sizeCalculation, status, } = setOptions;
|
|
860
|
-
let { noUpdateTTL = this.noUpdateTTL } = setOptions;
|
|
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);
|
|
121
|
+
set(key, value) {
|
|
122
|
+
if (this.has(key))
|
|
871
123
|
return this;
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
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;
|
|
1053
|
-
}
|
|
1054
|
-
/**
|
|
1055
|
-
* Like {@link LRUCache#get} but doesn't update recency or delete stale
|
|
1056
|
-
* items.
|
|
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;
|
|
124
|
+
__classPrivateFieldGet(this, _Cache_keyArray, "f").push(key);
|
|
125
|
+
this._checkLength();
|
|
126
|
+
return super.set(key, value);
|
|
1424
127
|
}
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
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) {
|
|
@@ -1515,6 +183,7 @@ lowlight.register("vue", function hljsDefineVue(hljs) {
|
|
|
1515
183
|
const highlighter = lowlight;
|
|
1516
184
|
let _autoDetectLang = true;
|
|
1517
185
|
let _maxLineToIgnoreSyntax = 2000;
|
|
186
|
+
const _ignoreSyntaxHighlightList = [];
|
|
1518
187
|
Object.defineProperty(highlighter, "maxLineToIgnoreSyntax", {
|
|
1519
188
|
get: () => _maxLineToIgnoreSyntax,
|
|
1520
189
|
});
|
|
@@ -1531,22 +200,43 @@ Object.defineProperty(highlighter, "setAutoDetectLang", {
|
|
|
1531
200
|
_autoDetectLang = v;
|
|
1532
201
|
},
|
|
1533
202
|
});
|
|
203
|
+
Object.defineProperty(highlighter, "ignoreSyntaxHighlightList", {
|
|
204
|
+
get: () => _ignoreSyntaxHighlightList,
|
|
205
|
+
});
|
|
206
|
+
Object.defineProperty(highlighter, "setIgnoreSyntaxHighlightList", {
|
|
207
|
+
value: (v) => {
|
|
208
|
+
_ignoreSyntaxHighlightList.length = 0;
|
|
209
|
+
_ignoreSyntaxHighlightList.push(...v);
|
|
210
|
+
},
|
|
211
|
+
});
|
|
1534
212
|
|
|
1535
|
-
|
|
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
|
+
}
|
|
1536
229
|
class File {
|
|
1537
|
-
raw
|
|
1538
|
-
|
|
1539
|
-
ast;
|
|
1540
|
-
rawFile = {};
|
|
1541
|
-
hasDoRaw = false;
|
|
1542
|
-
rawLength;
|
|
1543
|
-
syntaxFile = {};
|
|
1544
|
-
hasDoSyntax = false;
|
|
1545
|
-
syntaxLength;
|
|
1546
|
-
maxLineNumber = 0;
|
|
1547
|
-
constructor(raw, lang) {
|
|
230
|
+
constructor(raw, lang, fileName) {
|
|
231
|
+
_File_instances.add(this);
|
|
1548
232
|
this.raw = raw;
|
|
1549
233
|
this.lang = lang;
|
|
234
|
+
this.fileName = fileName;
|
|
235
|
+
this.rawFile = {};
|
|
236
|
+
this.hasDoRaw = false;
|
|
237
|
+
this.syntaxFile = {};
|
|
238
|
+
this.hasDoSyntax = false;
|
|
239
|
+
this.maxLineNumber = 0;
|
|
1550
240
|
Object.defineProperty(this, "__v_skip", { value: true });
|
|
1551
241
|
}
|
|
1552
242
|
doSyntax({ autoDetectLang, registerHighlighter, }) {
|
|
@@ -1569,15 +259,20 @@ class File {
|
|
|
1569
259
|
console.warn(`ignore syntax for current file, because the rawLength is too long: ${this.rawLength}`);
|
|
1570
260
|
return;
|
|
1571
261
|
}
|
|
262
|
+
if (this.fileName &&
|
|
263
|
+
_highlighter.ignoreSyntaxHighlightList.some((item) => item instanceof RegExp ? item.test(this.fileName) : this.fileName === item)) {
|
|
264
|
+
console.warn(`ignore syntax for current file, because the fileName is in the ignoreSyntaxHighlightList: ${this.fileName}`);
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
1572
267
|
if (hasRegisteredLang) {
|
|
1573
268
|
this.ast = _highlighter.highlight(this.lang, this.raw);
|
|
1574
269
|
}
|
|
1575
270
|
else {
|
|
1576
271
|
this.ast = _highlighter.highlightAuto(this.raw);
|
|
1577
272
|
}
|
|
1578
|
-
this
|
|
273
|
+
__classPrivateFieldGet(this, _File_instances, "m", _File_doAST).call(this);
|
|
1579
274
|
{
|
|
1580
|
-
this
|
|
275
|
+
__classPrivateFieldGet(this, _File_instances, "m", _File_doCheck).call(this);
|
|
1581
276
|
}
|
|
1582
277
|
this.hasDoSyntax = true;
|
|
1583
278
|
}
|
|
@@ -1588,108 +283,116 @@ class File {
|
|
|
1588
283
|
const rawArray = rawString.split("\n");
|
|
1589
284
|
this.rawLength = rawArray.length;
|
|
1590
285
|
this.maxLineNumber = rawArray.length;
|
|
1591
|
-
this.rawFile =
|
|
1592
|
-
|
|
1593
|
-
[
|
|
1594
|
-
}
|
|
286
|
+
this.rawFile = {};
|
|
287
|
+
for (let i = 0; i < rawArray.length; i++) {
|
|
288
|
+
this.rawFile[i + 1] = i < rawArray.length - 1 ? rawArray[i] + "\n" : rawArray[i];
|
|
289
|
+
}
|
|
290
|
+
// reduce 对于大数组性能很差
|
|
291
|
+
// this.rawFile = rawArray.reduce(
|
|
292
|
+
// (p, item, index) => ({
|
|
293
|
+
// ...p,
|
|
294
|
+
// [index + 1]: index < rawArray.length - 1 ? item + "\n" : item,
|
|
295
|
+
// }),
|
|
296
|
+
// {}
|
|
297
|
+
// );
|
|
1595
298
|
this.hasDoRaw = true;
|
|
1596
299
|
}
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
}
|
|
1615
|
-
syntaxObj[lineNumber] = item;
|
|
1616
|
-
}
|
|
1617
|
-
else {
|
|
1618
|
-
node.startIndex = syntaxObj[lineNumber].valueLength;
|
|
1619
|
-
node.endIndex = node.startIndex + valueLength - 1;
|
|
1620
|
-
syntaxObj[lineNumber].value += node.value;
|
|
1621
|
-
syntaxObj[lineNumber].valueLength += valueLength;
|
|
1622
|
-
syntaxObj[lineNumber].nodeList.push({ node, wrapper });
|
|
1623
|
-
}
|
|
1624
|
-
node.lineNumber = lineNumber;
|
|
1625
|
-
return;
|
|
1626
|
-
}
|
|
1627
|
-
const lines = node.value.split("\n");
|
|
1628
|
-
node.children = node.children || [];
|
|
1629
|
-
for (let i = 0; i < lines.length; i++) {
|
|
1630
|
-
const _value = i === lines.length - 1 ? lines[i] : lines[i] + "\n";
|
|
1631
|
-
const _lineNumber = i === 0 ? lineNumber : ++lineNumber;
|
|
1632
|
-
const _valueLength = _value.length;
|
|
1633
|
-
const _node = {
|
|
1634
|
-
type: "text",
|
|
1635
|
-
value: _value,
|
|
1636
|
-
startIndex: Infinity,
|
|
1637
|
-
endIndex: Infinity,
|
|
1638
|
-
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 }],
|
|
1639
318
|
};
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
};
|
|
1649
|
-
syntaxObj[_lineNumber] = item;
|
|
1650
|
-
}
|
|
1651
|
-
else {
|
|
1652
|
-
_node.startIndex = syntaxObj[_lineNumber].valueLength;
|
|
1653
|
-
_node.endIndex = _node.startIndex + _valueLength - 1;
|
|
1654
|
-
syntaxObj[_lineNumber].value += _value;
|
|
1655
|
-
syntaxObj[_lineNumber].valueLength += _valueLength;
|
|
1656
|
-
syntaxObj[_lineNumber].nodeList.push({ node: _node, wrapper });
|
|
1657
|
-
}
|
|
1658
|
-
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 });
|
|
1659
327
|
}
|
|
1660
328
|
node.lineNumber = lineNumber;
|
|
1661
329
|
return;
|
|
1662
330
|
}
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
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);
|
|
1666
363
|
}
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
loopAST(ast.children);
|
|
1670
|
-
this.syntaxLength = lineNumber;
|
|
1671
|
-
}
|
|
1672
|
-
#doCheck() {
|
|
1673
|
-
if (this.rawLength && this.syntaxLength) {
|
|
1674
|
-
if (this.rawLength !== this.syntaxLength) {
|
|
1675
|
-
console.warn("the rawLength not match for the syntaxLength");
|
|
364
|
+
node.lineNumber = lineNumber;
|
|
365
|
+
return;
|
|
1676
366
|
}
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
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");
|
|
1682
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
|
+
});
|
|
1683
385
|
}
|
|
1684
|
-
}
|
|
1685
|
-
const getFile = (raw, lang) => {
|
|
1686
|
-
const key = raw + "--" + "0.0.
|
|
386
|
+
};
|
|
387
|
+
const getFile = (raw, lang, fileName) => {
|
|
388
|
+
const key = raw + "--" + "0.0.7" + "--" + lang;
|
|
1687
389
|
if (map.has(key))
|
|
1688
390
|
return map.get(key);
|
|
1689
|
-
const file = new File(raw, lang);
|
|
391
|
+
const file = new File(raw, lang, fileName);
|
|
1690
392
|
map.set(key, file);
|
|
1691
393
|
return file;
|
|
1692
394
|
};
|
|
395
|
+
const _cacheMap = map;
|
|
1693
396
|
|
|
1694
397
|
const maxLength = 1000;
|
|
1695
398
|
/** Get the maximum position in the range. */
|
|
@@ -1720,10 +423,20 @@ function relativeChanges(stringA, stringB) {
|
|
|
1720
423
|
let aRange = { location: 0, length: stringA.length };
|
|
1721
424
|
const _stringA = stringA.trimEnd();
|
|
1722
425
|
const _stringB = stringB.trimEnd();
|
|
1723
|
-
|
|
426
|
+
const aEndStr = stringA.slice(-2);
|
|
427
|
+
const bEndStr = stringB.slice(-2);
|
|
428
|
+
if (_stringA === _stringB && aEndStr !== bEndStr && (aEndStr === "\r\n" || bEndStr === "\r\n")) {
|
|
1724
429
|
return {
|
|
1725
|
-
stringARange: {
|
|
1726
|
-
|
|
430
|
+
stringARange: {
|
|
431
|
+
location: _stringA.length,
|
|
432
|
+
length: stringA.length - _stringA.length,
|
|
433
|
+
isNewLineSymbolChanged: true,
|
|
434
|
+
},
|
|
435
|
+
stringBRange: {
|
|
436
|
+
location: _stringB.length,
|
|
437
|
+
length: stringB.length - _stringB.length,
|
|
438
|
+
isNewLineSymbolChanged: true,
|
|
439
|
+
},
|
|
1727
440
|
};
|
|
1728
441
|
}
|
|
1729
442
|
if (isInValidString(stringA) || isInValidString(stringB)) {
|
|
@@ -1745,25 +458,27 @@ function relativeChanges(stringA, stringB) {
|
|
|
1745
458
|
aRange.length -= suffixLength;
|
|
1746
459
|
return { stringARange: aRange, stringBRange: bRange };
|
|
1747
460
|
}
|
|
461
|
+
/** Check two string have a diff range */
|
|
462
|
+
function hasRelativeChange(stringA, stringB) {
|
|
463
|
+
const _stringA = stringA.trim();
|
|
464
|
+
const _stringB = stringB.trim();
|
|
465
|
+
const { stringARange, stringBRange } = relativeChanges(_stringA, _stringB);
|
|
466
|
+
return (stringARange.location > 0 ||
|
|
467
|
+
stringBRange.location > 0 ||
|
|
468
|
+
stringARange.length < _stringA.length ||
|
|
469
|
+
stringBRange.length < _stringB.length);
|
|
470
|
+
}
|
|
1748
471
|
|
|
1749
472
|
/** indicate what a line in the diff represents */
|
|
1750
|
-
|
|
473
|
+
exports.DiffLineType = void 0;
|
|
1751
474
|
(function (DiffLineType) {
|
|
1752
475
|
DiffLineType[DiffLineType["Context"] = 0] = "Context";
|
|
1753
476
|
DiffLineType[DiffLineType["Add"] = 1] = "Add";
|
|
1754
477
|
DiffLineType[DiffLineType["Delete"] = 2] = "Delete";
|
|
1755
478
|
DiffLineType[DiffLineType["Hunk"] = 3] = "Hunk";
|
|
1756
|
-
})(DiffLineType || (DiffLineType = {}));
|
|
479
|
+
})(exports.DiffLineType || (exports.DiffLineType = {}));
|
|
1757
480
|
/** track details related to each line in the diff */
|
|
1758
481
|
class DiffLine {
|
|
1759
|
-
text;
|
|
1760
|
-
type;
|
|
1761
|
-
originalLineNumber;
|
|
1762
|
-
oldLineNumber;
|
|
1763
|
-
newLineNumber;
|
|
1764
|
-
noTrailingNewLine;
|
|
1765
|
-
needRematch;
|
|
1766
|
-
range;
|
|
1767
482
|
constructor(text, type,
|
|
1768
483
|
// Line number in the original diff patch (before expanding it), or null if
|
|
1769
484
|
// it was added as part of a diff expansion action.
|
|
@@ -1781,7 +496,7 @@ class DiffLine {
|
|
|
1781
496
|
return new DiffLine(this.text, this.type, this.originalLineNumber, this.oldLineNumber, this.newLineNumber, noTrailingNewLine);
|
|
1782
497
|
}
|
|
1783
498
|
isIncludeableLine() {
|
|
1784
|
-
return this.type === DiffLineType.Add || this.type === DiffLineType.Delete;
|
|
499
|
+
return this.type === exports.DiffLineType.Add || this.type === exports.DiffLineType.Delete;
|
|
1785
500
|
}
|
|
1786
501
|
/** The content of the line, i.e., without the line type marker. */
|
|
1787
502
|
get content() {
|
|
@@ -1799,7 +514,7 @@ class DiffLine {
|
|
|
1799
514
|
const checkDiffLineIncludeChange = (diffLine) => {
|
|
1800
515
|
if (!diffLine)
|
|
1801
516
|
return false;
|
|
1802
|
-
return diffLine.type === DiffLineType.Add || diffLine.type === DiffLineType.Delete;
|
|
517
|
+
return diffLine.type === exports.DiffLineType.Add || diffLine.type === exports.DiffLineType.Delete;
|
|
1803
518
|
};
|
|
1804
519
|
|
|
1805
520
|
var DiffHunkExpansionType;
|
|
@@ -1826,11 +541,6 @@ var DiffHunkExpansionType;
|
|
|
1826
541
|
})(DiffHunkExpansionType || (DiffHunkExpansionType = {}));
|
|
1827
542
|
/** each diff is made up of a number of hunks */
|
|
1828
543
|
class DiffHunk {
|
|
1829
|
-
header;
|
|
1830
|
-
lines;
|
|
1831
|
-
unifiedDiffStart;
|
|
1832
|
-
unifiedDiffEnd;
|
|
1833
|
-
expansionType;
|
|
1834
544
|
/**
|
|
1835
545
|
* @param header The details from the diff hunk header about the line start and patch length.
|
|
1836
546
|
* @param lines The contents - context and changes - of the diff section.
|
|
@@ -1858,10 +568,6 @@ class DiffHunk {
|
|
|
1858
568
|
}
|
|
1859
569
|
/** details about the start and end of a diff hunk */
|
|
1860
570
|
class DiffHunkHeader {
|
|
1861
|
-
oldStartLine;
|
|
1862
|
-
oldLineCount;
|
|
1863
|
-
newStartLine;
|
|
1864
|
-
newLineCount;
|
|
1865
571
|
/**
|
|
1866
572
|
* @param oldStartLine The line in the old (or original) file where this diff hunk starts.
|
|
1867
573
|
* @param oldLineCount The number of lines in the old (or original) file that this diff hunk covers
|
|
@@ -1892,6 +598,7 @@ function assertNever(_, message) {
|
|
|
1892
598
|
}
|
|
1893
599
|
/** Utility function for getting the digit count of the largest line number in an array of diff hunks */
|
|
1894
600
|
function getLargestLineNumber(hunks) {
|
|
601
|
+
var _a, _b;
|
|
1895
602
|
if (hunks.length === 0) {
|
|
1896
603
|
return 0;
|
|
1897
604
|
}
|
|
@@ -1899,11 +606,11 @@ function getLargestLineNumber(hunks) {
|
|
|
1899
606
|
const hunk = hunks[i];
|
|
1900
607
|
for (let j = hunk.lines.length - 1; j >= 0; j--) {
|
|
1901
608
|
const line = hunk.lines[j];
|
|
1902
|
-
if (line.type === DiffLineType.Hunk) {
|
|
609
|
+
if (line.type === exports.DiffLineType.Hunk) {
|
|
1903
610
|
continue;
|
|
1904
611
|
}
|
|
1905
|
-
const newLineNumber = line.newLineNumber
|
|
1906
|
-
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;
|
|
1907
614
|
return newLineNumber > oldLineNumber ? newLineNumber : oldLineNumber;
|
|
1908
615
|
}
|
|
1909
616
|
}
|
|
@@ -1963,11 +670,14 @@ const getDiffRange = (additions, deletions) => {
|
|
|
1963
670
|
for (let i = 0; i < len; i++) {
|
|
1964
671
|
const addition = additions[i];
|
|
1965
672
|
const deletion = deletions[i];
|
|
1966
|
-
const
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
673
|
+
const hasDiffRange = hasRelativeChange(addition.text, deletion.text);
|
|
674
|
+
if (hasDiffRange) {
|
|
675
|
+
const { stringARange, stringBRange } = relativeChanges(addition.text, deletion.text);
|
|
676
|
+
addition.needRematch = true;
|
|
677
|
+
addition.range = stringARange;
|
|
678
|
+
deletion.needRematch = true;
|
|
679
|
+
deletion.range = stringBRange;
|
|
680
|
+
}
|
|
1971
681
|
}
|
|
1972
682
|
}
|
|
1973
683
|
};
|
|
@@ -2008,24 +718,6 @@ const DiffLinePrefixChars = new Set([
|
|
|
2008
718
|
* See https://www.gnu.org/software/diffutils/manual/html_node/Detailed-Unified.html
|
|
2009
719
|
*/
|
|
2010
720
|
class DiffParser {
|
|
2011
|
-
/**
|
|
2012
|
-
* Line start pointer.
|
|
2013
|
-
*
|
|
2014
|
-
* The offset into the text property where the current line starts (ie either zero
|
|
2015
|
-
* or one character ahead of the last newline character).
|
|
2016
|
-
*/
|
|
2017
|
-
ls;
|
|
2018
|
-
/**
|
|
2019
|
-
* Line end pointer.
|
|
2020
|
-
*
|
|
2021
|
-
* The offset into the text property where the current line ends (ie it points to
|
|
2022
|
-
* the newline character) or -1 if the line boundary hasn't been determined yet
|
|
2023
|
-
*/
|
|
2024
|
-
le;
|
|
2025
|
-
/**
|
|
2026
|
-
* The text buffer containing the raw, unified diff output to be parsed
|
|
2027
|
-
*/
|
|
2028
|
-
text;
|
|
2029
721
|
constructor() {
|
|
2030
722
|
Object.defineProperty(this, "__v_skip", { value: true });
|
|
2031
723
|
this.reset();
|
|
@@ -2209,7 +901,7 @@ class DiffParser {
|
|
|
2209
901
|
}
|
|
2210
902
|
const header = this.parseHunkHeader(headerLine);
|
|
2211
903
|
const lines = new Array();
|
|
2212
|
-
lines.push(new DiffLine(headerLine, DiffLineType.Hunk, 1, null, null));
|
|
904
|
+
lines.push(new DiffLine(headerLine, exports.DiffLineType.Hunk, 1, null, null));
|
|
2213
905
|
let c;
|
|
2214
906
|
let rollingDiffBeforeCounter = header.oldStartLine;
|
|
2215
907
|
let rollingDiffAfterCounter = header.newStartLine;
|
|
@@ -2238,13 +930,13 @@ class DiffParser {
|
|
|
2238
930
|
}
|
|
2239
931
|
let diffLine;
|
|
2240
932
|
if (c === DiffPrefixAdd) {
|
|
2241
|
-
diffLine = new DiffLine(line, DiffLineType.Add, diffLineNumber, null, rollingDiffAfterCounter++);
|
|
933
|
+
diffLine = new DiffLine(line, exports.DiffLineType.Add, diffLineNumber, null, rollingDiffAfterCounter++);
|
|
2242
934
|
}
|
|
2243
935
|
else if (c === DiffPrefixDelete) {
|
|
2244
|
-
diffLine = new DiffLine(line, DiffLineType.Delete, diffLineNumber, rollingDiffBeforeCounter++, null);
|
|
936
|
+
diffLine = new DiffLine(line, exports.DiffLineType.Delete, diffLineNumber, rollingDiffBeforeCounter++, null);
|
|
2245
937
|
}
|
|
2246
938
|
else if (c === DiffPrefixContext) {
|
|
2247
|
-
diffLine = new DiffLine(line, DiffLineType.Context, diffLineNumber, rollingDiffBeforeCounter++, rollingDiffAfterCounter++);
|
|
939
|
+
diffLine = new DiffLine(line, exports.DiffLineType.Context, diffLineNumber, rollingDiffBeforeCounter++, rollingDiffAfterCounter++);
|
|
2248
940
|
}
|
|
2249
941
|
else {
|
|
2250
942
|
return assertNever(c, `Unknown DiffLinePrefix: ${c}`);
|
|
@@ -2321,58 +1013,417 @@ class DiffParser {
|
|
|
2321
1013
|
}
|
|
2322
1014
|
const parseInstance = new DiffParser();
|
|
2323
1015
|
|
|
2324
|
-
|
|
2325
|
-
/* 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;
|
|
2326
1017
|
const composeLen = 40;
|
|
2327
1018
|
const idSet = new Set();
|
|
2328
1019
|
class DiffFile {
|
|
2329
|
-
_oldFileName;
|
|
2330
|
-
_newFileName;
|
|
2331
|
-
_diffList;
|
|
2332
|
-
#oldFileResult;
|
|
2333
|
-
#newFileResult;
|
|
2334
|
-
#diffListResults;
|
|
2335
|
-
#diffLines;
|
|
2336
|
-
#oldFileDiffLines;
|
|
2337
|
-
#newFileDiffLines;
|
|
2338
|
-
#oldFileLines;
|
|
2339
|
-
#newFileLines;
|
|
2340
|
-
#oldFileSyntaxLines;
|
|
2341
|
-
#newFileSyntaxLines;
|
|
2342
|
-
#splitLeftLines = [];
|
|
2343
|
-
#splitRightLines = [];
|
|
2344
|
-
#splitHunksLines;
|
|
2345
|
-
#splitLastStartIndex;
|
|
2346
|
-
#unifiedLines = [];
|
|
2347
|
-
#unifiedHunksLines;
|
|
2348
|
-
#unifiedLastStartIndex;
|
|
2349
|
-
#listeners = [];
|
|
2350
|
-
#hasInitRaw = false;
|
|
2351
|
-
#hasInitSyntax = false;
|
|
2352
|
-
#hasBuildSplit = false;
|
|
2353
|
-
#hasBuildUnified = false;
|
|
2354
|
-
#updateCount = 0;
|
|
2355
|
-
#composeByDiff = false;
|
|
2356
|
-
_oldFileContent = "";
|
|
2357
|
-
_oldFileLang = "";
|
|
2358
|
-
_newFileContent = "";
|
|
2359
|
-
_newFileLang = "";
|
|
2360
|
-
diffLineLength = 0;
|
|
2361
|
-
splitLineLength = 0;
|
|
2362
|
-
unifiedLineLength = 0;
|
|
2363
|
-
#id = "";
|
|
2364
|
-
#clonedInstance = new Map();
|
|
2365
1020
|
static createInstance(data, bundle) {
|
|
2366
|
-
|
|
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) || "");
|
|
2367
1023
|
if (bundle) {
|
|
2368
1024
|
instance.mergeBundle(bundle);
|
|
2369
1025
|
}
|
|
2370
1026
|
return instance;
|
|
2371
1027
|
}
|
|
2372
1028
|
constructor(_oldFileName, _oldFileContent, _newFileName, _newFileContent, _diffList, _oldFileLang, _newFileLang) {
|
|
1029
|
+
_DiffFile_instances.add(this);
|
|
2373
1030
|
this._oldFileName = _oldFileName;
|
|
2374
1031
|
this._newFileName = _newFileName;
|
|
2375
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 });
|
|
1106
|
+
}
|
|
1107
|
+
else {
|
|
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}` });
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
else {
|
|
1112
|
+
if (current.isLast) {
|
|
1113
|
+
console.error("the last hunk can not expand up!");
|
|
1114
|
+
return;
|
|
1115
|
+
}
|
|
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
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
current.unifiedInfo = Object.assign(Object.assign(Object.assign({}, current.unifiedInfo), current.hunkInfo), { plainText: current.text, startHiddenIndex: current.unifiedInfo.endHiddenIndex });
|
|
1159
|
+
}
|
|
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 });
|
|
1168
|
+
}
|
|
1169
|
+
else {
|
|
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}` });
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
else {
|
|
1174
|
+
if (current.isLast) {
|
|
1175
|
+
console.error("the last hunk can not expand up!");
|
|
1176
|
+
return;
|
|
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
|
+
});
|
|
1208
|
+
}
|
|
1209
|
+
this.notifyAll();
|
|
1210
|
+
};
|
|
1211
|
+
this.onAllCollapse = (mode) => {
|
|
1212
|
+
if (__classPrivateFieldGet(this, _DiffFile_composeByDiff, "f"))
|
|
1213
|
+
return;
|
|
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;
|
|
1218
|
+
}
|
|
1219
|
+
});
|
|
1220
|
+
Object.values(__classPrivateFieldGet(this, _DiffFile_splitRightLines, "f") || {}).forEach((item) => {
|
|
1221
|
+
if (!item.isHidden && item._isHidden) {
|
|
1222
|
+
item.isHidden = item._isHidden;
|
|
1223
|
+
}
|
|
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;
|
|
1237
|
+
}
|
|
1238
|
+
});
|
|
1239
|
+
}
|
|
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
|
+
});
|
|
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
|
+
};
|
|
2376
1427
|
Object.defineProperty(this, "__v_skip", { value: true });
|
|
2377
1428
|
let oldContent = _oldFileContent;
|
|
2378
1429
|
let newContent = _newFileContent;
|
|
@@ -2394,273 +1445,128 @@ class DiffFile {
|
|
|
2394
1445
|
});
|
|
2395
1446
|
this.initId();
|
|
2396
1447
|
}
|
|
2397
|
-
#doDiff() {
|
|
2398
|
-
if (!this._diffList)
|
|
2399
|
-
return;
|
|
2400
|
-
this.#diffListResults = this._diffList.map((s) => parseInstance.parse(s));
|
|
2401
|
-
}
|
|
2402
|
-
#doFile() {
|
|
2403
|
-
if (!this._oldFileContent && !this._newFileContent)
|
|
2404
|
-
return;
|
|
2405
|
-
if (this._oldFileContent) {
|
|
2406
|
-
this.#oldFileResult = getFile(this._oldFileContent, this._oldFileLang);
|
|
2407
|
-
}
|
|
2408
|
-
if (this._newFileContent) {
|
|
2409
|
-
this.#newFileResult = getFile(this._newFileContent, this._newFileLang);
|
|
2410
|
-
}
|
|
2411
|
-
}
|
|
2412
|
-
#composeRaw() {
|
|
2413
|
-
this.#oldFileResult?.doRaw();
|
|
2414
|
-
this.#oldFileLines = this.#oldFileResult?.rawFile;
|
|
2415
|
-
this.#newFileResult?.doRaw();
|
|
2416
|
-
this.#newFileLines = this.#newFileResult?.rawFile;
|
|
2417
|
-
}
|
|
2418
|
-
#composeFile() {
|
|
2419
|
-
if (this._oldFileContent && this._newFileContent)
|
|
2420
|
-
return;
|
|
2421
|
-
// all of the file content not exist, try to use diff result to compose
|
|
2422
|
-
if (!this._oldFileContent && !this._newFileContent) {
|
|
2423
|
-
let newLineNumber = 1;
|
|
2424
|
-
let oldLineNumber = 1;
|
|
2425
|
-
let oldFileContent = "";
|
|
2426
|
-
let newFileContent = "";
|
|
2427
|
-
while (oldLineNumber <= this.diffLineLength) {
|
|
2428
|
-
const diffLine = this.#getOldDiffLine(oldLineNumber++);
|
|
2429
|
-
if (diffLine) {
|
|
2430
|
-
oldFileContent += diffLine.text;
|
|
2431
|
-
}
|
|
2432
|
-
else {
|
|
2433
|
-
// empty line for placeholder
|
|
2434
|
-
oldFileContent += "\n";
|
|
2435
|
-
}
|
|
2436
|
-
}
|
|
2437
|
-
while (newLineNumber <= this.diffLineLength) {
|
|
2438
|
-
const diffLine = this.#getNewDiffLine(newLineNumber++);
|
|
2439
|
-
if (diffLine) {
|
|
2440
|
-
newFileContent += diffLine.text;
|
|
2441
|
-
}
|
|
2442
|
-
else {
|
|
2443
|
-
// empty line for placeholder
|
|
2444
|
-
newFileContent += "\n";
|
|
2445
|
-
}
|
|
2446
|
-
}
|
|
2447
|
-
if (oldFileContent === newFileContent)
|
|
2448
|
-
return;
|
|
2449
|
-
this._oldFileContent = oldFileContent;
|
|
2450
|
-
this._newFileContent = newFileContent;
|
|
2451
|
-
this.#oldFileResult = getFile(this._oldFileContent, this._oldFileLang);
|
|
2452
|
-
this.#newFileResult = getFile(this._newFileContent, this._newFileLang);
|
|
2453
|
-
// all of the file just compose by diff, so we can not do the expand action
|
|
2454
|
-
this.#composeByDiff = true;
|
|
2455
|
-
}
|
|
2456
|
-
else if (this.#oldFileResult) {
|
|
2457
|
-
let newLineNumber = 1;
|
|
2458
|
-
let oldLineNumber = 1;
|
|
2459
|
-
let newFileContent = "";
|
|
2460
|
-
while (oldLineNumber <= this.#oldFileResult.maxLineNumber) {
|
|
2461
|
-
const newDiffLine = this.#getNewDiffLine(newLineNumber++);
|
|
2462
|
-
if (newDiffLine) {
|
|
2463
|
-
newFileContent += newDiffLine.text;
|
|
2464
|
-
oldLineNumber = newDiffLine.oldLineNumber ? newDiffLine.oldLineNumber + 1 : oldLineNumber;
|
|
2465
|
-
}
|
|
2466
|
-
else {
|
|
2467
|
-
newFileContent += this.#getOldRawLine(oldLineNumber++);
|
|
2468
|
-
}
|
|
2469
|
-
}
|
|
2470
|
-
if (newFileContent === this._oldFileContent)
|
|
2471
|
-
return;
|
|
2472
|
-
this._newFileContent = newFileContent;
|
|
2473
|
-
this.#newFileResult = getFile(this._newFileContent, this._newFileLang);
|
|
2474
|
-
}
|
|
2475
|
-
else if (this.#newFileResult) {
|
|
2476
|
-
let oldLineNumber = 1;
|
|
2477
|
-
let newLineNumber = 1;
|
|
2478
|
-
let oldFileContent = "";
|
|
2479
|
-
while (newLineNumber <= this.#newFileResult.maxLineNumber) {
|
|
2480
|
-
const oldDiffLine = this.#getOldDiffLine(oldLineNumber++);
|
|
2481
|
-
if (oldDiffLine) {
|
|
2482
|
-
oldFileContent += oldDiffLine.text;
|
|
2483
|
-
newLineNumber = oldDiffLine.newLineNumber ? oldDiffLine.newLineNumber + 1 : newLineNumber;
|
|
2484
|
-
}
|
|
2485
|
-
else {
|
|
2486
|
-
oldFileContent += this.#getNewRawLine(newLineNumber++);
|
|
2487
|
-
}
|
|
2488
|
-
}
|
|
2489
|
-
if (oldFileContent === this._newFileContent)
|
|
2490
|
-
return;
|
|
2491
|
-
this._oldFileContent = oldFileContent;
|
|
2492
|
-
this.#oldFileResult = getFile(this._oldFileContent, this._oldFileLang);
|
|
2493
|
-
}
|
|
2494
|
-
this.#composeRaw();
|
|
2495
|
-
}
|
|
2496
|
-
#composeDiff() {
|
|
2497
|
-
if (!this.#diffListResults?.length)
|
|
2498
|
-
return;
|
|
2499
|
-
this.#diffListResults.forEach((item) => {
|
|
2500
|
-
const hunks = item.hunks;
|
|
2501
|
-
hunks.forEach((hunk) => {
|
|
2502
|
-
let additions = [];
|
|
2503
|
-
let deletions = [];
|
|
2504
|
-
hunk.lines.forEach((line) => {
|
|
2505
|
-
if (line.type === DiffLineType.Add) {
|
|
2506
|
-
additions.push(line);
|
|
2507
|
-
}
|
|
2508
|
-
else if (line.type === DiffLineType.Delete) {
|
|
2509
|
-
deletions.push(line);
|
|
2510
|
-
}
|
|
2511
|
-
else {
|
|
2512
|
-
getDiffRange(additions, deletions);
|
|
2513
|
-
additions = [];
|
|
2514
|
-
deletions = [];
|
|
2515
|
-
}
|
|
2516
|
-
});
|
|
2517
|
-
getDiffRange(additions, deletions);
|
|
2518
|
-
});
|
|
2519
|
-
});
|
|
2520
|
-
this.#diffLines = this.#diffListResults
|
|
2521
|
-
.reduce((p, c) => p.concat(...c.hunks.reduce((_p, _c) => _p.concat(..._c.lines), [])), [])
|
|
2522
|
-
.map((i, index) => {
|
|
2523
|
-
const typedI = i;
|
|
2524
|
-
typedI.index = index;
|
|
2525
|
-
if (typedI.type === DiffLineType.Hunk) {
|
|
2526
|
-
const numInfo = typedI.text.split("@@")?.[1].split(" ").filter(Boolean);
|
|
2527
|
-
const oldNumInfo = numInfo?.[0] || "";
|
|
2528
|
-
const newNumInfo = numInfo?.[1] || "";
|
|
2529
|
-
const [oldNumStartIndex, oldNumLength] = oldNumInfo.split(",");
|
|
2530
|
-
const [newNumStartIndex, newNumLength] = newNumInfo.split(",");
|
|
2531
|
-
const typedTypeI = typedI;
|
|
2532
|
-
typedTypeI.hunkInfo = {
|
|
2533
|
-
oldStartIndex: -Number(oldNumStartIndex),
|
|
2534
|
-
oldLength: Number(oldNumLength),
|
|
2535
|
-
newStartIndex: +Number(newNumStartIndex),
|
|
2536
|
-
newLength: Number(newNumLength),
|
|
2537
|
-
};
|
|
2538
|
-
}
|
|
2539
|
-
return typedI;
|
|
2540
|
-
});
|
|
2541
|
-
this.#oldFileDiffLines = this.#diffLines.reduce((p, c) => {
|
|
2542
|
-
if (c.oldLineNumber) {
|
|
2543
|
-
this.diffLineLength = Math.max(this.diffLineLength, c.oldLineNumber);
|
|
2544
|
-
return { ...p, [c.oldLineNumber]: c };
|
|
2545
|
-
}
|
|
2546
|
-
else {
|
|
2547
|
-
return p;
|
|
2548
|
-
}
|
|
2549
|
-
}, {});
|
|
2550
|
-
this.#newFileDiffLines = this.#diffLines.reduce((p, c) => {
|
|
2551
|
-
if (c.newLineNumber) {
|
|
2552
|
-
this.diffLineLength = Math.max(this.diffLineLength, c.newLineNumber);
|
|
2553
|
-
return { ...p, [c.newLineNumber]: c };
|
|
2554
|
-
}
|
|
2555
|
-
else {
|
|
2556
|
-
return p;
|
|
2557
|
-
}
|
|
2558
|
-
}, {});
|
|
2559
|
-
}
|
|
2560
|
-
#composeSyntax({ autoDetectLang, registerHighlighter, }) {
|
|
2561
|
-
this.#oldFileResult?.doSyntax({ autoDetectLang, registerHighlighter });
|
|
2562
|
-
this.#oldFileSyntaxLines = this.#oldFileResult?.syntaxFile;
|
|
2563
|
-
this.#newFileResult?.doSyntax({ autoDetectLang, registerHighlighter });
|
|
2564
|
-
this.#newFileSyntaxLines = this.#newFileResult?.syntaxFile;
|
|
2565
|
-
}
|
|
2566
|
-
#getOldDiffLine(lineNumber) {
|
|
2567
|
-
if (!lineNumber)
|
|
2568
|
-
return;
|
|
2569
|
-
return this.#oldFileDiffLines?.[lineNumber];
|
|
2570
|
-
}
|
|
2571
|
-
#getNewDiffLine(lineNumber) {
|
|
2572
|
-
if (!lineNumber)
|
|
2573
|
-
return;
|
|
2574
|
-
return this.#newFileDiffLines?.[lineNumber];
|
|
2575
|
-
}
|
|
2576
|
-
#getOldRawLine(lineNumber) {
|
|
2577
|
-
return this.#oldFileLines?.[lineNumber];
|
|
2578
|
-
}
|
|
2579
|
-
#getNewRawLine(lineNumber) {
|
|
2580
|
-
return this.#newFileLines?.[lineNumber];
|
|
2581
|
-
}
|
|
2582
1448
|
initId() {
|
|
2583
1449
|
let id = "--" + Math.random().toString().slice(2);
|
|
2584
1450
|
while (idSet.has(id)) {
|
|
2585
1451
|
id = "--" + Math.random().toString().slice(2);
|
|
2586
1452
|
}
|
|
2587
1453
|
idSet.add(id);
|
|
2588
|
-
this
|
|
1454
|
+
__classPrivateFieldSet(this, _DiffFile_id, id, "f");
|
|
2589
1455
|
}
|
|
2590
1456
|
getId() {
|
|
2591
|
-
return this
|
|
1457
|
+
return __classPrivateFieldGet(this, _DiffFile_id, "f");
|
|
2592
1458
|
}
|
|
2593
1459
|
clearId() {
|
|
2594
|
-
idSet.delete(this
|
|
1460
|
+
idSet.delete(__classPrivateFieldGet(this, _DiffFile_id, "f"));
|
|
2595
1461
|
}
|
|
2596
1462
|
initRaw() {
|
|
2597
|
-
if (this
|
|
1463
|
+
if (__classPrivateFieldGet(this, _DiffFile_hasInitRaw, "f"))
|
|
2598
1464
|
return;
|
|
2599
|
-
this
|
|
2600
|
-
this
|
|
2601
|
-
this
|
|
2602
|
-
this
|
|
2603
|
-
this
|
|
2604
|
-
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");
|
|
2605
1471
|
}
|
|
2606
1472
|
initSyntax({ autoDetectLang, registerHighlighter, } = {}) {
|
|
2607
|
-
if (this
|
|
1473
|
+
if (__classPrivateFieldGet(this, _DiffFile_hasInitSyntax, "f"))
|
|
2608
1474
|
return;
|
|
2609
|
-
this
|
|
2610
|
-
this
|
|
1475
|
+
__classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_composeSyntax).call(this, { registerHighlighter, autoDetectLang });
|
|
1476
|
+
__classPrivateFieldSet(this, _DiffFile_hasInitSyntax, true, "f");
|
|
2611
1477
|
}
|
|
2612
1478
|
init() {
|
|
2613
1479
|
this.initRaw();
|
|
2614
1480
|
this.initSyntax();
|
|
2615
1481
|
}
|
|
2616
1482
|
buildSplitDiffLines() {
|
|
2617
|
-
|
|
1483
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1484
|
+
if (__classPrivateFieldGet(this, _DiffFile_hasBuildSplit, "f"))
|
|
2618
1485
|
return;
|
|
2619
1486
|
let oldFileLineNumber = 1;
|
|
2620
1487
|
let newFileLineNumber = 1;
|
|
2621
1488
|
let prevIsHidden = false;
|
|
2622
1489
|
let hideStart = Infinity;
|
|
2623
|
-
const maxOldFileLineNumber = this
|
|
2624
|
-
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;
|
|
2625
1492
|
while (oldFileLineNumber <= maxOldFileLineNumber || newFileLineNumber <= maxNewFileLineNumber) {
|
|
2626
|
-
const
|
|
2627
|
-
const
|
|
2628
|
-
const
|
|
2629
|
-
const
|
|
2630
|
-
const oldLineHasChange = oldDiffLine
|
|
2631
|
-
const newLineHasChange = newDiffLine
|
|
2632
|
-
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;
|
|
2633
1500
|
const isHidden = !oldDiffLine && !newDiffLine;
|
|
2634
|
-
if (
|
|
1501
|
+
if (oldDiffLine && !newDiffLine) {
|
|
1502
|
+
if (oldDiffLine.newLineNumber && oldDiffLine.newLineNumber > newFileLineNumber) {
|
|
1503
|
+
newFileLineNumber++;
|
|
1504
|
+
continue;
|
|
1505
|
+
}
|
|
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++;
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
if (!oldDiffLine && !oldRawLine && !newDiffLine && !newRawLine)
|
|
2635
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
|
+
}
|
|
2636
1536
|
if ((oldLineHasChange && newLineHasChange) || (!oldLineHasChange && !newLineHasChange)) {
|
|
2637
|
-
this
|
|
1537
|
+
__classPrivateFieldGet(this, _DiffFile_splitLeftLines, "f").push({
|
|
2638
1538
|
lineNumber: oldFileLineNumber++,
|
|
2639
1539
|
value: oldRawLine,
|
|
2640
1540
|
diff: oldDiffLine,
|
|
2641
1541
|
isHidden,
|
|
1542
|
+
_isHidden: isHidden,
|
|
2642
1543
|
});
|
|
2643
|
-
this
|
|
1544
|
+
__classPrivateFieldGet(this, _DiffFile_splitRightLines, "f").push({
|
|
2644
1545
|
lineNumber: newFileLineNumber++,
|
|
2645
1546
|
value: newRawLine,
|
|
2646
1547
|
diff: newDiffLine,
|
|
2647
1548
|
isHidden,
|
|
1549
|
+
_isHidden: isHidden,
|
|
2648
1550
|
});
|
|
2649
1551
|
}
|
|
2650
1552
|
else if (oldLineHasChange) {
|
|
2651
|
-
this
|
|
1553
|
+
__classPrivateFieldGet(this, _DiffFile_splitLeftLines, "f").push({
|
|
2652
1554
|
lineNumber: oldFileLineNumber++,
|
|
2653
1555
|
value: oldRawLine,
|
|
2654
1556
|
diff: oldDiffLine,
|
|
1557
|
+
isHidden,
|
|
1558
|
+
_isHidden: isHidden,
|
|
2655
1559
|
});
|
|
2656
|
-
this
|
|
1560
|
+
__classPrivateFieldGet(this, _DiffFile_splitRightLines, "f").push({});
|
|
2657
1561
|
}
|
|
2658
1562
|
else if (newLineHasChange) {
|
|
2659
|
-
this
|
|
2660
|
-
this
|
|
1563
|
+
__classPrivateFieldGet(this, _DiffFile_splitLeftLines, "f").push({});
|
|
1564
|
+
__classPrivateFieldGet(this, _DiffFile_splitRightLines, "f").push({
|
|
2661
1565
|
lineNumber: newFileLineNumber++,
|
|
2662
1566
|
value: newRawLine,
|
|
2663
1567
|
diff: newDiffLine,
|
|
1568
|
+
isHidden,
|
|
1569
|
+
_isHidden: isHidden,
|
|
2664
1570
|
});
|
|
2665
1571
|
}
|
|
2666
1572
|
if (!prevIsHidden && isHidden) {
|
|
@@ -2669,71 +1575,126 @@ class DiffFile {
|
|
|
2669
1575
|
prevIsHidden = isHidden;
|
|
2670
1576
|
if (oldDiffLine && newDiffLine && !oldLineHasChange && !newLineHasChange) {
|
|
2671
1577
|
const current = newDiffLine;
|
|
2672
|
-
const previous = newDiffLine.index ? this
|
|
2673
|
-
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) {
|
|
2674
1580
|
const typedPrevious = previous;
|
|
2675
1581
|
if (Number.isFinite(hideStart)) {
|
|
2676
|
-
typedPrevious.splitInfo = {
|
|
2677
|
-
...typedPrevious.hunkInfo,
|
|
2678
|
-
startHiddenIndex: hideStart,
|
|
2679
|
-
endHiddenIndex: len,
|
|
2680
|
-
plainText: typedPrevious.text,
|
|
2681
|
-
};
|
|
1582
|
+
typedPrevious.splitInfo = Object.assign(Object.assign({}, typedPrevious.hunkInfo), { startHiddenIndex: hideStart, endHiddenIndex: len, plainText: typedPrevious.text, _startHiddenIndex: hideStart, _endHiddenIndex: len, _plainText: typedPrevious.text });
|
|
2682
1583
|
hideStart = Infinity;
|
|
2683
1584
|
}
|
|
2684
|
-
this
|
|
2685
|
-
...this.#splitHunksLines,
|
|
2686
|
-
[len]: previous,
|
|
2687
|
-
};
|
|
1585
|
+
__classPrivateFieldSet(this, _DiffFile_splitHunksLines, Object.assign(Object.assign({}, __classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f")), { [len]: typedPrevious }), "f");
|
|
2688
1586
|
}
|
|
2689
1587
|
}
|
|
2690
1588
|
}
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
1589
|
+
// have last hunk
|
|
1590
|
+
if (Number.isFinite(hideStart)) {
|
|
1591
|
+
const lastDiff = new DiffLine("", exports.DiffLineType.Hunk, null, null, null);
|
|
1592
|
+
const lastHunk = lastDiff;
|
|
1593
|
+
lastHunk.isLast = true;
|
|
1594
|
+
lastHunk.splitInfo = {
|
|
1595
|
+
startHiddenIndex: hideStart,
|
|
1596
|
+
endHiddenIndex: __classPrivateFieldGet(this, _DiffFile_splitRightLines, "f").length,
|
|
1597
|
+
_startHiddenIndex: hideStart,
|
|
1598
|
+
_endHiddenIndex: __classPrivateFieldGet(this, _DiffFile_splitRightLines, "f").length,
|
|
1599
|
+
// just for placeholder
|
|
1600
|
+
plainText: "",
|
|
1601
|
+
oldStartIndex: 0,
|
|
1602
|
+
newStartIndex: 0,
|
|
1603
|
+
oldLength: 0,
|
|
1604
|
+
newLength: 0,
|
|
1605
|
+
_plainText: "",
|
|
1606
|
+
_oldStartIndex: 0,
|
|
1607
|
+
_newStartIndex: 0,
|
|
1608
|
+
_oldLength: 0,
|
|
1609
|
+
_newLength: 0,
|
|
1610
|
+
};
|
|
1611
|
+
__classPrivateFieldSet(this, _DiffFile_splitHunksLines, Object.assign(Object.assign({}, __classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f")), { [__classPrivateFieldGet(this, _DiffFile_splitRightLines, "f").length]: lastHunk }), "f");
|
|
1612
|
+
hideStart = Infinity;
|
|
1613
|
+
}
|
|
1614
|
+
this.splitLineLength = __classPrivateFieldGet(this, _DiffFile_splitRightLines, "f").length;
|
|
1615
|
+
__classPrivateFieldSet(this, _DiffFile_hasBuildSplit, true, "f");
|
|
2694
1616
|
this.notifyAll();
|
|
2695
1617
|
}
|
|
2696
1618
|
buildUnifiedDiffLines() {
|
|
2697
|
-
|
|
1619
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1620
|
+
if (__classPrivateFieldGet(this, _DiffFile_hasBuildUnified, "f"))
|
|
2698
1621
|
return;
|
|
2699
1622
|
let oldFileLineNumber = 1;
|
|
2700
1623
|
let newFileLineNumber = 1;
|
|
2701
1624
|
let prevIsHidden = false;
|
|
2702
1625
|
let hideStart = Infinity;
|
|
2703
|
-
const maxOldFileLineNumber = this
|
|
2704
|
-
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;
|
|
2705
1628
|
while (oldFileLineNumber <= maxOldFileLineNumber || newFileLineNumber <= maxNewFileLineNumber) {
|
|
2706
|
-
const oldRawLine = this
|
|
2707
|
-
const oldDiffLine = this
|
|
2708
|
-
const newRawLine = this
|
|
2709
|
-
const newDiffLine = this
|
|
2710
|
-
const oldLineHasChange = oldDiffLine
|
|
2711
|
-
const newLineHasChange = newDiffLine
|
|
2712
|
-
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;
|
|
2713
1636
|
const isHidden = !oldDiffLine && !newDiffLine;
|
|
1637
|
+
if (oldDiffLine && !newDiffLine) {
|
|
1638
|
+
if (oldDiffLine.newLineNumber && oldDiffLine.newLineNumber > newFileLineNumber) {
|
|
1639
|
+
newFileLineNumber++;
|
|
1640
|
+
continue;
|
|
1641
|
+
}
|
|
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++;
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
2714
1655
|
if (!oldRawLine && !newRawLine && !newDiffLine && !oldDiffLine)
|
|
2715
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
|
+
}
|
|
2716
1672
|
if (!oldLineHasChange && !newLineHasChange) {
|
|
2717
|
-
this
|
|
1673
|
+
__classPrivateFieldGet(this, _DiffFile_unifiedLines, "f").push({
|
|
2718
1674
|
oldLineNumber: oldFileLineNumber++,
|
|
2719
1675
|
newLineNumber: newFileLineNumber++,
|
|
2720
1676
|
value: newRawLine,
|
|
2721
1677
|
diff: newDiffLine,
|
|
2722
1678
|
isHidden,
|
|
1679
|
+
_isHidden: isHidden,
|
|
2723
1680
|
});
|
|
2724
1681
|
}
|
|
2725
1682
|
else if (oldLineHasChange) {
|
|
2726
|
-
this
|
|
1683
|
+
__classPrivateFieldGet(this, _DiffFile_unifiedLines, "f").push({
|
|
2727
1684
|
oldLineNumber: oldFileLineNumber++,
|
|
2728
1685
|
value: oldRawLine,
|
|
2729
1686
|
diff: oldDiffLine,
|
|
1687
|
+
isHidden,
|
|
1688
|
+
_isHidden: isHidden,
|
|
2730
1689
|
});
|
|
2731
1690
|
}
|
|
2732
1691
|
else if (newLineHasChange) {
|
|
2733
|
-
this
|
|
1692
|
+
__classPrivateFieldGet(this, _DiffFile_unifiedLines, "f").push({
|
|
2734
1693
|
newLineNumber: newFileLineNumber++,
|
|
2735
1694
|
value: newRawLine,
|
|
2736
1695
|
diff: newDiffLine,
|
|
1696
|
+
isHidden,
|
|
1697
|
+
_isHidden: isHidden,
|
|
2737
1698
|
});
|
|
2738
1699
|
}
|
|
2739
1700
|
if (!prevIsHidden && isHidden) {
|
|
@@ -2742,453 +1703,345 @@ class DiffFile {
|
|
|
2742
1703
|
prevIsHidden = isHidden;
|
|
2743
1704
|
if (oldDiffLine && newDiffLine && !oldLineHasChange && !newLineHasChange) {
|
|
2744
1705
|
const current = newDiffLine;
|
|
2745
|
-
const previous = current.index ? this
|
|
2746
|
-
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) {
|
|
2747
1708
|
const typedPrevious = previous;
|
|
2748
1709
|
if (Number.isFinite(hideStart)) {
|
|
2749
|
-
typedPrevious.unifiedInfo = {
|
|
2750
|
-
...typedPrevious.hunkInfo,
|
|
2751
|
-
startHiddenIndex: hideStart,
|
|
2752
|
-
endHiddenIndex: len,
|
|
2753
|
-
plainText: typedPrevious.text,
|
|
2754
|
-
};
|
|
1710
|
+
typedPrevious.unifiedInfo = Object.assign(Object.assign({}, typedPrevious.hunkInfo), { startHiddenIndex: hideStart, endHiddenIndex: len, plainText: typedPrevious.text, _startHiddenIndex: hideStart, _endHiddenIndex: len, _plainText: typedPrevious.text });
|
|
2755
1711
|
hideStart = Infinity;
|
|
2756
1712
|
}
|
|
2757
|
-
this
|
|
2758
|
-
...this.#unifiedHunksLines,
|
|
2759
|
-
[len]: previous,
|
|
2760
|
-
};
|
|
1713
|
+
__classPrivateFieldSet(this, _DiffFile_unifiedHunksLines, Object.assign(Object.assign({}, __classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f")), { [len]: typedPrevious }), "f");
|
|
2761
1714
|
}
|
|
2762
1715
|
}
|
|
2763
1716
|
}
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
1717
|
+
// have last hunk
|
|
1718
|
+
if (Number.isFinite(hideStart)) {
|
|
1719
|
+
const lastDiff = new DiffLine("", exports.DiffLineType.Hunk, null, null, null);
|
|
1720
|
+
const lastHunk = lastDiff;
|
|
1721
|
+
lastHunk.isLast = true;
|
|
1722
|
+
lastHunk.unifiedInfo = {
|
|
1723
|
+
startHiddenIndex: hideStart,
|
|
1724
|
+
endHiddenIndex: __classPrivateFieldGet(this, _DiffFile_unifiedLines, "f").length,
|
|
1725
|
+
_startHiddenIndex: hideStart,
|
|
1726
|
+
_endHiddenIndex: __classPrivateFieldGet(this, _DiffFile_unifiedLines, "f").length,
|
|
1727
|
+
// just for placeholder
|
|
1728
|
+
plainText: "",
|
|
1729
|
+
oldStartIndex: 0,
|
|
1730
|
+
newStartIndex: 0,
|
|
1731
|
+
oldLength: 0,
|
|
1732
|
+
newLength: 0,
|
|
1733
|
+
_plainText: "",
|
|
1734
|
+
_oldStartIndex: 0,
|
|
1735
|
+
_newStartIndex: 0,
|
|
1736
|
+
_oldLength: 0,
|
|
1737
|
+
_newLength: 0,
|
|
1738
|
+
};
|
|
1739
|
+
__classPrivateFieldSet(this, _DiffFile_unifiedHunksLines, Object.assign(Object.assign({}, __classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f")), { [__classPrivateFieldGet(this, _DiffFile_unifiedLines, "f").length]: lastHunk }), "f");
|
|
1740
|
+
hideStart = Infinity;
|
|
1741
|
+
}
|
|
1742
|
+
this.unifiedLineLength = __classPrivateFieldGet(this, _DiffFile_unifiedLines, "f").length;
|
|
1743
|
+
__classPrivateFieldSet(this, _DiffFile_hasBuildUnified, true, "f");
|
|
2767
1744
|
this.notifyAll();
|
|
2768
1745
|
}
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
return
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
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;
|
|
2790
1782
|
}
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
plainText: current.text,
|
|
2796
|
-
startHiddenIndex: current.splitInfo.endHiddenIndex,
|
|
2797
|
-
};
|
|
2798
|
-
}
|
|
2799
|
-
else if (dir === "down") {
|
|
2800
|
-
for (let i = current.splitInfo.startHiddenIndex; i < current.splitInfo.startHiddenIndex + composeLen; i++) {
|
|
2801
|
-
const leftLine = this.#splitLeftLines[i];
|
|
2802
|
-
const rightLine = this.#splitRightLines[i];
|
|
2803
|
-
if (leftLine?.isHidden)
|
|
2804
|
-
leftLine.isHidden = false;
|
|
2805
|
-
if (rightLine?.isHidden)
|
|
2806
|
-
rightLine.isHidden = false;
|
|
1783
|
+
else {
|
|
1784
|
+
// empty line for placeholder
|
|
1785
|
+
oldFileContent += "\n";
|
|
1786
|
+
oldFilePlaceholderLines[index] = true;
|
|
2807
1787
|
}
|
|
2808
|
-
current.splitInfo = {
|
|
2809
|
-
...current.splitInfo,
|
|
2810
|
-
startHiddenIndex: current.splitInfo.startHiddenIndex + composeLen,
|
|
2811
|
-
plainText: `@@ -${current.splitInfo.oldStartIndex},${current.splitInfo.oldLength} +${current.splitInfo.newStartIndex},${current.splitInfo.newLength}`,
|
|
2812
|
-
};
|
|
2813
1788
|
}
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
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;
|
|
1794
|
+
}
|
|
1795
|
+
else {
|
|
1796
|
+
// empty line for placeholder
|
|
1797
|
+
newFileContent += "\n";
|
|
1798
|
+
newFilePlaceholderLines[index] = true;
|
|
2822
1799
|
}
|
|
2823
|
-
const oldStartIndex = current.splitInfo.oldStartIndex - composeLen;
|
|
2824
|
-
const oldLength = current.splitInfo.oldLength + composeLen;
|
|
2825
|
-
const newStartIndex = current.splitInfo.newStartIndex - composeLen;
|
|
2826
|
-
const newLength = current.splitInfo.newLength + composeLen;
|
|
2827
|
-
current.splitInfo = {
|
|
2828
|
-
...current.splitInfo,
|
|
2829
|
-
endHiddenIndex: current.splitInfo.endHiddenIndex - composeLen,
|
|
2830
|
-
oldStartIndex,
|
|
2831
|
-
oldLength,
|
|
2832
|
-
newStartIndex,
|
|
2833
|
-
newLength,
|
|
2834
|
-
plainText: `@@ -${oldStartIndex},${oldLength} +${newStartIndex},${newLength}`,
|
|
2835
|
-
};
|
|
2836
|
-
delete this.#splitHunksLines?.[index];
|
|
2837
|
-
this.#splitHunksLines[current.splitInfo.endHiddenIndex] = current;
|
|
2838
|
-
}
|
|
2839
|
-
this.notifyAll();
|
|
2840
|
-
};
|
|
2841
|
-
onSplitLastExpand = (expandAll) => {
|
|
2842
|
-
if (!this.#splitLastStartIndex || !Number.isFinite(this.#splitLastStartIndex))
|
|
2843
|
-
return;
|
|
2844
|
-
const start = this.#splitLastStartIndex;
|
|
2845
|
-
const end = expandAll ? this.splitLineLength : this.#splitLastStartIndex + composeLen;
|
|
2846
|
-
for (let i = start; i < end; i++) {
|
|
2847
|
-
const leftLine = this.#splitLeftLines[i];
|
|
2848
|
-
const rightLine = this.#splitRightLines[i];
|
|
2849
|
-
if (leftLine?.isHidden)
|
|
2850
|
-
leftLine.isHidden = false;
|
|
2851
|
-
if (rightLine?.isHidden)
|
|
2852
|
-
rightLine.isHidden = false;
|
|
2853
1800
|
}
|
|
2854
|
-
|
|
2855
|
-
this.#splitLastStartIndex =
|
|
2856
|
-
this.#splitLastStartIndex >= this.splitLineLength ? Infinity : this.#splitLastStartIndex;
|
|
2857
|
-
this.notifyAll();
|
|
2858
|
-
};
|
|
2859
|
-
getUnifiedLine = (index) => {
|
|
2860
|
-
return this.#unifiedLines[index];
|
|
2861
|
-
};
|
|
2862
|
-
getUnifiedHunkLine = (index) => {
|
|
2863
|
-
return this.#unifiedHunksLines?.[index];
|
|
2864
|
-
};
|
|
2865
|
-
onUnifiedHunkExpand = (dir, index) => {
|
|
2866
|
-
const current = this.#unifiedHunksLines?.[index];
|
|
2867
|
-
if (!current)
|
|
1801
|
+
if (oldFileContent === newFileContent)
|
|
2868
1802
|
return;
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
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;
|
|
2875
1821
|
}
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
...current.unifiedInfo,
|
|
2879
|
-
...current.hunkInfo,
|
|
2880
|
-
plainText: current.text,
|
|
2881
|
-
startHiddenIndex: current.unifiedInfo.endHiddenIndex,
|
|
2882
|
-
};
|
|
2883
|
-
}
|
|
2884
|
-
else if (dir === "down") {
|
|
2885
|
-
for (let i = current.unifiedInfo.startHiddenIndex; i < current.unifiedInfo.startHiddenIndex + composeLen; i++) {
|
|
2886
|
-
const unifiedLine = this.#unifiedLines[i];
|
|
2887
|
-
if (unifiedLine?.isHidden)
|
|
2888
|
-
unifiedLine.isHidden = false;
|
|
1822
|
+
else {
|
|
1823
|
+
newFileContent += __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getOldRawLine).call(this, oldLineNumber++);
|
|
2889
1824
|
}
|
|
2890
|
-
current.unifiedInfo = {
|
|
2891
|
-
...current.unifiedInfo,
|
|
2892
|
-
startHiddenIndex: current.unifiedInfo.startHiddenIndex + composeLen,
|
|
2893
|
-
plainText: `@@ -${current.unifiedInfo.oldStartIndex},${current.unifiedInfo.oldLength} +${current.unifiedInfo.newStartIndex},${current.unifiedInfo.newLength}`,
|
|
2894
|
-
};
|
|
2895
1825
|
}
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
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;
|
|
1840
|
+
}
|
|
1841
|
+
else {
|
|
1842
|
+
oldFileContent += __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getNewRawLine).call(this, newLineNumber++);
|
|
2901
1843
|
}
|
|
2902
|
-
const oldStartIndex = current.unifiedInfo.oldStartIndex - composeLen;
|
|
2903
|
-
const oldLength = current.unifiedInfo.oldLength + composeLen;
|
|
2904
|
-
const newStartIndex = current.unifiedInfo.newStartIndex - composeLen;
|
|
2905
|
-
const newLength = current.unifiedInfo.newLength + composeLen;
|
|
2906
|
-
current.unifiedInfo = {
|
|
2907
|
-
...current.unifiedInfo,
|
|
2908
|
-
endHiddenIndex: current.unifiedInfo.endHiddenIndex - composeLen,
|
|
2909
|
-
oldStartIndex,
|
|
2910
|
-
oldLength,
|
|
2911
|
-
newStartIndex,
|
|
2912
|
-
newLength,
|
|
2913
|
-
plainText: `@@ -${oldStartIndex},${oldLength} +${newStartIndex},${newLength}`,
|
|
2914
|
-
};
|
|
2915
|
-
delete this.#unifiedHunksLines?.[index];
|
|
2916
|
-
this.#unifiedHunksLines[current.unifiedInfo.endHiddenIndex] = current;
|
|
2917
1844
|
}
|
|
2918
|
-
this.
|
|
2919
|
-
};
|
|
2920
|
-
onUnifiedLastExpand = (expandAll) => {
|
|
2921
|
-
if (!this.#unifiedLastStartIndex || !Number.isFinite(this.#unifiedLastStartIndex))
|
|
1845
|
+
if (oldFileContent === this._newFileContent)
|
|
2922
1846
|
return;
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
if (skipSyncExternal && f.isSyncExternal) {
|
|
2951
|
-
return;
|
|
2952
|
-
}
|
|
2953
|
-
f();
|
|
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);
|
|
1866
|
+
}
|
|
1867
|
+
else {
|
|
1868
|
+
getDiffRange(additions, deletions);
|
|
1869
|
+
additions = [];
|
|
1870
|
+
deletions = [];
|
|
1871
|
+
}
|
|
1872
|
+
});
|
|
1873
|
+
getDiffRange(additions, deletions);
|
|
2954
1874
|
});
|
|
2955
|
-
};
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
|
|
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
|
+
};
|
|
2963
1904
|
}
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
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;
|
|
2968
1933
|
}
|
|
2969
|
-
};
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
oldFileLines,
|
|
3001
|
-
oldFileDiffLines,
|
|
3002
|
-
oldFileSyntaxLines,
|
|
3003
|
-
newFileLines,
|
|
3004
|
-
newFileDiffLines,
|
|
3005
|
-
newFileSyntaxLines,
|
|
3006
|
-
splitLineLength,
|
|
3007
|
-
unifiedLineLength,
|
|
3008
|
-
splitLeftLines,
|
|
3009
|
-
splitRightLines,
|
|
3010
|
-
splitHunkLines,
|
|
3011
|
-
splitLastStartIndex,
|
|
3012
|
-
unifiedLines,
|
|
3013
|
-
unifiedHunkLines,
|
|
3014
|
-
unifiedLastStartIndex,
|
|
3015
|
-
composeByDiff,
|
|
3016
|
-
};
|
|
3017
|
-
};
|
|
3018
|
-
mergeBundle = (data) => {
|
|
3019
|
-
this.#hasInitRaw = data.hasInitRaw;
|
|
3020
|
-
this.#hasInitSyntax = data.hasInitSyntax;
|
|
3021
|
-
this.#hasBuildSplit = data.hasBuildSplit;
|
|
3022
|
-
this.#hasBuildUnified = data.hasBuildUnified;
|
|
3023
|
-
this.#composeByDiff = data.composeByDiff;
|
|
3024
|
-
this.#oldFileLines = data.oldFileLines;
|
|
3025
|
-
this.#oldFileDiffLines = data.oldFileDiffLines;
|
|
3026
|
-
this.#oldFileSyntaxLines = data.oldFileSyntaxLines;
|
|
3027
|
-
this.#newFileLines = data.newFileLines;
|
|
3028
|
-
this.#newFileDiffLines = data.newFileDiffLines;
|
|
3029
|
-
this.#newFileSyntaxLines = data.newFileSyntaxLines;
|
|
3030
|
-
this.splitLineLength = data.splitLineLength;
|
|
3031
|
-
this.unifiedLineLength = data.unifiedLineLength;
|
|
3032
|
-
this.#splitLeftLines = data.splitLeftLines;
|
|
3033
|
-
this.#splitRightLines = data.splitRightLines;
|
|
3034
|
-
this.#splitHunksLines = data.splitHunkLines;
|
|
3035
|
-
this.#splitLastStartIndex = data.splitLastStartIndex;
|
|
3036
|
-
this.#unifiedLines = data.unifiedLines;
|
|
3037
|
-
this.#unifiedHunksLines = data.unifiedHunkLines;
|
|
3038
|
-
this.#unifiedLastStartIndex = data.unifiedLastStartIndex;
|
|
3039
|
-
this.notifyAll();
|
|
3040
|
-
};
|
|
3041
|
-
_addClonedInstance = (instance) => {
|
|
3042
|
-
const updateFunc = () => {
|
|
3043
|
-
this._notifyOthers(instance);
|
|
3044
|
-
};
|
|
3045
|
-
updateFunc.isSyncExternal = true;
|
|
3046
|
-
const unsubscribe = instance.subscribe(updateFunc);
|
|
3047
|
-
this.#clonedInstance.set(instance, unsubscribe);
|
|
3048
|
-
};
|
|
3049
|
-
_notifyOthers = (instance) => {
|
|
3050
|
-
this.#clonedInstance.forEach((_, i) => {
|
|
3051
|
-
if (i !== instance) {
|
|
3052
|
-
i.notifyAll(true);
|
|
3053
|
-
}
|
|
3054
|
-
});
|
|
3055
|
-
};
|
|
3056
|
-
_delClonedInstance = (instance) => {
|
|
3057
|
-
const unsubscribe = this.#clonedInstance.get(instance);
|
|
3058
|
-
unsubscribe && unsubscribe();
|
|
3059
|
-
this.#clonedInstance.delete(instance);
|
|
3060
|
-
};
|
|
3061
|
-
_getFullBundle = () => {
|
|
3062
|
-
const bundle = this.getBundle();
|
|
3063
|
-
const oldFileResult = this.#oldFileResult;
|
|
3064
|
-
const newFileResult = this.#newFileResult;
|
|
3065
|
-
const diffLines = this.#diffLines;
|
|
3066
|
-
const diffListResults = this.#diffListResults;
|
|
3067
|
-
return {
|
|
3068
|
-
...bundle,
|
|
3069
|
-
oldFileResult,
|
|
3070
|
-
newFileResult,
|
|
3071
|
-
diffLines,
|
|
3072
|
-
diffListResults,
|
|
3073
|
-
};
|
|
3074
|
-
};
|
|
3075
|
-
_mergeFullBundle = (data) => {
|
|
3076
|
-
this.mergeBundle(data);
|
|
3077
|
-
this.#oldFileResult = data.oldFileResult;
|
|
3078
|
-
this.#newFileResult = data.newFileResult;
|
|
3079
|
-
this.#diffLines = data.diffLines;
|
|
3080
|
-
this.#diffListResults = data.diffListResults;
|
|
3081
|
-
};
|
|
3082
|
-
_destroy = () => {
|
|
3083
|
-
this.clearId();
|
|
3084
|
-
this.#listeners.splice(0, this.#listeners.length);
|
|
3085
|
-
this.#clonedInstance.forEach((v) => v());
|
|
3086
|
-
this.#clonedInstance.clear();
|
|
3087
|
-
};
|
|
3088
|
-
clear = () => {
|
|
3089
|
-
this._destroy();
|
|
3090
|
-
this.#oldFileResult = null;
|
|
3091
|
-
this.#newFileResult = null;
|
|
3092
|
-
this.#diffLines = null;
|
|
3093
|
-
this.#diffListResults = null;
|
|
3094
|
-
this.#newFileDiffLines = null;
|
|
3095
|
-
this.#oldFileDiffLines = null;
|
|
3096
|
-
this.#newFileLines = null;
|
|
3097
|
-
this.#oldFileLines = null;
|
|
3098
|
-
this.#newFileSyntaxLines = null;
|
|
3099
|
-
this.#oldFileSyntaxLines = null;
|
|
3100
|
-
this.#splitHunksLines = null;
|
|
3101
|
-
this.#splitLeftLines = null;
|
|
3102
|
-
this.#splitRightLines = null;
|
|
3103
|
-
this.#unifiedHunksLines = null;
|
|
3104
|
-
this.#unifiedLines = null;
|
|
3105
|
-
};
|
|
3106
|
-
}
|
|
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;
|
|
1940
|
+
}
|
|
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
|
+
};
|
|
3107
1965
|
|
|
3108
|
-
|
|
1966
|
+
exports.DiffFileLineType = void 0;
|
|
3109
1967
|
(function (DiffFileLineType) {
|
|
3110
1968
|
DiffFileLineType[DiffFileLineType["hunk"] = 1] = "hunk";
|
|
3111
1969
|
DiffFileLineType[DiffFileLineType["content"] = 2] = "content";
|
|
3112
1970
|
DiffFileLineType[DiffFileLineType["widget"] = 3] = "widget";
|
|
3113
1971
|
DiffFileLineType[DiffFileLineType["extend"] = 4] = "extend";
|
|
3114
|
-
|
|
3115
|
-
})(DiffFileLineType || (DiffFileLineType = {}));
|
|
1972
|
+
})(exports.DiffFileLineType || (exports.DiffFileLineType = {}));
|
|
3116
1973
|
const getSplitLines = (diffFile, options) => {
|
|
3117
1974
|
const splitLineLength = diffFile.splitLineLength;
|
|
3118
1975
|
const splitLines = [];
|
|
3119
1976
|
numIterator(splitLineLength, (index) => {
|
|
1977
|
+
var _a, _b;
|
|
3120
1978
|
const hunkLine = diffFile.getSplitHunkLine(index);
|
|
3121
1979
|
const splitLeftLine = diffFile.getSplitLeftLine(index);
|
|
3122
1980
|
const splitRightLine = diffFile.getSplitRightLine(index);
|
|
3123
|
-
const widgetLine = options
|
|
3124
|
-
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]);
|
|
3125
1983
|
hunkLine &&
|
|
3126
1984
|
hunkLine.splitInfo &&
|
|
3127
1985
|
hunkLine.splitInfo.startHiddenIndex < hunkLine.splitInfo.endHiddenIndex &&
|
|
3128
|
-
splitLines.push({ type: DiffFileLineType.hunk, index, lineNumber: index + 1, hunkLine: hunkLine });
|
|
3129
|
-
|
|
3130
|
-
!
|
|
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) &&
|
|
3131
1994
|
splitLines.push({
|
|
3132
|
-
type: DiffFileLineType.content,
|
|
1995
|
+
type: exports.DiffFileLineType.content,
|
|
3133
1996
|
index,
|
|
3134
1997
|
lineNumber: index + 1,
|
|
3135
1998
|
splitLine: { left: splitLeftLine, right: splitRightLine },
|
|
3136
1999
|
});
|
|
3137
2000
|
widgetLine &&
|
|
3138
|
-
splitLines.push({ type: DiffFileLineType.widget, index, lineNumber: index + 1, widgetLine: widgetLine });
|
|
2001
|
+
splitLines.push({ type: exports.DiffFileLineType.widget, index, lineNumber: index + 1, widgetLine: widgetLine });
|
|
3139
2002
|
extendLine &&
|
|
3140
|
-
splitLines.push({ type: DiffFileLineType.extend, index, lineNumber: index + 1, extendLine: extendLine });
|
|
2003
|
+
splitLines.push({ type: exports.DiffFileLineType.extend, index, lineNumber: index + 1, extendLine: extendLine });
|
|
3141
2004
|
});
|
|
3142
|
-
const lastHunkLine = diffFile.getNeedShowExpandAll("split");
|
|
3143
|
-
const expandEnabled = diffFile.getExpandEnabled();
|
|
3144
|
-
if (lastHunkLine && expandEnabled) {
|
|
3145
|
-
splitLines.push({
|
|
3146
|
-
type: DiffFileLineType.lastHunk,
|
|
3147
|
-
index: splitLineLength,
|
|
3148
|
-
lineNumber: splitLineLength + 1,
|
|
3149
|
-
});
|
|
3150
|
-
}
|
|
3151
2005
|
return splitLines;
|
|
3152
2006
|
};
|
|
3153
2007
|
const getSplitContentLines = (diffFile) => {
|
|
3154
2008
|
const lines = getSplitLines(diffFile, {});
|
|
3155
|
-
return lines.filter((line) => line.type === DiffFileLineType.content);
|
|
2009
|
+
return lines.filter((line) => line.type === exports.DiffFileLineType.content);
|
|
3156
2010
|
};
|
|
3157
2011
|
const getUnifiedLines = (diffFile, options) => {
|
|
3158
2012
|
const unifiedLineLength = diffFile.unifiedLineLength;
|
|
3159
2013
|
const unifiedLines = [];
|
|
3160
2014
|
numIterator(unifiedLineLength, (index) => {
|
|
2015
|
+
var _a, _b;
|
|
3161
2016
|
const hunkLine = diffFile.getUnifiedHunkLine(index);
|
|
3162
2017
|
const unifiedLine = diffFile.getUnifiedLine(index);
|
|
3163
|
-
const widgetLine = options
|
|
3164
|
-
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]);
|
|
3165
2020
|
hunkLine &&
|
|
3166
2021
|
hunkLine.unifiedInfo &&
|
|
3167
2022
|
hunkLine.unifiedInfo.startHiddenIndex < hunkLine.unifiedInfo.endHiddenIndex &&
|
|
3168
|
-
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 });
|
|
3169
2029
|
!unifiedLine.isHidden &&
|
|
3170
|
-
unifiedLines.push({ type: DiffFileLineType.content, index, lineNumber: index + 1, unifiedLine: unifiedLine });
|
|
2030
|
+
unifiedLines.push({ type: exports.DiffFileLineType.content, index, lineNumber: index + 1, unifiedLine: unifiedLine });
|
|
3171
2031
|
widgetLine &&
|
|
3172
|
-
unifiedLines.push({ type: DiffFileLineType.widget, index, lineNumber: index + 1, widgetLine: widgetLine });
|
|
2032
|
+
unifiedLines.push({ type: exports.DiffFileLineType.widget, index, lineNumber: index + 1, widgetLine: widgetLine });
|
|
3173
2033
|
extendLine &&
|
|
3174
|
-
unifiedLines.push({ type: DiffFileLineType.extend, index, lineNumber: index + 1, extendLine: extendLine });
|
|
2034
|
+
unifiedLines.push({ type: exports.DiffFileLineType.extend, index, lineNumber: index + 1, extendLine: extendLine });
|
|
3175
2035
|
});
|
|
3176
|
-
const lastHunkLine = diffFile.getNeedShowExpandAll("unified");
|
|
3177
|
-
const expandEnabled = diffFile.getExpandEnabled();
|
|
3178
|
-
if (lastHunkLine && expandEnabled) {
|
|
3179
|
-
unifiedLines.push({
|
|
3180
|
-
type: DiffFileLineType.lastHunk,
|
|
3181
|
-
index: unifiedLineLength,
|
|
3182
|
-
lineNumber: unifiedLineLength + 1,
|
|
3183
|
-
});
|
|
3184
|
-
}
|
|
3185
2036
|
return unifiedLines;
|
|
3186
2037
|
};
|
|
3187
2038
|
const getUnifiedContentLine = (diffFile) => {
|
|
3188
2039
|
const lines = getUnifiedLines(diffFile, {});
|
|
3189
|
-
return lines.filter((line) => line.type === DiffFileLineType.content);
|
|
2040
|
+
return lines.filter((line) => line.type === exports.DiffFileLineType.content);
|
|
3190
2041
|
};
|
|
3191
2042
|
|
|
2043
|
+
const versions = "0.0.7";
|
|
2044
|
+
|
|
3192
2045
|
const useUnmount = (cb, deps) => {
|
|
3193
2046
|
const ref = React.useRef(cb);
|
|
3194
2047
|
ref.current = cb;
|
|
@@ -3198,24 +2051,24 @@ const useUnmount = (cb, deps) => {
|
|
|
3198
2051
|
const isClient = typeof window !== "undefined";
|
|
3199
2052
|
const useSafeLayout = isClient ? React.useLayoutEffect : React.useEffect;
|
|
3200
2053
|
|
|
2054
|
+
var _TextMeasure_instances, _TextMeasure_key, _TextMeasure_map, _TextMeasure_getInstance;
|
|
3201
2055
|
let canvasCtx = null;
|
|
3202
2056
|
class TextMeasure {
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
return canvasCtx;
|
|
2057
|
+
constructor() {
|
|
2058
|
+
_TextMeasure_instances.add(this);
|
|
2059
|
+
_TextMeasure_key.set(this, "");
|
|
2060
|
+
_TextMeasure_map.set(this, {});
|
|
3208
2061
|
}
|
|
3209
2062
|
measure(text, font) {
|
|
3210
|
-
const currentKey = `${font
|
|
3211
|
-
if (this
|
|
3212
|
-
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];
|
|
3213
2066
|
}
|
|
3214
|
-
const instance = this
|
|
2067
|
+
const instance = __classPrivateFieldGet$1(this, _TextMeasure_instances, "m", _TextMeasure_getInstance).call(this);
|
|
3215
2068
|
if (font) {
|
|
3216
2069
|
const currentFontKey = `${font.fontFamily}-${font.fontStyle}-${font.fontSize}`;
|
|
3217
|
-
if (this
|
|
3218
|
-
this
|
|
2070
|
+
if (__classPrivateFieldGet$1(this, _TextMeasure_key, "f") !== currentFontKey) {
|
|
2071
|
+
__classPrivateFieldSet$1(this, _TextMeasure_key, currentFontKey, "f");
|
|
3219
2072
|
instance.font = `${font.fontStyle || ""} ${font.fontSize || ""} ${font.fontFamily || ""}`;
|
|
3220
2073
|
}
|
|
3221
2074
|
}
|
|
@@ -3226,6 +2079,10 @@ class TextMeasure {
|
|
|
3226
2079
|
return textWidth;
|
|
3227
2080
|
}
|
|
3228
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
|
+
};
|
|
3229
2086
|
const measureInstance = new TextMeasure();
|
|
3230
2087
|
const useTextWidth = ({ text, font, }) => {
|
|
3231
2088
|
const [width, setWidth] = React.useState(0);
|
|
@@ -3243,19 +2100,21 @@ const useDomWidth = ({ selector, enable }) => {
|
|
|
3243
2100
|
React.useEffect(() => {
|
|
3244
2101
|
if (enable) {
|
|
3245
2102
|
const container = document.querySelector(`#diff-root${id}`);
|
|
3246
|
-
const wrapper = container
|
|
2103
|
+
const wrapper = container === null || container === void 0 ? void 0 : container.querySelector(selector);
|
|
3247
2104
|
if (!wrapper)
|
|
3248
2105
|
return;
|
|
3249
2106
|
const typedWrapper = wrapper;
|
|
3250
2107
|
const cb = () => {
|
|
3251
|
-
|
|
3252
|
-
|
|
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);
|
|
3253
2111
|
};
|
|
3254
2112
|
cb();
|
|
3255
2113
|
const cleanCb = () => {
|
|
2114
|
+
var _a;
|
|
3256
2115
|
typedWrapper.__observeCallback.delete(cb);
|
|
3257
2116
|
if (typedWrapper.__observeCallback.size === 0) {
|
|
3258
|
-
typedWrapper.__observeInstance
|
|
2117
|
+
(_a = typedWrapper.__observeInstance) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
3259
2118
|
typedWrapper.removeAttribute("data-observe");
|
|
3260
2119
|
delete typedWrapper.__observeCallback;
|
|
3261
2120
|
delete typedWrapper.__observeInstance;
|
|
@@ -3292,7 +2151,7 @@ const useSyncHeight = ({ selector, side, enable, }) => {
|
|
|
3292
2151
|
useSafeLayout(() => {
|
|
3293
2152
|
if (enable) {
|
|
3294
2153
|
const container = document.querySelector(`#diff-root${id}`);
|
|
3295
|
-
const elements = Array.from(container
|
|
2154
|
+
const elements = Array.from((container === null || container === void 0 ? void 0 : container.querySelectorAll(selector)) || []);
|
|
3296
2155
|
if (elements.length === 2) {
|
|
3297
2156
|
const ele1 = elements[0];
|
|
3298
2157
|
const ele2 = elements[1];
|
|
@@ -3320,7 +2179,7 @@ const useSyncHeight = ({ selector, side, enable, }) => {
|
|
|
3320
2179
|
target.setAttribute("data-observe", "height");
|
|
3321
2180
|
return () => {
|
|
3322
2181
|
observer.disconnect();
|
|
3323
|
-
target
|
|
2182
|
+
target === null || target === void 0 ? void 0 : target.removeAttribute("data-observe");
|
|
3324
2183
|
};
|
|
3325
2184
|
}
|
|
3326
2185
|
}
|
|
@@ -3363,12 +2222,13 @@ const getLineNumberBG = (isAdded, isDelete, hasDiff) => {
|
|
|
3363
2222
|
};
|
|
3364
2223
|
|
|
3365
2224
|
const _DiffSplitExtendLine$1 = ({ index, diffFile, side, lineNumber, }) => {
|
|
2225
|
+
var _a, _b;
|
|
3366
2226
|
const { useDiffContext } = useDiffViewContext();
|
|
3367
2227
|
const { extendData, renderExtendLine } = useDiffContext(React__namespace.useCallback((s) => ({ extendData: s.extendData, renderExtendLine: s.renderExtendLine }), []));
|
|
3368
2228
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
3369
2229
|
const newLine = diffFile.getSplitRightLine(index);
|
|
3370
|
-
const oldLineExtend = extendData
|
|
3371
|
-
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];
|
|
3372
2232
|
const currentExtend = side === exports.SplitSide.old ? oldLineExtend : newLineExtend;
|
|
3373
2233
|
const currentLineNumber = side === exports.SplitSide.old ? oldLine.lineNumber : newLine.lineNumber;
|
|
3374
2234
|
const otherSide = side === exports.SplitSide.old ? exports.SplitSide.new : exports.SplitSide.old;
|
|
@@ -3385,20 +2245,20 @@ const _DiffSplitExtendLine$1 = ({ index, diffFile, side, lineNumber, }) => {
|
|
|
3385
2245
|
return null;
|
|
3386
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 },
|
|
3387
2247
|
React__namespace.createElement("div", { className: "diff-line-extend-wrapper sticky left-0", style: { width } }, width > 0 &&
|
|
3388
|
-
renderExtendLine
|
|
2248
|
+
(renderExtendLine === null || renderExtendLine === void 0 ? void 0 : renderExtendLine({
|
|
3389
2249
|
diffFile,
|
|
3390
2250
|
side,
|
|
3391
2251
|
lineNumber: currentLineNumber,
|
|
3392
2252
|
data: currentExtend.data,
|
|
3393
2253
|
onUpdate: diffFile.notifyAll,
|
|
3394
|
-
})))) : (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 },
|
|
3395
2255
|
React__namespace.createElement("span", null, "\u2002")))));
|
|
3396
2256
|
};
|
|
3397
2257
|
const DiffSplitExtendLine$1 = ({ index, diffFile, side, lineNumber, }) => {
|
|
3398
2258
|
const { useDiffContext } = useDiffViewContext();
|
|
3399
2259
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
3400
2260
|
const newLine = diffFile.getSplitRightLine(index);
|
|
3401
|
-
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]));
|
|
3402
2262
|
// if the expand action not enabled, the `isHidden` property will never change
|
|
3403
2263
|
const enableExpand = diffFile.getExpandEnabled();
|
|
3404
2264
|
const currentLine = side === exports.SplitSide.old ? oldLine : newLine;
|
|
@@ -3422,6 +2282,7 @@ const ExpandAll = ({ className }) => {
|
|
|
3422
2282
|
};
|
|
3423
2283
|
|
|
3424
2284
|
const _DiffSplitHunkLine = ({ index, diffFile, side, lineNumber, }) => {
|
|
2285
|
+
var _a;
|
|
3425
2286
|
const currentHunk = diffFile.getSplitHunkLine(index);
|
|
3426
2287
|
const expandEnabled = diffFile.getExpandEnabled();
|
|
3427
2288
|
useSyncHeight({
|
|
@@ -3430,63 +2291,42 @@ const _DiffSplitHunkLine = ({ index, diffFile, side, lineNumber, }) => {
|
|
|
3430
2291
|
enable: side === exports.SplitSide.new,
|
|
3431
2292
|
});
|
|
3432
2293
|
const enableHunkAction = side === exports.SplitSide.old;
|
|
2294
|
+
const couldExpand = expandEnabled && currentHunk && currentHunk.splitInfo;
|
|
3433
2295
|
const isExpandAll = currentHunk &&
|
|
3434
2296
|
currentHunk.splitInfo &&
|
|
3435
2297
|
currentHunk.splitInfo.endHiddenIndex - currentHunk.splitInfo.startHiddenIndex < composeLen;
|
|
3436
2298
|
const isFirstLine = currentHunk && currentHunk.index === 0;
|
|
2299
|
+
const isLastLine = currentHunk && currentHunk.isLast;
|
|
3437
2300
|
return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-hunk`, "data-state": "hunk", "data-side": exports.SplitSide[side], className: "diff-line diff-line-hunk" }, enableHunkAction ? (React__namespace.createElement(React__namespace.Fragment, null,
|
|
3438
2301
|
React__namespace.createElement("td", { className: "diff-line-hunk-action sticky left-0 p-[1px] w-[1%] min-w-[40px] select-none", style: {
|
|
3439
2302
|
backgroundColor: `var(${hunkLineNumberBGName})`,
|
|
3440
2303
|
color: `var(${plainLineNumberColorName})`,
|
|
3441
|
-
} },
|
|
3442
|
-
React__namespace.createElement(ExpandUp, { className: "fill-current" }))) :
|
|
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) },
|
|
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: () => {
|
|
2306
|
+
diffFile.onSplitHunkExpand("down", index);
|
|
2307
|
+
} },
|
|
2308
|
+
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) },
|
|
3443
2309
|
React__namespace.createElement(ExpandAll, { className: "fill-current" }))) : (React__namespace.createElement(React__namespace.Fragment, null,
|
|
3444
2310
|
React__namespace.createElement("button", { className: "w-full diff-widget-tooltip hover:bg-blue-300 flex justify-center items-center py-[2px] cursor-pointer rounded-[2px]", title: "Expand Down", "data-title": "Expand Down", onClick: () => diffFile.onSplitHunkExpand("down", index) },
|
|
3445
2311
|
React__namespace.createElement(ExpandDown, { className: "fill-current" })),
|
|
3446
2312
|
React__namespace.createElement("button", { className: "w-full diff-widget-tooltip hover:bg-blue-300 flex justify-center items-center py-[2px] cursor-pointer rounded-[2px]", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onSplitHunkExpand("up", index) },
|
|
3447
|
-
React__namespace.createElement(ExpandUp, { className: "fill-current" }))))) : (React__namespace.createElement("
|
|
2313
|
+
React__namespace.createElement(ExpandUp, { className: "fill-current" }))))) : (React__namespace.createElement("div", { className: "min-h-[28px]" }, "\u2002"))),
|
|
3448
2314
|
React__namespace.createElement("td", { className: "diff-line-hunk-content pr-[10px] align-middle", style: { backgroundColor: `var(${hunkContentBGName})` } },
|
|
3449
2315
|
React__namespace.createElement("div", { className: "pl-[1.5em]", style: {
|
|
3450
2316
|
color: `var(${hunkContentColorName})`,
|
|
3451
|
-
} }, currentHunk.splitInfo.plainText)))) : (React__namespace.createElement("td", { className: "diff-line-hunk-placeholder select-none", colSpan: 2, style: { backgroundColor: `var(${hunkContentBGName})` } },
|
|
3452
|
-
React__namespace.createElement("
|
|
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})` } },
|
|
2318
|
+
React__namespace.createElement("div", { className: "min-h-[28px]" }, "\u2002")))));
|
|
3453
2319
|
};
|
|
3454
2320
|
const DiffSplitHunkLine$1 = ({ index, diffFile, side, lineNumber, }) => {
|
|
3455
2321
|
const currentHunk = diffFile.getSplitHunkLine(index);
|
|
3456
2322
|
const currentIsShow = currentHunk &&
|
|
3457
2323
|
currentHunk.splitInfo &&
|
|
3458
2324
|
currentHunk.splitInfo.startHiddenIndex < currentHunk.splitInfo.endHiddenIndex;
|
|
3459
|
-
|
|
2325
|
+
const currentIsPureHunk = currentHunk && diffFile._getIsPureDiffRender() && !currentHunk.splitInfo;
|
|
2326
|
+
if (!currentIsShow && !currentIsPureHunk)
|
|
3460
2327
|
return null;
|
|
3461
2328
|
return React__namespace.createElement(_DiffSplitHunkLine, { index: index, diffFile: diffFile, side: side, lineNumber: lineNumber });
|
|
3462
2329
|
};
|
|
3463
|
-
const _DiffSplitLastHunkLine = ({ diffFile, side }) => {
|
|
3464
|
-
const enableHunkAction = side === exports.SplitSide.old;
|
|
3465
|
-
useSyncHeight({
|
|
3466
|
-
selector: `tr[data-line="last-hunk"]`,
|
|
3467
|
-
side: exports.SplitSide[exports.SplitSide.old],
|
|
3468
|
-
enable: side === exports.SplitSide.new,
|
|
3469
|
-
});
|
|
3470
|
-
return (React__namespace.createElement("tr", { "data-line": "last-hunk", "data-state": "hunk", "data-side": exports.SplitSide[side], className: "diff-line diff-line-hunk" }, enableHunkAction ? (React__namespace.createElement(React__namespace.Fragment, null,
|
|
3471
|
-
React__namespace.createElement("td", { className: "diff-line-hunk-action sticky left-0 p-[1px] w-[1%] min-w-[40px] select-none", style: {
|
|
3472
|
-
backgroundColor: `var(${hunkLineNumberBGName})`,
|
|
3473
|
-
color: `var(${plainLineNumberColorName})`,
|
|
3474
|
-
} },
|
|
3475
|
-
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: () => {
|
|
3476
|
-
diffFile.onSplitLastExpand();
|
|
3477
|
-
} },
|
|
3478
|
-
React__namespace.createElement(ExpandDown, { className: "fill-current" }))),
|
|
3479
|
-
React__namespace.createElement("td", { className: "diff-line-hunk-content pr-[10px] align-middle select-none", style: { backgroundColor: `var(${hunkContentBGName})` } },
|
|
3480
|
-
React__namespace.createElement("span", null, "\u2002")))) : (React__namespace.createElement("td", { className: "diff-line-hunk-placeholder select-none", colSpan: 2, style: { backgroundColor: `var(${hunkContentBGName})` } },
|
|
3481
|
-
React__namespace.createElement("span", null, "\u2002")))));
|
|
3482
|
-
};
|
|
3483
|
-
const DiffSplitLastHunkLine$1 = ({ diffFile, side }) => {
|
|
3484
|
-
const currentIsShow = diffFile.getNeedShowExpandAll("split");
|
|
3485
|
-
const expandEnabled = diffFile.getExpandEnabled();
|
|
3486
|
-
if (!currentIsShow || !expandEnabled)
|
|
3487
|
-
return null;
|
|
3488
|
-
return React__namespace.createElement(_DiffSplitLastHunkLine, { diffFile: diffFile, side: side });
|
|
3489
|
-
};
|
|
3490
2330
|
|
|
3491
2331
|
const DiffSplitAddWidget = ({ side, className, lineNumber, onWidgetClick, onOpenAddWidget, }) => {
|
|
3492
2332
|
return (React__namespace.createElement("div", { className: "diff-add-widget-wrapper" + (className ? " " + className : ""), style: {
|
|
@@ -3500,7 +2340,7 @@ const DiffSplitAddWidget = ({ side, className, lineNumber, onWidgetClick, onOpen
|
|
|
3500
2340
|
backgroundColor: `var(${addWidgetBGName})`,
|
|
3501
2341
|
}, onClick: () => {
|
|
3502
2342
|
onOpenAddWidget(lineNumber, side);
|
|
3503
|
-
onWidgetClick
|
|
2343
|
+
onWidgetClick === null || onWidgetClick === void 0 ? void 0 : onWidgetClick(lineNumber, side);
|
|
3504
2344
|
} }, "+")));
|
|
3505
2345
|
};
|
|
3506
2346
|
const DiffUnifiedAddWidget = ({ lineNumber, side, onWidgetClick, onOpenAddWidget, }) => {
|
|
@@ -3515,36 +2355,47 @@ const DiffUnifiedAddWidget = ({ lineNumber, side, onWidgetClick, onOpenAddWidget
|
|
|
3515
2355
|
backgroundColor: `var(${addWidgetBGName})`,
|
|
3516
2356
|
}, onClick: () => {
|
|
3517
2357
|
onOpenAddWidget(lineNumber, side);
|
|
3518
|
-
onWidgetClick
|
|
2358
|
+
onWidgetClick === null || onWidgetClick === void 0 ? void 0 : onWidgetClick(lineNumber, side);
|
|
3519
2359
|
} }, "+")));
|
|
3520
2360
|
};
|
|
3521
2361
|
|
|
3522
2362
|
const DiffString = ({ rawLine, diffLine, operator, }) => {
|
|
3523
|
-
const range = diffLine
|
|
3524
|
-
if (range
|
|
2363
|
+
const range = diffLine === null || diffLine === void 0 ? void 0 : diffLine.range;
|
|
2364
|
+
if (range) {
|
|
3525
2365
|
const str1 = rawLine.slice(0, range.location);
|
|
3526
2366
|
const str2 = rawLine.slice(range.location, range.location + range.length);
|
|
3527
2367
|
const str3 = rawLine.slice(range.location + range.length);
|
|
2368
|
+
const isNewLineSymbolChanged = range.isNewLineSymbolChanged;
|
|
3528
2369
|
return (React__namespace.createElement("span", { className: "diff-line-content-raw" },
|
|
3529
2370
|
React__namespace.createElement("span", { "data-range-start": range.location, "data-range-end": range.location + range.length },
|
|
3530
2371
|
str1,
|
|
3531
2372
|
React__namespace.createElement("span", { "data-diff-highlight": true, className: "rounded-[0.2em]", style: {
|
|
3532
2373
|
backgroundColor: operator === "add" ? `var(${addContentHighlightBGName})` : `var(${delContentHighlightBGName})`,
|
|
3533
|
-
} },
|
|
2374
|
+
} }, isNewLineSymbolChanged
|
|
2375
|
+
? str2 === "\r"
|
|
2376
|
+
? "␍"
|
|
2377
|
+
: str2 === "\n"
|
|
2378
|
+
? "␊"
|
|
2379
|
+
: str2 === "\r\n"
|
|
2380
|
+
? "␍␊"
|
|
2381
|
+
: str2
|
|
2382
|
+
: str2),
|
|
3534
2383
|
str3)));
|
|
3535
2384
|
}
|
|
3536
2385
|
return React__namespace.createElement("span", { className: "diff-line-content-raw" }, rawLine);
|
|
3537
2386
|
};
|
|
3538
2387
|
const DiffSyntax = ({ rawLine, diffLine, operator, syntaxLine, }) => {
|
|
2388
|
+
var _a, _b;
|
|
3539
2389
|
if (!syntaxLine) {
|
|
3540
2390
|
return React__namespace.createElement(DiffString, { rawLine: rawLine, diffLine: diffLine, operator: operator });
|
|
3541
2391
|
}
|
|
3542
|
-
const range = diffLine
|
|
3543
|
-
if (range
|
|
2392
|
+
const range = diffLine === null || diffLine === void 0 ? void 0 : diffLine.range;
|
|
2393
|
+
if (range) {
|
|
3544
2394
|
return (React__namespace.createElement("span", { className: "diff-line-syntax-raw" },
|
|
3545
|
-
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;
|
|
3546
2397
|
if (node.endIndex < range.location || range.location + range.length < node.startIndex) {
|
|
3547
|
-
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));
|
|
3548
2399
|
}
|
|
3549
2400
|
else {
|
|
3550
2401
|
const index1 = range.location - node.startIndex;
|
|
@@ -3554,7 +2405,8 @@ const DiffSyntax = ({ rawLine, diffLine, operator, syntaxLine, }) => {
|
|
|
3554
2405
|
const str3 = node.value.slice(index1 + range.length);
|
|
3555
2406
|
const isStart = str1.length || range.location === node.startIndex;
|
|
3556
2407
|
const isEnd = str3.length || node.endIndex === range.location + range.length - 1;
|
|
3557
|
-
|
|
2408
|
+
const isNewLineSymbolChanged = range.isNewLineSymbolChanged;
|
|
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(" ") },
|
|
3558
2410
|
str1,
|
|
3559
2411
|
React__namespace.createElement("span", { "data-diff-highlight": true, style: {
|
|
3560
2412
|
backgroundColor: operator === "add" ? `var(${addContentHighlightBGName})` : `var(${delContentHighlightBGName})`,
|
|
@@ -3562,17 +2414,29 @@ const DiffSyntax = ({ rawLine, diffLine, operator, syntaxLine, }) => {
|
|
|
3562
2414
|
borderBottomLeftRadius: isStart ? "0.2em" : undefined,
|
|
3563
2415
|
borderTopRightRadius: isEnd ? "0.2em" : undefined,
|
|
3564
2416
|
borderBottomRightRadius: isEnd ? "0.2em" : undefined,
|
|
3565
|
-
} },
|
|
2417
|
+
} }, isNewLineSymbolChanged
|
|
2418
|
+
? str2 === "\r"
|
|
2419
|
+
? "␍"
|
|
2420
|
+
: str2 === "\n"
|
|
2421
|
+
? "␊"
|
|
2422
|
+
: str2 === "\r\n"
|
|
2423
|
+
? "␍␊"
|
|
2424
|
+
: str2
|
|
2425
|
+
: str2),
|
|
3566
2426
|
str3));
|
|
3567
2427
|
}
|
|
3568
2428
|
}))));
|
|
3569
2429
|
}
|
|
3570
|
-
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
|
+
})));
|
|
3571
2434
|
};
|
|
3572
2435
|
const DiffContent = ({ diffLine, rawLine, syntaxLine, enableWrap, enableHighlight, }) => {
|
|
3573
|
-
|
|
3574
|
-
const
|
|
3575
|
-
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;
|
|
3576
2440
|
return (React__namespace.createElement("div", { className: "diff-line-content-item pl-[2.0em]", "data-val": rawLine, style: {
|
|
3577
2441
|
whiteSpace: enableWrap ? "pre-wrap" : "pre",
|
|
3578
2442
|
wordBreak: enableWrap ? "break-all" : "initial",
|
|
@@ -3586,15 +2450,16 @@ DiffWidgetContext.displayName = "DiffWidgetContext";
|
|
|
3586
2450
|
const useDiffWidgetContext = () => React.useContext(DiffWidgetContext);
|
|
3587
2451
|
|
|
3588
2452
|
const _DiffSplitLine$1 = ({ index, diffFile, lineNumber, side, }) => {
|
|
2453
|
+
var _a, _b;
|
|
3589
2454
|
const getCurrentSyntaxLine = side === exports.SplitSide.old ? diffFile.getOldSyntaxLine : diffFile.getNewSyntaxLine;
|
|
3590
2455
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
3591
2456
|
const newLine = diffFile.getSplitRightLine(index);
|
|
3592
2457
|
const currentLine = side === exports.SplitSide.old ? oldLine : newLine;
|
|
3593
|
-
const hasDiff = !!currentLine
|
|
2458
|
+
const hasDiff = !!(currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff);
|
|
3594
2459
|
const hasContent = !!currentLine.lineNumber;
|
|
3595
|
-
const hasChange = checkDiffLineIncludeChange(currentLine
|
|
3596
|
-
const isAdded = currentLine
|
|
3597
|
-
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;
|
|
3598
2463
|
const { useDiffContext } = useDiffViewContext();
|
|
3599
2464
|
const { enableHighlight, enableAddWidget, onAddWidgetClick } = useDiffContext(React__namespace.useCallback((s) => ({
|
|
3600
2465
|
enableHighlight: s.enableHighlight,
|
|
@@ -3620,7 +2485,7 @@ const _DiffSplitLine$1 = ({ index, diffFile, lineNumber, side, }) => {
|
|
|
3620
2485
|
const DiffSplitLine$1 = ({ index, diffFile, lineNumber, side, }) => {
|
|
3621
2486
|
const getCurrentLine = side === exports.SplitSide.old ? diffFile.getSplitLeftLine : diffFile.getSplitRightLine;
|
|
3622
2487
|
const currentLine = getCurrentLine(index);
|
|
3623
|
-
if (currentLine
|
|
2488
|
+
if (currentLine === null || currentLine === void 0 ? void 0 : currentLine.isHidden)
|
|
3624
2489
|
return null;
|
|
3625
2490
|
return React__namespace.createElement(_DiffSplitLine$1, { index: index, diffFile: diffFile, lineNumber: lineNumber, side: side });
|
|
3626
2491
|
};
|
|
@@ -3642,12 +2507,12 @@ const _DiffSplitWidgetLine$1 = ({ diffFile, side, lineNumber, currentLine, setWi
|
|
|
3642
2507
|
return null;
|
|
3643
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 },
|
|
3644
2509
|
React__namespace.createElement("div", { className: "diff-line-widget-wrapper sticky left-0", style: { width } }, width > 0 &&
|
|
3645
|
-
renderWidgetLine
|
|
2510
|
+
(renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({
|
|
3646
2511
|
diffFile,
|
|
3647
2512
|
side,
|
|
3648
2513
|
lineNumber: currentLine.lineNumber,
|
|
3649
2514
|
onClose: () => setWidget({}),
|
|
3650
|
-
})))) : (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 },
|
|
3651
2516
|
React__namespace.createElement("span", null, "\u2002")))));
|
|
3652
2517
|
};
|
|
3653
2518
|
const DiffSplitWidgetLine$1 = ({ index, diffFile, side, lineNumber, }) => {
|
|
@@ -3725,7 +2590,7 @@ const DiffSplitViewTable = ({ side, diffFile, width }) => {
|
|
|
3725
2590
|
React__namespace.createElement(DiffSplitLine$1, { index: line.index, side: side, lineNumber: line.lineNumber, diffFile: diffFile }),
|
|
3726
2591
|
React__namespace.createElement(DiffSplitWidgetLine$1, { index: line.index, side: side, lineNumber: line.lineNumber, diffFile: diffFile }),
|
|
3727
2592
|
React__namespace.createElement(DiffSplitExtendLine$1, { index: line.index, side: side, lineNumber: line.lineNumber, diffFile: diffFile })))),
|
|
3728
|
-
React__namespace.createElement(
|
|
2593
|
+
React__namespace.createElement(DiffSplitHunkLine$1, { side: side, index: diffFile.splitLineLength, lineNumber: diffFile.splitLineLength, diffFile: diffFile }))));
|
|
3729
2594
|
};
|
|
3730
2595
|
const DiffSplitViewNormal = React.memo(({ diffFile }) => {
|
|
3731
2596
|
const ref1 = React.useRef(null);
|
|
@@ -3763,18 +2628,19 @@ const DiffSplitViewNormal = React.memo(({ diffFile }) => {
|
|
|
3763
2628
|
DiffSplitViewNormal.displayName = "DiffSplitViewNormal";
|
|
3764
2629
|
|
|
3765
2630
|
const _DiffSplitExtendLine = ({ index, diffFile, lineNumber, }) => {
|
|
2631
|
+
var _a, _b;
|
|
3766
2632
|
const { useDiffContext } = useDiffViewContext();
|
|
3767
2633
|
// 需要显示的时候才进行方法订阅,可以大幅度提高性能
|
|
3768
2634
|
const { extendData, renderExtendLine } = useDiffContext(React__namespace.useCallback((s) => ({ extendData: s.extendData, renderExtendLine: s.renderExtendLine }), []));
|
|
3769
2635
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
3770
2636
|
const newLine = diffFile.getSplitRightLine(index);
|
|
3771
|
-
const oldLineExtend = extendData
|
|
3772
|
-
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];
|
|
3773
2639
|
if (!renderExtendLine)
|
|
3774
2640
|
return null;
|
|
3775
2641
|
return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-extend`, "data-state": "extend", className: "diff-line diff-line-extend" },
|
|
3776
2642
|
oldLineExtend ? (React__namespace.createElement("td", { className: "diff-line-extend-old-content p-0", colSpan: 2 },
|
|
3777
|
-
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({
|
|
3778
2644
|
diffFile,
|
|
3779
2645
|
side: exports.SplitSide.old,
|
|
3780
2646
|
lineNumber: oldLine.lineNumber,
|
|
@@ -3783,7 +2649,7 @@ const _DiffSplitExtendLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
3783
2649
|
})))) : (React__namespace.createElement("td", { className: "diff-line-extend-old-placeholder p-0 select-none", style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
|
|
3784
2650
|
React__namespace.createElement("span", null, "\u2002"))),
|
|
3785
2651
|
newLineExtend ? (React__namespace.createElement("td", { className: "diff-line-extend-new-content p-0 border-l-[1px] border-l-[#ccc]", colSpan: 2 },
|
|
3786
|
-
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({
|
|
3787
2653
|
diffFile,
|
|
3788
2654
|
side: exports.SplitSide.new,
|
|
3789
2655
|
lineNumber: newLine.lineNumber,
|
|
@@ -3796,71 +2662,59 @@ const DiffSplitExtendLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
3796
2662
|
const { useDiffContext } = useDiffViewContext();
|
|
3797
2663
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
3798
2664
|
const newLine = diffFile.getSplitRightLine(index);
|
|
3799
|
-
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]));
|
|
3800
2666
|
// if the expand action not enabled, the `isHidden` property will never change
|
|
3801
2667
|
const enableExpand = diffFile.getExpandEnabled();
|
|
3802
|
-
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);
|
|
3803
2669
|
if (!currentIsShow)
|
|
3804
2670
|
return null;
|
|
3805
2671
|
return React__namespace.createElement(_DiffSplitExtendLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
3806
2672
|
};
|
|
3807
2673
|
|
|
3808
2674
|
const DiffSplitHunkLine = ({ index, diffFile, lineNumber, }) => {
|
|
2675
|
+
var _a;
|
|
3809
2676
|
const currentHunk = diffFile.getSplitHunkLine(index);
|
|
3810
2677
|
const expandEnabled = diffFile.getExpandEnabled();
|
|
2678
|
+
const couldExpand = expandEnabled && currentHunk && currentHunk.splitInfo;
|
|
3811
2679
|
const isExpandAll = currentHunk &&
|
|
3812
2680
|
currentHunk.splitInfo &&
|
|
3813
2681
|
currentHunk.splitInfo.endHiddenIndex - currentHunk.splitInfo.startHiddenIndex < composeLen;
|
|
3814
2682
|
const currentIsShow = currentHunk &&
|
|
3815
2683
|
currentHunk.splitInfo &&
|
|
3816
2684
|
currentHunk.splitInfo.startHiddenIndex < currentHunk.splitInfo.endHiddenIndex;
|
|
2685
|
+
const currentIsPureHunk = currentHunk && diffFile._getIsPureDiffRender() && !currentHunk.splitInfo;
|
|
3817
2686
|
const isFirstLine = currentHunk && currentHunk.index === 0;
|
|
3818
|
-
|
|
2687
|
+
const isLastLine = currentHunk && currentHunk.isLast;
|
|
2688
|
+
if (!currentIsShow && !currentIsPureHunk)
|
|
3819
2689
|
return null;
|
|
3820
2690
|
return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-hunk`, "data-state": "hunk", className: "diff-line diff-line-hunk" },
|
|
3821
2691
|
React__namespace.createElement("td", { className: "diff-line-hunk-action p-[1px] w-[1%] min-w-[40px] select-none", style: {
|
|
3822
2692
|
backgroundColor: `var(${hunkLineNumberBGName})`,
|
|
3823
2693
|
color: `var(${plainLineNumberColorName})`,
|
|
3824
|
-
} },
|
|
3825
|
-
(
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
|
|
3829
|
-
|
|
3830
|
-
|
|
3831
|
-
|
|
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) },
|
|
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) },
|
|
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) },
|
|
2697
|
+
React__namespace.createElement(ExpandAll, { className: "fill-current" }))) : (React__namespace.createElement(React__namespace.Fragment, null,
|
|
2698
|
+
React__namespace.createElement("button", { className: "w-full diff-widget-tooltip hover:bg-blue-300 flex justify-center items-center py-[2px] cursor-pointer rounded-[2px]", title: "Expand Down", "data-title": "Expand Down", onClick: () => diffFile.onSplitHunkExpand("down", index) },
|
|
2699
|
+
React__namespace.createElement(ExpandDown, { className: "fill-current" })),
|
|
2700
|
+
React__namespace.createElement("button", { className: "w-full diff-widget-tooltip hover:bg-blue-300 flex justify-center items-center py-[2px] cursor-pointer rounded-[2px]", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onSplitHunkExpand("up", index) },
|
|
2701
|
+
React__namespace.createElement(ExpandUp, { className: "fill-current" }))))) : (React__namespace.createElement("div", { className: "min-h-[28px]" }, "\u2002"))),
|
|
3832
2702
|
React__namespace.createElement("td", { className: "diff-line-hunk-content pr-[10px] align-middle", style: { backgroundColor: `var(${hunkContentBGName})` }, colSpan: 3 },
|
|
3833
2703
|
React__namespace.createElement("div", { className: "pl-[1.5em]", style: {
|
|
3834
2704
|
color: `var(${hunkContentColorName})`,
|
|
3835
|
-
} }, currentHunk.splitInfo.plainText))));
|
|
3836
|
-
};
|
|
3837
|
-
const DiffSplitLastHunkLine = ({ diffFile }) => {
|
|
3838
|
-
const currentIsShow = diffFile.getNeedShowExpandAll("split");
|
|
3839
|
-
const expandEnabled = diffFile.getExpandEnabled();
|
|
3840
|
-
if (!currentIsShow || !expandEnabled)
|
|
3841
|
-
return null;
|
|
3842
|
-
return (React__namespace.createElement("tr", { "data-line": "last-hunk", "data-state": "hunk", className: "diff-line diff-line-hunk" },
|
|
3843
|
-
React__namespace.createElement("td", { className: "diff-line-hunk-action p-[1px] w-[1%] min-w-[40px] select-none", style: {
|
|
3844
|
-
backgroundColor: `var(${hunkLineNumberBGName})`,
|
|
3845
|
-
color: `var(${plainLineNumberColorName})`,
|
|
3846
|
-
} },
|
|
3847
|
-
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: () => {
|
|
3848
|
-
diffFile.onSplitLastExpand();
|
|
3849
|
-
} },
|
|
3850
|
-
React__namespace.createElement(ExpandDown, { className: "fill-current" }))),
|
|
3851
|
-
React__namespace.createElement("td", { className: "diff-line-hunk-content pr-[10px] align-middle select-none", colSpan: 3, style: { backgroundColor: `var(${hunkContentBGName})` } },
|
|
3852
|
-
React__namespace.createElement("span", null, "\u2002"))));
|
|
2705
|
+
} }, ((_a = currentHunk.splitInfo) === null || _a === void 0 ? void 0 : _a.plainText) || currentHunk.text))));
|
|
3853
2706
|
};
|
|
3854
2707
|
|
|
3855
2708
|
const _DiffSplitLine = ({ index, diffFile, lineNumber }) => {
|
|
2709
|
+
var _a, _b;
|
|
3856
2710
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
3857
2711
|
const newLine = diffFile.getSplitRightLine(index);
|
|
3858
|
-
const oldSyntaxLine = diffFile.getOldSyntaxLine(oldLine
|
|
3859
|
-
const newSyntaxLine = diffFile.getNewSyntaxLine(newLine
|
|
3860
|
-
const hasDiff = !!oldLine
|
|
3861
|
-
const hasChange = checkDiffLineIncludeChange(oldLine
|
|
3862
|
-
const oldLineIsDelete = oldLine
|
|
3863
|
-
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;
|
|
3864
2718
|
const { useDiffContext } = useDiffViewContext();
|
|
3865
2719
|
const { enableHighlight, enableAddWidget, onAddWidgetClick } = useDiffContext(React__namespace.useCallback((s) => ({
|
|
3866
2720
|
enableHighlight: s.enableHighlight,
|
|
@@ -3896,7 +2750,7 @@ const _DiffSplitLine = ({ index, diffFile, lineNumber }) => {
|
|
|
3896
2750
|
const DiffSplitLine = ({ index, diffFile, lineNumber, }) => {
|
|
3897
2751
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
3898
2752
|
const newLine = diffFile.getSplitRightLine(index);
|
|
3899
|
-
if (oldLine
|
|
2753
|
+
if ((oldLine === null || oldLine === void 0 ? void 0 : oldLine.isHidden) && (newLine === null || newLine === void 0 ? void 0 : newLine.isHidden))
|
|
3900
2754
|
return null;
|
|
3901
2755
|
return React__namespace.createElement(_DiffSplitLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
3902
2756
|
};
|
|
@@ -3914,7 +2768,7 @@ const _DiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
3914
2768
|
return null;
|
|
3915
2769
|
return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-widget`, "data-state": "widget", className: "diff-line diff-line-widget" },
|
|
3916
2770
|
oldLineWidget ? (React__namespace.createElement("td", { className: "diff-line-widget-old-content p-0", colSpan: 2 },
|
|
3917
|
-
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({
|
|
3918
2772
|
diffFile,
|
|
3919
2773
|
side: exports.SplitSide.old,
|
|
3920
2774
|
lineNumber: oldLine.lineNumber,
|
|
@@ -3922,7 +2776,7 @@ const _DiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
3922
2776
|
})))) : (React__namespace.createElement("td", { className: "diff-line-widget-old-placeholder p-0 select-none", style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
|
|
3923
2777
|
React__namespace.createElement("span", null, "\u2002"))),
|
|
3924
2778
|
newLineWidget ? (React__namespace.createElement("td", { className: "diff-line-widget-new-content p-0 border-l-[1px] border-l-[#ccc]", colSpan: 2 },
|
|
3925
|
-
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({
|
|
3926
2780
|
diffFile,
|
|
3927
2781
|
side: exports.SplitSide.new,
|
|
3928
2782
|
lineNumber: newLine.lineNumber,
|
|
@@ -3943,7 +2797,6 @@ const DiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
3943
2797
|
return React__namespace.createElement(_DiffSplitWidgetLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
3944
2798
|
};
|
|
3945
2799
|
|
|
3946
|
-
/* eslint-disable jsx-a11y/no-noninteractive-element-interactions */
|
|
3947
2800
|
const Style = ({ useSelector, id, }) => {
|
|
3948
2801
|
const splitRef = useSelector((s) => s.splitRef);
|
|
3949
2802
|
return (React__namespace.createElement("style", null, splitRef === exports.SplitSide.old
|
|
@@ -4014,7 +2867,7 @@ const DiffSplitViewWrap = React.memo(({ diffFile }) => {
|
|
|
4014
2867
|
React__namespace.createElement(DiffSplitLine, { index: line.index, lineNumber: line.lineNumber, diffFile: diffFile }),
|
|
4015
2868
|
React__namespace.createElement(DiffSplitWidgetLine, { index: line.index, lineNumber: line.lineNumber, diffFile: diffFile }),
|
|
4016
2869
|
React__namespace.createElement(DiffSplitExtendLine, { index: line.index, lineNumber: line.lineNumber, diffFile: diffFile })))),
|
|
4017
|
-
React__namespace.createElement(
|
|
2870
|
+
React__namespace.createElement(DiffSplitHunkLine, { index: diffFile.splitLineLength, lineNumber: diffFile.splitLineLength, diffFile: diffFile }))))));
|
|
4018
2871
|
});
|
|
4019
2872
|
DiffSplitViewWrap.displayName = "DiffSplitViewWrap";
|
|
4020
2873
|
|
|
@@ -4026,11 +2879,14 @@ const DiffSplitView = React.memo(({ diffFile }) => {
|
|
|
4026
2879
|
const widgetSide = reactivityStore.ref(undefined);
|
|
4027
2880
|
const widgetLineNumber = reactivityStore.ref(undefined);
|
|
4028
2881
|
const setWidget = ({ side, lineNumber }) => {
|
|
2882
|
+
const { renderWidgetLine } = useDiffContext.getReadonlyState();
|
|
2883
|
+
if (typeof renderWidgetLine !== "function")
|
|
2884
|
+
return;
|
|
4029
2885
|
widgetSide.value = side;
|
|
4030
2886
|
widgetLineNumber.value = lineNumber;
|
|
4031
2887
|
};
|
|
4032
2888
|
return { widgetSide, widgetLineNumber, setWidget };
|
|
4033
|
-
}), []);
|
|
2889
|
+
}), [useDiffContext]);
|
|
4034
2890
|
const contextValue = React.useMemo(() => ({ useWidget }), [useWidget]);
|
|
4035
2891
|
shim.useSyncExternalStore(diffFile.subscribe, diffFile.getUpdateCount);
|
|
4036
2892
|
React.useEffect(() => {
|
|
@@ -4045,8 +2901,8 @@ const _DiffUnifiedExtendLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
4045
2901
|
const { useDiffContext } = useDiffViewContext();
|
|
4046
2902
|
const renderExtendLine = useDiffContext(React.useCallback((s) => s.renderExtendLine, []));
|
|
4047
2903
|
const unifiedItem = diffFile.getUnifiedLine(index);
|
|
4048
|
-
const oldExtend = useDiffContext(React.useCallback((s) => s.extendData
|
|
4049
|
-
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]));
|
|
4050
2906
|
const width = useDomWidth({
|
|
4051
2907
|
selector: ".unified-diff-table-wrapper",
|
|
4052
2908
|
enable: typeof renderExtendLine === "function",
|
|
@@ -4058,83 +2914,73 @@ const _DiffUnifiedExtendLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
4058
2914
|
React__namespace.createElement("div", { className: "diff-line-extend-wrapper sticky left-0", style: { width } },
|
|
4059
2915
|
width > 0 &&
|
|
4060
2916
|
oldExtend &&
|
|
4061
|
-
renderExtendLine
|
|
2917
|
+
(renderExtendLine === null || renderExtendLine === void 0 ? void 0 : renderExtendLine({
|
|
4062
2918
|
diffFile,
|
|
4063
2919
|
side: exports.SplitSide.old,
|
|
4064
2920
|
lineNumber: unifiedItem.oldLineNumber,
|
|
4065
2921
|
data: oldExtend.data,
|
|
4066
2922
|
onUpdate: diffFile.notifyAll,
|
|
4067
|
-
}),
|
|
2923
|
+
})),
|
|
4068
2924
|
width > 0 &&
|
|
4069
2925
|
newExtend &&
|
|
4070
|
-
renderExtendLine
|
|
2926
|
+
(renderExtendLine === null || renderExtendLine === void 0 ? void 0 : renderExtendLine({
|
|
4071
2927
|
diffFile,
|
|
4072
2928
|
side: exports.SplitSide.new,
|
|
4073
2929
|
lineNumber: unifiedItem.newLineNumber,
|
|
4074
2930
|
data: newExtend.data,
|
|
4075
2931
|
onUpdate: diffFile.notifyAll,
|
|
4076
|
-
})))));
|
|
2932
|
+
}))))));
|
|
4077
2933
|
};
|
|
4078
2934
|
const DiffUnifiedExtendLine = ({ index, diffFile, lineNumber, }) => {
|
|
4079
2935
|
const { useDiffContext } = useDiffViewContext();
|
|
4080
2936
|
const unifiedItem = diffFile.getUnifiedLine(index);
|
|
4081
|
-
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]));
|
|
4082
2938
|
if (!hasExtend || !unifiedItem || unifiedItem.isHidden || !unifiedItem.diff)
|
|
4083
2939
|
return null;
|
|
4084
2940
|
return React__namespace.createElement(_DiffUnifiedExtendLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
4085
2941
|
};
|
|
4086
2942
|
|
|
4087
2943
|
const _DiffUnifiedHunkLine = ({ index, diffFile, lineNumber, }) => {
|
|
2944
|
+
var _a;
|
|
4088
2945
|
const currentHunk = diffFile.getUnifiedHunkLine(index);
|
|
4089
2946
|
const expandEnabled = diffFile.getExpandEnabled();
|
|
4090
2947
|
const { useDiffContext } = useDiffViewContext();
|
|
4091
2948
|
const enableWrap = useDiffContext(React.useCallback((s) => s.enableWrap, []));
|
|
2949
|
+
const couldExpand = expandEnabled && currentHunk && currentHunk.unifiedInfo;
|
|
4092
2950
|
const isExpandAll = currentHunk &&
|
|
4093
2951
|
currentHunk.unifiedInfo &&
|
|
4094
2952
|
currentHunk.unifiedInfo.endHiddenIndex - currentHunk.unifiedInfo.startHiddenIndex < composeLen;
|
|
4095
2953
|
const isFirstLine = currentHunk && currentHunk.index === 0;
|
|
2954
|
+
const isLastLine = currentHunk && currentHunk.isLast;
|
|
4096
2955
|
return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-hunk`, "data-state": "hunk", className: "diff-line diff-line-hunk" },
|
|
4097
2956
|
React__namespace.createElement("td", { className: "diff-line-hunk-action sticky left-0 p-[1px] w-[1%] min-w-[100px] select-none", style: {
|
|
4098
2957
|
backgroundColor: `var(${hunkLineNumberBGName})`,
|
|
4099
2958
|
color: `var(${plainLineNumberColorName})`,
|
|
4100
|
-
} },
|
|
4101
|
-
React__namespace.createElement(ExpandUp, { className: "fill-current" }))) :
|
|
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) },
|
|
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) },
|
|
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) },
|
|
4102
2962
|
React__namespace.createElement(ExpandAll, { className: "fill-current" }))) : (React__namespace.createElement(React__namespace.Fragment, null,
|
|
4103
2963
|
React__namespace.createElement("button", { className: "w-full diff-widget-tooltip hover:bg-blue-300 flex justify-center items-center py-[2px] cursor-pointer rounded-[2px]", title: "Expand Down", "data-title": "Expand Down", onClick: () => diffFile.onUnifiedHunkExpand("down", index) },
|
|
4104
2964
|
React__namespace.createElement(ExpandDown, { className: "fill-current" })),
|
|
4105
2965
|
React__namespace.createElement("button", { className: "w-full diff-widget-tooltip hover:bg-blue-300 flex justify-center items-center py-[2px] cursor-pointer rounded-[2px]", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onUnifiedHunkExpand("up", index) },
|
|
4106
|
-
React__namespace.createElement(ExpandUp, { className: "fill-current" }))))) :
|
|
2966
|
+
React__namespace.createElement(ExpandUp, { className: "fill-current" }))))) : (React__namespace.createElement("div", { className: "min-h-[28px]" }, "\u2002"))),
|
|
4107
2967
|
React__namespace.createElement("td", { className: "diff-line-hunk-content pr-[10px] align-middle", style: { backgroundColor: `var(${hunkContentBGName})` } },
|
|
4108
2968
|
React__namespace.createElement("div", { className: "pl-[1.5em]", style: {
|
|
4109
2969
|
whiteSpace: enableWrap ? "pre-wrap" : "pre",
|
|
4110
2970
|
wordBreak: enableWrap ? "break-all" : "initial",
|
|
4111
2971
|
color: `var(${hunkContentColorName})`,
|
|
4112
|
-
} }, currentHunk.unifiedInfo.plainText))));
|
|
2972
|
+
} }, ((_a = currentHunk.unifiedInfo) === null || _a === void 0 ? void 0 : _a.plainText) || currentHunk.text))));
|
|
4113
2973
|
};
|
|
4114
2974
|
const DiffUnifiedHunkLine = ({ index, diffFile, lineNumber, }) => {
|
|
4115
2975
|
const currentHunk = diffFile.getUnifiedHunkLine(index);
|
|
4116
2976
|
const currentIsShow = currentHunk &&
|
|
4117
2977
|
currentHunk.unifiedInfo &&
|
|
4118
2978
|
currentHunk.unifiedInfo.startHiddenIndex < currentHunk.unifiedInfo.endHiddenIndex;
|
|
4119
|
-
|
|
2979
|
+
const currentIsPureHunk = currentHunk && diffFile._getIsPureDiffRender() && !currentHunk.unifiedInfo;
|
|
2980
|
+
if (!currentIsShow && !currentIsPureHunk)
|
|
4120
2981
|
return null;
|
|
4121
2982
|
return React__namespace.createElement(_DiffUnifiedHunkLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
4122
2983
|
};
|
|
4123
|
-
const DiffUnifiedLastHunkLine = ({ diffFile }) => {
|
|
4124
|
-
const currentIsShow = diffFile.getNeedShowExpandAll("unified");
|
|
4125
|
-
const expandEnabled = diffFile.getExpandEnabled();
|
|
4126
|
-
if (!currentIsShow || !expandEnabled)
|
|
4127
|
-
return null;
|
|
4128
|
-
return (React__namespace.createElement("tr", { "data-line": "last-hunk", "data-state": "hunk", className: "diff-line diff-line-hunk" },
|
|
4129
|
-
React__namespace.createElement("td", { className: "diff-line-hunk-action sticky left-0 w-[1%] min-w-[100px] select-none", style: {
|
|
4130
|
-
backgroundColor: `var(${hunkLineNumberBGName})`,
|
|
4131
|
-
color: `var(${plainLineNumberColorName})`,
|
|
4132
|
-
} },
|
|
4133
|
-
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.onUnifiedLastExpand() },
|
|
4134
|
-
React__namespace.createElement(ExpandDown, { className: "fill-current" }))),
|
|
4135
|
-
React__namespace.createElement("td", { className: "diff-line-hunk-content pr-[10px] align-middle", style: { backgroundColor: `var(${hunkContentBGName})` } },
|
|
4136
|
-
React__namespace.createElement("span", null, "\u2002"))));
|
|
4137
|
-
};
|
|
4138
2984
|
|
|
4139
2985
|
const DiffUnifiedOldLine = ({ index, diffLine, rawLine, syntaxLine, lineNumber, diffFile, setWidget, enableWrap, enableAddWidget, enableHighlight, onAddWidgetClick, }) => {
|
|
4140
2986
|
return (React__namespace.createElement("tr", { "data-line": index, "data-state": "diff", className: "diff-line group" },
|
|
@@ -4214,7 +3060,7 @@ const _DiffUnifiedLine = React.memo(({ index, diffFile, lineNumber }) => {
|
|
|
4214
3060
|
_DiffUnifiedLine.displayName = "_DiffUnifiedLine";
|
|
4215
3061
|
const DiffUnifiedLine = ({ index, diffFile, lineNumber, }) => {
|
|
4216
3062
|
const unifiedLine = diffFile.getUnifiedLine(index);
|
|
4217
|
-
if (unifiedLine
|
|
3063
|
+
if (unifiedLine === null || unifiedLine === void 0 ? void 0 : unifiedLine.isHidden)
|
|
4218
3064
|
return null;
|
|
4219
3065
|
return React__namespace.createElement(_DiffUnifiedLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
4220
3066
|
};
|
|
@@ -4236,10 +3082,10 @@ const _DiffUnifiedWidgetLine = ({ index, diffFile, oldWidget, newWidget, lineNum
|
|
|
4236
3082
|
React__namespace.createElement("div", { className: "diff-line-widget-wrapper sticky left-0", style: { width } },
|
|
4237
3083
|
width > 0 &&
|
|
4238
3084
|
oldWidget &&
|
|
4239
|
-
renderWidgetLine
|
|
3085
|
+
(renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({ diffFile, side: exports.SplitSide.old, lineNumber: unifiedItem.oldLineNumber, onClose })),
|
|
4240
3086
|
width > 0 &&
|
|
4241
3087
|
newWidget &&
|
|
4242
|
-
renderWidgetLine
|
|
3088
|
+
(renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({ diffFile, side: exports.SplitSide.new, lineNumber: unifiedItem.newLineNumber, onClose }))))));
|
|
4243
3089
|
};
|
|
4244
3090
|
const DiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
4245
3091
|
const { useWidget } = useDiffWidgetContext();
|
|
@@ -4262,16 +3108,20 @@ const onMouseDown = (e) => {
|
|
|
4262
3108
|
}
|
|
4263
3109
|
};
|
|
4264
3110
|
const DiffUnifiedView = React.memo(({ diffFile }) => {
|
|
3111
|
+
const { useDiffContext } = useDiffViewContext();
|
|
4265
3112
|
// performance optimization
|
|
4266
3113
|
const useWidget = React.useMemo(() => reactivityStore.createStore(() => {
|
|
4267
3114
|
const widgetSide = reactivityStore.ref(undefined);
|
|
4268
3115
|
const widgetLineNumber = reactivityStore.ref(undefined);
|
|
4269
3116
|
const setWidget = ({ side, lineNumber }) => {
|
|
3117
|
+
const { renderWidgetLine } = useDiffContext.getReadonlyState();
|
|
3118
|
+
if (typeof renderWidgetLine !== "function")
|
|
3119
|
+
return;
|
|
4270
3120
|
widgetSide.value = side;
|
|
4271
3121
|
widgetLineNumber.value = lineNumber;
|
|
4272
3122
|
};
|
|
4273
3123
|
return { widgetSide, widgetLineNumber, setWidget };
|
|
4274
|
-
}), []);
|
|
3124
|
+
}), [useDiffContext]);
|
|
4275
3125
|
const contextValue = React.useMemo(() => ({ useWidget }), [useWidget]);
|
|
4276
3126
|
shim.useSyncExternalStore(diffFile.subscribe, diffFile.getUpdateCount);
|
|
4277
3127
|
React.useEffect(() => {
|
|
@@ -4296,13 +3146,12 @@ const DiffUnifiedView = React.memo(({ diffFile }) => {
|
|
|
4296
3146
|
React__namespace.createElement(DiffUnifiedLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile }),
|
|
4297
3147
|
React__namespace.createElement(DiffUnifiedWidgetLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile }),
|
|
4298
3148
|
React__namespace.createElement(DiffUnifiedExtendLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile })))),
|
|
4299
|
-
React__namespace.createElement(
|
|
3149
|
+
React__namespace.createElement(DiffUnifiedHunkLine, { index: diffFile.unifiedLineLength, lineNumber: diffFile.unifiedLineLength, diffFile: diffFile })))))));
|
|
4300
3150
|
});
|
|
4301
3151
|
DiffUnifiedView.displayName = "DiffUnifiedView";
|
|
4302
3152
|
|
|
4303
|
-
/* eslint-disable @typescript-eslint/no-unnecessary-type-constraint */
|
|
4304
|
-
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
4305
3153
|
const diffFontSizeName = "--diff-font-size--";
|
|
3154
|
+
_cacheMap.name = "@git-diff-view/react";
|
|
4306
3155
|
exports.SplitSide = void 0;
|
|
4307
3156
|
(function (SplitSide) {
|
|
4308
3157
|
SplitSide[SplitSide["old"] = 1] = "old";
|
|
@@ -4313,6 +3162,7 @@ const _InternalDiffView = (props) => {
|
|
|
4313
3162
|
const diffFileId = React.useMemo(() => diffFile.getId(), [diffFile]);
|
|
4314
3163
|
// performance optimization
|
|
4315
3164
|
const useDiffContext = React.useMemo(() => reactivityStore.createStore(() => {
|
|
3165
|
+
var _a, _b;
|
|
4316
3166
|
const id = reactivityStore.ref(diffFileId);
|
|
4317
3167
|
const setId = (_id) => (id.value = _id);
|
|
4318
3168
|
const mode = reactivityStore.ref(props.diffViewMode);
|
|
@@ -4326,8 +3176,8 @@ const _InternalDiffView = (props) => {
|
|
|
4326
3176
|
const fontSize = reactivityStore.ref(props.diffViewFontSize);
|
|
4327
3177
|
const setFontSize = (_fontSize) => (fontSize.value = _fontSize);
|
|
4328
3178
|
const extendData = reactivityStore.ref({
|
|
4329
|
-
oldFile: {
|
|
4330
|
-
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),
|
|
4331
3181
|
});
|
|
4332
3182
|
const setExtendData = (_extendData) => {
|
|
4333
3183
|
const existOldKeys = Object.keys(extendData.value.oldFile || {});
|
|
@@ -4409,7 +3259,7 @@ const _InternalDiffView = (props) => {
|
|
|
4409
3259
|
]);
|
|
4410
3260
|
const value = React.useMemo(() => ({ useDiffContext }), [useDiffContext]);
|
|
4411
3261
|
return (React__namespace.createElement(DiffViewContext.Provider, { value: value },
|
|
4412
|
-
React__namespace.createElement("div", { className: "diff-tailwindcss-wrapper" },
|
|
3262
|
+
React__namespace.createElement("div", { className: "diff-tailwindcss-wrapper", "data-component": "git-diff-view", "data-version": `${"0.0.7"}` },
|
|
4413
3263
|
React__namespace.createElement("div", { className: "diff-style-root", style: {
|
|
4414
3264
|
// @ts-ignore
|
|
4415
3265
|
[diffFontSizeName]: diffViewFontSize + "px",
|
|
@@ -4417,16 +3267,17 @@ const _InternalDiffView = (props) => {
|
|
|
4417
3267
|
React__namespace.createElement("div", { id: `diff-root${diffFileId}`, className: "diff-view-wrapper" + (className ? ` ${className}` : ""), style: style }, diffViewMode === exports.DiffModeEnum.Split ? (React__namespace.createElement(DiffSplitView, { diffFile: diffFile })) : (React__namespace.createElement(DiffUnifiedView, { diffFile: diffFile })))))));
|
|
4418
3268
|
};
|
|
4419
3269
|
const InternalDiffView = React.memo(_InternalDiffView);
|
|
4420
|
-
const
|
|
4421
|
-
const { registerHighlighter, autoDetectLang, data, diffFile: _diffFile,
|
|
3270
|
+
const DiffViewWithRef = (props, ref) => {
|
|
3271
|
+
const { registerHighlighter, autoDetectLang, data, diffFile: _diffFile } = props, restProps = __rest(props, ["registerHighlighter", "autoDetectLang", "data", "diffFile"]);
|
|
4422
3272
|
const diffFile = React.useMemo(() => {
|
|
3273
|
+
var _a, _b, _c, _d, _e, _f;
|
|
4423
3274
|
if (_diffFile) {
|
|
4424
3275
|
const diffFile = DiffFile.createInstance({});
|
|
4425
3276
|
diffFile._mergeFullBundle(_diffFile._getFullBundle());
|
|
4426
3277
|
return diffFile;
|
|
4427
3278
|
}
|
|
4428
3279
|
else if (data) {
|
|
4429
|
-
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) || "");
|
|
4430
3281
|
}
|
|
4431
3282
|
return null;
|
|
4432
3283
|
}, [data, _diffFile]);
|
|
@@ -4454,14 +3305,39 @@ const DiffView = (props) => {
|
|
|
4454
3305
|
}
|
|
4455
3306
|
}, [diffFile, _diffFile]);
|
|
4456
3307
|
useUnmount(() => diffFile._destroy(), [diffFile]);
|
|
3308
|
+
React.useImperativeHandle(ref, () => ({ getDiffFileInstance: () => diffFile }), [diffFile]);
|
|
4457
3309
|
if (!diffFile)
|
|
4458
3310
|
return null;
|
|
4459
|
-
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 })));
|
|
4460
3312
|
};
|
|
4461
|
-
const
|
|
3313
|
+
const DiffView = React.forwardRef(DiffViewWithRef);
|
|
3314
|
+
DiffView.displayName = "DiffView";
|
|
3315
|
+
const version = "0.0.7";
|
|
4462
3316
|
|
|
3317
|
+
exports.DefaultDiffExpansionStep = DefaultDiffExpansionStep;
|
|
3318
|
+
exports.DiffFile = DiffFile;
|
|
3319
|
+
exports.DiffLine = DiffLine;
|
|
4463
3320
|
exports.DiffView = DiffView;
|
|
4464
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;
|
|
4465
3340
|
exports.useDiffViewContext = useDiffViewContext;
|
|
4466
3341
|
exports.version = version;
|
|
3342
|
+
exports.versions = versions;
|
|
4467
3343
|
//# sourceMappingURL=index.development.js.map
|