@pierre/diffs 1.3.6 → 1.4.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/CodeView.d.ts +115 -68
- package/dist/components/CodeView.d.ts.map +1 -1
- package/dist/components/CodeView.js +189 -59
- package/dist/components/CodeView.js.map +1 -1
- package/dist/components/File.d.ts +79 -15
- package/dist/components/File.d.ts.map +1 -1
- package/dist/components/File.js +244 -66
- package/dist/components/File.js.map +1 -1
- package/dist/components/FileDiff.d.ts +101 -21
- package/dist/components/FileDiff.d.ts.map +1 -1
- package/dist/components/FileDiff.js +432 -102
- package/dist/components/FileDiff.js.map +1 -1
- package/dist/components/FileStream.js +1 -1
- package/dist/components/UnresolvedFile.d.ts +2 -2
- package/dist/components/UnresolvedFile.d.ts.map +1 -1
- package/dist/components/UnresolvedFile.js +2 -2
- package/dist/components/UnresolvedFile.js.map +1 -1
- package/dist/components/VirtualizedFile.d.ts +17 -7
- package/dist/components/VirtualizedFile.d.ts.map +1 -1
- package/dist/components/VirtualizedFile.js +142 -53
- package/dist/components/VirtualizedFile.js.map +1 -1
- package/dist/components/VirtualizedFileDiff.d.ts +15 -8
- package/dist/components/VirtualizedFileDiff.d.ts.map +1 -1
- package/dist/components/VirtualizedFileDiff.js +186 -96
- package/dist/components/VirtualizedFileDiff.js.map +1 -1
- package/dist/components/VirtulizerDevelopment.d.ts +1 -1
- package/dist/components/VirtulizerDevelopment.d.ts.map +1 -1
- package/dist/edit/index.d.ts +7 -4
- package/dist/edit/index.js +5 -1
- package/dist/editor/EditStateManager.d.ts +56 -0
- package/dist/editor/EditStateManager.d.ts.map +1 -0
- package/dist/editor/EditStateManager.js +135 -0
- package/dist/editor/EditStateManager.js.map +1 -0
- package/dist/editor/cloneRetainedDiffSessionSnapshot.d.ts +7 -0
- package/dist/editor/cloneRetainedDiffSessionSnapshot.d.ts.map +1 -0
- package/dist/editor/cloneRetainedDiffSessionSnapshot.js +16 -0
- package/dist/editor/cloneRetainedDiffSessionSnapshot.js.map +1 -0
- package/dist/editor/editPrediction.d.ts +76 -0
- package/dist/editor/editPrediction.d.ts.map +1 -0
- package/dist/editor/editPrediction.js +365 -0
- package/dist/editor/editPrediction.js.map +1 -0
- package/dist/editor/editStack.d.ts +19 -40
- package/dist/editor/editStack.d.ts.map +1 -1
- package/dist/editor/editStack.js +67 -4
- package/dist/editor/editStack.js.map +1 -1
- package/dist/editor/editor.d.ts +118 -29
- package/dist/editor/editor.d.ts.map +1 -1
- package/dist/editor/editor.js +1108 -384
- package/dist/editor/editor.js.map +1 -1
- package/dist/editor/editor2.js +1 -1
- package/dist/editor/languages.d.ts +3 -3
- package/dist/editor/languages.d.ts.map +1 -1
- package/dist/editor/languages.js.map +1 -1
- package/dist/editor/lineAnnotations.d.ts +3 -3
- package/dist/editor/lineAnnotations.d.ts.map +1 -1
- package/dist/editor/lineAnnotations.js +16 -7
- package/dist/editor/lineAnnotations.js.map +1 -1
- package/dist/editor/marker.d.ts +2 -2
- package/dist/editor/marker.d.ts.map +1 -1
- package/dist/editor/marker.js.map +1 -1
- package/dist/editor/matchBrackets.d.ts +2 -2
- package/dist/editor/matchBrackets.d.ts.map +1 -1
- package/dist/editor/matchBrackets.js.map +1 -1
- package/dist/editor/pieceTable.d.ts +1 -1
- package/dist/editor/pieceTable.js.map +1 -1
- package/dist/editor/searchPanel.d.ts +2 -2
- package/dist/editor/searchPanel.js +1 -1
- package/dist/editor/searchPanel.js.map +1 -1
- package/dist/editor/selection.d.ts +32 -23
- package/dist/editor/selection.d.ts.map +1 -1
- package/dist/editor/selection.js +3 -3
- package/dist/editor/selection.js.map +1 -1
- package/dist/editor/selectionAction.d.ts +3 -3
- package/dist/editor/selectionAction.d.ts.map +1 -1
- package/dist/editor/selectionAction.js.map +1 -1
- package/dist/editor/textDocument.d.ts +11 -8
- package/dist/editor/textDocument.d.ts.map +1 -1
- package/dist/editor/textDocument.js +28 -5
- package/dist/editor/textDocument.js.map +1 -1
- package/dist/editor/textDocumentChangeTransaction.d.ts +15 -0
- package/dist/editor/textDocumentChangeTransaction.d.ts.map +1 -0
- package/dist/editor/textDocumentChangeTransaction.js +12 -0
- package/dist/editor/textDocumentChangeTransaction.js.map +1 -0
- package/dist/editor/textMeasure.d.ts +5 -0
- package/dist/editor/textMeasure.d.ts.map +1 -1
- package/dist/editor/textMeasure.js +10 -0
- package/dist/editor/textMeasure.js.map +1 -1
- package/dist/editor/tokenizer.d.ts +1 -1
- package/dist/editor/tokenizer.js.map +1 -1
- package/dist/editor/types.d.ts +267 -0
- package/dist/editor/types.d.ts.map +1 -0
- package/dist/editor/types.js +0 -0
- package/dist/editor/utils.d.ts +2 -1
- package/dist/editor/utils.d.ts.map +1 -1
- package/dist/editor/utils.js +4 -1
- package/dist/editor/utils.js.map +1 -1
- package/dist/highlighter/shared_highlighter.d.ts +6 -2
- package/dist/highlighter/shared_highlighter.d.ts.map +1 -1
- package/dist/highlighter/shared_highlighter.js +7 -3
- package/dist/highlighter/shared_highlighter.js.map +1 -1
- package/dist/highlighter/themes/areThemesAttached.js +1 -1
- package/dist/index.d.ts +8 -6
- package/dist/index.js +22 -21
- package/dist/managers/InteractionManager.d.ts.map +1 -1
- package/dist/managers/InteractionManager.js +7 -0
- package/dist/managers/InteractionManager.js.map +1 -1
- package/dist/react/CodeView.d.ts +36 -25
- package/dist/react/CodeView.d.ts.map +1 -1
- package/dist/react/CodeView.js +15 -14
- package/dist/react/CodeView.js.map +1 -1
- package/dist/react/EditContext.d.ts +8 -11
- package/dist/react/EditContext.d.ts.map +1 -1
- package/dist/react/EditContext.js +2 -9
- package/dist/react/EditContext.js.map +1 -1
- package/dist/react/File.d.ts +10 -6
- package/dist/react/File.d.ts.map +1 -1
- package/dist/react/File.js +8 -4
- package/dist/react/File.js.map +1 -1
- package/dist/react/FileDiff.d.ts +10 -5
- package/dist/react/FileDiff.d.ts.map +1 -1
- package/dist/react/FileDiff.js +8 -4
- package/dist/react/FileDiff.js.map +1 -1
- package/dist/react/MultiFileDiff.d.ts +8 -5
- package/dist/react/MultiFileDiff.d.ts.map +1 -1
- package/dist/react/MultiFileDiff.js +8 -12
- package/dist/react/MultiFileDiff.js.map +1 -1
- package/dist/react/PatchDiff.d.ts +7 -4
- package/dist/react/PatchDiff.d.ts.map +1 -1
- package/dist/react/PatchDiff.js +8 -4
- package/dist/react/PatchDiff.js.map +1 -1
- package/dist/react/UnresolvedFile.d.ts +3 -3
- package/dist/react/UnresolvedFile.d.ts.map +1 -1
- package/dist/react/UnresolvedFile.js.map +1 -1
- package/dist/react/index.d.ts +8 -5
- package/dist/react/types.d.ts +46 -9
- package/dist/react/types.d.ts.map +1 -1
- package/dist/react/utils/renderDiffChildren.d.ts +14 -12
- package/dist/react/utils/renderDiffChildren.d.ts.map +1 -1
- package/dist/react/utils/renderDiffChildren.js +2 -2
- package/dist/react/utils/renderDiffChildren.js.map +1 -1
- package/dist/react/utils/renderFileChildren.d.ts +14 -12
- package/dist/react/utils/renderFileChildren.d.ts.map +1 -1
- package/dist/react/utils/renderFileChildren.js +2 -2
- package/dist/react/utils/renderFileChildren.js.map +1 -1
- package/dist/react/utils/useFileDiffInstance.d.ts +22 -10
- package/dist/react/utils/useFileDiffInstance.d.ts.map +1 -1
- package/dist/react/utils/useFileDiffInstance.js +112 -22
- package/dist/react/utils/useFileDiffInstance.js.map +1 -1
- package/dist/react/utils/useFileInstance.d.ts +15 -9
- package/dist/react/utils/useFileInstance.d.ts.map +1 -1
- package/dist/react/utils/useFileInstance.js +84 -25
- package/dist/react/utils/useFileInstance.js.map +1 -1
- package/dist/renderers/DiffHunksRenderer.d.ts +30 -15
- package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
- package/dist/renderers/DiffHunksRenderer.js +172 -109
- package/dist/renderers/DiffHunksRenderer.js.map +1 -1
- package/dist/renderers/FileRenderer.d.ts +27 -11
- package/dist/renderers/FileRenderer.d.ts.map +1 -1
- package/dist/renderers/FileRenderer.js +141 -67
- package/dist/renderers/FileRenderer.js.map +1 -1
- package/dist/renderers/UnresolvedFileHunksRenderer.d.ts +2 -2
- 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/shiki-stream/tokenizer.d.ts.map +1 -1
- package/dist/shiki-stream/tokenizer.js +2 -1
- package/dist/shiki-stream/tokenizer.js.map +1 -1
- package/dist/ssr/index.d.ts +2 -2
- package/dist/ssr/preloadDiffs.d.ts +21 -21
- package/dist/ssr/preloadDiffs.d.ts.map +1 -1
- package/dist/ssr/preloadDiffs.js +1 -1
- package/dist/ssr/preloadDiffs.js.map +1 -1
- package/dist/ssr/preloadFile.d.ts +6 -6
- package/dist/ssr/preloadFile.d.ts.map +1 -1
- package/dist/ssr/preloadFile.js.map +1 -1
- package/dist/ssr/preloadPatchFile.d.ts +4 -4
- package/dist/ssr/preloadPatchFile.d.ts.map +1 -1
- package/dist/ssr/preloadPatchFile.js.map +1 -1
- package/dist/style.js +1 -1
- package/dist/types.d.ts +13 -263
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/appendItems.d.ts +5 -0
- package/dist/utils/appendItems.d.ts.map +1 -0
- package/dist/utils/appendItems.js +8 -0
- package/dist/utils/appendItems.js.map +1 -0
- package/dist/utils/areDiffTargetsEqual.js +1 -1
- package/dist/utils/areDiffTargetsEqual.js.map +1 -1
- package/dist/utils/areFileTargetsEqual.d.ts +7 -0
- package/dist/utils/areFileTargetsEqual.d.ts.map +1 -0
- package/dist/utils/areFileTargetsEqual.js +8 -0
- package/dist/utils/areFileTargetsEqual.js.map +1 -0
- package/dist/utils/areManagedSnapshotsEqual.d.ts +1 -1
- package/dist/utils/areManagedSnapshotsEqual.d.ts.map +1 -1
- package/dist/utils/areManagedSnapshotsEqual.js.map +1 -1
- package/dist/utils/areOptionsEqual.d.ts +3 -3
- package/dist/utils/areOptionsEqual.d.ts.map +1 -1
- package/dist/utils/areOptionsEqual.js.map +1 -1
- package/dist/utils/cloneFileDiffMetadata.d.ts +3 -2
- package/dist/utils/cloneFileDiffMetadata.d.ts.map +1 -1
- package/dist/utils/cloneFileDiffMetadata.js +8 -5
- package/dist/utils/cloneFileDiffMetadata.js.map +1 -1
- package/dist/utils/composeCacheKey.d.ts +6 -0
- package/dist/utils/composeCacheKey.d.ts.map +1 -0
- package/dist/utils/composeCacheKey.js +10 -0
- package/dist/utils/composeCacheKey.js.map +1 -0
- package/dist/utils/editSessionAnnotations.d.ts +69 -0
- package/dist/utils/editSessionAnnotations.d.ts.map +1 -0
- package/dist/utils/editSessionAnnotations.js +64 -0
- package/dist/utils/editSessionAnnotations.js.map +1 -0
- package/dist/utils/editSessionHunks.d.ts +5 -3
- package/dist/utils/editSessionHunks.d.ts.map +1 -1
- package/dist/utils/editSessionHunks.js +7 -5
- package/dist/utils/editSessionHunks.js.map +1 -1
- package/dist/utils/getDiffHunksRendererOptions.d.ts +1 -1
- package/dist/utils/getDiffHunksRendererOptions.d.ts.map +1 -1
- package/dist/utils/getDiffHunksRendererOptions.js.map +1 -1
- package/dist/utils/getFileRendererOptions.d.ts +1 -1
- package/dist/utils/getFileRendererOptions.d.ts.map +1 -1
- package/dist/utils/getFileRendererOptions.js.map +1 -1
- package/dist/utils/hydratePartialDiff.d.ts.map +1 -1
- package/dist/utils/hydratePartialDiff.js +2 -1
- package/dist/utils/hydratePartialDiff.js.map +1 -1
- package/dist/utils/lineAnnotationIdentity.d.ts +16 -0
- package/dist/utils/lineAnnotationIdentity.d.ts.map +1 -0
- package/dist/utils/lineAnnotationIdentity.js +17 -0
- package/dist/utils/lineAnnotationIdentity.js.map +1 -0
- package/dist/utils/parseDiffFromFile.d.ts +2 -2
- package/dist/utils/parseDiffFromFile.d.ts.map +1 -1
- package/dist/utils/parseDiffFromFile.js +6 -6
- package/dist/utils/parseDiffFromFile.js.map +1 -1
- package/dist/utils/parsePatchFiles.d.ts +6 -3
- package/dist/utils/parsePatchFiles.d.ts.map +1 -1
- package/dist/utils/parsePatchFiles.js +34 -9
- package/dist/utils/parsePatchFiles.js.map +1 -1
- package/dist/utils/renderDiffWithHighlighter.d.ts.map +1 -1
- package/dist/utils/renderDiffWithHighlighter.js +6 -5
- package/dist/utils/renderDiffWithHighlighter.js.map +1 -1
- package/dist/utils/renderFileWithHighlighter.d.ts.map +1 -1
- package/dist/utils/renderFileWithHighlighter.js +7 -4
- package/dist/utils/renderFileWithHighlighter.js.map +1 -1
- package/dist/utils/trimPatchContext.d.ts.map +1 -1
- package/dist/utils/trimPatchContext.js +3 -2
- package/dist/utils/trimPatchContext.js.map +1 -1
- package/dist/utils/updateDiffHunks.js +1 -1
- package/dist/utils/virtualDiffLayout.js +1 -1
- package/dist/worker/WorkerPoolManager.d.ts +4 -3
- package/dist/worker/WorkerPoolManager.d.ts.map +1 -1
- package/dist/worker/WorkerPoolManager.js +44 -6
- package/dist/worker/WorkerPoolManager.js.map +1 -1
- package/dist/worker/types.d.ts +5 -0
- package/dist/worker/types.d.ts.map +1 -1
- package/dist/worker/worker-portable.js +14 -6
- package/dist/worker/worker-portable.js.map +1 -1
- package/dist/worker/worker.js +14 -6
- package/dist/worker/worker.js.map +1 -1
- package/package.json +9 -1
- package/dist/editor/stateStorage.d.ts +0 -15
- package/dist/editor/stateStorage.d.ts.map +0 -1
- package/dist/editor/stateStorage.js +0 -65
- package/dist/editor/stateStorage.js.map +0 -1
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { DEFAULT_CODE_VIEW_FILE_METRICS, DEFAULT_CODE_VIEW_LAYOUT, DEFAULT_SMOOTH_SCROLL_SETTINGS, DEFAULT_THEMES, DIFFS_DEVELOPMENT_BUILD, DIFFS_TAG_NAME } from "../constants.js";
|
|
2
|
+
import { getThemes } from "../utils/getThemes.js";
|
|
3
|
+
import { areThemesAttached } from "../highlighter/themes/areThemesAttached.js";
|
|
4
|
+
import { isHighlighterLoaded, preloadHighlighter } from "../highlighter/shared_highlighter.js";
|
|
2
5
|
import { dequeueRender, queueRender } from "../managers/UniversalRenderingManager.js";
|
|
3
6
|
import { areManagedSnapshotsEqual } from "../utils/areManagedSnapshotsEqual.js";
|
|
4
7
|
import { areObjectsEqual } from "../utils/areObjectsEqual.js";
|
|
@@ -7,7 +10,6 @@ import { areOptionsEqual } from "../utils/areOptionsEqual.js";
|
|
|
7
10
|
import { areSelectionsEqual } from "../utils/areSelectionsEqual.js";
|
|
8
11
|
import { createCodeViewHeaderFooterHostElement } from "../utils/createCodeViewHeaderFooterHostElement.js";
|
|
9
12
|
import { createWindowFromScrollPosition } from "../utils/createWindowFromScrollPosition.js";
|
|
10
|
-
import { finishEditSessionForDiff } from "../utils/editSessionHunks.js";
|
|
11
13
|
import { isStyleNode } from "../utils/isStyleNode.js";
|
|
12
14
|
import { prefersReducedMotion } from "../utils/prefersReducedMotion.js";
|
|
13
15
|
import { roundToDevicePixel } from "../utils/roundToDevicePixel.js";
|
|
@@ -198,6 +200,7 @@ var CodeView = class CodeView {
|
|
|
198
200
|
options;
|
|
199
201
|
workerManager;
|
|
200
202
|
isReadySubscription;
|
|
203
|
+
pendingHighlighterTheme;
|
|
201
204
|
isContainerManaged;
|
|
202
205
|
constructor(options = { theme: DEFAULT_THEMES }, workerManager, isContainerManaged = false) {
|
|
203
206
|
this.options = options;
|
|
@@ -402,13 +405,31 @@ var CodeView = class CodeView {
|
|
|
402
405
|
this.clearReadySubscription();
|
|
403
406
|
this.restoreScrollInteractions();
|
|
404
407
|
this.cleanAllRenderedItems();
|
|
405
|
-
|
|
408
|
+
const teardownSessions = [...this.itemEditors.values()].map((record) => {
|
|
409
|
+
const item = this.idToItem.get(record.state.id);
|
|
410
|
+
if (item != null) record.state.removedItem = item.item;
|
|
411
|
+
return {
|
|
412
|
+
record,
|
|
413
|
+
instance: item?.instance
|
|
414
|
+
};
|
|
415
|
+
});
|
|
406
416
|
this.itemEditors.clear();
|
|
407
417
|
this.attachedEditors.clear();
|
|
408
418
|
this.selectedLines = null;
|
|
409
419
|
this.items.length = 0;
|
|
410
420
|
this.idToItem.clear();
|
|
411
421
|
this.instanceToItem.clear();
|
|
422
|
+
let failed = false;
|
|
423
|
+
let failure;
|
|
424
|
+
for (const { record, instance } of teardownSessions) try {
|
|
425
|
+
record.editor.cleanUp("discard");
|
|
426
|
+
instance?.cleanUp();
|
|
427
|
+
} catch (error) {
|
|
428
|
+
if (!failed) {
|
|
429
|
+
failed = true;
|
|
430
|
+
failure = error;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
412
433
|
this.layoutDirtyIndex = void 0;
|
|
413
434
|
this.pendingLayoutReset = void 0;
|
|
414
435
|
this.stickyContainer.textContent = "";
|
|
@@ -429,9 +450,17 @@ var CodeView = class CodeView {
|
|
|
429
450
|
this.heightDirty = true;
|
|
430
451
|
this.resetRenderState();
|
|
431
452
|
if (!this.isContainerManaged) this.flushSlotCoordinator();
|
|
453
|
+
if (failed) throw failure;
|
|
432
454
|
}
|
|
433
455
|
cleanUp() {
|
|
434
|
-
|
|
456
|
+
let resetFailed = false;
|
|
457
|
+
let resetFailure;
|
|
458
|
+
try {
|
|
459
|
+
this.reset();
|
|
460
|
+
} catch (error) {
|
|
461
|
+
resetFailed = true;
|
|
462
|
+
resetFailure = error;
|
|
463
|
+
}
|
|
435
464
|
this.clearElementPool();
|
|
436
465
|
this.restoreScrollInteractions();
|
|
437
466
|
this.workerManager?.unsubscribeToThemeChanges(this);
|
|
@@ -457,6 +486,7 @@ var CodeView = class CodeView {
|
|
|
457
486
|
this.footer.height = 0;
|
|
458
487
|
this.root = void 0;
|
|
459
488
|
this.container = void 0;
|
|
489
|
+
if (resetFailed) throw resetFailure;
|
|
460
490
|
}
|
|
461
491
|
cleanAllRenderedItems() {
|
|
462
492
|
if (this.renderState.firstIndex === -1) return;
|
|
@@ -585,7 +615,8 @@ var CodeView = class CodeView {
|
|
|
585
615
|
/**
|
|
586
616
|
* Get the live editor for an item currently in edit mode. Use this to drive
|
|
587
617
|
* editor APIs CodeView does not wrap (applyEdits, undo, setMarkers, …).
|
|
588
|
-
* Returns undefined once the item
|
|
618
|
+
* Returns undefined once the item's session ends (edit off or removal); a
|
|
619
|
+
* collapsed item keeps its suspended editor.
|
|
589
620
|
*/
|
|
590
621
|
getEditor(itemId) {
|
|
591
622
|
return this.itemEditors.get(itemId)?.editor;
|
|
@@ -628,7 +659,6 @@ var CodeView = class CodeView {
|
|
|
628
659
|
}
|
|
629
660
|
const editorRecord = this.itemEditors.get(oldId);
|
|
630
661
|
if (editorRecord != null) {
|
|
631
|
-
editorRecord.state.id = newId;
|
|
632
662
|
this.itemEditors.delete(oldId);
|
|
633
663
|
this.itemEditors.set(newId, editorRecord);
|
|
634
664
|
if (this.attachedEditors.delete(oldId)) this.attachedEditors.add(newId);
|
|
@@ -741,7 +771,8 @@ var CodeView = class CodeView {
|
|
|
741
771
|
}
|
|
742
772
|
isReady() {
|
|
743
773
|
const { workerManager } = this;
|
|
744
|
-
if (workerManager == null || workerManager.
|
|
774
|
+
if (workerManager == null || workerManager.getStats().workersFailed) return this.isSharedHighlighterReady();
|
|
775
|
+
if (workerManager.isInitialized()) {
|
|
745
776
|
this.clearReadySubscription();
|
|
746
777
|
return true;
|
|
747
778
|
}
|
|
@@ -757,6 +788,36 @@ var CodeView = class CodeView {
|
|
|
757
788
|
if (this.isReadySubscription == null) return;
|
|
758
789
|
this.isReadySubscription();
|
|
759
790
|
this.isReadySubscription = void 0;
|
|
791
|
+
this.pendingHighlighterTheme = void 0;
|
|
792
|
+
}
|
|
793
|
+
isSharedHighlighterReady() {
|
|
794
|
+
const theme = this.workerManager?.getFileRenderOptions().theme ?? this.options.theme ?? DEFAULT_THEMES;
|
|
795
|
+
if (isHighlighterLoaded() && areThemesAttached(theme)) {
|
|
796
|
+
this.clearReadySubscription();
|
|
797
|
+
return true;
|
|
798
|
+
}
|
|
799
|
+
if (!areThemesEqual(this.pendingHighlighterTheme, theme)) this.clearReadySubscription();
|
|
800
|
+
this.isReadySubscription ??= (() => {
|
|
801
|
+
this.pendingHighlighterTheme = theme;
|
|
802
|
+
let cancelled = false;
|
|
803
|
+
preloadHighlighter({
|
|
804
|
+
themes: getThemes(theme),
|
|
805
|
+
langs: [],
|
|
806
|
+
preferredHighlighter: this.options.preferredHighlighter
|
|
807
|
+
}).then(() => {
|
|
808
|
+
if (cancelled) return;
|
|
809
|
+
this.clearReadySubscription();
|
|
810
|
+
this.render(true);
|
|
811
|
+
}, (error) => {
|
|
812
|
+
if (cancelled) return;
|
|
813
|
+
this.clearReadySubscription();
|
|
814
|
+
console.error(error);
|
|
815
|
+
});
|
|
816
|
+
return () => {
|
|
817
|
+
cancelled = true;
|
|
818
|
+
};
|
|
819
|
+
})();
|
|
820
|
+
return false;
|
|
760
821
|
}
|
|
761
822
|
instanceChanged(instance, layoutDirty) {
|
|
762
823
|
const item = this.instanceToItem.get(instance);
|
|
@@ -888,58 +949,63 @@ var CodeView = class CodeView {
|
|
|
888
949
|
return item.item.edit === true && item.item.collapsed !== true;
|
|
889
950
|
}
|
|
890
951
|
/**
|
|
891
|
-
*
|
|
952
|
+
* Lazily create and attach the editor for a mounted edit-mode item. Called
|
|
892
953
|
* from the render loop so every mounted item passes through it: fresh
|
|
893
954
|
* mounts, remounts after virtualization released the item, and items whose
|
|
894
955
|
* edit flag was just turned on. Editors persist across unmounts, so a
|
|
895
|
-
* remounted item
|
|
896
|
-
*
|
|
897
|
-
*
|
|
956
|
+
* remounted item resumes its existing editor and retained document; the
|
|
957
|
+
* instance retains its private session model so the remount
|
|
958
|
+
* paints the edited text without changing the host input.
|
|
898
959
|
*/
|
|
899
960
|
attachItemEditor(item) {
|
|
900
961
|
const { id } = item.item;
|
|
901
962
|
const { createEditor } = this.options;
|
|
902
963
|
if (item.element == null || this.attachedEditors.has(id) || !this.isItemInEditMode(item)) return;
|
|
903
|
-
|
|
904
|
-
let createdEditor
|
|
964
|
+
const record = this.itemEditors.get(id);
|
|
965
|
+
let createdEditor;
|
|
905
966
|
try {
|
|
906
967
|
if (record == null) {
|
|
907
968
|
assertEditorFactory(createEditor);
|
|
908
|
-
const state =
|
|
909
|
-
|
|
969
|
+
const state = getItemOptionsState(item.instance.options);
|
|
970
|
+
if (state == null) throw new Error("CodeView.attachItemEditor: instance options are missing their state");
|
|
971
|
+
const onChange = (event) => {
|
|
910
972
|
const latest = this.idToItem.get(state.id);
|
|
911
973
|
if (latest == null) return;
|
|
912
|
-
|
|
913
|
-
item: latest.item,
|
|
914
|
-
file,
|
|
915
|
-
lineAnnotations
|
|
916
|
-
};
|
|
917
|
-
this.options.onItemEditChange?.(latest.item, file, lineAnnotations);
|
|
918
|
-
} });
|
|
919
|
-
if (editor == null) return;
|
|
920
|
-
record = {
|
|
921
|
-
editor,
|
|
922
|
-
state
|
|
974
|
+
this.options.onItemEditChange?.(event, latest.item);
|
|
923
975
|
};
|
|
924
|
-
this.
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
976
|
+
const editStateKey = this.options.getEditStateKey?.(item.item);
|
|
977
|
+
if (item.type === "diff") {
|
|
978
|
+
const editor = createEditor("file-diff", { onChange }, editStateKey);
|
|
979
|
+
createdEditor = editor;
|
|
980
|
+
this.itemEditors.set(id, {
|
|
981
|
+
editor,
|
|
982
|
+
state,
|
|
983
|
+
dispose: editor.edit(item.instance)
|
|
984
|
+
});
|
|
985
|
+
} else {
|
|
986
|
+
const editor = createEditor("file", { onChange }, editStateKey);
|
|
987
|
+
createdEditor = editor;
|
|
988
|
+
this.itemEditors.set(id, {
|
|
989
|
+
editor,
|
|
990
|
+
state,
|
|
991
|
+
dispose: editor.edit(item.instance)
|
|
992
|
+
});
|
|
993
|
+
}
|
|
994
|
+
} else if (item.type === "diff") record.dispose = record.editor.edit(item.instance);
|
|
995
|
+
else record.dispose = record.editor.edit(item.instance);
|
|
928
996
|
this.attachedEditors.add(id);
|
|
929
997
|
} catch (error) {
|
|
930
|
-
|
|
931
|
-
this.itemEditors.delete(id);
|
|
932
|
-
record.editor.cleanUp();
|
|
933
|
-
}
|
|
998
|
+
createdEditor?.cleanUp();
|
|
934
999
|
this.releaseRenderedItem(item);
|
|
935
1000
|
throw error;
|
|
936
1001
|
}
|
|
937
1002
|
}
|
|
938
1003
|
/**
|
|
939
|
-
*
|
|
940
|
-
* off
|
|
941
|
-
*
|
|
942
|
-
*
|
|
1004
|
+
* Reconcile the editors CodeView is holding: complete sessions for items
|
|
1005
|
+
* whose edit turned off or that were removed, and suspend sessions for
|
|
1006
|
+
* collapsed items (the editor tears down, the record and the instance's
|
|
1007
|
+
* session stay for the next expand). Attachment happens in the render loop
|
|
1008
|
+
* via attachItemEditor.
|
|
943
1009
|
*/
|
|
944
1010
|
syncItemEditors(removedItems) {
|
|
945
1011
|
if (this.itemEditors.size === 0) return;
|
|
@@ -947,25 +1013,77 @@ var CodeView = class CodeView {
|
|
|
947
1013
|
for (const [id, record] of this.itemEditors) {
|
|
948
1014
|
const item = this.idToItem.get(id);
|
|
949
1015
|
const removedItem = removedItems?.get(id);
|
|
950
|
-
if (removedItem == null && item != null
|
|
951
|
-
|
|
1016
|
+
if (removedItem == null && item != null) {
|
|
1017
|
+
const { edit = false, collapsed = false } = item.item;
|
|
1018
|
+
if (edit) {
|
|
1019
|
+
if (collapsed && this.attachedEditors.delete(id)) record.editor.cleanUp("recycle");
|
|
1020
|
+
continue;
|
|
1021
|
+
}
|
|
1022
|
+
} else if (removedItem != null) record.state.removedItem = removedItem.item;
|
|
952
1023
|
this.itemEditors.delete(id);
|
|
953
1024
|
this.attachedEditors.delete(id);
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
1025
|
+
completions.push(record);
|
|
1026
|
+
}
|
|
1027
|
+
if (completions.length === 0) return;
|
|
1028
|
+
let failed = false;
|
|
1029
|
+
let failure;
|
|
1030
|
+
for (const record of completions) {
|
|
1031
|
+
try {
|
|
1032
|
+
record.dispose();
|
|
1033
|
+
} catch (error) {
|
|
1034
|
+
if (!failed) {
|
|
1035
|
+
failed = true;
|
|
1036
|
+
failure = error;
|
|
960
1037
|
}
|
|
961
|
-
finishEditSessionForDiff(itemSnapshot.fileDiff);
|
|
962
1038
|
}
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
item: item.item
|
|
966
|
-
});
|
|
1039
|
+
const item = this.idToItem.get(record.state.id);
|
|
1040
|
+
if (item != null) this.markItemLayoutDirty(item);
|
|
967
1041
|
}
|
|
968
|
-
|
|
1042
|
+
this.render();
|
|
1043
|
+
if (failed) throw failure;
|
|
1044
|
+
}
|
|
1045
|
+
requireItemFromState(state) {
|
|
1046
|
+
const item = this.idToItem.get(state.id)?.item ?? state.removedItem;
|
|
1047
|
+
if (item == null) throw new Error(`CodeView.onItemEditComplete: unknown item "${state.id}"`);
|
|
1048
|
+
return item;
|
|
1049
|
+
}
|
|
1050
|
+
/**
|
|
1051
|
+
* Item-instance `onEditComplete` adapter for file items: builds the
|
|
1052
|
+
* accepted next item, hands it to `onItemEditComplete` alongside the event
|
|
1053
|
+
* and the owning item, and translates the identity of the returned item to
|
|
1054
|
+
* the component return contract.
|
|
1055
|
+
*/
|
|
1056
|
+
completeFileItemEdit(state, event) {
|
|
1057
|
+
const item = this.requireItemFromState(state);
|
|
1058
|
+
if (item.type !== "file") throw new Error(`CodeView.onItemEditComplete: item "${state.id}" is not a file item`);
|
|
1059
|
+
const nextItem = {
|
|
1060
|
+
...item,
|
|
1061
|
+
file: event.file,
|
|
1062
|
+
annotations: event.lineAnnotations,
|
|
1063
|
+
edit: false,
|
|
1064
|
+
version: (item.version ?? 0) + 1
|
|
1065
|
+
};
|
|
1066
|
+
if ((this.options.onItemEditComplete?.(event, item, nextItem) ?? "reject") === "reject") return "reject";
|
|
1067
|
+
if (this.idToItem.has(item.id)) this.updateItem(nextItem);
|
|
1068
|
+
return "accept";
|
|
1069
|
+
}
|
|
1070
|
+
/**
|
|
1071
|
+
* Item-instance `onEditComplete` adapter for diff items; see
|
|
1072
|
+
* completeFileItemEdit.
|
|
1073
|
+
*/
|
|
1074
|
+
completeDiffItemEdit(state, event) {
|
|
1075
|
+
const item = this.requireItemFromState(state);
|
|
1076
|
+
if (item.type !== "diff") throw new Error(`CodeView.onItemEditComplete: item "${state.id}" is not a diff item`);
|
|
1077
|
+
const nextItem = {
|
|
1078
|
+
...item,
|
|
1079
|
+
fileDiff: event.fileDiff,
|
|
1080
|
+
annotations: event.lineAnnotations,
|
|
1081
|
+
edit: false,
|
|
1082
|
+
version: (item.version ?? 0) + 1
|
|
1083
|
+
};
|
|
1084
|
+
if ((this.options.onItemEditComplete?.(event, item, nextItem) ?? "reject") === "reject") return "reject";
|
|
1085
|
+
if (this.idToItem.has(item.id)) this.updateItem(nextItem);
|
|
1086
|
+
return "accept";
|
|
969
1087
|
}
|
|
970
1088
|
renamePendingScrollTarget(oldId, newId) {
|
|
971
1089
|
const { pendingScrollTarget } = this;
|
|
@@ -987,6 +1105,12 @@ var CodeView = class CodeView {
|
|
|
987
1105
|
if (state == null) return;
|
|
988
1106
|
return this.getItemOptions(state, "file")?.item.collapsed;
|
|
989
1107
|
});
|
|
1108
|
+
defineItemOption(prototype, "onEditComplete", (receiver) => {
|
|
1109
|
+
if (this.options.onItemEditComplete == null) return;
|
|
1110
|
+
const state = getItemOptionsState(receiver);
|
|
1111
|
+
if (state == null) return;
|
|
1112
|
+
return (event) => this.completeFileItemEdit(state, event);
|
|
1113
|
+
});
|
|
990
1114
|
for (const key of CODE_VIEW_SHARED_CALLBACK_KEYS) this.defineItemSharedCallback(prototype, "file", key);
|
|
991
1115
|
for (const key of CODE_VIEW_SELECTION_CALLBACK_KEYS) this.defineItemSelectionCallback(prototype, "file", key);
|
|
992
1116
|
return prototype;
|
|
@@ -1001,6 +1125,12 @@ var CodeView = class CodeView {
|
|
|
1001
1125
|
if (state == null) return;
|
|
1002
1126
|
return this.getItemOptions(state, "diff")?.item.collapsed;
|
|
1003
1127
|
});
|
|
1128
|
+
defineItemOption(prototype, "onEditComplete", (receiver) => {
|
|
1129
|
+
if (this.options.onItemEditComplete == null) return;
|
|
1130
|
+
const state = getItemOptionsState(receiver);
|
|
1131
|
+
if (state == null) return;
|
|
1132
|
+
return (event) => this.completeDiffItemEdit(state, event);
|
|
1133
|
+
});
|
|
1004
1134
|
for (const key of CODE_VIEW_SHARED_CALLBACK_KEYS) this.defineItemSharedCallback(prototype, "diff", key);
|
|
1005
1135
|
for (const key of CODE_VIEW_SELECTION_CALLBACK_KEYS) this.defineItemSelectionCallback(prototype, "diff", key);
|
|
1006
1136
|
return prototype;
|
|
@@ -1598,7 +1728,10 @@ var CodeView = class CodeView {
|
|
|
1598
1728
|
syncPagedScrollScaffolding(windowSpecs) {
|
|
1599
1729
|
this.syncContainerHeight();
|
|
1600
1730
|
const stickyBounds = this.getStickyBounds(windowSpecs);
|
|
1601
|
-
if (stickyBounds == null)
|
|
1731
|
+
if (stickyBounds == null) {
|
|
1732
|
+
this.stickyOffset.style.height = `${this.getPagedLayoutTop(windowSpecs.top)}px`;
|
|
1733
|
+
return;
|
|
1734
|
+
}
|
|
1602
1735
|
this.applyStickyPositioning(stickyBounds);
|
|
1603
1736
|
}
|
|
1604
1737
|
reconcileRenderedItems(updatedItems) {
|
|
@@ -1910,11 +2043,8 @@ var CodeView = class CodeView {
|
|
|
1910
2043
|
const item = this.items[index];
|
|
1911
2044
|
if (item == null) throw new Error("CodeView.recomputeLayout: invalid item index");
|
|
1912
2045
|
item.top = runningTop;
|
|
1913
|
-
if (item.type === "diff")
|
|
1914
|
-
|
|
1915
|
-
if (fileDiff != null) Object.assign(item.item.fileDiff, fileDiff);
|
|
1916
|
-
item.height = item.instance.prepareCodeViewItem(item.item.fileDiff, runningTop, reset, item.item.annotations ?? []);
|
|
1917
|
-
} else item.height = item.instance.prepareCodeViewItem(item.item.file, runningTop, reset, item.item.annotations ?? []);
|
|
2046
|
+
if (item.type === "diff") item.height = item.instance.updateCodeViewLayout(item.item.fileDiff, runningTop, reset, item.item.annotations ?? []);
|
|
2047
|
+
else item.height = item.instance.updateCodeViewLayout(item.item.file, runningTop, reset, item.item.annotations ?? []);
|
|
1918
2048
|
runningTop += item.height;
|
|
1919
2049
|
if (index < this.items.length - 1) runningTop += layout.gap;
|
|
1920
2050
|
}
|
|
@@ -1935,8 +2065,8 @@ var CodeView = class CodeView {
|
|
|
1935
2065
|
};
|
|
1936
2066
|
function prepareItemInstance(item) {
|
|
1937
2067
|
item.instance.cleanUp(true);
|
|
1938
|
-
if (item.type === "diff") return item.instance.
|
|
1939
|
-
else return item.instance.
|
|
2068
|
+
if (item.type === "diff") return item.instance.updateCodeViewLayout(item.item.fileDiff, item.top, void 0, item.item.annotations ?? []);
|
|
2069
|
+
else return item.instance.updateCodeViewLayout(item.item.file, item.top, void 0, item.item.annotations ?? []);
|
|
1940
2070
|
}
|
|
1941
2071
|
function shouldClearPool(previousOptions, nextOptions) {
|
|
1942
2072
|
return !areThemesEqual(previousOptions.theme ?? DEFAULT_THEMES, nextOptions.theme ?? DEFAULT_THEMES) || (previousOptions.themeType ?? "system") !== (nextOptions.themeType ?? "system") || previousOptions.unsafeCSS !== nextOptions.unsafeCSS;
|