xtralab 0.3.0 → 0.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.
- package/README.md +11 -4
- package/lib/editorBreadcrumbs/index.d.ts +11 -0
- package/lib/editorBreadcrumbs/index.js +41 -0
- package/lib/editorBreadcrumbs/widget.d.ts +34 -0
- package/lib/editorBreadcrumbs/widget.js +131 -0
- package/lib/editorIndent/index.d.ts +17 -0
- package/lib/editorIndent/index.js +142 -0
- package/lib/fileBrowser/commands.d.ts +3 -0
- package/lib/fileBrowser/commands.js +40 -1
- package/lib/fileBrowser/fileBrowser.js +393 -10
- package/lib/fileBrowser/gitStatus.d.ts +13 -0
- package/lib/fileBrowser/gitStatus.js +60 -0
- package/lib/fileBrowser/widget.d.ts +48 -0
- package/lib/fileBrowser/widget.js +24 -0
- package/lib/git/commands.d.ts +12 -13
- package/lib/git/commands.js +7 -28
- package/lib/git/diffProvider.d.ts +8 -0
- package/lib/git/diffProvider.js +314 -0
- package/lib/git/diffSurface.d.ts +115 -0
- package/lib/git/diffSurface.js +342 -0
- package/lib/git/diffWidget.d.ts +8 -13
- package/lib/git/diffWidget.js +65 -311
- package/lib/git/imageDiff.d.ts +23 -0
- package/lib/git/imageDiff.js +184 -0
- package/lib/git/index.d.ts +10 -8
- package/lib/git/index.js +37 -52
- package/lib/index.d.ts +3 -2
- package/lib/index.js +9 -4
- package/lib/launcher/dashboard.js +27 -15
- package/package.json +24 -4
- package/src/editorBreadcrumbs/index.ts +70 -0
- package/src/editorBreadcrumbs/widget.ts +158 -0
- package/src/editorIndent/index.ts +177 -0
- package/src/fileBrowser/commands.ts +43 -1
- package/src/fileBrowser/fileBrowser.tsx +427 -11
- package/src/fileBrowser/gitStatus.ts +66 -0
- package/src/fileBrowser/widget.tsx +77 -0
- package/src/git/commands.ts +12 -38
- package/src/git/diffProvider.tsx +462 -0
- package/src/git/diffSurface.tsx +588 -0
- package/src/git/diffWidget.tsx +105 -465
- package/src/git/imageDiff.tsx +368 -0
- package/src/git/index.ts +38 -68
- package/src/index.ts +9 -4
- package/src/launcher/dashboard.tsx +28 -15
- package/style/editorBreadcrumbs.css +86 -0
- package/style/git.css +158 -266
- package/style/index.css +2 -0
- package/style/index.js +1 -0
- package/style/launcher.css +0 -5
- package/style/tabs.css +66 -0
- package/lib/git/icons.d.ts +0 -14
- package/lib/git/icons.js +0 -19
- package/lib/git/panel.d.ts +0 -29
- package/lib/git/panel.js +0 -42
- package/lib/git/panelComponent.d.ts +0 -28
- package/lib/git/panelComponent.js +0 -303
- package/src/git/icons.ts +0 -20
- package/src/git/panel.tsx +0 -56
- package/src/git/panelComponent.tsx +0 -561
package/lib/git/panel.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { ReactWidget } from '@jupyterlab/ui-components';
|
|
3
|
-
import { Signal } from '@lumino/signaling';
|
|
4
|
-
import { gitIcon } from './icons';
|
|
5
|
-
import { GitPanelComponent } from './panelComponent';
|
|
6
|
-
/**
|
|
7
|
-
* The id and CSS class used for the git panel widget. The id ends up as the
|
|
8
|
-
* sidebar tab id (so layout restoration can find the widget) and the CSS
|
|
9
|
-
* class lets per-panel styles attach without leaking to other widgets.
|
|
10
|
-
*/
|
|
11
|
-
export const GIT_PANEL_ID = 'xtralab:git-panel';
|
|
12
|
-
export const GIT_PANEL_CSS_CLASS = 'jp-xtralab-GitPanel';
|
|
13
|
-
/**
|
|
14
|
-
* The lumino host widget for the git changes panel. Owns the `refresh`
|
|
15
|
-
* signal that the React component listens to, and exposes a typed callback
|
|
16
|
-
* surface (`handlers`) the React component uses to react to user actions.
|
|
17
|
-
*/
|
|
18
|
-
export class GitPanel extends ReactWidget {
|
|
19
|
-
constructor(handlers) {
|
|
20
|
-
super();
|
|
21
|
-
this._refreshRequested = new Signal(this);
|
|
22
|
-
this.id = GIT_PANEL_ID;
|
|
23
|
-
this.title.icon = gitIcon;
|
|
24
|
-
this.title.caption = 'Git Changes';
|
|
25
|
-
this.addClass(GIT_PANEL_CSS_CLASS);
|
|
26
|
-
this._handlers = handlers;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Public refresh hook called by the plugin when something happened that
|
|
30
|
-
* invalidates the current view (the user clicked the toolbar refresh, the
|
|
31
|
-
* file browser refreshed, a focused notebook saved, …).
|
|
32
|
-
*/
|
|
33
|
-
refresh() {
|
|
34
|
-
this._refreshRequested.emit();
|
|
35
|
-
}
|
|
36
|
-
get refreshRequested() {
|
|
37
|
-
return this._refreshRequested;
|
|
38
|
-
}
|
|
39
|
-
render() {
|
|
40
|
-
return (React.createElement(GitPanelComponent, { handlers: this._handlers, refreshSignal: this._refreshRequested }));
|
|
41
|
-
}
|
|
42
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { ISignal } from '@lumino/signaling';
|
|
3
|
-
import { IFileChange } from './tokens';
|
|
4
|
-
/**
|
|
5
|
-
* Callbacks the panel needs to delegate to (so the React component stays
|
|
6
|
-
* free of any JupyterLab application coupling). The plugin wires these up
|
|
7
|
-
* with the actual `JupyterFrontEnd` reference.
|
|
8
|
-
*/
|
|
9
|
-
export interface IGitPanelHandlers {
|
|
10
|
-
/** Open a diff viewer for the given file in the main area. */
|
|
11
|
-
openDiff(change: IFileChange, options?: {
|
|
12
|
-
pin?: boolean;
|
|
13
|
-
}): void;
|
|
14
|
-
/** Show a confirmation dialog. Returns true when the user accepted. */
|
|
15
|
-
confirm(title: string, body: string, accept: string): Promise<boolean>;
|
|
16
|
-
/** Show an error dialog. */
|
|
17
|
-
showError(title: string, error: Error): Promise<void>;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Top-level React component rendered inside the {@link GitPanel} widget.
|
|
21
|
-
* Owns the polling + refresh wiring around the `/git/status` endpoint and
|
|
22
|
-
* the small bit of UI state that controls section collapse and the
|
|
23
|
-
* in-flight per-file action spinners.
|
|
24
|
-
*/
|
|
25
|
-
export declare function GitPanelComponent(props: {
|
|
26
|
-
handlers: IGitPanelHandlers;
|
|
27
|
-
refreshSignal: ISignal<unknown, void>;
|
|
28
|
-
}): React.ReactElement;
|
|
@@ -1,303 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { add, addAll, checkout, porcelainToFileChanges, reset, resetAll, showTopLevel, status } from './api';
|
|
3
|
-
/**
|
|
4
|
-
* The polling interval for the panel. We refresh the status periodically so
|
|
5
|
-
* out-of-band changes (e.g. the user runs `git add` from a terminal) become
|
|
6
|
-
* visible without requiring a manual refresh.
|
|
7
|
-
*/
|
|
8
|
-
const STATUS_POLL_INTERVAL_MS = 5000;
|
|
9
|
-
/**
|
|
10
|
-
* Top-level React component rendered inside the {@link GitPanel} widget.
|
|
11
|
-
* Owns the polling + refresh wiring around the `/git/status` endpoint and
|
|
12
|
-
* the small bit of UI state that controls section collapse and the
|
|
13
|
-
* in-flight per-file action spinners.
|
|
14
|
-
*/
|
|
15
|
-
export function GitPanelComponent(props) {
|
|
16
|
-
const { handlers, refreshSignal } = props;
|
|
17
|
-
const [state, setState] = React.useState({
|
|
18
|
-
loading: true,
|
|
19
|
-
result: null,
|
|
20
|
-
error: null
|
|
21
|
-
});
|
|
22
|
-
// The absolute filesystem path of the resolved git top-level. Used purely
|
|
23
|
-
// for display in the panel header.
|
|
24
|
-
const [topLevel, setTopLevel] = React.useState(null);
|
|
25
|
-
// Per-action spinner gating: keyed by `${group}:${path}`, value is the
|
|
26
|
-
// action currently in flight. Lets the row render a disabled state on
|
|
27
|
-
// exactly the file that is being mutated, without locking the whole panel.
|
|
28
|
-
const [pendingActions, setPendingActions] = React.useState({});
|
|
29
|
-
const [stagedCollapsed, setStagedCollapsed] = React.useState(false);
|
|
30
|
-
const [changesCollapsed, setChangesCollapsed] = React.useState(false);
|
|
31
|
-
// The repo path passed to every API call. We use the JupyterLab server's
|
|
32
|
-
// root (the empty string) and let `git` resolve the enclosing repo on the
|
|
33
|
-
// server side. This works as long as the server was started inside a git
|
|
34
|
-
// repo — the common case.
|
|
35
|
-
const repoPath = '';
|
|
36
|
-
const refresh = React.useCallback(async () => {
|
|
37
|
-
var _a;
|
|
38
|
-
try {
|
|
39
|
-
const [topLevelResult, statusResult] = await Promise.all([
|
|
40
|
-
showTopLevel(repoPath),
|
|
41
|
-
status(repoPath)
|
|
42
|
-
]);
|
|
43
|
-
setTopLevel(topLevelResult);
|
|
44
|
-
if (statusResult.code !== 0) {
|
|
45
|
-
setState({
|
|
46
|
-
loading: false,
|
|
47
|
-
result: null,
|
|
48
|
-
error: (_a = statusResult.message) !== null && _a !== void 0 ? _a : 'Failed to load git status'
|
|
49
|
-
});
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
setState({ loading: false, result: statusResult, error: null });
|
|
53
|
-
}
|
|
54
|
-
catch (err) {
|
|
55
|
-
setState({
|
|
56
|
-
loading: false,
|
|
57
|
-
result: null,
|
|
58
|
-
error: err instanceof Error ? err.message : String(err)
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
}, [repoPath]);
|
|
62
|
-
// Initial load + polling. `refresh` is stable for a given `repoPath`, so
|
|
63
|
-
// the polling interval is only re-created when the repo path changes.
|
|
64
|
-
React.useEffect(() => {
|
|
65
|
-
void refresh();
|
|
66
|
-
const interval = window.setInterval(() => void refresh(), STATUS_POLL_INTERVAL_MS);
|
|
67
|
-
return () => {
|
|
68
|
-
window.clearInterval(interval);
|
|
69
|
-
};
|
|
70
|
-
}, [refresh]);
|
|
71
|
-
// External refresh triggers (toolbar button, plugin-level events).
|
|
72
|
-
React.useEffect(() => {
|
|
73
|
-
const handler = () => {
|
|
74
|
-
void refresh();
|
|
75
|
-
};
|
|
76
|
-
refreshSignal.connect(handler);
|
|
77
|
-
return () => {
|
|
78
|
-
refreshSignal.disconnect(handler);
|
|
79
|
-
};
|
|
80
|
-
}, [refresh, refreshSignal]);
|
|
81
|
-
const runAction = React.useCallback(async (change, action, run) => {
|
|
82
|
-
const key = `${change.group}:${change.path}`;
|
|
83
|
-
setPendingActions(prev => ({ ...prev, [key]: action }));
|
|
84
|
-
try {
|
|
85
|
-
await run();
|
|
86
|
-
await refresh();
|
|
87
|
-
}
|
|
88
|
-
catch (err) {
|
|
89
|
-
await handlers.showError('Git operation failed', err instanceof Error ? err : new Error(String(err)));
|
|
90
|
-
}
|
|
91
|
-
finally {
|
|
92
|
-
setPendingActions(prev => {
|
|
93
|
-
const next = { ...prev };
|
|
94
|
-
delete next[key];
|
|
95
|
-
return next;
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
}, [handlers, refresh]);
|
|
99
|
-
const onStage = React.useCallback((change) => runAction(change, 'stage', () => add(repoPath, change.path)), [repoPath, runAction]);
|
|
100
|
-
const onUnstage = React.useCallback((change) => runAction(change, 'unstage', () => reset(repoPath, change.path)), [repoPath, runAction]);
|
|
101
|
-
const onDiscard = React.useCallback(async (change) => {
|
|
102
|
-
const verb = change.status === 'untracked' ? 'remove' : 'restore';
|
|
103
|
-
const accepted = await handlers.confirm(verb === 'remove' ? 'Remove file' : 'Discard changes', verb === 'remove'
|
|
104
|
-
? `Permanently remove ${change.path}? This cannot be undone.`
|
|
105
|
-
: `Discard all changes to ${change.path}? This will revert the file to its last staged version and cannot be undone.`, verb === 'remove' ? 'Remove' : 'Discard');
|
|
106
|
-
if (!accepted) {
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
// The git extension's `checkout` endpoint without a branch reverts the
|
|
110
|
-
// working tree copy of the file to the index. For untracked files we
|
|
111
|
-
// can't checkout, so the user is told the action is unsupported and we
|
|
112
|
-
// bail out — they can delete the file via the file browser instead.
|
|
113
|
-
if (change.status === 'untracked') {
|
|
114
|
-
await handlers.showError('Cannot discard untracked file', new Error('Untracked files cannot be discarded from the git panel — delete them from the file browser instead.'));
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
await runAction(change, 'discard', () => checkout(repoPath, change.path));
|
|
118
|
-
}, [handlers, repoPath, runAction]);
|
|
119
|
-
const onStageAll = React.useCallback(async () => {
|
|
120
|
-
try {
|
|
121
|
-
await addAll(repoPath);
|
|
122
|
-
await refresh();
|
|
123
|
-
}
|
|
124
|
-
catch (err) {
|
|
125
|
-
await handlers.showError('Stage all failed', err instanceof Error ? err : new Error(String(err)));
|
|
126
|
-
}
|
|
127
|
-
}, [handlers, refresh, repoPath]);
|
|
128
|
-
const onUnstageAll = React.useCallback(async () => {
|
|
129
|
-
try {
|
|
130
|
-
await resetAll(repoPath);
|
|
131
|
-
await refresh();
|
|
132
|
-
}
|
|
133
|
-
catch (err) {
|
|
134
|
-
await handlers.showError('Unstage all failed', err instanceof Error ? err : new Error(String(err)));
|
|
135
|
-
}
|
|
136
|
-
}, [handlers, refresh, repoPath]);
|
|
137
|
-
// Categorize the porcelain entries into the two visible groups. Because
|
|
138
|
-
// `porcelainToFileChanges` may emit two changes per file (one staged, one
|
|
139
|
-
// unstaged), the same file can show up in both lists when it has been
|
|
140
|
-
// partially staged.
|
|
141
|
-
const { staged, unstaged } = React.useMemo(() => {
|
|
142
|
-
const stagedAcc = [];
|
|
143
|
-
const unstagedAcc = [];
|
|
144
|
-
if (state.result === null) {
|
|
145
|
-
return { staged: stagedAcc, unstaged: unstagedAcc };
|
|
146
|
-
}
|
|
147
|
-
for (const file of state.result.files) {
|
|
148
|
-
for (const change of porcelainToFileChanges(file)) {
|
|
149
|
-
if (change.group === 'staged') {
|
|
150
|
-
stagedAcc.push(change);
|
|
151
|
-
}
|
|
152
|
-
else {
|
|
153
|
-
unstagedAcc.push(change);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
stagedAcc.sort((a, b) => a.path.localeCompare(b.path));
|
|
158
|
-
unstagedAcc.sort((a, b) => a.path.localeCompare(b.path));
|
|
159
|
-
return { staged: stagedAcc, unstaged: unstagedAcc };
|
|
160
|
-
}, [state.result]);
|
|
161
|
-
return (React.createElement("div", { className: "jp-xtralab-GitPanel-content" },
|
|
162
|
-
React.createElement(PanelHeader, { topLevel: topLevel, result: state.result, loading: state.loading, error: state.error, onRefresh: () => void refresh() }),
|
|
163
|
-
state.error !== null ? (React.createElement("div", { className: "jp-xtralab-GitPanel-error" }, state.error)) : (React.createElement(React.Fragment, null,
|
|
164
|
-
React.createElement(ChangeSection, { label: "Staged Changes", count: staged.length, collapsed: stagedCollapsed, onToggleCollapsed: () => setStagedCollapsed(c => !c), actions: staged.length > 0
|
|
165
|
-
? [
|
|
166
|
-
{
|
|
167
|
-
label: 'Unstage all changes',
|
|
168
|
-
symbol: '−',
|
|
169
|
-
onClick: onUnstageAll
|
|
170
|
-
}
|
|
171
|
-
]
|
|
172
|
-
: undefined }, staged.map(change => (React.createElement(ChangeRow, { key: `${change.group}:${change.path}`, change: change, pendingAction: pendingActions[`${change.group}:${change.path}`], onClick: event => handlers.openDiff(change, {
|
|
173
|
-
pin: event.ctrlKey || event.metaKey
|
|
174
|
-
}), actions: [
|
|
175
|
-
{
|
|
176
|
-
label: 'Unstage changes',
|
|
177
|
-
symbol: '−',
|
|
178
|
-
onClick: () => void onUnstage(change)
|
|
179
|
-
}
|
|
180
|
-
] })))),
|
|
181
|
-
React.createElement(ChangeSection, { label: "Changes", count: unstaged.length, collapsed: changesCollapsed, onToggleCollapsed: () => setChangesCollapsed(c => !c), actions: unstaged.length > 0
|
|
182
|
-
? [
|
|
183
|
-
{
|
|
184
|
-
label: 'Stage all changes',
|
|
185
|
-
symbol: '+',
|
|
186
|
-
onClick: onStageAll
|
|
187
|
-
}
|
|
188
|
-
]
|
|
189
|
-
: undefined }, unstaged.map(change => (React.createElement(ChangeRow, { key: `${change.group}:${change.path}`, change: change, pendingAction: pendingActions[`${change.group}:${change.path}`], onClick: event => handlers.openDiff(change, {
|
|
190
|
-
pin: event.ctrlKey || event.metaKey
|
|
191
|
-
}), actions: [
|
|
192
|
-
{
|
|
193
|
-
label: 'Discard changes',
|
|
194
|
-
symbol: '⟲',
|
|
195
|
-
onClick: () => void onDiscard(change)
|
|
196
|
-
},
|
|
197
|
-
{
|
|
198
|
-
label: 'Stage changes',
|
|
199
|
-
symbol: '+',
|
|
200
|
-
onClick: () => void onStage(change)
|
|
201
|
-
}
|
|
202
|
-
] })))),
|
|
203
|
-
staged.length === 0 && unstaged.length === 0 && !state.loading ? (React.createElement("div", { className: "jp-xtralab-GitPanel-empty" }, "No changes detected.")) : null))));
|
|
204
|
-
}
|
|
205
|
-
function PanelHeader(props) {
|
|
206
|
-
var _a;
|
|
207
|
-
const { topLevel, result, loading, error, onRefresh } = props;
|
|
208
|
-
const repoName = topLevel !== null
|
|
209
|
-
? ((_a = topLevel
|
|
210
|
-
.split('/')
|
|
211
|
-
.filter(s => s.length > 0)
|
|
212
|
-
.pop()) !== null && _a !== void 0 ? _a : topLevel)
|
|
213
|
-
: null;
|
|
214
|
-
return (React.createElement("div", { className: "jp-xtralab-GitPanel-header" },
|
|
215
|
-
React.createElement("div", { className: "jp-xtralab-GitPanel-headerInfo" },
|
|
216
|
-
repoName !== null ? (React.createElement("div", { className: "jp-xtralab-GitPanel-repo", title: topLevel !== null && topLevel !== void 0 ? topLevel : '' }, repoName)) : null,
|
|
217
|
-
(result === null || result === void 0 ? void 0 : result.branch) !== undefined && (result === null || result === void 0 ? void 0 : result.branch) !== null ? (React.createElement("div", { className: "jp-xtralab-GitPanel-branch" },
|
|
218
|
-
result.branch,
|
|
219
|
-
result.ahead > 0 ? React.createElement("span", null,
|
|
220
|
-
" \u2191",
|
|
221
|
-
result.ahead) : null,
|
|
222
|
-
result.behind > 0 ? React.createElement("span", null,
|
|
223
|
-
" \u2193",
|
|
224
|
-
result.behind) : null)) : null),
|
|
225
|
-
React.createElement("button", { type: "button", className: "jp-xtralab-GitPanel-iconButton", title: "Refresh", disabled: loading && error === null, onClick: onRefresh }, "\u27F3")));
|
|
226
|
-
}
|
|
227
|
-
function ChangeSection(props) {
|
|
228
|
-
const { label, count, collapsed, onToggleCollapsed, actions, children } = props;
|
|
229
|
-
return (React.createElement("div", { className: "jp-xtralab-GitPanel-section" },
|
|
230
|
-
React.createElement("div", { className: "jp-xtralab-GitPanel-sectionHeader", onClick: onToggleCollapsed },
|
|
231
|
-
React.createElement("span", { className: "jp-xtralab-GitPanel-sectionChevron" }, collapsed ? '▸' : '▾'),
|
|
232
|
-
React.createElement("span", { className: "jp-xtralab-GitPanel-sectionLabel" }, label),
|
|
233
|
-
actions !== undefined ? (React.createElement("span", { className: "jp-xtralab-GitPanel-sectionActions" }, actions.map(action => (React.createElement("button", { key: action.label, type: "button", className: "jp-xtralab-GitPanel-iconButton", title: action.label, onClick: event => {
|
|
234
|
-
event.stopPropagation();
|
|
235
|
-
action.onClick();
|
|
236
|
-
} }, action.symbol))))) : null,
|
|
237
|
-
React.createElement("span", { className: "jp-xtralab-GitPanel-sectionCount" }, count)),
|
|
238
|
-
!collapsed ? (React.createElement("div", { className: "jp-xtralab-GitPanel-sectionBody" }, children)) : null));
|
|
239
|
-
}
|
|
240
|
-
function ChangeRow(props) {
|
|
241
|
-
const { change, pendingAction, onClick, actions } = props;
|
|
242
|
-
const filename = basename(change.path);
|
|
243
|
-
const dirname = dirnameOrEmpty(change.path);
|
|
244
|
-
return (React.createElement("div", { className: "jp-xtralab-GitPanel-row", "data-status": change.status, title: change.from !== undefined
|
|
245
|
-
? `${change.from} → ${change.path}`
|
|
246
|
-
: change.path, onClick: onClick },
|
|
247
|
-
React.createElement("span", { className: "jp-xtralab-GitPanel-rowLabel" },
|
|
248
|
-
React.createElement("span", { className: "jp-xtralab-GitPanel-rowName" }, filename),
|
|
249
|
-
dirname !== '' ? (React.createElement("span", { className: "jp-xtralab-GitPanel-rowPath" }, dirname)) : null),
|
|
250
|
-
React.createElement("span", { className: "jp-xtralab-GitPanel-rowActions", "data-pending": pendingAction !== undefined }, actions.map(action => (React.createElement("button", { key: action.label, type: "button", className: "jp-xtralab-GitPanel-iconButton", title: action.label, disabled: pendingAction !== undefined, onClick: event => {
|
|
251
|
-
event.stopPropagation();
|
|
252
|
-
action.onClick();
|
|
253
|
-
} }, action.symbol)))),
|
|
254
|
-
React.createElement("span", { className: "jp-xtralab-GitPanel-rowBadge", "data-status": change.status, title: statusTooltip(change.status) }, statusBadge(change.status))));
|
|
255
|
-
}
|
|
256
|
-
function statusBadge(status) {
|
|
257
|
-
switch (status) {
|
|
258
|
-
case 'modified':
|
|
259
|
-
return 'M';
|
|
260
|
-
case 'added':
|
|
261
|
-
return 'A';
|
|
262
|
-
case 'deleted':
|
|
263
|
-
return 'D';
|
|
264
|
-
case 'renamed':
|
|
265
|
-
return 'R';
|
|
266
|
-
case 'untracked':
|
|
267
|
-
return 'U';
|
|
268
|
-
case 'unmerged':
|
|
269
|
-
return '!';
|
|
270
|
-
case 'typechange':
|
|
271
|
-
return 'T';
|
|
272
|
-
default:
|
|
273
|
-
return '?';
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
function statusTooltip(status) {
|
|
277
|
-
switch (status) {
|
|
278
|
-
case 'modified':
|
|
279
|
-
return 'Modified';
|
|
280
|
-
case 'added':
|
|
281
|
-
return 'Added';
|
|
282
|
-
case 'deleted':
|
|
283
|
-
return 'Deleted';
|
|
284
|
-
case 'renamed':
|
|
285
|
-
return 'Renamed';
|
|
286
|
-
case 'untracked':
|
|
287
|
-
return 'Untracked';
|
|
288
|
-
case 'unmerged':
|
|
289
|
-
return 'Unmerged (conflict)';
|
|
290
|
-
case 'typechange':
|
|
291
|
-
return 'Type changed';
|
|
292
|
-
default:
|
|
293
|
-
return 'Unknown';
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
function basename(path) {
|
|
297
|
-
const idx = path.lastIndexOf('/');
|
|
298
|
-
return idx < 0 ? path : path.slice(idx + 1);
|
|
299
|
-
}
|
|
300
|
-
function dirnameOrEmpty(path) {
|
|
301
|
-
const idx = path.lastIndexOf('/');
|
|
302
|
-
return idx < 0 ? '' : path.slice(0, idx);
|
|
303
|
-
}
|
package/src/git/icons.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
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/panel.tsx
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
|
|
3
|
-
import { ReactWidget } from '@jupyterlab/ui-components';
|
|
4
|
-
import { Signal, ISignal } from '@lumino/signaling';
|
|
5
|
-
|
|
6
|
-
import { gitIcon } from './icons';
|
|
7
|
-
import { GitPanelComponent, IGitPanelHandlers } from './panelComponent';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* The id and CSS class used for the git panel widget. The id ends up as the
|
|
11
|
-
* sidebar tab id (so layout restoration can find the widget) and the CSS
|
|
12
|
-
* class lets per-panel styles attach without leaking to other widgets.
|
|
13
|
-
*/
|
|
14
|
-
export const GIT_PANEL_ID = 'xtralab:git-panel';
|
|
15
|
-
export const GIT_PANEL_CSS_CLASS = 'jp-xtralab-GitPanel';
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* The lumino host widget for the git changes panel. Owns the `refresh`
|
|
19
|
-
* signal that the React component listens to, and exposes a typed callback
|
|
20
|
-
* surface (`handlers`) the React component uses to react to user actions.
|
|
21
|
-
*/
|
|
22
|
-
export class GitPanel extends ReactWidget {
|
|
23
|
-
constructor(handlers: IGitPanelHandlers) {
|
|
24
|
-
super();
|
|
25
|
-
this.id = GIT_PANEL_ID;
|
|
26
|
-
this.title.icon = gitIcon;
|
|
27
|
-
this.title.caption = 'Git Changes';
|
|
28
|
-
this.addClass(GIT_PANEL_CSS_CLASS);
|
|
29
|
-
this._handlers = handlers;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Public refresh hook called by the plugin when something happened that
|
|
34
|
-
* invalidates the current view (the user clicked the toolbar refresh, the
|
|
35
|
-
* file browser refreshed, a focused notebook saved, …).
|
|
36
|
-
*/
|
|
37
|
-
refresh(): void {
|
|
38
|
-
this._refreshRequested.emit();
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
get refreshRequested(): ISignal<this, void> {
|
|
42
|
-
return this._refreshRequested;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
protected render(): React.ReactElement {
|
|
46
|
-
return (
|
|
47
|
-
<GitPanelComponent
|
|
48
|
-
handlers={this._handlers}
|
|
49
|
-
refreshSignal={this._refreshRequested}
|
|
50
|
-
/>
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
private _handlers: IGitPanelHandlers;
|
|
55
|
-
private _refreshRequested = new Signal<this, void>(this);
|
|
56
|
-
}
|