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
package/src/git/icons.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { LabIcon } from '@jupyterlab/ui-components';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The branch glyph used as the git panel's sidebar tab icon. Defined as a
|
|
5
|
+
* `LabIcon` (rather than a CSS-only mask) so it picks up JupyterLab's icon
|
|
6
|
+
* recoloring and inverse-color sidebar painting automatically.
|
|
7
|
+
*
|
|
8
|
+
* Source: `git-branch` from SVG Repo (https://www.svgrepo.com/svg/377352/git-branch),
|
|
9
|
+
* part of the same Pixelarticons family as the Xtralab file browser's `file-tree`
|
|
10
|
+
* icon, so the two sidebar tab glyphs read as a matched set. The original
|
|
11
|
+
* `fill="#000000"` is replaced with `fill="currentColor"` and the root element
|
|
12
|
+
* is given the `jp-icon3` class so the icon picks up JupyterLab's theme color
|
|
13
|
+
* and the sidebar's inverse-color painting automatically.
|
|
14
|
+
*/
|
|
15
|
+
export const gitIcon = new LabIcon({
|
|
16
|
+
name: 'xtralab:git',
|
|
17
|
+
svgstr: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" class="jp-icon3" fill="currentColor">
|
|
18
|
+
<path d="M5 2h2v12h3v3h7v-7h-3V2h8v8h-3v9h-9v3H2v-8h3V2zm15 6V4h-4v4h4zM8 19v-3H4v4h4v-1z"/>
|
|
19
|
+
</svg>`
|
|
20
|
+
});
|
package/src/git/index.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ILayoutRestorer,
|
|
3
|
+
JupyterFrontEnd,
|
|
4
|
+
JupyterFrontEndPlugin
|
|
5
|
+
} from '@jupyterlab/application';
|
|
6
|
+
import {
|
|
7
|
+
Dialog,
|
|
8
|
+
ICommandPalette,
|
|
9
|
+
IThemeManager,
|
|
10
|
+
WidgetTracker,
|
|
11
|
+
showDialog,
|
|
12
|
+
showErrorMessage
|
|
13
|
+
} from '@jupyterlab/apputils';
|
|
14
|
+
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
|
|
15
|
+
|
|
16
|
+
import { ReadonlyPartialJSONObject } from '@lumino/coreutils';
|
|
17
|
+
|
|
18
|
+
import { CommandArguments, CommandIDs, registerGitCommands } from './commands';
|
|
19
|
+
import { DiffContentWidget, diffWidgetId } from './diffWidget';
|
|
20
|
+
import type { MainAreaWidget } from '@jupyterlab/apputils';
|
|
21
|
+
import { GitPanel } from './panel';
|
|
22
|
+
import { IFileChange } from './tokens';
|
|
23
|
+
|
|
24
|
+
const GIT_PLUGIN_ID = 'xtralab:git';
|
|
25
|
+
const GIT_DIFF_TRACKER_NAMESPACE = 'xtralab-git-diff';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The git plugin. Adds a VS Code-style "Source Control" panel to the
|
|
29
|
+
* JupyterLab left sidebar and opens file diffs in the main area when the
|
|
30
|
+
* user clicks an entry in the panel. Backed by the `jupyterlab_git` server
|
|
31
|
+
* extension's REST API; the bundled `@jupyterlab/git` frontend is disabled
|
|
32
|
+
* via `package.json`'s `jupyterlab.disabledExtensions` so the two panels do
|
|
33
|
+
* not coexist.
|
|
34
|
+
*/
|
|
35
|
+
const plugin: JupyterFrontEndPlugin<void> = {
|
|
36
|
+
id: GIT_PLUGIN_ID,
|
|
37
|
+
description:
|
|
38
|
+
'A VS Code-style git changes panel and diff viewer powered by jupyterlab-git and @pierre/diffs.',
|
|
39
|
+
autoStart: true,
|
|
40
|
+
optional: [
|
|
41
|
+
ILayoutRestorer,
|
|
42
|
+
IThemeManager,
|
|
43
|
+
ICommandPalette,
|
|
44
|
+
IRenderMimeRegistry
|
|
45
|
+
],
|
|
46
|
+
activate: (
|
|
47
|
+
app: JupyterFrontEnd,
|
|
48
|
+
restorer: ILayoutRestorer | null,
|
|
49
|
+
themeManager: IThemeManager | null,
|
|
50
|
+
commandPalette: ICommandPalette | null,
|
|
51
|
+
rendermime: IRenderMimeRegistry | null
|
|
52
|
+
): void => {
|
|
53
|
+
// Match the panel's repo path: empty string means "use the JupyterLab
|
|
54
|
+
// server's root and let git resolve the enclosing repo".
|
|
55
|
+
const repoPath = '';
|
|
56
|
+
|
|
57
|
+
// Track open diff widgets so the layout restorer can recreate them on
|
|
58
|
+
// reload, and so the openDiff handler can reveal an already-open diff
|
|
59
|
+
// for the same file instead of creating a duplicate.
|
|
60
|
+
const tracker = new WidgetTracker<MainAreaWidget<DiffContentWidget>>({
|
|
61
|
+
namespace: GIT_DIFF_TRACKER_NAMESPACE
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const findDiff = (
|
|
65
|
+
change: IFileChange
|
|
66
|
+
): MainAreaWidget<DiffContentWidget> | undefined => {
|
|
67
|
+
const id = diffWidgetId(change);
|
|
68
|
+
return tracker.find(widget => widget.id === id) ?? undefined;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const panel = new GitPanel({
|
|
72
|
+
openDiff: change => {
|
|
73
|
+
const args: CommandArguments.IOpenDiff = { repoPath, change };
|
|
74
|
+
void app.commands.execute(
|
|
75
|
+
CommandIDs.openDiff,
|
|
76
|
+
args as unknown as ReadonlyPartialJSONObject
|
|
77
|
+
);
|
|
78
|
+
},
|
|
79
|
+
confirm: async (title, body, accept) => {
|
|
80
|
+
const result = await showDialog({
|
|
81
|
+
title,
|
|
82
|
+
body,
|
|
83
|
+
buttons: [Dialog.cancelButton(), Dialog.warnButton({ label: accept })]
|
|
84
|
+
});
|
|
85
|
+
return result.button.accept === true;
|
|
86
|
+
},
|
|
87
|
+
showError: showErrorMessage
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
app.shell.add(panel, 'left', { rank: 800 });
|
|
91
|
+
if (restorer !== null) {
|
|
92
|
+
restorer.add(panel, panel.id);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
registerGitCommands({
|
|
96
|
+
app,
|
|
97
|
+
panel,
|
|
98
|
+
themeManager,
|
|
99
|
+
commandPalette,
|
|
100
|
+
contentsManager: app.serviceManager.contents,
|
|
101
|
+
rendermime,
|
|
102
|
+
onChanged: () => panel.refresh(),
|
|
103
|
+
trackDiff: widget => tracker.add(widget),
|
|
104
|
+
findDiff
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export default plugin;
|