@snack-uikit/code-editor 0.1.3-preview-c01bf388.0 → 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 +11 -0
- package/README.md +1 -0
- package/dist/components/CodeEditor.d.ts +3 -1
- package/dist/components/CodeEditor.js +5 -3
- package/dist/components/styles.module.css +13 -0
- package/package.json +4 -3
- package/src/components/CodeEditor.tsx +23 -10
- package/src/components/styles.module.scss +19 -0
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,6 +13,7 @@
|
|
|
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))` |
|
|
@@ -5,5 +5,7 @@ export type CodeEditorProps = WithSupportProps<{
|
|
|
5
5
|
* <br> По дефолту берется значение из useTheme внутри
|
|
6
6
|
*/
|
|
7
7
|
themeClassName?: string;
|
|
8
|
+
/** Включение/отключение псевдобекграунда*/
|
|
9
|
+
hasBackground?: boolean;
|
|
8
10
|
}> & EditorProps;
|
|
9
|
-
export declare function CodeEditor({ themeClassName, className, theme, options, loading, ...props }: CodeEditorProps): import("react/jsx-runtime").JSX.Element;
|
|
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
16
|
import { Spinner } from '@snack-uikit/loaders';
|
|
16
|
-
import {
|
|
17
|
+
import { extractSupportProps } from '@snack-uikit/utils';
|
|
17
18
|
import { CODE_EDITOR_OPTIONS, DEFAULT_THEME_OPTIONS, DEFAULT_THEME_VALUES } from './constants';
|
|
18
19
|
import { useCalculatedThemeValues } from './hooks';
|
|
20
|
+
import styles from './styles.module.css';
|
|
19
21
|
import { isDark } from './utils';
|
|
20
22
|
export function CodeEditor(_a) {
|
|
21
|
-
var { themeClassName, className, theme, options, loading } = _a, props = __rest(_a, ["themeClassName", "className", "theme", "options", "loading"]);
|
|
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)
|
|
@@ -77,5 +79,5 @@ export function CodeEditor(_a) {
|
|
|
77
79
|
fontFamily: themeValues.mono.body.s['font-family'],
|
|
78
80
|
}
|
|
79
81
|
: DEFAULT_THEME_OPTIONS.mono.s)), options)), [options, themeValues === null || themeValues === void 0 ? void 0 : themeValues.mono]);
|
|
80
|
-
return (_jsx(
|
|
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 })) })));
|
|
81
83
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.
|
|
7
|
+
"version": "0.2.0",
|
|
8
8
|
"sideEffects": [
|
|
9
9
|
"*.css",
|
|
10
10
|
"*.woff",
|
|
@@ -34,7 +34,8 @@
|
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@monaco-editor/react": "4.6.0",
|
|
36
36
|
"@snack-uikit/loaders": "0.5.2",
|
|
37
|
-
"@snack-uikit/utils": "3.3.0"
|
|
37
|
+
"@snack-uikit/utils": "3.3.0",
|
|
38
|
+
"classnames": "2.5.1"
|
|
38
39
|
},
|
|
39
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "e877cb36426721b752a2e98fc7cb28b3f05fc3bf"
|
|
40
41
|
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { Editor, EditorProps, useMonaco } from '@monaco-editor/react';
|
|
2
|
+
import cn from 'classnames';
|
|
2
3
|
import { useMemo } from 'react';
|
|
3
4
|
|
|
4
5
|
import { Spinner } from '@snack-uikit/loaders';
|
|
5
|
-
import {
|
|
6
|
+
import { extractSupportProps, WithSupportProps } from '@snack-uikit/utils';
|
|
6
7
|
|
|
7
8
|
import { CODE_EDITOR_OPTIONS, DEFAULT_THEME_OPTIONS, DEFAULT_THEME_VALUES } from './constants';
|
|
8
9
|
import { useCalculatedThemeValues } from './hooks';
|
|
10
|
+
import styles from './styles.module.scss';
|
|
9
11
|
import { isDark } from './utils';
|
|
10
12
|
|
|
11
13
|
export type CodeEditorProps = WithSupportProps<{
|
|
@@ -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
21
|
EditorProps;
|
|
18
22
|
|
|
19
|
-
export function CodeEditor({
|
|
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);
|
|
@@ -98,13 +110,14 @@ export function CodeEditor({ themeClassName, className, theme, options, loading,
|
|
|
98
110
|
);
|
|
99
111
|
|
|
100
112
|
return (
|
|
101
|
-
<
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
113
|
+
<div className={className} {...extractSupportProps(props)}>
|
|
114
|
+
<Editor
|
|
115
|
+
{...props}
|
|
116
|
+
theme={theme ?? dark ? 'snackDark' : 'snack'}
|
|
117
|
+
className={cn({ [styles.editor]: hasBackground })}
|
|
118
|
+
loading={loading ?? <Spinner />}
|
|
119
|
+
options={mergedOptions}
|
|
120
|
+
/>
|
|
121
|
+
</div>
|
|
109
122
|
);
|
|
110
123
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
}
|