@pierre/diffs 1.1.5 → 1.1.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/components/AdvancedVirtualizedFileDiff.d.ts.map +1 -1
- package/dist/components/File.d.ts +21 -1
- package/dist/components/File.d.ts.map +1 -1
- package/dist/components/File.js +142 -70
- package/dist/components/File.js.map +1 -1
- package/dist/components/FileDiff.d.ts +26 -5
- package/dist/components/FileDiff.d.ts.map +1 -1
- package/dist/components/FileDiff.js +143 -89
- package/dist/components/FileDiff.js.map +1 -1
- package/dist/components/FileStream.d.ts +4 -1
- package/dist/components/FileStream.d.ts.map +1 -1
- package/dist/components/FileStream.js +27 -12
- package/dist/components/FileStream.js.map +1 -1
- package/dist/components/UnresolvedFile.js +6 -42
- package/dist/components/UnresolvedFile.js.map +1 -1
- package/dist/components/VirtulizerDevelopment.d.ts.map +1 -1
- package/dist/constants.d.ts +3 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +3 -1
- package/dist/constants.js.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.js +4 -4
- package/dist/react/File.d.ts +3 -1
- package/dist/react/File.d.ts.map +1 -1
- package/dist/react/File.js +5 -2
- package/dist/react/File.js.map +1 -1
- package/dist/react/FileDiff.d.ts +4 -1
- package/dist/react/FileDiff.d.ts.map +1 -1
- package/dist/react/FileDiff.js +5 -2
- package/dist/react/FileDiff.js.map +1 -1
- package/dist/react/MultiFileDiff.d.ts +4 -1
- package/dist/react/MultiFileDiff.d.ts.map +1 -1
- package/dist/react/MultiFileDiff.js +12 -6
- package/dist/react/MultiFileDiff.js.map +1 -1
- package/dist/react/PatchDiff.d.ts +4 -1
- package/dist/react/PatchDiff.d.ts.map +1 -1
- package/dist/react/PatchDiff.js +5 -2
- package/dist/react/PatchDiff.js.map +1 -1
- package/dist/react/UnresolvedFile.d.ts +4 -1
- package/dist/react/UnresolvedFile.d.ts.map +1 -1
- package/dist/react/UnresolvedFile.js +5 -2
- package/dist/react/UnresolvedFile.js.map +1 -1
- package/dist/react/WorkerPoolContext.js +7 -5
- package/dist/react/WorkerPoolContext.js.map +1 -1
- package/dist/react/index.d.ts +2 -2
- package/dist/react/jsx.d.ts.map +1 -1
- package/dist/react/types.d.ts +6 -3
- package/dist/react/types.d.ts.map +1 -1
- package/dist/react/utils/renderDiffChildren.d.ts +4 -6
- package/dist/react/utils/renderDiffChildren.d.ts.map +1 -1
- package/dist/react/utils/renderDiffChildren.js +12 -17
- package/dist/react/utils/renderDiffChildren.js.map +1 -1
- package/dist/react/utils/renderFileChildren.d.ts +2 -0
- package/dist/react/utils/renderFileChildren.d.ts.map +1 -1
- package/dist/react/utils/renderFileChildren.js +9 -6
- package/dist/react/utils/renderFileChildren.js.map +1 -1
- package/dist/react/utils/useFileDiffInstance.d.ts +7 -7
- package/dist/react/utils/useFileDiffInstance.d.ts.map +1 -1
- package/dist/react/utils/useFileDiffInstance.js +20 -11
- package/dist/react/utils/useFileDiffInstance.js.map +1 -1
- package/dist/react/utils/useFileInstance.d.ts +5 -1
- package/dist/react/utils/useFileInstance.d.ts.map +1 -1
- package/dist/react/utils/useFileInstance.js +20 -7
- package/dist/react/utils/useFileInstance.js.map +1 -1
- package/dist/react/utils/useUnresolvedFileInstance.d.ts +5 -1
- package/dist/react/utils/useUnresolvedFileInstance.d.ts.map +1 -1
- package/dist/react/utils/useUnresolvedFileInstance.js +17 -4
- package/dist/react/utils/useUnresolvedFileInstance.js.map +1 -1
- package/dist/renderers/DiffHunksRenderer.d.ts +14 -9
- package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
- package/dist/renderers/DiffHunksRenderer.js +13 -21
- package/dist/renderers/DiffHunksRenderer.js.map +1 -1
- package/dist/renderers/FileRenderer.d.ts +5 -4
- package/dist/renderers/FileRenderer.d.ts.map +1 -1
- package/dist/renderers/FileRenderer.js +11 -19
- package/dist/renderers/FileRenderer.js.map +1 -1
- package/dist/renderers/UnresolvedFileHunksRenderer.d.ts +5 -5
- package/dist/renderers/UnresolvedFileHunksRenderer.d.ts.map +1 -1
- package/dist/renderers/UnresolvedFileHunksRenderer.js +2 -2
- package/dist/renderers/UnresolvedFileHunksRenderer.js.map +1 -1
- package/dist/ssr/index.d.ts +2 -2
- package/dist/ssr/preloadDiffs.js +7 -4
- package/dist/ssr/preloadDiffs.js.map +1 -1
- package/dist/ssr/preloadFile.js +7 -2
- package/dist/ssr/preloadFile.js.map +1 -1
- package/dist/style.js +1 -1
- package/dist/style.js.map +1 -1
- package/dist/types.d.ts +11 -11
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/arePrePropertiesEqual.js +1 -1
- package/dist/utils/arePrePropertiesEqual.js.map +1 -1
- package/dist/utils/createFileHeaderElement.d.ts +3 -5
- package/dist/utils/createFileHeaderElement.d.ts.map +1 -1
- package/dist/utils/createFileHeaderElement.js +17 -10
- package/dist/utils/createFileHeaderElement.js.map +1 -1
- package/dist/utils/createPreElement.d.ts +0 -2
- package/dist/utils/createPreElement.d.ts.map +1 -1
- package/dist/utils/createPreElement.js +4 -7
- package/dist/utils/createPreElement.js.map +1 -1
- package/dist/utils/createStyleElement.d.ts +2 -1
- package/dist/utils/createStyleElement.d.ts.map +1 -1
- package/dist/utils/createStyleElement.js +9 -2
- package/dist/utils/createStyleElement.js.map +1 -1
- package/dist/utils/cssWrappers.d.ts +4 -1
- package/dist/utils/cssWrappers.d.ts.map +1 -1
- package/dist/utils/cssWrappers.js +11 -2
- package/dist/utils/cssWrappers.js.map +1 -1
- package/dist/utils/hast_utils.d.ts +1 -1
- package/dist/utils/hast_utils.d.ts.map +1 -1
- package/dist/utils/hast_utils.js.map +1 -1
- package/dist/utils/hostTheme.d.ts +15 -0
- package/dist/utils/hostTheme.d.ts.map +1 -0
- package/dist/utils/hostTheme.js +22 -0
- package/dist/utils/hostTheme.js.map +1 -0
- package/dist/utils/isDiffPlainText.d.ts +7 -0
- package/dist/utils/isDiffPlainText.d.ts.map +1 -0
- package/dist/utils/isDiffPlainText.js +12 -0
- package/dist/utils/isDiffPlainText.js.map +1 -0
- package/dist/utils/isFilePlainText.d.ts +7 -0
- package/dist/utils/isFilePlainText.d.ts.map +1 -0
- package/dist/utils/isFilePlainText.js +10 -0
- package/dist/utils/isFilePlainText.js.map +1 -0
- package/dist/utils/parsePatchFiles.js +1 -1
- package/dist/utils/parsePatchFiles.js.map +1 -1
- package/dist/utils/renderDiffWithHighlighter.js +1 -4
- package/dist/utils/renderDiffWithHighlighter.js.map +1 -1
- package/dist/utils/renderFileWithHighlighter.js +1 -3
- package/dist/utils/renderFileWithHighlighter.js.map +1 -1
- package/dist/utils/setWrapperNodeProps.d.ts +0 -2
- package/dist/utils/setWrapperNodeProps.d.ts.map +1 -1
- package/dist/utils/setWrapperNodeProps.js +1 -4
- package/dist/utils/setWrapperNodeProps.js.map +1 -1
- package/dist/worker/WorkerPoolManager.js +4 -2
- package/dist/worker/WorkerPoolManager.js.map +1 -1
- package/dist/worker/worker-portable.js +4 -13
- package/dist/worker/worker-portable.js.map +1 -1
- package/dist/worker/worker.js +2 -7
- package/dist/worker/worker.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DEFAULT_THEMES, DIFFS_TAG_NAME, EMPTY_RENDER_RANGE, HEADER_METADATA_SLOT_ID, HEADER_PREFIX_SLOT_ID, UNSAFE_CSS_ATTRIBUTE } from "../constants.js";
|
|
1
|
+
import { CUSTOM_HEADER_SLOT_ID, DEFAULT_THEMES, DIFFS_TAG_NAME, EMPTY_RENDER_RANGE, HEADER_METADATA_SLOT_ID, HEADER_PREFIX_SLOT_ID, THEME_CSS_ATTRIBUTE, UNSAFE_CSS_ATTRIBUTE } from "../constants.js";
|
|
2
2
|
import { InteractionManager, pluckInteractionOptions } from "../managers/InteractionManager.js";
|
|
3
3
|
import { ResizeManager } from "../managers/ResizeManager.js";
|
|
4
4
|
import { areRenderRangesEqual } from "../utils/areRenderRangesEqual.js";
|
|
@@ -9,8 +9,9 @@ import { arePrePropertiesEqual } from "../utils/arePrePropertiesEqual.js";
|
|
|
9
9
|
import { createAnnotationWrapperNode } from "../utils/createAnnotationWrapperNode.js";
|
|
10
10
|
import { createGutterUtilityContentNode } from "../utils/createGutterUtilityContentNode.js";
|
|
11
11
|
import { createUnsafeCSSStyleNode } from "../utils/createUnsafeCSSStyleNode.js";
|
|
12
|
-
import { wrapUnsafeCSS } from "../utils/cssWrappers.js";
|
|
12
|
+
import { wrapThemeCSS, wrapUnsafeCSS } from "../utils/cssWrappers.js";
|
|
13
13
|
import { getOrCreateCodeNode } from "../utils/getOrCreateCodeNode.js";
|
|
14
|
+
import { upsertHostThemeStyle } from "../utils/hostTheme.js";
|
|
14
15
|
import { prerenderHTMLIfNecessary } from "../utils/prerenderHTMLIfNecessary.js";
|
|
15
16
|
import { setPreNodeProperties } from "../utils/setWrapperNodeProps.js";
|
|
16
17
|
import { DiffsContainerLoaded } from "./web-components.js";
|
|
@@ -34,11 +35,15 @@ var FileDiff = class {
|
|
|
34
35
|
codeAdditions;
|
|
35
36
|
bufferBefore;
|
|
36
37
|
bufferAfter;
|
|
38
|
+
themeCSSStyle;
|
|
39
|
+
appliedThemeCSS;
|
|
37
40
|
unsafeCSSStyle;
|
|
41
|
+
appliedUnsafeCSS;
|
|
38
42
|
gutterUtilityContent;
|
|
39
43
|
headerElement;
|
|
40
44
|
headerPrefix;
|
|
41
45
|
headerMetadata;
|
|
46
|
+
headerCustom;
|
|
42
47
|
separatorCache = /* @__PURE__ */ new Map();
|
|
43
48
|
errorWrapper;
|
|
44
49
|
placeHolder;
|
|
@@ -73,6 +78,7 @@ var FileDiff = class {
|
|
|
73
78
|
getHunksRendererOptions(options) {
|
|
74
79
|
return {
|
|
75
80
|
...options,
|
|
81
|
+
headerRenderMode: options.renderCustomHeader != null ? "custom" : "default",
|
|
76
82
|
hunkSeparators: typeof options.hunkSeparators === "function" ? "custom" : options.hunkSeparators
|
|
77
83
|
};
|
|
78
84
|
}
|
|
@@ -147,18 +153,8 @@ var FileDiff = class {
|
|
|
147
153
|
setThemeType(themeType) {
|
|
148
154
|
if ((this.options.themeType ?? "system") === themeType) return;
|
|
149
155
|
this.mergeOptions({ themeType });
|
|
150
|
-
this.
|
|
151
|
-
|
|
152
|
-
else this.headerElement.dataset.themeType = themeType;
|
|
153
|
-
if (this.pre != null) switch (themeType) {
|
|
154
|
-
case "system":
|
|
155
|
-
delete this.pre.dataset.themeType;
|
|
156
|
-
break;
|
|
157
|
-
case "light":
|
|
158
|
-
case "dark":
|
|
159
|
-
this.pre.dataset.themeType = themeType;
|
|
160
|
-
break;
|
|
161
|
-
}
|
|
156
|
+
if (typeof this.options.theme === "string" || this.fileContainer == null || this.appliedThemeCSS == null) return;
|
|
157
|
+
this.applyThemeState(this.fileContainer, this.appliedThemeCSS.themeStyles, themeType, this.appliedThemeCSS.baseThemeType);
|
|
162
158
|
}
|
|
163
159
|
getHoveredLine = () => {
|
|
164
160
|
return this.interactionManager.getHoveredLine();
|
|
@@ -195,10 +191,15 @@ var FileDiff = class {
|
|
|
195
191
|
this.headerElement = void 0;
|
|
196
192
|
this.headerPrefix = void 0;
|
|
197
193
|
this.headerMetadata = void 0;
|
|
194
|
+
this.headerCustom = void 0;
|
|
198
195
|
this.lastRenderedHeaderHTML = void 0;
|
|
199
196
|
this.errorWrapper = void 0;
|
|
200
197
|
this.spriteSVG = void 0;
|
|
201
198
|
this.lastRowCount = void 0;
|
|
199
|
+
this.themeCSSStyle = void 0;
|
|
200
|
+
this.appliedThemeCSS = void 0;
|
|
201
|
+
this.unsafeCSSStyle = void 0;
|
|
202
|
+
this.appliedUnsafeCSS = void 0;
|
|
202
203
|
if (recycle) this.hunksRenderer.recycle();
|
|
203
204
|
else {
|
|
204
205
|
this.hunksRenderer.cleanUp();
|
|
@@ -214,8 +215,21 @@ var FileDiff = class {
|
|
|
214
215
|
this.workerManager?.subscribeToThemeChanges(this);
|
|
215
216
|
}
|
|
216
217
|
hydrate(props) {
|
|
217
|
-
const {
|
|
218
|
-
|
|
218
|
+
const { fileContainer, prerenderedHTML, preventEmit = false, lineAnnotations, oldFile, newFile, fileDiff } = props;
|
|
219
|
+
this.hydrateElements(fileContainer, prerenderedHTML);
|
|
220
|
+
if (this.pre == null && this.headerElement == null) this.render({
|
|
221
|
+
...props,
|
|
222
|
+
preventEmit: true
|
|
223
|
+
});
|
|
224
|
+
else this.hydrationSetup({
|
|
225
|
+
fileDiff,
|
|
226
|
+
oldFile,
|
|
227
|
+
newFile,
|
|
228
|
+
lineAnnotations
|
|
229
|
+
});
|
|
230
|
+
if (!preventEmit) this.emitPostRender();
|
|
231
|
+
}
|
|
232
|
+
hydrateElements(fileContainer, prerenderedHTML) {
|
|
219
233
|
prerenderHTMLIfNecessary(fileContainer, prerenderedHTML);
|
|
220
234
|
for (const element of fileContainer.shadowRoot?.children ?? []) {
|
|
221
235
|
if (element instanceof SVGElement) {
|
|
@@ -237,33 +251,36 @@ var FileDiff = class {
|
|
|
237
251
|
this.headerElement = element;
|
|
238
252
|
continue;
|
|
239
253
|
}
|
|
254
|
+
if (element instanceof HTMLStyleElement && element.hasAttribute(THEME_CSS_ATTRIBUTE)) {
|
|
255
|
+
this.themeCSSStyle = element;
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
240
258
|
if (element instanceof HTMLStyleElement && element.hasAttribute(UNSAFE_CSS_ATTRIBUTE)) {
|
|
241
259
|
this.unsafeCSSStyle = element;
|
|
260
|
+
this.appliedUnsafeCSS = element.textContent;
|
|
242
261
|
continue;
|
|
243
262
|
}
|
|
244
263
|
}
|
|
245
|
-
if (this.pre != null)
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
preventEmit: true
|
|
249
|
-
});
|
|
250
|
-
else {
|
|
251
|
-
const { lineAnnotations, oldFile, newFile, fileDiff } = props;
|
|
252
|
-
this.fileContainer = fileContainer;
|
|
253
|
-
delete this.pre.dataset.dehydrated;
|
|
254
|
-
this.lineAnnotations = lineAnnotations ?? this.lineAnnotations;
|
|
255
|
-
this.additionFile = newFile;
|
|
256
|
-
this.deletionFile = oldFile;
|
|
257
|
-
this.fileDiff = fileDiff ?? (oldFile != null && newFile != null ? parseDiffFromFile(oldFile, newFile) : void 0);
|
|
258
|
-
this.hunksRenderer.hydrate(this.fileDiff);
|
|
259
|
-
this.renderAnnotations();
|
|
260
|
-
this.renderGutterUtility();
|
|
261
|
-
this.injectUnsafeCSS();
|
|
262
|
-
this.interactionManager.setup(this.pre);
|
|
263
|
-
this.resizeManager.setup(this.pre, overflow === "wrap");
|
|
264
|
-
if (overflow === "scroll" && diffStyle === "split") this.scrollSyncManager.setup(this.pre, this.codeDeletions, this.codeAdditions);
|
|
264
|
+
if (this.pre != null) {
|
|
265
|
+
this.syncCodeNodesFromPre(this.pre);
|
|
266
|
+
this.pre.removeAttribute("data-dehydrated");
|
|
265
267
|
}
|
|
266
|
-
|
|
268
|
+
this.fileContainer = fileContainer;
|
|
269
|
+
}
|
|
270
|
+
hydrationSetup({ fileDiff, oldFile, newFile, lineAnnotations }) {
|
|
271
|
+
const { diffStyle = "split", overflow = "scroll" } = this.options;
|
|
272
|
+
this.lineAnnotations = lineAnnotations ?? this.lineAnnotations;
|
|
273
|
+
this.additionFile = newFile;
|
|
274
|
+
this.deletionFile = oldFile;
|
|
275
|
+
this.fileDiff = fileDiff ?? (oldFile != null && newFile != null ? parseDiffFromFile(oldFile, newFile) : void 0);
|
|
276
|
+
if (this.pre == null) return;
|
|
277
|
+
this.hunksRenderer.hydrate(this.fileDiff);
|
|
278
|
+
this.renderAnnotations();
|
|
279
|
+
this.renderGutterUtility();
|
|
280
|
+
this.injectUnsafeCSS();
|
|
281
|
+
this.interactionManager.setup(this.pre);
|
|
282
|
+
this.resizeManager.setup(this.pre, overflow === "wrap");
|
|
283
|
+
if (overflow === "scroll" && diffStyle === "split") this.scrollSyncManager.setup(this.pre, this.codeDeletions, this.codeAdditions);
|
|
267
284
|
}
|
|
268
285
|
rerender() {
|
|
269
286
|
if (!this.enabled || this.fileDiff == null && this.additionFile == null && this.deletionFile == null) return;
|
|
@@ -298,26 +315,16 @@ var FileDiff = class {
|
|
|
298
315
|
}
|
|
299
316
|
if (lineAnnotations != null) this.setLineAnnotations(lineAnnotations);
|
|
300
317
|
if (this.fileDiff == null) return false;
|
|
301
|
-
this.hunksRenderer.setOptions(
|
|
302
|
-
...this.options,
|
|
303
|
-
hunkSeparators: typeof this.options.hunkSeparators === "function" ? "custom" : this.options.hunkSeparators
|
|
304
|
-
});
|
|
318
|
+
this.hunksRenderer.setOptions(this.getHunksRendererOptions(this.options));
|
|
305
319
|
this.hunksRenderer.setLineAnnotations(this.lineAnnotations);
|
|
306
|
-
const { diffStyle = "split", disableErrorHandling = false, disableFileHeader = false, overflow = "scroll" } = this.options;
|
|
320
|
+
const { diffStyle = "split", disableErrorHandling = false, disableFileHeader = false, overflow = "scroll", themeType = "system" } = this.options;
|
|
307
321
|
if (disableFileHeader) {
|
|
308
322
|
if (this.headerElement != null) {
|
|
309
323
|
this.headerElement.remove();
|
|
310
324
|
this.headerElement = void 0;
|
|
311
325
|
this.lastRenderedHeaderHTML = void 0;
|
|
312
326
|
}
|
|
313
|
-
|
|
314
|
-
this.headerPrefix.remove();
|
|
315
|
-
this.headerPrefix = void 0;
|
|
316
|
-
}
|
|
317
|
-
if (this.headerMetadata != null) {
|
|
318
|
-
this.headerMetadata.remove();
|
|
319
|
-
this.headerMetadata = void 0;
|
|
320
|
-
}
|
|
327
|
+
this.clearHeaderSlots();
|
|
321
328
|
}
|
|
322
329
|
fileContainer = this.getOrCreateFileContainer(fileContainer, containerWrapper);
|
|
323
330
|
if (collapsed) {
|
|
@@ -325,6 +332,7 @@ var FileDiff = class {
|
|
|
325
332
|
this.clearAuxiliaryNodes();
|
|
326
333
|
try {
|
|
327
334
|
const hunksResult = this.hunksRenderer.renderDiff(this.fileDiff, EMPTY_RENDER_RANGE);
|
|
335
|
+
if (hunksResult != null) this.applyThemeState(fileContainer, hunksResult.themeStyles, themeType, hunksResult.baseThemeType);
|
|
328
336
|
if (hunksResult?.headerElement != null) this.applyHeaderToDOM(hunksResult.headerElement, fileContainer);
|
|
329
337
|
this.renderSeparators([]);
|
|
330
338
|
this.injectUnsafeCSS();
|
|
@@ -347,6 +355,7 @@ var FileDiff = class {
|
|
|
347
355
|
if (this.workerManager?.isInitialized() === false) this.workerManager.initialize().then(() => this.rerender());
|
|
348
356
|
return false;
|
|
349
357
|
}
|
|
358
|
+
this.applyThemeState(fileContainer, hunksResult.themeStyles, themeType, hunksResult.baseThemeType);
|
|
350
359
|
if (hunksResult.headerElement != null) this.applyHeaderToDOM(hunksResult.headerElement, fileContainer);
|
|
351
360
|
if (hunksResult.additionsContentAST != null || hunksResult.deletionsContentAST != null || hunksResult.unifiedContentAST != null) this.applyHunksToDOM(pre, hunksResult);
|
|
352
361
|
else if (this.pre != null) {
|
|
@@ -427,8 +436,10 @@ var FileDiff = class {
|
|
|
427
436
|
this.gutterUtilityContent?.remove();
|
|
428
437
|
this.headerPrefix?.remove();
|
|
429
438
|
this.headerMetadata?.remove();
|
|
439
|
+
this.headerCustom?.remove();
|
|
430
440
|
this.pre?.remove();
|
|
431
441
|
this.spriteSVG?.remove();
|
|
442
|
+
this.themeCSSStyle?.remove();
|
|
432
443
|
this.unsafeCSSStyle?.remove();
|
|
433
444
|
this.bufferAfter = void 0;
|
|
434
445
|
this.bufferBefore = void 0;
|
|
@@ -440,9 +451,13 @@ var FileDiff = class {
|
|
|
440
451
|
this.gutterUtilityContent = void 0;
|
|
441
452
|
this.headerPrefix = void 0;
|
|
442
453
|
this.headerMetadata = void 0;
|
|
454
|
+
this.headerCustom = void 0;
|
|
443
455
|
this.pre = void 0;
|
|
444
456
|
this.spriteSVG = void 0;
|
|
457
|
+
this.themeCSSStyle = void 0;
|
|
458
|
+
this.appliedThemeCSS = void 0;
|
|
445
459
|
this.unsafeCSSStyle = void 0;
|
|
460
|
+
this.appliedUnsafeCSS = void 0;
|
|
446
461
|
this.lastRenderedHeaderHTML = void 0;
|
|
447
462
|
this.lastRowCount = void 0;
|
|
448
463
|
}
|
|
@@ -572,15 +587,16 @@ var FileDiff = class {
|
|
|
572
587
|
this.codeAdditions = void 0;
|
|
573
588
|
for (const child of Array.from(pre.children)) {
|
|
574
589
|
if (!(child instanceof HTMLElement)) continue;
|
|
575
|
-
if ("unified"
|
|
576
|
-
else if ("deletions"
|
|
577
|
-
else if ("additions"
|
|
590
|
+
if (child.hasAttribute("data-unified")) this.codeUnified = child;
|
|
591
|
+
else if (child.hasAttribute("data-deletions")) this.codeDeletions = child;
|
|
592
|
+
else if (child.hasAttribute("data-additions")) this.codeAdditions = child;
|
|
578
593
|
}
|
|
579
594
|
}
|
|
580
595
|
applyHeaderToDOM(headerAST, container) {
|
|
581
596
|
this.cleanupErrorWrapper();
|
|
582
597
|
this.placeHolder?.remove();
|
|
583
598
|
this.placeHolder = void 0;
|
|
599
|
+
const { fileDiff } = this;
|
|
584
600
|
const headerHTML = toHtml(headerAST);
|
|
585
601
|
if (headerHTML !== this.lastRenderedHeaderHTML) {
|
|
586
602
|
const tempDiv = document.createElement("div");
|
|
@@ -592,44 +608,84 @@ var FileDiff = class {
|
|
|
592
608
|
this.headerElement = newHeader;
|
|
593
609
|
this.lastRenderedHeaderHTML = headerHTML;
|
|
594
610
|
}
|
|
595
|
-
if (this.isContainerManaged) return;
|
|
596
|
-
const { renderHeaderPrefix, renderHeaderMetadata } = this.options;
|
|
597
|
-
if (
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
deletionFile: this.deletionFile,
|
|
606
|
-
additionFile: this.additionFile,
|
|
607
|
-
fileDiff: this.fileDiff
|
|
608
|
-
}) ?? void 0;
|
|
609
|
-
if (prefix != null) {
|
|
610
|
-
this.headerPrefix = document.createElement("div");
|
|
611
|
-
this.headerPrefix.slot = HEADER_PREFIX_SLOT_ID;
|
|
612
|
-
if (prefix instanceof Element) this.headerPrefix.appendChild(prefix);
|
|
613
|
-
else this.headerPrefix.innerText = `${prefix}`;
|
|
614
|
-
container.appendChild(this.headerPrefix);
|
|
611
|
+
if (this.isContainerManaged || fileDiff == null) return;
|
|
612
|
+
const { renderCustomHeader, renderHeaderPrefix, renderHeaderMetadata } = this.options;
|
|
613
|
+
if (renderCustomHeader != null) {
|
|
614
|
+
const content$1 = renderCustomHeader(fileDiff) ?? void 0;
|
|
615
|
+
this.headerCustom = this.upsertHeaderSlotElement(container, this.headerCustom, CUSTOM_HEADER_SLOT_ID, content$1);
|
|
616
|
+
this.headerPrefix?.remove();
|
|
617
|
+
this.headerMetadata?.remove();
|
|
618
|
+
this.headerPrefix = void 0;
|
|
619
|
+
this.headerMetadata = void 0;
|
|
620
|
+
return;
|
|
615
621
|
}
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
+
const prefix = renderHeaderPrefix?.(fileDiff) ?? void 0;
|
|
623
|
+
const content = renderHeaderMetadata?.(fileDiff) ?? void 0;
|
|
624
|
+
this.headerPrefix = this.upsertHeaderSlotElement(container, this.headerPrefix, HEADER_PREFIX_SLOT_ID, prefix);
|
|
625
|
+
this.headerMetadata = this.upsertHeaderSlotElement(container, this.headerMetadata, HEADER_METADATA_SLOT_ID, content);
|
|
626
|
+
this.headerCustom?.remove();
|
|
627
|
+
this.headerCustom = void 0;
|
|
628
|
+
}
|
|
629
|
+
clearHeaderSlots() {
|
|
630
|
+
this.headerPrefix?.remove();
|
|
631
|
+
this.headerMetadata?.remove();
|
|
632
|
+
this.headerCustom?.remove();
|
|
633
|
+
this.headerPrefix = void 0;
|
|
634
|
+
this.headerMetadata = void 0;
|
|
635
|
+
this.headerCustom = void 0;
|
|
636
|
+
}
|
|
637
|
+
upsertHeaderSlotElement(container, current, slot, content) {
|
|
638
|
+
if (content == null) {
|
|
639
|
+
current?.remove();
|
|
640
|
+
return;
|
|
622
641
|
}
|
|
642
|
+
const element = current ?? this.createHeaderSlotElement(slot);
|
|
643
|
+
if (current == null) container.appendChild(element);
|
|
644
|
+
this.replaceHeaderSlotContent(element, content);
|
|
645
|
+
return element;
|
|
646
|
+
}
|
|
647
|
+
replaceHeaderSlotContent(element, content) {
|
|
648
|
+
element.replaceChildren();
|
|
649
|
+
if (content instanceof Element) element.appendChild(content);
|
|
650
|
+
else element.innerText = `${content}`;
|
|
651
|
+
}
|
|
652
|
+
createHeaderSlotElement(slot) {
|
|
653
|
+
const element = document.createElement("div");
|
|
654
|
+
element.slot = slot;
|
|
655
|
+
return element;
|
|
623
656
|
}
|
|
624
657
|
injectUnsafeCSS() {
|
|
625
|
-
if (this.fileContainer?.shadowRoot == null) return;
|
|
626
658
|
const { unsafeCSS } = this.options;
|
|
627
|
-
|
|
628
|
-
if (
|
|
629
|
-
|
|
630
|
-
|
|
659
|
+
const shadowRoot = this.fileContainer?.shadowRoot;
|
|
660
|
+
if (shadowRoot == null) return;
|
|
661
|
+
if (unsafeCSS == null || unsafeCSS === "") {
|
|
662
|
+
if (this.unsafeCSSStyle != null) {
|
|
663
|
+
this.unsafeCSSStyle.remove();
|
|
664
|
+
this.unsafeCSSStyle = void 0;
|
|
665
|
+
}
|
|
666
|
+
this.appliedUnsafeCSS = void 0;
|
|
667
|
+
return;
|
|
631
668
|
}
|
|
632
|
-
this.unsafeCSSStyle.
|
|
669
|
+
if (this.unsafeCSSStyle?.parentNode === shadowRoot && this.appliedUnsafeCSS === unsafeCSS) return;
|
|
670
|
+
this.unsafeCSSStyle ??= createUnsafeCSSStyleNode();
|
|
671
|
+
if (this.unsafeCSSStyle.parentNode !== shadowRoot) shadowRoot.appendChild(this.unsafeCSSStyle);
|
|
672
|
+
this.unsafeCSSStyle.textContent = wrapUnsafeCSS(unsafeCSS);
|
|
673
|
+
this.appliedUnsafeCSS = unsafeCSS;
|
|
674
|
+
}
|
|
675
|
+
applyThemeState(container, themeStyles, themeType, baseThemeType) {
|
|
676
|
+
const shadowRoot = container.shadowRoot ?? container.attachShadow({ mode: "open" });
|
|
677
|
+
const effectiveThemeType = baseThemeType ?? themeType;
|
|
678
|
+
if (this.themeCSSStyle?.parentNode === shadowRoot && this.appliedThemeCSS?.themeStyles === themeStyles && this.appliedThemeCSS.themeType === effectiveThemeType) return;
|
|
679
|
+
this.themeCSSStyle = upsertHostThemeStyle({
|
|
680
|
+
shadowRoot,
|
|
681
|
+
currentNode: this.themeCSSStyle,
|
|
682
|
+
themeCSS: wrapThemeCSS(themeStyles, effectiveThemeType)
|
|
683
|
+
});
|
|
684
|
+
this.appliedThemeCSS = this.themeCSSStyle != null ? {
|
|
685
|
+
themeStyles,
|
|
686
|
+
themeType: effectiveThemeType,
|
|
687
|
+
baseThemeType
|
|
688
|
+
} : void 0;
|
|
633
689
|
}
|
|
634
690
|
applyHunksToDOM(pre, result) {
|
|
635
691
|
const { overflow = "scroll" } = this.options;
|
|
@@ -1003,8 +1059,8 @@ var FileDiff = class {
|
|
|
1003
1059
|
this.bufferAfter = void 0;
|
|
1004
1060
|
}
|
|
1005
1061
|
}
|
|
1006
|
-
applyPreNodeAttributes(pre, {
|
|
1007
|
-
const { diffIndicators = "bars", disableBackground = false, disableLineNumbers = false, overflow = "scroll",
|
|
1062
|
+
applyPreNodeAttributes(pre, { additionsContentAST, deletionsContentAST, totalLines }, customProperties) {
|
|
1063
|
+
const { diffIndicators = "bars", disableBackground = false, disableLineNumbers = false, overflow = "scroll", diffStyle = "split" } = this.options;
|
|
1008
1064
|
const preProperties = {
|
|
1009
1065
|
type: "diff",
|
|
1010
1066
|
diffIndicators,
|
|
@@ -1012,8 +1068,6 @@ var FileDiff = class {
|
|
|
1012
1068
|
disableLineNumbers,
|
|
1013
1069
|
overflow,
|
|
1014
1070
|
split: diffStyle === "unified" ? false : additionsContentAST != null && deletionsContentAST != null,
|
|
1015
|
-
themeStyles,
|
|
1016
|
-
themeType: baseThemeType ?? themeType,
|
|
1017
1071
|
totalLines,
|
|
1018
1072
|
customProperties
|
|
1019
1073
|
};
|