deck-plugin-sdk 1.2.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,19 @@
1
+ // GENERATED by sdk/gen-types.mjs from Deck's source — do not edit.
2
+ import { type RefObject } from "react";
3
+ import { monaco } from "../../core/monaco";
4
+ import { type DirtyRange } from "./hunks";
5
+ /**
6
+ * The peek, for the editor in `edRef` showing `path` with the gutter's `ranges`. Returns what to
7
+ * render (a portal into the overlay), or null while closed.
8
+ *
9
+ * `clean` is whether the editor holds what is on disk: the changes are git's, read from disk, so
10
+ * their line numbers only fit the buffer when it has no unsaved edits. Staging and reverting wait
11
+ * for a save otherwise. `readBase` gives the text a change is against: the index's copy of the
12
+ * file for a change in the working tree, HEAD's for a staged one.
13
+ */
14
+ export declare function useDiffPeek(edRef: RefObject<monaco.editor.IStandaloneCodeEditor | null>, path: string, ranges: DirtyRange[] | undefined, opts: {
15
+ clean: boolean;
16
+ onStage: (r: DirtyRange) => Promise<void>;
17
+ onUnstage: (r: DirtyRange) => Promise<void>;
18
+ readBase: (staged: boolean) => Promise<string>;
19
+ }): import("react").ReactPortal | null;
@@ -1,8 +1,8 @@
1
1
  // GENERATED by sdk/gen-types.mjs from Deck's source — do not edit.
2
2
  import { monaco } from "../../core/monaco";
3
3
  import { type EditorSettings } from "../../core/editorsettings";
4
- import type { DirtyRange } from "./tree";
5
- declare function MonacoEditorInner({ path, rel, value, onChange, onSave, gotoLine, gotoCol, gotoNonce, highlight, dirty, settings, onEditor }: {
4
+ import type { DirtyRange } from "./hunks";
5
+ declare function MonacoEditorInner({ path, rel, value, onChange, onSave, gotoLine, gotoCol, gotoNonce, highlight, dirty, settings, onEditor, clean, onStageChange, onUnstageChange, onReadBase }: {
6
6
  path: string;
7
7
  rel?: string | null;
8
8
  value: string;
@@ -22,6 +22,13 @@ declare function MonacoEditorInner({ path, rel, value, onChange, onSave, gotoLin
22
22
  /** Hands the live editor out, and null on unmount. For a formatting toolbar, which has to
23
23
  * dispatch into this instance rather than rewrite the string around it. */
24
24
  onEditor?: (e: monaco.editor.IStandaloneCodeEditor | null) => void;
25
+ /** The buffer matches the file on disk, which the gutter's changes were read from. */
26
+ clean?: boolean;
27
+ /** Stage or unstage one change from the gutter's peek (DiffPeek.tsx). */
28
+ onStageChange?: (r: DirtyRange) => Promise<void>;
29
+ onUnstageChange?: (r: DirtyRange) => Promise<void>;
30
+ /** The text the file's changes are against: the index's copy, or HEAD's for a staged change. */
31
+ onReadBase?: (staged: boolean) => Promise<string>;
25
32
  }): import("react").JSX.Element;
26
33
  /**
27
34
  * Monaco owns its buffer, so this component re-rendering achieves nothing on its own — yet it was
@@ -35,13 +42,19 @@ declare function MonacoEditorInner({ path, rel, value, onChange, onSave, gotoLin
35
42
  */
36
43
  export declare const MonacoEditor: import("react").MemoExoticComponent<typeof MonacoEditorInner>;
37
44
  export declare function applyLineChanges(original: monaco.editor.ITextModel, modified: monaco.editor.ITextModel, diffs: monaco.editor.ILineChange[]): string;
45
+ type HunkRun = (change: monaco.editor.ILineChange, models: {
46
+ original: monaco.editor.ITextModel;
47
+ modified: monaco.editor.ITextModel;
48
+ }) => void;
49
+ /**
50
+ * Per-change buttons in a diff's gutter: stage (or unstage) one change, and, given `revert`, put
51
+ * one change back to the left side's text. Each change gets them at its first line.
52
+ */
38
53
  export interface HunkAction {
39
54
  label: string;
40
55
  unstage: boolean;
41
- run: (change: monaco.editor.ILineChange, models: {
42
- original: monaco.editor.ITextModel;
43
- modified: monaco.editor.ITextModel;
44
- }) => void;
56
+ run: HunkRun;
57
+ revert?: HunkRun;
45
58
  }
46
59
  /** A side of a diff: LEFT the old version, RIGHT the new — GitHub's names, which line comments use. */
47
60
  export type DiffSide = "LEFT" | "RIGHT";
@@ -0,0 +1,54 @@
1
+ // GENERATED by sdk/gen-types.mjs from Deck's source — do not edit.
2
+ /** One change: lines `oldStart..` of the base replaced by lines `newStart..` of the file. */
3
+ export interface Hunk {
4
+ oldStart: number;
5
+ oldCount: number;
6
+ /** For a deletion (newCount 0), the line the removed lines were after; 0 at the very top. */
7
+ newStart: number;
8
+ newCount: number;
9
+ /** The base's lines and the file's, without git's prefix or a trailing \r. */
10
+ removed: string[];
11
+ added: string[];
12
+ /** The hunk exactly as git printed it, from its @@ line on, for a patch. */
13
+ raw: string[];
14
+ }
15
+ /** One file's diff: the lines before the first hunk (its header), and the hunks. */
16
+ export interface FileDiff {
17
+ header: string[];
18
+ hunks: Hunk[];
19
+ }
20
+ /** A changed line range in the file, for the gutter. */
21
+ export interface DirtyRange {
22
+ start: number;
23
+ end: number;
24
+ type: "added" | "modified" | "deleted";
25
+ /** Staged: in the index already, so shown dimmed. */
26
+ staged?: boolean;
27
+ hunk: Hunk;
28
+ }
29
+ /** Parse `git diff --unified=0` for one file. Empty text is an empty diff. */
30
+ export declare function parseDiff(diff: string): FileDiff;
31
+ /** Where a hunk sits in the file. A deletion is drawn on the line it follows (the first, at the top). */
32
+ export declare function rangeOf(h: Hunk): Omit<DirtyRange, "hunk">;
33
+ /**
34
+ * The gutter's ranges: every unstaged change, and every staged one that has not been changed again
35
+ * since it was staged.
36
+ *
37
+ * `unstaged` is the file against the index; `sinceHead`, when given, the file against HEAD. Both
38
+ * are in the file's own line numbers, which a diff of the index against HEAD (`--cached`) would
39
+ * not be once there are unstaged edits too. A change against HEAD that touches no unstaged line is
40
+ * entirely in the index: that is a staged one.
41
+ */
42
+ export declare function dirtyRanges(unstaged: FileDiff, sinceHead?: FileDiff): DirtyRange[];
43
+ /** A patch holding just this hunk, for `git apply --cached --unidiff-zero`. */
44
+ export declare function hunkPatch(file: FileDiff, h: Hunk): string;
45
+ /** The hunk in `file` with the same removed and added lines as `h`: a staged change, found in `--cached`. */
46
+ export declare function sameHunk(file: FileDiff, h: Hunk): Hunk | undefined;
47
+ /**
48
+ * The edit that puts a hunk's base lines back in the file, as a range in 1-based lines and
49
+ * columns and its replacement text. `lineCount` and `maxColumn` describe the file as it is.
50
+ */
51
+ export declare function revertEdit(h: Hunk, lineCount: number, maxColumn: (line: number) => number, eol?: string): {
52
+ range: [number, number, number, number];
53
+ text: string;
54
+ };
@@ -48,12 +48,6 @@ export declare function sameRows(a: readonly {
48
48
  export declare function buildChangeTree<T extends {
49
49
  rel: string;
50
50
  }>(rows: T[]): TreeNodeOf<T>[];
51
- export interface DirtyRange {
52
- start: number;
53
- end: number;
54
- type: "added" | "modified" | "deleted";
55
- }
56
51
  export declare function statusColor(letter: string): string;
57
52
  /** Flatten a tree node to the file rows underneath it (a file node is just itself). */
58
53
  export declare function collectFiles(node: ChangeTreeNode): GitStatusRow[];
59
- export declare function parseDirty(diff: string): DirtyRange[];