@thxgg/steward 0.1.25 → 0.1.26
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/.output/nitro.json +1 -1
- package/.output/public/_nuxt/{Bc2V3wPK.js → B2ow85x_.js} +2 -2
- package/.output/public/_nuxt/{U78rMDmo.js → B6CbIr08.js} +1 -1
- package/.output/public/_nuxt/{BknRrWsw.js → BLQAF8wp.js} +1 -1
- package/.output/public/_nuxt/BXuwtOqb.js +1 -0
- package/.output/public/_nuxt/CAMiEhze.js +1 -0
- package/.output/public/_nuxt/{BRQ9Cxaw.js → CIBCqZF5.js} +1 -1
- package/.output/public/_nuxt/Ce0-nlm9.js +1 -0
- package/.output/public/_nuxt/{T11EuTtn.js → ConzneVY.js} +1 -1
- package/.output/public/_nuxt/D0qxz_Pn.js +1310 -0
- package/.output/public/_nuxt/D3PDtLSF.js +3 -0
- package/.output/public/_nuxt/{C73kduX-.js → DdKC0UAK.js} +1 -1
- package/.output/public/_nuxt/Detail.BGdvrJGh.css +1 -0
- package/.output/public/_nuxt/{C53_p0K1.js → Dkh9ic1y.js} +1 -1
- package/.output/public/_nuxt/LEjJTR7-.js +1 -0
- package/.output/public/_nuxt/{BTmXUZ_s.js → UqZfMfrZ.js} +1 -1
- package/.output/public/_nuxt/builds/latest.json +1 -1
- package/.output/public/_nuxt/builds/meta/25438e34-19a2-421d-aede-53fd18f1ccd4.json +1 -0
- package/.output/public/_nuxt/dckrK0oj.js +1 -0
- package/.output/public/_nuxt/entry.DT4p6_uW.css +1 -0
- package/.output/public/_nuxt/pIWeVmPw.js +1 -0
- package/.output/public/_nuxt/xrHaPo1U.js +60 -0
- package/.output/server/chunks/build/{Detail-DMMUwTWr.mjs → Detail-rpcemNXe.mjs} +674 -481
- package/.output/server/chunks/build/Detail-rpcemNXe.mjs.map +1 -0
- package/.output/server/chunks/build/DiffViewer-styles.B1FB5NJj.mjs +8 -0
- package/.output/server/chunks/build/DiffViewer-styles.B1FB5NJj.mjs.map +1 -0
- package/.output/server/chunks/build/{_prd_-ByugK4Yi.mjs → _prd_-CeibvZOH.mjs} +67 -233
- package/.output/server/chunks/build/_prd_-CeibvZOH.mjs.map +1 -0
- package/.output/server/chunks/build/client.precomputed.mjs +1 -1
- package/.output/server/chunks/build/{default-BKKgG7HJ.mjs → default-iq8SaDDN.mjs} +3 -3
- package/.output/server/chunks/build/default-iq8SaDDN.mjs.map +1 -0
- package/.output/server/chunks/build/{error-404-Bf6kdO80.mjs → error-404-DFale9A5.mjs} +2 -2
- package/.output/server/chunks/build/error-404-DFale9A5.mjs.map +1 -0
- package/.output/server/chunks/build/{index-DE1tjHAd.mjs → index-Po00RvHm.mjs} +2 -2
- package/.output/server/chunks/build/index-Po00RvHm.mjs.map +1 -0
- package/.output/server/chunks/build/{nuxt-link-SvT1nf8Z.mjs → nuxt-link-B4oWFn7n.mjs} +2 -2
- package/.output/server/chunks/build/nuxt-link-B4oWFn7n.mjs.map +1 -0
- package/.output/server/chunks/build/{repo-graph-DzT45gSB.mjs → repo-graph-BQVFpA-w.mjs} +5 -4
- package/.output/server/chunks/build/repo-graph-BQVFpA-w.mjs.map +1 -0
- package/.output/server/chunks/build/server.mjs +7 -7
- package/.output/server/chunks/build/styles.mjs +4 -5
- package/.output/server/chunks/build/{usePrd-hXZOmvAv.mjs → usePrd-Bb6jlnNZ.mjs} +2 -2
- package/.output/server/chunks/build/usePrd-Bb6jlnNZ.mjs.map +1 -0
- package/.output/server/chunks/nitro/nitro.mjs +663 -660
- package/.output/server/node_modules/@pierre/diffs/dist/components/File.js +324 -0
- package/.output/server/node_modules/@pierre/diffs/dist/components/FileDiff.js +395 -0
- package/.output/server/node_modules/@pierre/diffs/dist/components/FileStream.js +161 -0
- package/.output/server/node_modules/@pierre/diffs/dist/components/web-components.js +25 -0
- package/.output/server/node_modules/@pierre/diffs/dist/constants.js +23 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/languages/areLanguagesAttached.js +11 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/languages/attachResolvedLanguages.js +20 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/languages/cleanUpResolvedLanguages.js +11 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/languages/constants.js +8 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/languages/getResolvedLanguages.js +16 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/languages/getResolvedOrResolveLanguage.js +11 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/languages/hasResolvedLanguages.js +11 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/languages/resolveLanguage.js +30 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/languages/resolveLanguages.js +25 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/shared_highlighter.js +71 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/themes/areThemesAttached.js +12 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/themes/attachResolvedThemes.js +24 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/themes/cleanUpResolvedThemes.js +11 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/themes/constants.js +9 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/themes/getResolvedOrResolveTheme.js +11 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/themes/getResolvedThemes.js +16 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/themes/hasResolvedThemes.js +11 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/themes/registerCustomCSSVariableTheme.js +18 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/themes/registerCustomTheme.js +14 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/themes/resolveTheme.js +35 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/themes/resolveThemes.js +21 -0
- package/.output/server/node_modules/@pierre/diffs/dist/index.js +84 -0
- package/.output/server/node_modules/@pierre/diffs/dist/managers/LineSelectionManager.js +282 -0
- package/.output/server/node_modules/@pierre/diffs/dist/managers/MouseEventManager.js +244 -0
- package/.output/server/node_modules/@pierre/diffs/dist/managers/ResizeManager.js +132 -0
- package/.output/server/node_modules/@pierre/diffs/dist/managers/ScrollSyncManager.js +62 -0
- package/.output/server/node_modules/@pierre/diffs/dist/managers/UniversalRenderingManager.js +32 -0
- package/.output/server/node_modules/@pierre/diffs/dist/renderers/DiffHunksRenderer.js +655 -0
- package/.output/server/node_modules/@pierre/diffs/dist/renderers/FileRenderer.js +243 -0
- package/.output/server/node_modules/@pierre/diffs/dist/shiki-stream/stream.js +32 -0
- package/.output/server/node_modules/@pierre/diffs/dist/shiki-stream/tokenizer.js +71 -0
- package/.output/server/node_modules/@pierre/diffs/dist/sprite.js +55 -0
- package/.output/server/node_modules/@pierre/diffs/dist/style.js +6 -0
- package/.output/server/node_modules/@pierre/diffs/dist/themes/pierre-dark.js +1328 -0
- package/.output/server/node_modules/@pierre/diffs/dist/themes/pierre-light.js +1328 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/areFilesEqual.js +8 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/areObjectsEqual.js +18 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/areOptionsEqual.js +12 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/areSelectionsEqual.js +8 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/areThemesEqual.js +9 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/cleanLastNewline.js +8 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/createAnnotationElement.js +21 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/createAnnotationWrapperNode.js +12 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/createCodeNode.js +12 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/createEmptyRowBuffer.js +16 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/createFileHeaderElement.js +84 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/createHoverContentNode.js +15 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/createNoNewlineElement.js +24 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/createPreElement.js +28 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/createRowNodes.js +20 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/createSeparator.js +69 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/createSpanNodeFromToken.js +13 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/createStyleElement.js +19 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/createTransformerWithState.js +56 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/createUnsafeCSSStyleNode.js +12 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/cssWrappers.js +21 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/diffAcceptRejectHunk.js +82 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/formatCSSVariablePrefix.js +8 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/getFiletypeFromFileName.js +343 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/getHighlighterOptions.js +13 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/getHighlighterThemeStyles.js +40 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/getHunkSeparatorSlotName.js +8 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/getIconForType.js +15 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/getLineAnnotationName.js +8 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/getLineEndingType.js +11 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/getLineNodes.js +15 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/getSingularPatch.js +20 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/getThemes.js +16 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/getTotalLineCountFromHunks.js +10 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/hast_utils.js +42 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/isWorkerContext.js +8 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/parseDiffDecorations.js +34 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/parseDiffFromFile.js +23 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/parseLineType.js +17 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/parsePatchFiles.js +211 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/prerenderHTMLIfNecessary.js +10 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/processLine.js +42 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/renderDiffWithHighlighter.js +339 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/renderFileWithHighlighter.js +52 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/setLanguageOverride.js +11 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/setWrapperNodeProps.js +29 -0
- package/.output/server/node_modules/@pierre/diffs/package.json +89 -0
- package/.output/server/node_modules/@shikijs/transformers/dist/index.mjs +831 -0
- package/.output/server/node_modules/@shikijs/transformers/package.json +37 -0
- package/.output/server/node_modules/diff/libesm/convert/dmp.js +21 -0
- package/.output/server/node_modules/diff/libesm/convert/xml.js +31 -0
- package/.output/server/node_modules/diff/libesm/diff/array.js +16 -0
- package/.output/server/node_modules/diff/libesm/diff/base.js +253 -0
- package/.output/server/node_modules/diff/libesm/diff/character.js +7 -0
- package/.output/server/node_modules/diff/libesm/diff/css.js +10 -0
- package/.output/server/node_modules/diff/libesm/diff/json.js +78 -0
- package/.output/server/node_modules/diff/libesm/diff/line.js +65 -0
- package/.output/server/node_modules/diff/libesm/diff/sentence.js +43 -0
- package/.output/server/node_modules/diff/libesm/diff/word.js +296 -0
- package/.output/server/node_modules/diff/libesm/index.js +30 -0
- package/.output/server/node_modules/diff/libesm/package.json +1 -0
- package/.output/server/node_modules/diff/libesm/patch/apply.js +257 -0
- package/.output/server/node_modules/diff/libesm/patch/create.js +228 -0
- package/.output/server/node_modules/diff/libesm/patch/line-endings.js +44 -0
- package/.output/server/node_modules/diff/libesm/patch/parse.js +147 -0
- package/.output/server/node_modules/diff/libesm/patch/reverse.js +23 -0
- package/.output/server/node_modules/diff/libesm/util/distance-iterator.js +37 -0
- package/.output/server/node_modules/diff/libesm/util/params.js +14 -0
- package/.output/server/node_modules/diff/libesm/util/string.js +128 -0
- package/.output/server/node_modules/diff/package.json +132 -0
- package/.output/server/package.json +4 -1
- package/dist/server/utils/git.js +8 -6
- package/package.json +2 -1
- package/.output/public/_nuxt/6tINjQEd.js +0 -141
- package/.output/public/_nuxt/B2mIQf5X.js +0 -3
- package/.output/public/_nuxt/C0BBSDJ7.js +0 -1
- package/.output/public/_nuxt/CN46Bgts.js +0 -1
- package/.output/public/_nuxt/CTJgb0zb.js +0 -1
- package/.output/public/_nuxt/Cce168lk.js +0 -30
- package/.output/public/_nuxt/CyVSeLw5.js +0 -1
- package/.output/public/_nuxt/Detail.CYc96mGf.css +0 -1
- package/.output/public/_nuxt/ZNypZshD.js +0 -13
- package/.output/public/_nuxt/builds/meta/9ce7f1bc-d5e2-47bf-8026-f4910c257b2e.json +0 -1
- package/.output/public/_nuxt/entry.Bw0CE6Iz.css +0 -1
- package/.output/public/_nuxt/pYJYAY-W.js +0 -60
- package/.output/server/chunks/build/Detail-DMMUwTWr.mjs.map +0 -1
- package/.output/server/chunks/build/DiffViewer-styles-1.mjs-d2dQvARr.mjs +0 -4
- package/.output/server/chunks/build/DiffViewer-styles-1.mjs-d2dQvARr.mjs.map +0 -1
- package/.output/server/chunks/build/DiffViewer-styles-2.mjs-X6QKNjM0.mjs +0 -4
- package/.output/server/chunks/build/DiffViewer-styles-2.mjs-X6QKNjM0.mjs.map +0 -1
- package/.output/server/chunks/build/DiffViewer-styles.0AbHFl6N.mjs +0 -8
- package/.output/server/chunks/build/DiffViewer-styles.0AbHFl6N.mjs.map +0 -1
- package/.output/server/chunks/build/DiffViewer-styles.BDwAqkTk.mjs +0 -8
- package/.output/server/chunks/build/DiffViewer-styles.BDwAqkTk.mjs.map +0 -1
- package/.output/server/chunks/build/DiffViewer-styles.DRJh5Ui4.mjs +0 -10
- package/.output/server/chunks/build/DiffViewer-styles.DRJh5Ui4.mjs.map +0 -1
- package/.output/server/chunks/build/_prd_-ByugK4Yi.mjs.map +0 -1
- package/.output/server/chunks/build/default-BKKgG7HJ.mjs.map +0 -1
- package/.output/server/chunks/build/error-404-Bf6kdO80.mjs.map +0 -1
- package/.output/server/chunks/build/index-DE1tjHAd.mjs.map +0 -1
- package/.output/server/chunks/build/nuxt-link-SvT1nf8Z.mjs.map +0 -1
- package/.output/server/chunks/build/repo-graph-DzT45gSB.mjs.map +0 -1
- package/.output/server/chunks/build/usePrd-hXZOmvAv.mjs.map +0 -1
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { areSelectionsEqual } from "../utils/areSelectionsEqual.js";
|
|
2
|
+
|
|
3
|
+
//#region src/managers/LineSelectionManager.ts
|
|
4
|
+
/**
|
|
5
|
+
* Manages line selection state and interactions for code/diff viewers.
|
|
6
|
+
* Handles:
|
|
7
|
+
* - Click and drag selection
|
|
8
|
+
* - Shift-click to extend selection
|
|
9
|
+
* - DOM attribute updates (data-selected-line)
|
|
10
|
+
*/
|
|
11
|
+
var LineSelectionManager = class {
|
|
12
|
+
pre;
|
|
13
|
+
selectedRange = null;
|
|
14
|
+
renderedSelectionRange;
|
|
15
|
+
anchor;
|
|
16
|
+
_queuedRender;
|
|
17
|
+
constructor(options = {}) {
|
|
18
|
+
this.options = options;
|
|
19
|
+
}
|
|
20
|
+
setOptions(options) {
|
|
21
|
+
this.options = {
|
|
22
|
+
...this.options,
|
|
23
|
+
...options
|
|
24
|
+
};
|
|
25
|
+
this.removeEventListeners();
|
|
26
|
+
if (this.options.enableLineSelection === true) this.attachEventListeners();
|
|
27
|
+
}
|
|
28
|
+
cleanUp() {
|
|
29
|
+
this.removeEventListeners();
|
|
30
|
+
if (this._queuedRender != null) {
|
|
31
|
+
cancelAnimationFrame(this._queuedRender);
|
|
32
|
+
this._queuedRender = void 0;
|
|
33
|
+
}
|
|
34
|
+
if (this.pre != null) delete this.pre.dataset.interactiveLineNumbers;
|
|
35
|
+
this.pre = void 0;
|
|
36
|
+
}
|
|
37
|
+
setup(pre) {
|
|
38
|
+
this.setDirty();
|
|
39
|
+
if (this.pre !== pre) this.cleanUp();
|
|
40
|
+
this.pre = pre;
|
|
41
|
+
const { enableLineSelection = false } = this.options;
|
|
42
|
+
if (enableLineSelection) {
|
|
43
|
+
this.pre.dataset.interactiveLineNumbers = "";
|
|
44
|
+
this.attachEventListeners();
|
|
45
|
+
} else {
|
|
46
|
+
this.removeEventListeners();
|
|
47
|
+
delete this.pre.dataset.interactiveLineNumbers;
|
|
48
|
+
}
|
|
49
|
+
this.setSelection(this.selectedRange);
|
|
50
|
+
}
|
|
51
|
+
setDirty() {
|
|
52
|
+
this.renderedSelectionRange = void 0;
|
|
53
|
+
}
|
|
54
|
+
isDirty() {
|
|
55
|
+
return this.renderedSelectionRange === void 0;
|
|
56
|
+
}
|
|
57
|
+
setSelection(range) {
|
|
58
|
+
const isRangeChange = !(range === this.selectedRange || areSelectionsEqual(range ?? void 0, this.selectedRange ?? void 0));
|
|
59
|
+
if (!this.isDirty() && !isRangeChange) return;
|
|
60
|
+
this.selectedRange = range;
|
|
61
|
+
this.renderSelection();
|
|
62
|
+
if (isRangeChange) this.notifySelectionChange();
|
|
63
|
+
}
|
|
64
|
+
getSelection() {
|
|
65
|
+
return this.selectedRange;
|
|
66
|
+
}
|
|
67
|
+
attachEventListeners() {
|
|
68
|
+
if (this.pre == null) return;
|
|
69
|
+
this.removeEventListeners();
|
|
70
|
+
this.pre.addEventListener("pointerdown", this.handleMouseDown);
|
|
71
|
+
}
|
|
72
|
+
removeEventListeners() {
|
|
73
|
+
if (this.pre == null) return;
|
|
74
|
+
this.pre.removeEventListener("pointerdown", this.handleMouseDown);
|
|
75
|
+
document.removeEventListener("pointermove", this.handleMouseMove);
|
|
76
|
+
document.removeEventListener("pointerup", this.handleMouseUp);
|
|
77
|
+
}
|
|
78
|
+
handleMouseDown = (event) => {
|
|
79
|
+
const mouseEventData = event.button === 0 ? this.getMouseEventDataForPath(event.composedPath(), "click") : void 0;
|
|
80
|
+
if (mouseEventData == null) return;
|
|
81
|
+
event.preventDefault();
|
|
82
|
+
const { lineNumber, eventSide, lineIndex } = mouseEventData;
|
|
83
|
+
if (event.shiftKey && this.selectedRange != null) {
|
|
84
|
+
const range = this.deriveRowRangeFromDOM(this.selectedRange, this.pre?.dataset.type === "split");
|
|
85
|
+
if (range == null) return;
|
|
86
|
+
const useStart = range.start <= range.end ? lineIndex >= range.start : lineIndex <= range.end;
|
|
87
|
+
this.anchor = {
|
|
88
|
+
line: useStart ? this.selectedRange.start : this.selectedRange.end,
|
|
89
|
+
side: (useStart ? this.selectedRange.side : this.selectedRange.endSide ?? this.selectedRange.side) ?? "additions"
|
|
90
|
+
};
|
|
91
|
+
this.updateSelection(lineNumber, eventSide);
|
|
92
|
+
this.notifySelectionStart(this.selectedRange);
|
|
93
|
+
} else {
|
|
94
|
+
if (this.selectedRange?.start === lineNumber && this.selectedRange?.end === lineNumber) {
|
|
95
|
+
this.updateSelection(null);
|
|
96
|
+
this.notifySelectionEnd(null);
|
|
97
|
+
this.notifySelectionChange();
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
this.selectedRange = null;
|
|
101
|
+
this.anchor = {
|
|
102
|
+
line: lineNumber,
|
|
103
|
+
side: eventSide
|
|
104
|
+
};
|
|
105
|
+
this.updateSelection(lineNumber, eventSide);
|
|
106
|
+
this.notifySelectionStart(this.selectedRange);
|
|
107
|
+
}
|
|
108
|
+
document.addEventListener("pointermove", this.handleMouseMove);
|
|
109
|
+
document.addEventListener("pointerup", this.handleMouseUp);
|
|
110
|
+
};
|
|
111
|
+
handleMouseMove = (event) => {
|
|
112
|
+
const mouseEventData = this.getMouseEventDataForPath(event.composedPath(), "move");
|
|
113
|
+
if (mouseEventData == null || this.anchor == null) return;
|
|
114
|
+
const { lineNumber, eventSide } = mouseEventData;
|
|
115
|
+
this.updateSelection(lineNumber, eventSide);
|
|
116
|
+
};
|
|
117
|
+
handleMouseUp = () => {
|
|
118
|
+
this.anchor = void 0;
|
|
119
|
+
document.removeEventListener("pointermove", this.handleMouseMove);
|
|
120
|
+
document.removeEventListener("pointerup", this.handleMouseUp);
|
|
121
|
+
this.notifySelectionEnd(this.selectedRange);
|
|
122
|
+
this.notifySelectionChange();
|
|
123
|
+
};
|
|
124
|
+
updateSelection(currentLine, side) {
|
|
125
|
+
if (currentLine == null) this.selectedRange = null;
|
|
126
|
+
else {
|
|
127
|
+
const anchorSide = this.anchor?.side ?? side;
|
|
128
|
+
this.selectedRange = {
|
|
129
|
+
start: this.anchor?.line ?? currentLine,
|
|
130
|
+
end: currentLine,
|
|
131
|
+
side: anchorSide,
|
|
132
|
+
endSide: anchorSide !== side ? side : void 0
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
this._queuedRender ??= requestAnimationFrame(this.renderSelection);
|
|
136
|
+
}
|
|
137
|
+
renderSelection = () => {
|
|
138
|
+
if (this._queuedRender != null) {
|
|
139
|
+
cancelAnimationFrame(this._queuedRender);
|
|
140
|
+
this._queuedRender = void 0;
|
|
141
|
+
}
|
|
142
|
+
if (this.pre == null || this.renderedSelectionRange === this.selectedRange) return;
|
|
143
|
+
const allSelected = this.pre.querySelectorAll("[data-selected-line]");
|
|
144
|
+
for (const element of allSelected) element.removeAttribute("data-selected-line");
|
|
145
|
+
this.renderedSelectionRange = this.selectedRange;
|
|
146
|
+
if (this.selectedRange == null) return;
|
|
147
|
+
const codeElements = this.pre.querySelectorAll("[data-code]");
|
|
148
|
+
if (codeElements.length === 0) return;
|
|
149
|
+
if (codeElements.length > 2) {
|
|
150
|
+
console.error(codeElements);
|
|
151
|
+
throw new Error("LineSelectionManager.applySelectionToDOM: Somehow there are more than 2 code elements...");
|
|
152
|
+
}
|
|
153
|
+
const split = this.pre.dataset.type === "split";
|
|
154
|
+
const rowRange = this.deriveRowRangeFromDOM(this.selectedRange, split);
|
|
155
|
+
if (rowRange == null) {
|
|
156
|
+
console.error({
|
|
157
|
+
rowRange,
|
|
158
|
+
selectedRange: this.selectedRange
|
|
159
|
+
});
|
|
160
|
+
throw new Error("LineSelectionManager.renderSelection: No valid rowRange");
|
|
161
|
+
}
|
|
162
|
+
const isSingle = rowRange.start === rowRange.end;
|
|
163
|
+
const first = Math.min(rowRange.start, rowRange.end);
|
|
164
|
+
const last = Math.max(rowRange.start, rowRange.end);
|
|
165
|
+
for (const code of codeElements) for (const element of code.children) {
|
|
166
|
+
if (!(element instanceof HTMLElement)) continue;
|
|
167
|
+
const lineIndex = this.getLineIndex(element, split);
|
|
168
|
+
if ((lineIndex ?? 0) > last) break;
|
|
169
|
+
if (lineIndex == null || lineIndex < first) continue;
|
|
170
|
+
let attributeValue = isSingle ? "single" : lineIndex === first ? "first" : lineIndex === last ? "last" : "";
|
|
171
|
+
element.setAttribute("data-selected-line", attributeValue);
|
|
172
|
+
if (element.nextSibling instanceof HTMLElement && element.nextSibling.hasAttribute("data-line-annotation")) {
|
|
173
|
+
if (isSingle) {
|
|
174
|
+
attributeValue = "last";
|
|
175
|
+
element.setAttribute("data-selected-line", "first");
|
|
176
|
+
} else if (lineIndex === first) attributeValue = "";
|
|
177
|
+
else if (lineIndex === last) element.setAttribute("data-selected-line", "");
|
|
178
|
+
element.nextSibling.setAttribute("data-selected-line", attributeValue);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
deriveRowRangeFromDOM(range, split) {
|
|
183
|
+
if (range == null) return void 0;
|
|
184
|
+
const start = this.findRowIndexForLineNumber(range.start, range.side, split);
|
|
185
|
+
const end = range.end === range.start && (range.endSide == null || range.endSide === range.side) ? start : this.findRowIndexForLineNumber(range.end, range.endSide ?? range.side, split);
|
|
186
|
+
return start != null && end != null ? {
|
|
187
|
+
start,
|
|
188
|
+
end
|
|
189
|
+
} : void 0;
|
|
190
|
+
}
|
|
191
|
+
findRowIndexForLineNumber(lineNumber, targetSide = "additions", split) {
|
|
192
|
+
if (this.pre == null) return void 0;
|
|
193
|
+
const elements = Array.from(this.pre.querySelectorAll(`[data-line="${lineNumber}"]`));
|
|
194
|
+
elements.push(...Array.from(this.pre.querySelectorAll(`[data-alt-line="${lineNumber}"]`)));
|
|
195
|
+
if (elements.length === 0) return void 0;
|
|
196
|
+
for (const element of elements) {
|
|
197
|
+
if (!(element instanceof HTMLElement)) continue;
|
|
198
|
+
if (this.getLineSideFromElement(element) === targetSide) return this.getLineIndex(element, split);
|
|
199
|
+
else if (parseInt(element.dataset.altLine ?? "") === lineNumber) return this.getLineIndex(element, split);
|
|
200
|
+
}
|
|
201
|
+
console.error("LineSelectionManager.findRowIndexForLineNumber: Invalid selection", lineNumber, targetSide);
|
|
202
|
+
}
|
|
203
|
+
notifySelectionChange() {
|
|
204
|
+
const { onLineSelected } = this.options;
|
|
205
|
+
if (onLineSelected == null) return;
|
|
206
|
+
onLineSelected(this.selectedRange ?? null);
|
|
207
|
+
}
|
|
208
|
+
notifySelectionStart(range) {
|
|
209
|
+
const { onLineSelectionStart } = this.options;
|
|
210
|
+
if (onLineSelectionStart == null) return;
|
|
211
|
+
onLineSelectionStart(range);
|
|
212
|
+
}
|
|
213
|
+
notifySelectionEnd(range) {
|
|
214
|
+
const { onLineSelectionEnd } = this.options;
|
|
215
|
+
if (onLineSelectionEnd == null) return;
|
|
216
|
+
onLineSelectionEnd(range);
|
|
217
|
+
}
|
|
218
|
+
getMouseEventDataForPath(path, eventType) {
|
|
219
|
+
let lineNumber;
|
|
220
|
+
let lineIndex;
|
|
221
|
+
let isNumberColumn = false;
|
|
222
|
+
let eventSide;
|
|
223
|
+
for (const element of path) {
|
|
224
|
+
if (!(element instanceof HTMLElement)) continue;
|
|
225
|
+
if (element.hasAttribute("data-column-number")) {
|
|
226
|
+
isNumberColumn = true;
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
if (element.hasAttribute("data-line")) {
|
|
230
|
+
lineNumber = this.getLineNumber(element);
|
|
231
|
+
lineIndex = this.getLineIndex(element, this.pre?.dataset.type === "split");
|
|
232
|
+
if (element.dataset.lineType === "change-deletion") eventSide = "deletions";
|
|
233
|
+
else if (element.dataset.lineType === "change-additions") eventSide = "additions";
|
|
234
|
+
if (lineIndex == null || lineNumber == null) {
|
|
235
|
+
lineIndex = void 0;
|
|
236
|
+
lineNumber = void 0;
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
if (eventSide != null) break;
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
if (element.hasAttribute("data-code")) {
|
|
243
|
+
eventSide ??= element.hasAttribute("data-deletions") ? "deletions" : "additions";
|
|
244
|
+
break;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
if (eventType === "click" && !isNumberColumn || lineIndex == null || lineNumber == null) return;
|
|
248
|
+
return {
|
|
249
|
+
lineIndex,
|
|
250
|
+
lineNumber,
|
|
251
|
+
eventSide: eventSide ?? "additions"
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
getLineNumber(element) {
|
|
255
|
+
const lineNumber = parseInt(element.dataset.line ?? "", 10);
|
|
256
|
+
return !Number.isNaN(lineNumber) ? lineNumber : void 0;
|
|
257
|
+
}
|
|
258
|
+
getLineIndex(element, split) {
|
|
259
|
+
const lineIndexes = (element.dataset.lineIndex ?? "").split(",").map((value) => parseInt(value)).filter((value) => !Number.isNaN(value));
|
|
260
|
+
if (split && lineIndexes.length === 2) return lineIndexes[1];
|
|
261
|
+
else if (!split) return lineIndexes[0];
|
|
262
|
+
}
|
|
263
|
+
getLineSideFromElement(element) {
|
|
264
|
+
if (element.dataset.lineType === "change-deletion") return "deletions";
|
|
265
|
+
if (element.dataset.lineType === "change-addition") return "additions";
|
|
266
|
+
const parent = element.closest("[data-code]");
|
|
267
|
+
if (!(parent instanceof HTMLElement)) return "additions";
|
|
268
|
+
return parent.hasAttribute("data-deletions") ? "deletions" : "additions";
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
function pluckLineSelectionOptions({ enableLineSelection, onLineSelected, onLineSelectionStart, onLineSelectionEnd }) {
|
|
272
|
+
return {
|
|
273
|
+
enableLineSelection,
|
|
274
|
+
onLineSelected,
|
|
275
|
+
onLineSelectionStart,
|
|
276
|
+
onLineSelectionEnd
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
//#endregion
|
|
281
|
+
export { LineSelectionManager, pluckLineSelectionOptions };
|
|
282
|
+
//# sourceMappingURL=LineSelectionManager.js.map
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
//#region src/managers/MouseEventManager.ts
|
|
2
|
+
function isLineEventData(data, mode) {
|
|
3
|
+
if (data == null) return false;
|
|
4
|
+
if (mode === "file") return data.type === "line";
|
|
5
|
+
else return data.type === "diff-line";
|
|
6
|
+
}
|
|
7
|
+
function isExpandoEventData(data) {
|
|
8
|
+
return data?.type === "line-info";
|
|
9
|
+
}
|
|
10
|
+
var MouseEventManager = class {
|
|
11
|
+
hoveredLine;
|
|
12
|
+
pre;
|
|
13
|
+
hoverSlot;
|
|
14
|
+
constructor(mode, options) {
|
|
15
|
+
this.mode = mode;
|
|
16
|
+
this.options = options;
|
|
17
|
+
}
|
|
18
|
+
setOptions(options) {
|
|
19
|
+
this.options = options;
|
|
20
|
+
}
|
|
21
|
+
cleanUp() {
|
|
22
|
+
this.pre?.removeEventListener("click", this.handleMouseClick);
|
|
23
|
+
this.pre?.removeEventListener("pointermove", this.handleMouseMove);
|
|
24
|
+
this.pre?.removeEventListener("pointerout", this.handleMouseLeave);
|
|
25
|
+
delete this.pre?.dataset.interactiveLines;
|
|
26
|
+
delete this.pre?.dataset.interactiveLineNumbers;
|
|
27
|
+
this.pre = void 0;
|
|
28
|
+
}
|
|
29
|
+
setup(pre) {
|
|
30
|
+
const { __debugMouseEvents, onLineClick, onLineNumberClick, onLineEnter, onLineLeave, onHunkExpand, enableHoverUtility = false } = this.options;
|
|
31
|
+
this.cleanUp();
|
|
32
|
+
this.pre = pre;
|
|
33
|
+
if (enableHoverUtility && this.hoverSlot == null) {
|
|
34
|
+
this.hoverSlot = document.createElement("div");
|
|
35
|
+
this.hoverSlot.dataset.hoverSlot = "";
|
|
36
|
+
const slotElement = document.createElement("slot");
|
|
37
|
+
slotElement.name = "hover-slot";
|
|
38
|
+
this.hoverSlot.appendChild(slotElement);
|
|
39
|
+
} else if (!enableHoverUtility && this.hoverSlot != null) {
|
|
40
|
+
this.hoverSlot.parentNode?.removeChild(this.hoverSlot);
|
|
41
|
+
this.hoverSlot = void 0;
|
|
42
|
+
}
|
|
43
|
+
if (onLineClick != null || onLineNumberClick != null || onHunkExpand != null) {
|
|
44
|
+
pre.addEventListener("click", this.handleMouseClick);
|
|
45
|
+
if (onLineClick != null) pre.dataset.interactiveLines = "";
|
|
46
|
+
else if (onLineNumberClick != null) pre.dataset.interactiveLineNumbers = "";
|
|
47
|
+
debugLogIfEnabled(__debugMouseEvents, "click", "FileDiff.DEBUG.attachEventListeners: Attaching click events for:", (() => {
|
|
48
|
+
const reasons = [];
|
|
49
|
+
if (__debugMouseEvents === "both" || __debugMouseEvents === "click") {
|
|
50
|
+
if (onLineClick != null) reasons.push("onLineClick");
|
|
51
|
+
if (onLineNumberClick != null) reasons.push("onLineNumberClick");
|
|
52
|
+
if (onHunkExpand != null) reasons.push("expandable hunk separators");
|
|
53
|
+
}
|
|
54
|
+
return reasons;
|
|
55
|
+
})());
|
|
56
|
+
}
|
|
57
|
+
if (onLineEnter != null || onLineLeave != null || enableHoverUtility) {
|
|
58
|
+
pre.addEventListener("pointermove", this.handleMouseMove);
|
|
59
|
+
debugLogIfEnabled(__debugMouseEvents, "move", "FileDiff.DEBUG.attachEventListeners: Attaching pointer move event");
|
|
60
|
+
pre.addEventListener("pointerleave", this.handleMouseLeave);
|
|
61
|
+
debugLogIfEnabled(__debugMouseEvents, "move", "FileDiff.DEBUG.attachEventListeners: Attaching pointer leave event");
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
getHoveredLine = () => {
|
|
65
|
+
if (this.hoveredLine != null) {
|
|
66
|
+
if (this.mode === "diff" && this.hoveredLine.type === "diff-line") return {
|
|
67
|
+
lineNumber: this.hoveredLine.lineNumber,
|
|
68
|
+
side: this.hoveredLine.annotationSide
|
|
69
|
+
};
|
|
70
|
+
if (this.mode === "file" && this.hoveredLine.type === "line") return { lineNumber: this.hoveredLine.lineNumber };
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
handleMouseClick = (event) => {
|
|
74
|
+
debugLogIfEnabled(this.options.__debugMouseEvents, "click", "FileDiff.DEBUG.handleMouseClick:", event);
|
|
75
|
+
this.handleMouseEvent({
|
|
76
|
+
eventType: "click",
|
|
77
|
+
event
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
handleMouseMove = (event) => {
|
|
81
|
+
debugLogIfEnabled(this.options.__debugMouseEvents, "move", "FileDiff.DEBUG.handleMouseMove:", event);
|
|
82
|
+
this.handleMouseEvent({
|
|
83
|
+
eventType: "move",
|
|
84
|
+
event
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
handleMouseLeave = (event) => {
|
|
88
|
+
const { __debugMouseEvents } = this.options;
|
|
89
|
+
debugLogIfEnabled(__debugMouseEvents, "move", "FileDiff.DEBUG.handleMouseLeave: no event");
|
|
90
|
+
if (this.hoveredLine == null) {
|
|
91
|
+
debugLogIfEnabled(__debugMouseEvents, "move", "FileDiff.DEBUG.handleMouseLeave: returned early, no .hoveredLine");
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
this.hoverSlot?.parentElement?.removeChild(this.hoverSlot);
|
|
95
|
+
this.options.onLineLeave?.({
|
|
96
|
+
...this.hoveredLine,
|
|
97
|
+
event
|
|
98
|
+
});
|
|
99
|
+
this.hoveredLine = void 0;
|
|
100
|
+
};
|
|
101
|
+
handleMouseEvent({ eventType, event }) {
|
|
102
|
+
const { __debugMouseEvents } = this.options;
|
|
103
|
+
const composedPath = event.composedPath();
|
|
104
|
+
debugLogIfEnabled(__debugMouseEvents, eventType, "FileDiff.DEBUG.handleMouseEvent:", {
|
|
105
|
+
eventType,
|
|
106
|
+
composedPath
|
|
107
|
+
});
|
|
108
|
+
const data = this.getLineData(composedPath);
|
|
109
|
+
debugLogIfEnabled(__debugMouseEvents, eventType, "FileDiff.DEBUG.handleMouseEvent: getLineData result:", data);
|
|
110
|
+
const { onLineClick, onLineNumberClick, onLineEnter, onLineLeave, onHunkExpand } = this.options;
|
|
111
|
+
switch (eventType) {
|
|
112
|
+
case "move":
|
|
113
|
+
if (isLineEventData(data, this.mode) && this.hoveredLine?.lineElement === data.lineElement) {
|
|
114
|
+
debugLogIfEnabled(__debugMouseEvents, "move", "FileDiff.DEBUG.handleMouseEvent: switch, 'move', returned early because same line");
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
if (this.hoveredLine != null) {
|
|
118
|
+
debugLogIfEnabled(__debugMouseEvents, "move", "FileDiff.DEBUG.handleMouseEvent: switch, 'move', clearing an existing hovered line and firing onLineLeave");
|
|
119
|
+
this.hoverSlot?.parentElement?.removeChild(this.hoverSlot);
|
|
120
|
+
onLineLeave?.({
|
|
121
|
+
...this.hoveredLine,
|
|
122
|
+
event
|
|
123
|
+
});
|
|
124
|
+
this.hoveredLine = void 0;
|
|
125
|
+
}
|
|
126
|
+
if (isLineEventData(data, this.mode)) {
|
|
127
|
+
debugLogIfEnabled(__debugMouseEvents, "move", "FileDiff.DEBUG.handleMouseEvent: switch, 'move', setting up a new hoveredLine and firing onLineEnter");
|
|
128
|
+
this.hoveredLine = data;
|
|
129
|
+
if (this.hoverSlot != null) data.numberElement?.appendChild(this.hoverSlot);
|
|
130
|
+
onLineEnter?.({
|
|
131
|
+
...this.hoveredLine,
|
|
132
|
+
event
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
break;
|
|
136
|
+
case "click":
|
|
137
|
+
debugLogIfEnabled(__debugMouseEvents, "click", "FileDiff.DEBUG.handleMouseEvent: switch, 'click', with data:", data);
|
|
138
|
+
if (data == null) break;
|
|
139
|
+
if (isExpandoEventData(data) && onHunkExpand != null) {
|
|
140
|
+
debugLogIfEnabled(__debugMouseEvents, "click", "FileDiff.DEBUG.handleMouseEvent: switch, 'click', expanding a hunk");
|
|
141
|
+
onHunkExpand(data.hunkIndex, data.direction);
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
if (isLineEventData(data, this.mode)) if (onLineNumberClick != null && data.numberColumn) {
|
|
145
|
+
debugLogIfEnabled(__debugMouseEvents, "click", "FileDiff.DEBUG.handleMouseEvent: switch, 'click', firing 'onLineNumberClick'");
|
|
146
|
+
onLineNumberClick({
|
|
147
|
+
...data,
|
|
148
|
+
event
|
|
149
|
+
});
|
|
150
|
+
} else if (onLineClick != null) {
|
|
151
|
+
debugLogIfEnabled(__debugMouseEvents, "click", "FileDiff.DEBUG.handleMouseEvent: switch, 'click', firing 'onLineClick'");
|
|
152
|
+
onLineClick({
|
|
153
|
+
...data,
|
|
154
|
+
event
|
|
155
|
+
});
|
|
156
|
+
} else debugLogIfEnabled(__debugMouseEvents, "click", "FileDiff.DEBUG.handleMouseEvent: switch, 'click', fell through, no event to fire");
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
getLineData(path) {
|
|
161
|
+
let numberColumn = false;
|
|
162
|
+
const lineElement = path.find((element) => {
|
|
163
|
+
if (!(element instanceof HTMLElement)) return false;
|
|
164
|
+
numberColumn = numberColumn || "columnNumber" in element.dataset;
|
|
165
|
+
return "line" in element.dataset || "expandIndex" in element.dataset;
|
|
166
|
+
});
|
|
167
|
+
if (!(lineElement instanceof HTMLElement)) return void 0;
|
|
168
|
+
if (lineElement.dataset.expandIndex != null) {
|
|
169
|
+
const hunkIndex = parseInt(lineElement.dataset.expandIndex);
|
|
170
|
+
if (isNaN(hunkIndex)) return;
|
|
171
|
+
let direction;
|
|
172
|
+
for (const element of path) {
|
|
173
|
+
if (element === lineElement) break;
|
|
174
|
+
if (element instanceof HTMLElement) {
|
|
175
|
+
direction = direction ?? ("expandUp" in element.dataset ? "up" : void 0) ?? ("expandDown" in element.dataset ? "down" : void 0) ?? ("expandBoth" in element.dataset ? "both" : void 0);
|
|
176
|
+
if (direction != null) break;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return direction != null ? {
|
|
180
|
+
type: "line-info",
|
|
181
|
+
hunkIndex,
|
|
182
|
+
direction
|
|
183
|
+
} : void 0;
|
|
184
|
+
}
|
|
185
|
+
const lineNumber = parseInt(lineElement.dataset.line ?? "");
|
|
186
|
+
if (isNaN(lineNumber)) return;
|
|
187
|
+
const lineType = lineElement.dataset.lineType;
|
|
188
|
+
if (lineType !== "context" && lineType !== "context-expanded" && lineType !== "change-deletion" && lineType !== "change-addition") return;
|
|
189
|
+
const numberElement = (() => {
|
|
190
|
+
const numberElement$1 = lineElement.children[0];
|
|
191
|
+
return numberElement$1 instanceof HTMLElement && numberElement$1.dataset.columnNumber != null ? numberElement$1 : void 0;
|
|
192
|
+
})();
|
|
193
|
+
if (this.mode === "file") return {
|
|
194
|
+
type: "line",
|
|
195
|
+
lineElement,
|
|
196
|
+
lineNumber,
|
|
197
|
+
numberElement,
|
|
198
|
+
numberColumn
|
|
199
|
+
};
|
|
200
|
+
return {
|
|
201
|
+
type: "diff-line",
|
|
202
|
+
annotationSide: (() => {
|
|
203
|
+
if (lineType === "change-deletion") return "deletions";
|
|
204
|
+
if (lineType === "change-addition") return "additions";
|
|
205
|
+
const parent = lineElement.closest("[data-code]");
|
|
206
|
+
if (!(parent instanceof HTMLElement)) return "additions";
|
|
207
|
+
return "deletions" in parent.dataset ? "deletions" : "additions";
|
|
208
|
+
})(),
|
|
209
|
+
lineType,
|
|
210
|
+
lineElement,
|
|
211
|
+
numberElement,
|
|
212
|
+
lineNumber,
|
|
213
|
+
numberColumn
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
function debugLogIfEnabled(debugLogType = "none", logIfType, ...args) {
|
|
218
|
+
switch (debugLogType) {
|
|
219
|
+
case "none": return;
|
|
220
|
+
case "both": break;
|
|
221
|
+
case "click":
|
|
222
|
+
if (logIfType !== "click") return;
|
|
223
|
+
break;
|
|
224
|
+
case "move":
|
|
225
|
+
if (logIfType !== "move") return;
|
|
226
|
+
break;
|
|
227
|
+
}
|
|
228
|
+
console.log(...args);
|
|
229
|
+
}
|
|
230
|
+
function pluckMouseEventOptions({ onLineClick, onLineNumberClick, onLineEnter, onLineLeave, enableHoverUtility, __debugMouseEvents }, onHunkExpand) {
|
|
231
|
+
return {
|
|
232
|
+
onLineClick,
|
|
233
|
+
onLineNumberClick,
|
|
234
|
+
onLineEnter,
|
|
235
|
+
onLineLeave,
|
|
236
|
+
enableHoverUtility,
|
|
237
|
+
__debugMouseEvents,
|
|
238
|
+
onHunkExpand
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
//#endregion
|
|
243
|
+
export { MouseEventManager, pluckMouseEventOptions };
|
|
244
|
+
//# sourceMappingURL=MouseEventManager.js.map
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
//#region src/managers/ResizeManager.ts
|
|
2
|
+
var ResizeManager = class {
|
|
3
|
+
observedNodes = /* @__PURE__ */ new Map();
|
|
4
|
+
cleanUp() {
|
|
5
|
+
this.resizeObserver?.disconnect();
|
|
6
|
+
this.observedNodes.clear();
|
|
7
|
+
}
|
|
8
|
+
resizeObserver;
|
|
9
|
+
setup(pre) {
|
|
10
|
+
this.cleanUp();
|
|
11
|
+
const annotationElements = pre.querySelectorAll("[data-line-annotation*=\",\"]");
|
|
12
|
+
this.resizeObserver ??= new ResizeObserver(this.handleResizeObserver);
|
|
13
|
+
const codeElements = pre.querySelectorAll("code");
|
|
14
|
+
for (const codeElement of codeElements) {
|
|
15
|
+
let numberElement = codeElement.querySelector("[data-column-number]");
|
|
16
|
+
if (!(numberElement instanceof HTMLElement)) numberElement = null;
|
|
17
|
+
const item = {
|
|
18
|
+
type: "code",
|
|
19
|
+
codeElement,
|
|
20
|
+
numberElement,
|
|
21
|
+
codeWidth: "auto",
|
|
22
|
+
numberWidth: 0
|
|
23
|
+
};
|
|
24
|
+
this.observedNodes.set(codeElement, item);
|
|
25
|
+
this.resizeObserver.observe(codeElement);
|
|
26
|
+
if (numberElement != null) {
|
|
27
|
+
this.observedNodes.set(numberElement, item);
|
|
28
|
+
this.resizeObserver.observe(numberElement);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (codeElements.length <= 1) return;
|
|
32
|
+
const elementMap = /* @__PURE__ */ new Map();
|
|
33
|
+
for (const element of annotationElements) {
|
|
34
|
+
if (!(element instanceof HTMLElement)) continue;
|
|
35
|
+
const { lineAnnotation = "" } = element.dataset;
|
|
36
|
+
if (!/^\d+,\d+$/.test(lineAnnotation)) {
|
|
37
|
+
console.error("DiffFileRenderer.setupResizeObserver: Invalid element or annotation", {
|
|
38
|
+
lineAnnotation,
|
|
39
|
+
element
|
|
40
|
+
});
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
let pairs = elementMap.get(lineAnnotation);
|
|
44
|
+
if (pairs == null) {
|
|
45
|
+
pairs = [];
|
|
46
|
+
elementMap.set(lineAnnotation, pairs);
|
|
47
|
+
}
|
|
48
|
+
pairs.push(element);
|
|
49
|
+
}
|
|
50
|
+
for (const [key, pair] of elementMap) {
|
|
51
|
+
if (pair.length !== 2) {
|
|
52
|
+
console.error("DiffFileRenderer.setupResizeObserver: Bad Pair", key, pair);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const [container1, container2] = pair;
|
|
56
|
+
const child1 = container1.firstElementChild;
|
|
57
|
+
const child2 = container2.firstElementChild;
|
|
58
|
+
if (!(container1 instanceof HTMLElement) || !(container2 instanceof HTMLElement) || !(child1 instanceof HTMLElement) || !(child2 instanceof HTMLElement)) continue;
|
|
59
|
+
const item = {
|
|
60
|
+
type: "annotations",
|
|
61
|
+
column1: {
|
|
62
|
+
container: container1,
|
|
63
|
+
child: child1,
|
|
64
|
+
childHeight: 0
|
|
65
|
+
},
|
|
66
|
+
column2: {
|
|
67
|
+
container: container2,
|
|
68
|
+
child: child2,
|
|
69
|
+
childHeight: 0
|
|
70
|
+
},
|
|
71
|
+
currentHeight: "auto"
|
|
72
|
+
};
|
|
73
|
+
this.observedNodes.set(child1, item);
|
|
74
|
+
this.observedNodes.set(child2, item);
|
|
75
|
+
this.resizeObserver.observe(child1);
|
|
76
|
+
this.resizeObserver.observe(child2);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
handleResizeObserver = (entries) => {
|
|
80
|
+
for (const entry of entries) {
|
|
81
|
+
const { target, borderBoxSize } = entry;
|
|
82
|
+
if (!(target instanceof HTMLElement)) {
|
|
83
|
+
console.error("FileDiff.handleResizeObserver: Invalid element for ResizeObserver", entry);
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
const item = this.observedNodes.get(target);
|
|
87
|
+
if (item == null) {
|
|
88
|
+
console.error("FileDiff.handleResizeObserver: Not a valid observed node", entry);
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
const specs = borderBoxSize[0];
|
|
92
|
+
if (item.type === "annotations") {
|
|
93
|
+
const column = (() => {
|
|
94
|
+
if (target === item.column1.child) return item.column1;
|
|
95
|
+
if (target === item.column2.child) return item.column2;
|
|
96
|
+
})();
|
|
97
|
+
if (column == null) {
|
|
98
|
+
console.error(`FileDiff.handleResizeObserver: Couldn't find a column for`, {
|
|
99
|
+
item,
|
|
100
|
+
target
|
|
101
|
+
});
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
column.childHeight = specs.blockSize;
|
|
105
|
+
const newHeight = Math.max(item.column1.childHeight, item.column2.childHeight);
|
|
106
|
+
if (newHeight !== item.currentHeight) {
|
|
107
|
+
item.currentHeight = Math.max(newHeight, 0);
|
|
108
|
+
item.column1.container.style.setProperty("--diffs-annotation-min-height", `${item.currentHeight}px`);
|
|
109
|
+
item.column2.container.style.setProperty("--diffs-annotation-min-height", `${item.currentHeight}px`);
|
|
110
|
+
}
|
|
111
|
+
} else if (item.type === "code") {
|
|
112
|
+
if (target === item.codeElement) {
|
|
113
|
+
if (specs.inlineSize !== item.codeWidth) {
|
|
114
|
+
item.codeWidth = specs.inlineSize;
|
|
115
|
+
item.codeElement.style.setProperty("--diffs-column-content-width", `${Math.max(item.codeWidth - item.numberWidth, 0)}px`);
|
|
116
|
+
item.codeElement.style.setProperty("--diffs-column-width", `${item.codeWidth}px`);
|
|
117
|
+
}
|
|
118
|
+
} else if (target === item.numberElement) {
|
|
119
|
+
if (specs.inlineSize !== item.numberWidth) {
|
|
120
|
+
item.numberWidth = specs.inlineSize;
|
|
121
|
+
item.codeElement.style.setProperty("--diffs-column-number-width", `${item.numberWidth}px`);
|
|
122
|
+
if (item.codeWidth !== "auto") item.codeElement.style.setProperty("--diffs-column-content-width", `${Math.max(item.codeWidth - item.numberWidth, 0)}px`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
//#endregion
|
|
131
|
+
export { ResizeManager };
|
|
132
|
+
//# sourceMappingURL=ResizeManager.js.map
|