@pierre/diffs 1.3.0-rc.4 → 1.3.1
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/File.d.ts +3 -1
- package/dist/components/File.d.ts.map +1 -1
- package/dist/components/File.js +39 -20
- package/dist/components/File.js.map +1 -1
- package/dist/components/FileDiff.d.ts +6 -1
- package/dist/components/FileDiff.d.ts.map +1 -1
- package/dist/components/FileDiff.js +63 -25
- package/dist/components/FileDiff.js.map +1 -1
- package/dist/components/VirtualizedFile.d.ts +2 -1
- package/dist/components/VirtualizedFile.d.ts.map +1 -1
- package/dist/components/VirtualizedFile.js +27 -18
- package/dist/components/VirtualizedFile.js.map +1 -1
- package/dist/components/VirtualizedFileDiff.d.ts +1 -0
- package/dist/components/VirtualizedFileDiff.d.ts.map +1 -1
- package/dist/components/VirtualizedFileDiff.js +7 -1
- package/dist/components/VirtualizedFileDiff.js.map +1 -1
- package/dist/edit/index.d.ts +3 -3
- package/dist/editor/command.js +2 -1
- package/dist/editor/command.js.map +1 -1
- package/dist/editor/editStack.d.ts +2 -2
- package/dist/editor/editStack.d.ts.map +1 -1
- package/dist/editor/editStack.js.map +1 -1
- package/dist/editor/editor.d.ts +2 -2
- package/dist/editor/editor.d.ts.map +1 -1
- package/dist/editor/editor.js +28 -9
- package/dist/editor/editor.js.map +1 -1
- package/dist/editor/pieceTable.d.ts +1 -2
- package/dist/editor/pieceTable.d.ts.map +1 -1
- package/dist/editor/pieceTable.js.map +1 -1
- package/dist/editor/platform.d.ts +3 -11
- package/dist/editor/platform.d.ts.map +1 -1
- package/dist/editor/platform.js +2 -28
- package/dist/editor/platform.js.map +1 -1
- package/dist/editor/searchPanel.d.ts +2 -1
- package/dist/editor/searchPanel.d.ts.map +1 -1
- package/dist/editor/searchPanel.js.map +1 -1
- package/dist/editor/selection.d.ts +2 -2
- package/dist/editor/selection.d.ts.map +1 -1
- package/dist/editor/selection.js.map +1 -1
- package/dist/editor/textDocument.d.ts +4 -14
- package/dist/editor/textDocument.d.ts.map +1 -1
- package/dist/editor/textDocument.js +7 -0
- package/dist/editor/textDocument.js.map +1 -1
- package/dist/editor/tokenizer.d.ts.map +1 -1
- package/dist/editor/tokenizer.js +8 -2
- package/dist/editor/tokenizer.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/react/index.d.ts +2 -2
- package/dist/renderers/DiffHunksRenderer.d.ts +2 -1
- package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
- package/dist/renderers/DiffHunksRenderer.js +7 -0
- package/dist/renderers/DiffHunksRenderer.js.map +1 -1
- package/dist/renderers/FileRenderer.d.ts +1 -0
- package/dist/renderers/FileRenderer.d.ts.map +1 -1
- package/dist/renderers/FileRenderer.js +7 -0
- package/dist/renderers/FileRenderer.js.map +1 -1
- package/dist/ssr/index.d.ts +2 -2
- package/dist/types.d.ts +27 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/guardWebKitScrollDuringRebuild.d.ts +20 -0
- package/dist/utils/guardWebKitScrollDuringRebuild.d.ts.map +1 -0
- package/dist/utils/guardWebKitScrollDuringRebuild.js +34 -0
- package/dist/utils/guardWebKitScrollDuringRebuild.js.map +1 -0
- package/dist/utils/platform.d.ts +14 -0
- package/dist/utils/platform.d.ts.map +1 -0
- package/dist/utils/platform.js +32 -0
- package/dist/utils/platform.js.map +1 -0
- package/package.json +4 -5
|
@@ -19,7 +19,9 @@ import { createUnsafeCSSStyleNode } from "../utils/createUnsafeCSSStyleNode.js";
|
|
|
19
19
|
import { getMeasuredScrollbarGutter } from "../utils/scrollbarGutter.js";
|
|
20
20
|
import { patchScrollbarGutterSize, wrapThemeCSS, wrapUnsafeCSS } from "../utils/cssWrappers.js";
|
|
21
21
|
import { getOrCreateCodeNode } from "../utils/getOrCreateCodeNode.js";
|
|
22
|
+
import { guardWebKitScrollDuringRebuild } from "../utils/guardWebKitScrollDuringRebuild.js";
|
|
22
23
|
import { upsertHostThemeStyle } from "../utils/hostTheme.js";
|
|
24
|
+
import { isSafari } from "../utils/platform.js";
|
|
23
25
|
import { prerenderHTMLIfNecessary } from "../utils/prerenderHTMLIfNecessary.js";
|
|
24
26
|
import { setPreNodeProperties } from "../utils/setWrapperNodeProps.js";
|
|
25
27
|
import "./web-components.js";
|
|
@@ -254,6 +256,12 @@ var FileDiff = class {
|
|
|
254
256
|
if (this.codeAdditions != null) this.codeAdditions.scrollLeft = position;
|
|
255
257
|
if (this.codeDeletions != null) this.codeDeletions.scrollLeft = position;
|
|
256
258
|
}
|
|
259
|
+
__getEffectiveCodeOptions() {
|
|
260
|
+
return {
|
|
261
|
+
...this.options,
|
|
262
|
+
...this.hunksRenderer.getEffectiveCodeOptions()
|
|
263
|
+
};
|
|
264
|
+
}
|
|
257
265
|
cleanUp(recycle = false) {
|
|
258
266
|
dequeueRender(this.handleEditSessionRender);
|
|
259
267
|
this.emitPostRender(true);
|
|
@@ -475,8 +483,13 @@ var FileDiff = class {
|
|
|
475
483
|
if (fileDiff == null && hasFileInput && (filesDidChange || this.fileDiff == null)) nextParsedFileDiff = parseDiffFromFile(fileInput.oldFile, fileInput.newFile, this.options.parseDiffOptions);
|
|
476
484
|
const { renderRange: previousRenderRange } = this;
|
|
477
485
|
this.renderRange = nextRenderRange;
|
|
478
|
-
|
|
479
|
-
|
|
486
|
+
if (hasFileInput) {
|
|
487
|
+
this.deletionFile = oldFile;
|
|
488
|
+
this.additionFile = newFile;
|
|
489
|
+
} else if (fileDiff != null) {
|
|
490
|
+
this.deletionFile = void 0;
|
|
491
|
+
this.additionFile = void 0;
|
|
492
|
+
}
|
|
480
493
|
if (fileDiff != null) this.fileDiff = fileDiff;
|
|
481
494
|
else if (nextParsedFileDiff != null) {
|
|
482
495
|
diffDidChange = true;
|
|
@@ -1130,7 +1143,28 @@ var FileDiff = class {
|
|
|
1130
1143
|
if (shadowRoot == null || this.themeCSSStyle == null) return;
|
|
1131
1144
|
this.themeCSSStyle.textContent = patchScrollbarGutterSize(this.themeCSSStyle.textContent ?? "", getMeasuredScrollbarGutter(shadowRoot));
|
|
1132
1145
|
}
|
|
1146
|
+
shouldGuardRebuildScroll() {
|
|
1147
|
+
return this.editor != null && isSafari();
|
|
1148
|
+
}
|
|
1133
1149
|
applyHunksToDOM(pre, result) {
|
|
1150
|
+
if (this.shouldGuardRebuildScroll()) guardWebKitScrollDuringRebuild(pre, () => this.replaceCodeColumns(pre, result));
|
|
1151
|
+
else this.replaceCodeColumns(pre, result);
|
|
1152
|
+
}
|
|
1153
|
+
applyCodeColumnsInPlace(code, ast, rowCount) {
|
|
1154
|
+
const columns = this.getColumnPair(code);
|
|
1155
|
+
if (columns == null) return false;
|
|
1156
|
+
const gutterChildren = getElementChildren(ast[0]);
|
|
1157
|
+
const contentChildren = getElementChildren(ast[1]);
|
|
1158
|
+
if (gutterChildren == null || contentChildren == null) return false;
|
|
1159
|
+
columns.gutter.innerHTML = toHtml(gutterChildren);
|
|
1160
|
+
columns.content.innerHTML = toHtml(contentChildren);
|
|
1161
|
+
if (rowCount !== this.lastRowCount) {
|
|
1162
|
+
columns.gutter.style.setProperty("grid-row", `span ${rowCount}`);
|
|
1163
|
+
columns.content.style.setProperty("grid-row", `span ${rowCount}`);
|
|
1164
|
+
}
|
|
1165
|
+
return true;
|
|
1166
|
+
}
|
|
1167
|
+
replaceCodeColumns(pre, result) {
|
|
1134
1168
|
const { overflow = "scroll" } = this.options;
|
|
1135
1169
|
const containerSize = (this.options.hunkSeparators ?? "line-info") === "line-info";
|
|
1136
1170
|
const rowSpan = overflow === "wrap" ? result.rowCount : void 0;
|
|
@@ -1154,7 +1188,7 @@ var FileDiff = class {
|
|
|
1154
1188
|
rowSpan,
|
|
1155
1189
|
containerSize
|
|
1156
1190
|
});
|
|
1157
|
-
this.codeUnified.innerHTML = this.hunksRenderer.renderPartialHTML(unifiedAST);
|
|
1191
|
+
if (!this.applyCodeColumnsInPlace(this.codeUnified, unifiedAST, result.rowCount)) this.codeUnified.innerHTML = this.hunksRenderer.renderPartialHTML(unifiedAST);
|
|
1158
1192
|
codeElements.push(this.codeUnified);
|
|
1159
1193
|
} else if (deletionsAST != null || additionsAST != null) {
|
|
1160
1194
|
if (deletionsAST != null) {
|
|
@@ -1167,7 +1201,7 @@ var FileDiff = class {
|
|
|
1167
1201
|
rowSpan,
|
|
1168
1202
|
containerSize
|
|
1169
1203
|
});
|
|
1170
|
-
this.codeDeletions.innerHTML = this.hunksRenderer.renderPartialHTML(deletionsAST);
|
|
1204
|
+
if (!this.applyCodeColumnsInPlace(this.codeDeletions, deletionsAST, result.rowCount)) this.codeDeletions.innerHTML = this.hunksRenderer.renderPartialHTML(deletionsAST);
|
|
1171
1205
|
codeElements.push(this.codeDeletions);
|
|
1172
1206
|
} else {
|
|
1173
1207
|
this.codeDeletions?.remove();
|
|
@@ -1183,7 +1217,7 @@ var FileDiff = class {
|
|
|
1183
1217
|
rowSpan,
|
|
1184
1218
|
containerSize
|
|
1185
1219
|
});
|
|
1186
|
-
this.codeAdditions.innerHTML = this.hunksRenderer.renderPartialHTML(additionsAST);
|
|
1220
|
+
if (!this.applyCodeColumnsInPlace(this.codeAdditions, additionsAST, result.rowCount)) this.codeAdditions.innerHTML = this.hunksRenderer.renderPartialHTML(additionsAST);
|
|
1187
1221
|
codeElements.push(this.codeAdditions);
|
|
1188
1222
|
} else {
|
|
1189
1223
|
this.codeAdditions?.remove();
|
|
@@ -1224,8 +1258,8 @@ var FileDiff = class {
|
|
|
1224
1258
|
overlapEnd,
|
|
1225
1259
|
diffStyle
|
|
1226
1260
|
});
|
|
1227
|
-
if (trimResult < 0) throw new Error("applyPartialRender: failed to trim to overlap");
|
|
1228
|
-
if (this.lastRowCount < trimResult) throw new Error("applyPartialRender: trimmed beyond DOM row count");
|
|
1261
|
+
if (trimResult < 0) throw new Error("FileDiff.applyPartialRender: failed to trim to overlap");
|
|
1262
|
+
if (this.lastRowCount < trimResult) throw new Error("FileDiff.applyPartialRender: trimmed beyond DOM row count");
|
|
1229
1263
|
let rowCount = this.lastRowCount - trimResult;
|
|
1230
1264
|
const renderChunk = (startingLine, totalLines) => {
|
|
1231
1265
|
if (totalLines <= 0 || this.fileDiff == null) return;
|
|
@@ -1296,11 +1330,15 @@ var FileDiff = class {
|
|
|
1296
1330
|
const ast = this.hunksRenderer.renderCodeAST("unified", hunksResult);
|
|
1297
1331
|
const gutterChildren = getElementChildren(ast?.[0]);
|
|
1298
1332
|
const contentChildren = getElementChildren(ast?.[1]);
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1333
|
+
const applyColumns = () => {
|
|
1334
|
+
for (const [el, astChildren] of [[columns.gutter, gutterChildren], [columns.content, contentChildren]]) if (astChildren != null) el.innerHTML = toHtml(astChildren);
|
|
1335
|
+
if (hunksResult.rowCount !== this.lastRowCount) {
|
|
1336
|
+
this.applyRowSpan("unified", columns, hunksResult.rowCount);
|
|
1337
|
+
this.lastRowCount = hunksResult.rowCount;
|
|
1338
|
+
}
|
|
1339
|
+
};
|
|
1340
|
+
if (this.shouldGuardRebuildScroll()) guardWebKitScrollDuringRebuild(this.pre, applyColumns);
|
|
1341
|
+
else applyColumns();
|
|
1304
1342
|
this.renderSeparators(hunksResult.hunkData);
|
|
1305
1343
|
this.managersDirty = true;
|
|
1306
1344
|
this.flushManagers();
|
|
@@ -1487,21 +1525,21 @@ var FileDiff = class {
|
|
|
1487
1525
|
element.style.setProperty("grid-row", `span ${size}`);
|
|
1488
1526
|
element.style.setProperty("min-height", `calc(${size} * 1lh)`);
|
|
1489
1527
|
}
|
|
1528
|
+
getColumnPair(code) {
|
|
1529
|
+
if (code == null) return;
|
|
1530
|
+
const gutter = code.children[0];
|
|
1531
|
+
const content = code.children[1];
|
|
1532
|
+
if (!(gutter instanceof HTMLElement) || !(content instanceof HTMLElement) || gutter.dataset.gutter == null || content.dataset.content == null) return;
|
|
1533
|
+
return {
|
|
1534
|
+
gutter,
|
|
1535
|
+
content
|
|
1536
|
+
};
|
|
1537
|
+
}
|
|
1490
1538
|
getCodeColumns(diffStyle, codeUnified, codeDeletions, codeAdditions) {
|
|
1491
|
-
|
|
1492
|
-
if (code == null) return;
|
|
1493
|
-
const gutter = code.children[0];
|
|
1494
|
-
const content = code.children[1];
|
|
1495
|
-
if (!(gutter instanceof HTMLElement) || !(content instanceof HTMLElement) || gutter.dataset.gutter == null || content.dataset.content == null) return;
|
|
1496
|
-
return {
|
|
1497
|
-
gutter,
|
|
1498
|
-
content
|
|
1499
|
-
};
|
|
1500
|
-
}
|
|
1501
|
-
if (diffStyle === "unified") return getColumns(codeUnified);
|
|
1539
|
+
if (diffStyle === "unified") return this.getColumnPair(codeUnified);
|
|
1502
1540
|
else {
|
|
1503
|
-
const deletions =
|
|
1504
|
-
const additions =
|
|
1541
|
+
const deletions = this.getColumnPair(codeDeletions);
|
|
1542
|
+
const additions = this.getColumnPair(codeAdditions);
|
|
1505
1543
|
return deletions != null || additions != null ? [deletions, additions] : void 0;
|
|
1506
1544
|
}
|
|
1507
1545
|
}
|