@snack-uikit/code-editor 0.2.1 → 0.2.2-preview-b06241ae.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.
|
@@ -12,7 +12,7 @@ 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 cn from 'classnames';
|
|
15
|
-
import { useCallback, useMemo,
|
|
15
|
+
import { useCallback, useMemo, useState } from 'react';
|
|
16
16
|
import { Spinner } from '@snack-uikit/loaders';
|
|
17
17
|
import { extractSupportProps } from '@snack-uikit/utils';
|
|
18
18
|
import { CODE_EDITOR_OPTIONS, DEFAULT_THEME_OPTIONS, DEFAULT_THEME_VALUES } from './constants';
|
|
@@ -23,13 +23,13 @@ initLoaderConfig();
|
|
|
23
23
|
export function CodeEditor(_a) {
|
|
24
24
|
var { themeName, className, theme, options, loading, hasBackground = true, onMount } = _a, props = __rest(_a, ["themeName", "className", "theme", "options", "loading", "hasBackground", "onMount"]);
|
|
25
25
|
const monaco = useMonaco();
|
|
26
|
-
const
|
|
26
|
+
const [wrapperElement, setWrapperElement] = useState(null);
|
|
27
27
|
const onEditorMount = useCallback((editor, monaco) => {
|
|
28
28
|
var _a, _b;
|
|
29
29
|
monaco && ((_b = (_a = window === null || window === void 0 ? void 0 : window.document) === null || _a === void 0 ? void 0 : _a.fonts) === null || _b === void 0 ? void 0 : _b.ready.finally(monaco.editor.remeasureFonts));
|
|
30
30
|
onMount === null || onMount === void 0 ? void 0 : onMount(editor, monaco);
|
|
31
31
|
}, [onMount]);
|
|
32
|
-
const themeValues = useCalculatedThemeValues({ themeName, stylesOriginNode:
|
|
32
|
+
const themeValues = useCalculatedThemeValues({ themeName, stylesOriginNode: wrapperElement });
|
|
33
33
|
const themeDataWithoutBase = useMemo(() => (Object.assign({ inherit: true }, ((themeValues === null || themeValues === void 0 ? void 0 : themeValues.sys)
|
|
34
34
|
? {
|
|
35
35
|
semanticTokenColors: {
|
|
@@ -86,5 +86,5 @@ export function CodeEditor(_a) {
|
|
|
86
86
|
fontFamily: themeValues.mono.body.s['font-family'],
|
|
87
87
|
}
|
|
88
88
|
: DEFAULT_THEME_OPTIONS.mono.s)), options)), [options, themeValues === null || themeValues === void 0 ? void 0 : themeValues.mono]);
|
|
89
|
-
return (_jsx("div", Object.assign({ className: className }, extractSupportProps(props), { ref:
|
|
89
|
+
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 })) })));
|
|
90
90
|
}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.2.
|
|
7
|
+
"version": "0.2.2-preview-b06241ae.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": "a38ff50b1c431849e638f80ff5a3dd37d268e8ec"
|
|
41
41
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Editor, EditorProps, OnMount, useMonaco } from '@monaco-editor/react';
|
|
2
2
|
import cn from 'classnames';
|
|
3
|
-
import { useCallback, useMemo,
|
|
3
|
+
import { useCallback, useMemo, useState } from 'react';
|
|
4
4
|
|
|
5
5
|
import { Spinner } from '@snack-uikit/loaders';
|
|
6
6
|
import { extractSupportProps, WithSupportProps } from '@snack-uikit/utils';
|
|
@@ -35,7 +35,7 @@ export function CodeEditor({
|
|
|
35
35
|
...props
|
|
36
36
|
}: CodeEditorProps) {
|
|
37
37
|
const monaco = useMonaco();
|
|
38
|
-
const
|
|
38
|
+
const [wrapperElement, setWrapperElement] = useState<HTMLDivElement | null>(null);
|
|
39
39
|
|
|
40
40
|
const onEditorMount = useCallback<OnMount>(
|
|
41
41
|
(editor, monaco) => {
|
|
@@ -45,7 +45,7 @@ export function CodeEditor({
|
|
|
45
45
|
[onMount],
|
|
46
46
|
);
|
|
47
47
|
|
|
48
|
-
const themeValues = useCalculatedThemeValues({ themeName, stylesOriginNode:
|
|
48
|
+
const themeValues = useCalculatedThemeValues({ themeName, stylesOriginNode: wrapperElement });
|
|
49
49
|
|
|
50
50
|
const themeDataWithoutBase = useMemo(
|
|
51
51
|
() => ({
|
|
@@ -124,7 +124,7 @@ export function CodeEditor({
|
|
|
124
124
|
);
|
|
125
125
|
|
|
126
126
|
return (
|
|
127
|
-
<div className={className} {...extractSupportProps(props)} ref={
|
|
127
|
+
<div className={className} {...extractSupportProps(props)} ref={setWrapperElement}>
|
|
128
128
|
<Editor
|
|
129
129
|
{...props}
|
|
130
130
|
theme={theme ?? dark ? 'snackDark' : 'snack'}
|