@snack-uikit/code-editor 0.1.2-preview-cb79db34.0 → 0.1.3-preview-c01bf388.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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,15 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## 0.1.2 (2024-04-23)
7
+
8
+ ### Only dependencies have been changed
9
+ * [@snack-uikit/utils@3.3.0](https://github.com/cloud-ru-tech/snack-uikit/blob/master/packages/utils/CHANGELOG.md)
10
+
11
+
12
+
13
+
14
+
6
15
  ## 0.1.1 (2023-12-14)
7
16
 
8
17
  ### Only dependencies have been changed
package/README.md CHANGED
@@ -19,6 +19,7 @@
19
19
  | value | `string` | - | Value of the current model |
20
20
  | language | `string` | - | Language of the current model |
21
21
  | path | `string` | - | Path of the current model Will be passed as the third argument to `.createModel` method `monaco.editor.createModel(..., ..., monaco.Uri.parse(defaultPath))` |
22
+ | theme | `string` | "light" | The theme for the monaco Available options "vs-dark" \| "light" Define new themes by `monaco.editor.defineTheme` |
22
23
  | line | `number` | - | The line to jump on it |
23
24
  | loading | `ReactNode` | "Loading..." | The loading screen before the editor will be mounted |
24
25
  | options | `IStandaloneEditorConstructionOptions` | - | IStandaloneEditorConstructionOptions |
@@ -5,5 +5,5 @@ export type CodeEditorProps = WithSupportProps<{
5
5
  * <br> По дефолту берется значение из useTheme внутри
6
6
  */
7
7
  themeClassName?: string;
8
- }> & Omit<EditorProps, 'theme'>;
9
- export declare function CodeEditor({ themeClassName, className, options, ...props }: CodeEditorProps): import("react/jsx-runtime").JSX.Element;
8
+ }> & EditorProps;
9
+ export declare function CodeEditor({ themeClassName, className, theme, options, loading, ...props }: CodeEditorProps): import("react/jsx-runtime").JSX.Element;
@@ -12,13 +12,13 @@ var __rest = (this && this.__rest) || function (s, e) {
12
12
  import { jsx as _jsx } from "react/jsx-runtime";
13
13
  import { Editor, useMonaco } from '@monaco-editor/react';
14
14
  import { useMemo } from 'react';
15
+ import { Spinner } from '@snack-uikit/loaders';
15
16
  import { excludeSupportProps, extractSupportProps } from '@snack-uikit/utils';
16
- import { DEFAULT_THEME_OPTIONS, DEFAULT_THEME_VALUES } from './constants';
17
+ import { CODE_EDITOR_OPTIONS, DEFAULT_THEME_OPTIONS, DEFAULT_THEME_VALUES } from './constants';
17
18
  import { useCalculatedThemeValues } from './hooks';
18
- import styles from './styles.module.css';
19
19
  import { isDark } from './utils';
20
20
  export function CodeEditor(_a) {
21
- var { themeClassName, className, options } = _a, props = __rest(_a, ["themeClassName", "className", "options"]);
21
+ var { themeClassName, className, theme, options, loading } = _a, props = __rest(_a, ["themeClassName", "className", "theme", "options", "loading"]);
22
22
  const monaco = useMonaco();
23
23
  const themeValues = useCalculatedThemeValues(themeClassName);
24
24
  const themeDataWithoutBase = useMemo(() => (Object.assign({ inherit: true }, ((themeValues === null || themeValues === void 0 ? void 0 : themeValues.sys)
@@ -53,6 +53,7 @@ export function CodeEditor(_a) {
53
53
  },
54
54
  ],
55
55
  colors: {
56
+ 'editor.background': '#00000000',
56
57
  'editor.foreground': themeValues.sys.neutral.textMain,
57
58
  'editor.selectionBackground': themeValues.sys.primary.decorHovered,
58
59
  'editor.lineHighlightBackground': themeValues.sys.neutral.decorDefault + '3F',
@@ -61,20 +62,20 @@ export function CodeEditor(_a) {
61
62
  'scrollbarSlider.background': themeValues.sys.neutral.accentDefault + '52',
62
63
  'scrollbarSlider.hoverBackground': themeValues.sys.neutral.accentDefault + '7B',
63
64
  'scrollbarSlider.activeBackground': themeValues.sys.neutral.accentDefault + 'A4',
64
- "editorLineNumber.foreground": themeValues.sys.neutral.textLight,
65
- "editorLineNumber.activeForeground": themeValues.sys.neutral.textMain
65
+ 'editorLineNumber.foreground': themeValues.sys.neutral.textLight,
66
+ 'editorLineNumber.activeForeground': themeValues.sys.neutral.textMain,
66
67
  },
67
68
  }
68
69
  : DEFAULT_THEME_VALUES))), [themeValues === null || themeValues === void 0 ? void 0 : themeValues.sys]);
69
70
  const dark = useMemo(() => { var _a; return isDark((_a = themeValues === null || themeValues === void 0 ? void 0 : themeValues.sys.available.complementary) !== null && _a !== void 0 ? _a : ''); }, [themeValues === null || themeValues === void 0 ? void 0 : themeValues.sys.available.complementary]);
70
71
  monaco === null || monaco === void 0 ? void 0 : monaco.editor.defineTheme('snackDark', Object.assign(Object.assign({}, themeDataWithoutBase), { base: 'vs-dark' }));
71
72
  monaco === null || monaco === void 0 ? void 0 : monaco.editor.defineTheme('snack', Object.assign(Object.assign({}, themeDataWithoutBase), { base: 'vs' }));
72
- return (_jsx("div", Object.assign({ className: className }, extractSupportProps(props), { children: _jsx(Editor, Object.assign({ theme: dark ? 'snackDark' : 'snack', className: styles.editor, options: Object.assign(Object.assign({ minimap: {
73
- enabled: false,
74
- } }, ((themeValues === null || themeValues === void 0 ? void 0 : themeValues.mono)
75
- ? {
76
- fontSize: Number.parseFloat(themeValues.mono.body.s['font-size']),
77
- fontWeight: themeValues.mono.body.s['font-weight'],
78
- }
79
- : DEFAULT_THEME_OPTIONS)), options) }, excludeSupportProps(props))) })));
73
+ const mergedOptions = useMemo(() => (Object.assign(Object.assign(Object.assign({}, CODE_EDITOR_OPTIONS), ((themeValues === null || themeValues === void 0 ? void 0 : themeValues.mono)
74
+ ? {
75
+ fontSize: Number.parseFloat(themeValues.mono.body.s['font-size']),
76
+ fontWeight: themeValues.mono.body.s['font-weight'],
77
+ fontFamily: themeValues.mono.body.s['font-family'],
78
+ }
79
+ : DEFAULT_THEME_OPTIONS.mono.s)), options)), [options, themeValues === null || themeValues === void 0 ? void 0 : themeValues.mono]);
80
+ return (_jsx(Editor, Object.assign({}, extractSupportProps(props), { theme: (theme !== null && theme !== void 0 ? theme : dark) ? 'snackDark' : 'snack', className: className, loading: loading !== null && loading !== void 0 ? loading : _jsx(Spinner, {}), options: mergedOptions }, excludeSupportProps(props))));
80
81
  }
@@ -15,6 +15,7 @@ export declare const DEFAULT_THEME_VALUES: {
15
15
  token: string;
16
16
  }[];
17
17
  colors: {
18
+ 'editor.background': string;
18
19
  'editor.foreground': string;
19
20
  'editor.selectionBackground': string;
20
21
  'editor.lineHighlightBackground': string;
@@ -23,15 +24,16 @@ export declare const DEFAULT_THEME_VALUES: {
23
24
  'scrollbarSlider.background': string;
24
25
  'scrollbarSlider.hoverBackground': string;
25
26
  'scrollbarSlider.activeBackground': string;
26
- "editorLineNumber.foreground": string;
27
- "editorLineNumber.activeForeground": string;
27
+ 'editorLineNumber.foreground': string;
28
+ 'editorLineNumber.activeForeground': string;
28
29
  };
29
30
  };
30
31
  export declare const DEFAULT_THEME_OPTIONS: {
31
- body: {
32
+ mono: {
32
33
  s: {
33
34
  fontWeight: string;
34
35
  fontSize: number;
36
+ fontFamily: string;
35
37
  };
36
38
  };
37
39
  };
@@ -69,7 +71,31 @@ export declare const THEME_VARS: {
69
71
  s: {
70
72
  'font-weight': string;
71
73
  'font-size': string;
74
+ 'font-family': string;
72
75
  };
73
76
  };
74
77
  };
75
78
  };
79
+ export declare const CODE_EDITOR_OPTIONS: {
80
+ minimap: {
81
+ enabled: boolean;
82
+ };
83
+ padding: {
84
+ top: number;
85
+ bottom: number;
86
+ };
87
+ tabSize: number;
88
+ scrollBeyondLastLine: boolean;
89
+ fixedOverflowWidgets: boolean;
90
+ lineDecorationsWidth: number;
91
+ lineNumbersMinChars: number;
92
+ scrollbar: {
93
+ verticalScrollbarSize: number;
94
+ horizontalScrollbarSize: number;
95
+ useShadows: boolean;
96
+ };
97
+ contextmenu: boolean;
98
+ guides: {
99
+ indentation: boolean;
100
+ };
101
+ };
@@ -11,6 +11,7 @@ export const DEFAULT_THEME_VALUES = {
11
11
  { foreground: '#3280e8', token: 'keyword' },
12
12
  ],
13
13
  colors: {
14
+ 'editor.background': '#00000000',
14
15
  'editor.foreground': '#333333',
15
16
  'editor.selectionBackground': '#decdfb',
16
17
  'editor.lineHighlightBackground': '#decdfb',
@@ -19,15 +20,16 @@ export const DEFAULT_THEME_VALUES = {
19
20
  'scrollbarSlider.background': '#75757552',
20
21
  'scrollbarSlider.hoverBackground': '#7575757B',
21
22
  'scrollbarSlider.activeBackground': '#757575A4',
22
- "editorLineNumber.foreground": "#333333",
23
- "editorLineNumber.activeForeground": "#898989"
23
+ 'editorLineNumber.foreground': '#333333',
24
+ 'editorLineNumber.activeForeground': '#898989',
24
25
  },
25
26
  };
26
27
  export const DEFAULT_THEME_OPTIONS = {
27
- body: {
28
+ mono: {
28
29
  s: {
29
30
  fontWeight: '400',
30
- fontSize: 14,
31
+ fontSize: 12,
32
+ fontFamily: 'SB Sans Text Mono',
31
33
  },
32
34
  },
33
35
  };
@@ -65,7 +67,31 @@ export const THEME_VARS = {
65
67
  s: {
66
68
  'font-weight': '--mono-body-s-font-weight',
67
69
  'font-size': '--mono-body-s-font-size',
70
+ 'font-family': '--mono-body-s-font-family',
68
71
  },
69
72
  },
70
73
  },
71
74
  };
75
+ export const CODE_EDITOR_OPTIONS = {
76
+ minimap: {
77
+ enabled: false,
78
+ },
79
+ padding: {
80
+ top: 4,
81
+ bottom: 4,
82
+ },
83
+ tabSize: 4,
84
+ scrollBeyondLastLine: false,
85
+ fixedOverflowWidgets: true,
86
+ lineDecorationsWidth: 4,
87
+ lineNumbersMinChars: 2,
88
+ scrollbar: {
89
+ verticalScrollbarSize: 8,
90
+ horizontalScrollbarSize: 8,
91
+ useShadows: false,
92
+ },
93
+ contextmenu: false,
94
+ guides: {
95
+ indentation: false,
96
+ },
97
+ };
@@ -32,6 +32,7 @@ export declare function useCalculatedThemeValues(themeClassNameProps?: string):
32
32
  s: {
33
33
  'font-weight': string;
34
34
  'font-size': string;
35
+ 'font-family': string;
35
36
  };
36
37
  };
37
38
  };
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.1.2-preview-cb79db34.0",
7
+ "version": "0.1.3-preview-c01bf388.0",
8
8
  "sideEffects": [
9
9
  "*.css",
10
10
  "*.woff",
@@ -33,7 +33,8 @@
33
33
  "scripts": {},
34
34
  "dependencies": {
35
35
  "@monaco-editor/react": "4.6.0",
36
- "@snack-uikit/utils": "3.2.1-preview-cb79db34.0"
36
+ "@snack-uikit/loaders": "0.5.2",
37
+ "@snack-uikit/utils": "3.3.0"
37
38
  },
38
- "gitHead": "ec06c40c0ed64aa42d8842734a8c532f5c4603e6"
39
+ "gitHead": "81d58386bd6b1a8ab786092bfb598811c5e31045"
39
40
  }
@@ -1,11 +1,11 @@
1
1
  import { Editor, EditorProps, useMonaco } from '@monaco-editor/react';
2
2
  import { useMemo } from 'react';
3
3
 
4
+ import { Spinner } from '@snack-uikit/loaders';
4
5
  import { excludeSupportProps, extractSupportProps, WithSupportProps } from '@snack-uikit/utils';
5
6
 
6
- import { DEFAULT_THEME_OPTIONS, DEFAULT_THEME_VALUES } from './constants';
7
+ import { CODE_EDITOR_OPTIONS, DEFAULT_THEME_OPTIONS, DEFAULT_THEME_VALUES } from './constants';
7
8
  import { useCalculatedThemeValues } from './hooks';
8
- import styles from './styles.module.scss';
9
9
  import { isDark } from './utils';
10
10
 
11
11
  export type CodeEditorProps = WithSupportProps<{
@@ -14,9 +14,9 @@ export type CodeEditorProps = WithSupportProps<{
14
14
  */
15
15
  themeClassName?: string;
16
16
  }> &
17
- Omit<EditorProps, 'theme'>;
17
+ EditorProps;
18
18
 
19
- export function CodeEditor({ themeClassName, className, options, ...props }: CodeEditorProps) {
19
+ export function CodeEditor({ themeClassName, className, theme, options, loading, ...props }: CodeEditorProps) {
20
20
  const monaco = useMonaco();
21
21
 
22
22
  const themeValues = useCalculatedThemeValues(themeClassName);
@@ -56,6 +56,7 @@ export function CodeEditor({ themeClassName, className, options, ...props }: Cod
56
56
  },
57
57
  ],
58
58
  colors: {
59
+ 'editor.background': '#00000000',
59
60
  'editor.foreground': themeValues.sys.neutral.textMain,
60
61
  'editor.selectionBackground': themeValues.sys.primary.decorHovered,
61
62
  'editor.lineHighlightBackground': themeValues.sys.neutral.decorDefault + '3F',
@@ -64,8 +65,8 @@ export function CodeEditor({ themeClassName, className, options, ...props }: Cod
64
65
  'scrollbarSlider.background': themeValues.sys.neutral.accentDefault + '52',
65
66
  'scrollbarSlider.hoverBackground': themeValues.sys.neutral.accentDefault + '7B',
66
67
  'scrollbarSlider.activeBackground': themeValues.sys.neutral.accentDefault + 'A4',
67
- "editorLineNumber.foreground": themeValues.sys.neutral.textLight,
68
- "editorLineNumber.activeForeground": themeValues.sys.neutral.textMain
68
+ 'editorLineNumber.foreground': themeValues.sys.neutral.textLight,
69
+ 'editorLineNumber.activeForeground': themeValues.sys.neutral.textMain,
69
70
  },
70
71
  }
71
72
  : DEFAULT_THEME_VALUES),
@@ -81,25 +82,29 @@ export function CodeEditor({ themeClassName, className, options, ...props }: Cod
81
82
  monaco?.editor.defineTheme('snackDark', { ...themeDataWithoutBase, base: 'vs-dark' });
82
83
  monaco?.editor.defineTheme('snack', { ...themeDataWithoutBase, base: 'vs' });
83
84
 
85
+ const mergedOptions = useMemo(
86
+ () => ({
87
+ ...CODE_EDITOR_OPTIONS,
88
+ ...(themeValues?.mono
89
+ ? {
90
+ fontSize: Number.parseFloat(themeValues.mono.body.s['font-size']),
91
+ fontWeight: themeValues.mono.body.s['font-weight'],
92
+ fontFamily: themeValues.mono.body.s['font-family'],
93
+ }
94
+ : DEFAULT_THEME_OPTIONS.mono.s),
95
+ ...options,
96
+ }),
97
+ [options, themeValues?.mono],
98
+ );
99
+
84
100
  return (
85
- <div className={className} {...extractSupportProps(props)}>
86
- <Editor
87
- theme={dark ? 'snackDark' : 'snack'}
88
- className={styles.editor}
89
- options={{
90
- minimap: {
91
- enabled: false,
92
- },
93
- ...(themeValues?.mono
94
- ? {
95
- fontSize: Number.parseFloat(themeValues.mono.body.s['font-size']),
96
- fontWeight: themeValues.mono.body.s['font-weight'],
97
- }
98
- : DEFAULT_THEME_OPTIONS),
99
- ...options,
100
- }}
101
- {...excludeSupportProps(props)}
102
- />
103
- </div>
101
+ <Editor
102
+ {...extractSupportProps(props)}
103
+ theme={theme ?? dark ? 'snackDark' : 'snack'}
104
+ className={className}
105
+ loading={loading ?? <Spinner />}
106
+ options={mergedOptions}
107
+ {...excludeSupportProps(props)}
108
+ />
104
109
  );
105
110
  }
@@ -11,6 +11,7 @@ export const DEFAULT_THEME_VALUES = {
11
11
  { foreground: '#3280e8', token: 'keyword' },
12
12
  ],
13
13
  colors: {
14
+ 'editor.background': '#00000000',
14
15
  'editor.foreground': '#333333',
15
16
  'editor.selectionBackground': '#decdfb',
16
17
  'editor.lineHighlightBackground': '#decdfb',
@@ -19,16 +20,17 @@ export const DEFAULT_THEME_VALUES = {
19
20
  'scrollbarSlider.background': '#75757552',
20
21
  'scrollbarSlider.hoverBackground': '#7575757B',
21
22
  'scrollbarSlider.activeBackground': '#757575A4',
22
- "editorLineNumber.foreground": "#333333",
23
- "editorLineNumber.activeForeground": "#898989"
23
+ 'editorLineNumber.foreground': '#333333',
24
+ 'editorLineNumber.activeForeground': '#898989',
24
25
  },
25
26
  };
26
27
 
27
28
  export const DEFAULT_THEME_OPTIONS = {
28
- body: {
29
+ mono: {
29
30
  s: {
30
31
  fontWeight: '400',
31
- fontSize: 14,
32
+ fontSize: 12,
33
+ fontFamily: 'SB Sans Text Mono',
32
34
  },
33
35
  },
34
36
  };
@@ -67,7 +69,32 @@ export const THEME_VARS = {
67
69
  s: {
68
70
  'font-weight': '--mono-body-s-font-weight',
69
71
  'font-size': '--mono-body-s-font-size',
72
+ 'font-family': '--mono-body-s-font-family',
70
73
  },
71
74
  },
72
75
  },
73
76
  };
77
+
78
+ export const CODE_EDITOR_OPTIONS = {
79
+ minimap: {
80
+ enabled: false,
81
+ },
82
+ padding: {
83
+ top: 4,
84
+ bottom: 4,
85
+ },
86
+ tabSize: 4,
87
+ scrollBeyondLastLine: false,
88
+ fixedOverflowWidgets: true,
89
+ lineDecorationsWidth: 4,
90
+ lineNumbersMinChars: 2,
91
+ scrollbar: {
92
+ verticalScrollbarSize: 8,
93
+ horizontalScrollbarSize: 8,
94
+ useShadows: false,
95
+ },
96
+ contextmenu: false,
97
+ guides: {
98
+ indentation: false,
99
+ },
100
+ };
@@ -1,13 +0,0 @@
1
- .editor{
2
- background-color:inherit;
3
- }
4
- .editor::after{
5
- pointer-events:none;
6
- content:"";
7
- position:absolute;
8
- top:0;
9
- bottom:0;
10
- width:100%;
11
- opacity:var(--opacity-a004, 0.04);
12
- background-color:var(--sys-neutral-accent-default, #6f717c);
13
- }
@@ -1,19 +0,0 @@
1
- @import '@snack-uikit/figma-tokens/build/scss/styles-theme-variables';
2
-
3
- .editor {
4
- background-color: inherit;
5
-
6
- &::after {
7
- pointer-events: none;
8
- content: '';
9
-
10
- position: absolute;
11
- top: 0;
12
- bottom: 0;
13
-
14
- width: 100%;
15
-
16
- opacity: $opacity-a004;
17
- background-color: $sys-neutral-accent-default;
18
- }
19
- }