@pierre/diffs 1.6.0-beta.1 → 1.6.0

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 (151) hide show
  1. package/dist/components/CodeView.d.ts +3 -2
  2. package/dist/components/CodeView.d.ts.map +1 -1
  3. package/dist/components/CodeView.js +18 -14
  4. package/dist/components/CodeView.js.map +1 -1
  5. package/dist/components/File.d.ts +31 -9
  6. package/dist/components/File.d.ts.map +1 -1
  7. package/dist/components/File.js +165 -84
  8. package/dist/components/File.js.map +1 -1
  9. package/dist/components/FileDiff.d.ts +32 -9
  10. package/dist/components/FileDiff.d.ts.map +1 -1
  11. package/dist/components/FileDiff.js +213 -124
  12. package/dist/components/FileDiff.js.map +1 -1
  13. package/dist/components/UnresolvedFile.d.ts +14 -4
  14. package/dist/components/UnresolvedFile.d.ts.map +1 -1
  15. package/dist/components/UnresolvedFile.js +35 -16
  16. package/dist/components/UnresolvedFile.js.map +1 -1
  17. package/dist/components/VirtualizedFile.d.ts +3 -2
  18. package/dist/components/VirtualizedFile.d.ts.map +1 -1
  19. package/dist/components/VirtualizedFile.js +28 -20
  20. package/dist/components/VirtualizedFile.js.map +1 -1
  21. package/dist/components/VirtualizedFileDiff.d.ts +3 -2
  22. package/dist/components/VirtualizedFileDiff.d.ts.map +1 -1
  23. package/dist/components/VirtualizedFileDiff.js +31 -24
  24. package/dist/components/VirtualizedFileDiff.js.map +1 -1
  25. package/dist/constants.d.ts +2 -1
  26. package/dist/constants.d.ts.map +1 -1
  27. package/dist/constants.js +2 -1
  28. package/dist/constants.js.map +1 -1
  29. package/dist/editor/platform.d.ts +1 -1
  30. package/dist/editor/platform.js +5 -4
  31. package/dist/editor/platform.js.map +1 -1
  32. package/dist/editor/selection.d.ts +2 -2
  33. package/dist/editor/selection.d.ts.map +1 -1
  34. package/dist/editor/selection.js +31 -6
  35. package/dist/editor/selection.js.map +1 -1
  36. package/dist/highlighter/shared_highlighter.d.ts +2 -1
  37. package/dist/highlighter/shared_highlighter.d.ts.map +1 -1
  38. package/dist/highlighter/shared_highlighter.js +2 -2
  39. package/dist/highlighter/shared_highlighter.js.map +1 -1
  40. package/dist/index.d.ts +10 -5
  41. package/dist/index.js +8 -3
  42. package/dist/react/CodeView.d.ts +4 -3
  43. package/dist/react/CodeView.d.ts.map +1 -1
  44. package/dist/react/CodeView.js +48 -39
  45. package/dist/react/CodeView.js.map +1 -1
  46. package/dist/react/File.js +3 -3
  47. package/dist/react/File.js.map +1 -1
  48. package/dist/react/FileDiff.js +3 -3
  49. package/dist/react/FileDiff.js.map +1 -1
  50. package/dist/react/MultiFileDiff.js +2 -2
  51. package/dist/react/MultiFileDiff.js.map +1 -1
  52. package/dist/react/PatchDiff.js +3 -3
  53. package/dist/react/PatchDiff.js.map +1 -1
  54. package/dist/react/UnresolvedFile.js +2 -2
  55. package/dist/react/UnresolvedFile.js.map +1 -1
  56. package/dist/react/index.d.ts +2 -2
  57. package/dist/react/types.d.ts +4 -2
  58. package/dist/react/types.d.ts.map +1 -1
  59. package/dist/react/utils/renderDiffChildren.js +1 -1
  60. package/dist/react/utils/renderDiffChildren.js.map +1 -1
  61. package/dist/react/utils/renderFileChildren.js +1 -1
  62. package/dist/react/utils/renderFileChildren.js.map +1 -1
  63. package/dist/react/utils/useFileDiffInstance.d.ts +1 -0
  64. package/dist/react/utils/useFileDiffInstance.d.ts.map +1 -1
  65. package/dist/react/utils/useFileDiffInstance.js +29 -24
  66. package/dist/react/utils/useFileDiffInstance.js.map +1 -1
  67. package/dist/react/utils/useFileInstance.d.ts +2 -0
  68. package/dist/react/utils/useFileInstance.d.ts.map +1 -1
  69. package/dist/react/utils/useFileInstance.js +38 -28
  70. package/dist/react/utils/useFileInstance.js.map +1 -1
  71. package/dist/react/utils/useForceUpdate.d.ts +5 -0
  72. package/dist/react/utils/useForceUpdate.d.ts.map +1 -0
  73. package/dist/react/utils/useForceUpdate.js +27 -0
  74. package/dist/react/utils/useForceUpdate.js.map +1 -0
  75. package/dist/react/utils/useNextRenderData.d.ts +9 -0
  76. package/dist/react/utils/useNextRenderData.d.ts.map +1 -0
  77. package/dist/react/utils/useNextRenderData.js +9 -0
  78. package/dist/react/utils/useNextRenderData.js.map +1 -0
  79. package/dist/react/utils/useUnresolvedFileInstance.d.ts +1 -0
  80. package/dist/react/utils/useUnresolvedFileInstance.d.ts.map +1 -1
  81. package/dist/react/utils/useUnresolvedFileInstance.js +26 -11
  82. package/dist/react/utils/useUnresolvedFileInstance.js.map +1 -1
  83. package/dist/renderers/DiffHunksRenderer.d.ts +2 -1
  84. package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
  85. package/dist/renderers/DiffHunksRenderer.js +62 -32
  86. package/dist/renderers/DiffHunksRenderer.js.map +1 -1
  87. package/dist/renderers/FileRenderer.d.ts +4 -1
  88. package/dist/renderers/FileRenderer.d.ts.map +1 -1
  89. package/dist/renderers/FileRenderer.js +55 -30
  90. package/dist/renderers/FileRenderer.js.map +1 -1
  91. package/dist/renderers/UnresolvedFileHunksRenderer.d.ts.map +1 -1
  92. package/dist/renderers/UnresolvedFileHunksRenderer.js +1 -1
  93. package/dist/renderers/UnresolvedFileHunksRenderer.js.map +1 -1
  94. package/dist/ssr/FileDiffReact.js +1 -1
  95. package/dist/types.d.ts +10 -0
  96. package/dist/types.d.ts.map +1 -1
  97. package/dist/utils/canUseWASM.d.ts +13 -0
  98. package/dist/utils/canUseWASM.d.ts.map +1 -0
  99. package/dist/utils/canUseWASM.js +59 -0
  100. package/dist/utils/canUseWASM.js.map +1 -0
  101. package/dist/utils/getCodeViewItemRenderData.d.ts +10 -0
  102. package/dist/utils/getCodeViewItemRenderData.d.ts.map +1 -0
  103. package/dist/utils/getCodeViewItemRenderData.js +19 -0
  104. package/dist/utils/getCodeViewItemRenderData.js.map +1 -0
  105. package/dist/utils/hastToHtml.d.ts +2 -2
  106. package/dist/utils/hastToHtml.js +2 -2
  107. package/dist/utils/hastToHtml.js.map +1 -1
  108. package/dist/utils/hydratePartialDiff.js +4 -0
  109. package/dist/utils/hydratePartialDiff.js.map +1 -1
  110. package/dist/utils/parseMergeConflictDiffFromFile.d.ts.map +1 -1
  111. package/dist/utils/parseMergeConflictDiffFromFile.js +2 -0
  112. package/dist/utils/parseMergeConflictDiffFromFile.js.map +1 -1
  113. package/dist/utils/parsePatchFiles.d.ts.map +1 -1
  114. package/dist/utils/parsePatchFiles.js +24 -4
  115. package/dist/utils/parsePatchFiles.js.map +1 -1
  116. package/dist/utils/renderTokenLines.d.ts +6 -1
  117. package/dist/utils/renderTokenLines.d.ts.map +1 -1
  118. package/dist/utils/renderTokenLines.js +4 -0
  119. package/dist/utils/renderTokenLines.js.map +1 -1
  120. package/dist/utils/resolveRegion.js +20 -10
  121. package/dist/utils/resolveRegion.js.map +1 -1
  122. package/dist/utils/tokenStyle.d.ts +5 -1
  123. package/dist/utils/tokenStyle.d.ts.map +1 -1
  124. package/dist/utils/tokenStyle.js +5 -1
  125. package/dist/utils/tokenStyle.js.map +1 -1
  126. package/dist/utils/tokensToHtml.d.ts +5 -2
  127. package/dist/utils/tokensToHtml.d.ts.map +1 -1
  128. package/dist/utils/tokensToHtml.js +5 -2
  129. package/dist/utils/tokensToHtml.js.map +1 -1
  130. package/dist/utils/updateDiffHunks.d.ts +2 -2
  131. package/dist/utils/updateDiffHunks.d.ts.map +1 -1
  132. package/dist/utils/updateDiffHunks.js +7 -3
  133. package/dist/utils/updateDiffHunks.js.map +1 -1
  134. package/dist/worker/WorkerPoolManager.d.ts +12 -0
  135. package/dist/worker/WorkerPoolManager.d.ts.map +1 -1
  136. package/dist/worker/WorkerPoolManager.js +99 -21
  137. package/dist/worker/WorkerPoolManager.js.map +1 -1
  138. package/dist/worker/{highlights-sAHlxqlf.js → highlights-CpZm9DAR.js} +2 -2
  139. package/dist/worker/{highlights-sAHlxqlf.js.map → highlights-CpZm9DAR.js.map} +1 -1
  140. package/dist/worker/{shiki-Bx2JpdqZ.js → shiki-Ci4cdHsM.js} +2 -2
  141. package/dist/worker/{shiki-Bx2JpdqZ.js.map → shiki-Ci4cdHsM.js.map} +1 -1
  142. package/dist/worker/{stream-tokenizer-YZ6M1qSx.js → stream-tokenizer-DK9xp5M5.js} +8 -5
  143. package/dist/worker/stream-tokenizer-DK9xp5M5.js.map +1 -0
  144. package/dist/worker/types.d.ts +11 -0
  145. package/dist/worker/types.d.ts.map +1 -1
  146. package/dist/worker/worker-portable.js +2 -2
  147. package/dist/worker/worker-portable.js.map +1 -1
  148. package/dist/worker/worker.js +12 -3
  149. package/dist/worker/worker.js.map +1 -1
  150. package/package.json +28 -30
  151. package/dist/worker/stream-tokenizer-YZ6M1qSx.js.map +0 -1
@@ -44,7 +44,8 @@ interface FileOptions<LAnnotation, Caret> extends BaseCodeOptions, InteractionMa
44
44
  * errors yourself.
45
45
  */
46
46
  disableErrorHandling?: boolean;
47
- renderAnnotation?(annotation: LineAnnotation<LAnnotation>): HTMLElement | undefined;
47
+ /** Receives the matching file, including any editor changes. */
48
+ renderAnnotation?(annotation: LineAnnotation<LAnnotation>, file: FileContents): HTMLElement | undefined;
48
49
  renderGutterUtility?(getHoveredRow: () => GetHoveredLineResult<'file'> | undefined): HTMLElement | null | undefined;
49
50
  onPostRender?(node: HTMLElement, instance: File<LAnnotation, Caret>, phase: PostRenderPhase): unknown;
50
51
  /**
@@ -65,15 +66,24 @@ interface FileOptions<LAnnotation, Caret> extends BaseCodeOptions, InteractionMa
65
66
  interface AnnotationElementCache<LAnnotation> {
66
67
  element: HTMLElement;
67
68
  annotation: LineAnnotation<LAnnotation>;
69
+ file: FileContents;
68
70
  }
69
71
  interface HydrationSetup<LAnnotation> {
70
72
  file: FileContents;
71
73
  lineAnnotations: LineAnnotation<LAnnotation>[] | undefined;
72
74
  }
75
+ interface FileRenderData<LAnnotation> {
76
+ file: FileContents;
77
+ lineAnnotations: LineAnnotation<LAnnotation>[];
78
+ }
79
+ interface FileRenderInput<LAnnotation> {
80
+ file: FileContents;
81
+ lineAnnotations: LineAnnotation<LAnnotation>[] | undefined;
82
+ }
73
83
  declare class File<LAnnotation = undefined, Caret = undefined> {
74
84
  options: FileOptions<LAnnotation, Caret>;
75
85
  private workerManager?;
76
- private isContainerManaged;
86
+ private requestOwnerRender?;
77
87
  static LoadedCustomComponent: boolean;
78
88
  readonly __id: string;
79
89
  readonly type = "file";
@@ -105,24 +115,36 @@ declare class File<LAnnotation = undefined, Caret = undefined> {
105
115
  protected resizeManager: ResizeManager;
106
116
  protected interactionManager: InteractionManager<'file'>;
107
117
  protected annotationCache: Map<string, AnnotationElementCache<LAnnotation>>;
108
- protected lineAnnotations: LineAnnotation<LAnnotation>[];
118
+ protected get lineAnnotations(): LineAnnotation<LAnnotation>[];
109
119
  protected managersDirty: boolean;
110
120
  file: FileContents | undefined;
111
121
  private editSession;
112
- protected renderedFile: FileContents | undefined;
122
+ private renderedData;
123
+ private pendingData;
124
+ protected forceRenderOverride: true | undefined;
113
125
  protected renderRange: RenderRange | undefined;
114
126
  protected enabled: boolean;
115
127
  protected editor: Editor<'file', LAnnotation, Caret> | undefined;
116
- constructor(options?: FileOptions<LAnnotation, Caret>, workerManager?: WorkerPoolManager | undefined, isContainerManaged?: boolean);
128
+ constructor(options?: FileOptions<LAnnotation, Caret>, workerManager?: WorkerPoolManager | undefined, requestOwnerRender?: (() => void) | undefined);
117
129
  getAnnotationSlotName: (annotation: LineAnnotation<LAnnotation> | DiffLineAnnotation<LAnnotation>) => string;
118
130
  private handleHighlightRender;
119
131
  rerender(): void;
132
+ protected requestRender(): boolean;
133
+ protected get isComponentManaged(): boolean;
120
134
  private getTheme;
121
- protected getLatestFile(file?: FileContents | undefined): FileContents | undefined;
135
+ protected getInputFile(): FileContents | undefined;
136
+ protected getWorkingFile(fallbackFile?: FileContents | undefined): FileContents | undefined;
122
137
  protected getRenderedFile(): FileContents | undefined;
138
+ /**
139
+ * @internal Data the next render() with this input will display. While a
140
+ * replacement file is being highlighted, this is still the displayed data.
141
+ */
142
+ __getNextRenderData({ file, lineAnnotations }: FileRenderInput<LAnnotation>): FileRenderData<LAnnotation>;
123
143
  protected getLatestAnnotations(): LineAnnotation<LAnnotation>[];
144
+ protected getAnnotationsForFile(file: FileContents): LineAnnotation<LAnnotation>[];
145
+ private adoptRenderData;
124
146
  protected isNewAnnotations(lineAnnotations: LineAnnotation<LAnnotation>[]): boolean;
125
- protected updateExternalFile(incomingFile: FileContents, lineAnnotations?: LineAnnotation<LAnnotation>[]): boolean;
147
+ protected updateInputFile(incomingFile: FileContents, lineAnnotations?: LineAnnotation<LAnnotation>[]): boolean;
126
148
  private installEditSession;
127
149
  onThemeChange(): void;
128
150
  setOptions(options: FileOptions<LAnnotation, Caret> | undefined): void;
@@ -168,7 +190,7 @@ declare class File<LAnnotation = undefined, Caret = undefined> {
168
190
  * Requires the editor to be detached first. Does nothing when no session
169
191
  * exists, so callers can invoke it again safely after it has settled.
170
192
  *
171
- * `onEditComplete` receives the completed file, current external file, and
193
+ * `onEditComplete` receives the completed file, current input file, and
172
194
  * both annotation collections even when the final text is unchanged. In
173
195
  * `install` mode, accepting installs the completed file and its annotations;
174
196
  * rejecting or having no handler restores the external values. `discard`
@@ -222,5 +244,5 @@ declare class File<LAnnotation = undefined, Caret = undefined> {
222
244
  private cleanupErrorWrapper;
223
245
  }
224
246
  //#endregion
225
- export { File, FileEditChangeHandler, type FileEditCompleteEvent, FileEditCompleteHandler, FileHydrateProps, FileOptions, FileRenderProps };
247
+ export { File, FileEditChangeHandler, type FileEditCompleteEvent, FileEditCompleteHandler, FileHydrateProps, FileOptions, FileRenderData, FileRenderInput, FileRenderProps };
226
248
  //# sourceMappingURL=File.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"File.d.ts","names":[],"sources":["../../src/components/File.ts"],"mappings":";;;;;;;;;;UA6FiB,gBAAgB;EAC/B,MAAM;EACN,gBAAgB;EAChB,mBAAmB;EACnB;EACA;EACA;EACA,kBAAkB,eAAe;EACjC,cAAc;;UAGC,iBAAiB,qBAAqB,KAC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;;EAiBG,SACL,MACA,eACA,aACA,aACA,kBACA,eACA,iBACA,eACC,gBAAgB;YAwMT;UAEF;UA2BA;UAmBA;UAUA;EAWD,kBAAkB;YAkBf,qBAAqB;EAQlB,oBACX,OAAM,2BACL;UA4BK;UA0CA;UA+CA;UAqBA;UAkCA;UAqDA;YAeE;UAIF;UA6BA;UA6GA;UAcA;UA2BA;UA8CA;UASA;YAiDE;UAIF;UA4EA;UAYA;UAkBA;UAYA;YAME,6BACR,gBAAgB,aAChB,aAAa,cACZ;UAmCK;UAyBA;UAgBA;UAwBA;UAaA;UAqBA;UAqBA"}
@@ -1,4 +1,4 @@
1
- import { CUSTOM_HEADER_SLOT_ID, DEFAULT_THEMES, EMPTY_RENDER_RANGE, HEADER_FILENAME_SUFFIX_SLOT_ID, HEADER_METADATA_SLOT_ID, HEADER_PREFIX_SLOT_ID } from "../constants.js";
1
+ import { CUSTOM_HEADER_SLOT_ID, DEFAULT_THEMES, EMPTY_LINE_ANNOTATIONS, EMPTY_RENDER_RANGE, HEADER_FILENAME_SUFFIX_SLOT_ID, HEADER_METADATA_SLOT_ID, HEADER_PREFIX_SLOT_ID } from "../constants.js";
2
2
  import { HighlighterDisposedError } from "../highlighter/highlighterType.js";
3
3
  import { getThemes } from "../utils/getThemes.js";
4
4
  import { getHighlighterIfLoaded, getSharedHighlighter } from "../highlighter/shared_highlighter.js";
@@ -43,7 +43,7 @@ let instanceId = -1;
43
43
  var File = class {
44
44
  options;
45
45
  workerManager;
46
- isContainerManaged;
46
+ requestOwnerRender;
47
47
  static LoadedCustomComponent = true;
48
48
  __id = `file:${++instanceId}`;
49
49
  type = "file";
@@ -75,18 +75,22 @@ var File = class {
75
75
  resizeManager;
76
76
  interactionManager;
77
77
  annotationCache = /* @__PURE__ */ new Map();
78
- lineAnnotations = [];
78
+ get lineAnnotations() {
79
+ return this.renderedData?.lineAnnotations ?? EMPTY_LINE_ANNOTATIONS;
80
+ }
79
81
  managersDirty = false;
80
82
  file;
81
83
  editSession;
82
- renderedFile;
84
+ renderedData;
85
+ pendingData;
86
+ forceRenderOverride;
83
87
  renderRange;
84
88
  enabled = true;
85
89
  editor;
86
- constructor(options = { theme: DEFAULT_THEMES }, workerManager, isContainerManaged = false) {
90
+ constructor(options = { theme: DEFAULT_THEMES }, workerManager, requestOwnerRender) {
87
91
  this.options = options;
88
92
  this.workerManager = workerManager;
89
- this.isContainerManaged = isContainerManaged;
93
+ this.requestOwnerRender = requestOwnerRender;
90
94
  this.fileRenderer = new FileRenderer(options, this.getAnnotationSlotName, this.handleHighlightRender, this.workerManager);
91
95
  this.resizeManager = new ResizeManager();
92
96
  this.interactionManager = new InteractionManager("file", pluckInteractionOptions(options));
@@ -99,51 +103,104 @@ var File = class {
99
103
  this.rerender();
100
104
  };
101
105
  rerender() {
102
- if (!this.enabled || this.file == null) return;
106
+ const file = this.getInputFile();
107
+ if (!this.enabled || file == null) return;
108
+ if (this.requestRender()) return;
103
109
  this.render({
104
- file: this.file,
110
+ file,
105
111
  forceRender: true,
106
112
  renderRange: this.renderRange
107
113
  });
108
114
  }
115
+ requestRender() {
116
+ const { requestOwnerRender } = this;
117
+ if (this.editSession != null || requestOwnerRender == null) return false;
118
+ this.forceRenderOverride = true;
119
+ requestOwnerRender();
120
+ return true;
121
+ }
122
+ get isComponentManaged() {
123
+ return this.requestOwnerRender != null;
124
+ }
109
125
  getTheme() {
110
126
  return this.workerManager?.getFileRenderOptions().theme ?? this.options.theme ?? DEFAULT_THEMES;
111
127
  }
112
- getLatestFile(file = this.file) {
113
- return this.editSession?.file ?? file;
128
+ getInputFile() {
129
+ return this.file;
130
+ }
131
+ getWorkingFile(fallbackFile = this.file) {
132
+ return this.editSession?.file ?? fallbackFile;
114
133
  }
115
134
  getRenderedFile() {
116
- return this.renderedFile;
135
+ return this.renderedData?.file;
136
+ }
137
+ /**
138
+ * @internal Data the next render() with this input will display. While a
139
+ * replacement file is being highlighted, this is still the displayed data.
140
+ */
141
+ __getNextRenderData({ file, lineAnnotations }) {
142
+ const sessionAnnotations = this.editSession?.annotations;
143
+ if (sessionAnnotations != null) return {
144
+ file,
145
+ lineAnnotations: lineAnnotations != null && this.isNewAnnotations(lineAnnotations) ? lineAnnotations : sessionAnnotations.provided
146
+ };
147
+ const workingFile = this.getWorkingFile(file) ?? file;
148
+ const nextFile = this.fileRenderer.getFileForNextRender(workingFile);
149
+ return {
150
+ file: nextFile,
151
+ lineAnnotations: lineAnnotations != null && areFileTargetsEqual(nextFile, workingFile) ? lineAnnotations : this.getAnnotationsForFile(nextFile)
152
+ };
117
153
  }
118
154
  getLatestAnnotations() {
119
- return this.editSession?.annotations?.current ?? this.lineAnnotations;
155
+ return this.pendingData?.lineAnnotations ?? this.editSession?.annotations?.current ?? this.lineAnnotations;
156
+ }
157
+ getAnnotationsForFile(file) {
158
+ const { pendingData } = this;
159
+ return pendingData != null && areFileTargetsEqual(file, pendingData.file) ? pendingData.lineAnnotations : this.lineAnnotations;
160
+ }
161
+ adoptRenderData(file) {
162
+ const { pendingData } = this;
163
+ const matchesPending = pendingData != null && areFileTargetsEqual(file, pendingData.file);
164
+ this.renderedData = {
165
+ file,
166
+ lineAnnotations: matchesPending ? pendingData.lineAnnotations : this.lineAnnotations
167
+ };
168
+ if (matchesPending) this.pendingData = void 0;
120
169
  }
121
170
  isNewAnnotations(lineAnnotations) {
122
171
  const session = this.editSession?.annotations;
123
- if (lineAnnotations === this.lineAnnotations) return false;
172
+ if (lineAnnotations === this.getLatestAnnotations()) return false;
124
173
  return session == null || lineAnnotations !== session.provided && lineAnnotations !== session.current;
125
174
  }
126
- updateExternalFile(incomingFile, lineAnnotations) {
127
- if (areFileTargetsEqual(this.file, incomingFile)) return false;
175
+ updateInputFile(incomingFile, lineAnnotations) {
176
+ if (areFileTargetsEqual(this.getInputFile(), incomingFile)) return false;
128
177
  const hadSession = this.editSession != null;
178
+ const previousAnnotations = this.getLatestAnnotations();
129
179
  this.file = incomingFile;
130
180
  if (hadSession || this.editor != null) this.installEditSession(incomingFile, hadSession ? void 0 : this.editor?.__getDocumentContents(incomingFile), true);
131
181
  else this.editSession = void 0;
132
- if (this.editSession?.annotations != null && lineAnnotations != null) {
133
- this.lineAnnotations = lineAnnotations;
134
- this.editSession.annotations = adoptEditSessionAnnotations(lineAnnotations, getLineAnnotationName, this.editSession.annotations);
135
- }
182
+ if (this.editSession?.annotations != null && lineAnnotations != null) this.editSession.annotations = adoptEditSessionAnnotations(lineAnnotations, getLineAnnotationName, this.editSession.annotations);
183
+ this.pendingData = {
184
+ file: this.editSession?.file ?? incomingFile,
185
+ lineAnnotations: this.editSession?.annotations?.current ?? lineAnnotations ?? previousAnnotations
186
+ };
136
187
  return true;
137
188
  }
138
- installEditSession(externalFile, retainedDocument, hostReplacement = false) {
139
- const usesExternalDocument = retainedDocument == null || retainedDocument.name === externalFile.name && retainedDocument.lang === externalFile.lang && retainedDocument.contents === externalFile.contents;
140
- const file = createEditSessionFile(retainedDocument ?? externalFile);
189
+ installEditSession(inputFile, retainedDocument, hostReplacement = false) {
190
+ const usesInputDocument = retainedDocument == null || retainedDocument.name === inputFile.name && retainedDocument.lang === inputFile.lang && retainedDocument.contents === inputFile.contents;
191
+ const file = createEditSessionFile(retainedDocument ?? inputFile);
192
+ const annotations = this.editSession?.annotations ?? adoptEditSessionAnnotations(this.getLatestAnnotations(), getLineAnnotationName);
141
193
  this.editSession = {
142
194
  file,
143
- externalReplacement: hostReplacement && usesExternalDocument,
144
- annotations: this.editSession?.annotations ?? adoptEditSessionAnnotations(this.lineAnnotations, getLineAnnotationName)
195
+ inputFile,
196
+ externalReplacement: hostReplacement && usesInputDocument,
197
+ annotations
145
198
  };
146
- this.fileRenderer.beginEditSession(file, usesExternalDocument ? externalFile : void 0);
199
+ this.pendingData = {
200
+ file,
201
+ lineAnnotations: annotations.current
202
+ };
203
+ this.fileRenderer.beginEditSession(file, usesInputDocument ? inputFile : void 0);
147
204
  }
148
205
  onThemeChange() {
149
206
  this.fileRenderer.clearRenderCache();
@@ -184,18 +241,22 @@ var File = class {
184
241
  };
185
242
  setLineAnnotations(lineAnnotations) {
186
243
  const sessionAnnotations = this.editSession?.annotations;
187
- if (sessionAnnotations == null) {
188
- this.lineAnnotations = lineAnnotations;
189
- return;
244
+ if (sessionAnnotations != null) {
245
+ if (!this.isNewAnnotations(lineAnnotations)) return;
246
+ writeEditSessionAnnotations(sessionAnnotations, lineAnnotations, getLineAnnotationName);
190
247
  }
191
- if (!this.isNewAnnotations(lineAnnotations)) return;
192
- this.lineAnnotations = lineAnnotations;
193
- writeEditSessionAnnotations(sessionAnnotations, lineAnnotations, getLineAnnotationName);
248
+ const file = this.getWorkingFile();
249
+ if (file != null) this.pendingData = {
250
+ file,
251
+ lineAnnotations
252
+ };
194
253
  }
195
254
  syncEditSessionAnnotationsFromEditor(lineAnnotations) {
196
255
  const session = this.editSession?.annotations;
197
256
  if (session == null || lineAnnotations === session.current) return false;
198
257
  session.current = lineAnnotations;
258
+ if (this.renderedData != null) this.renderedData.lineAnnotations = lineAnnotations;
259
+ this.pendingData = void 0;
199
260
  this.fileRenderer.setLineAnnotations(lineAnnotations);
200
261
  this.renderAnnotations();
201
262
  return true;
@@ -235,7 +296,7 @@ var File = class {
235
296
  this.managersDirty = false;
236
297
  }
237
298
  shouldApplyColumnVariables(overflow) {
238
- return overflow === "scroll" && this.getLatestAnnotations().length > 0;
299
+ return overflow === "scroll" && this.lineAnnotations.length > 0;
239
300
  }
240
301
  cleanUp(recycle = false) {
241
302
  const editor = this.editor;
@@ -247,10 +308,13 @@ var File = class {
247
308
  this.managersDirty = false;
248
309
  this.workerManager?.unsubscribeToThemeChanges(this);
249
310
  this.renderRange = void 0;
250
- if (!this.isContainerManaged) this.fileContainer?.remove();
311
+ if (!this.isComponentManaged) this.fileContainer?.remove();
251
312
  this.fileContainer = void 0;
252
313
  this.mounted = false;
253
- if (!recycle) this.lineAnnotations = [];
314
+ if (!recycle) {
315
+ this.renderedData = void 0;
316
+ this.pendingData = void 0;
317
+ }
254
318
  this.clearAuxiliaryNodes();
255
319
  this.pre = void 0;
256
320
  this.code = void 0;
@@ -283,7 +347,6 @@ var File = class {
283
347
  this.workerManager = void 0;
284
348
  this.file = void 0;
285
349
  this.editSession = void 0;
286
- this.renderedFile = void 0;
287
350
  }
288
351
  this.enabled = false;
289
352
  }
@@ -345,20 +408,23 @@ var File = class {
345
408
  this.hydrateMeasuredScrollbar();
346
409
  }
347
410
  hydrationSetup({ file, lineAnnotations }) {
348
- this.lineAnnotations = lineAnnotations ?? this.lineAnnotations;
411
+ this.renderedData = {
412
+ file,
413
+ lineAnnotations: lineAnnotations ?? this.getLatestAnnotations()
414
+ };
415
+ this.pendingData = void 0;
349
416
  this.file = file;
350
417
  this.fileRenderer.setOptions(getFileRendererOptions(this.options));
351
418
  this.syncInteractionOptions();
352
419
  if (this.pre == null) return;
353
420
  this.fileRenderer.hydrate(file);
354
- this.renderedFile = file;
355
421
  this.renderAnnotations();
356
422
  this.renderGutterUtility();
357
423
  this.injectUnsafeCSS();
358
424
  this.managersDirty = true;
359
425
  this.flushManagers();
360
426
  }
361
- getOrCreateLineCache(file = this.getLatestFile()) {
427
+ getOrCreateLineCache(file = this.getWorkingFile()) {
362
428
  return file != null ? this.fileRenderer.getOrCreateLineCache(file) : EMPTY_STRINGS;
363
429
  }
364
430
  updateBuffers(renderRange) {
@@ -367,10 +433,10 @@ var File = class {
367
433
  syncRenderViewToEditor() {
368
434
  const { editor, fileContainer, renderRange } = this;
369
435
  const lineAnnotations = this.getLatestAnnotations();
370
- const file = this.getLatestFile();
436
+ const file = this.getWorkingFile();
371
437
  if (editor == null || fileContainer == null || file == null) return;
372
438
  const syncEditor = (highlighter) => {
373
- if (!this.enabled || this.editor !== editor || this.fileContainer !== fileContainer || this.getLatestFile() !== file) return;
439
+ if (!this.enabled || this.editor !== editor || this.fileContainer !== fileContainer || this.getWorkingFile() !== file) return;
374
440
  editor.__syncRenderView({
375
441
  highlighter,
376
442
  fileContainer,
@@ -433,10 +499,13 @@ var File = class {
433
499
  }
434
500
  resumeEditorRendering(editor) {
435
501
  if (this.editSession != null) this.fileRenderer.beginEditSession(this.editSession.file);
436
- else if (this.file != null) this.installEditSession(this.file, editor.__getDocumentContents(this.file));
502
+ else {
503
+ const inputFile = this.getInputFile();
504
+ if (inputFile != null) this.installEditSession(inputFile, editor.__getDocumentContents(inputFile));
505
+ }
437
506
  const editSessionFile = this.editSession?.file;
438
507
  if (this.fileRenderer.editorRenderReady()) {
439
- if (this.fileRenderer.fileCache === editSessionFile) this.renderedFile = editSessionFile;
508
+ if (editSessionFile != null && this.fileRenderer.fileCache === editSessionFile) this.adoptRenderData(editSessionFile);
440
509
  this.syncRenderViewToEditor();
441
510
  } else this.rerender();
442
511
  }
@@ -447,7 +516,7 @@ var File = class {
447
516
  * Requires the editor to be detached first. Does nothing when no session
448
517
  * exists, so callers can invoke it again safely after it has settled.
449
518
  *
450
- * `onEditComplete` receives the completed file, current external file, and
519
+ * `onEditComplete` receives the completed file, current input file, and
451
520
  * both annotation collections even when the final text is unchanged. In
452
521
  * `install` mode, accepting installs the completed file and its annotations;
453
522
  * rejecting or having no handler restores the external values. `discard`
@@ -458,9 +527,10 @@ var File = class {
458
527
  this.settleEditSession(mode === "install", editor);
459
528
  }
460
529
  settleEditSession(installResult, editor) {
461
- const { editSession, file: externalFile, lineAnnotations: externalAnnotations } = this;
462
- if (editSession == null || externalFile == null) return;
463
- const { file: editSessionFile, annotations: editSessionAnnotations } = editSession;
530
+ const { editSession } = this;
531
+ if (editSession == null) return;
532
+ const { file: editSessionFile, inputFile, annotations: editSessionAnnotations } = editSession;
533
+ const inputAnnotations = editSessionAnnotations?.provided ?? this.lineAnnotations;
464
534
  if (this.editor != null) throw new Error("File.__completeEditSession: detach the editor before completing the session");
465
535
  const sessionAnnotationsCurrent = editSessionAnnotations?.current;
466
536
  let acceptedFile;
@@ -471,29 +541,31 @@ var File = class {
471
541
  const event = {
472
542
  file: completedFile,
473
543
  editor,
474
- originalFile: externalFile,
544
+ originalFile: inputFile,
475
545
  lineAnnotations: sessionAnnotationsCurrent,
476
- originalLineAnnotations: externalAnnotations
546
+ originalLineAnnotations: inputAnnotations
477
547
  };
478
548
  Object.freeze(event);
479
549
  try {
480
550
  editor.__emitEditComplete(event);
481
551
  if (this.options.onEditComplete?.(event) === "accept") {
482
- if (completedFile.cacheKey != null && completedFile.cacheKey === externalFile.cacheKey) throw new Error("File.__completeEditSession: an accepted file must not reuse the replaced file cacheKey");
552
+ if (completedFile.cacheKey != null && completedFile.cacheKey === inputFile.cacheKey) throw new Error("File.__completeEditSession: an accepted file must not reuse the replaced file cacheKey");
483
553
  acceptedFile = completedFile;
484
554
  }
485
555
  } catch (error) {
486
556
  failed = true;
487
557
  failure = error;
488
558
  }
489
- if (installResult && acceptedFile != null) {
490
- this.file = acceptedFile;
491
- if (sessionAnnotationsCurrent != null) this.lineAnnotations = sessionAnnotationsCurrent;
492
- }
559
+ const settledFile = installResult && acceptedFile != null ? acceptedFile : inputFile;
560
+ const settledAnnotations = installResult && acceptedFile != null ? sessionAnnotationsCurrent ?? inputAnnotations : inputAnnotations;
493
561
  this.editSession = void 0;
494
- const { renderedFile, file: settledFile } = this;
562
+ this.file = settledFile;
563
+ this.pendingData = {
564
+ file: settledFile,
565
+ lineAnnotations: settledAnnotations
566
+ };
495
567
  this.fileRenderer.endEditSession(settledFile);
496
- if (renderedFile != null && settledFile != null && renderedFile !== settledFile && areFileTargetsEqual(renderedFile, settledFile)) this.renderedFile = settledFile;
568
+ if (areFileTargetsEqual(this.getRenderedFile(), settledFile)) this.adoptRenderData(settledFile);
497
569
  if (installResult && this.fileContainer != null) this.rerender();
498
570
  if (failed) throw failure;
499
571
  }
@@ -518,15 +590,17 @@ var File = class {
518
590
  }
519
591
  render({ file, fileContainer, forceRender = false, preventEmit = false, containerWrapper, deferManagers = false, lineAnnotations, renderRange }) {
520
592
  if (!this.enabled) throw new Error("File.render: attempting to call render after cleaned up");
593
+ forceRender = this.forceRenderOverride ?? forceRender;
594
+ this.forceRenderOverride = void 0;
521
595
  this.editor?.__postponeBgTokenizeToNextFrame();
522
596
  const { collapsed = false, themeType = "system" } = this.options;
523
597
  const nextRenderRange = collapsed ? void 0 : renderRange;
524
598
  const previousRenderRange = this.renderRange;
525
599
  const themeChanged = this.hasThemeChanged();
526
600
  const annotationsChanged = lineAnnotations != null && (lineAnnotations.length > 0 || this.getLatestAnnotations().length > 0) ? this.isNewAnnotations(lineAnnotations) : false;
527
- const didFileChange = !areFileTargetsEqual(this.file, file);
528
- if (didFileChange) this.updateExternalFile(file, lineAnnotations);
529
- const latestFile = this.getLatestFile(file) ?? file;
601
+ const didFileChange = !areFileTargetsEqual(this.getInputFile(), file);
602
+ if (didFileChange) this.updateInputFile(file, lineAnnotations);
603
+ const workingFile = this.getWorkingFile(file) ?? file;
530
604
  if (!collapsed && !forceRender && areRenderRangesEqual(nextRenderRange, this.renderRange) && !didFileChange && !annotationsChanged && !themeChanged) {
531
605
  const rendered = this.applyCachedThemeState(themeType);
532
606
  if (rendered) this.finalizeRender();
@@ -537,7 +611,8 @@ var File = class {
537
611
  this.fileRenderer.setOptions(getFileRendererOptions(this.options));
538
612
  this.syncInteractionOptions();
539
613
  if (lineAnnotations != null) this.setLineAnnotations(lineAnnotations);
540
- this.fileRenderer.setLineAnnotations(this.getLatestAnnotations());
614
+ const nextRenderFile = this.fileRenderer.getFileForNextRender(workingFile);
615
+ this.fileRenderer.setLineAnnotations(this.getAnnotationsForFile(nextRenderFile));
541
616
  const { disableErrorHandling = false, disableFileHeader = false } = this.options;
542
617
  if (disableFileHeader) {
543
618
  if (this.headerElement != null) {
@@ -553,10 +628,10 @@ var File = class {
553
628
  this.removeRenderedCode();
554
629
  this.clearAuxiliaryNodes();
555
630
  try {
556
- const fileResult = this.fileRenderer.renderFile(latestFile, EMPTY_RENDER_RANGE);
631
+ const fileResult = this.fileRenderer.renderFile(workingFile, EMPTY_RENDER_RANGE);
557
632
  if (fileResult != null) this.applyThemeState(fileContainer, fileResult.themeStyles, themeType, fileResult.baseThemeType);
558
633
  if (fileResult?.headerAST != null) this.applyHeaderToDOM(fileResult.headerAST, fileContainer, fileResult.file);
559
- this.renderedFile = fileResult?.file ?? latestFile;
634
+ this.adoptRenderData(fileResult?.file ?? workingFile);
560
635
  this.injectUnsafeCSS();
561
636
  } catch (error) {
562
637
  if (disableErrorHandling) throw error;
@@ -569,8 +644,9 @@ var File = class {
569
644
  }
570
645
  try {
571
646
  const pre = this.getOrCreatePreNode(fileContainer);
572
- if (!this.canPartiallyRender(forceRender, annotationsChanged, didFileChange || themeChanged || !areFileTargetsEqual(this.renderedFile, latestFile)) || !this.applyPartialRender(latestFile, previousRenderRange, nextRenderRange)) {
573
- const fileResult = this.fileRenderer.renderFile(latestFile, nextRenderRange);
647
+ let renderedFile = this.getRenderedFile();
648
+ if (!this.canPartiallyRender(forceRender, annotationsChanged, didFileChange || themeChanged || !areFileTargetsEqual(this.getRenderedFile(), workingFile)) || !this.applyPartialRender(workingFile, previousRenderRange, nextRenderRange)) {
649
+ const fileResult = this.fileRenderer.renderFile(workingFile, nextRenderRange);
574
650
  if (fileResult == null) {
575
651
  if (this.workerManager?.isInitialized() === false && this.workerManager.isWorkingPool()) this.workerManager.initialize().catch(() => {}).then(() => this.rerender());
576
652
  return false;
@@ -578,10 +654,11 @@ var File = class {
578
654
  this.applyThemeState(fileContainer, fileResult.themeStyles, themeType, fileResult.baseThemeType);
579
655
  if (fileResult.headerAST != null) this.applyHeaderToDOM(fileResult.headerAST, fileContainer, fileResult.file);
580
656
  this.applyFullRender(fileResult, pre);
581
- this.renderedFile = fileResult.file;
657
+ renderedFile = fileResult.file;
582
658
  }
583
659
  this.applyBuffers(pre, nextRenderRange);
584
660
  this.injectUnsafeCSS();
661
+ if (renderedFile != null) this.adoptRenderData(renderedFile);
585
662
  this.renderAnnotations();
586
663
  this.renderGutterUtility();
587
664
  this.managersDirty = true;
@@ -652,7 +729,7 @@ var File = class {
652
729
  this.placeHolder.style.setProperty("height", `${height}px`);
653
730
  return true;
654
731
  }
655
- async primeHighlightCache(file = this.file) {
732
+ async primeHighlightCache(file = this.getInputFile()) {
656
733
  const { workerManager } = this;
657
734
  if (file == null || workerManager == null || !workerManager.isWorkingPool() || file.cacheKey == null || isFilePlainText(file)) return;
658
735
  const tokenizeMaxLength = this.options.tokenizeMaxLength ?? 1e5;
@@ -700,31 +777,35 @@ var File = class {
700
777
  this.mounted = false;
701
778
  }
702
779
  renderAnnotations() {
703
- if (this.isContainerManaged || this.fileContainer == null) {
780
+ if (this.isComponentManaged || this.fileContainer == null) {
704
781
  for (const { element } of this.annotationCache.values()) element.remove();
705
782
  this.annotationCache.clear();
706
783
  return;
707
784
  }
708
785
  const staleAnnotations = new Map(this.annotationCache);
709
786
  const { renderAnnotation } = this.options;
710
- const lineAnnotations = this.getLatestAnnotations();
711
- if (renderAnnotation != null && lineAnnotations.length > 0) for (const [index, annotation] of lineAnnotations.entries()) {
712
- const name = this.getAnnotationSlotName(annotation);
713
- const id = `${index}-${name}`;
714
- let cache = this.annotationCache.get(id);
715
- if (cache == null || !areLineAnnotationsEqual(annotation, cache.annotation)) {
716
- cache?.element.remove();
717
- const content = renderAnnotation(annotation);
718
- if (content == null) continue;
719
- cache = {
720
- element: createAnnotationWrapperNode(name),
721
- annotation
722
- };
723
- cache.element.appendChild(content);
724
- this.fileContainer.appendChild(cache.element);
725
- this.annotationCache.set(id, cache);
787
+ const { renderedData } = this;
788
+ if (renderAnnotation != null && renderedData != null) {
789
+ const { file, lineAnnotations } = renderedData;
790
+ for (const [index, annotation] of lineAnnotations.entries()) {
791
+ const name = this.getAnnotationSlotName(annotation);
792
+ const id = `${index}-${name}`;
793
+ let cache = this.annotationCache.get(id);
794
+ if (cache == null || cache.file !== file || !areLineAnnotationsEqual(annotation, cache.annotation)) {
795
+ cache?.element.remove();
796
+ const content = renderAnnotation(annotation, file);
797
+ if (content == null) continue;
798
+ cache = {
799
+ element: createAnnotationWrapperNode(name),
800
+ annotation,
801
+ file
802
+ };
803
+ cache.element.appendChild(content);
804
+ this.fileContainer.appendChild(cache.element);
805
+ this.annotationCache.set(id, cache);
806
+ }
807
+ staleAnnotations.delete(id);
726
808
  }
727
- staleAnnotations.delete(id);
728
809
  }
729
810
  for (const [id, { element }] of staleAnnotations.entries()) {
730
811
  this.annotationCache.delete(id);
@@ -984,7 +1065,7 @@ var File = class {
984
1065
  this.headerElement = newHeader;
985
1066
  this.lastRenderedHeaderHTML = headerHTML;
986
1067
  }
987
- if (this.isContainerManaged) return;
1068
+ if (this.isComponentManaged) return;
988
1069
  const { renderHeaderPrefix, renderHeaderFilenameSuffix, renderCustomHeader, renderHeaderMetadata } = this.options;
989
1070
  if (renderCustomHeader != null) {
990
1071
  const content = renderCustomHeader(file) ?? void 0;