@snack-uikit/code-editor 0.1.2 → 0.2.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,17 @@
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.2.0 (2024-04-27)
7
+
8
+
9
+ ### Features
10
+
11
+ * **PDS-62:** upd default theme; add theme prop ([522efca](https://git.sbercloud.tech/sbercloud-ui/tokens-design-system/snack-uikit/commits/522efcad7a40cf9dccfef8c5192580c6d2c4b1ee))
12
+
13
+
14
+
15
+
16
+
6
17
  ## 0.1.2 (2024-04-23)
7
18
 
8
19
  ### Only dependencies have been changed
package/README.md CHANGED
@@ -13,12 +13,14 @@
13
13
  | name | type | default value | description |
14
14
  |------|------|---------------|-------------|
15
15
  | themeClassName | `string` | - | Класснейм подключенной темы (из хука useThemeConfig() или ThemeProvider) <br> По дефолту берется значение из useTheme внутри |
16
+ | hasBackground | `boolean` | true | Включение/отключение псевдобекграунда |
16
17
  | defaultValue | `string` | - | Default value of the current model |
17
18
  | defaultLanguage | `string` | - | Default language of the current model |
18
19
  | defaultPath | `string` | - | Default path of the current model Will be passed as the third argument to `.createModel` method `monaco.editor.createModel(..., ..., monaco.Uri.parse(defaultPath))` |
19
20
  | value | `string` | - | Value of the current model |
20
21
  | language | `string` | - | Language of the current model |
21
22
  | path | `string` | - | Path of the current model Will be passed as the third argument to `.createModel` method `monaco.editor.createModel(..., ..., monaco.Uri.parse(defaultPath))` |
23
+ | theme | `string` | "light" | The theme for the monaco Available options "vs-dark" \| "light" Define new themes by `monaco.editor.defineTheme` |
22
24
  | line | `number` | - | The line to jump on it |
23
25
  | loading | `ReactNode` | "Loading..." | The loading screen before the editor will be mounted |
24
26
  | options | `IStandaloneEditorConstructionOptions` | - | IStandaloneEditorConstructionOptions |
@@ -5,5 +5,7 @@ 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
+ /** Включение/отключение псевдобекграунда*/
9
+ hasBackground?: boolean;
10
+ }> & EditorProps;
11
+ export declare function CodeEditor({ themeClassName, className, theme, options, loading, hasBackground, ...props }: CodeEditorProps): import("react/jsx-runtime").JSX.Element;
@@ -11,14 +11,16 @@ var __rest = (this && this.__rest) || function (s, e) {
11
11
  };
12
12
  import { jsx as _jsx } from "react/jsx-runtime";
13
13
  import { Editor, useMonaco } from '@monaco-editor/react';
14
+ import cn from 'classnames';
14
15
  import { useMemo } from 'react';
15
- import { excludeSupportProps, extractSupportProps } from '@snack-uikit/utils';
16
- import { DEFAULT_THEME_OPTIONS, DEFAULT_THEME_VALUES } from './constants';
16
+ import { Spinner } from '@snack-uikit/loaders';
17
+ import { extractSupportProps } from '@snack-uikit/utils';
18
+ import { CODE_EDITOR_OPTIONS, DEFAULT_THEME_OPTIONS, DEFAULT_THEME_VALUES } from './constants';
17
19
  import { useCalculatedThemeValues } from './hooks';
18
20
  import styles from './styles.module.css';
19
21
  import { isDark } from './utils';
20
22
  export function CodeEditor(_a) {
21
- var { themeClassName, className, options } = _a, props = __rest(_a, ["themeClassName", "className", "options"]);
23
+ var { themeClassName, className, theme, options, loading, hasBackground = true } = _a, props = __rest(_a, ["themeClassName", "className", "theme", "options", "loading", "hasBackground"]);
22
24
  const monaco = useMonaco();
23
25
  const themeValues = useCalculatedThemeValues(themeClassName);
24
26
  const themeDataWithoutBase = useMemo(() => (Object.assign({ inherit: true }, ((themeValues === null || themeValues === void 0 ? void 0 : themeValues.sys)
@@ -53,6 +55,7 @@ export function CodeEditor(_a) {
53
55
  },
54
56
  ],
55
57
  colors: {
58
+ 'editor.background': '#00000000',
56
59
  'editor.foreground': themeValues.sys.neutral.textMain,
57
60
  'editor.selectionBackground': themeValues.sys.primary.decorHovered,
58
61
  'editor.lineHighlightBackground': themeValues.sys.neutral.decorDefault + '3F',
@@ -61,20 +64,20 @@ export function CodeEditor(_a) {
61
64
  'scrollbarSlider.background': themeValues.sys.neutral.accentDefault + '52',
62
65
  'scrollbarSlider.hoverBackground': themeValues.sys.neutral.accentDefault + '7B',
63
66
  'scrollbarSlider.activeBackground': themeValues.sys.neutral.accentDefault + 'A4',
64
- "editorLineNumber.foreground": themeValues.sys.neutral.textLight,
65
- "editorLineNumber.activeForeground": themeValues.sys.neutral.textMain
67
+ 'editorLineNumber.foreground': themeValues.sys.neutral.textLight,
68
+ 'editorLineNumber.activeForeground': themeValues.sys.neutral.textMain,
66
69
  },
67
70
  }
68
71
  : DEFAULT_THEME_VALUES))), [themeValues === null || themeValues === void 0 ? void 0 : themeValues.sys]);
69
72
  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
73
  monaco === null || monaco === void 0 ? void 0 : monaco.editor.defineTheme('snackDark', Object.assign(Object.assign({}, themeDataWithoutBase), { base: 'vs-dark' }));
71
74
  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))) })));
75
+ const mergedOptions = useMemo(() => (Object.assign(Object.assign(Object.assign({}, CODE_EDITOR_OPTIONS), ((themeValues === null || themeValues === void 0 ? void 0 : themeValues.mono)
76
+ ? {
77
+ fontSize: Number.parseFloat(themeValues.mono.body.s['font-size']),
78
+ fontWeight: themeValues.mono.body.s['font-weight'],
79
+ fontFamily: themeValues.mono.body.s['font-family'],
80
+ }
81
+ : DEFAULT_THEME_OPTIONS.mono.s)), options)), [options, themeValues === null || themeValues === void 0 ? void 0 : themeValues.mono]);
82
+ return (_jsx("div", Object.assign({ className: className }, extractSupportProps(props), { children: _jsx(Editor, Object.assign({}, props, { theme: (theme !== null && theme !== void 0 ? theme : dark) ? 'snackDark' : 'snack', className: cn({ [styles.editor]: hasBackground }), loading: loading !== null && loading !== void 0 ? loading : _jsx(Spinner, {}), options: mergedOptions })) })));
80
83
  }
@@ -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",
7
+ "version": "0.2.0",
8
8
  "sideEffects": [
9
9
  "*.css",
10
10
  "*.woff",
@@ -33,7 +33,9 @@
33
33
  "scripts": {},
34
34
  "dependencies": {
35
35
  "@monaco-editor/react": "4.6.0",
36
- "@snack-uikit/utils": "3.3.0"
36
+ "@snack-uikit/loaders": "0.5.2",
37
+ "@snack-uikit/utils": "3.3.0",
38
+ "classnames": "2.5.1"
37
39
  },
38
- "gitHead": "bf1e1f3cfabccc1ee288c18722e33009bd001798"
40
+ "gitHead": "e877cb36426721b752a2e98fc7cb28b3f05fc3bf"
39
41
  }
@@ -1,9 +1,11 @@
1
1
  import { Editor, EditorProps, useMonaco } from '@monaco-editor/react';
2
+ import cn from 'classnames';
2
3
  import { useMemo } from 'react';
3
4
 
4
- import { excludeSupportProps, extractSupportProps, WithSupportProps } from '@snack-uikit/utils';
5
+ import { Spinner } from '@snack-uikit/loaders';
6
+ import { extractSupportProps, WithSupportProps } from '@snack-uikit/utils';
5
7
 
6
- import { DEFAULT_THEME_OPTIONS, DEFAULT_THEME_VALUES } from './constants';
8
+ import { CODE_EDITOR_OPTIONS, DEFAULT_THEME_OPTIONS, DEFAULT_THEME_VALUES } from './constants';
7
9
  import { useCalculatedThemeValues } from './hooks';
8
10
  import styles from './styles.module.scss';
9
11
  import { isDark } from './utils';
@@ -13,10 +15,20 @@ export type CodeEditorProps = WithSupportProps<{
13
15
  * <br> По дефолту берется значение из useTheme внутри
14
16
  */
15
17
  themeClassName?: string;
18
+ /** Включение/отключение псевдобекграунда*/
19
+ hasBackground?: boolean;
16
20
  }> &
17
- Omit<EditorProps, 'theme'>;
21
+ EditorProps;
18
22
 
19
- export function CodeEditor({ themeClassName, className, options, ...props }: CodeEditorProps) {
23
+ export function CodeEditor({
24
+ themeClassName,
25
+ className,
26
+ theme,
27
+ options,
28
+ loading,
29
+ hasBackground = true,
30
+ ...props
31
+ }: CodeEditorProps) {
20
32
  const monaco = useMonaco();
21
33
 
22
34
  const themeValues = useCalculatedThemeValues(themeClassName);
@@ -56,6 +68,7 @@ export function CodeEditor({ themeClassName, className, options, ...props }: Cod
56
68
  },
57
69
  ],
58
70
  colors: {
71
+ 'editor.background': '#00000000',
59
72
  'editor.foreground': themeValues.sys.neutral.textMain,
60
73
  'editor.selectionBackground': themeValues.sys.primary.decorHovered,
61
74
  'editor.lineHighlightBackground': themeValues.sys.neutral.decorDefault + '3F',
@@ -64,8 +77,8 @@ export function CodeEditor({ themeClassName, className, options, ...props }: Cod
64
77
  'scrollbarSlider.background': themeValues.sys.neutral.accentDefault + '52',
65
78
  'scrollbarSlider.hoverBackground': themeValues.sys.neutral.accentDefault + '7B',
66
79
  'scrollbarSlider.activeBackground': themeValues.sys.neutral.accentDefault + 'A4',
67
- "editorLineNumber.foreground": themeValues.sys.neutral.textLight,
68
- "editorLineNumber.activeForeground": themeValues.sys.neutral.textMain
80
+ 'editorLineNumber.foreground': themeValues.sys.neutral.textLight,
81
+ 'editorLineNumber.activeForeground': themeValues.sys.neutral.textMain,
69
82
  },
70
83
  }
71
84
  : DEFAULT_THEME_VALUES),
@@ -81,24 +94,29 @@ export function CodeEditor({ themeClassName, className, options, ...props }: Cod
81
94
  monaco?.editor.defineTheme('snackDark', { ...themeDataWithoutBase, base: 'vs-dark' });
82
95
  monaco?.editor.defineTheme('snack', { ...themeDataWithoutBase, base: 'vs' });
83
96
 
97
+ const mergedOptions = useMemo(
98
+ () => ({
99
+ ...CODE_EDITOR_OPTIONS,
100
+ ...(themeValues?.mono
101
+ ? {
102
+ fontSize: Number.parseFloat(themeValues.mono.body.s['font-size']),
103
+ fontWeight: themeValues.mono.body.s['font-weight'],
104
+ fontFamily: themeValues.mono.body.s['font-family'],
105
+ }
106
+ : DEFAULT_THEME_OPTIONS.mono.s),
107
+ ...options,
108
+ }),
109
+ [options, themeValues?.mono],
110
+ );
111
+
84
112
  return (
85
113
  <div className={className} {...extractSupportProps(props)}>
86
114
  <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)}
115
+ {...props}
116
+ theme={theme ?? dark ? 'snackDark' : 'snack'}
117
+ className={cn({ [styles.editor]: hasBackground })}
118
+ loading={loading ?? <Spinner />}
119
+ options={mergedOptions}
102
120
  />
103
121
  </div>
104
122
  );
@@ -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
+ };
@@ -16,4 +16,4 @@
16
16
  opacity: $opacity-a004;
17
17
  background-color: $sys-neutral-accent-default;
18
18
  }
19
- }
19
+ }