xtralab 0.1.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.
- package/LICENSE +28 -0
- package/README.md +69 -0
- package/lib/fileBrowser/commands.d.ts +62 -0
- package/lib/fileBrowser/commands.js +418 -0
- package/lib/fileBrowser/contents.d.ts +28 -0
- package/lib/fileBrowser/contents.js +48 -0
- package/lib/fileBrowser/fileBrowser.d.ts +24 -0
- package/lib/fileBrowser/fileBrowser.js +535 -0
- package/lib/fileBrowser/icons.d.ts +37 -0
- package/lib/fileBrowser/icons.js +153 -0
- package/lib/fileBrowser/index.d.ts +7 -0
- package/lib/fileBrowser/index.js +38 -0
- package/lib/fileBrowser/widget.d.ts +97 -0
- package/lib/fileBrowser/widget.js +95 -0
- package/lib/git/api.d.ts +39 -0
- package/lib/git/api.js +164 -0
- package/lib/git/commands.d.ts +69 -0
- package/lib/git/commands.js +67 -0
- package/lib/git/diffWidget.d.ts +108 -0
- package/lib/git/diffWidget.js +624 -0
- package/lib/git/icons.d.ts +14 -0
- package/lib/git/icons.js +19 -0
- package/lib/git/index.d.ts +11 -0
- package/lib/git/index.js +74 -0
- package/lib/git/notebookDiff.d.ts +176 -0
- package/lib/git/notebookDiff.js +805 -0
- package/lib/git/panel.d.ts +29 -0
- package/lib/git/panel.js +42 -0
- package/lib/git/panelComponent.d.ts +26 -0
- package/lib/git/panelComponent.js +300 -0
- package/lib/git/tokens.d.ts +78 -0
- package/lib/git/tokens.js +6 -0
- package/lib/index.d.ts +10 -0
- package/lib/index.js +14 -0
- package/package.json +216 -0
- package/schema/plugin.json +67 -0
- package/src/fileBrowser/commands.ts +507 -0
- package/src/fileBrowser/contents.ts +66 -0
- package/src/fileBrowser/fileBrowser.tsx +635 -0
- package/src/fileBrowser/icons.ts +172 -0
- package/src/fileBrowser/index.ts +56 -0
- package/src/fileBrowser/widget.tsx +202 -0
- package/src/git/api.ts +207 -0
- package/src/git/commands.ts +143 -0
- package/src/git/diffWidget.tsx +903 -0
- package/src/git/icons.ts +20 -0
- package/src/git/index.ts +109 -0
- package/src/git/notebookDiff.tsx +1294 -0
- package/src/git/panel.tsx +56 -0
- package/src/git/panelComponent.tsx +558 -0
- package/src/git/tokens.ts +91 -0
- package/src/index.ts +18 -0
- package/style/base.css +175 -0
- package/style/git.css +770 -0
- package/style/index.css +2 -0
- package/style/index.js +2 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { JupyterFrontEnd } from '@jupyterlab/application';
|
|
2
|
+
import { ICommandPalette, IThemeManager } from '@jupyterlab/apputils';
|
|
3
|
+
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
|
|
4
|
+
import { Contents } from '@jupyterlab/services';
|
|
5
|
+
import { refreshIcon } from '@jupyterlab/ui-components';
|
|
6
|
+
import { ReadonlyPartialJSONObject } from '@lumino/coreutils';
|
|
7
|
+
|
|
8
|
+
import { createGitDiffWidget, diffWidgetId } from './diffWidget';
|
|
9
|
+
import { GitPanel } from './panel';
|
|
10
|
+
import { IFileChange } from './tokens';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Command IDs exposed by the git plugin. Both are registered in
|
|
14
|
+
* {@link registerGitCommands} so other extensions, the command palette and
|
|
15
|
+
* keybindings can drive the panel without going through the React internals.
|
|
16
|
+
*/
|
|
17
|
+
export namespace CommandIDs {
|
|
18
|
+
export const refresh = 'xtralab:git:refresh';
|
|
19
|
+
export const openDiff = 'xtralab:git:open-diff';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Argument shapes used by {@link CommandIDs.openDiff}. Cast to this type
|
|
24
|
+
* inside the execute callback for type safety; the registry itself takes
|
|
25
|
+
* `ReadonlyPartialJSONObject` because Lumino does not know about our
|
|
26
|
+
* extension-specific shapes.
|
|
27
|
+
*/
|
|
28
|
+
export namespace CommandArguments {
|
|
29
|
+
export interface IOpenDiff {
|
|
30
|
+
repoPath: string;
|
|
31
|
+
change: IFileChange;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface IRegisterGitCommandsOptions {
|
|
36
|
+
app: JupyterFrontEnd;
|
|
37
|
+
panel: GitPanel;
|
|
38
|
+
themeManager: IThemeManager | null;
|
|
39
|
+
commandPalette: ICommandPalette | null;
|
|
40
|
+
/**
|
|
41
|
+
* Contents manager used by the diff widget to write hunk-discard
|
|
42
|
+
* results back to the working tree.
|
|
43
|
+
*/
|
|
44
|
+
contentsManager: Contents.IManager;
|
|
45
|
+
/**
|
|
46
|
+
* Rendermime registry used by the notebook diff to render outputs and
|
|
47
|
+
* markdown cells with their actual mime-type renderers (images as
|
|
48
|
+
* images, HTML as HTML, etc.). May be `null` in stripped-down hosts —
|
|
49
|
+
* the notebook diff falls back to a text representation in that case.
|
|
50
|
+
*/
|
|
51
|
+
rendermime: IRenderMimeRegistry | null;
|
|
52
|
+
/**
|
|
53
|
+
* Called whenever the diff widget mutates the working tree (e.g. after
|
|
54
|
+
* a hunk discard) so the plugin can refresh the changes panel.
|
|
55
|
+
*/
|
|
56
|
+
onChanged: () => void;
|
|
57
|
+
/**
|
|
58
|
+
* Called for every diff widget created via the {@link CommandIDs.openDiff}
|
|
59
|
+
* command, before the widget is added to the shell. Lets the plugin track
|
|
60
|
+
* the widget for layout restoration and reveal-on-reuse.
|
|
61
|
+
*/
|
|
62
|
+
trackDiff(widget: ReturnType<typeof createGitDiffWidget>): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Look up an already-open diff widget for a given file change. Returns
|
|
65
|
+
* `undefined` when none is open.
|
|
66
|
+
*/
|
|
67
|
+
findDiff(
|
|
68
|
+
change: IFileChange
|
|
69
|
+
): ReturnType<typeof createGitDiffWidget> | undefined;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Register the git commands on the application command registry. Returns
|
|
74
|
+
* a disposer that clears the command palette items the registration created
|
|
75
|
+
* (the commands themselves stay registered for the lifetime of the plugin).
|
|
76
|
+
*/
|
|
77
|
+
export function registerGitCommands(
|
|
78
|
+
options: IRegisterGitCommandsOptions
|
|
79
|
+
): () => void {
|
|
80
|
+
const {
|
|
81
|
+
app,
|
|
82
|
+
panel,
|
|
83
|
+
themeManager,
|
|
84
|
+
commandPalette,
|
|
85
|
+
contentsManager,
|
|
86
|
+
rendermime,
|
|
87
|
+
onChanged,
|
|
88
|
+
trackDiff,
|
|
89
|
+
findDiff
|
|
90
|
+
} = options;
|
|
91
|
+
const { commands } = app;
|
|
92
|
+
|
|
93
|
+
commands.addCommand(CommandIDs.refresh, {
|
|
94
|
+
label: 'Refresh Git Changes',
|
|
95
|
+
caption: 'Refresh the git changes panel',
|
|
96
|
+
icon: refreshIcon,
|
|
97
|
+
execute: () => {
|
|
98
|
+
panel.refresh();
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
commands.addCommand(CommandIDs.openDiff, {
|
|
103
|
+
label: 'Open Git Diff',
|
|
104
|
+
caption: 'Open a side-by-side diff for a changed file',
|
|
105
|
+
execute: async (args: ReadonlyPartialJSONObject) => {
|
|
106
|
+
const typed = args as unknown as CommandArguments.IOpenDiff;
|
|
107
|
+
if (typed?.change === undefined) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const existing = findDiff(typed.change);
|
|
111
|
+
if (existing !== undefined && !existing.isDisposed) {
|
|
112
|
+
app.shell.activateById(existing.id);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const widget = createGitDiffWidget({
|
|
116
|
+
repoPath: typed.repoPath,
|
|
117
|
+
change: typed.change,
|
|
118
|
+
themeManager,
|
|
119
|
+
contentsManager,
|
|
120
|
+
rendermime,
|
|
121
|
+
onChanged
|
|
122
|
+
});
|
|
123
|
+
await trackDiff(widget);
|
|
124
|
+
app.shell.add(widget, 'main', { mode: 'tab-after' });
|
|
125
|
+
app.shell.activateById(widget.id);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
const paletteItems = commandPalette
|
|
130
|
+
? [
|
|
131
|
+
commandPalette.addItem({
|
|
132
|
+
command: CommandIDs.refresh,
|
|
133
|
+
category: 'Git'
|
|
134
|
+
})
|
|
135
|
+
]
|
|
136
|
+
: [];
|
|
137
|
+
|
|
138
|
+
return () => {
|
|
139
|
+
paletteItems.forEach(item => item.dispose());
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export { diffWidgetId };
|