@snack-uikit/code-editor 0.4.7-preview-b4050474.0 → 0.4.7-preview-ac85ab7b.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.
|
@@ -10,4 +10,4 @@ export type CodeEditorProps = WithSupportProps<{
|
|
|
10
10
|
*/
|
|
11
11
|
hasBackground?: boolean;
|
|
12
12
|
}> & (EditorProps | YamlEditorProps);
|
|
13
|
-
export declare function CodeEditor({ themeName, className, theme, options, loading, hasBackground, onMount, ...props }: CodeEditorProps): import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
export declare function CodeEditor({ themeName, className, theme, options, loading, hasBackground, onMount, ...props }: CodeEditorProps): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -27,7 +27,6 @@ const constants_1 = require("./constants");
|
|
|
27
27
|
const hooks_1 = require("./hooks");
|
|
28
28
|
const styles_module_scss_1 = __importDefault(require('./styles.module.css'));
|
|
29
29
|
const utils_2 = require("./utils");
|
|
30
|
-
(0, utils_2.initLoaderConfig)();
|
|
31
30
|
function CodeEditor(_a) {
|
|
32
31
|
var {
|
|
33
32
|
themeName,
|
|
@@ -42,6 +41,11 @@ function CodeEditor(_a) {
|
|
|
42
41
|
const {
|
|
43
42
|
language
|
|
44
43
|
} = props;
|
|
44
|
+
const [canRender, setCanRender] = (0, react_2.useState)(false);
|
|
45
|
+
(0, utils_1.useLayoutEffect)(() => {
|
|
46
|
+
(0, utils_2.initLoaderConfig)();
|
|
47
|
+
setCanRender(true);
|
|
48
|
+
}, []);
|
|
45
49
|
const monaco = (0, react_1.useMonaco)();
|
|
46
50
|
const [wrapperElement, setWrapperElement] = (0, react_2.useState)(null);
|
|
47
51
|
const yamlModelPath = (0, hooks_1.useYamlEditor)(props.language === 'yaml' ? props.yamlSchema : undefined);
|
|
@@ -110,6 +114,9 @@ function CodeEditor(_a) {
|
|
|
110
114
|
fontWeight: themeValues.mono.body.s['font-weight'],
|
|
111
115
|
fontFamily: themeValues.mono.body.s['font-family']
|
|
112
116
|
} : constants_1.DEFAULT_THEME_OPTIONS.mono.s), options), [options, language, themeValues === null || themeValues === void 0 ? void 0 : themeValues.mono]);
|
|
117
|
+
if (!canRender) {
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
113
120
|
return (0, jsx_runtime_1.jsx)("div", Object.assign({
|
|
114
121
|
className: className
|
|
115
122
|
}, (0, utils_1.extractSupportProps)(props), {
|
|
@@ -10,4 +10,4 @@ export type CodeEditorProps = WithSupportProps<{
|
|
|
10
10
|
*/
|
|
11
11
|
hasBackground?: boolean;
|
|
12
12
|
}> & (EditorProps | YamlEditorProps);
|
|
13
|
-
export declare function CodeEditor({ themeName, className, theme, options, loading, hasBackground, onMount, ...props }: CodeEditorProps): import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
export declare function CodeEditor({ themeName, className, theme, options, loading, hasBackground, onMount, ...props }: CodeEditorProps): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -14,15 +14,19 @@ import { Editor, useMonaco } from '@monaco-editor/react';
|
|
|
14
14
|
import cn from 'classnames';
|
|
15
15
|
import { useCallback, useMemo, useState } from 'react';
|
|
16
16
|
import { Spinner } from '@snack-uikit/loaders';
|
|
17
|
-
import { extractSupportProps, isBrowser } from '@snack-uikit/utils';
|
|
17
|
+
import { extractSupportProps, isBrowser, useLayoutEffect } from '@snack-uikit/utils';
|
|
18
18
|
import { CODE_EDITOR_OPTIONS, DEFAULT_THEME_OPTIONS, DEFAULT_THEME_VALUES, YAML_CODE_EDITOR_OPTIONS, } from './constants';
|
|
19
19
|
import { useCalculatedThemeValues, useYamlEditor } from './hooks';
|
|
20
20
|
import styles from './styles.module.css';
|
|
21
21
|
import { initLoaderConfig, isDark } from './utils';
|
|
22
|
-
initLoaderConfig();
|
|
23
22
|
export function CodeEditor(_a) {
|
|
24
23
|
var { themeName, className, theme, options, loading, hasBackground = true, onMount } = _a, props = __rest(_a, ["themeName", "className", "theme", "options", "loading", "hasBackground", "onMount"]);
|
|
25
24
|
const { language } = props;
|
|
25
|
+
const [canRender, setCanRender] = useState(false);
|
|
26
|
+
useLayoutEffect(() => {
|
|
27
|
+
initLoaderConfig();
|
|
28
|
+
setCanRender(true);
|
|
29
|
+
}, []);
|
|
26
30
|
const monaco = useMonaco();
|
|
27
31
|
const [wrapperElement, setWrapperElement] = useState(null);
|
|
28
32
|
const yamlModelPath = useYamlEditor(props.language === 'yaml' ? props.yamlSchema : undefined);
|
|
@@ -88,5 +92,8 @@ export function CodeEditor(_a) {
|
|
|
88
92
|
fontFamily: themeValues.mono.body.s['font-family'],
|
|
89
93
|
}
|
|
90
94
|
: DEFAULT_THEME_OPTIONS.mono.s)), options)), [options, language, themeValues === null || themeValues === void 0 ? void 0 : themeValues.mono]);
|
|
95
|
+
if (!canRender) {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
91
98
|
return (_jsx("div", Object.assign({ className: className }, extractSupportProps(props), { ref: setWrapperElement, 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, onMount: onEditorMount, path: yamlModelPath })) })));
|
|
92
99
|
}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.4.7-preview-
|
|
7
|
+
"version": "0.4.7-preview-ac85ab7b.0",
|
|
8
8
|
"sideEffects": [
|
|
9
9
|
"*.css",
|
|
10
10
|
"*.woff",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@types/chroma-js": "2.4.4"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "b48c28c30724091afb0c9c00a9f06a0d8fdaa943"
|
|
50
50
|
}
|
|
@@ -3,7 +3,7 @@ import cn from 'classnames';
|
|
|
3
3
|
import { useCallback, useMemo, useState } from 'react';
|
|
4
4
|
|
|
5
5
|
import { Spinner } from '@snack-uikit/loaders';
|
|
6
|
-
import { extractSupportProps, isBrowser, WithSupportProps } from '@snack-uikit/utils';
|
|
6
|
+
import { extractSupportProps, isBrowser, useLayoutEffect, WithSupportProps } from '@snack-uikit/utils';
|
|
7
7
|
|
|
8
8
|
import {
|
|
9
9
|
CODE_EDITOR_OPTIONS,
|
|
@@ -16,8 +16,6 @@ import styles from './styles.module.scss';
|
|
|
16
16
|
import { EditorProps, YamlEditorProps } from './types';
|
|
17
17
|
import { initLoaderConfig, isDark } from './utils';
|
|
18
18
|
|
|
19
|
-
initLoaderConfig();
|
|
20
|
-
|
|
21
19
|
export type CodeEditorProps = WithSupportProps<{
|
|
22
20
|
/**
|
|
23
21
|
* Название текущей темы. Значение не важно, важно что смена значения запускает пересчет стилей.
|
|
@@ -41,6 +39,12 @@ export function CodeEditor({
|
|
|
41
39
|
...props
|
|
42
40
|
}: CodeEditorProps) {
|
|
43
41
|
const { language } = props;
|
|
42
|
+
const [canRender, setCanRender] = useState(false);
|
|
43
|
+
|
|
44
|
+
useLayoutEffect(() => {
|
|
45
|
+
initLoaderConfig();
|
|
46
|
+
setCanRender(true);
|
|
47
|
+
}, []);
|
|
44
48
|
|
|
45
49
|
const monaco = useMonaco();
|
|
46
50
|
const [wrapperElement, setWrapperElement] = useState<HTMLDivElement | null>(null);
|
|
@@ -134,6 +138,10 @@ export function CodeEditor({
|
|
|
134
138
|
[options, language, themeValues?.mono],
|
|
135
139
|
);
|
|
136
140
|
|
|
141
|
+
if (!canRender) {
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
|
|
137
145
|
return (
|
|
138
146
|
<div className={className} {...extractSupportProps(props)} ref={setWrapperElement}>
|
|
139
147
|
<Editor
|