@snack-uikit/code-editor 0.2.1-preview-69f7a1cd.0 → 0.2.1-preview-03f6df7e.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.
@@ -8,4 +8,4 @@ export type CodeEditorProps = WithSupportProps<{
8
8
  /** Включение/отключение псевдобекграунда*/
9
9
  hasBackground?: boolean;
10
10
  }> & EditorProps;
11
- export declare function CodeEditor({ themeClassName, className, theme, options, loading, hasBackground, ...props }: CodeEditorProps): import("react/jsx-runtime").JSX.Element;
11
+ export declare function CodeEditor({ themeClassName, className, theme, options, loading, hasBackground, onMount, ...props }: CodeEditorProps): import("react/jsx-runtime").JSX.Element;
@@ -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 { useEffect, useMemo } from 'react';
15
+ import { useCallback, useMemo } 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';
@@ -21,8 +21,13 @@ import styles from './styles.module.css';
21
21
  import { initLoaderConfig, isDark } from './utils';
22
22
  initLoaderConfig();
23
23
  export function CodeEditor(_a) {
24
- var { themeClassName, className, theme, options, loading, hasBackground = true } = _a, props = __rest(_a, ["themeClassName", "className", "theme", "options", "loading", "hasBackground"]);
24
+ var { themeClassName, className, theme, options, loading, hasBackground = true, onMount } = _a, props = __rest(_a, ["themeClassName", "className", "theme", "options", "loading", "hasBackground", "onMount"]);
25
25
  const monaco = useMonaco();
26
+ const onEditorMount = useCallback((editor, monaco) => {
27
+ var _a, _b;
28
+ 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));
29
+ onMount === null || onMount === void 0 ? void 0 : onMount(editor, monaco);
30
+ }, [onMount]);
26
31
  const themeValues = useCalculatedThemeValues(themeClassName);
27
32
  const themeDataWithoutBase = useMemo(() => (Object.assign({ inherit: true }, ((themeValues === null || themeValues === void 0 ? void 0 : themeValues.sys)
28
33
  ? {
@@ -80,10 +85,5 @@ export function CodeEditor(_a) {
80
85
  fontFamily: themeValues.mono.body.s['font-family'],
81
86
  }
82
87
  : DEFAULT_THEME_OPTIONS.mono.s)), options)), [options, themeValues === null || themeValues === void 0 ? void 0 : themeValues.mono]);
83
- useEffect(() => {
84
- // eslint-disable-next-line no-console
85
- console.log('!_! remeasureFonts');
86
- setTimeout(() => monaco === null || monaco === void 0 ? void 0 : monaco.editor.remeasureFonts(), 0);
87
- }, [mergedOptions, monaco === null || monaco === void 0 ? void 0 : monaco.editor]);
88
- 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 })) })));
88
+ 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, onMount: onEditorMount })) })));
89
89
  }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.2.1-preview-69f7a1cd.0",
7
+ "version": "0.2.1-preview-03f6df7e.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": "54528abded4adf2830a4eb799a0096664ee715de"
40
+ "gitHead": "6901ea13eae02eca6b24ac88fc2f8e8e8f9c3dba"
41
41
  }
@@ -1,6 +1,6 @@
1
- import { Editor, EditorProps, useMonaco } from '@monaco-editor/react';
1
+ import { Editor, EditorProps, OnMount, useMonaco } from '@monaco-editor/react';
2
2
  import cn from 'classnames';
3
- import { useEffect, useMemo } from 'react';
3
+ import { useCallback, useMemo } from 'react';
4
4
 
5
5
  import { Spinner } from '@snack-uikit/loaders';
6
6
  import { extractSupportProps, WithSupportProps } from '@snack-uikit/utils';
@@ -29,10 +29,19 @@ export function CodeEditor({
29
29
  options,
30
30
  loading,
31
31
  hasBackground = true,
32
+ onMount,
32
33
  ...props
33
34
  }: CodeEditorProps) {
34
35
  const monaco = useMonaco();
35
36
 
37
+ const onEditorMount = useCallback<OnMount>(
38
+ (editor, monaco) => {
39
+ monaco && window?.document?.fonts?.ready.finally(monaco.editor.remeasureFonts);
40
+ onMount?.(editor, monaco);
41
+ },
42
+ [onMount],
43
+ );
44
+
36
45
  const themeValues = useCalculatedThemeValues(themeClassName);
37
46
 
38
47
  const themeDataWithoutBase = useMemo(
@@ -111,12 +120,6 @@ export function CodeEditor({
111
120
  [options, themeValues?.mono],
112
121
  );
113
122
 
114
- useEffect(() => {
115
- // eslint-disable-next-line no-console
116
- console.log('!_! remeasureFonts');
117
- setTimeout(() => monaco?.editor.remeasureFonts(), 0);
118
- }, [mergedOptions, monaco?.editor]);
119
-
120
123
  return (
121
124
  <div className={className} {...extractSupportProps(props)}>
122
125
  <Editor
@@ -125,6 +128,7 @@ export function CodeEditor({
125
128
  className={cn({ [styles.editor]: hasBackground })}
126
129
  loading={loading ?? <Spinner />}
127
130
  options={mergedOptions}
131
+ onMount={onEditorMount}
128
132
  />
129
133
  </div>
130
134
  );