@spences10/pi-git-ui 0.0.3 → 0.0.5
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/stage-actions.d.ts +18 -0
- package/dist/stage-actions.js +82 -0
- package/dist/stage-actions.js.map +1 -0
- package/dist/stage-input.d.ts +14 -0
- package/dist/stage-input.js +71 -0
- package/dist/stage-input.js.map +1 -0
- package/dist/stage-selection.d.ts +28 -0
- package/dist/stage-selection.js +96 -0
- package/dist/stage-selection.js.map +1 -0
- package/package.json +8 -4
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { GitFile } from './git.js';
|
|
2
|
+
import type { ActionItem } from './stage-types.js';
|
|
3
|
+
export interface StageActionHandlers {
|
|
4
|
+
stage_file: () => void;
|
|
5
|
+
unstage_file: () => void;
|
|
6
|
+
stage_hunk: () => void;
|
|
7
|
+
unstage_hunk: () => void;
|
|
8
|
+
stage_line: () => void;
|
|
9
|
+
unstage_line: () => void;
|
|
10
|
+
discard_file: () => void;
|
|
11
|
+
commit: () => void;
|
|
12
|
+
amend: () => void;
|
|
13
|
+
repository: () => void;
|
|
14
|
+
refresh: () => void;
|
|
15
|
+
conflict_help: () => void;
|
|
16
|
+
}
|
|
17
|
+
export declare function create_stage_actions(file: GitFile, handlers: StageActionHandlers): ActionItem[];
|
|
18
|
+
export declare function create_discard_confirmation_actions(on_confirm: () => void, on_cancel: () => void): ActionItem[];
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
export function create_stage_actions(file, handlers) {
|
|
2
|
+
const actions = [
|
|
3
|
+
{
|
|
4
|
+
action_label: 'stage file',
|
|
5
|
+
action_description: 'Stage all worktree changes for this file',
|
|
6
|
+
run: handlers.stage_file,
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
action_label: 'unstage file',
|
|
10
|
+
action_description: 'Remove this file from the index',
|
|
11
|
+
run: handlers.unstage_file,
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
action_label: 'stage hunk',
|
|
15
|
+
action_description: 'Stage the selected unstaged hunk',
|
|
16
|
+
run: handlers.stage_hunk,
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
action_label: 'unstage hunk',
|
|
20
|
+
action_description: 'Unstage the selected staged hunk',
|
|
21
|
+
run: handlers.unstage_hunk,
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
action_label: 'stage line',
|
|
25
|
+
action_description: 'Stage the selected changed line',
|
|
26
|
+
run: handlers.stage_line,
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
action_label: 'unstage line',
|
|
30
|
+
action_description: 'Unstage the selected changed line',
|
|
31
|
+
run: handlers.unstage_line,
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
action_label: 'discard file',
|
|
35
|
+
action_description: 'Discard unstaged worktree changes for this file',
|
|
36
|
+
run: handlers.discard_file,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
action_label: 'commit',
|
|
40
|
+
action_description: 'Commit currently staged changes',
|
|
41
|
+
run: handlers.commit,
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
action_label: 'amend commit',
|
|
45
|
+
action_description: 'Amend HEAD with staged changes',
|
|
46
|
+
run: handlers.amend,
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
action_label: 'repository',
|
|
50
|
+
action_description: 'Show branches, log, stashes, and remotes',
|
|
51
|
+
run: handlers.repository,
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
action_label: 'refresh',
|
|
55
|
+
action_description: 'Reload git status and diff',
|
|
56
|
+
run: handlers.refresh,
|
|
57
|
+
},
|
|
58
|
+
];
|
|
59
|
+
if (file.state === 'conflicted') {
|
|
60
|
+
actions.unshift({
|
|
61
|
+
action_label: 'conflict help',
|
|
62
|
+
action_description: 'Show safe conflict resolution steps',
|
|
63
|
+
run: handlers.conflict_help,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return actions;
|
|
67
|
+
}
|
|
68
|
+
export function create_discard_confirmation_actions(on_confirm, on_cancel) {
|
|
69
|
+
return [
|
|
70
|
+
{
|
|
71
|
+
action_label: 'confirm discard',
|
|
72
|
+
action_description: 'Permanently remove unstaged worktree changes',
|
|
73
|
+
run: on_confirm,
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
action_label: 'cancel',
|
|
77
|
+
action_description: 'Keep changes',
|
|
78
|
+
run: on_cancel,
|
|
79
|
+
},
|
|
80
|
+
];
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=stage-actions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stage-actions.js","sourceRoot":"","sources":["../src/stage-actions.ts"],"names":[],"mappings":"AAkBA,MAAM,UAAU,oBAAoB,CACnC,IAAa,EACb,QAA6B;IAE7B,MAAM,OAAO,GAAiB;QAC7B;YACC,YAAY,EAAE,YAAY;YAC1B,kBAAkB,EAAE,0CAA0C;YAC9D,GAAG,EAAE,QAAQ,CAAC,UAAU;SACxB;QACD;YACC,YAAY,EAAE,cAAc;YAC5B,kBAAkB,EAAE,iCAAiC;YACrD,GAAG,EAAE,QAAQ,CAAC,YAAY;SAC1B;QACD;YACC,YAAY,EAAE,YAAY;YAC1B,kBAAkB,EAAE,kCAAkC;YACtD,GAAG,EAAE,QAAQ,CAAC,UAAU;SACxB;QACD;YACC,YAAY,EAAE,cAAc;YAC5B,kBAAkB,EAAE,kCAAkC;YACtD,GAAG,EAAE,QAAQ,CAAC,YAAY;SAC1B;QACD;YACC,YAAY,EAAE,YAAY;YAC1B,kBAAkB,EAAE,iCAAiC;YACrD,GAAG,EAAE,QAAQ,CAAC,UAAU;SACxB;QACD;YACC,YAAY,EAAE,cAAc;YAC5B,kBAAkB,EAAE,mCAAmC;YACvD,GAAG,EAAE,QAAQ,CAAC,YAAY;SAC1B;QACD;YACC,YAAY,EAAE,cAAc;YAC5B,kBAAkB,EACjB,iDAAiD;YAClD,GAAG,EAAE,QAAQ,CAAC,YAAY;SAC1B;QACD;YACC,YAAY,EAAE,QAAQ;YACtB,kBAAkB,EAAE,iCAAiC;YACrD,GAAG,EAAE,QAAQ,CAAC,MAAM;SACpB;QACD;YACC,YAAY,EAAE,cAAc;YAC5B,kBAAkB,EAAE,gCAAgC;YACpD,GAAG,EAAE,QAAQ,CAAC,KAAK;SACnB;QACD;YACC,YAAY,EAAE,YAAY;YAC1B,kBAAkB,EAAE,0CAA0C;YAC9D,GAAG,EAAE,QAAQ,CAAC,UAAU;SACxB;QACD;YACC,YAAY,EAAE,SAAS;YACvB,kBAAkB,EAAE,4BAA4B;YAChD,GAAG,EAAE,QAAQ,CAAC,OAAO;SACrB;KACD,CAAC;IACF,IAAI,IAAI,CAAC,KAAK,KAAK,YAAY,EAAE,CAAC;QACjC,OAAO,CAAC,OAAO,CAAC;YACf,YAAY,EAAE,eAAe;YAC7B,kBAAkB,EAAE,qCAAqC;YACzD,GAAG,EAAE,QAAQ,CAAC,aAAa;SAC3B,CAAC,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,mCAAmC,CAClD,UAAsB,EACtB,SAAqB;IAErB,OAAO;QACN;YACC,YAAY,EAAE,iBAAiB;YAC/B,kBAAkB,EACjB,8CAA8C;YAC/C,GAAG,EAAE,UAAU;SACf;QACD;YACC,YAAY,EAAE,QAAQ;YACtB,kBAAkB,EAAE,cAAc;YAClC,GAAG,EAAE,SAAS;SACd;KACD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type StageInputCommand = 'quit' | 'move-up' | 'move-down' | 'scroll-right' | 'scroll-left' | 'toggle-file' | 'stage-file' | 'unstage-file' | 'stage-hunk' | 'unstage-hunk' | 'stage-line' | 'unstage-line' | 'move-line-down' | 'move-line-up' | 'next-hunk' | 'previous-hunk' | 'stage-all-safe' | 'stage-all-force' | 'unstage-all' | 'repo-overview' | 'commit' | 'amend' | 'action-menu' | 'help' | 'filter' | 'refresh';
|
|
2
|
+
export declare function stage_input_command(data: string): StageInputCommand | undefined;
|
|
3
|
+
export type ActionMenuInput = {
|
|
4
|
+
type: 'close';
|
|
5
|
+
} | {
|
|
6
|
+
type: 'move';
|
|
7
|
+
delta: -1 | 1;
|
|
8
|
+
} | {
|
|
9
|
+
type: 'run';
|
|
10
|
+
} | {
|
|
11
|
+
type: 'ignore';
|
|
12
|
+
};
|
|
13
|
+
export declare function action_menu_input(data: string): ActionMenuInput;
|
|
14
|
+
export declare function action_menu_selection(selected: number, delta: -1 | 1, action_count: number): number;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { key_is_down, key_is_up } from './render.js';
|
|
2
|
+
export function stage_input_command(data) {
|
|
3
|
+
if (data === 'q' || data === '\x1B')
|
|
4
|
+
return 'quit';
|
|
5
|
+
if (key_is_up(data))
|
|
6
|
+
return 'move-up';
|
|
7
|
+
if (key_is_down(data))
|
|
8
|
+
return 'move-down';
|
|
9
|
+
if (data === '\x1B[C' || data === 'l')
|
|
10
|
+
return 'scroll-right';
|
|
11
|
+
if (data === '\x1B[D' || data === 'h')
|
|
12
|
+
return 'scroll-left';
|
|
13
|
+
if (data === ' ')
|
|
14
|
+
return 'toggle-file';
|
|
15
|
+
if (data === 's')
|
|
16
|
+
return 'stage-file';
|
|
17
|
+
if (data === 'x')
|
|
18
|
+
return 'unstage-file';
|
|
19
|
+
if (data === 'S')
|
|
20
|
+
return 'stage-hunk';
|
|
21
|
+
if (data === 'X')
|
|
22
|
+
return 'unstage-hunk';
|
|
23
|
+
if (data === '+')
|
|
24
|
+
return 'stage-line';
|
|
25
|
+
if (data === '-')
|
|
26
|
+
return 'unstage-line';
|
|
27
|
+
if (data === ']')
|
|
28
|
+
return 'move-line-down';
|
|
29
|
+
if (data === '[')
|
|
30
|
+
return 'move-line-up';
|
|
31
|
+
if (data === 'n')
|
|
32
|
+
return 'next-hunk';
|
|
33
|
+
if (data === 'p')
|
|
34
|
+
return 'previous-hunk';
|
|
35
|
+
if (data === 'a')
|
|
36
|
+
return 'stage-all-safe';
|
|
37
|
+
if (data === 'A')
|
|
38
|
+
return 'stage-all-force';
|
|
39
|
+
if (data === 'u')
|
|
40
|
+
return 'unstage-all';
|
|
41
|
+
if (data === 'g')
|
|
42
|
+
return 'repo-overview';
|
|
43
|
+
if (data === 'c')
|
|
44
|
+
return 'commit';
|
|
45
|
+
if (data === 'm')
|
|
46
|
+
return 'amend';
|
|
47
|
+
if (data === '\r' || data === '\n')
|
|
48
|
+
return 'action-menu';
|
|
49
|
+
if (data === '?')
|
|
50
|
+
return 'help';
|
|
51
|
+
if (data === '/')
|
|
52
|
+
return 'filter';
|
|
53
|
+
if (data === 'r')
|
|
54
|
+
return 'refresh';
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
export function action_menu_input(data) {
|
|
58
|
+
if (data === '\x1B' || data === 'q')
|
|
59
|
+
return { type: 'close' };
|
|
60
|
+
if (key_is_up(data))
|
|
61
|
+
return { type: 'move', delta: -1 };
|
|
62
|
+
if (key_is_down(data))
|
|
63
|
+
return { type: 'move', delta: 1 };
|
|
64
|
+
if (data === '\r' || data === '\n')
|
|
65
|
+
return { type: 'run' };
|
|
66
|
+
return { type: 'ignore' };
|
|
67
|
+
}
|
|
68
|
+
export function action_menu_selection(selected, delta, action_count) {
|
|
69
|
+
return Math.max(0, Math.min(action_count - 1, selected + delta));
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=stage-input.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stage-input.js","sourceRoot":"","sources":["../src/stage-input.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AA8BrD,MAAM,UAAU,mBAAmB,CAClC,IAAY;IAEZ,IAAI,IAAI,KAAK,GAAG,IAAI,IAAI,KAAK,MAAM;QAAE,OAAO,MAAM,CAAC;IACnD,IAAI,SAAS,CAA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AI,KAAK,IAAI;QAAE,OAAO,aAAa,CAAC;IACzD,IAAI,IAAI,KAAK,GAAG;QAAE,OAAO,MAAM,CAAC;IAChC,IAAI,IAAI,KAAK,GAAG;QAAE,OAAO,QAAQ,CAAC;IAClC,IAAI,IAAI,KAAK,GAAG;QAAE,OAAO,SAAS,CAAC;IACnC,OAAO,SAAS,CAAC;AAClB,CAAC;AAQD,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC7C,IAAI,IAAI,KAAK,MAAM,IAAI,IAAI,KAAK,GAAG;QAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;IAC9D,IAAI,SAAS,CAAC,IAAI,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC;IACxD,IAAI,WAAW,CAAC,IAAI,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;IACzD,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,IAAI;QAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;IAC3D,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;AAC3B,CAAC;AAED,MAAM,UAAU,qBAAqB,CACpC,QAAgB,EAChB,KAAa,EACb,YAAoB;IAEpB,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,YAAY,GAAG,CAAC,EAAE,QAAQ,GAAG,KAAK,CAAC,CAAC,CAAC;AAClE,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { DiffHunk, GitFile, GitStatus } from './git.js';
|
|
2
|
+
export interface FilterUpdate {
|
|
3
|
+
filter_text: string;
|
|
4
|
+
message: string;
|
|
5
|
+
closed: boolean;
|
|
6
|
+
changed: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare function visible_stage_files(status: GitStatus, filter_text: string): GitFile[];
|
|
9
|
+
export declare function selected_stage_file(files: GitFile[], selected: number): GitFile | undefined;
|
|
10
|
+
export declare function restore_stage_selection(files: GitFile[], selected: number, preferred_path?: string): number;
|
|
11
|
+
export declare function next_stage_selection(files: GitFile[], selected: number, delta: number): number;
|
|
12
|
+
export declare function update_filter_text(filter_text: string, data: string): FilterUpdate;
|
|
13
|
+
export declare function changed_line_index_list(hunks: DiffHunk[]): number[];
|
|
14
|
+
export declare function selected_line_hunk(hunks: DiffHunk[] | undefined, selected_line_index: number | undefined): DiffHunk | undefined;
|
|
15
|
+
export interface HunkSelection {
|
|
16
|
+
selected_hunk: number;
|
|
17
|
+
diff_scroll: number;
|
|
18
|
+
selected_line_index?: number;
|
|
19
|
+
message?: string;
|
|
20
|
+
}
|
|
21
|
+
export declare function move_hunk_selection(hunks: DiffHunk[] | undefined, selected_hunk: number, delta: number): HunkSelection;
|
|
22
|
+
export interface LineSelection {
|
|
23
|
+
selected_line_index?: number;
|
|
24
|
+
diff_scroll: number;
|
|
25
|
+
selected_hunk: number;
|
|
26
|
+
message?: string;
|
|
27
|
+
}
|
|
28
|
+
export declare function move_line_selection(hunks: DiffHunk[] | undefined, selected_line_index: number | undefined, selected_hunk: number, delta: number): LineSelection;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { changed_line_indexes } from './git.js';
|
|
2
|
+
import { state_label, status_code } from './render.js';
|
|
3
|
+
export function visible_stage_files(status, filter_text) {
|
|
4
|
+
const query = filter_text.trim().toLowerCase();
|
|
5
|
+
if (!query)
|
|
6
|
+
return status.files;
|
|
7
|
+
return status.files.filter((file) => {
|
|
8
|
+
const searchable_text = `${file.path} ${state_label(file.state)} ${status_code(file)}`;
|
|
9
|
+
return searchable_text.toLowerCase().includes(query);
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
export function selected_stage_file(files, selected) {
|
|
13
|
+
return files[selected];
|
|
14
|
+
}
|
|
15
|
+
export function restore_stage_selection(files, selected, preferred_path) {
|
|
16
|
+
const path = preferred_path ?? files[selected]?.path;
|
|
17
|
+
const index = path
|
|
18
|
+
? files.findIndex((file) => file.path === path)
|
|
19
|
+
: -1;
|
|
20
|
+
return index >= 0
|
|
21
|
+
? index
|
|
22
|
+
: Math.min(selected, Math.max(0, files.length - 1));
|
|
23
|
+
}
|
|
24
|
+
export function next_stage_selection(files, selected, delta) {
|
|
25
|
+
return Math.max(0, Math.min(files.length - 1, selected + delta));
|
|
26
|
+
}
|
|
27
|
+
export function update_filter_text(filter_text, data) {
|
|
28
|
+
if (data === '\r' || data === '\n' || data === '\x1B') {
|
|
29
|
+
return {
|
|
30
|
+
filter_text,
|
|
31
|
+
message: filter_text ? `Filtered by ${filter_text}` : '',
|
|
32
|
+
closed: true,
|
|
33
|
+
changed: false,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
let next = filter_text;
|
|
37
|
+
if (data === '\x7F' || data === '\b')
|
|
38
|
+
next = filter_text.slice(0, -1);
|
|
39
|
+
else if (data === '\x15')
|
|
40
|
+
next = '';
|
|
41
|
+
else if (data.length === 1 && data >= ' ')
|
|
42
|
+
next = filter_text + data;
|
|
43
|
+
return {
|
|
44
|
+
filter_text: next,
|
|
45
|
+
message: next ? `Filter: ${next}` : 'Filter cleared',
|
|
46
|
+
closed: false,
|
|
47
|
+
changed: true,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export function changed_line_index_list(hunks) {
|
|
51
|
+
return hunks.flatMap(changed_line_indexes);
|
|
52
|
+
}
|
|
53
|
+
export function selected_line_hunk(hunks, selected_line_index) {
|
|
54
|
+
return hunks?.find((hunk) => selected_line_index === undefined
|
|
55
|
+
? false
|
|
56
|
+
: changed_line_indexes(hunk).includes(selected_line_index));
|
|
57
|
+
}
|
|
58
|
+
export function move_hunk_selection(hunks, selected_hunk, delta) {
|
|
59
|
+
if (!hunks || hunks.length === 0) {
|
|
60
|
+
return {
|
|
61
|
+
selected_hunk,
|
|
62
|
+
diff_scroll: 0,
|
|
63
|
+
message: 'No hunks in selected diff.',
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
const next_hunk = Math.max(0, Math.min(hunks.length - 1, selected_hunk + delta));
|
|
67
|
+
const hunk = hunks[next_hunk];
|
|
68
|
+
return {
|
|
69
|
+
selected_hunk: next_hunk,
|
|
70
|
+
diff_scroll: hunk.line_index,
|
|
71
|
+
selected_line_index: changed_line_indexes(hunk)[0],
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
export function move_line_selection(hunks, selected_line_index, selected_hunk, delta) {
|
|
75
|
+
const indexes = changed_line_index_list(hunks ?? []);
|
|
76
|
+
if (indexes.length === 0) {
|
|
77
|
+
return {
|
|
78
|
+
selected_line_index,
|
|
79
|
+
diff_scroll: 0,
|
|
80
|
+
selected_hunk,
|
|
81
|
+
message: 'No stageable lines in selected diff.',
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
const current = selected_line_index ?? indexes[0];
|
|
85
|
+
const current_index = Math.max(0, indexes.indexOf(current));
|
|
86
|
+
const next = indexes[Math.max(0, Math.min(indexes.length - 1, current_index + delta))];
|
|
87
|
+
const hunk_index = hunks?.findIndex((hunk) => changed_line_indexes(hunk).includes(next));
|
|
88
|
+
return {
|
|
89
|
+
selected_line_index: next,
|
|
90
|
+
diff_scroll: next,
|
|
91
|
+
selected_hunk: hunk_index !== undefined && hunk_index >= 0
|
|
92
|
+
? hunk_index
|
|
93
|
+
: selected_hunk,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=stage-selection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stage-selection.js","sourceRoot":"","sources":["../src/stage-selection.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AASvD,MAAM,UAAU,mBAAmB,CAClC,MAAiB,EACjB,WAAmB;IAEn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G,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,aAAa,GAAG,KAAK,CAAC,CAAC,CAC/D,CAAC;IACJ,MAAM,UAAU,GAAG,KAAK,EAAE,SAAS,CAAC,CAAC,IAAI,EAAE,EAAE,CAC5C,oBAAoB,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CACzC,CAAC;IACF,OAAO;QACN,mBAAmB,EAAE,IAAI;QACzB,WAAW,EAAE,IAAI;QACjB,aAAa,EACZ,UAAU,KAAK,SAAS,IAAI,UAAU,IAAI,CAAC;YAC1C,CAAC,CAAC,UAAU;YACZ,CAAC,CAAC,aAAa;KACjB,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spences10/pi-git-ui",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "Focused Git staging and commit modal for Pi",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"git",
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
"pi-package",
|
|
9
9
|
"tui"
|
|
10
10
|
],
|
|
11
|
+
"homepage": "https://github.com/spences10/my-pi/tree/main/packages/pi-git-ui#readme",
|
|
11
12
|
"license": "MIT",
|
|
12
13
|
"author": "Scott Spence <me@scottspence.com>",
|
|
13
14
|
"repository": {
|
|
@@ -29,7 +30,7 @@
|
|
|
29
30
|
}
|
|
30
31
|
},
|
|
31
32
|
"dependencies": {
|
|
32
|
-
"@spences10/pi-tui-modal": "0.0.
|
|
33
|
+
"@spences10/pi-tui-modal": "0.0.14"
|
|
33
34
|
},
|
|
34
35
|
"devDependencies": {
|
|
35
36
|
"@types/node": "^25.8.0",
|
|
@@ -45,7 +46,8 @@
|
|
|
45
46
|
"pi": {
|
|
46
47
|
"extensions": [
|
|
47
48
|
"./dist/index.js"
|
|
48
|
-
]
|
|
49
|
+
],
|
|
50
|
+
"image": "https://raw.githubusercontent.com/spences10/my-pi/main/assets/pi-package-preview.png"
|
|
49
51
|
},
|
|
50
52
|
"scripts": {
|
|
51
53
|
"build": "pnpm --filter \"$npm_package_name^...\" run build:self && pnpm run build:self",
|
|
@@ -53,6 +55,8 @@
|
|
|
53
55
|
"check": "pnpm --filter \"$npm_package_name^...\" run build:self && pnpm run check:self",
|
|
54
56
|
"check:self": "tsc --noEmit",
|
|
55
57
|
"test": "pnpm --filter \"$npm_package_name^...\" run build:self && pnpm run test:self",
|
|
56
|
-
"test:self": "vitest run
|
|
58
|
+
"test:self": "vitest run",
|
|
59
|
+
"coverage:self": "vitest run --coverage",
|
|
60
|
+
"coverage": "pnpm --filter \"$npm_package_name^...\" run build:self && pnpm run coverage:self"
|
|
57
61
|
}
|
|
58
62
|
}
|