@finos/legend-lego 0.1.4 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/application/DocumentationLink.d.ts +27 -0
- package/lib/application/DocumentationLink.d.ts.map +1 -0
- package/lib/application/DocumentationLink.js +45 -0
- package/lib/application/DocumentationLink.js.map +1 -0
- package/lib/application/FuzzySearchAdvancedConfigMenu.d.ts +23 -0
- package/lib/application/FuzzySearchAdvancedConfigMenu.d.ts.map +1 -0
- package/lib/application/FuzzySearchAdvancedConfigMenu.js +35 -0
- package/lib/application/FuzzySearchAdvancedConfigMenu.js.map +1 -0
- package/lib/application/TabManager.d.ts +24 -0
- package/lib/application/TabManager.d.ts.map +1 -0
- package/lib/application/TabManager.js +117 -0
- package/lib/application/TabManager.js.map +1 -0
- package/lib/application/TabManagerState.d.ts +40 -0
- package/lib/application/TabManagerState.d.ts.map +1 -0
- package/lib/application/TabManagerState.js +93 -0
- package/lib/application/TabManagerState.js.map +1 -0
- package/lib/application/index.d.ts +20 -0
- package/lib/application/index.d.ts.map +1 -0
- package/lib/application/index.js +20 -0
- package/lib/application/index.js.map +1 -0
- package/lib/code-editor/CodeDiffView.d.ts +35 -0
- package/lib/code-editor/CodeDiffView.d.ts.map +1 -0
- package/lib/code-editor/CodeDiffView.js +78 -0
- package/lib/code-editor/CodeDiffView.js.map +1 -0
- package/lib/code-editor/CodeEditor.d.ts +1 -1
- package/lib/code-editor/CodeEditor.d.ts.map +1 -1
- package/lib/code-editor/CodeEditor.js +5 -3
- package/lib/code-editor/CodeEditor.js.map +1 -1
- package/lib/code-editor/CodeEditorConfig.d.ts +31 -0
- package/lib/code-editor/CodeEditorConfig.d.ts.map +1 -0
- package/lib/code-editor/CodeEditorConfig.js +33 -0
- package/lib/code-editor/CodeEditorConfig.js.map +1 -0
- package/lib/code-editor/CodeEditorUtils.d.ts +2 -0
- package/lib/code-editor/CodeEditorUtils.d.ts.map +1 -1
- package/lib/code-editor/CodeEditorUtils.js +46 -1
- package/lib/code-editor/CodeEditorUtils.js.map +1 -1
- package/lib/code-editor/PureLanguageCodeEditorSupport.d.ts +70 -0
- package/lib/code-editor/PureLanguageCodeEditorSupport.d.ts.map +1 -0
- package/lib/code-editor/PureLanguageCodeEditorSupport.js +237 -0
- package/lib/code-editor/PureLanguageCodeEditorSupport.js.map +1 -0
- package/lib/code-editor/PureLanguageService.d.ts +42 -0
- package/lib/code-editor/PureLanguageService.d.ts.map +1 -0
- package/lib/code-editor/PureLanguageService.js +437 -0
- package/lib/code-editor/PureLanguageService.js.map +1 -0
- package/lib/code-editor/__test-utils__/MockedMonacoEditor.d.ts.map +1 -0
- package/lib/code-editor/__test-utils__/MockedMonacoEditor.js.map +1 -0
- package/lib/code-editor/__test-utils__/MonacoEditorMockUtils.d.ts.map +1 -0
- package/lib/code-editor/{testing → __test-utils__}/MonacoEditorMockUtils.js +1 -1
- package/lib/code-editor/__test-utils__/MonacoEditorMockUtils.js.map +1 -0
- package/lib/code-editor/__test__.d.ts +17 -0
- package/lib/code-editor/__test__.d.ts.map +1 -0
- package/lib/code-editor/{testing/index.js → __test__.js} +2 -2
- package/lib/code-editor/__test__.js.map +1 -0
- package/lib/code-editor/index.d.ts +4 -0
- package/lib/code-editor/index.d.ts.map +1 -1
- package/lib/code-editor/index.js +4 -0
- package/lib/code-editor/index.js.map +1 -1
- package/lib/graph-editor/ElementIconUtils.d.ts +18 -0
- package/lib/graph-editor/ElementIconUtils.d.ts.map +1 -0
- package/lib/graph-editor/ElementIconUtils.js +37 -0
- package/lib/graph-editor/ElementIconUtils.js.map +1 -0
- package/lib/graph-editor/PackageableElementOption.d.ts +25 -0
- package/lib/graph-editor/PackageableElementOption.d.ts.map +1 -0
- package/lib/graph-editor/PackageableElementOption.js +46 -0
- package/lib/graph-editor/PackageableElementOption.js.map +1 -0
- package/lib/graph-editor/index.d.ts +18 -0
- package/lib/graph-editor/index.d.ts.map +1 -0
- package/lib/graph-editor/index.js +18 -0
- package/lib/graph-editor/index.js.map +1 -0
- package/lib/index.css +2 -2
- package/lib/index.css.map +1 -1
- package/package.json +14 -9
- package/src/application/DocumentationLink.tsx +82 -0
- package/src/application/FuzzySearchAdvancedConfigMenu.tsx +66 -0
- package/src/application/TabManager.tsx +285 -0
- package/src/application/TabManagerState.ts +124 -0
- package/src/application/index.ts +22 -0
- package/src/code-editor/CodeDiffView.tsx +128 -0
- package/src/code-editor/CodeEditor.tsx +8 -5
- package/src/code-editor/CodeEditorConfig.ts +32 -0
- package/src/code-editor/CodeEditorUtils.ts +76 -1
- package/src/code-editor/PureLanguageCodeEditorSupport.ts +338 -0
- package/src/code-editor/PureLanguageService.ts +501 -0
- package/src/code-editor/{testing → __test-utils__}/MonacoEditorMockUtils.tsx +1 -1
- package/src/code-editor/{testing/index.ts → __test__.ts} +1 -1
- package/src/code-editor/index.ts +8 -0
- package/src/graph-editor/ElementIconUtils.tsx +47 -0
- package/src/graph-editor/PackageableElementOption.tsx +86 -0
- package/{lib/code-editor/testing/index.d.ts → src/graph-editor/index.ts} +3 -2
- package/tsconfig.json +16 -4
- package/lib/code-editor/testing/MockedMonacoEditor.d.ts.map +0 -1
- package/lib/code-editor/testing/MockedMonacoEditor.js.map +0 -1
- package/lib/code-editor/testing/MonacoEditorMockUtils.d.ts.map +0 -1
- package/lib/code-editor/testing/MonacoEditorMockUtils.js.map +0 -1
- package/lib/code-editor/testing/index.d.ts.map +0 -1
- package/lib/code-editor/testing/index.js.map +0 -1
- /package/lib/code-editor/{testing → __test-utils__}/MockedMonacoEditor.d.ts +0 -0
- /package/lib/code-editor/{testing → __test-utils__}/MockedMonacoEditor.js +0 -0
- /package/lib/code-editor/{testing → __test-utils__}/MonacoEditorMockUtils.d.ts +0 -0
- /package/src/code-editor/{testing → __test-utils__}/MockedMonacoEditor.ts +0 -0
@@ -0,0 +1,124 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) 2020-present, Goldman Sachs
|
3
|
+
*
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
* you may not use this file except in compliance with the License.
|
6
|
+
* You may obtain a copy of the License at
|
7
|
+
*
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
*
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
* See the License for the specific language governing permissions and
|
14
|
+
* limitations under the License.
|
15
|
+
*/
|
16
|
+
|
17
|
+
import {
|
18
|
+
assertNonNullable,
|
19
|
+
assertTrue,
|
20
|
+
swapEntry,
|
21
|
+
uuid,
|
22
|
+
} from '@finos/legend-shared';
|
23
|
+
import { action, makeObservable, observable } from 'mobx';
|
24
|
+
|
25
|
+
export abstract class TabState {
|
26
|
+
readonly uuid = uuid();
|
27
|
+
|
28
|
+
abstract get label(): string;
|
29
|
+
|
30
|
+
get description(): string | undefined {
|
31
|
+
return undefined;
|
32
|
+
}
|
33
|
+
|
34
|
+
match(tab: TabState): boolean {
|
35
|
+
return this === tab;
|
36
|
+
}
|
37
|
+
|
38
|
+
onOpen(): void {
|
39
|
+
// do nothing
|
40
|
+
}
|
41
|
+
|
42
|
+
onClose(): void {
|
43
|
+
// do nothing
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
export abstract class TabManagerState {
|
48
|
+
currentTab?: TabState | undefined;
|
49
|
+
tabs: TabState[] = [];
|
50
|
+
|
51
|
+
constructor() {
|
52
|
+
makeObservable(this, {
|
53
|
+
currentTab: observable,
|
54
|
+
tabs: observable,
|
55
|
+
setCurrentTab: action,
|
56
|
+
closeTab: action,
|
57
|
+
closeAllTabs: action,
|
58
|
+
closeAllOtherTabs: action,
|
59
|
+
openTab: action,
|
60
|
+
swapTabs: action,
|
61
|
+
});
|
62
|
+
}
|
63
|
+
|
64
|
+
setCurrentTab(val: TabState | undefined): void {
|
65
|
+
this.currentTab = val;
|
66
|
+
}
|
67
|
+
|
68
|
+
closeAllOtherTabs(tab: TabState): void {
|
69
|
+
assertNonNullable(
|
70
|
+
this.tabs.find((e) => e === tab),
|
71
|
+
'Specified tab should be currently opened',
|
72
|
+
);
|
73
|
+
this.setCurrentTab(tab);
|
74
|
+
this.tabs = [tab];
|
75
|
+
}
|
76
|
+
|
77
|
+
closeAllTabs(): void {
|
78
|
+
this.setCurrentTab(undefined);
|
79
|
+
this.tabs = [];
|
80
|
+
}
|
81
|
+
|
82
|
+
swapTabs(tab1: TabState, tab2: TabState): void {
|
83
|
+
swapEntry(this.tabs, tab1, tab2);
|
84
|
+
}
|
85
|
+
|
86
|
+
/**
|
87
|
+
* The unique drag and drop type
|
88
|
+
* See https://react-dnd.github.io/react-dnd/docs/overview#items-and-types
|
89
|
+
*/
|
90
|
+
abstract get dndType(): string;
|
91
|
+
|
92
|
+
openTab(tab: TabState): void {
|
93
|
+
const existingTab = this.tabs.find((t) => t.match(tab));
|
94
|
+
if (!existingTab) {
|
95
|
+
if (this.currentTab) {
|
96
|
+
const currIndex = this.tabs.findIndex((e) => e === this.currentTab);
|
97
|
+
this.tabs.splice(currIndex + 1, 0, tab);
|
98
|
+
} else {
|
99
|
+
this.tabs.push(tab);
|
100
|
+
}
|
101
|
+
}
|
102
|
+
this.setCurrentTab(tab);
|
103
|
+
|
104
|
+
tab.onOpen();
|
105
|
+
}
|
106
|
+
|
107
|
+
closeTab(tab: TabState): void {
|
108
|
+
const tabIndex = this.tabs.findIndex((t) => t.match(tab));
|
109
|
+
assertTrue(tabIndex !== -1, `Can't close a tab which is not opened`);
|
110
|
+
this.tabs.splice(tabIndex, 1);
|
111
|
+
if (this.currentTab === tab) {
|
112
|
+
if (this.tabs.length) {
|
113
|
+
const openIndex = tabIndex - 1;
|
114
|
+
this.setCurrentTab(
|
115
|
+
openIndex >= 0 ? this.tabs[openIndex] : this.tabs[0],
|
116
|
+
);
|
117
|
+
} else {
|
118
|
+
this.setCurrentTab(undefined);
|
119
|
+
}
|
120
|
+
}
|
121
|
+
|
122
|
+
tab.onClose();
|
123
|
+
}
|
124
|
+
}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) 2020-present, Goldman Sachs
|
3
|
+
*
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
* you may not use this file except in compliance with the License.
|
6
|
+
* You may obtain a copy of the License at
|
7
|
+
*
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
*
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
* See the License for the specific language governing permissions and
|
14
|
+
* limitations under the License.
|
15
|
+
*/
|
16
|
+
|
17
|
+
export * from './DocumentationLink.js';
|
18
|
+
|
19
|
+
export * from './TabManager.js';
|
20
|
+
export * from './TabManagerState.js';
|
21
|
+
|
22
|
+
export * from './FuzzySearchAdvancedConfigMenu.js';
|
@@ -0,0 +1,128 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) 2020-present, Goldman Sachs
|
3
|
+
*
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
* you may not use this file except in compliance with the License.
|
6
|
+
* You may obtain a copy of the License at
|
7
|
+
*
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
*
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
* See the License for the specific language governing permissions and
|
14
|
+
* limitations under the License.
|
15
|
+
*/
|
16
|
+
|
17
|
+
import { useEffect, useState, useRef } from 'react';
|
18
|
+
import { observer } from 'mobx-react-lite';
|
19
|
+
import { editor as monacoEditorAPI } from 'monaco-editor';
|
20
|
+
import {
|
21
|
+
DEFAULT_TAB_SIZE,
|
22
|
+
useApplicationStore,
|
23
|
+
} from '@finos/legend-application';
|
24
|
+
import { useResizeDetector } from '@finos/legend-art';
|
25
|
+
import {
|
26
|
+
isString,
|
27
|
+
stringifyLosslessJSON,
|
28
|
+
tryToFormatJSONString,
|
29
|
+
tryToFormatLosslessJSONString,
|
30
|
+
} from '@finos/legend-shared';
|
31
|
+
import {
|
32
|
+
disposeDiffCodeEditor,
|
33
|
+
getBaseCodeEditorOptions,
|
34
|
+
} from './CodeEditorUtils.js';
|
35
|
+
import { CODE_EDITOR_LANGUAGE, CODE_EDITOR_THEME } from './CodeEditorConfig.js';
|
36
|
+
|
37
|
+
export const CodeDiffView = observer(
|
38
|
+
(props: {
|
39
|
+
language: CODE_EDITOR_LANGUAGE;
|
40
|
+
from?: string | undefined;
|
41
|
+
to?: string | undefined;
|
42
|
+
}) => {
|
43
|
+
const { from, to, language } = props;
|
44
|
+
const applicationStore = useApplicationStore();
|
45
|
+
const [editor, setEditor] =
|
46
|
+
useState<monacoEditorAPI.IStandaloneDiffEditor>();
|
47
|
+
const editorRef = useRef<HTMLDivElement>(null);
|
48
|
+
const originalText = from ?? '';
|
49
|
+
const modifiedText = to ?? '';
|
50
|
+
|
51
|
+
const { ref, width, height } = useResizeDetector<HTMLDivElement>();
|
52
|
+
|
53
|
+
useEffect(() => {
|
54
|
+
if (width !== undefined && height !== undefined) {
|
55
|
+
editor?.layout({ width, height });
|
56
|
+
}
|
57
|
+
}, [editor, width, height]);
|
58
|
+
|
59
|
+
useEffect(() => {
|
60
|
+
if (!editor && editorRef.current) {
|
61
|
+
const element = editorRef.current;
|
62
|
+
const _editor = monacoEditorAPI.createDiffEditor(element, {
|
63
|
+
...getBaseCodeEditorOptions(),
|
64
|
+
theme: CODE_EDITOR_THEME.LEGEND,
|
65
|
+
readOnly: true,
|
66
|
+
});
|
67
|
+
setEditor(_editor);
|
68
|
+
}
|
69
|
+
}, [applicationStore, editor]);
|
70
|
+
|
71
|
+
if (editor) {
|
72
|
+
const originalModel = monacoEditorAPI.createModel(originalText, language);
|
73
|
+
const modifiedModel = monacoEditorAPI.createModel(modifiedText, language);
|
74
|
+
editor.setModel({
|
75
|
+
original: originalModel,
|
76
|
+
modified: modifiedModel,
|
77
|
+
});
|
78
|
+
}
|
79
|
+
|
80
|
+
// dispose editor
|
81
|
+
useEffect(
|
82
|
+
() => (): void => {
|
83
|
+
if (editor) {
|
84
|
+
disposeDiffCodeEditor(editor);
|
85
|
+
}
|
86
|
+
},
|
87
|
+
[editor],
|
88
|
+
);
|
89
|
+
|
90
|
+
return (
|
91
|
+
<div ref={ref} className="code-editor__container">
|
92
|
+
<div className="code-editor__body" ref={editorRef} />
|
93
|
+
</div>
|
94
|
+
);
|
95
|
+
},
|
96
|
+
);
|
97
|
+
|
98
|
+
const formatJSONLikeValue = (value: unknown, lossless: boolean): string =>
|
99
|
+
value
|
100
|
+
? isString(value)
|
101
|
+
? lossless
|
102
|
+
? tryToFormatLosslessJSONString(value)
|
103
|
+
: tryToFormatJSONString(value)
|
104
|
+
: lossless
|
105
|
+
? stringifyLosslessJSON(value, undefined, DEFAULT_TAB_SIZE)
|
106
|
+
: JSON.stringify(value, undefined, DEFAULT_TAB_SIZE)
|
107
|
+
: '';
|
108
|
+
|
109
|
+
export const JSONDiffView = observer(
|
110
|
+
(props: {
|
111
|
+
from?: unknown;
|
112
|
+
to?: unknown;
|
113
|
+
/**
|
114
|
+
* Use lossless algorithm while parsing/stringifying JSON-like value
|
115
|
+
*/
|
116
|
+
lossless?: boolean;
|
117
|
+
}) => {
|
118
|
+
const { from, to, lossless } = props;
|
119
|
+
|
120
|
+
return (
|
121
|
+
<CodeDiffView
|
122
|
+
language={CODE_EDITOR_LANGUAGE.JSON}
|
123
|
+
from={formatJSONLikeValue(from, Boolean(lossless))}
|
124
|
+
to={formatJSONLikeValue(to, Boolean(lossless))}
|
125
|
+
/>
|
126
|
+
);
|
127
|
+
},
|
128
|
+
);
|
@@ -25,11 +25,13 @@ import {
|
|
25
25
|
} from './CodeEditorUtils.js';
|
26
26
|
import { useResizeDetector } from '@finos/legend-art';
|
27
27
|
import {
|
28
|
-
|
29
|
-
CODE_EDITOR_THEME,
|
30
|
-
TAB_SIZE,
|
28
|
+
DEFAULT_TAB_SIZE,
|
31
29
|
useApplicationStore,
|
32
30
|
} from '@finos/legend-application';
|
31
|
+
import {
|
32
|
+
CODE_EDITOR_THEME,
|
33
|
+
type CODE_EDITOR_LANGUAGE,
|
34
|
+
} from './CodeEditorConfig.js';
|
33
35
|
|
34
36
|
export const CodeEditor: React.FC<{
|
35
37
|
inputValue: string;
|
@@ -137,9 +139,10 @@ export const CodeEditor: React.FC<{
|
|
137
139
|
...(extraEditorOptions ?? {}),
|
138
140
|
});
|
139
141
|
const model = editor.getModel();
|
140
|
-
model?.updateOptions({ tabSize:
|
142
|
+
model?.updateOptions({ tabSize: DEFAULT_TAB_SIZE });
|
141
143
|
}
|
142
144
|
|
145
|
+
// dispose editor
|
143
146
|
useEffect(
|
144
147
|
() => (): void => {
|
145
148
|
if (editor) {
|
@@ -147,7 +150,7 @@ export const CodeEditor: React.FC<{
|
|
147
150
|
}
|
148
151
|
},
|
149
152
|
[editor],
|
150
|
-
);
|
153
|
+
);
|
151
154
|
|
152
155
|
return (
|
153
156
|
<div ref={ref} className="code-editor__container">
|
@@ -0,0 +1,32 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) 2020-present, Goldman Sachs
|
3
|
+
*
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
* you may not use this file except in compliance with the License.
|
6
|
+
* You may obtain a copy of the License at
|
7
|
+
*
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
*
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
* See the License for the specific language governing permissions and
|
14
|
+
* limitations under the License.
|
15
|
+
*/
|
16
|
+
|
17
|
+
export enum CODE_EDITOR_THEME {
|
18
|
+
LEGEND = 'legend',
|
19
|
+
TEMPORARY__VSCODE_LIGHT = 'vs',
|
20
|
+
}
|
21
|
+
|
22
|
+
export enum CODE_EDITOR_LANGUAGE {
|
23
|
+
TEXT = 'plaintext',
|
24
|
+
PURE = 'pure',
|
25
|
+
JSON = 'json',
|
26
|
+
JAVA = 'java',
|
27
|
+
MARKDOWN = 'markdown',
|
28
|
+
SQL = 'sql',
|
29
|
+
XML = 'xml',
|
30
|
+
YAML = 'yaml',
|
31
|
+
GRAPHQL = 'graphql',
|
32
|
+
}
|
@@ -14,7 +14,18 @@
|
|
14
14
|
* limitations under the License.
|
15
15
|
*/
|
16
16
|
|
17
|
-
import {
|
17
|
+
import {
|
18
|
+
APPLICATION_EVENT,
|
19
|
+
DEFAULT_MONOSPACED_FONT_FAMILY,
|
20
|
+
type GenericLegendApplicationStore,
|
21
|
+
} from '@finos/legend-application';
|
22
|
+
import { LogEvent } from '@finos/legend-shared';
|
23
|
+
import {
|
24
|
+
editor as monacoEditorAPI,
|
25
|
+
KeyCode,
|
26
|
+
KeyMod,
|
27
|
+
MarkerSeverity,
|
28
|
+
} from 'monaco-editor';
|
18
29
|
|
19
30
|
export type CodeEditorPosition = {
|
20
31
|
lineNumber: number;
|
@@ -199,3 +210,67 @@ export const resetLineNumberGutterWidth = (
|
|
199
210
|
),
|
200
211
|
});
|
201
212
|
};
|
213
|
+
|
214
|
+
export const configureCodeEditorComponent = async (
|
215
|
+
applicationStore: GenericLegendApplicationStore,
|
216
|
+
): Promise<void> => {
|
217
|
+
/**
|
218
|
+
* Since we use a custom fonts for text-editor, we want to make sure the font is loaded before any text-editor is opened
|
219
|
+
* this is to ensure
|
220
|
+
*/
|
221
|
+
const fontLoadFailureErrorMessage = `Monospaced font '${DEFAULT_MONOSPACED_FONT_FAMILY}' has not been loaded properly, code editor might not display properly`;
|
222
|
+
await Promise.all(
|
223
|
+
[400, 700].map((weight) =>
|
224
|
+
document.fonts.load(`${weight} 1em ${DEFAULT_MONOSPACED_FONT_FAMILY}`),
|
225
|
+
),
|
226
|
+
)
|
227
|
+
.then(() => {
|
228
|
+
if (document.fonts.check(`1em ${DEFAULT_MONOSPACED_FONT_FAMILY}`)) {
|
229
|
+
monacoEditorAPI.remeasureFonts();
|
230
|
+
} else {
|
231
|
+
applicationStore.logService.error(
|
232
|
+
LogEvent.create(APPLICATION_EVENT.APPLICATION_SETUP__FAILURE),
|
233
|
+
fontLoadFailureErrorMessage,
|
234
|
+
);
|
235
|
+
}
|
236
|
+
})
|
237
|
+
.catch(() =>
|
238
|
+
applicationStore.logService.error(
|
239
|
+
LogEvent.create(APPLICATION_EVENT.APPLICATION_SETUP__FAILURE),
|
240
|
+
fontLoadFailureErrorMessage,
|
241
|
+
),
|
242
|
+
);
|
243
|
+
|
244
|
+
// override native hotkeys supported by monaco-editor
|
245
|
+
// here we map these keys to a dummy command that would just dispatch the key combination
|
246
|
+
// to the application keyboard shortcut service, effectively bypassing the command associated
|
247
|
+
// with the native keybinding
|
248
|
+
const OVERRIDE_DEFAULT_KEYBINDING_COMMAND =
|
249
|
+
'legend.code-editor.override-default-keybinding';
|
250
|
+
monacoEditorAPI.registerCommand(
|
251
|
+
OVERRIDE_DEFAULT_KEYBINDING_COMMAND,
|
252
|
+
(accessor, ...args) => {
|
253
|
+
applicationStore.keyboardShortcutsService.dispatch(args[0]);
|
254
|
+
},
|
255
|
+
);
|
256
|
+
const hotkeyMapping: [number, string][] = [
|
257
|
+
[KeyCode.F1, 'F1'], // show command center
|
258
|
+
[KeyCode.F8, 'F8'], // show error
|
259
|
+
[KeyCode.F9, 'F9'], // toggle debugger breakpoint
|
260
|
+
[KeyMod.WinCtrl | KeyCode.KeyG, 'Control+KeyG'], // go-to line command
|
261
|
+
[KeyMod.WinCtrl | KeyCode.KeyB, 'Control+KeyB'], // cursor move (core command)
|
262
|
+
[KeyMod.WinCtrl | KeyCode.KeyO, 'Control+KeyO'], // cursor move (core command)
|
263
|
+
[KeyMod.WinCtrl | KeyCode.KeyD, 'Control+KeyD'], // cursor move (core command)
|
264
|
+
[KeyMod.WinCtrl | KeyCode.KeyP, 'Control+KeyP'], // cursor move (core command)
|
265
|
+
[KeyMod.Shift | KeyCode.F10, 'Shift+F10'], // show editor context menu
|
266
|
+
[KeyMod.WinCtrl | KeyCode.F2, 'Control+F2'], // change all instances
|
267
|
+
[KeyMod.WinCtrl | KeyCode.F12, 'Control+F12'], // go-to definition
|
268
|
+
];
|
269
|
+
monacoEditorAPI.addKeybindingRules(
|
270
|
+
hotkeyMapping.map(([nativeCodeEditorKeyBinding, keyCombination]) => ({
|
271
|
+
keybinding: nativeCodeEditorKeyBinding,
|
272
|
+
command: OVERRIDE_DEFAULT_KEYBINDING_COMMAND,
|
273
|
+
commandArgs: keyCombination,
|
274
|
+
})),
|
275
|
+
);
|
276
|
+
};
|