Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Commit 14c7d1c

Browse files
authored
Merge pull request #48 from wonsjb/refactor
Cleanup of plugin dependencies to jupyterlab
2 parents b705507 + b8196a6 commit 14c7d1c

File tree

8 files changed

+444
-503
lines changed

8 files changed

+444
-503
lines changed

src/ShortcutWidget.tsx

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,60 +2,53 @@ import { VDomRenderer, VDomModel } from '@jupyterlab/apputils';
22

33
import * as React from 'react';
44

5-
import { JupyterFrontEnd } from '@jupyterlab/application';
6-
75
import { ShortcutUI } from './components/ShortcutUI';
86

97
import { ISettingRegistry } from '@jupyterlab/coreutils';
108

119
import { CommandRegistry } from '@phosphor/commands';
1210

13-
import { Widget, Title } from '@phosphor/widgets';
11+
import { Widget, Title, Menu } from '@phosphor/widgets';
1412

1513
import * as ReactDOM from 'react-dom';
14+
import { IDisposable } from '@phosphor/disposable';
15+
16+
/** All external actions, setting commands, getting command list ... */
17+
export interface IShortcutUIexternal {
18+
getAllShortCutSettings: () => Promise<ISettingRegistry.ISettings>;
19+
removeShortCut: (key: String) => Promise<void>;
20+
openAdvanced: () => void;
21+
createMenu: () => Menu;
22+
hasCommand: (id: string) => boolean;
23+
addCommand: (
24+
id: string,
25+
options: CommandRegistry.ICommandOptions
26+
) => IDisposable;
27+
getLabel: (id: string) => string;
28+
}
1629

1730
export default class ShortcutWidget extends VDomRenderer<VDomModel> {
1831
height: number;
1932
width: number;
20-
commandList: string[];
21-
settingRegistry: ISettingRegistry;
22-
shortcutPlugin: string;
23-
commandRegistry: CommandRegistry;
33+
external: IShortcutUIexternal;
2434
id: string;
2535
isAttached: boolean;
2636
title: Title<Widget>;
2737
reactComponent: React.ReactElement<any>;
28-
app: JupyterFrontEnd;
2938

30-
constructor(
31-
height: number,
32-
width: number,
33-
commandList: string[],
34-
settingRegistry: ISettingRegistry,
35-
commandRegistry: CommandRegistry,
36-
shortcutPlugin: string,
37-
app: JupyterFrontEnd
38-
) {
39+
constructor(external: IShortcutUIexternal) {
3940
super();
40-
this.height = height;
41-
this.width = width;
42-
this.commandList = commandList;
43-
this.settingRegistry = settingRegistry;
44-
this.commandRegistry = commandRegistry;
45-
this.shortcutPlugin = shortcutPlugin;
46-
this.app = app;
41+
this.height = -1;
42+
this.width = -1;
43+
this.external = external;
4744
}
4845

4946
protected onUpdateRequest(): void {
5047
this.reactComponent = (
5148
<ShortcutUI
52-
commandList={this.commandList}
53-
settingRegistry={this.settingRegistry}
54-
shortcutPlugin={this.shortcutPlugin}
55-
commandRegistry={this.commandRegistry}
49+
external={this.external}
5650
height={this.height}
5751
width={this.width}
58-
app={this.app}
5952
/>
6053
);
6154
ReactDOM.render(

src/componentStyle/ShortcutItemStyle.tsx

Lines changed: 18 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { style } from 'typestyle';
2+
import { UISize } from '../components/ShortcutUI';
23

34
export const CellStyle = style({
45
padding: '6px 12px',
@@ -17,15 +18,11 @@ export const EmptyShortcutCellStyle = style({
1718
height: '32px',
1819

1920
$nest: {
20-
'& #add-link': {
21-
//marginLeft: 'auto'
22-
}
21+
'& #add-link': {}
2322
}
2423
});
2524

26-
export const SingleShortcutCellStyle = style({
27-
//justifyContent: 'space-between'
28-
});
25+
export const SingleShortcutCellStyle = style({});
2926

3027
export const RowStyle = style({
3128
padding: '10px',
@@ -51,32 +48,24 @@ export const RowStyle = style({
5148
}
5249
});
5350

51+
function getMarginLeft(showSelectors: boolean, errorSize: UISize): string {
52+
if (errorSize === UISize.Regular) {
53+
return showSelectors ? '20%' : '25%';
54+
} else {
55+
return '0';
56+
}
57+
}
58+
5459
export function ConflictContainerStyle(
5560
showSelectors: boolean,
56-
errorSize: string
61+
errorSize: UISize
5762
) {
58-
if (showSelectors && errorSize === 'regular') {
59-
return style({
60-
display: 'flex',
61-
flexWrap: 'wrap',
62-
padding: '6px 12px',
63-
marginLeft: '20%'
64-
});
65-
} else if (!showSelectors && errorSize === 'regular') {
66-
return style({
67-
display: 'flex',
68-
flexWrap: 'wrap',
69-
padding: '6px 12px',
70-
marginLeft: '25%'
71-
});
72-
} else {
73-
return style({
74-
display: 'flex',
75-
flexWrap: 'wrap',
76-
padding: '6px 12px',
77-
marginLeft: '0'
78-
});
79-
}
63+
return style({
64+
display: 'flex',
65+
flexWrap: 'wrap',
66+
padding: '6px 12px',
67+
marginLeft: getMarginLeft(showSelectors, errorSize)
68+
});
8069
}
8170

8271
export const ErrorMessageStyle = style({
@@ -185,18 +174,6 @@ export const CommaStyle = style({
185174
});
186175

187176
export const PlusStyle = style({
188-
// backgroundColor: 'var(--jp-brand-color2)',
189-
// color: 'var(--jp-layout-color0)',
190-
// textDecoration: 'none',
191-
// display: 'block',
192-
// textAlign: 'center',
193-
// textTransform: 'uppercase',
194-
// boxSizing: 'border-box',
195-
// padding: '0px 12px',
196-
// height: '30px',
197-
// lineHeight: '30px',
198-
// border: '1px solid var(--jp-brand-color1)',
199-
200177
display: 'none',
201178
background: 'var(--jp-brand-color3)',
202179
borderColor: 'var(--jp-layout-color0)',

src/componentStyle/TopNavStyle.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { style } from 'typestyle';
2+
import { UISize } from '../components/ShortcutUI';
23

34
export const TopStyle = style({
45
display: 'block'
@@ -95,8 +96,8 @@ export const AdvancedOptionsRightStyle = style({
9596
marginTop: '8px'
9697
});
9798

98-
export function AdvancedOptionsLinkStyle(size: string) {
99-
if (size === 'regular') {
99+
export function AdvancedOptionsLinkStyle(size: UISize) {
100+
if (size === UISize.Regular) {
100101
return style({
101102
color: 'var(--jp-brand-color2)',
102103
textDecoration: 'none',

0 commit comments

Comments
 (0)