@snack-uikit/code-editor 0.4.7-preview-2af706c7.0 → 0.4.7
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 +10 -0
- package/README.md +0 -15
- package/dist/cjs/components/CodeEditor.d.ts +3 -3
- package/dist/cjs/components/CodeEditor.js +6 -12
- package/dist/cjs/components/constants.d.ts +0 -6
- package/dist/cjs/components/constants.js +2 -8
- package/dist/cjs/components/hooks.d.ts +0 -7
- package/dist/cjs/components/hooks.js +3 -61
- package/dist/cjs/components/index.d.ts +0 -1
- package/dist/cjs/components/index.js +1 -2
- package/dist/cjs/components/utils.d.ts +0 -3
- package/dist/cjs/components/utils.js +1 -8
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js +1 -7
- package/dist/esm/components/CodeEditor.d.ts +3 -3
- package/dist/esm/components/CodeEditor.js +5 -6
- package/dist/esm/components/constants.d.ts +0 -6
- package/dist/esm/components/constants.js +0 -6
- package/dist/esm/components/hooks.d.ts +0 -7
- package/dist/esm/components/hooks.js +2 -57
- package/dist/esm/components/index.d.ts +0 -1
- package/dist/esm/components/index.js +0 -1
- package/dist/esm/components/utils.d.ts +0 -3
- package/dist/esm/components/utils.js +0 -2
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -1
- package/package.json +5 -6
- package/src/components/CodeEditor.tsx +4 -14
- package/src/components/constants.ts +0 -8
- package/src/components/hooks.ts +2 -71
- package/src/components/index.ts +0 -1
- package/src/components/utils.ts +0 -7
- package/src/index.ts +1 -1
- package/dist/cjs/components/types.d.ts +0 -25
- package/dist/cjs/components/types.js +0 -5
- package/dist/esm/components/types.d.ts +0 -25
- package/dist/esm/components/types.js +0 -1
- package/src/components/types.ts +0 -33
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,16 @@
|
|
|
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.4.7 (2025-01-23)
|
|
7
|
+
|
|
8
|
+
### Only dependencies have been changed
|
|
9
|
+
* [@snack-uikit/loaders@0.9.1](https://github.com/cloud-ru-tech/snack-uikit/blob/master/packages/loaders/CHANGELOG.md)
|
|
10
|
+
* [@snack-uikit/utils@3.7.0](https://github.com/cloud-ru-tech/snack-uikit/blob/master/packages/utils/CHANGELOG.md)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
6
16
|
## 0.4.6 (2024-12-17)
|
|
7
17
|
|
|
8
18
|
### Only dependencies have been changed
|
package/README.md
CHANGED
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
### Props
|
|
13
13
|
| name | type | default value | description |
|
|
14
14
|
|------|------|---------------|-------------|
|
|
15
|
-
| jsonSchema* | `JsonSchema` | - | Схема для валидации |
|
|
16
15
|
| themeName | `string` | - | Название текущей темы. Значение не важно, важно что смена значения запускает пересчет стилей. |
|
|
17
16
|
| hasBackground | `boolean` | true | Включение/отключение псевдобекграунда |
|
|
18
17
|
| defaultValue | `string` | - | Default value of the current model |
|
|
@@ -39,17 +38,3 @@
|
|
|
39
38
|
|
|
40
39
|
|
|
41
40
|
[//]: DOCUMENTATION_SECTION_END
|
|
42
|
-
|
|
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))
|
|
45
|
-
|
|
46
|
-
### Как редактор загружает worker?
|
|
47
|
-
Плагин создает новые точки входа каждого build-in воркера и для каждого дабавленного отдельно. Плагин создат глобальную переменную, используя которую редкатор будет загружать нужный воркер на основе текущего `language`.
|
|
48
|
-
|
|
49
|
-
Чтобы управлять конфигурацией загрузчика Monaco Editor, добавьте
|
|
50
|
-
```typescript
|
|
51
|
-
import * as monaco from 'monaco-editor';
|
|
52
|
-
import { loader } from '@snack-uikit/code-editor';
|
|
53
|
-
loader.config({ monaco });
|
|
54
|
-
```
|
|
55
|
-
Это позволяет динамически настраивать пути и другие параметры при инициализации редактора.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { EditorProps } from '@monaco-editor/react';
|
|
1
2
|
import { WithSupportProps } from '@snack-uikit/utils';
|
|
2
|
-
import { EditorBaseProps, EditorWithJsonSchemaProps } from './types';
|
|
3
3
|
export type CodeEditorProps = WithSupportProps<{
|
|
4
4
|
/**
|
|
5
5
|
* Название текущей темы. Значение не важно, важно что смена значения запускает пересчет стилей.
|
|
@@ -9,5 +9,5 @@ export type CodeEditorProps = WithSupportProps<{
|
|
|
9
9
|
* Включение/отключение псевдобекграунда
|
|
10
10
|
*/
|
|
11
11
|
hasBackground?: boolean;
|
|
12
|
-
}> &
|
|
13
|
-
export declare function CodeEditor({ themeName, className, theme, options, loading, hasBackground, onMount,
|
|
12
|
+
}> & EditorProps;
|
|
13
|
+
export declare function CodeEditor({ themeName, className, theme, options, loading, hasBackground, onMount, ...props }: CodeEditorProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -36,16 +36,11 @@ function CodeEditor(_a) {
|
|
|
36
36
|
options,
|
|
37
37
|
loading,
|
|
38
38
|
hasBackground = true,
|
|
39
|
-
onMount
|
|
40
|
-
language
|
|
39
|
+
onMount
|
|
41
40
|
} = _a,
|
|
42
|
-
props = __rest(_a, ["themeName", "className", "theme", "options", "loading", "hasBackground", "onMount"
|
|
41
|
+
props = __rest(_a, ["themeName", "className", "theme", "options", "loading", "hasBackground", "onMount"]);
|
|
43
42
|
const monaco = (0, react_1.useMonaco)();
|
|
44
43
|
const [wrapperElement, setWrapperElement] = (0, react_2.useState)(null);
|
|
45
|
-
const {
|
|
46
|
-
jsonSchemaProps,
|
|
47
|
-
jsonSchemaOptions
|
|
48
|
-
} = (0, hooks_1.useApplyJsonSchema)(language, 'jsonSchema' in props ? props.jsonSchema : undefined);
|
|
49
44
|
const onEditorMount = (0, react_2.useCallback)((editor, monaco) => {
|
|
50
45
|
var _a;
|
|
51
46
|
monaco && (0, utils_1.isBrowser)() && ((_a = document === null || document === void 0 ? void 0 : document.fonts) === null || _a === void 0 ? void 0 : _a.ready.finally(monaco.editor.remeasureFonts));
|
|
@@ -106,24 +101,23 @@ function CodeEditor(_a) {
|
|
|
106
101
|
monaco === null || monaco === void 0 ? void 0 : monaco.editor.defineTheme('snack', Object.assign(Object.assign({}, themeDataWithoutBase), {
|
|
107
102
|
base: 'vs'
|
|
108
103
|
}));
|
|
109
|
-
const mergedOptions = (0, react_2.useMemo)(() => Object.assign(Object.assign(Object.assign(
|
|
104
|
+
const mergedOptions = (0, react_2.useMemo)(() => Object.assign(Object.assign(Object.assign({}, constants_1.CODE_EDITOR_OPTIONS), (themeValues === null || themeValues === void 0 ? void 0 : themeValues.mono) ? {
|
|
110
105
|
fontSize: Number.parseFloat(themeValues.mono.body.s['font-size']),
|
|
111
106
|
fontWeight: themeValues.mono.body.s['font-weight'],
|
|
112
107
|
fontFamily: themeValues.mono.body.s['font-family']
|
|
113
|
-
} : constants_1.DEFAULT_THEME_OPTIONS.mono.s), options), [options, themeValues === null || themeValues === void 0 ? void 0 : themeValues.mono
|
|
108
|
+
} : constants_1.DEFAULT_THEME_OPTIONS.mono.s), options), [options, themeValues === null || themeValues === void 0 ? void 0 : themeValues.mono]);
|
|
114
109
|
return (0, jsx_runtime_1.jsx)("div", Object.assign({
|
|
115
110
|
className: className
|
|
116
111
|
}, (0, utils_1.extractSupportProps)(props), {
|
|
117
112
|
ref: setWrapperElement,
|
|
118
|
-
children: (0, jsx_runtime_1.jsx)(react_1.Editor, Object.assign({}, props,
|
|
113
|
+
children: (0, jsx_runtime_1.jsx)(react_1.Editor, Object.assign({}, props, {
|
|
119
114
|
theme: theme !== null && theme !== void 0 ? theme : dark ? 'snackDark' : 'snack',
|
|
120
115
|
className: (0, classnames_1.default)({
|
|
121
116
|
[styles_module_scss_1.default.editor]: hasBackground
|
|
122
117
|
}),
|
|
123
118
|
loading: loading !== null && loading !== void 0 ? loading : (0, jsx_runtime_1.jsx)(loaders_1.Spinner, {}),
|
|
124
119
|
options: mergedOptions,
|
|
125
|
-
onMount: onEditorMount
|
|
126
|
-
language: language
|
|
120
|
+
onMount: onEditorMount
|
|
127
121
|
}))
|
|
128
122
|
}));
|
|
129
123
|
}
|
|
@@ -99,9 +99,3 @@ export declare const CODE_EDITOR_OPTIONS: {
|
|
|
99
99
|
indentation: boolean;
|
|
100
100
|
};
|
|
101
101
|
};
|
|
102
|
-
export declare const YAML_CODE_EDITOR_OPTIONS: {
|
|
103
|
-
quickSuggestions: {
|
|
104
|
-
strings: boolean;
|
|
105
|
-
};
|
|
106
|
-
};
|
|
107
|
-
export declare const DEFAULT_SCHEMA_URI = "schema://editor-schema";
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.CODE_EDITOR_OPTIONS = exports.THEME_VARS = exports.DEFAULT_THEME_OPTIONS = exports.DEFAULT_THEME_VALUES = void 0;
|
|
7
7
|
exports.DEFAULT_THEME_VALUES = {
|
|
8
8
|
semanticTokenColors: {
|
|
9
9
|
enumMember: {
|
|
@@ -113,10 +113,4 @@ exports.CODE_EDITOR_OPTIONS = {
|
|
|
113
113
|
guides: {
|
|
114
114
|
indentation: false
|
|
115
115
|
}
|
|
116
|
-
};
|
|
117
|
-
exports.YAML_CODE_EDITOR_OPTIONS = {
|
|
118
|
-
quickSuggestions: {
|
|
119
|
-
strings: true
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
exports.DEFAULT_SCHEMA_URI = 'schema://editor-schema';
|
|
116
|
+
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { JsonSchema } from './types';
|
|
2
1
|
type UseCalculatedThemeValuesProps = {
|
|
3
2
|
stylesOriginNode: HTMLDivElement | null;
|
|
4
3
|
themeName?: string;
|
|
@@ -42,10 +41,4 @@ export declare function useCalculatedThemeValues({ stylesOriginNode, themeName }
|
|
|
42
41
|
};
|
|
43
42
|
};
|
|
44
43
|
} | undefined;
|
|
45
|
-
export declare function useApplyJsonSchema(language?: string, jsonSchema?: JsonSchema): {
|
|
46
|
-
jsonSchemaProps: {
|
|
47
|
-
path: string | undefined;
|
|
48
|
-
};
|
|
49
|
-
jsonSchemaOptions: import("monaco-editor").editor.IStandaloneEditorConstructionOptions | undefined;
|
|
50
|
-
};
|
|
51
44
|
export {};
|
|
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.useCalculatedThemeValues = useCalculatedThemeValues;
|
|
7
|
-
|
|
8
|
-
const react_1 = require("@monaco-editor/react");
|
|
9
|
-
const monaco_yaml_1 = require("monaco-yaml");
|
|
10
|
-
const react_2 = require("react");
|
|
7
|
+
const react_1 = require("react");
|
|
11
8
|
const utils_1 = require("@snack-uikit/utils");
|
|
12
9
|
const constants_1 = require("./constants");
|
|
13
|
-
const utils_2 = require("./utils");
|
|
14
10
|
function getThemeVars(styles) {
|
|
15
11
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
12
|
return function mapComputedTree(tree) {
|
|
@@ -29,70 +25,16 @@ function useCalculatedThemeValues(_ref) {
|
|
|
29
25
|
stylesOriginNode,
|
|
30
26
|
themeName
|
|
31
27
|
} = _ref;
|
|
32
|
-
const [values, setValues] = (0,
|
|
28
|
+
const [values, setValues] = (0, react_1.useState)(undefined);
|
|
33
29
|
const {
|
|
34
30
|
themeClassName
|
|
35
31
|
} = (0, utils_1.useThemeContext)();
|
|
36
32
|
const trigger = themeName !== null && themeName !== void 0 ? themeName : themeClassName;
|
|
37
|
-
(0,
|
|
33
|
+
(0, react_1.useEffect)(() => {
|
|
38
34
|
if (stylesOriginNode) {
|
|
39
35
|
const styles = getComputedStyle(stylesOriginNode);
|
|
40
36
|
setValues(getThemeVars(styles)(constants_1.THEME_VARS));
|
|
41
37
|
}
|
|
42
38
|
}, [stylesOriginNode, trigger]);
|
|
43
39
|
return values;
|
|
44
|
-
}
|
|
45
|
-
function useApplyJsonSchema(language, jsonSchema) {
|
|
46
|
-
const monaco = (0, react_1.useMonaco)();
|
|
47
|
-
const [jsonSchemaOptions, setJsonSchemaOptions] = (0, react_2.useState)({});
|
|
48
|
-
const modelPath = jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.fileMatch;
|
|
49
|
-
const preparedJsonSchema = (0, react_2.useMemo)(() => (0, utils_2.getJsonSchema)(jsonSchema), [jsonSchema]);
|
|
50
|
-
const configureYamlLanguage = (0, react_2.useCallback)(() => {
|
|
51
|
-
if (!monaco || !preparedJsonSchema) {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
const model = (0, monaco_yaml_1.configureMonacoYaml)(monaco, {
|
|
55
|
-
enableSchemaRequest: true,
|
|
56
|
-
schemas: [preparedJsonSchema]
|
|
57
|
-
});
|
|
58
|
-
return {
|
|
59
|
-
options: constants_1.YAML_CODE_EDITOR_OPTIONS,
|
|
60
|
-
dispose: model.dispose
|
|
61
|
-
};
|
|
62
|
-
}, [monaco, preparedJsonSchema]);
|
|
63
|
-
const configureJsonLanguage = (0, react_2.useCallback)(() => {
|
|
64
|
-
if (!monaco || !preparedJsonSchema) {
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
|
|
68
|
-
validate: true,
|
|
69
|
-
schemas: [preparedJsonSchema]
|
|
70
|
-
});
|
|
71
|
-
}, [monaco, preparedJsonSchema]);
|
|
72
|
-
const configureJsonSchema = (0, react_2.useCallback)(() => {
|
|
73
|
-
switch (language) {
|
|
74
|
-
case 'yaml':
|
|
75
|
-
return configureYamlLanguage();
|
|
76
|
-
case 'json':
|
|
77
|
-
return configureJsonLanguage();
|
|
78
|
-
default:
|
|
79
|
-
break;
|
|
80
|
-
}
|
|
81
|
-
}, [language, configureYamlLanguage, configureJsonLanguage]);
|
|
82
|
-
(0, react_2.useEffect)(() => {
|
|
83
|
-
var _a;
|
|
84
|
-
const jsonSchemaSettings = configureJsonSchema();
|
|
85
|
-
setJsonSchemaOptions((_a = jsonSchemaSettings === null || jsonSchemaSettings === void 0 ? void 0 : jsonSchemaSettings.options) !== null && _a !== void 0 ? _a : {});
|
|
86
|
-
return () => {
|
|
87
|
-
var _a;
|
|
88
|
-
setJsonSchemaOptions({});
|
|
89
|
-
(_a = jsonSchemaSettings === null || jsonSchemaSettings === void 0 ? void 0 : jsonSchemaSettings.dispose) === null || _a === void 0 ? void 0 : _a.call(jsonSchemaSettings);
|
|
90
|
-
};
|
|
91
|
-
}, [configureJsonSchema]);
|
|
92
|
-
return (0, react_2.useMemo)(() => ({
|
|
93
|
-
jsonSchemaProps: {
|
|
94
|
-
path: modelPath
|
|
95
|
-
},
|
|
96
|
-
jsonSchemaOptions
|
|
97
|
-
}), [jsonSchemaOptions, modelPath]);
|
|
98
40
|
}
|
|
@@ -22,5 +22,4 @@ var __exportStar = void 0 && (void 0).__exportStar || function (m, exports) {
|
|
|
22
22
|
Object.defineProperty(exports, "__esModule", {
|
|
23
23
|
value: true
|
|
24
24
|
});
|
|
25
|
-
__exportStar(require("./CodeEditor"), exports);
|
|
26
|
-
__exportStar(require("./types"), exports);
|
|
25
|
+
__exportStar(require("./CodeEditor"), exports);
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import { SchemasSettings } from 'monaco-yaml';
|
|
2
|
-
import { JsonSchema } from './types';
|
|
3
1
|
export declare function rgb2hsl(HTMLcolor: string): number[];
|
|
4
2
|
export declare function isDark(color: string): boolean;
|
|
5
3
|
export declare function initLoaderConfig(): void;
|
|
6
|
-
export declare const getJsonSchema: (jsonSchema?: JsonSchema) => SchemasSettings | undefined;
|
|
@@ -8,13 +8,11 @@ var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", {
|
|
9
9
|
value: true
|
|
10
10
|
});
|
|
11
|
-
exports.getJsonSchema = void 0;
|
|
12
11
|
exports.rgb2hsl = rgb2hsl;
|
|
13
12
|
exports.isDark = isDark;
|
|
14
13
|
exports.initLoaderConfig = initLoaderConfig;
|
|
15
14
|
const react_1 = require("@monaco-editor/react");
|
|
16
15
|
const chroma_js_1 = __importDefault(require("chroma-js"));
|
|
17
|
-
const constants_1 = require("./constants");
|
|
18
16
|
function rgb2hsl(HTMLcolor) {
|
|
19
17
|
const [r, g, b] = chroma_js_1.default.valid(HTMLcolor) ? (0, chroma_js_1.default)(HTMLcolor).rgb().map(c => c / 255) : [0, 0, 0];
|
|
20
18
|
const max = Math.max(r, g, b),
|
|
@@ -55,9 +53,4 @@ function initLoaderConfig() {
|
|
|
55
53
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
56
54
|
// @ts-ignore
|
|
57
55
|
window['__snack-code-editor-loader-config__'] && react_1.loader.config(window['__snack-code-editor-loader-config__']);
|
|
58
|
-
}
|
|
59
|
-
const getJsonSchema = jsonSchema => jsonSchema && Object.assign(Object.assign({}, jsonSchema), {
|
|
60
|
-
uri: (jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.uri) || constants_1.DEFAULT_SCHEMA_URI,
|
|
61
|
-
fileMatch: [jsonSchema.fileMatch]
|
|
62
|
-
});
|
|
63
|
-
exports.getJsonSchema = getJsonSchema;
|
|
56
|
+
}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
Monaco loader defines the way how monaco will be loaded.
|
|
3
3
|
@see https://github.com/suren-atoyan/monaco-react/tree/master?tab=readme-ov-file#loader-config
|
|
4
4
|
*/
|
|
5
|
-
export { loader
|
|
5
|
+
export { loader } from '@monaco-editor/react';
|
|
6
6
|
export * from './components';
|
package/dist/cjs/index.js
CHANGED
|
@@ -22,7 +22,7 @@ var __exportStar = void 0 && (void 0).__exportStar || function (m, exports) {
|
|
|
22
22
|
Object.defineProperty(exports, "__esModule", {
|
|
23
23
|
value: true
|
|
24
24
|
});
|
|
25
|
-
exports.
|
|
25
|
+
exports.loader = void 0;
|
|
26
26
|
/**
|
|
27
27
|
Monaco loader defines the way how monaco will be loaded.
|
|
28
28
|
@see https://github.com/suren-atoyan/monaco-react/tree/master?tab=readme-ov-file#loader-config
|
|
@@ -34,10 +34,4 @@ Object.defineProperty(exports, "loader", {
|
|
|
34
34
|
return react_1.loader;
|
|
35
35
|
}
|
|
36
36
|
});
|
|
37
|
-
Object.defineProperty(exports, "useMonaco", {
|
|
38
|
-
enumerable: true,
|
|
39
|
-
get: function () {
|
|
40
|
-
return react_1.useMonaco;
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
37
|
__exportStar(require("./components"), exports);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { EditorProps } from '@monaco-editor/react';
|
|
1
2
|
import { WithSupportProps } from '@snack-uikit/utils';
|
|
2
|
-
import { EditorBaseProps, EditorWithJsonSchemaProps } from './types';
|
|
3
3
|
export type CodeEditorProps = WithSupportProps<{
|
|
4
4
|
/**
|
|
5
5
|
* Название текущей темы. Значение не важно, важно что смена значения запускает пересчет стилей.
|
|
@@ -9,5 +9,5 @@ export type CodeEditorProps = WithSupportProps<{
|
|
|
9
9
|
* Включение/отключение псевдобекграунда
|
|
10
10
|
*/
|
|
11
11
|
hasBackground?: boolean;
|
|
12
|
-
}> &
|
|
13
|
-
export declare function CodeEditor({ themeName, className, theme, options, loading, hasBackground, onMount,
|
|
12
|
+
}> & EditorProps;
|
|
13
|
+
export declare function CodeEditor({ themeName, className, theme, options, loading, hasBackground, onMount, ...props }: CodeEditorProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -16,15 +16,14 @@ import { useCallback, useMemo, useState } from 'react';
|
|
|
16
16
|
import { Spinner } from '@snack-uikit/loaders';
|
|
17
17
|
import { extractSupportProps, isBrowser } from '@snack-uikit/utils';
|
|
18
18
|
import { CODE_EDITOR_OPTIONS, DEFAULT_THEME_OPTIONS, DEFAULT_THEME_VALUES } from './constants';
|
|
19
|
-
import {
|
|
19
|
+
import { useCalculatedThemeValues } from './hooks';
|
|
20
20
|
import styles from './styles.module.css';
|
|
21
21
|
import { initLoaderConfig, isDark } from './utils';
|
|
22
22
|
initLoaderConfig();
|
|
23
23
|
export function CodeEditor(_a) {
|
|
24
|
-
var { themeName, className, theme, options, loading, hasBackground = true, onMount
|
|
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
26
|
const [wrapperElement, setWrapperElement] = useState(null);
|
|
27
|
-
const { jsonSchemaProps, jsonSchemaOptions } = useApplyJsonSchema(language, 'jsonSchema' in props ? props.jsonSchema : undefined);
|
|
28
27
|
const onEditorMount = useCallback((editor, monaco) => {
|
|
29
28
|
var _a;
|
|
30
29
|
monaco && isBrowser() && ((_a = document === null || document === void 0 ? void 0 : document.fonts) === null || _a === void 0 ? void 0 : _a.ready.finally(monaco.editor.remeasureFonts));
|
|
@@ -80,12 +79,12 @@ export function CodeEditor(_a) {
|
|
|
80
79
|
const dark = useMemo(() => { var _a; return isDark((_a = themeValues === null || themeValues === void 0 ? void 0 : themeValues.sys.available.complementary) !== null && _a !== void 0 ? _a : ''); }, [themeValues === null || themeValues === void 0 ? void 0 : themeValues.sys.available.complementary]);
|
|
81
80
|
monaco === null || monaco === void 0 ? void 0 : monaco.editor.defineTheme('snackDark', Object.assign(Object.assign({}, themeDataWithoutBase), { base: 'vs-dark' }));
|
|
82
81
|
monaco === null || monaco === void 0 ? void 0 : monaco.editor.defineTheme('snack', Object.assign(Object.assign({}, themeDataWithoutBase), { base: 'vs' }));
|
|
83
|
-
const mergedOptions = useMemo(() => (Object.assign(Object.assign(Object.assign(
|
|
82
|
+
const mergedOptions = useMemo(() => (Object.assign(Object.assign(Object.assign({}, CODE_EDITOR_OPTIONS), ((themeValues === null || themeValues === void 0 ? void 0 : themeValues.mono)
|
|
84
83
|
? {
|
|
85
84
|
fontSize: Number.parseFloat(themeValues.mono.body.s['font-size']),
|
|
86
85
|
fontWeight: themeValues.mono.body.s['font-weight'],
|
|
87
86
|
fontFamily: themeValues.mono.body.s['font-family'],
|
|
88
87
|
}
|
|
89
|
-
: DEFAULT_THEME_OPTIONS.mono.s)), options)), [options, themeValues === null || themeValues === void 0 ? void 0 : themeValues.mono
|
|
90
|
-
return (_jsx("div", Object.assign({ className: className }, extractSupportProps(props), { ref: setWrapperElement, children: _jsx(Editor, Object.assign({}, props,
|
|
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: 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 })) })));
|
|
91
90
|
}
|
|
@@ -99,9 +99,3 @@ export declare const CODE_EDITOR_OPTIONS: {
|
|
|
99
99
|
indentation: boolean;
|
|
100
100
|
};
|
|
101
101
|
};
|
|
102
|
-
export declare const YAML_CODE_EDITOR_OPTIONS: {
|
|
103
|
-
quickSuggestions: {
|
|
104
|
-
strings: boolean;
|
|
105
|
-
};
|
|
106
|
-
};
|
|
107
|
-
export declare const DEFAULT_SCHEMA_URI = "schema://editor-schema";
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { JsonSchema } from './types';
|
|
2
1
|
type UseCalculatedThemeValuesProps = {
|
|
3
2
|
stylesOriginNode: HTMLDivElement | null;
|
|
4
3
|
themeName?: string;
|
|
@@ -42,10 +41,4 @@ export declare function useCalculatedThemeValues({ stylesOriginNode, themeName }
|
|
|
42
41
|
};
|
|
43
42
|
};
|
|
44
43
|
} | undefined;
|
|
45
|
-
export declare function useApplyJsonSchema(language?: string, jsonSchema?: JsonSchema): {
|
|
46
|
-
jsonSchemaProps: {
|
|
47
|
-
path: string | undefined;
|
|
48
|
-
};
|
|
49
|
-
jsonSchemaOptions: import("monaco-editor").editor.IStandaloneEditorConstructionOptions | undefined;
|
|
50
|
-
};
|
|
51
44
|
export {};
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { configureMonacoYaml } from 'monaco-yaml';
|
|
3
|
-
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
4
2
|
import { useThemeContext } from '@snack-uikit/utils';
|
|
5
|
-
import { THEME_VARS
|
|
6
|
-
import { getJsonSchema } from './utils';
|
|
3
|
+
import { THEME_VARS } from './constants';
|
|
7
4
|
function getThemeVars(styles) {
|
|
8
5
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
6
|
return function mapComputedTree(tree) {
|
|
@@ -29,55 +26,3 @@ export function useCalculatedThemeValues({ stylesOriginNode, themeName }) {
|
|
|
29
26
|
}, [stylesOriginNode, trigger]);
|
|
30
27
|
return values;
|
|
31
28
|
}
|
|
32
|
-
export function useApplyJsonSchema(language, jsonSchema) {
|
|
33
|
-
const monaco = useMonaco();
|
|
34
|
-
const [jsonSchemaOptions, setJsonSchemaOptions] = useState({});
|
|
35
|
-
const modelPath = jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.fileMatch;
|
|
36
|
-
const preparedJsonSchema = useMemo(() => getJsonSchema(jsonSchema), [jsonSchema]);
|
|
37
|
-
const configureYamlLanguage = useCallback(() => {
|
|
38
|
-
if (!monaco || !preparedJsonSchema) {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
const model = configureMonacoYaml(monaco, {
|
|
42
|
-
enableSchemaRequest: true,
|
|
43
|
-
schemas: [preparedJsonSchema],
|
|
44
|
-
});
|
|
45
|
-
return {
|
|
46
|
-
options: YAML_CODE_EDITOR_OPTIONS,
|
|
47
|
-
dispose: model.dispose,
|
|
48
|
-
};
|
|
49
|
-
}, [monaco, preparedJsonSchema]);
|
|
50
|
-
const configureJsonLanguage = useCallback(() => {
|
|
51
|
-
if (!monaco || !preparedJsonSchema) {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
|
|
55
|
-
validate: true,
|
|
56
|
-
schemas: [preparedJsonSchema],
|
|
57
|
-
});
|
|
58
|
-
}, [monaco, preparedJsonSchema]);
|
|
59
|
-
const configureJsonSchema = useCallback(() => {
|
|
60
|
-
switch (language) {
|
|
61
|
-
case 'yaml':
|
|
62
|
-
return configureYamlLanguage();
|
|
63
|
-
case 'json':
|
|
64
|
-
return configureJsonLanguage();
|
|
65
|
-
default:
|
|
66
|
-
break;
|
|
67
|
-
}
|
|
68
|
-
}, [language, configureYamlLanguage, configureJsonLanguage]);
|
|
69
|
-
useEffect(() => {
|
|
70
|
-
var _a;
|
|
71
|
-
const jsonSchemaSettings = configureJsonSchema();
|
|
72
|
-
setJsonSchemaOptions((_a = jsonSchemaSettings === null || jsonSchemaSettings === void 0 ? void 0 : jsonSchemaSettings.options) !== null && _a !== void 0 ? _a : {});
|
|
73
|
-
return () => {
|
|
74
|
-
var _a;
|
|
75
|
-
setJsonSchemaOptions({});
|
|
76
|
-
(_a = jsonSchemaSettings === null || jsonSchemaSettings === void 0 ? void 0 : jsonSchemaSettings.dispose) === null || _a === void 0 ? void 0 : _a.call(jsonSchemaSettings);
|
|
77
|
-
};
|
|
78
|
-
}, [configureJsonSchema]);
|
|
79
|
-
return useMemo(() => ({
|
|
80
|
-
jsonSchemaProps: { path: modelPath },
|
|
81
|
-
jsonSchemaOptions,
|
|
82
|
-
}), [jsonSchemaOptions, modelPath]);
|
|
83
|
-
}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import { SchemasSettings } from 'monaco-yaml';
|
|
2
|
-
import { JsonSchema } from './types';
|
|
3
1
|
export declare function rgb2hsl(HTMLcolor: string): number[];
|
|
4
2
|
export declare function isDark(color: string): boolean;
|
|
5
3
|
export declare function initLoaderConfig(): void;
|
|
6
|
-
export declare const getJsonSchema: (jsonSchema?: JsonSchema) => SchemasSettings | undefined;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { loader } from '@monaco-editor/react';
|
|
2
2
|
import chroma from 'chroma-js';
|
|
3
|
-
import { DEFAULT_SCHEMA_URI } from './constants';
|
|
4
3
|
export function rgb2hsl(HTMLcolor) {
|
|
5
4
|
const [r, g, b] = chroma.valid(HTMLcolor)
|
|
6
5
|
? chroma(HTMLcolor)
|
|
@@ -46,4 +45,3 @@ export function initLoaderConfig() {
|
|
|
46
45
|
// @ts-ignore
|
|
47
46
|
window['__snack-code-editor-loader-config__'] && loader.config(window['__snack-code-editor-loader-config__']);
|
|
48
47
|
}
|
|
49
|
-
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/dist/esm/index.d.ts
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
Monaco loader defines the way how monaco will be loaded.
|
|
3
3
|
@see https://github.com/suren-atoyan/monaco-react/tree/master?tab=readme-ov-file#loader-config
|
|
4
4
|
*/
|
|
5
|
-
export { loader
|
|
5
|
+
export { loader } from '@monaco-editor/react';
|
|
6
6
|
export * from './components';
|
package/dist/esm/index.js
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
Monaco loader defines the way how monaco will be loaded.
|
|
3
3
|
@see https://github.com/suren-atoyan/monaco-react/tree/master?tab=readme-ov-file#loader-config
|
|
4
4
|
*/
|
|
5
|
-
export { loader
|
|
5
|
+
export { loader } from '@monaco-editor/react';
|
|
6
6
|
export * from './components';
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.4.7
|
|
7
|
+
"version": "0.4.7",
|
|
8
8
|
"sideEffects": [
|
|
9
9
|
"*.css",
|
|
10
10
|
"*.woff",
|
|
@@ -37,14 +37,13 @@
|
|
|
37
37
|
"scripts": {},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@monaco-editor/react": "4.6.0",
|
|
40
|
-
"@snack-uikit/loaders": "0.9.
|
|
41
|
-
"@snack-uikit/utils": "3.
|
|
40
|
+
"@snack-uikit/loaders": "0.9.1",
|
|
41
|
+
"@snack-uikit/utils": "3.7.0",
|
|
42
42
|
"chroma-js": "3.1.2",
|
|
43
|
-
"classnames": "2.5.1"
|
|
44
|
-
"monaco-yaml": "5.2.3"
|
|
43
|
+
"classnames": "2.5.1"
|
|
45
44
|
},
|
|
46
45
|
"devDependencies": {
|
|
47
46
|
"@types/chroma-js": "2.4.4"
|
|
48
47
|
},
|
|
49
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "3528e78aec23804dca44d311947c1dcd4ed3792b"
|
|
50
49
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Editor, OnMount, useMonaco } from '@monaco-editor/react';
|
|
1
|
+
import { Editor, EditorProps, OnMount, useMonaco } from '@monaco-editor/react';
|
|
2
2
|
import cn from 'classnames';
|
|
3
3
|
import { useCallback, useMemo, useState } from 'react';
|
|
4
4
|
|
|
@@ -6,9 +6,8 @@ import { Spinner } from '@snack-uikit/loaders';
|
|
|
6
6
|
import { extractSupportProps, isBrowser, WithSupportProps } from '@snack-uikit/utils';
|
|
7
7
|
|
|
8
8
|
import { CODE_EDITOR_OPTIONS, DEFAULT_THEME_OPTIONS, DEFAULT_THEME_VALUES } from './constants';
|
|
9
|
-
import {
|
|
9
|
+
import { useCalculatedThemeValues } from './hooks';
|
|
10
10
|
import styles from './styles.module.scss';
|
|
11
|
-
import { EditorBaseProps, EditorWithJsonSchemaProps } from './types';
|
|
12
11
|
import { initLoaderConfig, isDark } from './utils';
|
|
13
12
|
|
|
14
13
|
initLoaderConfig();
|
|
@@ -23,7 +22,7 @@ export type CodeEditorProps = WithSupportProps<{
|
|
|
23
22
|
*/
|
|
24
23
|
hasBackground?: boolean;
|
|
25
24
|
}> &
|
|
26
|
-
|
|
25
|
+
EditorProps;
|
|
27
26
|
|
|
28
27
|
export function CodeEditor({
|
|
29
28
|
themeName,
|
|
@@ -33,17 +32,11 @@ export function CodeEditor({
|
|
|
33
32
|
loading,
|
|
34
33
|
hasBackground = true,
|
|
35
34
|
onMount,
|
|
36
|
-
language,
|
|
37
35
|
...props
|
|
38
36
|
}: CodeEditorProps) {
|
|
39
37
|
const monaco = useMonaco();
|
|
40
38
|
const [wrapperElement, setWrapperElement] = useState<HTMLDivElement | null>(null);
|
|
41
39
|
|
|
42
|
-
const { jsonSchemaProps, jsonSchemaOptions } = useApplyJsonSchema(
|
|
43
|
-
language,
|
|
44
|
-
'jsonSchema' in props ? props.jsonSchema : undefined,
|
|
45
|
-
);
|
|
46
|
-
|
|
47
40
|
const onEditorMount = useCallback<OnMount>(
|
|
48
41
|
(editor, monaco) => {
|
|
49
42
|
monaco && isBrowser() && document?.fonts?.ready.finally(monaco.editor.remeasureFonts);
|
|
@@ -118,7 +111,6 @@ export function CodeEditor({
|
|
|
118
111
|
const mergedOptions = useMemo(
|
|
119
112
|
() => ({
|
|
120
113
|
...CODE_EDITOR_OPTIONS,
|
|
121
|
-
...jsonSchemaOptions,
|
|
122
114
|
...(themeValues?.mono
|
|
123
115
|
? {
|
|
124
116
|
fontSize: Number.parseFloat(themeValues.mono.body.s['font-size']),
|
|
@@ -128,20 +120,18 @@ export function CodeEditor({
|
|
|
128
120
|
: DEFAULT_THEME_OPTIONS.mono.s),
|
|
129
121
|
...options,
|
|
130
122
|
}),
|
|
131
|
-
[options, themeValues?.mono
|
|
123
|
+
[options, themeValues?.mono],
|
|
132
124
|
);
|
|
133
125
|
|
|
134
126
|
return (
|
|
135
127
|
<div className={className} {...extractSupportProps(props)} ref={setWrapperElement}>
|
|
136
128
|
<Editor
|
|
137
129
|
{...props}
|
|
138
|
-
{...jsonSchemaProps}
|
|
139
130
|
theme={theme ?? (dark ? 'snackDark' : 'snack')}
|
|
140
131
|
className={cn({ [styles.editor]: hasBackground })}
|
|
141
132
|
loading={loading ?? <Spinner />}
|
|
142
133
|
options={mergedOptions}
|
|
143
134
|
onMount={onEditorMount}
|
|
144
|
-
language={language}
|
|
145
135
|
/>
|
|
146
136
|
</div>
|
|
147
137
|
);
|
package/src/components/hooks.ts
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { configureMonacoYaml, SchemasSettings } from 'monaco-yaml';
|
|
3
|
-
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
4
2
|
|
|
5
3
|
import { useThemeContext } from '@snack-uikit/utils';
|
|
6
4
|
|
|
7
|
-
import { THEME_VARS
|
|
8
|
-
import { ConfigureJsonSchemaReturn, JsonSchema } from './types';
|
|
9
|
-
import { getJsonSchema } from './utils';
|
|
5
|
+
import { THEME_VARS } from './constants';
|
|
10
6
|
|
|
11
7
|
function getThemeVars(styles: CSSStyleDeclaration) {
|
|
12
8
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -46,68 +42,3 @@ export function useCalculatedThemeValues({ stylesOriginNode, themeName }: UseCal
|
|
|
46
42
|
|
|
47
43
|
return values;
|
|
48
44
|
}
|
|
49
|
-
|
|
50
|
-
export function useApplyJsonSchema(language?: string, jsonSchema?: JsonSchema) {
|
|
51
|
-
const monaco = useMonaco();
|
|
52
|
-
|
|
53
|
-
const [jsonSchemaOptions, setJsonSchemaOptions] = useState<MonacoEditorProps['options']>({});
|
|
54
|
-
const modelPath = jsonSchema?.fileMatch;
|
|
55
|
-
|
|
56
|
-
const preparedJsonSchema: SchemasSettings | undefined = useMemo(() => getJsonSchema(jsonSchema), [jsonSchema]);
|
|
57
|
-
|
|
58
|
-
const configureYamlLanguage = useCallback((): ConfigureJsonSchemaReturn => {
|
|
59
|
-
if (!monaco || !preparedJsonSchema) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const model = configureMonacoYaml(monaco, {
|
|
64
|
-
enableSchemaRequest: true,
|
|
65
|
-
schemas: [preparedJsonSchema],
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
return {
|
|
69
|
-
options: YAML_CODE_EDITOR_OPTIONS,
|
|
70
|
-
dispose: model.dispose,
|
|
71
|
-
};
|
|
72
|
-
}, [monaco, preparedJsonSchema]);
|
|
73
|
-
|
|
74
|
-
const configureJsonLanguage = useCallback((): ConfigureJsonSchemaReturn => {
|
|
75
|
-
if (!monaco || !preparedJsonSchema) {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
|
|
80
|
-
validate: true,
|
|
81
|
-
schemas: [preparedJsonSchema],
|
|
82
|
-
});
|
|
83
|
-
}, [monaco, preparedJsonSchema]);
|
|
84
|
-
|
|
85
|
-
const configureJsonSchema = useCallback(() => {
|
|
86
|
-
switch (language) {
|
|
87
|
-
case 'yaml':
|
|
88
|
-
return configureYamlLanguage();
|
|
89
|
-
case 'json':
|
|
90
|
-
return configureJsonLanguage();
|
|
91
|
-
default:
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
}, [language, configureYamlLanguage, configureJsonLanguage]);
|
|
95
|
-
|
|
96
|
-
useEffect(() => {
|
|
97
|
-
const jsonSchemaSettings = configureJsonSchema();
|
|
98
|
-
setJsonSchemaOptions(jsonSchemaSettings?.options ?? {});
|
|
99
|
-
|
|
100
|
-
return () => {
|
|
101
|
-
setJsonSchemaOptions({});
|
|
102
|
-
jsonSchemaSettings?.dispose?.();
|
|
103
|
-
};
|
|
104
|
-
}, [configureJsonSchema]);
|
|
105
|
-
|
|
106
|
-
return useMemo(
|
|
107
|
-
() => ({
|
|
108
|
-
jsonSchemaProps: { path: modelPath } satisfies MonacoEditorProps,
|
|
109
|
-
jsonSchemaOptions,
|
|
110
|
-
}),
|
|
111
|
-
[jsonSchemaOptions, modelPath],
|
|
112
|
-
);
|
|
113
|
-
}
|
package/src/components/index.ts
CHANGED
package/src/components/utils.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import { loader } from '@monaco-editor/react';
|
|
2
2
|
import chroma from 'chroma-js';
|
|
3
|
-
import { SchemasSettings } from 'monaco-yaml';
|
|
4
|
-
|
|
5
|
-
import { DEFAULT_SCHEMA_URI } from './constants';
|
|
6
|
-
import { JsonSchema } from './types';
|
|
7
3
|
|
|
8
4
|
export function rgb2hsl(HTMLcolor: string) {
|
|
9
5
|
const [r, g, b] = chroma.valid(HTMLcolor)
|
|
@@ -64,6 +60,3 @@ export function initLoaderConfig() {
|
|
|
64
60
|
// @ts-ignore
|
|
65
61
|
window['__snack-code-editor-loader-config__'] && loader.config(window['__snack-code-editor-loader-config__']);
|
|
66
62
|
}
|
|
67
|
-
|
|
68
|
-
export const getJsonSchema = (jsonSchema?: JsonSchema): SchemasSettings | undefined =>
|
|
69
|
-
jsonSchema && { ...jsonSchema, uri: jsonSchema?.uri || DEFAULT_SCHEMA_URI, fileMatch: [jsonSchema.fileMatch] };
|
package/src/index.ts
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
Monaco loader defines the way how monaco will be loaded.
|
|
3
3
|
@see https://github.com/suren-atoyan/monaco-react/tree/master?tab=readme-ov-file#loader-config
|
|
4
4
|
*/
|
|
5
|
-
export { loader
|
|
5
|
+
export { loader } from '@monaco-editor/react';
|
|
6
6
|
export * from './components';
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { EditorProps as MonacoEditorProps } from '@monaco-editor/react';
|
|
2
|
-
import { JSONSchema } from 'monaco-yaml';
|
|
3
|
-
export type EditorBaseProps = MonacoEditorProps;
|
|
4
|
-
export type SupportedSchemaLanguage = 'json' | 'yaml';
|
|
5
|
-
export type JsonSchema = {
|
|
6
|
-
uri?: string;
|
|
7
|
-
schema?: JSONSchema;
|
|
8
|
-
fileMatch: string;
|
|
9
|
-
};
|
|
10
|
-
export type WithJsonSchema = {
|
|
11
|
-
/**
|
|
12
|
-
* Схема для валидации
|
|
13
|
-
*/
|
|
14
|
-
jsonSchema: JsonSchema;
|
|
15
|
-
path?: never;
|
|
16
|
-
};
|
|
17
|
-
type WithoutJsonSchema = Pick<MonacoEditorProps, 'path'>;
|
|
18
|
-
export type EditorWithJsonSchemaProps = Omit<EditorBaseProps, 'language' | 'path'> & {
|
|
19
|
-
language: SupportedSchemaLanguage;
|
|
20
|
-
} & (WithJsonSchema | WithoutJsonSchema);
|
|
21
|
-
export type ConfigureJsonSchemaReturn = {
|
|
22
|
-
options?: MonacoEditorProps['options'];
|
|
23
|
-
dispose?: () => void;
|
|
24
|
-
} | undefined;
|
|
25
|
-
export {};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { EditorProps as MonacoEditorProps } from '@monaco-editor/react';
|
|
2
|
-
import { JSONSchema } from 'monaco-yaml';
|
|
3
|
-
export type EditorBaseProps = MonacoEditorProps;
|
|
4
|
-
export type SupportedSchemaLanguage = 'json' | 'yaml';
|
|
5
|
-
export type JsonSchema = {
|
|
6
|
-
uri?: string;
|
|
7
|
-
schema?: JSONSchema;
|
|
8
|
-
fileMatch: string;
|
|
9
|
-
};
|
|
10
|
-
export type WithJsonSchema = {
|
|
11
|
-
/**
|
|
12
|
-
* Схема для валидации
|
|
13
|
-
*/
|
|
14
|
-
jsonSchema: JsonSchema;
|
|
15
|
-
path?: never;
|
|
16
|
-
};
|
|
17
|
-
type WithoutJsonSchema = Pick<MonacoEditorProps, 'path'>;
|
|
18
|
-
export type EditorWithJsonSchemaProps = Omit<EditorBaseProps, 'language' | 'path'> & {
|
|
19
|
-
language: SupportedSchemaLanguage;
|
|
20
|
-
} & (WithJsonSchema | WithoutJsonSchema);
|
|
21
|
-
export type ConfigureJsonSchemaReturn = {
|
|
22
|
-
options?: MonacoEditorProps['options'];
|
|
23
|
-
dispose?: () => void;
|
|
24
|
-
} | undefined;
|
|
25
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/src/components/types.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { EditorProps as MonacoEditorProps } from '@monaco-editor/react';
|
|
2
|
-
import { JSONSchema } from 'monaco-yaml';
|
|
3
|
-
|
|
4
|
-
export type EditorBaseProps = MonacoEditorProps;
|
|
5
|
-
|
|
6
|
-
export type SupportedSchemaLanguage = 'json' | 'yaml';
|
|
7
|
-
|
|
8
|
-
export type JsonSchema = {
|
|
9
|
-
uri?: string;
|
|
10
|
-
schema?: JSONSchema;
|
|
11
|
-
fileMatch: string;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export type WithJsonSchema = {
|
|
15
|
-
/**
|
|
16
|
-
* Схема для валидации
|
|
17
|
-
*/
|
|
18
|
-
jsonSchema: JsonSchema;
|
|
19
|
-
path?: never;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
type WithoutJsonSchema = Pick<MonacoEditorProps, 'path'>;
|
|
23
|
-
|
|
24
|
-
export type EditorWithJsonSchemaProps = Omit<EditorBaseProps, 'language' | 'path'> & {
|
|
25
|
-
language: SupportedSchemaLanguage;
|
|
26
|
-
} & (WithJsonSchema | WithoutJsonSchema);
|
|
27
|
-
|
|
28
|
-
export type ConfigureJsonSchemaReturn =
|
|
29
|
-
| {
|
|
30
|
-
options?: MonacoEditorProps['options'];
|
|
31
|
-
dispose?: () => void;
|
|
32
|
-
}
|
|
33
|
-
| undefined;
|