@pierre/diffs 1.1.0-beta.5 → 1.1.0-beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/File.d.ts +6 -0
- package/dist/components/File.d.ts.map +1 -1
- package/dist/components/File.js +4 -5
- package/dist/components/File.js.map +1 -1
- package/dist/components/FileDiff.d.ts +6 -0
- package/dist/components/FileDiff.d.ts.map +1 -1
- package/dist/components/FileDiff.js +4 -5
- package/dist/components/FileDiff.js.map +1 -1
- package/dist/react/jsx.d.ts +1 -1
- package/dist/react/jsx.d.ts.map +1 -1
- package/dist/react/types.js +1 -0
- package/dist/utils/parseDiffFromFile.d.ts +1 -1
- package/dist/utils/parseDiffFromFile.d.ts.map +1 -1
- package/dist/utils/parseDiffFromFile.js +3 -2
- package/dist/utils/parseDiffFromFile.js.map +1 -1
- package/dist/utils/parsePatchFiles.d.ts +5 -3
- package/dist/utils/parsePatchFiles.d.ts.map +1 -1
- package/dist/utils/parsePatchFiles.js +16 -9
- package/dist/utils/parsePatchFiles.js.map +1 -1
- package/dist/worker/WorkerPoolManager.d.ts +1 -0
- package/dist/worker/WorkerPoolManager.d.ts.map +1 -1
- package/dist/worker/WorkerPoolManager.js +29 -22
- package/dist/worker/WorkerPoolManager.js.map +1 -1
- package/dist/worker/worker-portable.js +69 -36
- package/dist/worker/worker-portable.js.map +1 -1
- package/package.json +2 -2
|
@@ -19,6 +19,12 @@ interface FileHyrdateProps<LAnnotation> extends Omit<FileRenderProps<LAnnotation
|
|
|
19
19
|
interface FileOptions<LAnnotation> extends BaseCodeOptions, MouseEventManagerBaseOptions<"file">, LineSelectionOptions {
|
|
20
20
|
disableFileHeader?: boolean;
|
|
21
21
|
renderCustomMetadata?: RenderFileMetadata;
|
|
22
|
+
/**
|
|
23
|
+
* When true, errors during rendering are rethrown instead of being caught
|
|
24
|
+
* and displayed in the DOM. Useful for testing or when you want to handle
|
|
25
|
+
* errors yourself.
|
|
26
|
+
*/
|
|
27
|
+
disableErrorHandling?: boolean;
|
|
22
28
|
renderAnnotation?(annotation: LineAnnotation<LAnnotation>): HTMLElement | undefined;
|
|
23
29
|
renderHoverUtility?(getHoveredRow: () => GetHoveredLineResult<"file"> | undefined): HTMLElement | null;
|
|
24
30
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"File.d.ts","names":["options: FileOptions<LAnnotation>","workerManager?: WorkerPoolManager | undefined"],"sources":["../../src/components/File.ts"],"sourcesContent":[],"mappings":";;;;;;;UA8CiB;QACT;kBACU;EAFlB,gBAAiB,CAAA,EAGI,WAHJ;EACT,WAAA,CAAA,EAAA,OAAA;EACU,eAAA,CAAA,EAGE,cAHF,CAGiB,WAHjB,CAAA,EAAA;;AAGiB,UAGlB,gBAHkB,CAAA,WAAA,CAAA,SAIzB,IAJyB,CAIpB,eAJoB,CAIJ,WAJI,CAAA,EAAA,eAAA,CAAA,CAAA;EAAf,aAAA,EAKH,WALG;EAAA,eAAA,CAAA,EAAA,MAAA;AAGpB;AAC+B,UAKd,WALc,CAAA,WAAA,CAAA,SAMrB,eANqB,EAO3B,4BAP2B,CAAA,MAAA,CAAA,EAQ3B,oBAR2B,CAAA;EAAhB,iBAAA,CAAA,EAAA,OAAA;EACE,oBAAA,CAAA,EASQ,kBATR;EADP,gBAAA,EAAA,UAAA,
|
|
1
|
+
{"version":3,"file":"File.d.ts","names":["options: FileOptions<LAnnotation>","workerManager?: WorkerPoolManager | undefined"],"sources":["../../src/components/File.ts"],"sourcesContent":[],"mappings":";;;;;;;UA8CiB;QACT;kBACU;EAFlB,gBAAiB,CAAA,EAGI,WAHJ;EACT,WAAA,CAAA,EAAA,OAAA;EACU,eAAA,CAAA,EAGE,cAHF,CAGiB,WAHjB,CAAA,EAAA;;AAGiB,UAGlB,gBAHkB,CAAA,WAAA,CAAA,SAIzB,IAJyB,CAIpB,eAJoB,CAIJ,WAJI,CAAA,EAAA,eAAA,CAAA,CAAA;EAAf,aAAA,EA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Ie,eAAe;0BAI3B;;iBA+BT,iBAAiB;;;;;;;KA6D7B,gBAAgB"}
|
package/dist/components/File.js
CHANGED
|
@@ -163,7 +163,7 @@ var File = class {
|
|
|
163
163
|
this.fileRenderer.setOptions(this.options);
|
|
164
164
|
if (lineAnnotations != null) this.setLineAnnotations(lineAnnotations);
|
|
165
165
|
this.fileRenderer.setLineAnnotations(this.lineAnnotations);
|
|
166
|
-
const { disableFileHeader = false } = this.options;
|
|
166
|
+
const { disableFileHeader = false, disableErrorHandling = false } = this.options;
|
|
167
167
|
if (disableFileHeader) {
|
|
168
168
|
if (this.headerElement != null) {
|
|
169
169
|
this.headerElement.parentNode?.removeChild(this.headerElement);
|
|
@@ -184,10 +184,9 @@ var File = class {
|
|
|
184
184
|
this.renderAnnotations();
|
|
185
185
|
this.renderHoverUtility();
|
|
186
186
|
} catch (error) {
|
|
187
|
-
if (
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
}
|
|
187
|
+
if (disableErrorHandling) throw error;
|
|
188
|
+
console.error(error);
|
|
189
|
+
if (error instanceof Error) this.applyErrorToDOM(error, fileContainer);
|
|
191
190
|
}
|
|
192
191
|
}
|
|
193
192
|
renderAnnotations() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"File.js","names":["options: FileOptions<LAnnotation>","workerManager?: WorkerPoolManager | undefined","error: unknown","preProperties: PrePropertiesConfig"],"sources":["../../src/components/File.ts"],"sourcesContent":["import type { Element as HASTElement } from 'hast';\nimport { toHtml } from 'hast-util-to-html';\n\nimport {\n DEFAULT_THEMES,\n DIFFS_TAG_NAME,\n HEADER_METADATA_SLOT_ID,\n UNSAFE_CSS_ATTRIBUTE,\n} from '../constants';\nimport {\n LineSelectionManager,\n type LineSelectionOptions,\n type SelectedLineRange,\n pluckLineSelectionOptions,\n} from '../managers/LineSelectionManager';\nimport {\n type GetHoveredLineResult,\n MouseEventManager,\n type MouseEventManagerBaseOptions,\n pluckMouseEventOptions,\n} from '../managers/MouseEventManager';\nimport { ResizeManager } from '../managers/ResizeManager';\nimport { type FileRenderResult, FileRenderer } from '../renderers/FileRenderer';\nimport { SVGSpriteSheet } from '../sprite';\nimport type {\n BaseCodeOptions,\n FileContents,\n LineAnnotation,\n PrePropertiesConfig,\n RenderFileMetadata,\n ThemeTypes,\n} from '../types';\nimport { areFilesEqual } from '../utils/areFilesEqual';\nimport { areLineAnnotationsEqual } from '../utils/areLineAnnotationsEqual';\nimport { arePrePropertiesEqual } from '../utils/arePrePropertiesEqual';\nimport { createAnnotationWrapperNode } from '../utils/createAnnotationWrapperNode';\nimport { createHoverContentNode } from '../utils/createHoverContentNode';\nimport { createUnsafeCSSStyleNode } from '../utils/createUnsafeCSSStyleNode';\nimport { wrapUnsafeCSS } from '../utils/cssWrappers';\nimport { getLineAnnotationName } from '../utils/getLineAnnotationName';\nimport { getOrCreateCodeNode } from '../utils/getOrCreateCodeNode';\nimport { prerenderHTMLIfNecessary } from '../utils/prerenderHTMLIfNecessary';\nimport { setPreNodeProperties } from '../utils/setWrapperNodeProps';\nimport type { WorkerPoolManager } from '../worker';\nimport { DiffsContainerLoaded } from './web-components';\n\nexport interface FileRenderProps<LAnnotation> {\n file: FileContents;\n fileContainer?: HTMLElement;\n containerWrapper?: HTMLElement;\n forceRender?: boolean;\n lineAnnotations?: LineAnnotation<LAnnotation>[];\n}\n\nexport interface FileHyrdateProps<LAnnotation>\n extends Omit<FileRenderProps<LAnnotation>, 'fileContainer'> {\n fileContainer: HTMLElement;\n prerenderedHTML?: string;\n}\n\nexport interface FileOptions<LAnnotation>\n extends BaseCodeOptions,\n MouseEventManagerBaseOptions<'file'>,\n LineSelectionOptions {\n disableFileHeader?: boolean;\n renderCustomMetadata?: RenderFileMetadata;\n renderAnnotation?(\n annotation: LineAnnotation<LAnnotation>\n ): HTMLElement | undefined;\n renderHoverUtility?(\n getHoveredRow: () => GetHoveredLineResult<'file'> | undefined\n ): HTMLElement | null;\n}\n\ninterface AnnotationElementCache<LAnnotation> {\n element: HTMLElement;\n annotation: LineAnnotation<LAnnotation>;\n}\n\nlet instanceId = -1;\n\nexport class File<LAnnotation = undefined> {\n static LoadedCustomComponent: boolean = DiffsContainerLoaded;\n\n readonly __id: string = `file:${++instanceId}`;\n\n private fileContainer: HTMLElement | undefined;\n private spriteSVG: SVGElement | undefined;\n private pre: HTMLPreElement | undefined;\n private code: HTMLElement | undefined;\n private unsafeCSSStyle: HTMLStyleElement | undefined;\n private hoverContent: HTMLElement | undefined;\n private errorWrapper: HTMLElement | undefined;\n private lastRenderedHeaderHTML: string | undefined;\n private appliedPreAttributes: PrePropertiesConfig | undefined;\n\n private headerElement: HTMLElement | undefined;\n private headerMetadata: HTMLElement | undefined;\n\n private fileRenderer: FileRenderer<LAnnotation>;\n private resizeManager: ResizeManager;\n private mouseEventManager: MouseEventManager<'file'>;\n private lineSelectionManager: LineSelectionManager;\n\n private annotationCache: Map<string, AnnotationElementCache<LAnnotation>> =\n new Map();\n private lineAnnotations: LineAnnotation<LAnnotation>[] = [];\n\n private file: FileContents | undefined;\n\n constructor(\n public options: FileOptions<LAnnotation> = { theme: DEFAULT_THEMES },\n private workerManager?: WorkerPoolManager | undefined,\n private isContainerManaged = false\n ) {\n this.fileRenderer = new FileRenderer<LAnnotation>(\n options,\n this.handleHighlightRender,\n this.workerManager\n );\n this.resizeManager = new ResizeManager();\n this.mouseEventManager = new MouseEventManager(\n 'file',\n pluckMouseEventOptions(options)\n );\n this.lineSelectionManager = new LineSelectionManager(\n pluckLineSelectionOptions(options)\n );\n this.workerManager?.subscribeToThemeChanges(this);\n }\n\n private handleHighlightRender = (): void => {\n this.rerender();\n };\n\n rerender(): void {\n if (this.file == null) return;\n this.render({ file: this.file, forceRender: true });\n }\n\n setOptions(options: FileOptions<LAnnotation> | undefined): void {\n if (options == null) return;\n this.options = options;\n this.mouseEventManager.setOptions(pluckMouseEventOptions(options));\n this.lineSelectionManager.setOptions(pluckLineSelectionOptions(options));\n }\n\n private mergeOptions(options: Partial<FileOptions<LAnnotation>>): void {\n this.options = { ...this.options, ...options };\n }\n\n setThemeType(themeType: ThemeTypes): void {\n const currentThemeType = this.options.themeType ?? 'system';\n if (currentThemeType === themeType) {\n return;\n }\n this.mergeOptions({ themeType });\n this.fileRenderer.setThemeType(themeType);\n\n if (this.headerElement != null) {\n if (themeType === 'system') {\n delete this.headerElement.dataset.themeType;\n } else {\n this.headerElement.dataset.themeType = themeType;\n }\n }\n\n // Update pre element theme mode\n if (this.pre != null) {\n switch (themeType) {\n case 'system':\n delete this.pre.dataset.themeType;\n break;\n case 'light':\n case 'dark':\n this.pre.dataset.themeType = themeType;\n break;\n }\n }\n }\n\n getHoveredLine = (): GetHoveredLineResult<'file'> | undefined => {\n return this.mouseEventManager.getHoveredLine();\n };\n\n setLineAnnotations(lineAnnotations: LineAnnotation<LAnnotation>[]): void {\n this.lineAnnotations = lineAnnotations;\n }\n\n setSelectedLines(range: SelectedLineRange | null): void {\n this.lineSelectionManager.setSelection(range);\n }\n\n cleanUp(): void {\n this.fileRenderer.cleanUp();\n this.resizeManager.cleanUp();\n this.mouseEventManager.cleanUp();\n this.lineSelectionManager.cleanUp();\n this.workerManager?.unsubscribeToThemeChanges(this);\n this.workerManager = undefined;\n\n // Clean up the data\n this.file = undefined;\n\n // Clean up the elements\n if (!this.isContainerManaged) {\n this.fileContainer?.parentNode?.removeChild(this.fileContainer);\n }\n if (this.fileContainer?.shadowRoot != null) {\n this.fileContainer.shadowRoot.innerHTML = '';\n }\n this.fileContainer = undefined;\n this.pre = undefined;\n this.appliedPreAttributes = undefined;\n this.headerElement = undefined;\n this.lastRenderedHeaderHTML = undefined;\n this.errorWrapper = undefined;\n this.unsafeCSSStyle = undefined;\n }\n\n hydrate(props: FileHyrdateProps<LAnnotation>): void {\n const { fileContainer, prerenderedHTML } = props;\n prerenderHTMLIfNecessary(fileContainer, prerenderedHTML);\n for (const element of Array.from(\n fileContainer.shadowRoot?.children ?? []\n )) {\n if (element instanceof SVGElement) {\n this.spriteSVG = element;\n continue;\n }\n if (!(element instanceof HTMLElement)) {\n continue;\n }\n if (element instanceof HTMLPreElement) {\n this.pre = element;\n this.appliedPreAttributes = undefined;\n continue;\n }\n if (\n element instanceof HTMLStyleElement &&\n element.hasAttribute(UNSAFE_CSS_ATTRIBUTE)\n ) {\n this.unsafeCSSStyle = element;\n continue;\n }\n if ('diffsHeader' in element.dataset) {\n this.headerElement = element;\n this.lastRenderedHeaderHTML = undefined;\n continue;\n }\n }\n // If we have no pre tag, then we should render\n if (this.pre == null) {\n this.render(props);\n }\n // Otherwise orchestrate our setup\n else {\n const { file, lineAnnotations } = props;\n this.fileContainer = fileContainer;\n delete this.pre.dataset.dehydrated;\n\n this.lineAnnotations = lineAnnotations ?? this.lineAnnotations;\n this.file = file;\n this.fileRenderer.hydrate(file);\n this.renderAnnotations();\n this.renderHoverUtility();\n this.injectUnsafeCSS();\n this.mouseEventManager.setup(this.pre);\n this.lineSelectionManager.setup(this.pre);\n if ((this.options.overflow ?? 'scroll') === 'scroll') {\n this.resizeManager.setup(this.pre);\n }\n }\n }\n\n render({\n file,\n fileContainer,\n forceRender = false,\n containerWrapper,\n lineAnnotations,\n }: FileRenderProps<LAnnotation>): void {\n const annotationsChanged =\n lineAnnotations != null &&\n (lineAnnotations.length > 0 || this.lineAnnotations.length > 0)\n ? lineAnnotations !== this.lineAnnotations\n : false;\n if (!forceRender && areFilesEqual(this.file, file) && !annotationsChanged) {\n return;\n }\n\n this.file = file;\n this.fileRenderer.setOptions(this.options);\n if (lineAnnotations != null) {\n this.setLineAnnotations(lineAnnotations);\n }\n this.fileRenderer.setLineAnnotations(this.lineAnnotations);\n\n const { disableFileHeader = false } = this.options;\n if (disableFileHeader) {\n // Remove existing header from DOM\n if (this.headerElement != null) {\n this.headerElement.parentNode?.removeChild(this.headerElement);\n this.headerElement = undefined;\n this.lastRenderedHeaderHTML = undefined;\n }\n }\n\n fileContainer = this.getOrCreateFileContainerNode(\n fileContainer,\n containerWrapper\n );\n\n try {\n const fileResult = this.fileRenderer.renderFile(file);\n if (fileResult == null) {\n if (this.workerManager != null && !this.workerManager.isInitialized()) {\n void this.workerManager.initialize().then(() => this.rerender());\n }\n return;\n }\n if (fileResult.headerAST != null) {\n this.applyHeaderToDOM(fileResult.headerAST, fileContainer);\n }\n const pre = this.getOrCreatePreNode(fileContainer);\n this.applyHunksToDOM(fileResult, pre);\n this.renderAnnotations();\n this.renderHoverUtility();\n } catch (error: unknown) {\n if (error instanceof Error) {\n console.error(error);\n this.applyErrorToDOM(error, fileContainer);\n }\n }\n }\n\n private renderAnnotations(): void {\n if (this.isContainerManaged || this.fileContainer == null) {\n for (const { element } of this.annotationCache.values()) {\n element.parentNode?.removeChild(element);\n }\n this.annotationCache.clear();\n return;\n }\n const staleAnnotations = new Map(this.annotationCache);\n const { renderAnnotation } = this.options;\n if (renderAnnotation != null && this.lineAnnotations.length > 0) {\n for (const [index, annotation] of this.lineAnnotations.entries()) {\n const id = `${index}-${getLineAnnotationName(annotation)}`;\n let cache = this.annotationCache.get(id);\n if (\n cache == null ||\n !areLineAnnotationsEqual(annotation, cache.annotation)\n ) {\n cache?.element.parentElement?.removeChild(cache.element);\n const content = renderAnnotation(annotation);\n // If we can't render anything, then we should not render anything\n // and clear the annotation cache if necessary.\n if (content == null) {\n continue;\n }\n cache = {\n element: createAnnotationWrapperNode(\n getLineAnnotationName(annotation)\n ),\n annotation,\n };\n cache.element.appendChild(content);\n this.fileContainer.appendChild(cache.element);\n this.annotationCache.set(id, cache);\n }\n staleAnnotations.delete(id);\n }\n }\n for (const [id, { element }] of staleAnnotations.entries()) {\n this.annotationCache.delete(id);\n element.parentNode?.removeChild(element);\n }\n }\n\n private renderHoverUtility() {\n const { renderHoverUtility } = this.options;\n if (this.fileContainer == null || renderHoverUtility == null) {\n return;\n }\n const element = renderHoverUtility(this.mouseEventManager.getHoveredLine);\n if (element != null && this.hoverContent != null) {\n return;\n } else if (element == null) {\n this.hoverContent?.parentNode?.removeChild(this.hoverContent);\n this.hoverContent = undefined;\n return;\n }\n this.hoverContent = createHoverContentNode();\n this.hoverContent.appendChild(element);\n this.fileContainer.appendChild(this.hoverContent);\n }\n\n private injectUnsafeCSS(): void {\n if (this.fileContainer?.shadowRoot == null) {\n return;\n }\n const { unsafeCSS } = this.options;\n\n if (unsafeCSS == null || unsafeCSS === '') {\n if (this.unsafeCSSStyle != null) {\n this.unsafeCSSStyle.parentNode?.removeChild(this.unsafeCSSStyle);\n this.unsafeCSSStyle = undefined;\n }\n return;\n }\n\n // Create or update the style element\n if (this.unsafeCSSStyle == null) {\n this.unsafeCSSStyle = createUnsafeCSSStyleNode();\n this.fileContainer.shadowRoot.appendChild(this.unsafeCSSStyle);\n }\n // Wrap in @layer unsafe to match SSR behavior\n this.unsafeCSSStyle.innerText = wrapUnsafeCSS(unsafeCSS);\n }\n\n private applyHunksToDOM(result: FileRenderResult, pre: HTMLPreElement): void {\n this.cleanupErrorWrapper();\n this.applyPreNodeAttributes(pre, result);\n // Create code elements and insert HTML content\n this.code = getOrCreateCodeNode({ code: this.code });\n this.code.innerHTML = this.fileRenderer.renderPartialHTML(result.codeAST);\n pre.replaceChildren(this.code);\n this.injectUnsafeCSS();\n this.mouseEventManager.setup(pre);\n this.lineSelectionManager.setup(pre);\n this.lineSelectionManager.setDirty();\n if ((this.options.overflow ?? 'scroll') === 'scroll') {\n this.resizeManager.setup(pre);\n } else {\n this.resizeManager.cleanUp();\n }\n }\n\n private applyHeaderToDOM(\n headerAST: HASTElement,\n container: HTMLElement\n ): void {\n const { file } = this;\n if (file == null) return;\n this.cleanupErrorWrapper();\n const headerHTML = toHtml(headerAST);\n if (headerHTML !== this.lastRenderedHeaderHTML) {\n const tempDiv = document.createElement('div');\n tempDiv.innerHTML = headerHTML;\n const newHeader = tempDiv.firstElementChild;\n if (!(newHeader instanceof HTMLElement)) {\n return;\n }\n if (this.headerElement != null) {\n container.shadowRoot?.replaceChild(newHeader, this.headerElement);\n } else {\n container.shadowRoot?.prepend(newHeader);\n }\n this.headerElement = newHeader;\n this.lastRenderedHeaderHTML = headerHTML;\n }\n\n if (this.isContainerManaged) return;\n\n const { renderCustomMetadata } = this.options;\n if (this.headerMetadata != null) {\n this.headerMetadata.parentNode?.removeChild(this.headerMetadata);\n }\n const content = renderCustomMetadata?.(file) ?? undefined;\n if (content != null) {\n this.headerMetadata = document.createElement('div');\n this.headerMetadata.slot = HEADER_METADATA_SLOT_ID;\n if (content instanceof Element) {\n this.headerMetadata.appendChild(content);\n } else {\n this.headerMetadata.innerText = `${content}`;\n }\n container.appendChild(this.headerMetadata);\n }\n }\n\n private getOrCreateFileContainerNode(\n fileContainer?: HTMLElement,\n parentNode?: HTMLElement\n ): HTMLElement {\n const previousContainer = this.fileContainer;\n this.fileContainer =\n fileContainer ??\n this.fileContainer ??\n document.createElement(DIFFS_TAG_NAME);\n if (previousContainer != null && previousContainer !== this.fileContainer) {\n this.lastRenderedHeaderHTML = undefined;\n this.headerElement = undefined;\n }\n if (parentNode != null && this.fileContainer.parentNode !== parentNode) {\n parentNode.appendChild(this.fileContainer);\n }\n if (this.spriteSVG == null) {\n const fragment = document.createElement('div');\n fragment.innerHTML = SVGSpriteSheet;\n const firstChild = fragment.firstChild;\n if (firstChild instanceof SVGElement) {\n this.spriteSVG = firstChild;\n this.fileContainer.shadowRoot?.appendChild(this.spriteSVG);\n }\n }\n return this.fileContainer;\n }\n\n private getOrCreatePreNode(container: HTMLElement): HTMLPreElement {\n // If we haven't created a pre element yet, lets go ahead and do that\n if (this.pre == null) {\n this.pre = document.createElement('pre');\n container.shadowRoot?.appendChild(this.pre);\n this.appliedPreAttributes = undefined;\n }\n // If we have a new parent container for the pre element, lets go ahead and\n // move it into the new container\n else if (this.pre.parentNode !== container) {\n container.shadowRoot?.appendChild(this.pre);\n this.appliedPreAttributes = undefined;\n }\n return this.pre;\n }\n\n private applyPreNodeAttributes(\n pre: HTMLPreElement,\n { totalLines, themeStyles, baseThemeType }: FileRenderResult\n ): void {\n const {\n overflow = 'scroll',\n themeType = 'system',\n disableLineNumbers = false,\n } = this.options;\n const preProperties: PrePropertiesConfig = {\n split: false,\n themeStyles,\n overflow,\n disableLineNumbers,\n themeType: baseThemeType ?? themeType,\n diffIndicators: 'none',\n disableBackground: true,\n totalLines,\n };\n if (arePrePropertiesEqual(preProperties, this.appliedPreAttributes)) {\n return;\n }\n setPreNodeProperties(pre, preProperties);\n this.appliedPreAttributes = preProperties;\n }\n\n private applyErrorToDOM(error: Error, container: HTMLElement) {\n this.cleanupErrorWrapper();\n const pre = this.getOrCreatePreNode(container);\n pre.innerHTML = '';\n pre.parentNode?.removeChild(pre);\n this.pre = undefined;\n this.appliedPreAttributes = undefined;\n const shadowRoot =\n container.shadowRoot ?? container.attachShadow({ mode: 'open' });\n this.errorWrapper ??= document.createElement('div');\n this.errorWrapper.dataset.errorWrapper = '';\n this.errorWrapper.innerHTML = '';\n shadowRoot.appendChild(this.errorWrapper);\n const errorMessage = document.createElement('div');\n errorMessage.dataset.errorMessage = '';\n errorMessage.innerText = error.message;\n this.errorWrapper.appendChild(errorMessage);\n const errorStack = document.createElement('pre');\n errorStack.dataset.errorStack = '';\n errorStack.innerText = error.stack ?? 'No Error Stack';\n this.errorWrapper.appendChild(errorStack);\n }\n\n private cleanupErrorWrapper() {\n this.errorWrapper?.parentNode?.removeChild(this.errorWrapper);\n this.errorWrapper = undefined;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA+EA,IAAI,aAAa;AAEjB,IAAa,OAAb,MAA2C;CACzC,OAAO,wBAAiC;CAExC,AAAS,OAAe,QAAQ,EAAE;CAElC,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CAER,AAAQ;CACR,AAAQ;CAER,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CAER,AAAQ,kCACN,IAAI,KAAK;CACX,AAAQ,kBAAiD,EAAE;CAE3D,AA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YAAY,YAAY,KAAK,IAAI;AAC3C,QAAK,uBAAuB;;AAE9B,SAAO,KAAK;;CAGd,AAAQ,uBACN,KACA,EAAE,YAAY,aAAa,iBACrB;EACN,MAAM,EACJ,WAAW,UACX,YAAY,UACZ,qBAAqB,UACnB,KAAK;EACT,MAAMC,gBAAqC;GACzC,OAAO;GACP;GACA;GACA;GACA,WAAW,iBAAiB;GAC5B,gBAAgB;GAChB,mBAAmB;GACnB;GACD;AACD,MAAI,sBAAsB,eAAe,KAAK,qBAAqB,CACjE;AAEF,uBAAqB,KAAK,cAAc;AACxC,OAAK,uBAAuB;;CAG9B,AAAQ,gBAAgB,OAAc,WAAwB;AAC5D,OAAK,qBAAqB;EAC1B,MAAM,MAAM,KAAK,mBAAmB,UAAU;AAC9C,MAAI,YAAY;AAChB,MAAI,YAAY,YAAY,IAAI;AAChC,OAAK,MAAM;AACX,OAAK,uBAAuB;EAC5B,MAAM,aACJ,UAAU,cAAc,UAAU,aAAa,EAAE,MAAM,QAAQ,CAAC;AAClE,OAAK,iBAAiB,SAAS,cAAc,MAAM;AACnD,OAAK,aAAa,QAAQ,eAAe;AACzC,OAAK,aAAa,YAAY;AAC9B,aAAW,YAAY,KAAK,aAAa;EACzC,MAAM,eAAe,SAAS,cAAc,MAAM;AAClD,eAAa,QAAQ,eAAe;AACpC,eAAa,YAAY,MAAM;AAC/B,OAAK,aAAa,YAAY,aAAa;EAC3C,MAAM,aAAa,SAAS,cAAc,MAAM;AAChD,aAAW,QAAQ,aAAa;AAChC,aAAW,YAAY,MAAM,SAAS;AACtC,OAAK,aAAa,YAAY,WAAW;;CAG3C,AAAQ,sBAAsB;AAC5B,OAAK,cAAc,YAAY,YAAY,KAAK,aAAa;AAC7D,OAAK,eAAe"}
|
|
1
|
+
{"version":3,"file":"File.js","names":["options: FileOptions<LAnnotation>","workerManager?: WorkerPoolManager | undefined","error: unknown","preProperties: PrePropertiesConfig"],"sources":["../../src/components/File.ts"],"sourcesContent":["import type { Element as HASTElement } from 'hast';\nimport { toHtml } from 'hast-util-to-html';\n\nimport {\n DEFAULT_THEMES,\n DIFFS_TAG_NAME,\n HEADER_METADATA_SLOT_ID,\n UNSAFE_CSS_ATTRIBUTE,\n} from '../constants';\nimport {\n LineSelectionManager,\n type LineSelectionOptions,\n type SelectedLineRange,\n pluckLineSelectionOptions,\n} from '../managers/LineSelectionManager';\nimport {\n type GetHoveredLineResult,\n MouseEventManager,\n type MouseEventManagerBaseOptions,\n pluckMouseEventOptions,\n} from '../managers/MouseEventManager';\nimport { ResizeManager } from '../managers/ResizeManager';\nimport { type FileRenderResult, FileRenderer } from '../renderers/FileRenderer';\nimport { SVGSpriteSheet } from '../sprite';\nimport type {\n BaseCodeOptions,\n FileContents,\n LineAnnotation,\n PrePropertiesConfig,\n RenderFileMetadata,\n ThemeTypes,\n} from '../types';\nimport { areFilesEqual } from '../utils/areFilesEqual';\nimport { areLineAnnotationsEqual } from '../utils/areLineAnnotationsEqual';\nimport { arePrePropertiesEqual } from '../utils/arePrePropertiesEqual';\nimport { createAnnotationWrapperNode } from '../utils/createAnnotationWrapperNode';\nimport { createHoverContentNode } from '../utils/createHoverContentNode';\nimport { createUnsafeCSSStyleNode } from '../utils/createUnsafeCSSStyleNode';\nimport { wrapUnsafeCSS } from '../utils/cssWrappers';\nimport { getLineAnnotationName } from '../utils/getLineAnnotationName';\nimport { getOrCreateCodeNode } from '../utils/getOrCreateCodeNode';\nimport { prerenderHTMLIfNecessary } from '../utils/prerenderHTMLIfNecessary';\nimport { setPreNodeProperties } from '../utils/setWrapperNodeProps';\nimport type { WorkerPoolManager } from '../worker';\nimport { DiffsContainerLoaded } from './web-components';\n\nexport interface FileRenderProps<LAnnotation> {\n file: FileContents;\n fileContainer?: HTMLElement;\n containerWrapper?: HTMLElement;\n forceRender?: boolean;\n lineAnnotations?: LineAnnotation<LAnnotation>[];\n}\n\nexport interface FileHyrdateProps<LAnnotation>\n extends Omit<FileRenderProps<LAnnotation>, 'fileContainer'> {\n fileContainer: HTMLElement;\n prerenderedHTML?: string;\n}\n\nexport interface FileOptions<LAnnotation>\n extends BaseCodeOptions,\n MouseEventManagerBaseOptions<'file'>,\n LineSelectionOptions {\n disableFileHeader?: boolean;\n renderCustomMetadata?: RenderFileMetadata;\n /**\n * When true, errors during rendering are rethrown instead of being caught\n * and displayed in the DOM. Useful for testing or when you want to handle\n * errors yourself.\n */\n disableErrorHandling?: boolean;\n renderAnnotation?(\n annotation: LineAnnotation<LAnnotation>\n ): HTMLElement | undefined;\n renderHoverUtility?(\n getHoveredRow: () => GetHoveredLineResult<'file'> | undefined\n ): HTMLElement | null;\n}\n\ninterface AnnotationElementCache<LAnnotation> {\n element: HTMLElement;\n annotation: LineAnnotation<LAnnotation>;\n}\n\nlet instanceId = -1;\n\nexport class File<LAnnotation = undefined> {\n static LoadedCustomComponent: boolean = DiffsContainerLoaded;\n\n readonly __id: string = `file:${++instanceId}`;\n\n private fileContainer: HTMLElement | undefined;\n private spriteSVG: SVGElement | undefined;\n private pre: HTMLPreElement | undefined;\n private code: HTMLElement | undefined;\n private unsafeCSSStyle: HTMLStyleElement | undefined;\n private hoverContent: HTMLElement | undefined;\n private errorWrapper: HTMLElement | undefined;\n private lastRenderedHeaderHTML: string | undefined;\n private appliedPreAttributes: PrePropertiesConfig | undefined;\n\n private headerElement: HTMLElement | undefined;\n private headerMetadata: HTMLElement | undefined;\n\n private fileRenderer: FileRenderer<LAnnotation>;\n private resizeManager: ResizeManager;\n private mouseEventManager: MouseEventManager<'file'>;\n private lineSelectionManager: LineSelectionManager;\n\n private annotationCache: Map<string, AnnotationElementCache<LAnnotation>> =\n new Map();\n private lineAnnotations: LineAnnotation<LAnnotation>[] = [];\n\n private file: FileContents | undefined;\n\n constructor(\n public options: FileOptions<LAnnotation> = { theme: DEFAULT_THEMES },\n private workerManager?: WorkerPoolManager | undefined,\n private isContainerManaged = false\n ) {\n this.fileRenderer = new FileRenderer<LAnnotation>(\n options,\n this.handleHighlightRender,\n this.workerManager\n );\n this.resizeManager = new ResizeManager();\n this.mouseEventManager = new MouseEventManager(\n 'file',\n pluckMouseEventOptions(options)\n );\n this.lineSelectionManager = new LineSelectionManager(\n pluckLineSelectionOptions(options)\n );\n this.workerManager?.subscribeToThemeChanges(this);\n }\n\n private handleHighlightRender = (): void => {\n this.rerender();\n };\n\n rerender(): void {\n if (this.file == null) return;\n this.render({ file: this.file, forceRender: true });\n }\n\n setOptions(options: FileOptions<LAnnotation> | undefined): void {\n if (options == null) return;\n this.options = options;\n this.mouseEventManager.setOptions(pluckMouseEventOptions(options));\n this.lineSelectionManager.setOptions(pluckLineSelectionOptions(options));\n }\n\n private mergeOptions(options: Partial<FileOptions<LAnnotation>>): void {\n this.options = { ...this.options, ...options };\n }\n\n setThemeType(themeType: ThemeTypes): void {\n const currentThemeType = this.options.themeType ?? 'system';\n if (currentThemeType === themeType) {\n return;\n }\n this.mergeOptions({ themeType });\n this.fileRenderer.setThemeType(themeType);\n\n if (this.headerElement != null) {\n if (themeType === 'system') {\n delete this.headerElement.dataset.themeType;\n } else {\n this.headerElement.dataset.themeType = themeType;\n }\n }\n\n // Update pre element theme mode\n if (this.pre != null) {\n switch (themeType) {\n case 'system':\n delete this.pre.dataset.themeType;\n break;\n case 'light':\n case 'dark':\n this.pre.dataset.themeType = themeType;\n break;\n }\n }\n }\n\n getHoveredLine = (): GetHoveredLineResult<'file'> | undefined => {\n return this.mouseEventManager.getHoveredLine();\n };\n\n setLineAnnotations(lineAnnotations: LineAnnotation<LAnnotation>[]): void {\n this.lineAnnotations = lineAnnotations;\n }\n\n setSelectedLines(range: SelectedLineRange | null): void {\n this.lineSelectionManager.setSelection(range);\n }\n\n cleanUp(): void {\n this.fileRenderer.cleanUp();\n this.resizeManager.cleanUp();\n this.mouseEventManager.cleanUp();\n this.lineSelectionManager.cleanUp();\n this.workerManager?.unsubscribeToThemeChanges(this);\n this.workerManager = undefined;\n\n // Clean up the data\n this.file = undefined;\n\n // Clean up the elements\n if (!this.isContainerManaged) {\n this.fileContainer?.parentNode?.removeChild(this.fileContainer);\n }\n if (this.fileContainer?.shadowRoot != null) {\n this.fileContainer.shadowRoot.innerHTML = '';\n }\n this.fileContainer = undefined;\n this.pre = undefined;\n this.appliedPreAttributes = undefined;\n this.headerElement = undefined;\n this.lastRenderedHeaderHTML = undefined;\n this.errorWrapper = undefined;\n this.unsafeCSSStyle = undefined;\n }\n\n hydrate(props: FileHyrdateProps<LAnnotation>): void {\n const { fileContainer, prerenderedHTML } = props;\n prerenderHTMLIfNecessary(fileContainer, prerenderedHTML);\n for (const element of Array.from(\n fileContainer.shadowRoot?.children ?? []\n )) {\n if (element instanceof SVGElement) {\n this.spriteSVG = element;\n continue;\n }\n if (!(element instanceof HTMLElement)) {\n continue;\n }\n if (element instanceof HTMLPreElement) {\n this.pre = element;\n this.appliedPreAttributes = undefined;\n continue;\n }\n if (\n element instanceof HTMLStyleElement &&\n element.hasAttribute(UNSAFE_CSS_ATTRIBUTE)\n ) {\n this.unsafeCSSStyle = element;\n continue;\n }\n if ('diffsHeader' in element.dataset) {\n this.headerElement = element;\n this.lastRenderedHeaderHTML = undefined;\n continue;\n }\n }\n // If we have no pre tag, then we should render\n if (this.pre == null) {\n this.render(props);\n }\n // Otherwise orchestrate our setup\n else {\n const { file, lineAnnotations } = props;\n this.fileContainer = fileContainer;\n delete this.pre.dataset.dehydrated;\n\n this.lineAnnotations = lineAnnotations ?? this.lineAnnotations;\n this.file = file;\n this.fileRenderer.hydrate(file);\n this.renderAnnotations();\n this.renderHoverUtility();\n this.injectUnsafeCSS();\n this.mouseEventManager.setup(this.pre);\n this.lineSelectionManager.setup(this.pre);\n if ((this.options.overflow ?? 'scroll') === 'scroll') {\n this.resizeManager.setup(this.pre);\n }\n }\n }\n\n render({\n file,\n fileContainer,\n forceRender = false,\n containerWrapper,\n lineAnnotations,\n }: FileRenderProps<LAnnotation>): void {\n const annotationsChanged =\n lineAnnotations != null &&\n (lineAnnotations.length > 0 || this.lineAnnotations.length > 0)\n ? lineAnnotations !== this.lineAnnotations\n : false;\n if (!forceRender && areFilesEqual(this.file, file) && !annotationsChanged) {\n return;\n }\n\n this.file = file;\n this.fileRenderer.setOptions(this.options);\n if (lineAnnotations != null) {\n this.setLineAnnotations(lineAnnotations);\n }\n this.fileRenderer.setLineAnnotations(this.lineAnnotations);\n\n const { disableFileHeader = false, disableErrorHandling = false } =\n this.options;\n if (disableFileHeader) {\n // Remove existing header from DOM\n if (this.headerElement != null) {\n this.headerElement.parentNode?.removeChild(this.headerElement);\n this.headerElement = undefined;\n this.lastRenderedHeaderHTML = undefined;\n }\n }\n\n fileContainer = this.getOrCreateFileContainerNode(\n fileContainer,\n containerWrapper\n );\n\n try {\n const fileResult = this.fileRenderer.renderFile(file);\n if (fileResult == null) {\n if (this.workerManager != null && !this.workerManager.isInitialized()) {\n void this.workerManager.initialize().then(() => this.rerender());\n }\n return;\n }\n if (fileResult.headerAST != null) {\n this.applyHeaderToDOM(fileResult.headerAST, fileContainer);\n }\n const pre = this.getOrCreatePreNode(fileContainer);\n this.applyHunksToDOM(fileResult, pre);\n this.renderAnnotations();\n this.renderHoverUtility();\n } catch (error: unknown) {\n if (disableErrorHandling) {\n throw error;\n }\n console.error(error);\n if (error instanceof Error) {\n this.applyErrorToDOM(error, fileContainer);\n }\n }\n }\n\n private renderAnnotations(): void {\n if (this.isContainerManaged || this.fileContainer == null) {\n for (const { element } of this.annotationCache.values()) {\n element.parentNode?.removeChild(element);\n }\n this.annotationCache.clear();\n return;\n }\n const staleAnnotations = new Map(this.annotationCache);\n const { renderAnnotation } = this.options;\n if (renderAnnotation != null && this.lineAnnotations.length > 0) {\n for (const [index, annotation] of this.lineAnnotations.entries()) {\n const id = `${index}-${getLineAnnotationName(annotation)}`;\n let cache = this.annotationCache.get(id);\n if (\n cache == null ||\n !areLineAnnotationsEqual(annotation, cache.annotation)\n ) {\n cache?.element.parentElement?.removeChild(cache.element);\n const content = renderAnnotation(annotation);\n // If we can't render anything, then we should not render anything\n // and clear the annotation cache if necessary.\n if (content == null) {\n continue;\n }\n cache = {\n element: createAnnotationWrapperNode(\n getLineAnnotationName(annotation)\n ),\n annotation,\n };\n cache.element.appendChild(content);\n this.fileContainer.appendChild(cache.element);\n this.annotationCache.set(id, cache);\n }\n staleAnnotations.delete(id);\n }\n }\n for (const [id, { element }] of staleAnnotations.entries()) {\n this.annotationCache.delete(id);\n element.parentNode?.removeChild(element);\n }\n }\n\n private renderHoverUtility() {\n const { renderHoverUtility } = this.options;\n if (this.fileContainer == null || renderHoverUtility == null) {\n return;\n }\n const element = renderHoverUtility(this.mouseEventManager.getHoveredLine);\n if (element != null && this.hoverContent != null) {\n return;\n } else if (element == null) {\n this.hoverContent?.parentNode?.removeChild(this.hoverContent);\n this.hoverContent = undefined;\n return;\n }\n this.hoverContent = createHoverContentNode();\n this.hoverContent.appendChild(element);\n this.fileContainer.appendChild(this.hoverContent);\n }\n\n private injectUnsafeCSS(): void {\n if (this.fileContainer?.shadowRoot == null) {\n return;\n }\n const { unsafeCSS } = this.options;\n\n if (unsafeCSS == null || unsafeCSS === '') {\n if (this.unsafeCSSStyle != null) {\n this.unsafeCSSStyle.parentNode?.removeChild(this.unsafeCSSStyle);\n this.unsafeCSSStyle = undefined;\n }\n return;\n }\n\n // Create or update the style element\n if (this.unsafeCSSStyle == null) {\n this.unsafeCSSStyle = createUnsafeCSSStyleNode();\n this.fileContainer.shadowRoot.appendChild(this.unsafeCSSStyle);\n }\n // Wrap in @layer unsafe to match SSR behavior\n this.unsafeCSSStyle.innerText = wrapUnsafeCSS(unsafeCSS);\n }\n\n private applyHunksToDOM(result: FileRenderResult, pre: HTMLPreElement): void {\n this.cleanupErrorWrapper();\n this.applyPreNodeAttributes(pre, result);\n // Create code elements and insert HTML content\n this.code = getOrCreateCodeNode({ code: this.code });\n this.code.innerHTML = this.fileRenderer.renderPartialHTML(result.codeAST);\n pre.replaceChildren(this.code);\n this.injectUnsafeCSS();\n this.mouseEventManager.setup(pre);\n this.lineSelectionManager.setup(pre);\n this.lineSelectionManager.setDirty();\n if ((this.options.overflow ?? 'scroll') === 'scroll') {\n this.resizeManager.setup(pre);\n } else {\n this.resizeManager.cleanUp();\n }\n }\n\n private applyHeaderToDOM(\n headerAST: HASTElement,\n container: HTMLElement\n ): void {\n const { file } = this;\n if (file == null) return;\n this.cleanupErrorWrapper();\n const headerHTML = toHtml(headerAST);\n if (headerHTML !== this.lastRenderedHeaderHTML) {\n const tempDiv = document.createElement('div');\n tempDiv.innerHTML = headerHTML;\n const newHeader = tempDiv.firstElementChild;\n if (!(newHeader instanceof HTMLElement)) {\n return;\n }\n if (this.headerElement != null) {\n container.shadowRoot?.replaceChild(newHeader, this.headerElement);\n } else {\n container.shadowRoot?.prepend(newHeader);\n }\n this.headerElement = newHeader;\n this.lastRenderedHeaderHTML = headerHTML;\n }\n\n if (this.isContainerManaged) return;\n\n const { renderCustomMetadata } = this.options;\n if (this.headerMetadata != null) {\n this.headerMetadata.parentNode?.removeChild(this.headerMetadata);\n }\n const content = renderCustomMetadata?.(file) ?? undefined;\n if (content != null) {\n this.headerMetadata = document.createElement('div');\n this.headerMetadata.slot = HEADER_METADATA_SLOT_ID;\n if (content instanceof Element) {\n this.headerMetadata.appendChild(content);\n } else {\n this.headerMetadata.innerText = `${content}`;\n }\n container.appendChild(this.headerMetadata);\n }\n }\n\n private getOrCreateFileContainerNode(\n fileContainer?: HTMLElement,\n parentNode?: HTMLElement\n ): HTMLElement {\n const previousContainer = this.fileContainer;\n this.fileContainer =\n fileContainer ??\n this.fileContainer ??\n document.createElement(DIFFS_TAG_NAME);\n if (previousContainer != null && previousContainer !== this.fileContainer) {\n this.lastRenderedHeaderHTML = undefined;\n this.headerElement = undefined;\n }\n if (parentNode != null && this.fileContainer.parentNode !== parentNode) {\n parentNode.appendChild(this.fileContainer);\n }\n if (this.spriteSVG == null) {\n const fragment = document.createElement('div');\n fragment.innerHTML = SVGSpriteSheet;\n const firstChild = fragment.firstChild;\n if (firstChild instanceof SVGElement) {\n this.spriteSVG = firstChild;\n this.fileContainer.shadowRoot?.appendChild(this.spriteSVG);\n }\n }\n return this.fileContainer;\n }\n\n private getOrCreatePreNode(container: HTMLElement): HTMLPreElement {\n // If we haven't created a pre element yet, lets go ahead and do that\n if (this.pre == null) {\n this.pre = document.createElement('pre');\n container.shadowRoot?.appendChild(this.pre);\n this.appliedPreAttributes = undefined;\n }\n // If we have a new parent container for the pre element, lets go ahead and\n // move it into the new container\n else if (this.pre.parentNode !== container) {\n container.shadowRoot?.appendChild(this.pre);\n this.appliedPreAttributes = undefined;\n }\n return this.pre;\n }\n\n private applyPreNodeAttributes(\n pre: HTMLPreElement,\n { totalLines, themeStyles, baseThemeType }: FileRenderResult\n ): void {\n const {\n overflow = 'scroll',\n themeType = 'system',\n disableLineNumbers = false,\n } = this.options;\n const preProperties: PrePropertiesConfig = {\n split: false,\n themeStyles,\n overflow,\n disableLineNumbers,\n themeType: baseThemeType ?? themeType,\n diffIndicators: 'none',\n disableBackground: true,\n totalLines,\n };\n if (arePrePropertiesEqual(preProperties, this.appliedPreAttributes)) {\n return;\n }\n setPreNodeProperties(pre, preProperties);\n this.appliedPreAttributes = preProperties;\n }\n\n private applyErrorToDOM(error: Error, container: HTMLElement) {\n this.cleanupErrorWrapper();\n const pre = this.getOrCreatePreNode(container);\n pre.innerHTML = '';\n pre.parentNode?.removeChild(pre);\n this.pre = undefined;\n this.appliedPreAttributes = undefined;\n const shadowRoot =\n container.shadowRoot ?? container.attachShadow({ mode: 'open' });\n this.errorWrapper ??= document.createElement('div');\n this.errorWrapper.dataset.errorWrapper = '';\n this.errorWrapper.innerHTML = '';\n shadowRoot.appendChild(this.errorWrapper);\n const errorMessage = document.createElement('div');\n errorMessage.dataset.errorMessage = '';\n errorMessage.innerText = error.message;\n this.errorWrapper.appendChild(errorMessage);\n const errorStack = document.createElement('pre');\n errorStack.dataset.errorStack = '';\n errorStack.innerText = error.stack ?? 'No Error Stack';\n this.errorWrapper.appendChild(errorStack);\n }\n\n private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AAK,aAAa;EACzC,MAAM,eAAe,SAAS,cAAc,MAAM;AAClD,eAAa,QAAQ,eAAe;AACpC,eAAa,YAAY,MAAM;AAC/B,OAAK,aAAa,YAAY,aAAa;EAC3C,MAAM,aAAa,SAAS,cAAc,MAAM;AAChD,aAAW,QAAQ,aAAa;AAChC,aAAW,YAAY,MAAM,SAAS;AACtC,OAAK,aAAa,YAAY,WAAW;;CAG3C,AAAQ,sBAAsB;AAC5B,OAAK,cAAc,YAAY,YAAY,KAAK,aAAa;AAC7D,OAAK,eAAe"}
|
|
@@ -26,6 +26,12 @@ interface FileDiffOptions<LAnnotation> extends Omit<BaseDiffOptions, "hunkSepara
|
|
|
26
26
|
hunkSeparators?: Exclude<HunkSeparators, "custom"> | ((hunk: HunkData, instance: FileDiff<LAnnotation>) => HTMLElement | DocumentFragment);
|
|
27
27
|
disableFileHeader?: boolean;
|
|
28
28
|
renderHeaderMetadata?: RenderHeaderMetadataCallback;
|
|
29
|
+
/**
|
|
30
|
+
* When true, errors during rendering are rethrown instead of being caught
|
|
31
|
+
* and displayed in the DOM. Useful for testing or when you want to handle
|
|
32
|
+
* errors yourself.
|
|
33
|
+
*/
|
|
34
|
+
disableErrorHandling?: boolean;
|
|
29
35
|
renderAnnotation?(annotation: DiffLineAnnotation<LAnnotation>): HTMLElement | undefined;
|
|
30
36
|
renderHoverUtility?(getHoveredRow: () => GetHoveredLineResult<"diff"> | undefined): HTMLElement | null;
|
|
31
37
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileDiff.d.ts","names":["options: FileDiffOptions<LAnnotation>","workerManager?: WorkerPoolManager | undefined"],"sources":["../../src/components/FileDiff.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;UA0DiB;aACJ;YACD;EAFZ,OAAiB,CAAA,EAGL,YAHK;EACJ,WAAA,CAAA,EAAA,OAAA;EACD,aAAA,CAAA,EAGM,WAHN;EACA,gBAAA,CAAA,EAGS,WAHT;EAEM,eAAA,CAAA,EAEE,kBAFF,CAEqB,WAFrB,CAAA,EAAA;EACG,WAAA,CAAA,EAEL,WAFK;;AACD,UAIH,sBAJG,CAAA,WAAA,CAAA,SAKV,IALU,CAKL,mBALK,CAKe,WALf,CAAA,EAAA,eAAA,CAAA,CAAA;EACJ,aAAA,EAKC,WALD;EAAA,eAAA,CAAA,EAAA,MAAA;AAGhB;AACmC,UAKlB,eALkB,CAAA,WAAA,CAAA,SAMzB,IANyB,CAMpB,eANoB,EAAA,gBAAA,CAAA,EAO/B,4BAP+B,CAAA,MAAA,CAAA,EAQ/B,oBAR+B,CAAA;EAApB,cAAA,CAAA,EAUT,OAVS,CAUD,cAVC,EAAA,QAAA,CAAA,GAAA,CAAA,CAAA,IAAA,EAYD,QAZC,EAAA,QAAA,EAaG,QAbH,CAaY,WAbZ,CAAA,EAAA,GAcJ,WAdI,GAcU,gBAdV,CAAA;EACE,iBAAA,CAAA,EAAA,OAAA;EADP,oBAAA,CAAA,EAgBe,4BAhBf;EAAA,gBAAA,EAAA,UAAA,
|
|
1
|
+
{"version":3,"file":"FileDiff.d.ts","names":["options: FileDiffOptions<LAnnotation>","workerManager?: WorkerPoolManager | undefined"],"sources":["../../src/components/FileDiff.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;UA0DiB;aACJ;YACD;EAFZ,OAAiB,CAAA,EAGL,YAHK;EACJ,WAAA,CAAA,EAAA,OAAA;EACD,aAAA,CAAA,EAGM,WAHN;EACA,gBAAA,CAAA,EAGS,WAHT;EAEM,eAAA,CAAA,EAEE,kBAFF,CAEqB,WAFrB,CAAA,EAAA;EACG,WAAA,CAAA,EAEL,WAFK;;AACD,UAIH,sBAJG,CAAA,WAAA,CAAA,SAKV,IALU,CAKL,mBALK,CAKe,WALf,CAAA,EAAA,eAAA,CAAA,CAAA;EACJ,aAAA,EAKC,WALD;EAAA,eAAA,CAAA,EAAA,MAAA;AAGhB;AACmC,UAKlB,eALkB,CAAA,WAAA,CAAA,SAMzB,IANyB,CAMpB,eANo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hunkSeparators === "function" ? "custom" : this.options.hunkSeparators
|
|
233
233
|
});
|
|
234
234
|
this.hunksRenderer.setLineAnnotations(this.lineAnnotations);
|
|
235
|
-
const { disableFileHeader = false } = this.options;
|
|
235
|
+
const { disableFileHeader = false, disableErrorHandling = false } = this.options;
|
|
236
236
|
if (disableFileHeader) {
|
|
237
237
|
if (this.headerElement != null) {
|
|
238
238
|
this.headerElement.parentNode?.removeChild(this.headerElement);
|
|
@@ -259,10 +259,9 @@ var FileDiff = class {
|
|
|
259
259
|
this.renderAnnotations();
|
|
260
260
|
this.renderHoverUtility();
|
|
261
261
|
} catch (error) {
|
|
262
|
-
if (
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
}
|
|
262
|
+
if (disableErrorHandling) throw error;
|
|
263
|
+
console.error(error);
|
|
264
|
+
if (error instanceof Error) this.applyErrorToDOM(error, fileContainer);
|
|
266
265
|
}
|
|
267
266
|
}
|
|
268
267
|
renderSeparators(hunkData) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileDiff.js","names":["options: FileDiffOptions<LAnnotation>","workerManager?: WorkerPoolManager | undefined","error: unknown","codeDeletions: HTMLElement | undefined","codeAdditions: HTMLElement | undefined","codeElements: HTMLElement[]","preProperties: PrePropertiesConfig"],"sources":["../../src/components/FileDiff.ts"],"sourcesContent":["import type { Element as HASTElement } from 'hast';\nimport { toHtml } from 'hast-util-to-html';\n\nimport {\n DEFAULT_THEMES,\n DIFFS_TAG_NAME,\n HEADER_METADATA_SLOT_ID,\n UNSAFE_CSS_ATTRIBUTE,\n} from '../constants';\nimport {\n LineSelectionManager,\n type LineSelectionOptions,\n type SelectedLineRange,\n pluckLineSelectionOptions,\n} from '../managers/LineSelectionManager';\nimport {\n type GetHoveredLineResult,\n MouseEventManager,\n type MouseEventManagerBaseOptions,\n pluckMouseEventOptions,\n} from '../managers/MouseEventManager';\nimport { ResizeManager } from '../managers/ResizeManager';\nimport { ScrollSyncManager } from '../managers/ScrollSyncManager';\nimport {\n DiffHunksRenderer,\n type HunksRenderResult,\n} from '../renderers/DiffHunksRenderer';\nimport { SVGSpriteSheet } from '../sprite';\nimport type {\n BaseDiffOptions,\n DiffLineAnnotation,\n ExpansionDirections,\n FileContents,\n FileDiffMetadata,\n HunkData,\n HunkSeparators,\n PrePropertiesConfig,\n RenderHeaderMetadataCallback,\n RenderRange,\n ThemeTypes,\n} from '../types';\nimport { areDiffLineAnnotationsEqual } from '../utils/areDiffLineAnnotationsEqual';\nimport { areFilesEqual } from '../utils/areFilesEqual';\nimport { areHunkDataEqual } from '../utils/areHunkDataEqual';\nimport { arePrePropertiesEqual } from '../utils/arePrePropertiesEqual';\nimport { areRenderRangesEqual } from '../utils/areRenderRangesEqual';\nimport { createAnnotationWrapperNode } from '../utils/createAnnotationWrapperNode';\nimport { createHoverContentNode } from '../utils/createHoverContentNode';\nimport { createUnsafeCSSStyleNode } from '../utils/createUnsafeCSSStyleNode';\nimport { wrapUnsafeCSS } from '../utils/cssWrappers';\nimport { getLineAnnotationName } from '../utils/getLineAnnotationName';\nimport { getOrCreateCodeNode } from '../utils/getOrCreateCodeNode';\nimport { parseDiffFromFile } from '../utils/parseDiffFromFile';\nimport { prerenderHTMLIfNecessary } from '../utils/prerenderHTMLIfNecessary';\nimport { setPreNodeProperties } from '../utils/setWrapperNodeProps';\nimport type { WorkerPoolManager } from '../worker';\nimport { DiffsContainerLoaded } from './web-components';\n\nexport interface FileDiffRenderProps<LAnnotation> {\n fileDiff?: FileDiffMetadata;\n oldFile?: FileContents;\n newFile?: FileContents;\n forceRender?: boolean;\n fileContainer?: HTMLElement;\n containerWrapper?: HTMLElement;\n lineAnnotations?: DiffLineAnnotation<LAnnotation>[];\n renderRange?: RenderRange;\n}\n\nexport interface FileDiffHydrationProps<LAnnotation>\n extends Omit<FileDiffRenderProps<LAnnotation>, 'fileContainer'> {\n fileContainer: HTMLElement;\n prerenderedHTML?: string;\n}\n\nexport interface FileDiffOptions<LAnnotation>\n extends Omit<BaseDiffOptions, 'hunkSeparators'>,\n MouseEventManagerBaseOptions<'diff'>,\n LineSelectionOptions {\n hunkSeparators?:\n | Exclude<HunkSeparators, 'custom'>\n | ((\n hunk: HunkData,\n instance: FileDiff<LAnnotation>\n ) => HTMLElement | DocumentFragment);\n disableFileHeader?: boolean;\n renderHeaderMetadata?: RenderHeaderMetadataCallback;\n renderAnnotation?(\n annotation: DiffLineAnnotation<LAnnotation>\n ): HTMLElement | undefined;\n renderHoverUtility?(\n getHoveredRow: () => GetHoveredLineResult<'diff'> | undefined\n ): HTMLElement | null;\n}\n\ninterface AnnotationElementCache<LAnnotation> {\n element: HTMLElement;\n annotation: DiffLineAnnotation<LAnnotation>;\n}\n\ninterface CustomHunkElementCache {\n element: HTMLElement;\n hunkData: HunkData;\n}\n\nlet instanceId = -1;\n\nexport class FileDiff<LAnnotation = undefined> {\n // NOTE(amadeus): We sorta need this to ensure the web-component file is\n // properly loaded\n static LoadedCustomComponent: boolean = DiffsContainerLoaded;\n\n readonly __id: string = `file-diff:${++instanceId}`;\n\n protected fileContainer: HTMLElement | undefined;\n protected spriteSVG: SVGElement | undefined;\n protected pre: HTMLPreElement | undefined;\n protected codeUnified: HTMLElement | undefined;\n protected codeDeletions: HTMLElement | undefined;\n protected codeAdditions: HTMLElement | undefined;\n protected unsafeCSSStyle: HTMLStyleElement | undefined;\n protected hoverContent: HTMLElement | undefined;\n\n protected headerElement: HTMLElement | undefined;\n protected headerMetadata: HTMLElement | undefined;\n protected separatorCache: Map<string, CustomHunkElementCache> = new Map();\n protected errorWrapper: HTMLElement | undefined;\n\n protected hunksRenderer: DiffHunksRenderer<LAnnotation>;\n protected resizeManager: ResizeManager;\n protected scrollSyncManager: ScrollSyncManager;\n protected mouseEventManager: MouseEventManager<'diff'>;\n protected lineSelectionManager: LineSelectionManager;\n\n protected annotationCache: Map<string, AnnotationElementCache<LAnnotation>> =\n new Map();\n protected lineAnnotations: DiffLineAnnotation<LAnnotation>[] = [];\n\n protected deletionFile: FileContents | undefined;\n protected additionFile: FileContents | undefined;\n protected fileDiff: FileDiffMetadata | undefined;\n protected renderRange: RenderRange | undefined;\n protected appliedPreAttributes: PrePropertiesConfig | undefined;\n protected lastRenderedHeaderHTML: string | undefined;\n\n protected enabled = true;\n\n constructor(\n public options: FileDiffOptions<LAnnotation> = { theme: DEFAULT_THEMES },\n protected workerManager?: WorkerPoolManager | undefined,\n protected isContainerManaged = false\n ) {\n this.hunksRenderer = new DiffHunksRenderer(\n {\n ...options,\n hunkSeparators:\n typeof options.hunkSeparators === 'function'\n ? 'custom'\n : options.hunkSeparators,\n },\n this.handleHighlightRender,\n this.workerManager\n );\n this.resizeManager = new ResizeManager();\n this.scrollSyncManager = new ScrollSyncManager();\n this.mouseEventManager = new MouseEventManager(\n 'diff',\n pluckMouseEventOptions(\n options,\n typeof options.hunkSeparators === 'function' ||\n (options.hunkSeparators ?? 'line-info') === 'line-info'\n ? this.handleExpandHunk\n : undefined\n )\n );\n this.lineSelectionManager = new LineSelectionManager(\n pluckLineSelectionOptions(options)\n );\n this.workerManager?.subscribeToThemeChanges(this);\n this.enabled = true;\n }\n\n private handleHighlightRender = (): void => {\n this.rerender();\n };\n\n // FIXME(amadeus): This is a bit of a looming issue that I'll need to resolve:\n // * Do we publicly allow merging of options or do we have individualized setters?\n // * When setting new options, we need to figure out what settings require a\n // re-render and which can just be applied more elegantly\n // * There's also an issue of options that live here on the File class and\n // those that live on the Hunk class, and it's a bit of an issue with passing\n // settings down and mirroring them (not great...)\n setOptions(options: FileDiffOptions<LAnnotation> | undefined): void {\n if (options == null) return;\n this.options = options;\n this.hunksRenderer.setOptions({\n ...this.options,\n hunkSeparators:\n typeof options.hunkSeparators === 'function'\n ? 'custom'\n : options.hunkSeparators,\n });\n this.mouseEventManager.setOptions(\n pluckMouseEventOptions(\n options,\n typeof options.hunkSeparators === 'function' ||\n (options.hunkSeparators ?? 'line-info') === 'line-info'\n ? this.handleExpandHunk\n : undefined\n )\n );\n this.lineSelectionManager.setOptions(pluckLineSelectionOptions(options));\n }\n\n private mergeOptions(options: Partial<FileDiffOptions<LAnnotation>>): void {\n this.options = { ...this.options, ...options };\n }\n\n setThemeType(themeType: ThemeTypes): void {\n if ((this.options.themeType ?? 'system') === themeType) {\n return;\n }\n this.mergeOptions({ themeType });\n this.hunksRenderer.setThemeType(themeType);\n\n if (this.headerElement != null) {\n if (themeType === 'system') {\n delete this.headerElement.dataset.themeType;\n } else {\n this.headerElement.dataset.themeType = themeType;\n }\n }\n\n // Update pre element theme mode\n if (this.pre != null) {\n switch (themeType) {\n case 'system':\n delete this.pre.dataset.themeType;\n break;\n case 'light':\n case 'dark':\n this.pre.dataset.themeType = themeType;\n break;\n }\n }\n }\n\n getHoveredLine = (): GetHoveredLineResult<'diff'> | undefined => {\n return this.mouseEventManager.getHoveredLine();\n };\n\n setLineAnnotations(lineAnnotations: DiffLineAnnotation<LAnnotation>[]): void {\n this.lineAnnotations = lineAnnotations;\n }\n\n setSelectedLines(range: SelectedLineRange | null): void {\n this.lineSelectionManager.setSelection(range);\n }\n\n cleanUp(recycle: boolean = false): void {\n this.resizeManager.cleanUp();\n this.mouseEventManager.cleanUp();\n this.scrollSyncManager.cleanUp();\n this.lineSelectionManager.cleanUp();\n this.workerManager?.unsubscribeToThemeChanges(this);\n this.renderRange = undefined;\n\n // Clean up the elements\n if (!this.isContainerManaged) {\n this.fileContainer?.parentNode?.removeChild(this.fileContainer);\n }\n if (this.fileContainer?.shadowRoot != null) {\n // Manually help garbage collection\n this.fileContainer.shadowRoot.innerHTML = '';\n }\n this.fileContainer = undefined;\n // Manually help garbage collection\n if (this.pre != null) {\n this.pre.innerHTML = '';\n this.pre = undefined;\n }\n this.codeUnified = undefined;\n this.codeDeletions = undefined;\n this.codeAdditions = undefined;\n this.appliedPreAttributes = undefined;\n this.headerElement = undefined;\n this.lastRenderedHeaderHTML = undefined;\n this.errorWrapper = undefined;\n this.spriteSVG = undefined;\n\n if (recycle) {\n this.hunksRenderer.recycle();\n } else {\n this.hunksRenderer.cleanUp();\n this.workerManager = undefined;\n // Clean up the data\n this.fileDiff = undefined;\n this.deletionFile = undefined;\n this.additionFile = undefined;\n }\n\n this.enabled = false;\n }\n\n virtualizedSetup(): void {\n this.enabled = true;\n this.workerManager?.subscribeToThemeChanges(this);\n }\n\n hydrate(props: FileDiffHydrationProps<LAnnotation>): void {\n const { fileContainer, prerenderedHTML } = props;\n prerenderHTMLIfNecessary(fileContainer, prerenderedHTML);\n for (const element of fileContainer.shadowRoot?.children ?? []) {\n if (element instanceof SVGElement) {\n this.spriteSVG = element;\n continue;\n }\n if (!(element instanceof HTMLElement)) {\n continue;\n }\n if (element instanceof HTMLPreElement) {\n this.pre = element;\n for (const code of element.children) {\n if (\n !(code instanceof HTMLElement) ||\n code.tagName.toLowerCase() !== 'code'\n ) {\n continue;\n }\n if ('deletions' in code.dataset) {\n this.codeDeletions = code;\n }\n if ('additions' in code.dataset) {\n this.codeAdditions = code;\n }\n if ('unified' in code.dataset) {\n this.codeUnified = code;\n }\n }\n continue;\n }\n if ('diffsHeader' in element.dataset) {\n this.headerElement = element;\n continue;\n }\n if (\n element instanceof HTMLStyleElement &&\n element.hasAttribute(UNSAFE_CSS_ATTRIBUTE)\n ) {\n this.unsafeCSSStyle = element;\n continue;\n }\n }\n if (this.pre != null) {\n this.syncCodeNodesFromPre(this.pre);\n }\n // If we have no pre tag, then we should render\n if (this.pre == null) {\n this.render(props);\n }\n // Otherwise orchestrate our setup\n else {\n const { lineAnnotations, oldFile, newFile, fileDiff } = props;\n this.fileContainer = fileContainer;\n delete this.pre.dataset.dehydrated;\n\n this.lineAnnotations = lineAnnotations ?? this.lineAnnotations;\n this.additionFile = newFile;\n this.deletionFile = oldFile;\n this.fileDiff =\n fileDiff ??\n (oldFile != null && newFile != null\n ? parseDiffFromFile(oldFile, newFile)\n : undefined);\n\n this.hunksRenderer.hydrate(this.fileDiff);\n // FIXME(amadeus): not sure how to handle this yet...\n // this.renderSeparators();\n this.renderAnnotations();\n this.renderHoverUtility();\n this.injectUnsafeCSS();\n this.mouseEventManager.setup(this.pre);\n this.lineSelectionManager.setup(this.pre);\n if ((this.options.overflow ?? 'scroll') === 'scroll') {\n this.resizeManager.setup(this.pre);\n if ((this.options.diffStyle ?? 'split') === 'split') {\n this.scrollSyncManager.setup(\n this.pre,\n this.codeDeletions,\n this.codeAdditions\n );\n }\n }\n }\n }\n\n rerender(): void {\n if (\n !this.enabled ||\n (this.fileDiff == null &&\n this.additionFile == null &&\n this.deletionFile == null)\n ) {\n return;\n }\n this.render({\n oldFile: this.deletionFile,\n newFile: this.additionFile,\n fileDiff: this.fileDiff,\n forceRender: true,\n renderRange: this.renderRange,\n });\n }\n\n handleExpandHunk = (\n hunkIndex: number,\n direction: ExpansionDirections\n ): void => {\n this.expandHunk(hunkIndex, direction);\n };\n\n expandHunk(hunkIndex: number, direction: ExpansionDirections): void {\n this.hunksRenderer.expandHunk(hunkIndex, direction);\n this.rerender();\n }\n\n render({\n oldFile,\n newFile,\n fileDiff,\n forceRender = false,\n lineAnnotations,\n fileContainer,\n containerWrapper,\n renderRange,\n }: FileDiffRenderProps<LAnnotation>): void {\n if (!this.enabled) {\n // NOTE(amadeus): May need to be a silent failure? Making it loud for now\n // to better understand it\n throw new Error(\n 'FileDiff.render: attempting to call render after cleaned up'\n );\n }\n const filesDidChange =\n oldFile != null &&\n newFile != null &&\n (!areFilesEqual(oldFile, this.deletionFile) ||\n !areFilesEqual(newFile, this.additionFile));\n const annotationsChanged =\n lineAnnotations != null &&\n (lineAnnotations.length > 0 || this.lineAnnotations.length > 0)\n ? lineAnnotations !== this.lineAnnotations\n : false;\n if (\n areRenderRangesEqual(renderRange, this.renderRange) &&\n !forceRender &&\n !annotationsChanged &&\n // If using the fileDiff API, lets check to see if they are equal to\n // avoid doing work\n ((fileDiff != null && fileDiff === this.fileDiff) ||\n // If using the oldFile/newFile API then lets check to see if they are\n // equal\n (fileDiff == null && !filesDidChange))\n ) {\n return;\n }\n\n this.renderRange = renderRange;\n this.deletionFile = oldFile;\n this.additionFile = newFile;\n if (fileDiff != null) {\n this.fileDiff = fileDiff;\n } else if (oldFile != null && newFile != null && filesDidChange) {\n this.fileDiff = parseDiffFromFile(oldFile, newFile);\n }\n\n if (lineAnnotations != null) {\n this.setLineAnnotations(lineAnnotations);\n }\n if (this.fileDiff == null) {\n return;\n }\n this.hunksRenderer.setOptions({\n ...this.options,\n hunkSeparators:\n typeof this.options.hunkSeparators === 'function'\n ? 'custom'\n : this.options.hunkSeparators,\n });\n\n this.hunksRenderer.setLineAnnotations(this.lineAnnotations);\n\n const { disableFileHeader = false } = this.options;\n\n if (disableFileHeader) {\n // Remove existing header from DOM\n if (this.headerElement != null) {\n this.headerElement.parentNode?.removeChild(this.headerElement);\n this.headerElement = undefined;\n this.lastRenderedHeaderHTML = undefined;\n }\n }\n fileContainer = this.getOrCreateFileContainer(\n fileContainer,\n containerWrapper\n );\n\n try {\n const hunksResult = this.hunksRenderer.renderDiff(\n this.fileDiff,\n renderRange\n );\n if (hunksResult == null) {\n if (this.workerManager != null && !this.workerManager.isInitialized()) {\n void this.workerManager.initialize().then(() => this.rerender());\n }\n return;\n }\n\n if (hunksResult.headerElement != null) {\n this.applyHeaderToDOM(hunksResult.headerElement, fileContainer);\n }\n if (\n hunksResult.additionsAST != null ||\n hunksResult.deletionsAST != null ||\n hunksResult.unifiedAST != null\n ) {\n const pre = this.getOrCreatePreNode(fileContainer);\n this.applyHunksToDOM(pre, hunksResult);\n } else if (this.pre != null) {\n this.pre.parentNode?.removeChild(this.pre);\n this.pre = undefined;\n }\n this.renderSeparators(hunksResult.hunkData);\n this.renderAnnotations();\n this.renderHoverUtility();\n } catch (error: unknown) {\n if (error instanceof Error) {\n console.error(error);\n this.applyErrorToDOM(error, fileContainer);\n }\n }\n }\n\n private renderSeparators(hunkData: HunkData[]): void {\n const { hunkSeparators } = this.options;\n if (\n this.isContainerManaged ||\n this.fileContainer == null ||\n typeof hunkSeparators !== 'function'\n ) {\n for (const { element } of this.separatorCache.values()) {\n element.parentNode?.removeChild(element);\n }\n this.separatorCache.clear();\n return;\n }\n const staleSeparators = new Map(this.separatorCache);\n for (const hunk of hunkData) {\n const id = hunk.slotName;\n let cache = this.separatorCache.get(id);\n if (cache == null || !areHunkDataEqual(hunk, cache.hunkData)) {\n cache?.element.parentNode?.removeChild(cache.element);\n const element = document.createElement('div');\n element.style.display = 'contents';\n element.slot = hunk.slotName;\n element.appendChild(hunkSeparators(hunk, this));\n this.fileContainer.appendChild(element);\n cache = { element, hunkData: hunk };\n this.separatorCache.set(id, cache);\n }\n staleSeparators.delete(id);\n }\n for (const [id, { element }] of staleSeparators.entries()) {\n this.separatorCache.delete(id);\n element.parentNode?.removeChild(element);\n }\n }\n\n private renderAnnotations(): void {\n if (this.isContainerManaged || this.fileContainer == null) {\n for (const { element } of this.annotationCache.values()) {\n element.parentNode?.removeChild(element);\n }\n this.annotationCache.clear();\n return;\n }\n const staleAnnotations = new Map(this.annotationCache);\n const { renderAnnotation } = this.options;\n if (renderAnnotation != null && this.lineAnnotations.length > 0) {\n for (const [index, annotation] of this.lineAnnotations.entries()) {\n const id = `${index}-${getLineAnnotationName(annotation)}`;\n let cache = this.annotationCache.get(id);\n if (\n cache == null ||\n !areDiffLineAnnotationsEqual(annotation, cache.annotation)\n ) {\n cache?.element.parentElement?.removeChild(cache.element);\n const content = renderAnnotation(annotation);\n // If we can't render anything, then we should not render anything\n // and clear the annotation cache if necessary.\n if (content == null) {\n continue;\n }\n cache = {\n element: createAnnotationWrapperNode(\n getLineAnnotationName(annotation)\n ),\n annotation,\n };\n cache.element.appendChild(content);\n this.fileContainer.appendChild(cache.element);\n this.annotationCache.set(id, cache);\n }\n staleAnnotations.delete(id);\n }\n }\n for (const [id, { element }] of staleAnnotations.entries()) {\n this.annotationCache.delete(id);\n element.parentNode?.removeChild(element);\n }\n }\n\n private renderHoverUtility() {\n const { renderHoverUtility } = this.options;\n if (this.fileContainer == null || renderHoverUtility == null) {\n return;\n }\n const element = renderHoverUtility(this.mouseEventManager.getHoveredLine);\n if (element != null && this.hoverContent != null) {\n return;\n } else if (element == null) {\n this.hoverContent?.parentNode?.removeChild(this.hoverContent);\n this.hoverContent = undefined;\n return;\n }\n this.hoverContent = createHoverContentNode();\n this.hoverContent.appendChild(element);\n this.fileContainer.appendChild(this.hoverContent);\n }\n\n getOrCreateFileContainer(\n fileContainer?: HTMLElement,\n parentNode?: HTMLElement\n ): HTMLElement {\n const previousContainer = this.fileContainer;\n this.fileContainer =\n fileContainer ??\n this.fileContainer ??\n document.createElement(DIFFS_TAG_NAME);\n // NOTE(amadeus): If the container changes, we should reset the rendered\n // HTML\n if (previousContainer != null && previousContainer !== this.fileContainer) {\n this.lastRenderedHeaderHTML = undefined;\n this.headerElement = undefined;\n }\n if (parentNode != null && this.fileContainer.parentNode !== parentNode) {\n parentNode.appendChild(this.fileContainer);\n }\n if (this.spriteSVG == null) {\n const fragment = document.createElement('div');\n fragment.innerHTML = SVGSpriteSheet;\n const firstChild = fragment.firstChild;\n if (firstChild instanceof SVGElement) {\n this.spriteSVG = firstChild;\n this.fileContainer.shadowRoot?.appendChild(this.spriteSVG);\n }\n }\n return this.fileContainer;\n }\n\n getFileContainer(): HTMLElement | undefined {\n return this.fileContainer;\n }\n\n private getOrCreatePreNode(container: HTMLElement): HTMLPreElement {\n const shadowRoot =\n container.shadowRoot ?? container.attachShadow({ mode: 'open' });\n // If we haven't created a pre element yet, lets go ahead and do that\n if (this.pre == null) {\n this.pre = document.createElement('pre');\n this.appliedPreAttributes = undefined;\n this.codeUnified = undefined;\n this.codeDeletions = undefined;\n this.codeAdditions = undefined;\n shadowRoot.appendChild(this.pre);\n }\n // If we have a new parent container for the pre element, lets go ahead and\n // move it into the new container\n else if (this.pre.parentNode !== shadowRoot) {\n shadowRoot.appendChild(this.pre);\n this.appliedPreAttributes = undefined;\n }\n return this.pre;\n }\n\n private syncCodeNodesFromPre(pre: HTMLPreElement): void {\n this.codeUnified = undefined;\n this.codeDeletions = undefined;\n this.codeAdditions = undefined;\n for (const child of Array.from(pre.children)) {\n if (!(child instanceof HTMLElement)) {\n continue;\n }\n if ('unified' in child.dataset) {\n this.codeUnified = child;\n } else if ('deletions' in child.dataset) {\n this.codeDeletions = child;\n } else if ('additions' in child.dataset) {\n this.codeAdditions = child;\n }\n }\n }\n\n private applyHeaderToDOM(\n headerAST: HASTElement,\n container: HTMLElement\n ): void {\n this.cleanupErrorWrapper();\n const headerHTML = toHtml(headerAST);\n if (headerHTML !== this.lastRenderedHeaderHTML) {\n const tempDiv = document.createElement('div');\n tempDiv.innerHTML = headerHTML;\n const newHeader = tempDiv.firstElementChild;\n if (!(newHeader instanceof HTMLElement)) {\n return;\n }\n if (this.headerElement != null) {\n container.shadowRoot?.replaceChild(newHeader, this.headerElement);\n } else {\n container.shadowRoot?.prepend(newHeader);\n }\n this.headerElement = newHeader;\n this.lastRenderedHeaderHTML = headerHTML;\n }\n\n if (this.isContainerManaged) return;\n\n const { renderHeaderMetadata } = this.options;\n if (this.headerMetadata != null) {\n this.headerMetadata.parentNode?.removeChild(this.headerMetadata);\n }\n const content =\n renderHeaderMetadata?.({\n deletionFile: this.deletionFile,\n additionFile: this.additionFile,\n fileDiff: this.fileDiff,\n }) ?? undefined;\n if (content != null) {\n this.headerMetadata = document.createElement('div');\n this.headerMetadata.slot = HEADER_METADATA_SLOT_ID;\n if (content instanceof Element) {\n this.headerMetadata.appendChild(content);\n } else {\n this.headerMetadata.innerText = `${content}`;\n }\n container.appendChild(this.headerMetadata);\n }\n }\n\n private injectUnsafeCSS(): void {\n if (this.fileContainer?.shadowRoot == null) {\n return;\n }\n const { unsafeCSS } = this.options;\n\n if (unsafeCSS == null || unsafeCSS === '') {\n return;\n }\n\n // Create or update the style element\n if (this.unsafeCSSStyle == null) {\n this.unsafeCSSStyle = createUnsafeCSSStyleNode();\n this.fileContainer.shadowRoot.appendChild(this.unsafeCSSStyle);\n }\n // Wrap in @layer unsafe to match SSR behavior\n this.unsafeCSSStyle.innerText = wrapUnsafeCSS(unsafeCSS);\n }\n\n private applyHunksToDOM(\n pre: HTMLPreElement,\n result: HunksRenderResult\n ): void {\n this.cleanupErrorWrapper();\n this.applyPreNodeAttributes(pre, result);\n\n let shouldReplace = false;\n let codeDeletions: HTMLElement | undefined;\n let codeAdditions: HTMLElement | undefined;\n // Create code elements and insert HTML content\n const codeElements: HTMLElement[] = [];\n if (result.unifiedAST != null) {\n shouldReplace =\n this.codeUnified == null ||\n this.codeAdditions != null ||\n this.codeDeletions != null;\n this.codeDeletions = undefined;\n this.codeAdditions = undefined;\n if (result.unifiedAST.length > 0) {\n this.codeUnified = getOrCreateCodeNode({\n code: this.codeUnified,\n columnType: 'unified',\n });\n this.codeUnified.innerHTML = this.hunksRenderer.renderPartialHTML(\n result.unifiedAST\n );\n codeElements.push(this.codeUnified);\n } else {\n this.codeUnified = undefined;\n }\n } else {\n if (result.deletionsAST != null) {\n shouldReplace = this.codeDeletions == null || this.codeUnified != null;\n this.codeUnified = undefined;\n if (result.deletionsAST.length > 0) {\n this.codeDeletions = getOrCreateCodeNode({\n code: this.codeDeletions,\n columnType: 'deletions',\n });\n this.codeDeletions.innerHTML = this.hunksRenderer.renderPartialHTML(\n result.deletionsAST\n );\n codeElements.push(this.codeDeletions);\n } else {\n this.codeDeletions = undefined;\n }\n }\n if (result.additionsAST != null) {\n shouldReplace =\n shouldReplace ||\n this.codeAdditions == null ||\n this.codeUnified != null;\n this.codeUnified = undefined;\n if (result.additionsAST.length > 0) {\n this.codeAdditions = getOrCreateCodeNode({\n code: this.codeAdditions,\n columnType: 'additions',\n });\n this.codeAdditions.innerHTML = this.hunksRenderer.renderPartialHTML(\n result.additionsAST\n );\n codeElements.push(this.codeAdditions);\n } else {\n this.codeAdditions = undefined;\n }\n }\n }\n\n if (codeElements.length === 0) {\n pre.textContent = '';\n } else if (shouldReplace) {\n pre.replaceChildren(...codeElements);\n }\n\n this.injectUnsafeCSS();\n\n this.mouseEventManager.setup(pre);\n this.lineSelectionManager.setup(pre);\n if ((this.options.overflow ?? 'scroll') === 'scroll') {\n this.resizeManager.setup(pre);\n if ((this.options.diffStyle ?? 'split') === 'split') {\n this.scrollSyncManager.setup(pre, codeDeletions, codeAdditions);\n } else {\n this.scrollSyncManager.cleanUp();\n }\n } else {\n this.resizeManager.cleanUp();\n this.scrollSyncManager.cleanUp();\n }\n }\n\n private applyPreNodeAttributes(\n pre: HTMLPreElement,\n {\n themeStyles,\n baseThemeType,\n additionsAST,\n deletionsAST,\n totalLines,\n }: HunksRenderResult\n ): void {\n const {\n diffIndicators = 'bars',\n disableBackground = false,\n disableLineNumbers = false,\n overflow = 'scroll',\n themeType = 'system',\n diffStyle = 'split',\n } = this.options;\n const preProperties: PrePropertiesConfig = {\n diffIndicators,\n disableBackground,\n disableLineNumbers,\n overflow,\n split:\n diffStyle === 'unified'\n ? false\n : additionsAST != null && deletionsAST != null,\n themeStyles,\n themeType: baseThemeType ?? themeType,\n totalLines,\n };\n if (arePrePropertiesEqual(preProperties, this.appliedPreAttributes)) {\n return;\n }\n setPreNodeProperties(pre, preProperties);\n this.appliedPreAttributes = preProperties;\n }\n\n private applyErrorToDOM(error: Error, container: HTMLElement) {\n this.cleanupErrorWrapper();\n const pre = this.getOrCreatePreNode(container);\n pre.innerHTML = '';\n pre.parentNode?.removeChild(pre);\n this.pre = undefined;\n this.appliedPreAttributes = undefined;\n const shadowRoot =\n container.shadowRoot ?? container.attachShadow({ mode: 'open' });\n this.errorWrapper ??= document.createElement('div');\n this.errorWrapper.dataset.errorWrapper = '';\n this.errorWrapper.innerHTML = '';\n shadowRoot.appendChild(this.errorWrapper);\n const errorMessage = document.createElement('div');\n errorMessage.dataset.errorMessage = '';\n errorMessage.innerText = error.message;\n this.errorWrapper.appendChild(errorMessage);\n const errorStack = document.createElement('pre');\n errorStack.dataset.errorStack = '';\n errorStack.innerText = error.stack ?? 'No Error Stack';\n this.errorWrapper.appendChild(errorStack);\n }\n\n private cleanupErrorWrapper() {\n this.errorWrapper?.parentNode?.removeChild(this.errorWrapper);\n this.errorWrapper = undefined;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAyGA,IAAI,aAAa;AAEjB,IAAa,WAAb,MAA+C;CAG7C,OAAO,wBAAiC;CAExC,AAAS,OAAe,aAAa,EAAE;CAEvC,AAAU;CACV,AAAU;CACV,AAAU;CACV,AAAU;CACV,AAAU;CACV,AAAU;CACV,AAAU;CACV,AAAU;CAEV,AAAU;CACV,AAAU;CACV,AAAU,iCAAsD,IAAI,KAAK;CACzE,AAAU;CAEV,AAAU;CACV,AAAU;CACV,AAAU;CACV,AAAU;CACV,AAAU;CAEV,AAAU,kCACR,IAAI,KAAK;CACX,AAAU,kBAAqD,EAAE;CAEjE,AAAU;CACV,AAAU;CACV,AAAU;CACV,AAAU;CACV,AAAU;CACV,AAAU;CAEV,AAAU,UAAU;CAEpB,YACE,AAAOA,UAAwC,EAAE,OAAO,gBAAgB,EACxE,AAAUC,eACV,AAAU,qBAAqB,OAC/B;EAHO;EACG;EACA;AAEV,OAAK,gBAAgB,IAAI,kBACvB;GACE,GAAG;GACH,gBACE,OAAO,QAAQ,mBAAmB,aAC9B,WACA,QAAQ;GACf,EACD,KAAK,uBACL,KAAK,cACN;AACD,OAAK,gBAAgB,IAAI,eAAe;AACxC,OAAK,oBAAoB,IAAI,mBAAmB;AAChD,OAAK,oBAAoB,IAAI,kBAC3B,QACA,uBACE,SACA,OAAO,QAAQ,mBAAmB,eAC/B,QAAQ,kBAAkB,iBAAiB,cAC1C,KAAK,mBACL,OACL,CACF;AACD,OAAK,uBAAuB,IAAI,qBAC9B,0BAA0B,QAAQ,CACnC;AACD,OAAK,eAAe,wBAAwB,KAAK;AACjD,OAAK,UAAU;;CAGjB,AAAQ,8BAAoC;AAC1C,OAAK,UAAU;;CAUjB,WAAW,SAAyD;AAClE,MAAI,WAAW,KAAM;AACrB,OAAK,UAAU;AACf,OAAK,cAAc,WAAW;GAC5B,GAAG,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","names":["options: FileDiffOptions<LAnnotation>","workerManager?: WorkerPoolManager | undefined","error: unknown","codeDeletions: HTMLElement | undefined","codeAdditions: HTMLElement | undefined","codeElements: HTMLElement[]","preProperties: PrePropertiesConfig"],"sources":["../../src/components/FileDiff.ts"],"sourcesContent":["import type { Element as HASTElement } from 'hast';\nimport { toHtml } from 'hast-util-to-html';\n\nimport {\n DEFAULT_THEMES,\n DIFFS_TAG_NAME,\n HEADER_METADATA_SLOT_ID,\n UNSAFE_CSS_ATTRIBUTE,\n} from '../constants';\nimport {\n LineSelectionManager,\n type LineSelectionOptions,\n type SelectedLineRange,\n pluckLineSelectionOptions,\n} from '../managers/LineSelectionManager';\nimport {\n type GetHoveredLineResult,\n MouseEventManager,\n type MouseEventManagerBaseOptions,\n pluckMouseEventOptions,\n} from '../managers/MouseEventManager';\nimport { ResizeManager } from '../managers/ResizeManager';\nimport { ScrollSyncManager } from '../managers/ScrollSyncManager';\nimport {\n DiffHunksRenderer,\n type HunksRenderResult,\n} from '../renderers/DiffHunksRenderer';\nimport { SVGSpriteSheet } from '../sprite';\nimport type {\n BaseDiffOptions,\n DiffLineAnnotation,\n ExpansionDirections,\n FileContents,\n FileDiffMetadata,\n HunkData,\n HunkSeparators,\n PrePropertiesConfig,\n RenderHeaderMetadataCallback,\n RenderRange,\n ThemeTypes,\n} from '../types';\nimport { areDiffLineAnnotationsEqual } from '../utils/areDiffLineAnnotationsEqual';\nimport { areFilesEqual } from '../utils/areFilesEqual';\nimport { areHunkDataEqual } from '../utils/areHunkDataEqual';\nimport { arePrePropertiesEqual } from '../utils/arePrePropertiesEqual';\nimport { areRenderRangesEqual } from '../utils/areRenderRangesEqual';\nimport { createAnnotationWrapperNode } from '../utils/createAnnotationWrapperNode';\nimport { createHoverContentNode } from '../utils/createHoverContentNode';\nimport { createUnsafeCSSStyleNode } from '../utils/createUnsafeCSSStyleNode';\nimport { wrapUnsafeCSS } from '../utils/cssWrappers';\nimport { getLineAnnotationName } from '../utils/getLineAnnotationName';\nimport { getOrCreateCodeNode } from '../utils/getOrCreateCodeNode';\nimport { parseDiffFromFile } from '../utils/parseDiffFromFile';\nimport { prerenderHTMLIfNecessary } from '../utils/prerenderHTMLIfNecessary';\nimport { setPreNodeProperties } from '../utils/setWrapperNodeProps';\nimport type { WorkerPoolManager } from '../worker';\nimport { DiffsContainerLoaded } from './web-components';\n\nexport interface FileDiffRenderProps<LAnnotation> {\n fileDiff?: FileDiffMetadata;\n oldFile?: FileContents;\n newFile?: FileContents;\n forceRender?: boolean;\n fileContainer?: HTMLElement;\n containerWrapper?: HTMLElement;\n lineAnnotations?: DiffLineAnnotation<LAnnotation>[];\n renderRange?: RenderRange;\n}\n\nexport interface FileDiffHydrationProps<LAnnotation>\n extends Omit<FileDiffRenderProps<LAnnotation>, 'fileContainer'> {\n fileContainer: HTMLElement;\n prerenderedHTML?: string;\n}\n\nexport interface FileDiffOptions<LAnnotation>\n extends Omit<BaseDiffOptions, 'hunkSeparators'>,\n MouseEventManagerBaseOptions<'diff'>,\n LineSelectionOptions {\n hunkSeparators?:\n | Exclude<HunkSeparators, 'custom'>\n | ((\n hunk: HunkData,\n instance: FileDiff<LAnnotation>\n ) => HTMLElement | DocumentFragment);\n disableFileHeader?: boolean;\n renderHeaderMetadata?: RenderHeaderMetadataCallback;\n /**\n * When true, errors during rendering are rethrown instead of being caught\n * and displayed in the DOM. Useful for testing or when you want to handle\n * errors yourself.\n */\n disableErrorHandling?: boolean;\n renderAnnotation?(\n annotation: DiffLineAnnotation<LAnnotation>\n ): HTMLElement | undefined;\n renderHoverUtility?(\n getHoveredRow: () => GetHoveredLineResult<'diff'> | undefined\n ): HTMLElement | null;\n}\n\ninterface AnnotationElementCache<LAnnotation> {\n element: HTMLElement;\n annotation: DiffLineAnnotation<LAnnotation>;\n}\n\ninterface CustomHunkElementCache {\n element: HTMLElement;\n hunkData: HunkData;\n}\n\nlet instanceId = -1;\n\nexport class FileDiff<LAnnotation = undefined> {\n // NOTE(amadeus): We sorta need this to ensure the web-component file is\n // properly loaded\n static LoadedCustomComponent: boolean = DiffsContainerLoaded;\n\n readonly __id: string = `file-diff:${++instanceId}`;\n\n protected fileContainer: HTMLElement | undefined;\n protected spriteSVG: SVGElement | undefined;\n protected pre: HTMLPreElement | undefined;\n protected codeUnified: HTMLElement | undefined;\n protected codeDeletions: HTMLElement | undefined;\n protected codeAdditions: HTMLElement | undefined;\n protected unsafeCSSStyle: HTMLStyleElement | undefined;\n protected hoverContent: HTMLElement | undefined;\n\n protected headerElement: HTMLElement | undefined;\n protected headerMetadata: HTMLElement | undefined;\n protected separatorCache: Map<string, CustomHunkElementCache> = new Map();\n protected errorWrapper: HTMLElement | undefined;\n\n protected hunksRenderer: DiffHunksRenderer<LAnnotation>;\n protected resizeManager: ResizeManager;\n protected scrollSyncManager: ScrollSyncManager;\n protected mouseEventManager: MouseEventManager<'diff'>;\n protected lineSelectionManager: LineSelectionManager;\n\n protected annotationCache: Map<string, AnnotationElementCache<LAnnotation>> =\n new Map();\n protected lineAnnotations: DiffLineAnnotation<LAnnotation>[] = [];\n\n protected deletionFile: FileContents | undefined;\n protected additionFile: FileContents | undefined;\n protected fileDiff: FileDiffMetadata | undefined;\n protected renderRange: RenderRange | undefined;\n protected appliedPreAttributes: PrePropertiesConfig | undefined;\n protected lastRenderedHeaderHTML: string | undefined;\n\n protected enabled = true;\n\n constructor(\n public options: FileDiffOptions<LAnnotation> = { theme: DEFAULT_THEMES },\n protected workerManager?: WorkerPoolManager | undefined,\n protected isContainerManaged = false\n ) {\n this.hunksRenderer = new DiffHunksRenderer(\n {\n ...options,\n hunkSeparators:\n typeof options.hunkSeparators === 'function'\n ? 'custom'\n : options.hunkSeparators,\n },\n this.handleHighlightRender,\n this.workerManager\n );\n this.resizeManager = new ResizeManager();\n this.scrollSyncManager = new ScrollSyncManager();\n this.mouseEventManager = new MouseEventManager(\n 'diff',\n pluckMouseEventOptions(\n options,\n typeof options.hunkSeparators === 'function' ||\n (options.hunkSeparators ?? 'line-info') === 'line-info'\n ? this.handleExpandHunk\n : undefined\n )\n );\n this.lineSelectionManager = new LineSelectionManager(\n pluckLineSelectionOptions(options)\n );\n this.workerManager?.subscribeToThemeChanges(this);\n this.enabled = true;\n }\n\n private handleHighlightRender = (): void => {\n this.rerender();\n };\n\n // FIXME(amadeus): This is a bit of a looming issue that I'll need to resolve:\n // * Do we publicly allow merging of options or do we have individualized setters?\n // * When setting new options, we need to figure out what settings require a\n // re-render and which can just be applied more elegantly\n // * There's also an issue of options that live here on the File class and\n // those that live on the Hunk class, and it's a bit of an issue with passing\n // settings down and mirroring them (not great...)\n setOptions(options: FileDiffOptions<LAnnotation> | undefined): void {\n if (options == null) return;\n this.options = options;\n this.hunksRenderer.setOptions({\n ...this.options,\n hunkSeparators:\n typeof options.hunkSeparators === 'function'\n ? 'custom'\n : options.hunkSeparators,\n });\n this.mouseEventManager.setOptions(\n pluckMouseEventOptions(\n options,\n typeof options.hunkSeparators === 'function' ||\n (options.hunkSeparators ?? 'line-info') === 'line-info'\n ? this.handleExpandHunk\n : undefined\n )\n );\n this.lineSelectionManager.setOptions(pluckLineSelectionOptions(options));\n }\n\n private mergeOptions(options: Partial<FileDiffOptions<LAnnotation>>): void {\n this.options = { ...this.options, ...options };\n }\n\n setThemeType(themeType: ThemeTypes): void {\n if ((this.options.themeType ?? 'system') === themeType) {\n return;\n }\n this.mergeOptions({ themeType });\n this.hunksRenderer.setThemeType(themeType);\n\n if (this.headerElement != null) {\n if (themeType === 'system') {\n delete this.headerElement.dataset.themeType;\n } else {\n this.headerElement.dataset.themeType = themeType;\n }\n }\n\n // Update pre element theme mode\n if (this.pre != null) {\n switch (themeType) {\n case 'system':\n delete this.pre.dataset.themeType;\n break;\n case 'light':\n case 'dark':\n this.pre.dataset.themeType = themeType;\n break;\n }\n }\n }\n\n getHoveredLine = (): GetHoveredLineResult<'diff'> | undefined => {\n return this.mouseEventManager.getHoveredLine();\n };\n\n setLineAnnotations(lineAnnotations: DiffLineAnnotation<LAnnotation>[]): void {\n this.lineAnnotations = lineAnnotations;\n }\n\n setSelectedLines(range: SelectedLineRange | null): void {\n this.lineSelectionManager.setSelection(range);\n }\n\n cleanUp(recycle: boolean = false): void {\n this.resizeManager.cleanUp();\n this.mouseEventManager.cleanUp();\n this.scrollSyncManager.cleanUp();\n this.lineSelectionManager.cleanUp();\n this.workerManager?.unsubscribeToThemeChanges(this);\n this.renderRange = undefined;\n\n // Clean up the elements\n if (!this.isContainerManaged) {\n this.fileContainer?.parentNode?.removeChild(this.fileContainer);\n }\n if (this.fileContainer?.shadowRoot != null) {\n // Manually help garbage collection\n this.fileContainer.shadowRoot.innerHTML = '';\n }\n this.fileContainer = undefined;\n // Manually help garbage collection\n if (this.pre != null) {\n this.pre.innerHTML = '';\n this.pre = undefined;\n }\n this.codeUnified = undefined;\n this.codeDeletions = undefined;\n this.codeAdditions = undefined;\n this.appliedPreAttributes = undefined;\n this.headerElement = undefined;\n this.lastRenderedHeaderHTML = undefined;\n this.errorWrapper = undefined;\n this.spriteSVG = undefined;\n\n if (recycle) {\n this.hunksRenderer.recycle();\n } else {\n this.hunksRenderer.cleanUp();\n this.workerManager = undefined;\n // Clean up the data\n this.fileDiff = undefined;\n this.deletionFile = undefined;\n this.additionFile = undefined;\n }\n\n this.enabled = false;\n }\n\n virtualizedSetup(): void {\n this.enabled = true;\n this.workerManager?.subscribeToThemeChanges(this);\n }\n\n hydrate(props: FileDiffHydrationProps<LAnnotation>): void {\n const { fileContainer, prerenderedHTML } = props;\n prerenderHTMLIfNecessary(fileContainer, prerenderedHTML);\n for (const element of fileContainer.shadowRoot?.children ?? []) {\n if (element instanceof SVGElement) {\n this.spriteSVG = element;\n continue;\n }\n if (!(element instanceof HTMLElement)) {\n continue;\n }\n if (element instanceof HTMLPreElement) {\n this.pre = element;\n for (const code of element.children) {\n if (\n !(code instanceof HTMLElement) ||\n code.tagName.toLowerCase() !== 'code'\n ) {\n continue;\n }\n if ('deletions' in code.dataset) {\n this.codeDeletions = code;\n }\n if ('additions' in code.dataset) {\n this.codeAdditions = code;\n }\n if ('unified' in code.dataset) {\n this.codeUnified = code;\n }\n }\n continue;\n }\n if ('diffsHeader' in element.dataset) {\n this.headerElement = element;\n continue;\n }\n if (\n element instanceof HTMLStyleElement &&\n element.hasAttribute(UNSAFE_CSS_ATTRIBUTE)\n ) {\n this.unsafeCSSStyle = element;\n continue;\n }\n }\n if (this.pre != null) {\n this.syncCodeNodesFromPre(this.pre);\n }\n // If we have no pre tag, then we should render\n if (this.pre == null) {\n this.render(props);\n }\n // Otherwise orchestrate our setup\n else {\n const { lineAnnotations, oldFile, newFile, fileDiff } = props;\n this.fileContainer = fileContainer;\n delete this.pre.dataset.dehydrated;\n\n this.lineAnnotations = lineAnnotations ?? this.lineAnnotations;\n this.additionFile = newFile;\n this.deletionFile = oldFile;\n this.fileDiff =\n fileDiff ??\n (oldFile != null && newFile != null\n ? parseDiffFromFile(oldFile, newFile)\n : undefined);\n\n this.hunksRenderer.hydrate(this.fileDiff);\n // FIXME(amadeus): not sure how to handle this yet...\n // this.renderSeparators();\n this.renderAnnotations();\n this.renderHoverUtility();\n this.injectUnsafeCSS();\n this.mouseEventManager.setup(this.pre);\n this.lineSelectionManager.setup(this.pre);\n if ((this.options.overflow ?? 'scroll') === 'scroll') {\n this.resizeManager.setup(this.pre);\n if ((this.options.diffStyle ?? 'split') === 'split') {\n this.scrollSyncManager.setup(\n this.pre,\n this.codeDeletions,\n this.codeAdditions\n );\n }\n }\n }\n }\n\n rerender(): void {\n if (\n !this.enabled ||\n (this.fileDiff == null &&\n this.additionFile == null &&\n this.deletionFile == null)\n ) {\n return;\n }\n this.render({\n oldFile: this.deletionFile,\n newFile: this.additionFile,\n fileDiff: this.fileDiff,\n forceRender: true,\n renderRange: this.renderRange,\n });\n }\n\n handleExpandHunk = (\n hunkIndex: number,\n direction: ExpansionDirections\n ): void => {\n this.expandHunk(hunkIndex, direction);\n };\n\n expandHunk(hunkIndex: number, direction: ExpansionDirections): void {\n this.hunksRenderer.expandHunk(hunkIndex, direction);\n this.rerender();\n }\n\n render({\n oldFile,\n newFile,\n fileDiff,\n forceRender = false,\n lineAnnotations,\n fileContainer,\n containerWrapper,\n renderRange,\n }: FileDiffRenderProps<LAnnotation>): void {\n if (!this.enabled) {\n // NOTE(amadeus): May need to be a silent failure? Making it loud for now\n // to better understand it\n throw new Error(\n 'FileDiff.render: attempting to call render after cleaned up'\n );\n }\n const filesDidChange =\n oldFile != null &&\n newFile != null &&\n (!areFilesEqual(oldFile, this.deletionFile) ||\n !areFilesEqual(newFile, this.additionFile));\n const annotationsChanged =\n lineAnnotations != null &&\n (lineAnnotations.length > 0 || this.lineAnnotations.length > 0)\n ? lineAnnotations !== this.lineAnnotations\n : false;\n if (\n areRenderRangesEqual(renderRange, this.renderRange) &&\n !forceRender &&\n !annotationsChanged &&\n // If using the fileDiff API, lets check to see if they are equal to\n // avoid doing work\n ((fileDiff != null && fileDiff === this.fileDiff) ||\n // If using the oldFile/newFile API then lets check to see if they are\n // equal\n (fileDiff == null && !filesDidChange))\n ) {\n return;\n }\n\n this.renderRange = renderRange;\n this.deletionFile = oldFile;\n this.additionFile = newFile;\n if (fileDiff != null) {\n this.fileDiff = fileDiff;\n } else if (oldFile != null && newFile != null && filesDidChange) {\n this.fileDiff = parseDiffFromFile(oldFile, newFile);\n }\n\n if (lineAnnotations != null) {\n this.setLineAnnotations(lineAnnotations);\n }\n if (this.fileDiff == null) {\n return;\n }\n this.hunksRenderer.setOptions({\n ...this.options,\n hunkSeparators:\n typeof this.options.hunkSeparators === 'function'\n ? 'custom'\n : this.options.hunkSeparators,\n });\n\n this.hunksRenderer.setLineAnnotations(this.lineAnnotations);\n\n const { disableFileHeader = false, disableErrorHandling = false } =\n this.options;\n\n if (disableFileHeader) {\n // Remove existing header from DOM\n if (this.headerElement != null) {\n this.headerElement.parentNode?.removeChild(this.headerElement);\n this.headerElement = undefined;\n this.lastRenderedHeaderHTML = undefined;\n }\n }\n fileContainer = this.getOrCreateFileContainer(\n fileContainer,\n containerWrapper\n );\n\n try {\n const hunksResult = this.hunksRenderer.renderDiff(\n this.fileDiff,\n renderRange\n );\n if (hunksResult == null) {\n if (this.workerManager != null && !this.workerManager.isInitialized()) {\n void this.workerManager.initialize().then(() => this.rerender());\n }\n return;\n }\n\n if (hunksResult.headerElement != null) {\n this.applyHeaderToDOM(hunksResult.headerElement, fileContainer);\n }\n if (\n hunksResult.additionsAST != null ||\n hunksResult.deletionsAST != null ||\n hunksResult.unifiedAST != null\n ) {\n const pre = this.getOrCreatePreNode(fileContainer);\n this.applyHunksToDOM(pre, hunksResult);\n } else if (this.pre != null) {\n this.pre.parentNode?.removeChild(this.pre);\n this.pre = undefined;\n }\n this.renderSeparators(hunksResult.hunkData);\n this.renderAnnotations();\n this.renderHoverUtility();\n } catch (error: unknown) {\n if (disableErrorHandling) {\n throw error;\n }\n console.error(error);\n if (error instanceof Error) {\n this.applyErrorToDOM(error, fileContainer);\n }\n }\n }\n\n private renderSeparators(hunkData: HunkData[]): void {\n const { hunkSeparators } = this.options;\n if (\n this.isContainerManaged ||\n this.fileContainer == null ||\n typeof hunkSeparators !== 'function'\n ) {\n for (const { element } of this.separatorCache.values()) {\n element.parentNode?.removeChild(element);\n }\n this.separatorCache.clear();\n return;\n }\n const staleSeparators = new Map(this.separatorCache);\n for (const hunk of hunkData) {\n const id = hunk.slotName;\n let cache = this.separatorCache.get(id);\n if (cache == null || !areHunkDataEqual(hunk, cache.hunkData)) {\n cache?.element.parentNode?.removeChild(cache.element);\n const element = document.createElement('div');\n element.style.display = 'contents';\n element.slot = hunk.slotName;\n element.appendChild(hunkSeparators(hunk, this));\n this.fileContainer.appendChild(element);\n cache = { element, hunkData: hunk };\n this.separatorCache.set(id, cache);\n }\n staleSeparators.delete(id);\n }\n for (const [id, { element }] of staleSeparators.entries()) {\n this.separatorCache.delete(id);\n element.parentNode?.removeChild(element);\n }\n }\n\n private renderAnnotations(): void {\n if (this.isContainerManaged || this.fileContainer == null) {\n for (const { element } of this.annotationCache.values()) {\n element.parentNode?.removeChild(element);\n }\n this.annotationCache.clear();\n return;\n }\n const staleAnnotations = new Map(this.annotationCache);\n const { renderAnnotation } = this.options;\n if (renderAnnotation != null && this.lineAnnotations.length > 0) {\n for (const [index, annotation] of this.lineAnnotations.entries()) {\n const id = `${index}-${getLineAnnotationName(annotation)}`;\n let cache = this.annotationCache.get(id);\n if (\n cache == null ||\n !areDiffLineAnnotationsEqual(annotation, cache.annotation)\n ) {\n cache?.element.parentElement?.removeChild(cache.element);\n const content = renderAnnotation(annotation);\n // If we can't render anything, then we should not render anything\n // and clear the annotation cache if necessary.\n if (content == null) {\n continue;\n }\n cache = {\n element: createAnnotationWrapperNode(\n getLineAnnotationName(annotation)\n ),\n annotation,\n };\n cache.element.appendChild(content);\n this.fileContainer.appendChild(cache.element);\n this.annotationCache.set(id, cache);\n }\n staleAnnotations.delete(id);\n }\n }\n for (const [id, { element }] of staleAnnotations.entries()) {\n this.annotationCache.delete(id);\n element.parentNode?.removeChild(element);\n }\n }\n\n private renderHoverUtility() {\n const { renderHoverUtility } = this.options;\n if (this.fileContainer == null || renderHoverUtility == null) {\n return;\n }\n const element = renderHoverUtility(this.mouseEventManager.getHoveredLine);\n if (element != null && this.hoverContent != null) {\n return;\n } else if (element == null) {\n this.hoverContent?.parentNode?.removeChild(this.hoverContent);\n this.hoverContent = undefined;\n return;\n }\n this.hoverContent = createHoverContentNode();\n this.hoverContent.appendChild(element);\n this.fileContainer.appendChild(this.hoverContent);\n }\n\n getOrCreateFileContainer(\n fileContainer?: HTMLElement,\n parentNode?: HTMLElement\n ): HTMLElement {\n const previousContainer = this.fileContainer;\n this.fileContainer =\n fileContainer ??\n this.fileContainer ??\n document.createElement(DIFFS_TAG_NAME);\n // NOTE(amadeus): If the container changes, we should reset the rendered\n // HTML\n if (previousContainer != null && previousContainer !== this.fileContainer) {\n this.lastRenderedHeaderHTML = undefined;\n this.headerElement = undefined;\n }\n if (parentNode != null && this.fileContainer.parentNode !== parentNode) {\n parentNode.appendChild(this.fileContainer);\n }\n if (this.spriteSVG == null) {\n const fragment = document.createElement('div');\n fragment.innerHTML = SVGSpriteSheet;\n const firstChild = fragment.firstChild;\n if (firstChild instanceof SVGElement) {\n this.spriteSVG = firstChild;\n this.fileContainer.shadowRoot?.appendChild(this.spriteSVG);\n }\n }\n return this.fileContainer;\n }\n\n getFileContainer(): HTMLElement | undefined {\n return this.fileContainer;\n }\n\n private getOrCreatePreNode(container: HTMLElement): HTMLPreElement {\n const shadowRoot =\n container.shadowRoot ?? container.attachShadow({ mode: 'open' });\n // If we haven't created a pre element yet, lets go ahead and do that\n if (this.pre == null) {\n this.pre = document.createElement('pre');\n this.appliedPreAttributes = undefined;\n this.codeUnified = undefined;\n this.codeDeletions = undefined;\n this.codeAdditions = undefined;\n shadowRoot.appendChild(this.pre);\n }\n // If we have a new parent container for the pre element, lets go ahead and\n // move it into the new container\n else if (this.pre.parentNode !== shadowRoot) {\n shadowRoot.appendChild(this.pre);\n this.appliedPreAttributes = undefined;\n }\n return this.pre;\n }\n\n private syncCodeNodesFromPre(pre: HTMLPreElement): void {\n this.codeUnified = undefined;\n this.codeDeletions = undefined;\n this.codeAdditions = undefined;\n for (const child of Array.from(pre.children)) {\n if (!(child instanceof HTMLElement)) {\n continue;\n }\n if ('unified' in child.dataset) {\n this.codeUnified = child;\n } else if ('deletions' in child.dataset) {\n this.codeDeletions = child;\n } else if ('additions' in child.dataset) {\n this.codeAdditions = child;\n }\n }\n }\n\n private applyHeaderToDOM(\n headerAST: HASTElement,\n container: HTMLElement\n ): void {\n this.cleanupErrorWrapper();\n const headerHTML = toHtml(headerAST);\n if (headerHTML !== this.lastRenderedHeaderHTML) {\n const tempDiv = document.createElement('div');\n tempDiv.innerHTML = headerHTML;\n const newHeader = tempDiv.firstElementChild;\n if (!(newHeader instanceof HTMLElement)) {\n return;\n }\n if (this.headerElement != null) {\n container.shadowRoot?.replaceChild(newHeader, this.headerElement);\n } else {\n container.shadowRoot?.prepend(newHeader);\n }\n this.headerElement = newHeader;\n this.lastRenderedHeaderHTML = headerHTML;\n }\n\n if (this.isContainerManaged) return;\n\n const { renderHeaderMetadata } = this.options;\n if (this.headerMetadata != null) {\n this.headerMetadata.parentNode?.removeChild(this.headerMetadata);\n }\n const content =\n renderHeaderMetadata?.({\n deletionFile: this.deletionFile,\n additionFile: this.additionFile,\n fileDiff: this.fileDiff,\n }) ?? undefined;\n if (content != null) {\n this.headerMetadata = document.createElement('div');\n this.headerMetadata.slot = HEADER_METADATA_SLOT_ID;\n if (content instanceof Element) {\n this.headerMetadata.appendChild(content);\n } else {\n this.headerMetadata.innerText = `${content}`;\n }\n container.appendChild(this.headerMetadata);\n }\n }\n\n private injectUnsafeCSS(): void {\n if (this.fileContainer?.shadowRoot == null) {\n return;\n }\n const { unsafeCSS } = this.options;\n\n if (unsafeCSS == null || unsafeCSS === '') {\n return;\n }\n\n // Create or update the style element\n if (this.unsafeCSSStyle == null) {\n this.unsafeCSSStyle = createUnsafeCSSStyleNode();\n this.fileContainer.shadowRoot.appendChild(this.unsafeCSSStyle);\n }\n // Wrap in @layer unsafe to match SSR behavior\n this.unsafeCSSStyle.innerText = wrapUnsafeCSS(unsafeCSS);\n }\n\n private applyHunksToDOM(\n pre: HTMLPreElement,\n result: HunksRenderResult\n ): void {\n this.cleanupErrorWrapper();\n this.applyPreNodeAttributes(pre, result);\n\n let shouldReplace = false;\n let codeDeletions: HTMLElement | undefined;\n let codeAdditions: HTMLElement | undefined;\n // Create code elements and insert HTML content\n const codeElements: HTMLElement[] = [];\n if (result.unifiedAST != null) {\n shouldReplace =\n this.codeUnified == null ||\n this.codeAdditions != null ||\n this.codeDeletions != null;\n this.codeDeletions = undefined;\n this.codeAdditions = undefined;\n if (result.unifiedAST.length > 0) {\n this.codeUnified = getOrCreateCodeNode({\n code: this.codeUnified,\n columnType: 'unified',\n });\n this.codeUnified.innerHTML = this.hunksRenderer.renderPartialHTML(\n result.unifiedAST\n );\n codeElements.push(this.codeUnified);\n } else {\n this.codeUnified = undefined;\n }\n } else {\n if (result.deletionsAST != null) {\n shouldReplace = this.codeDeletions == null || this.codeUnified != null;\n this.codeUnified = undefined;\n if (result.deletionsAST.length > 0) {\n this.codeDeletions = getOrCreateCodeNode({\n code: this.codeDeletions,\n columnType: 'deletions',\n });\n this.codeDeletions.innerHTML = this.hunksRenderer.renderPartialHTML(\n result.deletionsAST\n );\n codeElements.push(this.codeDeletions);\n } else {\n this.codeDeletions = undefined;\n }\n }\n if (result.additionsAST != null) {\n shouldReplace =\n shouldReplace ||\n this.codeAdditions == null ||\n this.codeUnified != null;\n this.codeUnified = undefined;\n if (result.additionsAST.length > 0) {\n this.codeAdditions = getOrCreateCodeNode({\n code: this.codeAdditions,\n columnType: 'additions',\n });\n this.codeAdditions.innerHTML = this.hunksRenderer.renderPartialHTML(\n result.additionsAST\n );\n codeElements.push(this.codeAdditions);\n } else {\n this.codeAdditions = undefined;\n }\n }\n }\n\n if (codeElements.length === 0) {\n pre.textContent = '';\n } else if (shouldReplace) {\n pre.replaceChildren(...codeElements);\n }\n\n this.injectUnsafeCSS();\n\n this.mouseEventManager.setup(pre);\n this.lineSelectionManager.setup(pre);\n if ((this.options.overflow ?? 'scroll') === 'scroll') {\n this.resizeManager.setup(pre);\n if ((this.options.diffStyle ?? 'split') === 'split') {\n this.scrollSyncManager.setup(pre, codeDeletions, codeAdditions);\n } else {\n this.scrollSyncManager.cleanUp();\n }\n } else {\n this.resizeManager.cleanUp();\n this.scrollSyncManager.cleanUp();\n }\n }\n\n private applyPreNodeAttributes(\n pre: HTMLPreElement,\n {\n themeStyles,\n baseThemeType,\n additionsAST,\n deletionsAST,\n totalLines,\n }: HunksRenderResult\n ): void {\n const {\n diffIndicators = 'bars',\n disableBackground = false,\n disableLineNumbers = false,\n overflow = 'scroll',\n themeType = 'system',\n diffStyle = 'split',\n } = this.options;\n const preProperties: PrePropertiesConfig = {\n diffIndicators,\n disableBackground,\n disableLineNumbers,\n overflow,\n split:\n diffStyle === 'unified'\n ? false\n : additionsAST != null && deletionsAST != null,\n themeStyles,\n themeType: baseThemeType ?? themeType,\n totalLines,\n };\n if (arePrePropertiesEqual(preProperties, this.appliedPreAttributes)) {\n return;\n }\n setPreNodeProperties(pre, preProperties);\n this.appliedPreAttributes = preProperties;\n }\n\n private applyErrorToDOM(error: Error, container: HTMLElement) {\n this.cleanupErrorWrapper();\n const pre = this.getOrCreatePreNode(container);\n pre.innerHTML = '';\n pre.parentNode?.removeChild(pre);\n this.pre = undefined;\n this.appliedPreAttributes = undefined;\n const shadowRoot =\n container.shadowRoot ?? container.attachShadow({ mode: 'open' });\n this.errorWrapper ??= document.createElement('div');\n this.errorWrapper.dataset.errorWrapper = '';\n this.errorWrapper.innerHTML = '';\n shadowRoot.appendChild(this.errorWrapper);\n const errorMessage = document.createElement('div');\n errorMessage.dataset.errorMessage = '';\n errorMessage.innerText = error.message;\n this.errorWrapper.appendChild(errorMessage);\n const errorStack = document.createElement('pre');\n errorStack.dataset.errorStack = '';\n errorStack.innerText = error.stack ?? 'No Error Stack';\n this.errorWrapper.appendChild(errorStack);\n }\n\n private cleanupErrorWrapper() {\n this.errorWrapper?.parentNode?.removeChild(this.errorWrapper);\n this.errorWrapper = undefined;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA+GA,IAAI,aAAa;AAEjB,IAAa,WAAb,MAA+C;CAG7C,OAAO,wBAAiC;CAExC,AAAS,OAAe,aAAa,EAAE;CAEvC,AAAU;CACV,AAAU;CACV,AAAU;CACV,AAAU;CACV,AAAU;CACV,AAAU;CACV,AAAU;CACV,AAAU;CAEV,AAAU;CACV,AAAU;CACV,AAAU,iCAAsD,IAAI,KAAK;CACzE,AAAU;CAEV,AAAU;CACV,AAAU;CACV,AAAU;CACV,AAAU;CACV,AAAU;CAEV,AAAU,kCACR,IAAI,KAAK;CACX,AAAU,kBAAqD,EAAE;CAEjE,AAAU;CACV,AAAU;CACV,AAAU;CACV,AAAU;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AuB;;CAG9B,AAAQ,gBAAgB,OAAc,WAAwB;AAC5D,OAAK,qBAAqB;EAC1B,MAAM,MAAM,KAAK,mBAAmB,UAAU;AAC9C,MAAI,YAAY;AAChB,MAAI,YAAY,YAAY,IAAI;AAChC,OAAK,MAAM;AACX,OAAK,uBAAuB;EAC5B,MAAM,aACJ,UAAU,cAAc,UAAU,aAAa,EAAE,MAAM,QAAQ,CAAC;AAClE,OAAK,iBAAiB,SAAS,cAAc,MAAM;AACnD,OAAK,aAAa,QAAQ,eAAe;AACzC,OAAK,aAAa,YAAY;AAC9B,aAAW,YAAY,KAAK,aAAa;EACzC,MAAM,eAAe,SAAS,cAAc,MAAM;AAClD,eAAa,QAAQ,eAAe;AACpC,eAAa,YAAY,MAAM;AAC/B,OAAK,aAAa,YAAY,aAAa;EAC3C,MAAM,aAAa,SAAS,cAAc,MAAM;AAChD,aAAW,QAAQ,aAAa;AAChC,aAAW,YAAY,MAAM,SAAS;AACtC,OAAK,aAAa,YAAY,WAAW;;CAG3C,AAAQ,sBAAsB;AAC5B,OAAK,cAAc,YAAY,YAAY,KAAK,aAAa;AAC7D,OAAK,eAAe"}
|
package/dist/react/jsx.d.ts
CHANGED
package/dist/react/jsx.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsx.d.ts","names":["DIFFS_TAG_NAME","_0","HTMLElement","React","HTMLAttributes","DetailedHTMLProps","sideEffect"],"sources":["../../src/react/jsx.d.ts"],"sourcesContent":["import 'react';\n\nimport type { DIFFS_TAG_NAME } from '../constants';\n\ndeclare module 'react' {\n namespace JSX {\n interface IntrinsicElements {\n [DIFFS_TAG_NAME]: React.DetailedHTMLProps<\n React.HTMLAttributes<HTMLElement>,\n HTMLElement\n >;\n }\n }\n}\n"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"jsx.d.ts","names":["DIFFS_TAG_NAME","_0","HTMLElement","React","HTMLAttributes","DetailedHTMLProps","sideEffect"],"sources":["../../src/react/jsx.d.ts"],"sourcesContent":["import 'react';\n\nimport type { DIFFS_TAG_NAME } from '../constants';\n\ndeclare module 'react' {\n namespace JSX {\n interface IntrinsicElements {\n [DIFFS_TAG_NAME]: React.DetailedHTMLProps<\n React.HTMLAttributes<HTMLElement>,\n HTMLElement\n >;\n }\n }\n}\n"],"mappings":";;;;AAEmD,eAAA,OAAA,CAAA;EAAA,UAAA,GAAA,CAAA;cAAA,iBAAA,CAAA;MAMtBE,CADtBF,cAAAA,CACsBE,EADLC,KAAAA,CAAME,iBACDH,CAArBC,KAAAA,CAAMC,cAAAA,CAAeF,WAAfE,CAAAA,EACNF,WAAAA,CAFgBC;IAAjBH;EAAc"}
|
package/dist/react/types.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "react";
|
|
@@ -9,7 +9,7 @@ import { CreatePatchOptionsNonabortable } from "diff";
|
|
|
9
9
|
* If both `oldFile` and `newFile` have a `cacheKey`, the resulting diff will
|
|
10
10
|
* automatically get a combined cache key in the format `oldKey:newKey`.
|
|
11
11
|
*/
|
|
12
|
-
declare function parseDiffFromFile(oldFile: FileContents, newFile: FileContents, options?: CreatePatchOptionsNonabortable): FileDiffMetadata;
|
|
12
|
+
declare function parseDiffFromFile(oldFile: FileContents, newFile: FileContents, options?: CreatePatchOptionsNonabortable, throwOnError?: boolean): FileDiffMetadata;
|
|
13
13
|
//#endregion
|
|
14
14
|
export { parseDiffFromFile };
|
|
15
15
|
//# sourceMappingURL=parseDiffFromFile.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseDiffFromFile.d.ts","names":[],"sources":["../../src/utils/parseDiffFromFile.ts"],"sourcesContent":[],"mappings":";;;;;;;AAWA;;;;
|
|
1
|
+
{"version":3,"file":"parseDiffFromFile.d.ts","names":[],"sources":["../../src/utils/parseDiffFromFile.ts"],"sourcesContent":[],"mappings":";;;;;;;AAWA;;;;AAOG,iBAPa,iBAAA,CAOb,OAAA,EAJQ,YAIR,EAAA,OAAA,EAHQ,YAGR,EAAA,OAAA,CAAA,EAFS,8BAET,EAAA,YAAA,CAAA,EAAA,OAAA,CAAA,EAAA,gBAAA"}
|
|
@@ -8,13 +8,14 @@ import { createTwoFilesPatch } from "diff";
|
|
|
8
8
|
* If both `oldFile` and `newFile` have a `cacheKey`, the resulting diff will
|
|
9
9
|
* automatically get a combined cache key in the format `oldKey:newKey`.
|
|
10
10
|
*/
|
|
11
|
-
function parseDiffFromFile(oldFile, newFile, options) {
|
|
11
|
+
function parseDiffFromFile(oldFile, newFile, options, throwOnError = false) {
|
|
12
12
|
const fileData = processFile(createTwoFilesPatch(oldFile.name, newFile.name, oldFile.contents, newFile.contents, oldFile.header, newFile.header, options), {
|
|
13
13
|
cacheKey: (() => {
|
|
14
14
|
if (oldFile.cacheKey != null && newFile.cacheKey != null) return `${oldFile.cacheKey}:${newFile.cacheKey}`;
|
|
15
15
|
})(),
|
|
16
16
|
oldFile,
|
|
17
|
-
newFile
|
|
17
|
+
newFile,
|
|
18
|
+
throwOnError
|
|
18
19
|
});
|
|
19
20
|
if (fileData == null) throw new Error("parseDiffFrom: FileInvalid diff -- probably need to fix something -- if the files are the same maybe?");
|
|
20
21
|
return fileData;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseDiffFromFile.js","names":[],"sources":["../../src/utils/parseDiffFromFile.ts"],"sourcesContent":["import { type CreatePatchOptionsNonabortable, createTwoFilesPatch } from 'diff';\n\nimport type { FileContents, FileDiffMetadata } from '../types';\nimport { processFile } from './parsePatchFiles';\n\n/**\n * Parses a diff from two file contents objects.\n *\n * If both `oldFile` and `newFile` have a `cacheKey`, the resulting diff will\n * automatically get a combined cache key in the format `oldKey:newKey`.\n */\nexport function parseDiffFromFile(\n // FIXME(amadeus): oldFile/newFile should be optional to simulate new/deleted\n // files\n oldFile: FileContents,\n newFile: FileContents,\n options?: CreatePatchOptionsNonabortable\n): FileDiffMetadata {\n const patch = createTwoFilesPatch(\n oldFile.name,\n newFile.name,\n oldFile.contents,\n newFile.contents,\n oldFile.header,\n newFile.header,\n options\n );\n\n const fileData = processFile(patch, {\n cacheKey: (() => {\n if (oldFile.cacheKey != null && newFile.cacheKey != null) {\n return `${oldFile.cacheKey}:${newFile.cacheKey}`;\n }\n return undefined;\n })(),\n oldFile,\n newFile,\n });\n if (fileData == null) {\n throw new Error(\n 'parseDiffFrom: FileInvalid diff -- probably need to fix something -- if the files are the same maybe?'\n );\n }\n return fileData;\n}\n"],"mappings":";;;;;;;;;;AAWA,SAAgB,kBAGd,SACA,SACA,
|
|
1
|
+
{"version":3,"file":"parseDiffFromFile.js","names":[],"sources":["../../src/utils/parseDiffFromFile.ts"],"sourcesContent":["import { type CreatePatchOptionsNonabortable, createTwoFilesPatch } from 'diff';\n\nimport type { FileContents, FileDiffMetadata } from '../types';\nimport { processFile } from './parsePatchFiles';\n\n/**\n * Parses a diff from two file contents objects.\n *\n * If both `oldFile` and `newFile` have a `cacheKey`, the resulting diff will\n * automatically get a combined cache key in the format `oldKey:newKey`.\n */\nexport function parseDiffFromFile(\n // FIXME(amadeus): oldFile/newFile should be optional to simulate new/deleted\n // files\n oldFile: FileContents,\n newFile: FileContents,\n options?: CreatePatchOptionsNonabortable,\n throwOnError = false\n): FileDiffMetadata {\n const patch = createTwoFilesPatch(\n oldFile.name,\n newFile.name,\n oldFile.contents,\n newFile.contents,\n oldFile.header,\n newFile.header,\n options\n );\n\n const fileData = processFile(patch, {\n cacheKey: (() => {\n if (oldFile.cacheKey != null && newFile.cacheKey != null) {\n return `${oldFile.cacheKey}:${newFile.cacheKey}`;\n }\n return undefined;\n })(),\n oldFile,\n newFile,\n throwOnError,\n });\n if (fileData == null) {\n throw new Error(\n 'parseDiffFrom: FileInvalid diff -- probably need to fix something -- if the files are the same maybe?'\n );\n }\n return fileData;\n}\n"],"mappings":";;;;;;;;;;AAWA,SAAgB,kBAGd,SACA,SACA,SACA,eAAe,OACG;CAWlB,MAAM,WAAW,YAVH,oBACZ,QAAQ,MACR,QAAQ,MACR,QAAQ,UACR,QAAQ,UACR,QAAQ,QACR,QAAQ,QACR,QACD,EAEmC;EAClC,iBAAiB;AACf,OAAI,QAAQ,YAAY,QAAQ,QAAQ,YAAY,KAClD,QAAO,GAAG,QAAQ,SAAS,GAAG,QAAQ;MAGtC;EACJ;EACA;EACA;EACD,CAAC;AACF,KAAI,YAAY,KACd,OAAM,IAAI,MACR,wGACD;AAEH,QAAO"}
|
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import { FileContents, FileDiffMetadata, ParsedPatch } from "../types.js";
|
|
2
2
|
|
|
3
3
|
//#region src/utils/parsePatchFiles.d.ts
|
|
4
|
-
declare function processPatch(data: string, cacheKeyPrefix?: string): ParsedPatch;
|
|
4
|
+
declare function processPatch(data: string, cacheKeyPrefix?: string, throwOnError?: boolean): ParsedPatch;
|
|
5
5
|
interface ProcessFileOptions {
|
|
6
6
|
cacheKey?: string;
|
|
7
7
|
isGitDiff?: boolean;
|
|
8
8
|
oldFile?: FileContents;
|
|
9
9
|
newFile?: FileContents;
|
|
10
|
+
throwOnError?: boolean;
|
|
10
11
|
}
|
|
11
12
|
declare function processFile(fileDiffString: string, {
|
|
12
13
|
cacheKey,
|
|
13
14
|
isGitDiff,
|
|
14
15
|
oldFile,
|
|
15
|
-
newFile
|
|
16
|
+
newFile,
|
|
17
|
+
throwOnError
|
|
16
18
|
}?: ProcessFileOptions): FileDiffMetadata | undefined;
|
|
17
19
|
/**
|
|
18
20
|
* Parses a patch file string into an array of parsed patches.
|
|
@@ -22,7 +24,7 @@ declare function processFile(fileDiffString: string, {
|
|
|
22
24
|
* each file in the patch will get a cache key in the format `prefix-patchIndex-fileIndex`.
|
|
23
25
|
* This enables caching of rendered diff results in the worker pool.
|
|
24
26
|
*/
|
|
25
|
-
declare function parsePatchFiles(data: string, cacheKeyPrefix?: string): ParsedPatch[];
|
|
27
|
+
declare function parsePatchFiles(data: string, cacheKeyPrefix?: string, throwOnError?: boolean): ParsedPatch[];
|
|
26
28
|
//#endregion
|
|
27
29
|
export { parsePatchFiles, processFile, processPatch };
|
|
28
30
|
//# sourceMappingURL=parsePatchFiles.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parsePatchFiles.d.ts","names":[],"sources":["../../src/utils/parsePatchFiles.ts"],"sourcesContent":[],"mappings":";;;iBAuBgB,YAAA,
|
|
1
|
+
{"version":3,"file":"parsePatchFiles.d.ts","names":[],"sources":["../../src/utils/parsePatchFiles.ts"],"sourcesContent":[],"mappings":";;;iBAuBgB,YAAA,iEAIb;UAyDO,kBAAA;EA7DV,QAAgB,CAAA,EAAA,MAAA;EAIb,SAyDO,CAAA,EAAA,OAAA;EAQV,OAAgB,CAAA,EALJ,YAKI;EAGZ,OAAA,CAAA,EAPQ,YAOR;EACA,YAAA,CAAA,EAAA,OAAA;;AAEA,iBANY,WAAA,CAMZ,cAAA,EAAA,MAAA,EAAA;EAAA,QAAA;EAAA,SAAA;EAAA,OAAA;EAAA,OAAA;EAAA;AAAA,CAAA,CAAA,EAEC,kBAFD,CAAA,EAGD,gBAHC,GAAA,SAAA;;;;;AA+XJ;;;;iBAAgB,eAAA,iEAIb"}
|