@pierre/diffs 1.3.1 → 1.3.3

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.
@@ -29,8 +29,9 @@ declare class SelectionActionWidget {
29
29
  * @param top - The top position of the selection action widget.
30
30
  * @param gutterWidth - The width of the gutter.
31
31
  * @param placeAbove - Whether the selection action widget should be placed above the anchor.
32
+ * @param visible - Whether the selection intersects the viewport.
32
33
  */
33
- reposition(left: number, top: number, gutterWidth: number, placeAbove: boolean, viewport?: PopoverViewportBounds): void;
34
+ reposition(left: number, top: number, gutterWidth: number, placeAbove: boolean, visible: boolean, viewport?: PopoverViewportBounds): void;
34
35
  /**
35
36
  * Gets the height of the selection action widget.
36
37
  * @returns The height of the selection action widget.
@@ -1 +1 @@
1
- {"version":3,"file":"selectionAction.d.ts","names":[],"sources":["../../src/editor/selectionAction.ts"],"mappings":";;;;;UAQiB,sBAAA;;EAEf,SAAA,EAAW,eAAA;EAF0B;EAIrC,YAAA,EAAc,YAAA,CAAa,WAAA;EAFhB;EAIX,UAAA,GAAa,KAAA,EAAO,QAAA;EAFN;EAId,gBAAA;EAF4B;EAI5B,oBAAA,GAAuB,IAAA;EAVe;EAYtC,KAAA;AAAA;;;;cAMW,qBAAA;EAAA;EAOX,WAAA,CACE,sBAAA,EAAwB,WAAA,EACxB,cAAA,EAAgB,WAAA,EAChB,cAAA;EApBF;;;;;AAIK;AAMP;EAuCE,UAAA,CACE,IAAA,UACA,GAAA,UACA,WAAA,UACA,UAAA,WACA,QAAA,GAAW,qBAAA;;;;;MAeT,MAAA;EAf8B;;;EAsBlC,OAAA;AAAA"}
1
+ {"version":3,"file":"selectionAction.d.ts","names":[],"sources":["../../src/editor/selectionAction.ts"],"mappings":";;;;;UAQiB,sBAAA;;EAEf,SAAA,EAAW,eAAA;EAF0B;EAIrC,YAAA,EAAc,YAAA,CAAa,WAAA;EAFhB;EAIX,UAAA,GAAa,KAAA,EAAO,QAAA;EAFN;EAId,gBAAA;EAF4B;EAI5B,oBAAA,GAAuB,IAAA;EAVe;EAYtC,KAAA;AAAA;;;;cAMW,qBAAA;EAAA;EAOX,WAAA,CACE,sBAAA,EAAwB,WAAA,EACxB,cAAA,EAAgB,WAAA,EAChB,cAAA;EApBF;;;;;AAIK;AAMP;;EAwCE,UAAA,CACE,IAAA,UACA,GAAA,UACA,WAAA,UACA,UAAA,WACA,OAAA,WACA,QAAA,GAAW,qBAAA;EAtCa;;;;EAAA,IAsDtB,MAAA;;;;EAOJ,OAAA;AAAA"}
@@ -33,8 +33,10 @@ var SelectionActionWidget = class {
33
33
  * @param top - The top position of the selection action widget.
34
34
  * @param gutterWidth - The width of the gutter.
35
35
  * @param placeAbove - Whether the selection action widget should be placed above the anchor.
36
+ * @param visible - Whether the selection intersects the viewport.
36
37
  */
37
- reposition(left, top, gutterWidth, placeAbove, viewport) {
38
+ reposition(left, top, gutterWidth, placeAbove, visible, viewport) {
39
+ this.#root.style.visibility = visible ? "" : "hidden";
38
40
  setPopoverPositionStyles(this.#root, {
39
41
  gutterWidth,
40
42
  placeAbove,
@@ -1 +1 @@
1
- {"version":3,"file":"selectionAction.js","names":["#root","#height","#resizeObserver"],"sources":["../../src/editor/selectionAction.ts"],"sourcesContent":["import type { EditorSelection, TextEdit } from '../types';\nimport {\n type PopoverViewportBounds,\n setPopoverPositionStyles,\n} from './popover';\nimport type { TextDocument } from './textDocument';\nimport { h } from './utils';\n\nexport interface SelectionActionContext<LAnnotation> {\n /** The current selection (live: reflects keyboard-driven changes). */\n selection: EditorSelection;\n /** The text document. */\n textDocument: TextDocument<LAnnotation>;\n /** Applies the edits to the text document. */\n applyEdits: (edits: TextEdit[]) => void;\n /** Gets the text of the current selection. */\n getSelectionText: () => string;\n /** Replaces the text of the current selection. */\n replaceSelectionText: (text: string) => void;\n /** Closes the selection action. */\n close: () => void;\n}\n\n/**\n * Selection action widget.\n */\nexport class SelectionActionWidget {\n #root: HTMLElement;\n // Cached border-box height, refreshed only when the popover's own size\n // actually changes (via #resizeObserver below)\n #height: number;\n #resizeObserver: ResizeObserver;\n\n constructor(\n selectionActionElement: HTMLElement,\n overlayElement: HTMLElement,\n onHeightChange: () => void\n ) {\n this.#root = h(\n 'div',\n {\n dataset: { editorWidget: '', selectionActionPopover: '' },\n contentEditable: 'false',\n children: [selectionActionElement],\n },\n overlayElement\n );\n this.#height = this.#root.offsetHeight;\n this.#resizeObserver = new ResizeObserver(() => {\n const height = this.#root.offsetHeight;\n if (height !== this.#height) {\n this.#height = height;\n onHeightChange();\n }\n });\n this.#resizeObserver.observe(this.#root);\n }\n\n /**\n * Repositions the selection action widget.\n * @param left - The left position of the selection action widget.\n * @param top - The top position of the selection action widget.\n * @param gutterWidth - The width of the gutter.\n * @param placeAbove - Whether the selection action widget should be placed above the anchor.\n */\n reposition(\n left: number,\n top: number,\n gutterWidth: number,\n placeAbove: boolean,\n viewport?: PopoverViewportBounds\n ): void {\n setPopoverPositionStyles(this.#root, {\n gutterWidth,\n placeAbove,\n viewport,\n x: left,\n y: top,\n });\n }\n\n /**\n * Gets the height of the selection action widget.\n * @returns The height of the selection action widget.\n */\n get height(): number {\n return this.#height;\n }\n\n /**\n * Cleans up the selection action widget.\n */\n cleanup(): void {\n this.#resizeObserver.disconnect();\n this.#root.remove();\n }\n}\n"],"mappings":";;;;;;AA0BA,IAAa,wBAAb,MAAmC;CACjC;CAGA;CACA;CAEA,YACE,wBACA,gBACA,gBACA;EACA,KAAKA,QAAQ,EACX,OACA;GACE,SAAS;IAAE,cAAc;IAAI,wBAAwB;GAAG;GACxD,iBAAiB;GACjB,UAAU,CAAC,sBAAsB;EACnC,GACA,cACF;EACA,KAAKC,UAAU,KAAKD,MAAM;EAC1B,KAAKE,kBAAkB,IAAI,qBAAqB;GAC9C,MAAM,SAAS,KAAKF,MAAM;GAC1B,IAAI,WAAW,KAAKC,SAAS;IAC3B,KAAKA,UAAU;IACf,eAAe;GACjB;EACF,CAAC;EACD,KAAKC,gBAAgB,QAAQ,KAAKF,KAAK;CACzC;;;;;;;;CASA,WACE,MACA,KACA,aACA,YACA,UACM;EACN,yBAAyB,KAAKA,OAAO;GACnC;GACA;GACA;GACA,GAAG;GACH,GAAG;EACL,CAAC;CACH;;;;;CAMA,IAAI,SAAiB;EACnB,OAAO,KAAKC;CACd;;;;CAKA,UAAgB;EACd,KAAKC,gBAAgB,WAAW;EAChC,KAAKF,MAAM,OAAO;CACpB;AACF"}
1
+ {"version":3,"file":"selectionAction.js","names":["#root","#height","#resizeObserver"],"sources":["../../src/editor/selectionAction.ts"],"sourcesContent":["import type { EditorSelection, TextEdit } from '../types';\nimport {\n type PopoverViewportBounds,\n setPopoverPositionStyles,\n} from './popover';\nimport type { TextDocument } from './textDocument';\nimport { h } from './utils';\n\nexport interface SelectionActionContext<LAnnotation> {\n /** The current selection (live: reflects keyboard-driven changes). */\n selection: EditorSelection;\n /** The text document. */\n textDocument: TextDocument<LAnnotation>;\n /** Applies the edits to the text document. */\n applyEdits: (edits: TextEdit[]) => void;\n /** Gets the text of the current selection. */\n getSelectionText: () => string;\n /** Replaces the text of the current selection. */\n replaceSelectionText: (text: string) => void;\n /** Closes the selection action. */\n close: () => void;\n}\n\n/**\n * Selection action widget.\n */\nexport class SelectionActionWidget {\n #root: HTMLElement;\n // Cached border-box height, refreshed only when the popover's own size\n // actually changes (via #resizeObserver below)\n #height: number;\n #resizeObserver: ResizeObserver;\n\n constructor(\n selectionActionElement: HTMLElement,\n overlayElement: HTMLElement,\n onHeightChange: () => void\n ) {\n this.#root = h(\n 'div',\n {\n dataset: { editorWidget: '', selectionActionPopover: '' },\n contentEditable: 'false',\n children: [selectionActionElement],\n },\n overlayElement\n );\n this.#height = this.#root.offsetHeight;\n this.#resizeObserver = new ResizeObserver(() => {\n const height = this.#root.offsetHeight;\n if (height !== this.#height) {\n this.#height = height;\n onHeightChange();\n }\n });\n this.#resizeObserver.observe(this.#root);\n }\n\n /**\n * Repositions the selection action widget.\n * @param left - The left position of the selection action widget.\n * @param top - The top position of the selection action widget.\n * @param gutterWidth - The width of the gutter.\n * @param placeAbove - Whether the selection action widget should be placed above the anchor.\n * @param visible - Whether the selection intersects the viewport.\n */\n reposition(\n left: number,\n top: number,\n gutterWidth: number,\n placeAbove: boolean,\n visible: boolean,\n viewport?: PopoverViewportBounds\n ): void {\n this.#root.style.visibility = visible ? '' : 'hidden';\n setPopoverPositionStyles(this.#root, {\n gutterWidth,\n placeAbove,\n viewport,\n x: left,\n y: top,\n });\n }\n\n /**\n * Gets the height of the selection action widget.\n * @returns The height of the selection action widget.\n */\n get height(): number {\n return this.#height;\n }\n\n /**\n * Cleans up the selection action widget.\n */\n cleanup(): void {\n this.#resizeObserver.disconnect();\n this.#root.remove();\n }\n}\n"],"mappings":";;;;;;AA0BA,IAAa,wBAAb,MAAmC;CACjC;CAGA;CACA;CAEA,YACE,wBACA,gBACA,gBACA;EACA,KAAKA,QAAQ,EACX,OACA;GACE,SAAS;IAAE,cAAc;IAAI,wBAAwB;GAAG;GACxD,iBAAiB;GACjB,UAAU,CAAC,sBAAsB;EACnC,GACA,cACF;EACA,KAAKC,UAAU,KAAKD,MAAM;EAC1B,KAAKE,kBAAkB,IAAI,qBAAqB;GAC9C,MAAM,SAAS,KAAKF,MAAM;GAC1B,IAAI,WAAW,KAAKC,SAAS;IAC3B,KAAKA,UAAU;IACf,eAAe;GACjB;EACF,CAAC;EACD,KAAKC,gBAAgB,QAAQ,KAAKF,KAAK;CACzC;;;;;;;;;CAUA,WACE,MACA,KACA,aACA,YACA,SACA,UACM;EACN,KAAKA,MAAM,MAAM,aAAa,UAAU,KAAK;EAC7C,yBAAyB,KAAKA,OAAO;GACnC;GACA;GACA;GACA,GAAG;GACH,GAAG;EACL,CAAC;CACH;;;;;CAMA,IAAI,SAAiB;EACnB,OAAO,KAAKC;CACd;;;;CAKA,UAAgB;EACd,KAAKC,gBAAgB,WAAW;EAChC,KAAKF,MAAM,OAAO;CACpB;AACF"}
@@ -56,6 +56,7 @@ type CodeViewProps<LAnnotation = undefined> = ControlledCodeViewProps<LAnnotatio
56
56
  interface CodeViewHandle<LAnnotation> {
57
57
  addItems(items: readonly CodeViewItem<LAnnotation>[]): void;
58
58
  getItem(id: string): CodeViewItem<LAnnotation> | undefined;
59
+ removeItem(id: string): boolean;
59
60
  updateItem(item: CodeViewItem<LAnnotation>): boolean;
60
61
  updateItemId(oldId: string, newId: string): boolean;
61
62
  scrollTo(target: CodeViewScrollTarget): void;
@@ -1 +1 @@
1
- {"version":3,"file":"CodeView.d.ts","names":[],"sources":["../../src/react/CodeView.tsx"],"mappings":";;;;;;;KA+CK,2BAAA,UACM,oBAAA,+BACA,oBAAoB;AAAA,KAEnB,oBAAA,4BAAgD,IAAA,CAC1D,eAAA,CAAgB,WAAA;AAAA,UAIR,iBAAA;EACR,OAAA,GAAU,oBAAA,CAAqB,WAAA;;;AArBf;;EA0BhB,aAAA,GAAgB,IAAA,CAAK,aAAA,CAAc,WAAA;EACnC,SAAA;EACA,KAAA,GAAQ,aAAA;EACR,YAAA,GAAe,GAAA,CAAI,cAAA;EACnB,iBAAA;EACA,aAAA,GAAgB,qBAAA;EAChB,qBAAA,EAAuB,SAAA,EAAW,qBAAA;EAClC,QAAA,EAAU,SAAA,UAAmB,MAAA,EAAQ,UAAA,CAAc,WAAA;EAlBO;;EAqB1D,oBAAA,KAAyB,SAAA;EArBM;;EAwB/B,oBAAA,KAAyB,SAAA;EAvBT;EAyBhB,gBAAA,EACE,IAAA,EAAM,YAAA,CAAa,WAAA,GACnB,IAAA,EAAM,YAAA,EACN,eAAA,GACI,cAAA,CAAe,WAAA,MACf,kBAAA,CAAmB,WAAA;EA9BE;AAE3B;;;;;;EAqCA,kBAAA,EACE,IAAA,EAAM,YAAA,CAAa,WAAA,GACnB,IAAA,EAAM,YAAA,EACN,eAAA,GACI,cAAA,CAAe,WAAA,MACf,kBAAA,CAAmB,WAAA;EAEzB,kBAAA,EAAoB,IAAA,EAAM,YAAA,CAAa,WAAA,IAAe,SAAA;EACt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Ae,kBAAA,CAAmB,WAAA,GAC7D,IAAA,EAAM,YAAA,CAAa,WAAA,IAClB,SAAA;EACH,mBAAA,EACE,cAAA,EAAgB,2BAAA,EAChB,IAAA,EAAM,YAAA,CAAa,WAAA,IAClB,SAAA;AAAA;AAAA,UAGY,uBAAA,sBAEP,iBAAA,CAAkB,WAAA;EAC1B,KAAA,WAAgB,YAAA,CAAa,WAAA;EAC7B,YAAA;AAAA;AAAA,UAGe,yBAAA,sBAEP,iBAAA,CAAkB,WAAA;EAG1B,YAAA,YAAwB,YAAA,CAAa,WAAA;EACrC,KAAA;AAAA;AAAA,KAGU,aAAA,4BACR,uBAAA,CAAwB,WAAA,IACxB,yBAAA,CAA0B,WAAA;AAAA,UAEb,cAAA;EACf,QAAA,CAAS,KAAA,WAAgB,YAAA,CAAa,WAAA;EACtC,OAAA,CAAQ,EAAA,WAAa,YAAA,CAAa,WAAA;EAClC,UAAA,CAAW,EAAA;EACX,UAAA,CAAW,IAAA,EAAM,YAAA,CAAa,WAAA;EAC9B,YAAA,CAAa,KAAA,UAAe,KAAA;EAC5B,QAAA,CAAS,MAAA,EAAQ,oBAAA;EACjB,gBAAA,CAAiB,SAAA,EAAW,qBAAA;EAC5B,gBAAA,IAAoB,qBAAA;EACpB,kBAAA;EACA,SAAA,CAAU,EAAA,WAAa,WAAA,CAAY,WAAA;EACnC,WAAA,IAAe,UAAA,CAAc,WAAA;AAAA;AAAA,KAG1B,iBAAA,6BACH,KAAA,EAAO,aAAA,CAAc,WAAA;EACnB,GAAA,GAAM,KAAA,CAAM,GAAA,CAAI,cAAA,CAAe,WAAA;AAAA,MAE9B,KAAA,CAAM,GAAA,CAAI,OAAA;AAAA,cAueF,QAAA,EAAwC,iBAAiB"}
@@ -182,6 +182,15 @@ function CodeViewInner(props, ref) {
182
182
  return;
183
183
  } else return instance.getItem(id);
184
184
  },
185
+ removeItem(id) {
186
+ const { controlled, instance } = cachedDataRef.current;
187
+ assertUncontrolledCodeViewAction(controlled, "removeItem");
188
+ if (instance == null) {
189
+ console.error("CodeView.removeItem: no valid instance to remove item from", id);
190
+ return false;
191
+ }
192
+ return instance.removeItem(id);
193
+ },
185
194
  updateItem(item) {
186
195
  const { controlled, instance } = cachedDataRef.current;
187
196
  assertUncontrolledCodeViewAction(controlled, "updateItem");
@@ -1 +1 @@
1
- {"version":3,"file":"CodeView.js","names":["CodeViewClass"],"sources":["../../src/react/CodeView.tsx"],"sourcesContent":["'use client';\n\nimport {\n type CSSProperties,\n forwardRef,\n memo,\n type ReactNode,\n type Ref,\n useContext,\n useEffect,\n useImperativeHandle,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n useSyncExternalStore,\n} from 'react';\nimport { createPortal, flushSync } from 'react-dom';\n\nimport type { EditorOptions } from '../edit';\nimport {\n areOptionsEqual,\n CodeView as CodeViewClass,\n type CodeViewCoordinator,\n type CodeViewCreateEditorOptions,\n type CodeViewItem,\n type CodeViewLineSelection,\n type CodeViewOptions,\n type CodeViewRenderedItem,\n type CodeViewScrollTarget,\n type CodeViewSlotSnapshot,\n type DiffLineAnnotation,\n type DiffsEditor,\n type FileContents,\n type GetHoveredLineResult,\n type LineAnnotation,\n} from '../index';\nimport { areManagedSnapshotsEqual } from '../utils/areManagedSnapshotsEqual';\nimport { useCreateEditor } from './EditContext';\nimport { renderDiffChildren } from './utils/renderDiffChildren';\nimport { renderFileChildren } from './utils/renderFileChildren';\nimport { useStableCallback } from './utils/useStableCallback';\nimport { WorkerPoolContext } from './WorkerPoolContext';\n\nconst useIsomorphicLayoutEffect =\n typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\ntype CodeViewGutterUtilityGetter =\n | (() => GetHoveredLineResult<'file'> | undefined)\n | (() => GetHoveredLineResult<'diff'> | undefined);\n\nexport type CodeViewReactOptions<LAnnotation = undefined> = Omit<\n CodeViewOptions<LAnnotation>,\n 'controlledSelection' | 'createEditor' | 'onSelectedLinesChange'\n>;\n\ninterface CodeViewBaseProps<LAnnotation> {\n options?: CodeViewReactOptions<LAnnotation>;\n /**\n * Creation-time options passed to the nearest EditProvider factory.\n * CodeView supplies its item-specific change callback.\n */\n editorOptions?: Omit<EditorOptions<LAnnotation>, 'onChange'>;\n className?: string;\n style?: CSSProperties;\n containerRef?: Ref<HTMLDivElement>;\n disableWorkerPool?: boolean;\n selectedLines?: CodeViewLineSelection | null;\n onSelectedLinesChange?(selection: CodeViewLineSelection | null): void;\n onScroll?(scrollTop: number, viewer: CodeViewClass<LAnnotation>): void;\n /** Render a non-virtualized node at the very start of the scroll content,\n * before the first item. Always rendered; scrolls with the content. */\n renderCodeViewHeader?(): ReactNode;\n /** Render a non-virtualized node at the very end of the scroll content, after\n * the last item. Always rendered; scrolls with the content. */\n renderCodeViewFooter?(): ReactNode;\n /** Called with the owning item on every edited-document change. */\n onItemEditChange?(\n item: CodeViewItem<LAnnotation>,\n file: FileContents,\n lineAnnotations?:\n | LineAnnotation<LAnnotation>[]\n | DiffLineAnnotation<LAnnotation>[]\n ): void;\n /**\n * Called once with the final contents when an item's edit session ends\n * (edit turned off, item removed or collapsed). Not called for sessions\n * that produced no changes. Committing is user-space: make one combined\n * item write carrying the new file/fileDiff (with a fresh `cacheKey`,\n * since the contents changed) along with `edit: false`.\n */\n onItemEditComplete?(\n item: CodeViewItem<LAnnotation>,\n file: FileContents,\n lineAnnotations?:\n | LineAnnotation<LAnnotation>[]\n | DiffLineAnnotation<LAnnotation>[]\n ): void;\n renderCustomHeader?(item: CodeViewItem<LAnnotation>): ReactNode;\n renderHeaderPrefix?(item: CodeViewItem<LAnnotation>): ReactNode;\n renderHeaderFilenameSuffix?(item: CodeViewItem<LAnnotation>): ReactNode;\n renderHeaderMetadata?(item: CodeViewItem<LAnnotation>): ReactNode;\n renderAnnotation?(\n annotation: LineAnnotation<LAnnotation> | DiffLineAnnotation<LAnnotation>,\n item: CodeViewItem<LAnnotation>\n ): ReactNode;\n renderGutterUtility?(\n getHoveredLine: CodeViewGutterUtilityGetter,\n item: CodeViewItem<LAnnotation>\n ): ReactNode;\n}\n\nexport interface ControlledCodeViewProps<\n LAnnotation,\n> extends CodeViewBaseProps<LAnnotation> {\n items: readonly CodeViewItem<LAnnotation>[];\n initialItems?: never;\n}\n\nexport interface UncontrolledCodeViewProps<\n LAnnotation,\n> extends CodeViewBaseProps<LAnnotation> {\n // Seeds the imperative CodeView instance once. Later item changes should go\n // through the ref API instead of being reconciled from React props.\n initialItems?: readonly CodeViewItem<LAnnotation>[];\n items?: never;\n}\n\nexport type CodeViewProps<LAnnotation = undefined> =\n | ControlledCodeViewProps<LAnnotation>\n | UncontrolledCodeViewProps<LAnnotation>;\n\nexport interface CodeViewHandle<LAnnotation> {\n addItems(items: readonly CodeViewItem<LAnnotation>[]): void;\n getItem(id: string): CodeViewItem<LAnnotation> | undefined;\n updateItem(item: CodeViewItem<LAnnotation>): boolean;\n updateItemId(oldId: string, newId: string): boolean;\n scrollTo(target: CodeViewScrollTarget): void;\n setSelectedLines(selection: CodeViewLineSelection | null): void;\n getSelectedLines(): CodeViewLineSelection | null;\n clearSelectedLines(): void;\n getEditor(id: string): DiffsEditor<LAnnotation> | undefined;\n getInstance(): CodeViewClass<LAnnotation> | undefined;\n}\n\ntype CodeViewComponent = <LAnnotation = undefined>(\n props: CodeViewProps<LAnnotation> & {\n ref?: React.Ref<CodeViewHandle<LAnnotation>>;\n }\n) => React.JSX.Element;\n\ntype SlotPortalsComponent = <LAnnotation = undefined>(\n props: SlotPortalsProps<LAnnotation>\n) => React.JSX.Element;\n\ninterface ManagedContentStore<LAnnotation> {\n getSnapshot(): CodeViewSlotSnapshot<LAnnotation> | undefined;\n publish(snapshot: CodeViewSlotSnapshot<LAnnotation> | undefined): void;\n subscribe(listener: () => void): () => void;\n}\n\ninterface CachedDataRef<LAnnotation> {\n instance: CodeViewClass<LAnnotation> | undefined;\n items: readonly CodeViewItem<LAnnotation>[] | undefined;\n controlled: boolean;\n managedOptions: CodeViewOptions<LAnnotation> | undefined;\n disableFlushSync: boolean;\n slotCoordinator: CodeViewCoordinator<LAnnotation> | undefined;\n}\n\nfunction createDefaultCache<LAnnotation>(\n controlled: boolean\n): CachedDataRef<LAnnotation> {\n return {\n instance: undefined,\n items: undefined,\n controlled,\n managedOptions: undefined,\n disableFlushSync: false,\n slotCoordinator: undefined,\n };\n}\n\nfunction CodeViewInner<LAnnotation = undefined>(\n props: CodeViewProps<LAnnotation>,\n ref: React.ForwardedRef<CodeViewHandle<LAnnotation>>\n): React.JSX.Element {\n const {\n className,\n containerRef,\n disableWorkerPool = false,\n editorOptions,\n initialItems,\n items: controlledItems,\n onItemEditChange,\n onItemEditComplete,\n onScroll,\n onSelectedLinesChange,\n options,\n renderAnnotation,\n renderCodeViewFooter,\n renderCodeViewHeader,\n renderCustomHeader,\n renderGutterUtility,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderHeaderPrefix,\n selectedLines,\n style,\n } = props;\n const controlled = controlledItems !== undefined;\n const contextCreateEditor = useCreateEditor<LAnnotation>();\n const poolManager = useContext(WorkerPoolContext);\n const cachedDataRef = useRef<CachedDataRef<LAnnotation>>(\n createDefaultCache<LAnnotation>(controlled)\n );\n const hasCustomHeader = renderCustomHeader != null;\n const hasAnnotationRenderer = renderAnnotation != null;\n const hasGutterRenderer = renderGutterUtility != null;\n const hasHeaderRenderers =\n hasCustomHeader ||\n renderHeaderPrefix != null ||\n renderHeaderFilenameSuffix != null ||\n renderHeaderMetadata != null;\n const hasRenderers =\n hasHeaderRenderers || hasAnnotationRenderer || hasGutterRenderer;\n const hasCodeViewHeader = renderCodeViewHeader != null;\n const hasCodeViewFooter = renderCodeViewFooter != null;\n const emitSelectedLinesChange = useStableCallback(\n (selection: CodeViewLineSelection | null) => {\n onSelectedLinesChange?.(selection);\n }\n );\n const controlledSelection = selectedLines !== undefined;\n\n // Keep the adapter stable so provider and editor-option changes affect the\n // next item edit session without forcing CodeView to reconcile active editors.\n const createEditor = useStableCallback(\n (\n options: CodeViewCreateEditorOptions<LAnnotation>\n ): DiffsEditor<LAnnotation> => {\n if (contextCreateEditor == null) {\n throw new Error('CodeView: EditContext is not attached');\n }\n\n const editor = contextCreateEditor({\n ...editorOptions,\n ...options,\n });\n if (editor == null) {\n throw new Error(\n 'CodeView: EditProvider.createEditor must return an editor instance'\n );\n }\n return editor;\n }\n );\n const emitItemEditChange = useStableCallback(\n (\n item: CodeViewItem<LAnnotation>,\n file: FileContents,\n lineAnnotations?:\n | LineAnnotation<LAnnotation>[]\n | DiffLineAnnotation<LAnnotation>[]\n ) => {\n onItemEditChange?.(item, file, lineAnnotations);\n }\n );\n const emitItemEditComplete = useStableCallback(\n (\n item: CodeViewItem<LAnnotation>,\n file: FileContents,\n lineAnnotations?:\n | LineAnnotation<LAnnotation>[]\n | DiffLineAnnotation<LAnnotation>[]\n ) => {\n onItemEditComplete?.(item, file, lineAnnotations);\n }\n );\n\n const managedOptions = useMemo(\n () =>\n createManagedCodeViewOptions({\n options,\n hasCustomHeader,\n hasGutterRenderer,\n hasCodeViewHeader,\n hasCodeViewFooter,\n onSelectedLinesChange:\n onSelectedLinesChange != null ? emitSelectedLinesChange : undefined,\n controlledSelection,\n createEditor: contextCreateEditor != null ? createEditor : undefined,\n onItemEditChange:\n onItemEditChange != null ? emitItemEditChange : undefined,\n onItemEditComplete:\n onItemEditComplete != null ? emitItemEditComplete : undefined,\n }),\n [\n contextCreateEditor,\n controlledSelection,\n createEditor,\n emitItemEditChange,\n emitItemEditComplete,\n emitSelectedLinesChange,\n hasCodeViewFooter,\n hasCodeViewHeader,\n hasCustomHeader,\n hasGutterRenderer,\n onItemEditChange,\n onItemEditComplete,\n onSelectedLinesChange,\n options,\n ]\n );\n\n const [slotContentStore] = useState<ManagedContentStore<LAnnotation>>(() =>\n createSlotContentStore()\n );\n const [, forceUpdate] = useState<unknown>({});\n\n const nodeRef = useStableCallback((node: HTMLDivElement | null) => {\n // If we have a pre-existing instance and there's no node or the node being\n // passed in is NOT the same as before, then we need to clean up and\n // garbage collect the old instance\n if (\n cachedDataRef.current.instance != null &&\n (node == null ||\n node !== cachedDataRef.current.instance.getContainerElement())\n ) {\n cachedDataRef.current.instance.cleanUp();\n slotContentStore.publish(undefined);\n cachedDataRef.current = createDefaultCache<LAnnotation>(controlled);\n }\n\n // If our node matches the existing node then we should not attempt to\n // setup. This is a case that should never be possible to hit, but just in\n // case, lets make sure we don't re-setup an instance that is already setup\n // properly\n if (\n node != null &&\n node !== cachedDataRef.current.instance?.getContainerElement()\n ) {\n cachedDataRef.current.instance = new CodeViewClass<LAnnotation>(\n managedOptions,\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n cachedDataRef.current.instance.setup(node);\n }\n\n if (typeof containerRef === 'function') {\n containerRef(node);\n } else if (containerRef != null) {\n containerRef.current = node;\n }\n });\n\n const onSnapshotChange = useStableCallback(\n (snapshot: CodeViewSlotSnapshot<LAnnotation> | undefined) => {\n if (cachedDataRef.current.disableFlushSync) {\n slotContentStore.publish(snapshot);\n } else {\n flushSync(() => {\n slotContentStore.publish(snapshot);\n });\n }\n }\n );\n\n const slotCoordinator: CodeViewCoordinator<LAnnotation> | undefined =\n useMemo(() => {\n // A coordinator is needed whenever React portals anything — per-item\n // slots and codeview header and footer\n if (\n !hasHeaderRenderers &&\n !hasAnnotationRenderer &&\n !hasGutterRenderer &&\n !hasCodeViewHeader &&\n !hasCodeViewFooter\n ) {\n return undefined;\n } else {\n return {\n hasHeaderRenderers,\n hasAnnotationRenderer,\n hasGutterRenderer,\n onSnapshotChange,\n };\n }\n }, [\n onSnapshotChange,\n hasAnnotationRenderer,\n hasGutterRenderer,\n hasHeaderRenderers,\n hasCodeViewHeader,\n hasCodeViewFooter,\n ]);\n\n useIsomorphicLayoutEffect(() => {\n return onScroll != null\n ? cachedDataRef.current.instance?.subscribeToScroll(onScroll)\n : undefined;\n });\n\n useIsomorphicLayoutEffect(() => {\n const {\n instance,\n controlled: prevControlled,\n items: prevItems,\n managedOptions: prevManagedOptions,\n slotCoordinator: prevSlotCoordinator,\n } = cachedDataRef.current;\n if (instance == null) {\n return;\n }\n\n try {\n cachedDataRef.current.disableFlushSync = true;\n let shouldRender = false;\n\n if (!areOptionsEqual(managedOptions, prevManagedOptions)) {\n cachedDataRef.current.managedOptions = managedOptions;\n instance.setOptions(managedOptions);\n shouldRender = true;\n }\n\n if (prevControlled !== controlled) {\n console.error(\n 'CodeView: cannot switch between controlled and uncontrolled modes. Remount with a new key instead.'\n );\n return;\n }\n\n if (controlled) {\n if (controlledItems !== prevItems) {\n if (areItemListsEqual(prevItems, controlledItems)) {\n cachedDataRef.current.items = controlledItems;\n } else if (isAppendOnlyItemUpdate(prevItems, controlledItems)) {\n cachedDataRef.current.items = controlledItems;\n instance.addItems(controlledItems.slice(prevItems.length));\n } else {\n cachedDataRef.current.items = controlledItems;\n instance.setItems(controlledItems);\n shouldRender = true;\n }\n }\n }\n // If uncontrolled, we should only ever set items once, and just depend\n // on imperative instance changes going forward\n else if (prevItems == null) {\n const seedItems = initialItems ?? [];\n cachedDataRef.current.items = seedItems;\n if (seedItems.length > 0) {\n instance.setItems(seedItems);\n shouldRender = true;\n }\n }\n\n if (selectedLines !== undefined) {\n instance.setSelectedLines(selectedLines, { notify: false });\n }\n\n const slotPublish = instance.setSlotCoordinator(slotCoordinator);\n let forceInlinePublish = false;\n if (slotCoordinator !== prevSlotCoordinator) {\n if (slotCoordinator == null || prevSlotCoordinator == null) {\n forceInlinePublish = true;\n }\n cachedDataRef.current.slotCoordinator = slotCoordinator;\n }\n\n if (shouldRender || slotPublish) {\n instance.render(true);\n }\n\n // FIXME(amadeus): This feels kinda bad and flakey with regards to how\n // other things are working... it makes me think that we should\n // re-architect the slotCoordinator a bit, and maybe DON'T make it an\n // undefineable thing...\n if (slotPublish && slotCoordinator == null) {\n slotContentStore.publish(undefined);\n }\n\n if (forceInlinePublish) {\n forceUpdate({});\n }\n } finally {\n cachedDataRef.current.disableFlushSync = false;\n }\n });\n\n // Setup the ref handler\n useImperativeHandle(\n ref,\n (): CodeViewHandle<LAnnotation> => ({\n addItems(items) {\n const { controlled, instance } = cachedDataRef.current;\n assertUncontrolledCodeViewAction(controlled, 'addItems');\n if (instance == null) {\n console.error(\n 'CodeView.addItems: no valid instance to append items with',\n items\n );\n } else {\n instance.addItems(items);\n }\n },\n getItem(id) {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error('CodeView.getItem: no valid instance exists', id);\n return undefined;\n } else {\n return instance.getItem(id);\n }\n },\n updateItem(item) {\n const { controlled, instance } = cachedDataRef.current;\n assertUncontrolledCodeViewAction(controlled, 'updateItem');\n if (instance == null) {\n console.error(\n 'CodeView.updateItem: no valid instance to update item with',\n item\n );\n return false;\n }\n\n return instance.updateItem(item);\n },\n updateItemId(oldId, newId) {\n const { controlled, instance } = cachedDataRef.current;\n assertUncontrolledCodeViewAction(controlled, 'updateItemId');\n if (instance == null) {\n console.error(\n 'CodeView.updateItemId: no valid instance to update item id with',\n oldId,\n newId\n );\n return false;\n }\n\n return instance.updateItemId(oldId, newId);\n },\n scrollTo(target) {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error(\n 'CodeView.scrollTo: no valid instance to scroll with',\n target\n );\n } else {\n instance.scrollTo(target);\n }\n },\n setSelectedLines(selection) {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error(\n 'CodeView.setSelectedLines: no valid instance to update selection with',\n selection\n );\n } else {\n instance.setSelectedLines(selection, { notify: false });\n emitSelectedLinesChange(selection);\n }\n },\n getSelectedLines() {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error('CodeView.getSelectedLines: no valid instance exists');\n return null;\n } else {\n return instance.getSelectedLines();\n }\n },\n clearSelectedLines() {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error(\n 'CodeView.clearSelectedLines: no valid instance to update selection with'\n );\n } else {\n instance.clearSelectedLines({ notify: false });\n emitSelectedLinesChange(null);\n }\n },\n getEditor(id) {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error('CodeView.getEditor: no valid instance exists', id);\n return undefined;\n }\n\n return instance.getEditor(id);\n },\n getInstance() {\n return cachedDataRef.current.instance;\n },\n }),\n [emitSelectedLinesChange]\n );\n\n return (\n <>\n <div ref={nodeRef} className={className} style={style} />\n {(hasRenderers || hasCodeViewHeader || hasCodeViewFooter) && (\n <SlotPortals<LAnnotation>\n managedContentStore={slotContentStore}\n renderCustomHeader={renderCustomHeader}\n renderHeaderPrefix={renderHeaderPrefix}\n renderHeaderFilenameSuffix={renderHeaderFilenameSuffix}\n renderHeaderMetadata={renderHeaderMetadata}\n renderAnnotation={renderAnnotation}\n renderGutterUtility={renderGutterUtility}\n renderCodeViewHeader={renderCodeViewHeader}\n renderCodeViewFooter={renderCodeViewFooter}\n />\n )}\n </>\n );\n}\n\n// React was a mistake\nexport const CodeView = forwardRef(CodeViewInner) as CodeViewComponent;\n\nfunction isAppendOnlyItemUpdate<LAnnotation>(\n previousItems: readonly CodeViewItem<LAnnotation>[] | undefined,\n nextItems: readonly CodeViewItem<LAnnotation>[]\n): previousItems is readonly CodeViewItem<LAnnotation>[] {\n if (previousItems == null || nextItems.length <= previousItems.length) {\n return false;\n }\n\n if (previousItems.length === 0) {\n return true;\n }\n\n for (let index = 0; index < previousItems.length; index++) {\n if (nextItems[index] !== previousItems[index]) {\n return false;\n }\n }\n\n return true;\n}\n\nfunction areItemListsEqual<LAnnotation>(\n previousItems: readonly CodeViewItem<LAnnotation>[] | undefined,\n nextItems: readonly CodeViewItem<LAnnotation>[]\n): boolean {\n if (previousItems == null || previousItems.length !== nextItems.length) {\n return false;\n }\n\n for (let index = 0; index < previousItems.length; index++) {\n if (previousItems[index] !== nextItems[index]) {\n return false;\n }\n }\n\n return true;\n}\n\nfunction assertUncontrolledCodeViewAction(\n controlled: boolean,\n action: string\n): void {\n if (!controlled) {\n return;\n }\n\n throw new Error(\n `CodeView.${action} cannot be used when CodeView is controlled. Use initialItems for imperative item updates.`\n );\n}\n\nfunction createSlotContentStore<\n LAnnotation,\n>(): ManagedContentStore<LAnnotation> {\n let snapshot: CodeViewSlotSnapshot<LAnnotation> | undefined;\n const listeners = new Set<() => void>();\n\n return {\n getSnapshot() {\n return snapshot;\n },\n publish(nextSnapshot) {\n if (areManagedSnapshotsEqual(snapshot, nextSnapshot)) {\n return;\n }\n\n snapshot = nextSnapshot;\n for (const listener of listeners) {\n listener();\n }\n },\n subscribe(listener) {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n };\n}\n\ninterface CreateManagedCodeViewOptionsProps<LAnnotation> {\n options: CodeViewReactOptions<LAnnotation> | undefined;\n hasCustomHeader: boolean;\n hasGutterRenderer: boolean;\n hasCodeViewHeader: boolean;\n hasCodeViewFooter: boolean;\n onSelectedLinesChange?(selection: CodeViewLineSelection | null): void;\n controlledSelection: boolean;\n createEditor: CodeViewOptions<LAnnotation>['createEditor'];\n onItemEditChange: CodeViewOptions<LAnnotation>['onItemEditChange'];\n onItemEditComplete: CodeViewOptions<LAnnotation>['onItemEditComplete'];\n}\n\nfunction createManagedCodeViewOptions<LAnnotation>({\n options,\n hasCustomHeader,\n hasGutterRenderer,\n hasCodeViewHeader,\n hasCodeViewFooter,\n onSelectedLinesChange,\n controlledSelection,\n createEditor,\n onItemEditChange,\n onItemEditComplete,\n}: CreateManagedCodeViewOptionsProps<LAnnotation>): CodeViewOptions<LAnnotation> {\n const managedOptions: CodeViewOptions<LAnnotation> = {\n ...options,\n controlledSelection,\n onSelectedLinesChange,\n createEditor,\n };\n\n // Prop-level editor callbacks win over their options-object counterparts,\n // but an absent prop must not clobber a value provided via `options`.\n if (onItemEditChange != null) {\n managedOptions.onItemEditChange = onItemEditChange;\n }\n if (onItemEditComplete != null) {\n managedOptions.onItemEditComplete = onItemEditComplete;\n }\n\n // The imperative CodeView adapters use this callback's presence to\n // switch file and diff headers into custom-slot mode. React portals\n // provide the actual header content, so this placeholder\n // intentionally returns nothing.\n if (hasCustomHeader) {\n managedOptions.renderCustomHeader = noopRender;\n }\n\n // The imperative CodeView adapters use this callback's presence to\n // create the custom gutter utility slot. React portals provide the\n // actual content, so this placeholder intentionally returns nothing.\n if (hasGutterRenderer) {\n managedOptions.renderGutterUtility = noopRender;\n }\n\n // The imperative CodeView adapters use these callbacks' presence to create the\n // header/footer host elements. React portals the actual content into them (via\n // the slot snapshot), so these placeholders intentionally return nothing.\n if (hasCodeViewHeader) {\n managedOptions.renderCodeViewHeader = noopRender;\n }\n if (hasCodeViewFooter) {\n managedOptions.renderCodeViewFooter = noopRender;\n }\n\n return managedOptions;\n}\n\ninterface RenderCodeViewItemChildrenProps<LAnnotation> {\n renderedItem: CodeViewRenderedItem<LAnnotation>;\n renderCustomHeader: CodeViewBaseProps<LAnnotation>['renderCustomHeader'];\n renderHeaderPrefix: CodeViewBaseProps<LAnnotation>['renderHeaderPrefix'];\n renderHeaderFilenameSuffix: CodeViewBaseProps<LAnnotation>['renderHeaderFilenameSuffix'];\n renderHeaderMetadata: CodeViewBaseProps<LAnnotation>['renderHeaderMetadata'];\n renderAnnotation: CodeViewBaseProps<LAnnotation>['renderAnnotation'];\n renderGutterUtility: CodeViewBaseProps<LAnnotation>['renderGutterUtility'];\n}\n\ninterface SlotPortalsProps<LAnnotation> {\n managedContentStore: ManagedContentStore<LAnnotation>;\n renderCustomHeader: CodeViewBaseProps<LAnnotation>['renderCustomHeader'];\n renderHeaderPrefix: CodeViewBaseProps<LAnnotation>['renderHeaderPrefix'];\n renderHeaderFilenameSuffix: CodeViewBaseProps<LAnnotation>['renderHeaderFilenameSuffix'];\n renderHeaderMetadata: CodeViewBaseProps<LAnnotation>['renderHeaderMetadata'];\n renderAnnotation: CodeViewBaseProps<LAnnotation>['renderAnnotation'];\n renderGutterUtility: CodeViewBaseProps<LAnnotation>['renderGutterUtility'];\n renderCodeViewHeader: CodeViewBaseProps<LAnnotation>['renderCodeViewHeader'];\n renderCodeViewFooter: CodeViewBaseProps<LAnnotation>['renderCodeViewFooter'];\n}\n\nconst SlotPortals = memo(function SlotPortals<LAnnotation>({\n managedContentStore,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderAnnotation,\n renderGutterUtility,\n renderCodeViewHeader,\n renderCodeViewFooter,\n}: SlotPortalsProps<LAnnotation>) {\n 'use no memo';\n const subscribe = useStableCallback((listener: () => void) =>\n managedContentStore.subscribe(listener)\n );\n const getSnapshot = useStableCallback(() =>\n managedContentStore.getSnapshot()\n );\n const snapshot = useSyncExternalStore<\n CodeViewSlotSnapshot<LAnnotation> | undefined\n >(subscribe, getSnapshot, getSnapshot);\n let itemKeys = '';\n for (const item of snapshot?.items ?? []) {\n itemKeys += `${item.id}:${item.version}:${item.type}`;\n }\n // NOTE(amadeus): And just like that, the react compiler do be failing us\n // lol... we need to pre-render everything for items, headers and footers to\n // not trigger needless renders while scrolling\n const renderedItems = useMemo(\n () => {\n return snapshot?.items?.map((renderedItem) =>\n createPortal(\n renderCodeViewItemChildren({\n renderedItem,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderAnnotation,\n renderGutterUtility,\n }),\n renderedItem.element,\n renderedItem.id\n )\n );\n },\n // oxlint-disable-next-line react-hooks/exhaustive-deps\n [\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderAnnotation,\n renderGutterUtility,\n itemKeys,\n ]\n );\n const renderedHeader = useMemo(() => {\n return renderCodeViewHeader != null && snapshot?.header != null\n ? createPortal(renderCodeViewHeader(), snapshot.header)\n : null;\n }, [renderCodeViewHeader, snapshot?.header]);\n const renderedFooter = useMemo(() => {\n return renderCodeViewFooter != null && snapshot?.footer != null\n ? createPortal(renderCodeViewFooter(), snapshot.footer)\n : null;\n }, [renderCodeViewFooter, snapshot?.footer]);\n return (\n <>\n {renderedItems}\n {renderedHeader}\n {renderedFooter}\n </>\n );\n}) as SlotPortalsComponent;\n\nfunction renderCodeViewItemChildren<LAnnotation>({\n renderedItem,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderAnnotation,\n renderGutterUtility,\n}: RenderCodeViewItemChildrenProps<LAnnotation>): ReactNode {\n if (renderedItem.type === 'diff') {\n const { item, instance } = renderedItem;\n return renderDiffChildren({\n fileDiff: item.fileDiff,\n renderCustomHeader:\n renderCustomHeader != null ? () => renderCustomHeader(item) : undefined,\n renderHeaderPrefix:\n renderHeaderPrefix != null ? () => renderHeaderPrefix(item) : undefined,\n renderHeaderFilenameSuffix:\n renderHeaderFilenameSuffix != null\n ? () => renderHeaderFilenameSuffix(item)\n : undefined,\n renderHeaderMetadata:\n renderHeaderMetadata != null\n ? () => renderHeaderMetadata(item)\n : undefined,\n renderAnnotation:\n renderAnnotation != null\n ? (annotation) => renderAnnotation(annotation, item)\n : undefined,\n lineAnnotations: item.annotations,\n renderGutterUtility:\n renderGutterUtility != null\n ? (getHoveredLine) => renderGutterUtility(getHoveredLine, item)\n : undefined,\n getHoveredLine: instance.getHoveredLine,\n });\n } else {\n const { item, instance } = renderedItem;\n return renderFileChildren({\n file: item.file,\n renderCustomHeader:\n renderCustomHeader != null ? () => renderCustomHeader(item) : undefined,\n renderHeaderPrefix:\n renderHeaderPrefix != null ? () => renderHeaderPrefix(item) : undefined,\n renderHeaderFilenameSuffix:\n renderHeaderFilenameSuffix != null\n ? () => renderHeaderFilenameSuffix(item)\n : undefined,\n renderHeaderMetadata:\n renderHeaderMetadata != null\n ? () => renderHeaderMetadata(item)\n : undefined,\n renderAnnotation:\n renderAnnotation != null\n ? (annotation) => renderAnnotation(annotation, item)\n : undefined,\n lineAnnotations: item.annotations,\n renderGutterUtility:\n renderGutterUtility != null\n ? (getHoveredLine) => renderGutterUtility(getHoveredLine, item)\n : undefined,\n getHoveredLine: instance.getHoveredLine,\n });\n }\n}\n\nfunction noopRender() {\n return undefined;\n}\n"],"mappings":";;;;;;;;;;;;;AA4CA,MAAM,4BACJ,OAAO,WAAW,cAAc,YAAY;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I,IAC/B,KAAA;GACN,kBACE,oBAAoB,QACf,eAAe,iBAAiB,YAAY,IAAI,IACjD,KAAA;GACN,iBAAiB,KAAK;GACtB,qBACE,uBAAuB,QAClB,mBAAmB,oBAAoB,gBAAgB,IAAI,IAC5D,KAAA;GACN,gBAAgB,SAAS;EAC3B,CAAC;CACH;AACF;AAEA,SAAS,aAAa,CAEtB"}
1
+ {"version":3,"file":"CodeView.js","names":["CodeViewClass"],"sources":["../../src/react/CodeView.tsx"],"sourcesContent":["'use client';\n\nimport {\n type CSSProperties,\n forwardRef,\n memo,\n type ReactNode,\n type Ref,\n useContext,\n useEffect,\n useImperativeHandle,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n useSyncExternalStore,\n} from 'react';\nimport { createPortal, flushSync } from 'react-dom';\n\nimport type { EditorOptions } from '../edit';\nimport {\n areOptionsEqual,\n CodeView as CodeViewClass,\n type CodeViewCoordinator,\n type CodeViewCreateEditorOptions,\n type CodeViewItem,\n type CodeViewLineSelection,\n type CodeViewOptions,\n type CodeViewRenderedItem,\n type CodeViewScrollTarget,\n type CodeViewSlotSnapshot,\n type DiffLineAnnotation,\n type DiffsEditor,\n type FileContents,\n type GetHoveredLineResult,\n type LineAnnotation,\n} from '../index';\nimport { areManagedSnapshotsEqual } from '../utils/areManagedSnapshotsEqual';\nimport { useCreateEditor } from './EditContext';\nimport { renderDiffChildren } from './utils/renderDiffChildren';\nimport { renderFileChildren } from './utils/renderFileChildren';\nimport { useStableCallback } from './utils/useStableCallback';\nimport { WorkerPoolContext } from './WorkerPoolContext';\n\nconst useIsomorphicLayoutEffect =\n typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\ntype CodeViewGutterUtilityGetter =\n | (() => GetHoveredLineResult<'file'> | undefined)\n | (() => GetHoveredLineResult<'diff'> | undefined);\n\nexport type CodeViewReactOptions<LAnnotation = undefined> = Omit<\n CodeViewOptions<LAnnotation>,\n 'controlledSelection' | 'createEditor' | 'onSelectedLinesChange'\n>;\n\ninterface CodeViewBaseProps<LAnnotation> {\n options?: CodeViewReactOptions<LAnnotation>;\n /**\n * Creation-time options passed to the nearest EditProvider factory.\n * CodeView supplies its item-specific change callback.\n */\n editorOptions?: Omit<EditorOptions<LAnnotation>, 'onChange'>;\n className?: string;\n style?: CSSProperties;\n containerRef?: Ref<HTMLDivElement>;\n disableWorkerPool?: boolean;\n selectedLines?: CodeViewLineSelection | null;\n onSelectedLinesChange?(selection: CodeViewLineSelection | null): void;\n onScroll?(scrollTop: number, viewer: CodeViewClass<LAnnotation>): void;\n /** Render a non-virtualized node at the very start of the scroll content,\n * before the first item. Always rendered; scrolls with the content. */\n renderCodeViewHeader?(): ReactNode;\n /** Render a non-virtualized node at the very end of the scroll content, after\n * the last item. Always rendered; scrolls with the content. */\n renderCodeViewFooter?(): ReactNode;\n /** Called with the owning item on every edited-document change. */\n onItemEditChange?(\n item: CodeViewItem<LAnnotation>,\n file: FileContents,\n lineAnnotations?:\n | LineAnnotation<LAnnotation>[]\n | DiffLineAnnotation<LAnnotation>[]\n ): void;\n /**\n * Called once with the final contents when an item's edit session ends\n * (edit turned off, item removed or collapsed). Not called for sessions\n * that produced no changes. Committing is user-space: make one combined\n * item write carrying the new file/fileDiff (with a fresh `cacheKey`,\n * since the contents changed) along with `edit: false`.\n */\n onItemEditComplete?(\n item: CodeViewItem<LAnnotation>,\n file: FileContents,\n lineAnnotations?:\n | LineAnnotation<LAnnotation>[]\n | DiffLineAnnotation<LAnnotation>[]\n ): void;\n renderCustomHeader?(item: CodeViewItem<LAnnotation>): ReactNode;\n renderHeaderPrefix?(item: CodeViewItem<LAnnotation>): ReactNode;\n renderHeaderFilenameSuffix?(item: CodeViewItem<LAnnotation>): ReactNode;\n renderHeaderMetadata?(item: CodeViewItem<LAnnotation>): ReactNode;\n renderAnnotation?(\n annotation: LineAnnotation<LAnnotation> | DiffLineAnnotation<LAnnotation>,\n item: CodeViewItem<LAnnotation>\n ): ReactNode;\n renderGutterUtility?(\n getHoveredLine: CodeViewGutterUtilityGetter,\n item: CodeViewItem<LAnnotation>\n ): ReactNode;\n}\n\nexport interface ControlledCodeViewProps<\n LAnnotation,\n> extends CodeViewBaseProps<LAnnotation> {\n items: readonly CodeViewItem<LAnnotation>[];\n initialItems?: never;\n}\n\nexport interface UncontrolledCodeViewProps<\n LAnnotation,\n> extends CodeViewBaseProps<LAnnotation> {\n // Seeds the imperative CodeView instance once. Later item changes should go\n // through the ref API instead of being reconciled from React props.\n initialItems?: readonly CodeViewItem<LAnnotation>[];\n items?: never;\n}\n\nexport type CodeViewProps<LAnnotation = undefined> =\n | ControlledCodeViewProps<LAnnotation>\n | UncontrolledCodeViewProps<LAnnotation>;\n\nexport interface CodeViewHandle<LAnnotation> {\n addItems(items: readonly CodeViewItem<LAnnotation>[]): void;\n getItem(id: string): CodeViewItem<LAnnotation> | undefined;\n removeItem(id: string): boolean;\n updateItem(item: CodeViewItem<LAnnotation>): boolean;\n updateItemId(oldId: string, newId: string): boolean;\n scrollTo(target: CodeViewScrollTarget): void;\n setSelectedLines(selection: CodeViewLineSelection | null): void;\n getSelectedLines(): CodeViewLineSelection | null;\n clearSelectedLines(): void;\n getEditor(id: string): DiffsEditor<LAnnotation> | undefined;\n getInstance(): CodeViewClass<LAnnotation> | undefined;\n}\n\ntype CodeViewComponent = <LAnnotation = undefined>(\n props: CodeViewProps<LAnnotation> & {\n ref?: React.Ref<CodeViewHandle<LAnnotation>>;\n }\n) => React.JSX.Element;\n\ntype SlotPortalsComponent = <LAnnotation = undefined>(\n props: SlotPortalsProps<LAnnotation>\n) => React.JSX.Element;\n\ninterface ManagedContentStore<LAnnotation> {\n getSnapshot(): CodeViewSlotSnapshot<LAnnotation> | undefined;\n publish(snapshot: CodeViewSlotSnapshot<LAnnotation> | undefined): void;\n subscribe(listener: () => void): () => void;\n}\n\ninterface CachedDataRef<LAnnotation> {\n instance: CodeViewClass<LAnnotation> | undefined;\n items: readonly CodeViewItem<LAnnotation>[] | undefined;\n controlled: boolean;\n managedOptions: CodeViewOptions<LAnnotation> | undefined;\n disableFlushSync: boolean;\n slotCoordinator: CodeViewCoordinator<LAnnotation> | undefined;\n}\n\nfunction createDefaultCache<LAnnotation>(\n controlled: boolean\n): CachedDataRef<LAnnotation> {\n return {\n instance: undefined,\n items: undefined,\n controlled,\n managedOptions: undefined,\n disableFlushSync: false,\n slotCoordinator: undefined,\n };\n}\n\nfunction CodeViewInner<LAnnotation = undefined>(\n props: CodeViewProps<LAnnotation>,\n ref: React.ForwardedRef<CodeViewHandle<LAnnotation>>\n): React.JSX.Element {\n const {\n className,\n containerRef,\n disableWorkerPool = false,\n editorOptions,\n initialItems,\n items: controlledItems,\n onItemEditChange,\n onItemEditComplete,\n onScroll,\n onSelectedLinesChange,\n options,\n renderAnnotation,\n renderCodeViewFooter,\n renderCodeViewHeader,\n renderCustomHeader,\n renderGutterUtility,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderHeaderPrefix,\n selectedLines,\n style,\n } = props;\n const controlled = controlledItems !== undefined;\n const contextCreateEditor = useCreateEditor<LAnnotation>();\n const poolManager = useContext(WorkerPoolContext);\n const cachedDataRef = useRef<CachedDataRef<LAnnotation>>(\n createDefaultCache<LAnnotation>(controlled)\n );\n const hasCustomHeader = renderCustomHeader != null;\n const hasAnnotationRenderer = renderAnnotation != null;\n const hasGutterRenderer = renderGutterUtility != null;\n const hasHeaderRenderers =\n hasCustomHeader ||\n renderHeaderPrefix != null ||\n renderHeaderFilenameSuffix != null ||\n renderHeaderMetadata != null;\n const hasRenderers =\n hasHeaderRenderers || hasAnnotationRenderer || hasGutterRenderer;\n const hasCodeViewHeader = renderCodeViewHeader != null;\n const hasCodeViewFooter = renderCodeViewFooter != null;\n const emitSelectedLinesChange = useStableCallback(\n (selection: CodeViewLineSelection | null) => {\n onSelectedLinesChange?.(selection);\n }\n );\n const controlledSelection = selectedLines !== undefined;\n\n // Keep the adapter stable so provider and editor-option changes affect the\n // next item edit session without forcing CodeView to reconcile active editors.\n const createEditor = useStableCallback(\n (\n options: CodeViewCreateEditorOptions<LAnnotation>\n ): DiffsEditor<LAnnotation> => {\n if (contextCreateEditor == null) {\n throw new Error('CodeView: EditContext is not attached');\n }\n\n const editor = contextCreateEditor({\n ...editorOptions,\n ...options,\n });\n if (editor == null) {\n throw new Error(\n 'CodeView: EditProvider.createEditor must return an editor instance'\n );\n }\n return editor;\n }\n );\n const emitItemEditChange = useStableCallback(\n (\n item: CodeViewItem<LAnnotation>,\n file: FileContents,\n lineAnnotations?:\n | LineAnnotation<LAnnotation>[]\n | DiffLineAnnotation<LAnnotation>[]\n ) => {\n onItemEditChange?.(item, file, lineAnnotations);\n }\n );\n const emitItemEditComplete = useStableCallback(\n (\n item: CodeViewItem<LAnnotation>,\n file: FileContents,\n lineAnnotations?:\n | LineAnnotation<LAnnotation>[]\n | DiffLineAnnotation<LAnnotation>[]\n ) => {\n onItemEditComplete?.(item, file, lineAnnotations);\n }\n );\n\n const managedOptions = useMemo(\n () =>\n createManagedCodeViewOptions({\n options,\n hasCustomHeader,\n hasGutterRenderer,\n hasCodeViewHeader,\n hasCodeViewFooter,\n onSelectedLinesChange:\n onSelectedLinesChange != null ? emitSelectedLinesChange : undefined,\n controlledSelection,\n createEditor: contextCreateEditor != null ? createEditor : undefined,\n onItemEditChange:\n onItemEditChange != null ? emitItemEditChange : undefined,\n onItemEditComplete:\n onItemEditComplete != null ? emitItemEditComplete : undefined,\n }),\n [\n contextCreateEditor,\n controlledSelection,\n createEditor,\n emitItemEditChange,\n emitItemEditComplete,\n emitSelectedLinesChange,\n hasCodeViewFooter,\n hasCodeViewHeader,\n hasCustomHeader,\n hasGutterRenderer,\n onItemEditChange,\n onItemEditComplete,\n onSelectedLinesChange,\n options,\n ]\n );\n\n const [slotContentStore] = useState<ManagedContentStore<LAnnotation>>(() =>\n createSlotContentStore()\n );\n const [, forceUpdate] = useState<unknown>({});\n\n const nodeRef = useStableCallback((node: HTMLDivElement | null) => {\n // If we have a pre-existing instance and there's no node or the node being\n // passed in is NOT the same as before, then we need to clean up and\n // garbage collect the old instance\n if (\n cachedDataRef.current.instance != null &&\n (node == null ||\n node !== cachedDataRef.current.instance.getContainerElement())\n ) {\n cachedDataRef.current.instance.cleanUp();\n slotContentStore.publish(undefined);\n cachedDataRef.current = createDefaultCache<LAnnotation>(controlled);\n }\n\n // If our node matches the existing node then we should not attempt to\n // setup. This is a case that should never be possible to hit, but just in\n // case, lets make sure we don't re-setup an instance that is already setup\n // properly\n if (\n node != null &&\n node !== cachedDataRef.current.instance?.getContainerElement()\n ) {\n cachedDataRef.current.instance = new CodeViewClass<LAnnotation>(\n managedOptions,\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n cachedDataRef.current.instance.setup(node);\n }\n\n if (typeof containerRef === 'function') {\n containerRef(node);\n } else if (containerRef != null) {\n containerRef.current = node;\n }\n });\n\n const onSnapshotChange = useStableCallback(\n (snapshot: CodeViewSlotSnapshot<LAnnotation> | undefined) => {\n if (cachedDataRef.current.disableFlushSync) {\n slotContentStore.publish(snapshot);\n } else {\n flushSync(() => {\n slotContentStore.publish(snapshot);\n });\n }\n }\n );\n\n const slotCoordinator: CodeViewCoordinator<LAnnotation> | undefined =\n useMemo(() => {\n // A coordinator is needed whenever React portals anything — per-item\n // slots and codeview header and footer\n if (\n !hasHeaderRenderers &&\n !hasAnnotationRenderer &&\n !hasGutterRenderer &&\n !hasCodeViewHeader &&\n !hasCodeViewFooter\n ) {\n return undefined;\n } else {\n return {\n hasHeaderRenderers,\n hasAnnotationRenderer,\n hasGutterRenderer,\n onSnapshotChange,\n };\n }\n }, [\n onSnapshotChange,\n hasAnnotationRenderer,\n hasGutterRenderer,\n hasHeaderRenderers,\n hasCodeViewHeader,\n hasCodeViewFooter,\n ]);\n\n useIsomorphicLayoutEffect(() => {\n return onScroll != null\n ? cachedDataRef.current.instance?.subscribeToScroll(onScroll)\n : undefined;\n });\n\n useIsomorphicLayoutEffect(() => {\n const {\n instance,\n controlled: prevControlled,\n items: prevItems,\n managedOptions: prevManagedOptions,\n slotCoordinator: prevSlotCoordinator,\n } = cachedDataRef.current;\n if (instance == null) {\n return;\n }\n\n try {\n cachedDataRef.current.disableFlushSync = true;\n let shouldRender = false;\n\n if (!areOptionsEqual(managedOptions, prevManagedOptions)) {\n cachedDataRef.current.managedOptions = managedOptions;\n instance.setOptions(managedOptions);\n shouldRender = true;\n }\n\n if (prevControlled !== controlled) {\n console.error(\n 'CodeView: cannot switch between controlled and uncontrolled modes. Remount with a new key instead.'\n );\n return;\n }\n\n if (controlled) {\n if (controlledItems !== prevItems) {\n if (areItemListsEqual(prevItems, controlledItems)) {\n cachedDataRef.current.items = controlledItems;\n } else if (isAppendOnlyItemUpdate(prevItems, controlledItems)) {\n cachedDataRef.current.items = controlledItems;\n instance.addItems(controlledItems.slice(prevItems.length));\n } else {\n cachedDataRef.current.items = controlledItems;\n instance.setItems(controlledItems);\n shouldRender = true;\n }\n }\n }\n // If uncontrolled, we should only ever set items once, and just depend\n // on imperative instance changes going forward\n else if (prevItems == null) {\n const seedItems = initialItems ?? [];\n cachedDataRef.current.items = seedItems;\n if (seedItems.length > 0) {\n instance.setItems(seedItems);\n shouldRender = true;\n }\n }\n\n if (selectedLines !== undefined) {\n instance.setSelectedLines(selectedLines, { notify: false });\n }\n\n const slotPublish = instance.setSlotCoordinator(slotCoordinator);\n let forceInlinePublish = false;\n if (slotCoordinator !== prevSlotCoordinator) {\n if (slotCoordinator == null || prevSlotCoordinator == null) {\n forceInlinePublish = true;\n }\n cachedDataRef.current.slotCoordinator = slotCoordinator;\n }\n\n if (shouldRender || slotPublish) {\n instance.render(true);\n }\n\n // FIXME(amadeus): This feels kinda bad and flakey with regards to how\n // other things are working... it makes me think that we should\n // re-architect the slotCoordinator a bit, and maybe DON'T make it an\n // undefineable thing...\n if (slotPublish && slotCoordinator == null) {\n slotContentStore.publish(undefined);\n }\n\n if (forceInlinePublish) {\n forceUpdate({});\n }\n } finally {\n cachedDataRef.current.disableFlushSync = false;\n }\n });\n\n // Setup the ref handler\n useImperativeHandle(\n ref,\n (): CodeViewHandle<LAnnotation> => ({\n addItems(items) {\n const { controlled, instance } = cachedDataRef.current;\n assertUncontrolledCodeViewAction(controlled, 'addItems');\n if (instance == null) {\n console.error(\n 'CodeView.addItems: no valid instance to append items with',\n items\n );\n } else {\n instance.addItems(items);\n }\n },\n getItem(id) {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error('CodeView.getItem: no valid instance exists', id);\n return undefined;\n } else {\n return instance.getItem(id);\n }\n },\n removeItem(id) {\n const { controlled, instance } = cachedDataRef.current;\n assertUncontrolledCodeViewAction(controlled, 'removeItem');\n if (instance == null) {\n console.error(\n 'CodeView.removeItem: no valid instance to remove item from',\n id\n );\n return false;\n }\n\n return instance.removeItem(id);\n },\n updateItem(item) {\n const { controlled, instance } = cachedDataRef.current;\n assertUncontrolledCodeViewAction(controlled, 'updateItem');\n if (instance == null) {\n console.error(\n 'CodeView.updateItem: no valid instance to update item with',\n item\n );\n return false;\n }\n\n return instance.updateItem(item);\n },\n updateItemId(oldId, newId) {\n const { controlled, instance } = cachedDataRef.current;\n assertUncontrolledCodeViewAction(controlled, 'updateItemId');\n if (instance == null) {\n console.error(\n 'CodeView.updateItemId: no valid instance to update item id with',\n oldId,\n newId\n );\n return false;\n }\n\n return instance.updateItemId(oldId, newId);\n },\n scrollTo(target) {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error(\n 'CodeView.scrollTo: no valid instance to scroll with',\n target\n );\n } else {\n instance.scrollTo(target);\n }\n },\n setSelectedLines(selection) {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error(\n 'CodeView.setSelectedLines: no valid instance to update selection with',\n selection\n );\n } else {\n instance.setSelectedLines(selection, { notify: false });\n emitSelectedLinesChange(selection);\n }\n },\n getSelectedLines() {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error('CodeView.getSelectedLines: no valid instance exists');\n return null;\n } else {\n return instance.getSelectedLines();\n }\n },\n clearSelectedLines() {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error(\n 'CodeView.clearSelectedLines: no valid instance to update selection with'\n );\n } else {\n instance.clearSelectedLines({ notify: false });\n emitSelectedLinesChange(null);\n }\n },\n getEditor(id) {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error('CodeView.getEditor: no valid instance exists', id);\n return undefined;\n }\n\n return instance.getEditor(id);\n },\n getInstance() {\n return cachedDataRef.current.instance;\n },\n }),\n [emitSelectedLinesChange]\n );\n\n return (\n <>\n <div ref={nodeRef} className={className} style={style} />\n {(hasRenderers || hasCodeViewHeader || hasCodeViewFooter) && (\n <SlotPortals<LAnnotation>\n managedContentStore={slotContentStore}\n renderCustomHeader={renderCustomHeader}\n renderHeaderPrefix={renderHeaderPrefix}\n renderHeaderFilenameSuffix={renderHeaderFilenameSuffix}\n renderHeaderMetadata={renderHeaderMetadata}\n renderAnnotation={renderAnnotation}\n renderGutterUtility={renderGutterUtility}\n renderCodeViewHeader={renderCodeViewHeader}\n renderCodeViewFooter={renderCodeViewFooter}\n />\n )}\n </>\n );\n}\n\n// React was a mistake\nexport const CodeView = forwardRef(CodeViewInner) as CodeViewComponent;\n\nfunction isAppendOnlyItemUpdate<LAnnotation>(\n previousItems: readonly CodeViewItem<LAnnotation>[] | undefined,\n nextItems: readonly CodeViewItem<LAnnotation>[]\n): previousItems is readonly CodeViewItem<LAnnotation>[] {\n if (previousItems == null || nextItems.length <= previousItems.length) {\n return false;\n }\n\n if (previousItems.length === 0) {\n return true;\n }\n\n for (let index = 0; index < previousItems.length; index++) {\n if (nextItems[index] !== previousItems[index]) {\n return false;\n }\n }\n\n return true;\n}\n\nfunction areItemListsEqual<LAnnotation>(\n previousItems: readonly CodeViewItem<LAnnotation>[] | undefined,\n nextItems: readonly CodeViewItem<LAnnotation>[]\n): boolean {\n if (previousItems == null || previousItems.length !== nextItems.length) {\n return false;\n }\n\n for (let index = 0; index < previousItems.length; index++) {\n if (previousItems[index] !== nextItems[index]) {\n return false;\n }\n }\n\n return true;\n}\n\nfunction assertUncontrolledCodeViewAction(\n controlled: boolean,\n action: string\n): void {\n if (!controlled) {\n return;\n }\n\n throw new Error(\n `CodeView.${action} cannot be used when CodeView is controlled. Use initialItems for imperative item updates.`\n );\n}\n\nfunction createSlotContentStore<\n LAnnotation,\n>(): ManagedContentStore<LAnnotation> {\n let snapshot: CodeViewSlotSnapshot<LAnnotation> | undefined;\n const listeners = new Set<() => void>();\n\n return {\n getSnapshot() {\n return snapshot;\n },\n publish(nextSnapshot) {\n if (areManagedSnapshotsEqual(snapshot, nextSnapshot)) {\n return;\n }\n\n snapshot = nextSnapshot;\n for (const listener of listeners) {\n listener();\n }\n },\n subscribe(listener) {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n };\n}\n\ninterface CreateManagedCodeViewOptionsProps<LAnnotation> {\n options: CodeViewReactOptions<LAnnotation> | undefined;\n hasCustomHeader: boolean;\n hasGutterRenderer: boolean;\n hasCodeViewHeader: boolean;\n hasCodeViewFooter: boolean;\n onSelectedLinesChange?(selection: CodeViewLineSelection | null): void;\n controlledSelection: boolean;\n createEditor: CodeViewOptions<LAnnotation>['createEditor'];\n onItemEditChange: CodeViewOptions<LAnnotation>['onItemEditChange'];\n onItemEditComplete: CodeViewOptions<LAnnotation>['onItemEditComplete'];\n}\n\nfunction createManagedCodeViewOptions<LAnnotation>({\n options,\n hasCustomHeader,\n hasGutterRenderer,\n hasCodeViewHeader,\n hasCodeViewFooter,\n onSelectedLinesChange,\n controlledSelection,\n createEditor,\n onItemEditChange,\n onItemEditComplete,\n}: CreateManagedCodeViewOptionsProps<LAnnotation>): CodeViewOptions<LAnnotation> {\n const managedOptions: CodeViewOptions<LAnnotation> = {\n ...options,\n controlledSelection,\n onSelectedLinesChange,\n createEditor,\n };\n\n // Prop-level editor callbacks win over their options-object counterparts,\n // but an absent prop must not clobber a value provided via `options`.\n if (onItemEditChange != null) {\n managedOptions.onItemEditChange = onItemEditChange;\n }\n if (onItemEditComplete != null) {\n managedOptions.onItemEditComplete = onItemEditComplete;\n }\n\n // The imperative CodeView adapters use this callback's presence to\n // switch file and diff headers into custom-slot mode. React portals\n // provide the actual header content, so this placeholder\n // intentionally returns nothing.\n if (hasCustomHeader) {\n managedOptions.renderCustomHeader = noopRender;\n }\n\n // The imperative CodeView adapters use this callback's presence to\n // create the custom gutter utility slot. React portals provide the\n // actual content, so this placeholder intentionally returns nothing.\n if (hasGutterRenderer) {\n managedOptions.renderGutterUtility = noopRender;\n }\n\n // The imperative CodeView adapters use these callbacks' presence to create the\n // header/footer host elements. React portals the actual content into them (via\n // the slot snapshot), so these placeholders intentionally return nothing.\n if (hasCodeViewHeader) {\n managedOptions.renderCodeViewHeader = noopRender;\n }\n if (hasCodeViewFooter) {\n managedOptions.renderCodeViewFooter = noopRender;\n }\n\n return managedOptions;\n}\n\ninterface RenderCodeViewItemChildrenProps<LAnnotation> {\n renderedItem: CodeViewRenderedItem<LAnnotation>;\n renderCustomHeader: CodeViewBaseProps<LAnnotation>['renderCustomHeader'];\n renderHeaderPrefix: CodeViewBaseProps<LAnnotation>['renderHeaderPrefix'];\n renderHeaderFilenameSuffix: CodeViewBaseProps<LAnnotation>['renderHeaderFilenameSuffix'];\n renderHeaderMetadata: CodeViewBaseProps<LAnnotation>['renderHeaderMetadata'];\n renderAnnotation: CodeViewBaseProps<LAnnotation>['renderAnnotation'];\n renderGutterUtility: CodeViewBaseProps<LAnnotation>['renderGutterUtility'];\n}\n\ninterface SlotPortalsProps<LAnnotation> {\n managedContentStore: ManagedContentStore<LAnnotation>;\n renderCustomHeader: CodeViewBaseProps<LAnnotation>['renderCustomHeader'];\n renderHeaderPrefix: CodeViewBaseProps<LAnnotation>['renderHeaderPrefix'];\n renderHeaderFilenameSuffix: CodeViewBaseProps<LAnnotation>['renderHeaderFilenameSuffix'];\n renderHeaderMetadata: CodeViewBaseProps<LAnnotation>['renderHeaderMetadata'];\n renderAnnotation: CodeViewBaseProps<LAnnotation>['renderAnnotation'];\n renderGutterUtility: CodeViewBaseProps<LAnnotation>['renderGutterUtility'];\n renderCodeViewHeader: CodeViewBaseProps<LAnnotation>['renderCodeViewHeader'];\n renderCodeViewFooter: CodeViewBaseProps<LAnnotation>['renderCodeViewFooter'];\n}\n\nconst SlotPortals = memo(function SlotPortals<LAnnotation>({\n managedContentStore,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderAnnotation,\n renderGutterUtility,\n renderCodeViewHeader,\n renderCodeViewFooter,\n}: SlotPortalsProps<LAnnotation>) {\n 'use no memo';\n const subscribe = useStableCallback((listener: () => void) =>\n managedContentStore.subscribe(listener)\n );\n const getSnapshot = useStableCallback(() =>\n managedContentStore.getSnapshot()\n );\n const snapshot = useSyncExternalStore<\n CodeViewSlotSnapshot<LAnnotation> | undefined\n >(subscribe, getSnapshot, getSnapshot);\n let itemKeys = '';\n for (const item of snapshot?.items ?? []) {\n itemKeys += `${item.id}:${item.version}:${item.type}`;\n }\n // NOTE(amadeus): And just like that, the react compiler do be failing us\n // lol... we need to pre-render everything for items, headers and footers to\n // not trigger needless renders while scrolling\n const renderedItems = useMemo(\n () => {\n return snapshot?.items?.map((renderedItem) =>\n createPortal(\n renderCodeViewItemChildren({\n renderedItem,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderAnnotation,\n renderGutterUtility,\n }),\n renderedItem.element,\n renderedItem.id\n )\n );\n },\n // oxlint-disable-next-line react-hooks/exhaustive-deps\n [\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderAnnotation,\n renderGutterUtility,\n itemKeys,\n ]\n );\n const renderedHeader = useMemo(() => {\n return renderCodeViewHeader != null && snapshot?.header != null\n ? createPortal(renderCodeViewHeader(), snapshot.header)\n : null;\n }, [renderCodeViewHeader, snapshot?.header]);\n const renderedFooter = useMemo(() => {\n return renderCodeViewFooter != null && snapshot?.footer != null\n ? createPortal(renderCodeViewFooter(), snapshot.footer)\n : null;\n }, [renderCodeViewFooter, snapshot?.footer]);\n return (\n <>\n {renderedItems}\n {renderedHeader}\n {renderedFooter}\n </>\n );\n}) as SlotPortalsComponent;\n\nfunction renderCodeViewItemChildren<LAnnotation>({\n renderedItem,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderAnnotation,\n renderGutterUtility,\n}: RenderCodeViewItemChildrenProps<LAnnotation>): ReactNode {\n if (renderedItem.type === 'diff') {\n const { item, instance } = renderedItem;\n return renderDiffChildren({\n fileDiff: item.fileDiff,\n renderCustomHeader:\n renderCustomHeader != null ? () => renderCustomHeader(item) : undefined,\n renderHeaderPrefix:\n renderHeaderPrefix != null ? () => renderHeaderPrefix(item) : undefined,\n renderHeaderFilenameSuffix:\n renderHeaderFilenameSuffix != null\n ? () => renderHeaderFilenameSuffix(item)\n : undefined,\n renderHeaderMetadata:\n renderHeaderMetadata != null\n ? () => renderHeaderMetadata(item)\n : undefined,\n renderAnnotation:\n renderAnnotation != null\n ? (annotation) => renderAnnotation(annotation, item)\n : undefined,\n lineAnnotations: item.annotations,\n renderGutterUtility:\n renderGutterUtility != null\n ? (getHoveredLine) => renderGutterUtility(getHoveredLine, item)\n : undefined,\n getHoveredLine: instance.getHoveredLine,\n });\n } else {\n const { item, instance } = renderedItem;\n return renderFileChildren({\n file: item.file,\n renderCustomHeader:\n renderCustomHeader != null ? () => renderCustomHeader(item) : undefined,\n renderHeaderPrefix:\n renderHeaderPrefix != null ? () => renderHeaderPrefix(item) : undefined,\n renderHeaderFilenameSuffix:\n renderHeaderFilenameSuffix != null\n ? () => renderHeaderFilenameSuffix(item)\n : undefined,\n renderHeaderMetadata:\n renderHeaderMetadata != null\n ? () => renderHeaderMetadata(item)\n : undefined,\n renderAnnotation:\n renderAnnotation != null\n ? (annotation) => renderAnnotation(annotation, item)\n : undefined,\n lineAnnotations: item.annotations,\n renderGutterUtility:\n renderGutterUtility != null\n ? (getHoveredLine) => renderGutterUtility(getHoveredLine, item)\n : undefined,\n getHoveredLine: instance.getHoveredLine,\n });\n }\n}\n\nfunction noopRender() {\n return undefined;\n}\n"],"mappings":";;;;;;;;;;;;;AA4CA,MAAM,4BACJ,OAAO,WAAW,cAAc,YAAY;AA8H9C,SAAS,mBACP,YAC4B;CAC5B,OAAO;EACL,UAAU,KAAA;EACV,OAAO,KAAA;EACP;EACA,gBAAgB,KAAA;EAChB,kBAAkB;EAClB,iBAAiB,KAAA;CACnB;AACF;AAEA,SAAS,cACP,OACA,KACmB;CACnB,MAAM,EACJ,WACA,cACA,oBAAoB,OACpB,eACA,cACA,OAAO,iBACP,kBACA,oBACA,UACA,uBACA,SACA,kBACA,sBACA,sBACA,oBACA,qBACA,4BACA,sBACA,oBACA,eACA,UACE;CACJ,MAAM,aAAa,oBAAoB,KAAA;CACvC,MAAM,sBAAsB,gBAA6B;CACzD,MAAM,cAAc,WAAW,iBAAiB;CAChD,MAAM,gBAAgB,OACpB,mBAAgC,UAAU,CAC5C;CACA,MAAM,kBAAkB,sBAAsB;CAC9C,MAAM,wBAAwB,oBAAoB;CAClD,MAAM,oBAAoB,uBAAuB;CACjD,MAAM,qBACJ,mBACA,sBAAsB,QACtB,8BAA8B,QAC9B,wBAAwB;CAC1B,MAAM,eACJ,sBAAsB,yBAAyB;CACjD,MAAM,oBAAoB,wBAAwB;CAClD,MAAM,oBAAoB,wBAAwB;CAClD,MAAM,0BAA0B,mBAC7B,cAA4C;EAC3C,wBAAwB,SAAS;CACnC,CACF;CACA,MAAM,sBAAsB,kBAAkB,KAAA;CAI9C,MAAM,eAAe,mBAEjB,YAC6B;EAC7B,IAAI,uBAAuB,MACzB,MAAM,IAAI,MAAM,uCAAuC;EAGzD,MAAM,SAAS,oBAAoB;GACjC,GAAG;GACH,GAAG;EACL,CAAC;EACD,IAAI,UAAU,MACZ,MAAM,IAAI,MACR,oEACF;EAEF,OAA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KAAA;GACN,iBAAiB,KAAK;GACtB,qBACE,uBAAuB,QAClB,mBAAmB,oBAAoB,gBAAgB,IAAI,IAC5D,KAAA;GACN,gBAAgB,SAAS;EAC3B,CAAC;CACH,OAAO;EACL,MAAM,EAAE,MAAM,aAAa;EAC3B,OAAO,mBAAmB;GACxB,MAAM,KAAK;GACX,oBACE,sBAAsB,aAAa,mBAAmB,IAAI,IAAI,KAAA;GAChE,oBACE,sBAAsB,aAAa,mBAAmB,IAAI,IAAI,KAAA;GAChE,4BACE,8BAA8B,aACpB,2BAA2B,IAAI,IACrC,KAAA;GACN,sBACE,wBAAwB,aACd,qBAAqB,IAAI,IAC/B,KAAA;GACN,kBACE,oBAAoB,QACf,eAAe,iBAAiB,YAAY,IAAI,IACjD,KAAA;GACN,iBAAiB,KAAK;GACtB,qBACE,uBAAuB,QAClB,mBAAmB,oBAAoB,gBAAgB,IAAI,IAC5D,KAAA;GACN,gBAAgB,SAAS;EAC3B,CAAC;CACH;AACF;AAEA,SAAS,aAAa,CAEtB"}
@@ -10,7 +10,7 @@ function areRenderedItemsEqual(previous, next) {
10
10
  for (let index = 0; index < previous.length; index++) {
11
11
  const previousItem = previous[index];
12
12
  const nextItem = next[index];
13
- if (previousItem == null || nextItem == null || previousItem.id !== nextItem.id || previousItem.type !== nextItem.type || previousItem.element !== nextItem.element || previousItem.version !== nextItem.version) return false;
13
+ if (previousItem == null || nextItem == null || previousItem.id !== nextItem.id || previousItem.type !== nextItem.type || previousItem.element !== nextItem.element || previousItem.instance !== nextItem.instance || previousItem.version !== nextItem.version) return false;
14
14
  }
15
15
  return true;
16
16
  }
@@ -1 +1 @@
1
- {"version":3,"file":"areManagedSnapshotsEqual.js","names":[],"sources":["../../src/utils/areManagedSnapshotsEqual.ts"],"sourcesContent":["import type {\n CodeViewRenderedItem,\n CodeViewSlotSnapshot,\n} from '../components/CodeView';\n\nexport function areManagedSnapshotsEqual<LAnnotation>(\n previous: CodeViewSlotSnapshot<LAnnotation> | undefined,\n next: CodeViewSlotSnapshot<LAnnotation> | undefined\n): boolean {\n if (previous == null || next == null) {\n return previous === next;\n }\n\n if (previous.header !== next.header || previous.footer !== next.footer) {\n return false;\n }\n\n return areRenderedItemsEqual(previous.items, next.items);\n}\n\nfunction areRenderedItemsEqual<LAnnotation>(\n previous: CodeViewRenderedItem<LAnnotation>[] | undefined,\n next: CodeViewRenderedItem<LAnnotation>[] | undefined\n): boolean {\n if (previous == null || next == null) {\n return previous === next;\n }\n\n if (previous.length !== next.length) {\n return false;\n }\n\n for (let index = 0; index < previous.length; index++) {\n const previousItem = previous[index];\n const nextItem = next[index];\n if (\n previousItem == null ||\n nextItem == null ||\n previousItem.id !== nextItem.id ||\n previousItem.type !== nextItem.type ||\n previousItem.element !== nextItem.element ||\n previousItem.version !== nextItem.version\n ) {\n return false;\n }\n }\n\n return true;\n}\n"],"mappings":";AAKA,SAAgB,yBACd,UACA,MACS;CACT,IAAI,YAAY,QAAQ,QAAQ,MAC9B,OAAO,aAAa;CAGtB,IAAI,SAAS,WAAW,KAAK,UAAU,SAAS,WAAW,KAAK,QAC9D,OAAO;CAGT,OAAO,sBAAsB,SAAS,OAAO,KAAK,KAAK;AACzD;AAEA,SAAS,sBACP,UACA,MACS;CACT,IAAI,YAAY,QAAQ,QAAQ,MAC9B,OAAO,aAAa;CAGtB,IAAI,SAAS,WAAW,KAAK,QAC3B,OAAO;CAGT,KAAK,IAAI,QAAQ,GAAG,QAAQ,SAAS,QAAQ,SAAS;EACpD,MAAM,eAAe,SAAS;EAC9B,MAAM,WAAW,KAAK;EACtB,IACE,gBAAgB,QAChB,YAAY,QACZ,aAAa,OAAO,SAAS,MAC7B,aAAa,SAAS,SAAS,QAC/B,aAAa,YAAY,SAAS,WAClC,aAAa,YAAY,SAAS,SAElC,OAAO;CAEX;CAEA,OAAO;AACT"}
1
+ {"version":3,"file":"areManagedSnapshotsEqual.js","names":[],"sources":["../../src/utils/areManagedSnapshotsEqual.ts"],"sourcesContent":["import type {\n CodeViewRenderedItem,\n CodeViewSlotSnapshot,\n} from '../components/CodeView';\n\nexport function areManagedSnapshotsEqual<LAnnotation>(\n previous: CodeViewSlotSnapshot<LAnnotation> | undefined,\n next: CodeViewSlotSnapshot<LAnnotation> | undefined\n): boolean {\n if (previous == null || next == null) {\n return previous === next;\n }\n\n if (previous.header !== next.header || previous.footer !== next.footer) {\n return false;\n }\n\n return areRenderedItemsEqual(previous.items, next.items);\n}\n\nfunction areRenderedItemsEqual<LAnnotation>(\n previous: CodeViewRenderedItem<LAnnotation>[] | undefined,\n next: CodeViewRenderedItem<LAnnotation>[] | undefined\n): boolean {\n if (previous == null || next == null) {\n return previous === next;\n }\n\n if (previous.length !== next.length) {\n return false;\n }\n\n for (let index = 0; index < previous.length; index++) {\n const previousItem = previous[index];\n const nextItem = next[index];\n if (\n previousItem == null ||\n nextItem == null ||\n previousItem.id !== nextItem.id ||\n previousItem.type !== nextItem.type ||\n previousItem.element !== nextItem.element ||\n previousItem.instance !== nextItem.instance ||\n previousItem.version !== nextItem.version\n ) {\n return false;\n }\n }\n\n return true;\n}\n"],"mappings":";AAKA,SAAgB,yBACd,UACA,MACS;CACT,IAAI,YAAY,QAAQ,QAAQ,MAC9B,OAAO,aAAa;CAGtB,IAAI,SAAS,WAAW,KAAK,UAAU,SAAS,WAAW,KAAK,QAC9D,OAAO;CAGT,OAAO,sBAAsB,SAAS,OAAO,KAAK,KAAK;AACzD;AAEA,SAAS,sBACP,UACA,MACS;CACT,IAAI,YAAY,QAAQ,QAAQ,MAC9B,OAAO,aAAa;CAGtB,IAAI,SAAS,WAAW,KAAK,QAC3B,OAAO;CAGT,KAAK,IAAI,QAAQ,GAAG,QAAQ,SAAS,QAAQ,SAAS;EACpD,MAAM,eAAe,SAAS;EAC9B,MAAM,WAAW,KAAK;EACtB,IACE,gBAAgB,QAChB,YAAY,QACZ,aAAa,OAAO,SAAS,MAC7B,aAAa,SAAS,SAAS,QAC/B,aAAa,YAAY,SAAS,WAClC,aAAa,aAAa,SAAS,YACnC,aAAa,YAAY,SAAS,SAElC,OAAO;CAEX;CAEA,OAAO;AACT"}