Skip to content

Commit 63e543f

Browse files
author
winjo
committed
feat: 优化样式
1 parent 9c88234 commit 63e543f

5 files changed

Lines changed: 51 additions & 60 deletions

File tree

packages/alex/src/api/renderEditor.tsx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import { REPORT_NAME } from '@alipay/alex-core';
55
import { createEditor } from './createEditor';
66
import { Root } from '../core/Root';
77
import { RootProps, LandingProps } from '../core/types';
8-
import { themeStorage } from '../core/utils';
98
import { useConstant } from '../core/hooks';
109
import { IConfig, IAppInstance } from './types';
1110
import { EditorProps } from '../core/editor/types';
1211
import { Container } from '../core/editor/container';
1312
import { HIDE_EDITOR_TAB_CLASS_NAME } from '../core/constants';
13+
import styles from '../core/style.module.less';
1414

1515
interface IRenderProps extends IConfig {
1616
onLoad?(app: IAppInstance): void;
@@ -22,18 +22,17 @@ export type IEditorRenderProps = IRenderProps & EditorProps;
2222
export const renderEditor = (domElement: HTMLElement, props: IEditorRenderProps) => {
2323
const { onLoad, Landing, ...opts } = props;
2424
const app = createEditor(opts);
25-
const themeType = themeStorage.get();
26-
ReactDOM.render(<Root status="loading" theme={themeType} Landing={Landing} />, domElement);
25+
const className = `alex-editor ${
26+
opts.runtimeConfig.hideEditorTab ? styles['hide-editor-tab'] : ''
27+
}`;
28+
29+
ReactDOM.render(<Root status="loading" Landing={Landing} className={className} />, domElement);
2730

2831
app
2932
.start((appElement) => {
3033
return new Promise((resolve) => {
3134
ReactDOM.render(
32-
<Root
33-
status="success"
34-
theme={themeType}
35-
className={opts.runtimeConfig.hideEditorTab ? HIDE_EDITOR_TAB_CLASS_NAME : ''}
36-
>
35+
<Root status="success" className={className}>
3736
{appElement}
3837
</Root>,
3938
domElement,
@@ -46,7 +45,11 @@ export const renderEditor = (domElement: HTMLElement, props: IEditorRenderProps)
4645
})
4746
.catch((err: Error) => {
4847
ReactDOM.render(
49-
<Root status="error" error={err?.message || localize('error.unknown')} theme={themeType} />,
48+
<Root
49+
status="error"
50+
error={err?.message || localize('error.unknown')}
51+
className={className}
52+
/>,
5053
domElement
5154
);
5255

@@ -66,7 +69,6 @@ export const renderEditor = (domElement: HTMLElement, props: IEditorRenderProps)
6669

6770
export const EditorRenderer: React.FC<IEditorRenderProps> = ({ onLoad, Landing, ...opts }) => {
6871
const app = useConstant(() => createEditor(opts));
69-
const themeType = useConstant(() => themeStorage.get());
7072
const appElementRef = useRef<React.ReactElement | null>(null);
7173

7274
const [state, setState] = useState<{
@@ -106,13 +108,13 @@ export const EditorRenderer: React.FC<IEditorRenderProps> = ({ onLoad, Landing,
106108
}, []);
107109

108110
const rootClassName = useMemo(
109-
() => (opts.runtimeConfig.hideEditorTab ? HIDE_EDITOR_TAB_CLASS_NAME : ''),
111+
() => (opts.runtimeConfig.hideEditorTab ? styles['hide-editor-tab'] : ''),
110112
[opts.runtimeConfig.hideEditorTab]
111113
);
112114

113115
return (
114116
<Container value={{ documentModel: opts.documentModel }}>
115-
<Root {...state} theme={themeType} Landing={Landing} className={rootClassName}>
117+
<Root {...state} Landing={Landing} className={`alex-editor ${rootClassName}`}>
116118
{appElementRef.current}
117119
</Root>
118120
</Container>

packages/alex/src/core/editor/editor.module.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@ import {
44
BrowserModule,
55
ClientAppContribution,
66
URI,
7-
Uri,
87
Domain,
9-
getPreferenceThemeId,
108
CommandService,
119
PreferenceProvider,
1210
PreferenceScope,
13-
Emitter,
1411
CommandContribution,
1512
CommandRegistry,
1613
Disposable,
@@ -52,6 +49,7 @@ import { DirtyDiffWidget } from '@ali/ide-scm/lib/browser/dirty-diff/dirty-diff-
5249
import { IDETheme } from '../../core/extensions';
5350
import { select, onSelect } from './container';
5451
import { isCodeDocumentModel, CodeDocumentModel } from './types';
52+
import styles from '../style.module.less';
5553

5654
// TODO: 此处 diff 的 stage 和 revertChange 应该是 git 注册的,框架中直接添加了按钮,耦合,需要修复实现 scm/change/title
5755
// @ts-ignore
@@ -395,8 +393,8 @@ class EditorSpecialContribution
395393
{
396394
range: new monaco.Range(lineNumber, 1, lineNumber, 1),
397395
options: {
398-
className: 'alex-line-content',
399-
glyphMarginClassName: `alex-line-glyph-margin}`,
396+
className: styles['line-content'],
397+
glyphMarginClassName: styles['line-glyph-margin'],
400398
},
401399
},
402400
]);
@@ -410,13 +408,13 @@ class EditorSpecialContribution
410408
const highlightLine = (lineNumber: number) => {
411409
// 延迟高亮,否则不居中
412410
setTimeout(() => {
413-
editor.monacoEditor.revealLineInCenter(Number(lineNumber));
411+
editor.monacoEditor.revealLineInCenterIfOutsideViewport(Number(lineNumber));
414412
oldClickDecorations = editor.monacoEditor.deltaDecorations(oldClickDecorations, [
415413
{
416414
range: new monaco.Range(lineNumber, 1, lineNumber, 1),
417415
options: {
418416
isWholeLine: true,
419-
className: 'alex-line-content',
417+
className: styles['line-content'],
420418
},
421419
},
422420
]);

packages/alex/src/core/style.module.less

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,34 @@ alex-root {
4343
}
4444
}
4545

46+
.hide-editor-tab {
47+
[class^='kt_editor_group'] {
48+
> [class^='editorGroupHeader'] {
49+
display: none !important;
50+
}
51+
> [class^='kt_editor_body'] {
52+
height: 100% !important;
53+
}
54+
}
55+
}
56+
57+
.line-glyph-margin {
58+
cursor: pointer;
59+
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='64 64 896 896' focusable='false' data-icon='link' width='1em' height='1em' fill='currentColor' aria-hidden='true'%3E%3Cpath d='M574 665.4a8.03 8.03 0 00-11.3 0L446.5 781.6c-53.8 53.8-144.6 59.5-204 0-59.5-59.5-53.8-150.2 0-204l116.2-116.2c3.1-3.1 3.1-8.2 0-11.3l-39.8-39.8a8.03 8.03 0 00-11.3 0L191.4 526.5c-84.6 84.6-84.6 221.5 0 306s221.5 84.6 306 0l116.2-116.2c3.1-3.1 3.1-8.2 0-11.3L574 665.4zm258.6-474c-84.6-84.6-221.5-84.6-306 0L410.3 307.6a8.03 8.03 0 000 11.3l39.7 39.7c3.1 3.1 8.2 3.1 11.3 0l116.2-116.2c53.8-53.8 144.6-59.5 204 0 59.5 59.5 53.8 150.2 0 204L665.3 562.6a8.03 8.03 0 000 11.3l39.8 39.8c3.1 3.1 8.2 3.1 11.3 0l116.2-116.2c84.5-84.6 84.5-221.5 0-306.1zM610.1 372.3a8.03 8.03 0 00-11.3 0L372.3 598.7a8.03 8.03 0 000 11.3l39.6 39.6c3.1 3.1 8.2 3.1 11.3 0l226.4-226.4c3.1-3.1 3.1-8.2 0-11.3l-39.5-39.6z'%3E%3C/path%3E%3C/svg%3E");
60+
background-repeat: no-repeat;
61+
background-size: 12px 12px;
62+
background-position: center center;
63+
}
64+
65+
.line-glyph-margin ~ :global(.line-numbers) {
66+
text-decoration: underline;
67+
}
68+
69+
.line-content {
70+
background-color: #F90;
71+
opacity: 0.2;
72+
}
73+
4674
// override kaitian style
4775
:global {
4876
// fix image-preview style
@@ -52,33 +80,9 @@ alex-root {
5280
object-fit: contain;
5381
width: auto !important;
5482
}
55-
alex-root.alex-hide-editor-tab {
56-
[class^='kt_editor_group_'] {
57-
> [class^='editorGroupHeader_'] {
58-
display: none !important;
59-
}
60-
> [class^='kt_editor_body_'] {
61-
height: 100% !important;
62-
}
63-
}
64-
}
6583
}
6684

67-
:global {
68-
.alex-root {
69-
.alex-line-glyph-margin {
70-
cursor: pointer;
71-
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='64 64 896 896' focusable='false' data-icon='link' width='1em' height='1em' fill='currentColor' aria-hidden='true'%3E%3Cpath d='M574 665.4a8.03 8.03 0 00-11.3 0L446.5 781.6c-53.8 53.8-144.6 59.5-204 0-59.5-59.5-53.8-150.2 0-204l116.2-116.2c3.1-3.1 3.1-8.2 0-11.3l-39.8-39.8a8.03 8.03 0 00-11.3 0L191.4 526.5c-84.6 84.6-84.6 221.5 0 306s221.5 84.6 306 0l116.2-116.2c3.1-3.1 3.1-8.2 0-11.3L574 665.4zm258.6-474c-84.6-84.6-221.5-84.6-306 0L410.3 307.6a8.03 8.03 0 000 11.3l39.7 39.7c3.1 3.1 8.2 3.1 11.3 0l116.2-116.2c53.8-53.8 144.6-59.5 204 0 59.5 59.5 53.8 150.2 0 204L665.3 562.6a8.03 8.03 0 000 11.3l39.8 39.8c3.1 3.1 8.2 3.1 11.3 0l116.2-116.2c84.5-84.6 84.5-221.5 0-306.1zM610.1 372.3a8.03 8.03 0 00-11.3 0L372.3 598.7a8.03 8.03 0 000 11.3l39.6 39.6c3.1 3.1 8.2 3.1 11.3 0l226.4-226.4c3.1-3.1 3.1-8.2 0-11.3l-39.5-39.6z'%3E%3C/path%3E%3C/svg%3E");
72-
background-repeat: no-repeat;
73-
background-size: 12px 12px;
74-
background-position: center center;
75-
}
76-
.alex-line-glyph-margin ~ .line-numbers {
77-
text-decoration: underline;
78-
}
79-
.alex-line-content {
80-
background-color: #F90;
81-
opacity: 0.2;
82-
}
83-
}
85+
:global(.alex-editor) .landing {
86+
color: inherit;
87+
background-color: inherit;
8488
}

packages/alex/src/integration/editor/index.tsx

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -124,19 +124,6 @@ const App = () => {
124124
onLoad={(app) => {
125125
window.app = app;
126126
}}
127-
Landing={() => (
128-
<div
129-
style={{
130-
width: '100%',
131-
height: '100%',
132-
display: 'flex',
133-
alignItems: 'center',
134-
justifyContent: 'center',
135-
}}
136-
>
137-
<Spin />
138-
</div>
139-
)}
140127
appConfig={{
141128
workspaceDir: 'editor',
142129
defaultPreferences: {

packages/core/src/client/editor-empty/editor-empty.module.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
}
1212
p {
1313
font-size: 20px;
14-
color: var(--button-foreground);
14+
color: var(--foreground);
1515
}
1616
i {
1717
font-style: normal;

0 commit comments

Comments
 (0)