@snack-uikit/code-editor 0.5.2 → 0.6.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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # 0.6.0 (2025-03-27)
7
+
8
+
9
+ ### BREAKING CHANGES
10
+
11
+
12
+ * **FF-6299:** Remove module level initial function. ([5b2280a](https://git.sbercloud.tech/sbercloud-ui/tokens-design-system/snack-uikit/commits/5b2280af6fd2a14f990598e717d117818bf10353))
13
+
14
+
15
+
16
+
6
17
  ## 0.5.2 (2025-03-17)
7
18
 
8
19
  ### Only dependencies have been changed
package/README.md CHANGED
@@ -41,15 +41,39 @@
41
41
  [//]: DOCUMENTATION_SECTION_END
42
42
 
43
43
  ### Поддержка YAML
44
- Для обеспечения полноценной работы YAML Monaco Editor необходимо подключить `yaml.worker`. Это можно сделать следующими способами: с использованием [`window.MonacoEnvironment`](https://www.npmjs.com/package/monaco-yaml#usage) или с помощью плагина [`MonacoWebpackPlugin`](https://www.npmjs.com/package/monaco-yaml#using-monaco-webpack-loader-plugin) . Подробнее с `monaco-yaml` можно ознакомиться [тут]((https://www.npmjs.com/package/monaco-yaml))
44
+
45
+ Для обеспечения полноценной работы YAML Monaco Editor необходимо подключить `yaml.worker`. Это можно сделать следующими способами: с использованием [`window.MonacoEnvironment`](https://www.npmjs.com/package/monaco-yaml#usage) или с помощью плагина [`MonacoWebpackPlugin`](https://www.npmjs.com/package/monaco-yaml#using-monaco-webpack-loader-plugin) . Подробнее с `monaco-yaml` можно ознакомиться [тут](<(https://www.npmjs.com/package/monaco-yaml)>)
45
46
 
46
47
  ### Как редактор загружает worker?
48
+
47
49
  Плагин создает новые точки входа каждого build-in воркера и для каждого дабавленного отдельно. Плагин создат глобальную переменную, используя которую редкатор будет загружать нужный воркер на основе текущего `language`.
48
50
 
49
51
  Чтобы управлять конфигурацией загрузчика Monaco Editor, добавьте
52
+
50
53
  ```typescript
51
54
  import * as monaco from 'monaco-editor';
52
55
  import { loader } from '@snack-uikit/code-editor';
53
56
  loader.config({ monaco });
54
57
  ```
58
+
55
59
  Это позволяет динамически настраивать пути и другие параметры при инициализации редактора.
60
+
61
+ Для загрузки `monaco-editor` асинхронно можно воспользоваться следующим способом:
62
+
63
+ ```typescript
64
+ // import * as monaco from 'monaco-editor'; // ~3Mb
65
+ import { lazy, Suspense } from 'react';
66
+ import { loader, CodeEditor } from '@snack-uikit/code-editor';
67
+
68
+ const Editor = lazy(async () => {
69
+ const monaco = await import('monaco-editor').then(module => module.default);
70
+ loader.config({ monaco });
71
+ return { default: CodeEditor };
72
+ });
73
+
74
+ const MyComponent = () => {
75
+ return <Suspense fallback={<Loader height={height} />}>
76
+ <Editor />
77
+ </Suspense>
78
+ }
79
+ ```
@@ -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,
@@ -2,5 +2,4 @@ import { SchemasSettings } from 'monaco-yaml';
2
2
  import { JsonSchema } from './types';
3
3
  export declare function rgb2hsl(HTMLcolor: string): number[];
4
4
  export declare function isDark(color: string): boolean;
5
- export declare function initLoaderConfig(): void;
6
5
  export declare const getJsonSchema: (jsonSchema?: JsonSchema) => SchemasSettings | undefined;
@@ -11,8 +11,6 @@ Object.defineProperty(exports, "__esModule", {
11
11
  exports.getJsonSchema = void 0;
12
12
  exports.rgb2hsl = rgb2hsl;
13
13
  exports.isDark = isDark;
14
- exports.initLoaderConfig = initLoaderConfig;
15
- const react_1 = require("@monaco-editor/react");
16
14
  const chroma_js_1 = __importDefault(require("chroma-js"));
17
15
  const constants_1 = require("./constants");
18
16
  function rgb2hsl(HTMLcolor) {
@@ -48,14 +46,6 @@ function isDark(color) {
48
46
  const [h, _, l] = rgb2hsl(color);
49
47
  return h < 0.55 && l >= 0.5 || h >= 0.55 && l >= 0.75;
50
48
  }
51
- function initLoaderConfig() {
52
- if (!window) {
53
- return;
54
- }
55
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
56
- // @ts-ignore
57
- window['__snack-code-editor-loader-config__'] && react_1.loader.config(window['__snack-code-editor-loader-config__']);
58
- }
59
49
  const getJsonSchema = jsonSchema => jsonSchema && Object.assign(Object.assign({}, jsonSchema), {
60
50
  uri: (jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.uri) || constants_1.DEFAULT_SCHEMA_URI,
61
51
  fileMatch: [jsonSchema.fileMatch]
@@ -18,8 +18,7 @@ import { extractSupportProps, isBrowser } from '@snack-uikit/utils';
18
18
  import { CODE_EDITOR_OPTIONS, DEFAULT_THEME_OPTIONS, DEFAULT_THEME_VALUES } from './constants';
19
19
  import { useApplyJsonSchema, useCalculatedThemeValues } from './hooks';
20
20
  import styles from './styles.module.css';
21
- import { initLoaderConfig, isDark } from './utils';
22
- initLoaderConfig();
21
+ import { isDark } from './utils';
23
22
  export function CodeEditor(_a) {
24
23
  var { themeName, className, theme, options, loading, hasBackground = true, onMount, language } = _a, props = __rest(_a, ["themeName", "className", "theme", "options", "loading", "hasBackground", "onMount", "language"]);
25
24
  const monaco = useMonaco();
@@ -2,5 +2,4 @@ import { SchemasSettings } from 'monaco-yaml';
2
2
  import { JsonSchema } from './types';
3
3
  export declare function rgb2hsl(HTMLcolor: string): number[];
4
4
  export declare function isDark(color: string): boolean;
5
- export declare function initLoaderConfig(): void;
6
5
  export declare const getJsonSchema: (jsonSchema?: JsonSchema) => SchemasSettings | undefined;
@@ -1,4 +1,3 @@
1
- import { loader } from '@monaco-editor/react';
2
1
  import chroma from 'chroma-js';
3
2
  import { DEFAULT_SCHEMA_URI } from './constants';
4
3
  export function rgb2hsl(HTMLcolor) {
@@ -38,12 +37,4 @@ export function isDark(color) {
38
37
  const [h, _, l] = rgb2hsl(color);
39
38
  return (h < 0.55 && l >= 0.5) || (h >= 0.55 && l >= 0.75);
40
39
  }
41
- export function initLoaderConfig() {
42
- if (!window) {
43
- return;
44
- }
45
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
46
- // @ts-ignore
47
- window['__snack-code-editor-loader-config__'] && loader.config(window['__snack-code-editor-loader-config__']);
48
- }
49
40
  export const getJsonSchema = (jsonSchema) => jsonSchema && Object.assign(Object.assign({}, jsonSchema), { uri: (jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.uri) || DEFAULT_SCHEMA_URI, fileMatch: [jsonSchema.fileMatch] });
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.5.2",
7
+ "version": "0.6.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": "d12776ae6b32233f12df33facc32de6a8758706a"
49
+ "gitHead": "2f7303852cd42843ff939a7c5eaa0dceeb5a49df"
50
50
  }
@@ -9,9 +9,7 @@ import { CODE_EDITOR_OPTIONS, DEFAULT_THEME_OPTIONS, DEFAULT_THEME_VALUES } from
9
9
  import { useApplyJsonSchema, useCalculatedThemeValues } from './hooks';
10
10
  import styles from './styles.module.scss';
11
11
  import { EditorBaseProps, EditorWithJsonSchemaProps } from './types';
12
- import { initLoaderConfig, isDark } from './utils';
13
-
14
- initLoaderConfig();
12
+ import { isDark } from './utils';
15
13
 
16
14
  export type CodeEditorProps = WithSupportProps<{
17
15
  /**
@@ -1,4 +1,3 @@
1
- import { loader } from '@monaco-editor/react';
2
1
  import chroma from 'chroma-js';
3
2
  import { SchemasSettings } from 'monaco-yaml';
4
3
 
@@ -55,15 +54,5 @@ export function isDark(color: string) {
55
54
  return (h < 0.55 && l >= 0.5) || (h >= 0.55 && l >= 0.75);
56
55
  }
57
56
 
58
- export function initLoaderConfig() {
59
- if (!window) {
60
- return;
61
- }
62
-
63
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
64
- // @ts-ignore
65
- window['__snack-code-editor-loader-config__'] && loader.config(window['__snack-code-editor-loader-config__']);
66
- }
67
-
68
57
  export const getJsonSchema = (jsonSchema?: JsonSchema): SchemasSettings | undefined =>
69
58
  jsonSchema && { ...jsonSchema, uri: jsonSchema?.uri || DEFAULT_SCHEMA_URI, fileMatch: [jsonSchema.fileMatch] };