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.
Files changed (56) hide show
  1. package/LICENSE +28 -0
  2. package/README.md +69 -0
  3. package/lib/fileBrowser/commands.d.ts +62 -0
  4. package/lib/fileBrowser/commands.js +418 -0
  5. package/lib/fileBrowser/contents.d.ts +28 -0
  6. package/lib/fileBrowser/contents.js +48 -0
  7. package/lib/fileBrowser/fileBrowser.d.ts +24 -0
  8. package/lib/fileBrowser/fileBrowser.js +535 -0
  9. package/lib/fileBrowser/icons.d.ts +37 -0
  10. package/lib/fileBrowser/icons.js +153 -0
  11. package/lib/fileBrowser/index.d.ts +7 -0
  12. package/lib/fileBrowser/index.js +38 -0
  13. package/lib/fileBrowser/widget.d.ts +97 -0
  14. package/lib/fileBrowser/widget.js +95 -0
  15. package/lib/git/api.d.ts +39 -0
  16. package/lib/git/api.js +164 -0
  17. package/lib/git/commands.d.ts +69 -0
  18. package/lib/git/commands.js +67 -0
  19. package/lib/git/diffWidget.d.ts +108 -0
  20. package/lib/git/diffWidget.js +624 -0
  21. package/lib/git/icons.d.ts +14 -0
  22. package/lib/git/icons.js +19 -0
  23. package/lib/git/index.d.ts +11 -0
  24. package/lib/git/index.js +74 -0
  25. package/lib/git/notebookDiff.d.ts +176 -0
  26. package/lib/git/notebookDiff.js +805 -0
  27. package/lib/git/panel.d.ts +29 -0
  28. package/lib/git/panel.js +42 -0
  29. package/lib/git/panelComponent.d.ts +26 -0
  30. package/lib/git/panelComponent.js +300 -0
  31. package/lib/git/tokens.d.ts +78 -0
  32. package/lib/git/tokens.js +6 -0
  33. package/lib/index.d.ts +10 -0
  34. package/lib/index.js +14 -0
  35. package/package.json +216 -0
  36. package/schema/plugin.json +67 -0
  37. package/src/fileBrowser/commands.ts +507 -0
  38. package/src/fileBrowser/contents.ts +66 -0
  39. package/src/fileBrowser/fileBrowser.tsx +635 -0
  40. package/src/fileBrowser/icons.ts +172 -0
  41. package/src/fileBrowser/index.ts +56 -0
  42. package/src/fileBrowser/widget.tsx +202 -0
  43. package/src/git/api.ts +207 -0
  44. package/src/git/commands.ts +143 -0
  45. package/src/git/diffWidget.tsx +903 -0
  46. package/src/git/icons.ts +20 -0
  47. package/src/git/index.ts +109 -0
  48. package/src/git/notebookDiff.tsx +1294 -0
  49. package/src/git/panel.tsx +56 -0
  50. package/src/git/panelComponent.tsx +558 -0
  51. package/src/git/tokens.ts +91 -0
  52. package/src/index.ts +18 -0
  53. package/style/base.css +175 -0
  54. package/style/git.css +770 -0
  55. package/style/index.css +2 -0
  56. package/style/index.js +2 -0
@@ -0,0 +1,67 @@
1
+ import { refreshIcon } from '@jupyterlab/ui-components';
2
+ import { createGitDiffWidget, diffWidgetId } from './diffWidget';
3
+ /**
4
+ * Command IDs exposed by the git plugin. Both are registered in
5
+ * {@link registerGitCommands} so other extensions, the command palette and
6
+ * keybindings can drive the panel without going through the React internals.
7
+ */
8
+ export var CommandIDs;
9
+ (function (CommandIDs) {
10
+ CommandIDs.refresh = 'xtralab:git:refresh';
11
+ CommandIDs.openDiff = 'xtralab:git:open-diff';
12
+ })(CommandIDs || (CommandIDs = {}));
13
+ /**
14
+ * Register the git commands on the application command registry. Returns
15
+ * a disposer that clears the command palette items the registration created
16
+ * (the commands themselves stay registered for the lifetime of the plugin).
17
+ */
18
+ export function registerGitCommands(options) {
19
+ const { app, panel, themeManager, commandPalette, contentsManager, rendermime, onChanged, trackDiff, findDiff } = options;
20
+ const { commands } = app;
21
+ commands.addCommand(CommandIDs.refresh, {
22
+ label: 'Refresh Git Changes',
23
+ caption: 'Refresh the git changes panel',
24
+ icon: refreshIcon,
25
+ execute: () => {
26
+ panel.refresh();
27
+ }
28
+ });
29
+ commands.addCommand(CommandIDs.openDiff, {
30
+ label: 'Open Git Diff',
31
+ caption: 'Open a side-by-side diff for a changed file',
32
+ execute: async (args) => {
33
+ const typed = args;
34
+ if ((typed === null || typed === void 0 ? void 0 : typed.change) === undefined) {
35
+ return;
36
+ }
37
+ const existing = findDiff(typed.change);
38
+ if (existing !== undefined && !existing.isDisposed) {
39
+ app.shell.activateById(existing.id);
40
+ return;
41
+ }
42
+ const widget = createGitDiffWidget({
43
+ repoPath: typed.repoPath,
44
+ change: typed.change,
45
+ themeManager,
46
+ contentsManager,
47
+ rendermime,
48
+ onChanged
49
+ });
50
+ await trackDiff(widget);
51
+ app.shell.add(widget, 'main', { mode: 'tab-after' });
52
+ app.shell.activateById(widget.id);
53
+ }
54
+ });
55
+ const paletteItems = commandPalette
56
+ ? [
57
+ commandPalette.addItem({
58
+ command: CommandIDs.refresh,
59
+ category: 'Git'
60
+ })
61
+ ]
62
+ : [];
63
+ return () => {
64
+ paletteItems.forEach(item => item.dispose());
65
+ };
66
+ }
67
+ export { diffWidgetId };
@@ -0,0 +1,108 @@
1
+ import * as React from 'react';
2
+ import { IThemeManager, MainAreaWidget } from '@jupyterlab/apputils';
3
+ import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
4
+ import { Contents } from '@jupyterlab/services';
5
+ import { ReactWidget } from '@jupyterlab/ui-components';
6
+ import { ISignal } from '@lumino/signaling';
7
+ import { GitReference, IFileChange } from './tokens';
8
+ /**
9
+ * The CSS class added to the diff main-area widget. The selectors that
10
+ * style the embedded `@pierre/diffs` viewer hang off this class.
11
+ */
12
+ export declare const DIFF_WIDGET_CSS_CLASS = "jp-xtralab-DiffWidget";
13
+ /**
14
+ * View modes available for `.ipynb` diffs. `notebook` is the cell-by-cell
15
+ * rendered view; `json` falls back to the raw nbformat JSON file diff so
16
+ * the user can inspect exactly which bytes changed (handy for nbformat
17
+ * spelunking, seeing execution_count drift, etc.).
18
+ */
19
+ type NotebookDiffViewMode = 'notebook' | 'json';
20
+ /**
21
+ * Build the deterministic widget id used for a diff against a particular
22
+ * file/group pair. Reused across plugin and command code so reopening a
23
+ * diff for the same file reveals the existing tab instead of opening a
24
+ * second one.
25
+ */
26
+ export declare function diffWidgetId(change: IFileChange): string;
27
+ /**
28
+ * Resolve the pair of git references whose `content` should appear on the
29
+ * left and right side of the diff for a given file change. Mirrors VS
30
+ * Code's source control diff: staged-side compares INDEX vs HEAD,
31
+ * unstaged-side compares WORKING vs INDEX, and untracked files have no
32
+ * "previous" version to compare against.
33
+ */
34
+ export declare function resolveReferences(change: IFileChange): {
35
+ oldRef: GitReference | null;
36
+ newRef: GitReference | null;
37
+ };
38
+ export interface IGitDiffWidgetOptions {
39
+ repoPath: string;
40
+ change: IFileChange;
41
+ themeManager: IThemeManager | null;
42
+ contentsManager: Contents.IManager;
43
+ /**
44
+ * Rendermime registry used by the notebook diff path to render outputs
45
+ * and markdown cells. May be `null` in stripped-down hosts; the notebook
46
+ * diff falls back to a textual representation in that case.
47
+ */
48
+ rendermime: IRenderMimeRegistry | null;
49
+ /**
50
+ * Called after a hunk-level operation mutates the working tree, so the
51
+ * surrounding plugin can refresh the changes panel.
52
+ */
53
+ onChanged: () => void;
54
+ /**
55
+ * Called when a post-discard reload finds no hunks left in the diff.
56
+ * Wired by {@link createGitDiffWidget} to close the host
57
+ * `MainAreaWidget` — there is nothing left to view, so the empty pane
58
+ * would just be visual noise.
59
+ */
60
+ onEmpty?: () => void;
61
+ }
62
+ /**
63
+ * Build a `MainAreaWidget`-hosted diff viewer for a single file change.
64
+ * Wrapping the `ReactWidget` in a `MainAreaWidget` is what gives it the
65
+ * usual document chrome — toolbar slot, focus tracker integration, and
66
+ * spinner-while-loading hooks — and matches the pattern used for other
67
+ * read-only main-area widgets in the JupyterLab ecosystem.
68
+ */
69
+ export declare function createGitDiffWidget(options: IGitDiffWidgetOptions): MainAreaWidget<DiffContentWidget>;
70
+ /**
71
+ * The actual React-rendered region of the diff viewer. Held in its own
72
+ * `ReactWidget` so the surrounding `MainAreaWidget` can manage chrome
73
+ * without React having to know about it.
74
+ *
75
+ * Owns the persistent UI state that the surrounding `MainAreaWidget`
76
+ * toolbar needs to read and write (`notebookViewMode` and whether a
77
+ * notebook view is even available for the current file). Storing this on
78
+ * the widget — and exposing change signals — lets the toolbar widget and
79
+ * the React content stay in sync without either side knowing about the
80
+ * other.
81
+ */
82
+ export declare class DiffContentWidget extends ReactWidget {
83
+ constructor(options: IGitDiffWidgetOptions);
84
+ /** The change this widget renders, used by callers to identify the widget. */
85
+ get change(): IFileChange;
86
+ /** The user's current rendered-vs-JSON view choice for notebook diffs. */
87
+ get notebookViewMode(): NotebookDiffViewMode;
88
+ /** Update the notebook view mode and persist it across sessions. */
89
+ setNotebookViewMode(mode: NotebookDiffViewMode): void;
90
+ /** Emits whenever {@link notebookViewMode} changes. */
91
+ get notebookViewModeChanged(): ISignal<this, NotebookDiffViewMode>;
92
+ /**
93
+ * Whether a rendered notebook view is currently available. Set by the
94
+ * React content once it has parsed the diff; the toolbar reads this to
95
+ * decide whether to show the view-mode selector.
96
+ */
97
+ get hasNotebookView(): boolean;
98
+ setHasNotebookView(value: boolean): void;
99
+ /** Emits whenever {@link hasNotebookView} changes. */
100
+ get hasNotebookViewChanged(): ISignal<this, boolean>;
101
+ protected render(): React.ReactElement;
102
+ private _options;
103
+ private _notebookViewMode;
104
+ private _notebookViewModeChanged;
105
+ private _hasNotebookView;
106
+ private _hasNotebookViewChanged;
107
+ }
108
+ export {};