@finos/legend-lego 1.2.72 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. package/lib/code-editor/CodeDiffView.d.ts +3 -1
  2. package/lib/code-editor/CodeDiffView.d.ts.map +1 -1
  3. package/lib/code-editor/CodeDiffView.js +6 -2
  4. package/lib/code-editor/CodeDiffView.js.map +1 -1
  5. package/lib/code-editor/CodeEditor.d.ts +8 -2
  6. package/lib/code-editor/CodeEditor.d.ts.map +1 -1
  7. package/lib/code-editor/CodeEditor.js +42 -4
  8. package/lib/code-editor/CodeEditor.js.map +1 -1
  9. package/lib/code-editor/index.d.ts +0 -5
  10. package/lib/code-editor/index.d.ts.map +1 -1
  11. package/lib/code-editor/index.js +0 -5
  12. package/lib/code-editor/index.js.map +1 -1
  13. package/lib/index.css +1 -1
  14. package/package.json +29 -29
  15. package/src/code-editor/CodeDiffView.tsx +10 -3
  16. package/src/code-editor/CodeEditor.tsx +69 -4
  17. package/src/code-editor/index.ts +0 -6
  18. package/tsconfig.json +1 -15
  19. package/lib/code-editor/CodeEditorTheme.d.ts +0 -41
  20. package/lib/code-editor/CodeEditorTheme.d.ts.map +0 -1
  21. package/lib/code-editor/CodeEditorTheme.js +0 -99
  22. package/lib/code-editor/CodeEditorTheme.js.map +0 -1
  23. package/lib/code-editor/CodeEditorUtils.d.ts +0 -74
  24. package/lib/code-editor/CodeEditorUtils.d.ts.map +0 -1
  25. package/lib/code-editor/CodeEditorUtils.js +0 -203
  26. package/lib/code-editor/CodeEditorUtils.js.map +0 -1
  27. package/lib/code-editor/PureLanguage.d.ts +0 -38
  28. package/lib/code-editor/PureLanguage.d.ts.map +0 -1
  29. package/lib/code-editor/PureLanguage.js +0 -39
  30. package/lib/code-editor/PureLanguage.js.map +0 -1
  31. package/lib/code-editor/PureLanguageCodeEditorSupport.d.ts +0 -71
  32. package/lib/code-editor/PureLanguageCodeEditorSupport.d.ts.map +0 -1
  33. package/lib/code-editor/PureLanguageCodeEditorSupport.js +0 -238
  34. package/lib/code-editor/PureLanguageCodeEditorSupport.js.map +0 -1
  35. package/lib/code-editor/PureLanguageService.d.ts +0 -19
  36. package/lib/code-editor/PureLanguageService.d.ts.map +0 -1
  37. package/lib/code-editor/PureLanguageService.js +0 -373
  38. package/lib/code-editor/PureLanguageService.js.map +0 -1
  39. package/lib/code-editor/themes/Github-Theme-dark-dimmed.json +0 -613
  40. package/lib/code-editor/themes/Github-Theme-dark.json +0 -513
  41. package/lib/code-editor/themes/Github-Theme-light.json +0 -598
  42. package/lib/code-editor/themes/Material-Theme-Darker.json +0 -816
  43. package/lib/code-editor/themes/Material-Theme-Default.json +0 -816
  44. package/lib/code-editor/themes/MonacoEditorThemeUtils.d.ts +0 -31
  45. package/lib/code-editor/themes/MonacoEditorThemeUtils.d.ts.map +0 -1
  46. package/lib/code-editor/themes/MonacoEditorThemeUtils.js +0 -88
  47. package/lib/code-editor/themes/MonacoEditorThemeUtils.js.map +0 -1
  48. package/lib/code-editor/themes/OneDark-Pro-darker.json +0 -2061
  49. package/lib/code-editor/themes/OneDark-Pro.json +0 -2090
  50. package/lib/code-editor/themes/solarized-dark-color-theme.json +0 -398
  51. package/src/code-editor/CodeEditorTheme.ts +0 -151
  52. package/src/code-editor/CodeEditorUtils.ts +0 -336
  53. package/src/code-editor/PureLanguage.ts +0 -42
  54. package/src/code-editor/PureLanguageCodeEditorSupport.ts +0 -341
  55. package/src/code-editor/PureLanguageService.ts +0 -416
  56. package/src/code-editor/themes/Github-Theme-dark-dimmed.json +0 -613
  57. package/src/code-editor/themes/Github-Theme-dark.json +0 -513
  58. package/src/code-editor/themes/Github-Theme-light.json +0 -598
  59. package/src/code-editor/themes/Material-Theme-Darker.json +0 -816
  60. package/src/code-editor/themes/Material-Theme-Default.json +0 -816
  61. package/src/code-editor/themes/MonacoEditorThemeUtils.ts +0 -128
  62. package/src/code-editor/themes/OneDark-Pro-darker.json +0 -2061
  63. package/src/code-editor/themes/OneDark-Pro.json +0 -2090
  64. package/src/code-editor/themes/README.md +0 -8
  65. package/src/code-editor/themes/solarized-dark-color-theme.json +0 -423
@@ -1,336 +0,0 @@
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
- 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';
29
- import {
30
- CODE_EDITOR_THEME,
31
- DEFAULT_DARK_THEME,
32
- GITHUB_DARK_DIMMED_THEME,
33
- GITHUB_DARK_THEME,
34
- GITHUB_LIGHT_THEME,
35
- MATERIAL_DARKER_THEME,
36
- MATERIAL_DEFAULT_THEME,
37
- ONE_DARK_PRO_DARKER_THEME,
38
- ONE_DARK_PRO_THEME,
39
- SOLARIZED_DARK_THEME,
40
- } from './CodeEditorTheme.js';
41
-
42
- export type CodeEditorPosition = {
43
- lineNumber: number;
44
- column: number;
45
- };
46
-
47
- /**
48
- * Normally `monaco-editor` worker disposes after 5 minutes staying idle, but we fasten
49
- * this pace just in case the usage of the editor causes memory-leak somehow
50
- */
51
- export const disposeCodeEditor = (
52
- editor: monacoEditorAPI.IStandaloneCodeEditor,
53
- ): void => {
54
- editor.dispose();
55
- // NOTE: just to be sure, we dispose the model after disposing the editor
56
- editor.getModel()?.dispose();
57
- };
58
-
59
- export const disposeDiffCodeEditor = (
60
- editor: monacoEditorAPI.IStandaloneDiffEditor,
61
- ): void => {
62
- editor.dispose();
63
- editor.getOriginalEditor().getModel()?.dispose();
64
- editor.getModifiedEditor().getModel()?.dispose();
65
- };
66
-
67
- /**
68
- * Get the text value with LF line ending.
69
- * This is needed since if there are CR `\r` characters in the text input
70
- * (e.g. users of Windows doing copy/paste)
71
- * the default mode of `monaco-editor` is `TextDefined` which means if the text
72
- * contains CR character(s), it will automatically be treated as CRLF. As such, we want
73
- * an utility method to extract the text value with line ending option LF
74
- * to force omission of CR characters
75
- * See https://github.com/finos/legend-studio/issues/608
76
- */
77
- export const getCodeEditorValue = (
78
- editor: monacoEditorAPI.IStandaloneCodeEditor,
79
- ): string =>
80
- editor.getModel()?.getValue(monacoEditorAPI.EndOfLinePreference.LF) ?? '';
81
-
82
- export const getBaseCodeEditorOptions =
83
- (): monacoEditorAPI.IStandaloneEditorConstructionOptions =>
84
- ({
85
- contextmenu: false,
86
- copyWithSyntaxHighlighting: false,
87
- // NOTE: These following font options are needed (and CSS font-size option `.monaco-editor * { font-size: ... }` as well)
88
- // in order to make the editor appear properly on multiple platform, the ligatures option is needed for Mac to display properly
89
- // otherwise the cursor position relatively to text would be off
90
- // Another potential cause for this misaligment is that the fonts are being lazy-loaded and made available after `monaco-editor`
91
- // calculated the font-width, for this, we can use `remeasureFonts`, but our case here, `fontLigatures: true` seems
92
- // to do the trick
93
- // See https://github.com/microsoft/monaco-editor/issues/392
94
- fontSize: 14,
95
- // Enforce a fixed font-family to make cross platform display consistent (i.e. Mac defaults to use `Menlo` which is bigger than
96
- // `Consolas` on Windows, etc.)
97
- fontFamily: 'Roboto Mono',
98
- // Enable font ligature: glyphs which combine the shapes of certain sequences of characters into a new form that makes for
99
- // a more harmonious reading experience.
100
- fontLigatures: true,
101
- // Make sure hover or widget shown near boundary are not truncated by setting their position to `fixed`
102
- fixedOverflowWidgets: true,
103
- detectIndentation: false, // i.e. so we can force tab-size
104
- tabSize: 2,
105
- // The typing is currently not correct for `bracketPairColorization`, until this is fixed, we will remove the cast
106
- // See https://github.com/microsoft/monaco-editor/issues/3013
107
- 'bracketPairColorization.enabled': false,
108
- automaticLayout: true,
109
- }) as monacoEditorAPI.IStandaloneEditorConstructionOptions;
110
-
111
- export const getBaseConsoleOptions =
112
- (): monacoEditorAPI.IStandaloneEditorConstructionOptions => ({
113
- ...getBaseCodeEditorOptions(),
114
- fontSize: 12,
115
- extraEditorClassName: 'monaco-editor--small-font',
116
- readOnly: true,
117
- glyphMargin: false,
118
- folding: false,
119
- lineNumbers: 'off',
120
- lineDecorationsWidth: 10,
121
- lineNumbersMinChars: 0,
122
- minimap: {
123
- enabled: false,
124
- },
125
- guides: {
126
- bracketPairs: false,
127
- bracketPairsHorizontal: false,
128
- highlightActiveBracketPair: false,
129
- indentation: false,
130
- highlightActiveIndentation: false,
131
- },
132
- renderLineHighlight: 'none',
133
- });
134
-
135
- export const moveCursorToPosition = (
136
- editor: monacoEditorAPI.ICodeEditor,
137
- position: CodeEditorPosition,
138
- ): void => {
139
- if (!editor.hasTextFocus()) {
140
- editor.focus();
141
- } // focus the editor first so that it can shows the cursor
142
- editor.revealPositionInCenter(position, 0);
143
- editor.setPosition(position);
144
- };
145
-
146
- const INTERNAL__DUMMY_PROBLEM_MARKER_OWNER = 'dummy_problem_marker_owner';
147
-
148
- export const setErrorMarkers = (
149
- editorModel: monacoEditorAPI.ITextModel,
150
- errors: {
151
- message: string;
152
- startLineNumber: number;
153
- startColumn: number;
154
- endLineNumber: number;
155
- endColumn: number;
156
- }[],
157
- ownerId?: string,
158
- ): void => {
159
- monacoEditorAPI.setModelMarkers(
160
- editorModel,
161
- ownerId ?? INTERNAL__DUMMY_PROBLEM_MARKER_OWNER,
162
- errors.map((error) => ({
163
- startLineNumber: error.startLineNumber,
164
- startColumn: error.startColumn,
165
- endLineNumber: error.endLineNumber,
166
- endColumn: error.endColumn + 1, // add a 1 to endColumn as monaco editor range is not inclusive
167
- // NOTE: when the message is empty, no error tooltip is shown, we want to avoid this
168
- message: error.message === '' ? '(no error message)' : error.message,
169
- severity: MarkerSeverity.Error,
170
- })),
171
- );
172
- };
173
-
174
- export const setWarningMarkers = (
175
- editorModel: monacoEditorAPI.ITextModel,
176
- warnings: {
177
- message: string;
178
- startLineNumber: number;
179
- startColumn: number;
180
- endLineNumber: number;
181
- endColumn: number;
182
- }[],
183
- ownerId?: string,
184
- ): void => {
185
- monacoEditorAPI.setModelMarkers(
186
- editorModel,
187
- ownerId ?? INTERNAL__DUMMY_PROBLEM_MARKER_OWNER,
188
- warnings.map((warning) => ({
189
- startLineNumber: warning.startLineNumber,
190
- startColumn: warning.startColumn,
191
- endColumn: warning.endColumn,
192
- endLineNumber: warning.endLineNumber,
193
- message:
194
- warning.message === '' ? '(no warning message)' : warning.message,
195
- severity: MarkerSeverity.Warning,
196
- })),
197
- );
198
- };
199
-
200
- export const clearMarkers = (ownerId?: string): void => {
201
- monacoEditorAPI.removeAllMarkers(
202
- ownerId ?? INTERNAL__DUMMY_PROBLEM_MARKER_OWNER,
203
- );
204
- };
205
-
206
- /**
207
- * This method eliminates CR '\r' character(s) in the provided text value.
208
- */
209
- export const normalizeLineEnding = (val: string): string =>
210
- val.replace(/\r/g, '');
211
-
212
- // We need to dynamically adjust the width of the line number gutter, otherwise as the document gets
213
- // larger, the left margin will start to shrink
214
- // See https://github.com/microsoft/monaco-editor/issues/2206
215
- export const resetLineNumberGutterWidth = (
216
- editor: monacoEditorAPI.ICodeEditor,
217
- ): void => {
218
- const currentValue = editor.getValue();
219
- editor.updateOptions({
220
- lineNumbersMinChars: Math.max(
221
- Math.floor(Math.log10(currentValue.split(/\r\n|\r|\n/g).length)) + 3,
222
- 5,
223
- ),
224
- });
225
- };
226
-
227
- export const configureCodeEditorComponent = async (
228
- applicationStore: GenericLegendApplicationStore,
229
- ): Promise<void> => {
230
- /**
231
- * Since we use a custom fonts for text-editor, we want to make sure the font is loaded before any text-editor is opened
232
- * this is to ensure
233
- */
234
- const fontLoadFailureErrorMessage = `Monospaced font '${DEFAULT_MONOSPACED_FONT_FAMILY}' has not been loaded properly, code editor might not display properly`;
235
- await Promise.all(
236
- [400, 700].map((weight) =>
237
- document.fonts.load(`${weight} 1em ${DEFAULT_MONOSPACED_FONT_FAMILY}`),
238
- ),
239
- )
240
- .then(() => {
241
- if (document.fonts.check(`1em ${DEFAULT_MONOSPACED_FONT_FAMILY}`)) {
242
- monacoEditorAPI.remeasureFonts();
243
- } else {
244
- applicationStore.logService.error(
245
- LogEvent.create(APPLICATION_EVENT.APPLICATION_SETUP__FAILURE),
246
- fontLoadFailureErrorMessage,
247
- );
248
- }
249
- })
250
- .catch(() =>
251
- applicationStore.logService.error(
252
- LogEvent.create(APPLICATION_EVENT.APPLICATION_SETUP__FAILURE),
253
- fontLoadFailureErrorMessage,
254
- ),
255
- );
256
-
257
- // override native hotkeys supported by monaco-editor
258
- // here we map these keys to a dummy command that would just dispatch the key combination
259
- // to the application keyboard shortcut service, effectively bypassing the command associated
260
- // with the native keybinding
261
- const OVERRIDE_DEFAULT_KEYBINDING_COMMAND =
262
- 'legend.code-editor.override-default-keybinding';
263
- monacoEditorAPI.registerCommand(
264
- OVERRIDE_DEFAULT_KEYBINDING_COMMAND,
265
- (accessor, ...args) => {
266
- applicationStore.keyboardShortcutsService.dispatch(args[0]);
267
- },
268
- );
269
- const hotkeyMapping: [number, string][] = [
270
- [KeyCode.F1, 'F1'], // show command center
271
- [KeyCode.F8, 'F8'], // show error
272
- [KeyCode.F9, 'F9'], // toggle debugger breakpoint
273
- [KeyMod.WinCtrl | KeyCode.KeyG, 'Control+KeyG'], // go-to line command
274
- [KeyMod.WinCtrl | KeyCode.KeyB, 'Control+KeyB'], // cursor move (core command)
275
- [KeyMod.WinCtrl | KeyCode.KeyO, 'Control+KeyO'], // cursor move (core command)
276
- [KeyMod.WinCtrl | KeyCode.KeyD, 'Control+KeyD'], // cursor move (core command)
277
- [KeyMod.WinCtrl | KeyCode.KeyP, 'Control+KeyP'], // cursor move (core command)
278
- [KeyMod.Shift | KeyCode.F10, 'Shift+F10'], // show editor context menu
279
- [KeyMod.WinCtrl | KeyCode.F2, 'Control+F2'], // change all instances
280
- [KeyMod.WinCtrl | KeyCode.F12, 'Control+F12'], // go-to definition
281
- ];
282
- monacoEditorAPI.addKeybindingRules(
283
- hotkeyMapping.map(([nativeCodeEditorKeyBinding, keyCombination]) => ({
284
- keybinding: nativeCodeEditorKeyBinding,
285
- command: OVERRIDE_DEFAULT_KEYBINDING_COMMAND,
286
- commandArgs: keyCombination,
287
- })),
288
- );
289
-
290
- // themes
291
- monacoEditorAPI.defineTheme(
292
- CODE_EDITOR_THEME.DEFAULT_DARK,
293
- DEFAULT_DARK_THEME,
294
- );
295
- monacoEditorAPI.defineTheme(
296
- CODE_EDITOR_THEME.SOLARIZED_DARK,
297
- SOLARIZED_DARK_THEME,
298
- );
299
- monacoEditorAPI.defineTheme(CODE_EDITOR_THEME.GITHUB_DARK, GITHUB_DARK_THEME);
300
- monacoEditorAPI.defineTheme(
301
- CODE_EDITOR_THEME.GITHUB_DARK_DIMMED,
302
- GITHUB_DARK_DIMMED_THEME,
303
- );
304
- monacoEditorAPI.defineTheme(
305
- CODE_EDITOR_THEME.GITHUB_LIGHT,
306
- GITHUB_LIGHT_THEME,
307
- );
308
- monacoEditorAPI.defineTheme(
309
- CODE_EDITOR_THEME.MATERIAL_DEFAULT,
310
- MATERIAL_DEFAULT_THEME,
311
- );
312
- monacoEditorAPI.defineTheme(
313
- CODE_EDITOR_THEME.MATERIAL_DARKER,
314
- MATERIAL_DARKER_THEME,
315
- );
316
- monacoEditorAPI.defineTheme(
317
- CODE_EDITOR_THEME.ONE_DARK_PRO,
318
- ONE_DARK_PRO_THEME,
319
- );
320
- monacoEditorAPI.defineTheme(
321
- CODE_EDITOR_THEME.ONE_DARK_PRO_DARKER,
322
- ONE_DARK_PRO_DARKER_THEME,
323
- );
324
- };
325
-
326
- export enum CODE_EDITOR_LANGUAGE {
327
- TEXT = 'plaintext',
328
- PURE = 'pure',
329
- JSON = 'json',
330
- JAVA = 'java',
331
- MARKDOWN = 'markdown',
332
- SQL = 'sql',
333
- XML = 'xml',
334
- YAML = 'yaml',
335
- GRAPHQL = 'graphql',
336
- }
@@ -1,42 +0,0 @@
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 PURE_GRAMMAR_TOKEN {
18
- WHITESPACE = '',
19
-
20
- KEYWORD = 'keyword',
21
- IDENTIFIER = 'identifier',
22
- OPERATOR = 'operator',
23
- DELIMITER = 'delimiter',
24
-
25
- PARSER = 'parser',
26
- NUMBER = 'number',
27
- DATE = 'date',
28
- COLOR = 'color',
29
- PACKAGE = 'package',
30
- STRING = 'string',
31
- COMMENT = 'comment',
32
-
33
- LANGUAGE_STRUCT = 'language-struct',
34
- MULTIPLICITY = 'multiplicity',
35
- GENERICS = 'generics',
36
- PROPERTY = 'property',
37
- PARAMETER = 'parameter',
38
- VARIABLE = 'variable',
39
- TYPE = 'type',
40
-
41
- INVALID = 'invalid',
42
- }