@youtyan/code-viewer 0.1.29 → 0.1.30

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/web/app.js +42 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@youtyan/code-viewer",
3
- "version": "0.1.29",
3
+ "version": "0.1.30",
4
4
  "description": "Local browser-based code and git diff viewer",
5
5
  "type": "module",
6
6
  "bin": {
package/web/app.js CHANGED
@@ -90,6 +90,12 @@
90
90
  function trailingClickRange(hunkEndNew, step) {
91
91
  return { start: hunkEndNew, end: hunkEndNew + step - 1 };
92
92
  }
93
+ function trailingExpandTargetIndex(hunkCount) {
94
+ return hunkCount > 0 ? hunkCount - 1 : null;
95
+ }
96
+ function shouldAttachTrailingExpand(probeLineCount) {
97
+ return probeLineCount > 0;
98
+ }
93
99
  function applyTrailingResult(state, receivedCount, step) {
94
100
  return {
95
101
  newStart: state.newStart + receivedCount,
@@ -106,6 +112,8 @@
106
112
  applyUp,
107
113
  applyDown,
108
114
  mapNewToOld,
115
+ trailingExpandTargetIndex,
116
+ shouldAttachTrailingExpand,
109
117
  trailingClickRange,
110
118
  applyTrailingResult
111
119
  };
@@ -10310,6 +10318,10 @@ ${frontmatter.yaml}
10310
10318
  for (const item of infoRows) {
10311
10319
  attachExpandControls(item, file, ref, refPath);
10312
10320
  }
10321
+ const trailingIndex = window.GdpExpandLogic.trailingExpandTargetIndex(infoRows.length);
10322
+ if (trailingIndex != null) {
10323
+ probeAndAttachTrailingExpandControls(infoRows[trailingIndex], file, ref, refPath);
10324
+ }
10313
10325
  }
10314
10326
  function attachExpandControls(item, file, ref, refPath) {
10315
10327
  const { hunk, prevHunkEndNew, prevHunkEndOld } = item;
@@ -10451,7 +10463,10 @@ ${frontmatter.yaml}
10451
10463
  requestAnimationFrame(syncHeight);
10452
10464
  setTimeout(syncHeight, 100);
10453
10465
  }
10454
- function _attachTrailingExpandControls(item, file, ref, refPath) {
10466
+ function attachTrailingExpandControls(item, file, ref, refPath) {
10467
+ const hasTrailingRow = (item.siblings || []).some((sib) => !!sib.tr.parentElement?.querySelector(".gdp-trailing-expand-row"));
10468
+ if (hasTrailingRow)
10469
+ return;
10455
10470
  const STEP = 20;
10456
10471
  let nextNewStart = nextNewLine(item.hunk);
10457
10472
  let nextOldStart = nextOldLine(item.hunk);
@@ -10485,9 +10500,16 @@ ${frontmatter.yaml}
10485
10500
  };
10486
10501
  const fetchAndInsert = () => {
10487
10502
  const range = window.GdpExpandLogic.trailingClickRange(nextNewStart, STEP);
10503
+ const myGen = SERVER_GENERATION;
10488
10504
  setBusy(true);
10489
10505
  const url = "/file_range?path=" + refPath + "&ref=" + encodeURIComponent(ref) + "&start=" + range.start + "&end=" + range.end;
10490
10506
  trackLoad(fetch(url).then((r2) => r2.json())).then((data) => {
10507
+ if (myGen !== SERVER_GENERATION || data.generation && data.generation !== SERVER_GENERATION) {
10508
+ setBusy(false);
10509
+ return;
10510
+ }
10511
+ if (!item.tr.isConnected)
10512
+ return;
10491
10513
  const lines = data?.lines || [];
10492
10514
  if (!lines.length) {
10493
10515
  rows.forEach((row) => {
@@ -10526,6 +10548,25 @@ ${frontmatter.yaml}
10526
10548
  });
10527
10549
  syncExpandRowHeights(rows.map((row) => row.tr), rows[0].tr);
10528
10550
  }
10551
+ function probeAndAttachTrailingExpandControls(item, file, ref, refPath) {
10552
+ const start = nextNewLine(item.hunk);
10553
+ const myGen = SERVER_GENERATION;
10554
+ const url = "/file_range?path=" + refPath + "&ref=" + encodeURIComponent(ref) + "&start=" + start + "&end=" + start;
10555
+ trackLoad(fetch(url).then((r2) => r2.json())).then((data) => {
10556
+ if (myGen !== SERVER_GENERATION)
10557
+ return;
10558
+ if (data.generation && data.generation !== SERVER_GENERATION)
10559
+ return;
10560
+ if (!item.tr.isConnected)
10561
+ return;
10562
+ const hasTrailingRow = (item.siblings || []).some((sib) => !!sib.tr.parentElement?.querySelector(".gdp-trailing-expand-row"));
10563
+ if (hasTrailingRow)
10564
+ return;
10565
+ if (!window.GdpExpandLogic.shouldAttachTrailingExpand(data?.lines?.length || 0))
10566
+ return;
10567
+ attachTrailingExpandControls(item, file, ref, refPath);
10568
+ }).catch(() => {});
10569
+ }
10529
10570
  function insertContextRows(targetTr, lines, newStart, oldStart, dir, sideIndex) {
10530
10571
  const tbody = targetTr.parentElement;
10531
10572
  if (!tbody)