@snack-uikit/code-editor 0.2.0 → 0.2.1-preview-01f9b65f.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.
|
@@ -18,7 +18,8 @@ import { extractSupportProps } from '@snack-uikit/utils';
|
|
|
18
18
|
import { CODE_EDITOR_OPTIONS, DEFAULT_THEME_OPTIONS, DEFAULT_THEME_VALUES } from './constants';
|
|
19
19
|
import { useCalculatedThemeValues } from './hooks';
|
|
20
20
|
import styles from './styles.module.css';
|
|
21
|
-
import { isDark } from './utils';
|
|
21
|
+
import { initMonacoEnvironment, isDark } from './utils';
|
|
22
|
+
initMonacoEnvironment();
|
|
22
23
|
export function CodeEditor(_a) {
|
|
23
24
|
var { themeClassName, className, theme, options, loading, hasBackground = true } = _a, props = __rest(_a, ["themeClassName", "className", "theme", "options", "loading", "hasBackground"]);
|
|
24
25
|
const monaco = useMonaco();
|
package/dist/components/utils.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { loader } from '@monaco-editor/react';
|
|
1
2
|
export function rgb2hsl(HTMLcolor) {
|
|
2
3
|
const r = parseInt(HTMLcolor.substring(1, 3), 16) / 255;
|
|
3
4
|
const g = parseInt(HTMLcolor.substring(3, 5), 16) / 255;
|
|
@@ -33,3 +34,13 @@ export function isDark(color) {
|
|
|
33
34
|
const [h, _, l] = rgb2hsl(color);
|
|
34
35
|
return (h < 0.55 && l >= 0.5) || (h >= 0.55 && l >= 0.75);
|
|
35
36
|
}
|
|
37
|
+
export function initMonacoEnvironment() {
|
|
38
|
+
var _a;
|
|
39
|
+
if (!window) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const vs = (_a = window.MonacoEnvironment) === null || _a === void 0 ? void 0 : _a.baseUrl;
|
|
43
|
+
if (vs) {
|
|
44
|
+
loader.config({ paths: { vs } });
|
|
45
|
+
}
|
|
46
|
+
}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.2.0",
|
|
7
|
+
"version": "0.2.1-preview-01f9b65f.0",
|
|
8
8
|
"sideEffects": [
|
|
9
9
|
"*.css",
|
|
10
10
|
"*.woff",
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"@snack-uikit/utils": "3.3.0",
|
|
38
38
|
"classnames": "2.5.1"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "4fc8efb2c8fab602fc1e0391b743448d6dffd89b"
|
|
41
41
|
}
|
|
@@ -8,7 +8,9 @@ import { extractSupportProps, WithSupportProps } from '@snack-uikit/utils';
|
|
|
8
8
|
import { CODE_EDITOR_OPTIONS, DEFAULT_THEME_OPTIONS, DEFAULT_THEME_VALUES } from './constants';
|
|
9
9
|
import { useCalculatedThemeValues } from './hooks';
|
|
10
10
|
import styles from './styles.module.scss';
|
|
11
|
-
import { isDark } from './utils';
|
|
11
|
+
import { initMonacoEnvironment, isDark } from './utils';
|
|
12
|
+
|
|
13
|
+
initMonacoEnvironment();
|
|
12
14
|
|
|
13
15
|
export type CodeEditorProps = WithSupportProps<{
|
|
14
16
|
/** Класснейм подключенной темы (из хука useThemeConfig() или ThemeProvider)
|
package/src/components/utils.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { loader } from '@monaco-editor/react';
|
|
2
|
+
|
|
1
3
|
export function rgb2hsl(HTMLcolor: string) {
|
|
2
4
|
const r = parseInt(HTMLcolor.substring(1, 3), 16) / 255;
|
|
3
5
|
const g = parseInt(HTMLcolor.substring(3, 5), 16) / 255;
|
|
@@ -45,3 +47,15 @@ export function isDark(color: string) {
|
|
|
45
47
|
|
|
46
48
|
return (h < 0.55 && l >= 0.5) || (h >= 0.55 && l >= 0.75);
|
|
47
49
|
}
|
|
50
|
+
|
|
51
|
+
export function initMonacoEnvironment() {
|
|
52
|
+
if (!window) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const vs = window.MonacoEnvironment?.baseUrl;
|
|
57
|
+
|
|
58
|
+
if (vs) {
|
|
59
|
+
loader.config({ paths: { vs } });
|
|
60
|
+
}
|
|
61
|
+
}
|