@snack-uikit/code-editor 0.5.1 → 0.5.2-preview-76dd9d31.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/README.md CHANGED
@@ -36,6 +36,11 @@
36
36
  | onMount | `OnMount` | - | Signature: function(editor: monaco.editor.IStandaloneCodeEditor, monaco: Monaco) => void An event is emitted when the editor is mounted It gets the editor instance as a first argument and the monaco instance as a second Defaults to "noop" |
37
37
  | onChange | `OnChange` | - | Signature: function(value: string \| undefined, ev: monaco.editor.IModelContentChangedEvent) => void An event is emitted when the content of the current model is changed |
38
38
  | onValidate | `OnValidate` | - | Signature: function(markers: monaco.editor.IMarker[]) => void An event is emitted when the content of the current model is changed and the current model markers are ready Defaults to "noop" |
39
+ ## asyncCodeEditor
40
+ ### Props
41
+ | name | type | default value | description |
42
+ |------|------|---------------|-------------|
43
+ | configLoader* | `() => Promise<{ paths?: { vs?: string; }; 'vs/nls'?: { availableLanguages?: object; }; monaco?: typeof import("/Users/alssmirnov/p/snack-uikit/node_modules/monaco-editor/esm/vs/editor/editor.api"); }>` | - | |
39
44
 
40
45
 
41
46
  [//]: DOCUMENTATION_SECTION_END
@@ -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,
@@ -0,0 +1,9 @@
1
+ import { loader } from '@monaco-editor/react';
2
+ import { CodeEditor } from './CodeEditor';
3
+ type LoaderConfig = Parameters<(typeof loader)['config']>[0];
4
+ export declare const asyncCodeEditor: (opts: {
5
+ configLoader: () => Promise<LoaderConfig>;
6
+ }) => Promise<{
7
+ default: typeof CodeEditor;
8
+ }>;
9
+ export {};
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+
3
+ var __awaiter = void 0 && (void 0).__awaiter || function (thisArg, _arguments, P, generator) {
4
+ function adopt(value) {
5
+ return value instanceof P ? value : new P(function (resolve) {
6
+ resolve(value);
7
+ });
8
+ }
9
+ return new (P || (P = Promise))(function (resolve, reject) {
10
+ function fulfilled(value) {
11
+ try {
12
+ step(generator.next(value));
13
+ } catch (e) {
14
+ reject(e);
15
+ }
16
+ }
17
+ function rejected(value) {
18
+ try {
19
+ step(generator["throw"](value));
20
+ } catch (e) {
21
+ reject(e);
22
+ }
23
+ }
24
+ function step(result) {
25
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
26
+ }
27
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
28
+ });
29
+ };
30
+ Object.defineProperty(exports, "__esModule", {
31
+ value: true
32
+ });
33
+ exports.asyncCodeEditor = void 0;
34
+ const react_1 = require("@monaco-editor/react");
35
+ const CodeEditor_1 = require("./CodeEditor");
36
+ const asyncCodeEditor = opts => __awaiter(void 0, void 0, void 0, function* () {
37
+ const {
38
+ configLoader
39
+ } = opts;
40
+ const config = yield configLoader();
41
+ react_1.loader.config(config);
42
+ return {
43
+ default: CodeEditor_1.CodeEditor
44
+ };
45
+ });
46
+ exports.asyncCodeEditor = asyncCodeEditor;
@@ -1,2 +1,3 @@
1
1
  export * from './CodeEditor';
2
2
  export * from './types';
3
+ export * from './asyncLoader';
@@ -23,4 +23,5 @@ Object.defineProperty(exports, "__esModule", {
23
23
  value: true
24
24
  });
25
25
  __exportStar(require("./CodeEditor"), exports);
26
- __exportStar(require("./types"), exports);
26
+ __exportStar(require("./types"), exports);
27
+ __exportStar(require("./asyncLoader"), exports);
@@ -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();
@@ -0,0 +1,9 @@
1
+ import { loader } from '@monaco-editor/react';
2
+ import { CodeEditor } from './CodeEditor';
3
+ type LoaderConfig = Parameters<(typeof loader)['config']>[0];
4
+ export declare const asyncCodeEditor: (opts: {
5
+ configLoader: () => Promise<LoaderConfig>;
6
+ }) => Promise<{
7
+ default: typeof CodeEditor;
8
+ }>;
9
+ export {};
@@ -0,0 +1,17 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { loader } from '@monaco-editor/react';
11
+ import { CodeEditor } from './CodeEditor';
12
+ export const asyncCodeEditor = (opts) => __awaiter(void 0, void 0, void 0, function* () {
13
+ const { configLoader } = opts;
14
+ const config = yield configLoader();
15
+ loader.config(config);
16
+ return { default: CodeEditor };
17
+ });
@@ -1,2 +1,3 @@
1
1
  export * from './CodeEditor';
2
2
  export * from './types';
3
+ export * from './asyncLoader';
@@ -1,2 +1,3 @@
1
1
  export * from './CodeEditor';
2
2
  export * from './types';
3
+ export * from './asyncLoader';
@@ -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.1",
7
+ "version": "0.5.2-preview-76dd9d31.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": "ec4e54b1ea5c4455ca404632e1f205e22b881f98"
49
+ "gitHead": "77dd00305b277c6ffee68e32451d536d8da2dca2"
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
  /**
@@ -0,0 +1,14 @@
1
+ import { loader } from '@monaco-editor/react';
2
+
3
+ import { CodeEditor } from './CodeEditor';
4
+
5
+ type LoaderConfig = Parameters<(typeof loader)['config']>[0];
6
+
7
+ export const asyncCodeEditor = async (opts: { configLoader: () => Promise<LoaderConfig> }) => {
8
+ const { configLoader } = opts;
9
+ const config = await configLoader();
10
+
11
+ loader.config(config);
12
+
13
+ return { default: CodeEditor };
14
+ };
@@ -1,2 +1,3 @@
1
1
  export * from './CodeEditor';
2
2
  export * from './types';
3
+ export * from './asyncLoader';
@@ -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] };