@snack-uikit/code-editor 0.2.1-preview-62ed8d71.0 → 0.2.1-preview-a9faaab6.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,7 +10,7 @@ var __rest = (this && this.__rest) || function (s, e) {
10
10
  return t;
11
11
  };
12
12
  import { jsx as _jsx } from "react/jsx-runtime";
13
- import { Editor, loader, useMonaco } from '@monaco-editor/react';
13
+ import { Editor, useMonaco } from '@monaco-editor/react';
14
14
  import cn from 'classnames';
15
15
  import { useMemo } from 'react';
16
16
  import { Spinner } from '@snack-uikit/loaders';
@@ -18,8 +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';
22
- loader.config({ paths: { vs: 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.43.0/min/vs' } });
21
+ import { initMonacoEditorReactLoaderConfig, isDark } from './utils';
22
+ initMonacoEditorReactLoaderConfig();
23
23
  export function CodeEditor(_a) {
24
24
  var { themeClassName, className, theme, options, loading, hasBackground = true } = _a, props = __rest(_a, ["themeClassName", "className", "theme", "options", "loading", "hasBackground"]);
25
25
  const monaco = useMonaco();
@@ -1,2 +1,3 @@
1
1
  export declare function rgb2hsl(HTMLcolor: string): number[];
2
2
  export declare function isDark(color: string): boolean;
3
+ export declare function initMonacoEditorReactLoaderConfig(): void;
@@ -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,14 @@ 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 initMonacoEditorReactLoaderConfig() {
38
+ if (!window) {
39
+ return;
40
+ }
41
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
42
+ // @ts-ignore
43
+ const vs = window['__snack_code_editor_paths__'];
44
+ if (vs) {
45
+ loader.config({ paths: { vs } });
46
+ }
47
+ }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.2.1-preview-62ed8d71.0",
7
+ "version": "0.2.1-preview-a9faaab6.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": "04318956c6d179aa137184a48f90ec3f9aa83942"
40
+ "gitHead": "6314839f8b24a0700f000e7a40145e85f0b0eea2"
41
41
  }
@@ -1,4 +1,4 @@
1
- import { Editor, EditorProps, loader, useMonaco } from '@monaco-editor/react';
1
+ import { Editor, EditorProps, useMonaco } from '@monaco-editor/react';
2
2
  import cn from 'classnames';
3
3
  import { useMemo } from 'react';
4
4
 
@@ -8,9 +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 { initMonacoEditorReactLoaderConfig, isDark } from './utils';
12
12
 
13
- loader.config({ paths: { vs: 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.43.0/min/vs' } });
13
+ initMonacoEditorReactLoaderConfig();
14
14
 
15
15
  export type CodeEditorProps = WithSupportProps<{
16
16
  /** Класснейм подключенной темы (из хука useThemeConfig() или ThemeProvider)
@@ -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,17 @@ 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 initMonacoEditorReactLoaderConfig() {
52
+ if (!window) {
53
+ return;
54
+ }
55
+
56
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
57
+ // @ts-ignore
58
+ const vs = window['__snack_code_editor_paths__'] as string | undefined;
59
+
60
+ if (vs) {
61
+ loader.config({ paths: { vs } });
62
+ }
63
+ }