@react-fabric/monaco 1.0.0-beta.6 → 1.0.0-beta.61
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/{src/components/CodeEditor.module.css → css/_codeEditor.css} +23 -25
- package/css/styles.css +24 -0
- package/dist/cjs/components/CodeEditor.js +34 -6
- package/dist/esm/components/CodeEditor.js +34 -6
- package/dist/types/components/CodeEditor.d.ts +31 -1
- package/package.json +13 -13
- package/src/components/CodeEditor.tsx +38 -9
- package/dist/cjs/components/CodeEditor.module.css +0 -1
- package/dist/esm/components/CodeEditor.module.css +0 -1
|
@@ -23,67 +23,65 @@
|
|
|
23
23
|
|
|
24
24
|
/* stylelint-disable custom-property-pattern */
|
|
25
25
|
|
|
26
|
-
@layer
|
|
27
|
-
.codeEditor {
|
|
26
|
+
@layer utilities {
|
|
27
|
+
.fabric-codeEditor {
|
|
28
28
|
direction: ltr;
|
|
29
29
|
overflow: hidden;
|
|
30
30
|
border: 1px solid transparent;
|
|
31
31
|
border-bottom-width: 2px;
|
|
32
32
|
|
|
33
|
-
&:has(
|
|
34
|
-
border-color:
|
|
33
|
+
&:has(.monaco-editor.focused) {
|
|
34
|
+
border-color: var(--color-primary-500);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
.editor {
|
|
38
|
-
& >
|
|
39
|
-
--vscode-menu-background:
|
|
40
|
-
--vscode-menu-border:
|
|
37
|
+
.fabric-editor {
|
|
38
|
+
& > .monaco-editor {
|
|
39
|
+
--vscode-menu-background: var(--color-tint-50) !important;
|
|
40
|
+
--vscode-menu-border: var(--border-color-base) !important;
|
|
41
41
|
--vscode-focusBorder: transparent !important;
|
|
42
42
|
--vscode-menu-selectionBackground: color(
|
|
43
|
-
from var(--primary) srgb r g b / 80%
|
|
43
|
+
from var(--color-primary) srgb r g b / 80%
|
|
44
44
|
) !important;
|
|
45
45
|
--vscode-editor-background: var(--fabric-bg) !important;
|
|
46
46
|
--vscode-editor-foreground: var(--fabric-text) !important;
|
|
47
47
|
--vscode-breadcrumb-background: var(--fabric-bg) !important;
|
|
48
48
|
--vscode-editorGutter-background: color(
|
|
49
|
-
from
|
|
49
|
+
from var(--color-tint-50) srgb r g g / 50%
|
|
50
50
|
) !important;
|
|
51
51
|
--vscode-minimapSlider-background: color(
|
|
52
|
-
from var(--tint) srgb r g b / 20%
|
|
52
|
+
from var(--color-tint) srgb r g b / 20%
|
|
53
53
|
) !important;
|
|
54
54
|
--vscode-minimapSlider-hoverBackground: color(
|
|
55
|
-
from var(--tint) srgb r g b / 25%
|
|
55
|
+
from var(--color-tint) srgb r g b / 25%
|
|
56
56
|
) !important;
|
|
57
57
|
--vscode-minimapSlider-activeBackground: color(
|
|
58
|
-
from var(--tint) srgb r g b / 30%
|
|
58
|
+
from var(--color-tint) srgb r g b / 30%
|
|
59
59
|
) !important;
|
|
60
|
-
--vscode-input-border: var(--primary) !important;
|
|
60
|
+
--vscode-input-border: var(--color-primary) !important;
|
|
61
61
|
--vscode-editorStickyScroll-background: var(--fabric-bg) !important;
|
|
62
62
|
--vscode-editorMarkerNavigation-background: var(--fabric-bg) !important;
|
|
63
63
|
--vscode-editor-wordHighlightTextBackground: color(
|
|
64
|
-
from
|
|
64
|
+
from var(--color-accent-700) srgb r g b / 20%
|
|
65
65
|
) !important;
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
&
|
|
68
|
+
& .minimap-decorations-layer {
|
|
69
69
|
background-color: color(
|
|
70
|
-
from
|
|
70
|
+
from var(--color-tint-50) srgb r g g / 50%
|
|
71
71
|
) !important;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
&
|
|
74
|
+
& .folded-background {
|
|
75
75
|
opacity: 0.5;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
&
|
|
78
|
+
& .monaco-findInput textarea {
|
|
79
79
|
resize: initial;
|
|
80
80
|
min-height: unset;
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
&
|
|
84
|
-
|
|
85
|
-
font-size: 0.75rem;
|
|
86
|
-
}
|
|
83
|
+
& .editor-widget.suggest-widget .message {
|
|
84
|
+
font-size: 0.75rem;
|
|
87
85
|
}
|
|
88
86
|
|
|
89
87
|
& span {
|
|
@@ -92,7 +90,7 @@
|
|
|
92
90
|
}
|
|
93
91
|
}
|
|
94
92
|
|
|
95
|
-
.editorTools {
|
|
96
|
-
|
|
93
|
+
.fabric-editorTools {
|
|
94
|
+
background-color: var(--bg-color-base);
|
|
97
95
|
}
|
|
98
96
|
}
|
package/css/styles.css
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* React Fabric
|
|
3
|
+
* @version: 1.0.0
|
|
4
|
+
*
|
|
5
|
+
*
|
|
6
|
+
* The MIT License (MIT)
|
|
7
|
+
* Copyright (c) 2025 Adarsh Pastakia
|
|
8
|
+
*
|
|
9
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
10
|
+
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
11
|
+
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
12
|
+
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
13
|
+
* subject to the following conditions:
|
|
14
|
+
*
|
|
15
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
16
|
+
* portions of the Software.
|
|
17
|
+
*
|
|
18
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
19
|
+
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
20
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
@import "./_codeEditor.css";
|
|
@@ -9,11 +9,37 @@ var utilities = require('@react-fabric/utilities');
|
|
|
9
9
|
var classNames = require('classnames');
|
|
10
10
|
var react = require('react');
|
|
11
11
|
var MonacoEditor = require('react-monaco-editor');
|
|
12
|
-
var CodeEditor_module = require('./CodeEditor.module.css');
|
|
13
12
|
var jsxRuntime = require('react/jsx-runtime');
|
|
14
13
|
|
|
15
14
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
16
15
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
16
|
+
/**
|
|
17
|
+
* CodeEditor component to render a code editor using Monaco Editor.
|
|
18
|
+
* It supports JSON and HTML languages with optional schema validation and handlebar suggestions.
|
|
19
|
+
* The editor can be configured to be read-only, minimal, and can handle changes in the code.
|
|
20
|
+
* It provides a ref to access the editor's value and validation methods.
|
|
21
|
+
*
|
|
22
|
+
* @param {EditorProps} props - The properties for the CodeEditor component.
|
|
23
|
+
* @param {RefProp<MonacoEditorRef>} ref - The ref to access the editor methods.
|
|
24
|
+
* @return {JSX.Element} The rendered CodeEditor component.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```jsx
|
|
28
|
+
* <CodeEditor
|
|
29
|
+
* value={initialValue}
|
|
30
|
+
* schema={[{ uri: "http://example.com/schema.json", schema: {} }]}
|
|
31
|
+
* handlebarSuggestions={[{ text: "example", description: "An example suggestion" }]}
|
|
32
|
+
* required={true}
|
|
33
|
+
* readOnly={false}
|
|
34
|
+
* minimal={false}
|
|
35
|
+
* onChange={(value) => console.log("Code changed:", value)}
|
|
36
|
+
* language="json"
|
|
37
|
+
* />
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @see {@link https://adarshpastakia.github.io/react-fabric/?path=/story/monaco-playground--playground}
|
|
41
|
+
* @see {@link https://microsoft.github.io/monaco-editor/}
|
|
42
|
+
*/
|
|
17
43
|
var CodeEditor = function CodeEditor(_ref) {
|
|
18
44
|
var ref = _ref.ref,
|
|
19
45
|
value = _ref.value,
|
|
@@ -91,14 +117,15 @@ var CodeEditor = function CodeEditor(_ref) {
|
|
|
91
117
|
}
|
|
92
118
|
};
|
|
93
119
|
}, [required, language]);
|
|
94
|
-
var disposeRef = react.useRef();
|
|
120
|
+
var disposeRef = react.useRef(null);
|
|
95
121
|
var schemaUri = react.useCallback(function (monaco) {
|
|
96
122
|
if (language === "json" && schema) {
|
|
123
|
+
var _monaco$languages;
|
|
97
124
|
var _schema = _toArray(schema),
|
|
98
125
|
main = _schema[0],
|
|
99
126
|
rest = _schema.slice(1);
|
|
100
127
|
// configure the JSON language support with schemas and schema associations
|
|
101
|
-
monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
|
|
128
|
+
(_monaco$languages = monaco.languages) === null || _monaco$languages === void 0 || (_monaco$languages = _monaco$languages.json) === null || _monaco$languages === void 0 || _monaco$languages.jsonDefaults.setDiagnosticsOptions({
|
|
102
129
|
validate: true,
|
|
103
130
|
allowComments: false,
|
|
104
131
|
schemas: [_objectSpread({
|
|
@@ -155,10 +182,11 @@ var CodeEditor = function CodeEditor(_ref) {
|
|
|
155
182
|
});
|
|
156
183
|
}, []);
|
|
157
184
|
return /*#__PURE__*/jsxRuntime.jsx(core.Section, {
|
|
185
|
+
className: "relative",
|
|
158
186
|
children: /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
159
187
|
ref: containerRef,
|
|
160
|
-
"data-
|
|
161
|
-
className: classNames(
|
|
188
|
+
"data-ref": "codeEditor",
|
|
189
|
+
className: classNames("fabric-codeEditor", "absolute inset-0"),
|
|
162
190
|
children: /*#__PURE__*/jsxRuntime.jsx(MonacoEditor, {
|
|
163
191
|
editorDidMount: function editorDidMount(e, m) {
|
|
164
192
|
return [!!e && setEditorRef(e), !!m && setMonacoRef(m)];
|
|
@@ -169,7 +197,7 @@ var CodeEditor = function CodeEditor(_ref) {
|
|
|
169
197
|
language: language,
|
|
170
198
|
onChange: handleChange,
|
|
171
199
|
theme: theme,
|
|
172
|
-
className:
|
|
200
|
+
className: "fabric-editor",
|
|
173
201
|
options: {
|
|
174
202
|
readOnly: readOnly,
|
|
175
203
|
minimap: {
|
|
@@ -9,11 +9,37 @@ import { isString, isEmpty } from '@react-fabric/utilities';
|
|
|
9
9
|
import classNames from 'classnames';
|
|
10
10
|
import { useState, useLayoutEffect, useCallback, useDeferredValue, useMemo, useImperativeHandle, useRef } from 'react';
|
|
11
11
|
import MonacoEditor from 'react-monaco-editor';
|
|
12
|
-
import classes from './CodeEditor.module.css';
|
|
13
12
|
import { jsx } from 'react/jsx-runtime';
|
|
14
13
|
|
|
15
14
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
16
15
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
16
|
+
/**
|
|
17
|
+
* CodeEditor component to render a code editor using Monaco Editor.
|
|
18
|
+
* It supports JSON and HTML languages with optional schema validation and handlebar suggestions.
|
|
19
|
+
* The editor can be configured to be read-only, minimal, and can handle changes in the code.
|
|
20
|
+
* It provides a ref to access the editor's value and validation methods.
|
|
21
|
+
*
|
|
22
|
+
* @param {EditorProps} props - The properties for the CodeEditor component.
|
|
23
|
+
* @param {RefProp<MonacoEditorRef>} ref - The ref to access the editor methods.
|
|
24
|
+
* @return {JSX.Element} The rendered CodeEditor component.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```jsx
|
|
28
|
+
* <CodeEditor
|
|
29
|
+
* value={initialValue}
|
|
30
|
+
* schema={[{ uri: "http://example.com/schema.json", schema: {} }]}
|
|
31
|
+
* handlebarSuggestions={[{ text: "example", description: "An example suggestion" }]}
|
|
32
|
+
* required={true}
|
|
33
|
+
* readOnly={false}
|
|
34
|
+
* minimal={false}
|
|
35
|
+
* onChange={(value) => console.log("Code changed:", value)}
|
|
36
|
+
* language="json"
|
|
37
|
+
* />
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @see {@link https://adarshpastakia.github.io/react-fabric/?path=/story/monaco-playground--playground}
|
|
41
|
+
* @see {@link https://microsoft.github.io/monaco-editor/}
|
|
42
|
+
*/
|
|
17
43
|
var CodeEditor = function CodeEditor(_ref) {
|
|
18
44
|
var ref = _ref.ref,
|
|
19
45
|
value = _ref.value,
|
|
@@ -91,14 +117,15 @@ var CodeEditor = function CodeEditor(_ref) {
|
|
|
91
117
|
}
|
|
92
118
|
};
|
|
93
119
|
}, [required, language]);
|
|
94
|
-
var disposeRef = useRef();
|
|
120
|
+
var disposeRef = useRef(null);
|
|
95
121
|
var schemaUri = useCallback(function (monaco) {
|
|
96
122
|
if (language === "json" && schema) {
|
|
123
|
+
var _monaco$languages;
|
|
97
124
|
var _schema = _toArray(schema),
|
|
98
125
|
main = _schema[0],
|
|
99
126
|
rest = _schema.slice(1);
|
|
100
127
|
// configure the JSON language support with schemas and schema associations
|
|
101
|
-
monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
|
|
128
|
+
(_monaco$languages = monaco.languages) === null || _monaco$languages === void 0 || (_monaco$languages = _monaco$languages.json) === null || _monaco$languages === void 0 || _monaco$languages.jsonDefaults.setDiagnosticsOptions({
|
|
102
129
|
validate: true,
|
|
103
130
|
allowComments: false,
|
|
104
131
|
schemas: [_objectSpread({
|
|
@@ -155,10 +182,11 @@ var CodeEditor = function CodeEditor(_ref) {
|
|
|
155
182
|
});
|
|
156
183
|
}, []);
|
|
157
184
|
return /*#__PURE__*/jsx(Section, {
|
|
185
|
+
className: "relative",
|
|
158
186
|
children: /*#__PURE__*/jsx("div", {
|
|
159
187
|
ref: containerRef,
|
|
160
|
-
"data-
|
|
161
|
-
className: classNames(
|
|
188
|
+
"data-ref": "codeEditor",
|
|
189
|
+
className: classNames("fabric-codeEditor", "absolute inset-0"),
|
|
162
190
|
children: /*#__PURE__*/jsx(MonacoEditor, {
|
|
163
191
|
editorDidMount: function editorDidMount(e, m) {
|
|
164
192
|
return [!!e && setEditorRef(e), !!m && setMonacoRef(m)];
|
|
@@ -169,7 +197,7 @@ var CodeEditor = function CodeEditor(_ref) {
|
|
|
169
197
|
language: language,
|
|
170
198
|
onChange: handleChange,
|
|
171
199
|
theme: theme,
|
|
172
|
-
className:
|
|
200
|
+
className: "fabric-editor",
|
|
173
201
|
options: {
|
|
174
202
|
readOnly: readOnly,
|
|
175
203
|
minimap: {
|
|
@@ -8,7 +8,6 @@ export interface BaseEditorProps {
|
|
|
8
8
|
required?: boolean;
|
|
9
9
|
readOnly?: boolean;
|
|
10
10
|
minimal?: boolean;
|
|
11
|
-
language?: "json" | "css" | "html" | "text" | "markdown";
|
|
12
11
|
onChange?: (value: string) => void;
|
|
13
12
|
}
|
|
14
13
|
type EditorProps = BaseEditorProps & ({
|
|
@@ -25,6 +24,37 @@ type EditorProps = BaseEditorProps & ({
|
|
|
25
24
|
text: string;
|
|
26
25
|
description?: string;
|
|
27
26
|
}>;
|
|
27
|
+
} | {
|
|
28
|
+
language?: "css" | "text" | "markdown" | "yaml" | "xml";
|
|
29
|
+
schema?: any;
|
|
30
|
+
handlebarSuggestions?: never;
|
|
28
31
|
});
|
|
32
|
+
/**
|
|
33
|
+
* CodeEditor component to render a code editor using Monaco Editor.
|
|
34
|
+
* It supports JSON and HTML languages with optional schema validation and handlebar suggestions.
|
|
35
|
+
* The editor can be configured to be read-only, minimal, and can handle changes in the code.
|
|
36
|
+
* It provides a ref to access the editor's value and validation methods.
|
|
37
|
+
*
|
|
38
|
+
* @param {EditorProps} props - The properties for the CodeEditor component.
|
|
39
|
+
* @param {RefProp<MonacoEditorRef>} ref - The ref to access the editor methods.
|
|
40
|
+
* @return {JSX.Element} The rendered CodeEditor component.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```jsx
|
|
44
|
+
* <CodeEditor
|
|
45
|
+
* value={initialValue}
|
|
46
|
+
* schema={[{ uri: "http://example.com/schema.json", schema: {} }]}
|
|
47
|
+
* handlebarSuggestions={[{ text: "example", description: "An example suggestion" }]}
|
|
48
|
+
* required={true}
|
|
49
|
+
* readOnly={false}
|
|
50
|
+
* minimal={false}
|
|
51
|
+
* onChange={(value) => console.log("Code changed:", value)}
|
|
52
|
+
* language="json"
|
|
53
|
+
* />
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @see {@link https://adarshpastakia.github.io/react-fabric/?path=/story/monaco-playground--playground}
|
|
57
|
+
* @see {@link https://microsoft.github.io/monaco-editor/}
|
|
58
|
+
*/
|
|
29
59
|
export declare const CodeEditor: ({ ref, value, schema, handlebarSuggestions, required, readOnly, minimal, onChange, language, }: EditorProps & RefProp<MonacoEditorRef>) => import("react/jsx-runtime").JSX.Element;
|
|
30
60
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-fabric/monaco",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.61",
|
|
4
4
|
"description": "RUF: Monaco editor",
|
|
5
5
|
"author": "Adarsh Pastakia <adarshpastakia@outlook.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -11,9 +11,11 @@
|
|
|
11
11
|
"types": "dist/types/index.d.ts",
|
|
12
12
|
"directories": {
|
|
13
13
|
"src": "src",
|
|
14
|
+
"styles": "css",
|
|
14
15
|
"test": "tests"
|
|
15
16
|
},
|
|
16
17
|
"files": [
|
|
18
|
+
"css",
|
|
17
19
|
"src",
|
|
18
20
|
"dist"
|
|
19
21
|
],
|
|
@@ -33,23 +35,21 @@
|
|
|
33
35
|
"watch": "npm-run-all -p watch:rollup watch:dts"
|
|
34
36
|
},
|
|
35
37
|
"dependencies": {
|
|
36
|
-
"@react-fabric/core": "^1.0.0-beta.
|
|
37
|
-
"@react-fabric/utilities": "^1.0.0-beta.
|
|
38
|
-
"classnames": "
|
|
39
|
-
"
|
|
38
|
+
"@react-fabric/core": "^1.0.0-beta.61",
|
|
39
|
+
"@react-fabric/utilities": "^1.0.0-beta.61",
|
|
40
|
+
"classnames": "~2.5.1",
|
|
41
|
+
"monaco-editor": "~0.54.0",
|
|
42
|
+
"react-monaco-editor": "~0.59.0"
|
|
40
43
|
},
|
|
41
44
|
"peerDependencies": {
|
|
42
|
-
"i18next": "
|
|
43
|
-
"react": "
|
|
44
|
-
"react-dom": "
|
|
45
|
-
"react-i18next": "
|
|
46
|
-
},
|
|
47
|
-
"devDependencies": {
|
|
48
|
-
"monaco-editor": "^0.52.0"
|
|
45
|
+
"i18next": "~25.6.0",
|
|
46
|
+
"react": "~19.2.0",
|
|
47
|
+
"react-dom": "~19.2.0",
|
|
48
|
+
"react-i18next": "~16.2.1"
|
|
49
49
|
},
|
|
50
50
|
"engines": {
|
|
51
51
|
"node": ">=18.12.0",
|
|
52
52
|
"npm": ">=8.19.0"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "a0b0c571bf9c189fa3355bbc3b896ecc4b9d6a04"
|
|
55
55
|
}
|
|
@@ -41,7 +41,6 @@ import {
|
|
|
41
41
|
useState,
|
|
42
42
|
} from "react";
|
|
43
43
|
import MonacoEditor from "react-monaco-editor";
|
|
44
|
-
import classes from "./CodeEditor.module.css";
|
|
45
44
|
|
|
46
45
|
export interface MonacoEditorRef {
|
|
47
46
|
validate: () => boolean;
|
|
@@ -56,8 +55,6 @@ export interface BaseEditorProps {
|
|
|
56
55
|
|
|
57
56
|
minimal?: boolean;
|
|
58
57
|
|
|
59
|
-
language?: "json" | "css" | "html" | "text" | "markdown";
|
|
60
|
-
|
|
61
58
|
onChange?: (value: string) => void;
|
|
62
59
|
}
|
|
63
60
|
|
|
@@ -73,8 +70,40 @@ type EditorProps = BaseEditorProps &
|
|
|
73
70
|
schema?: never;
|
|
74
71
|
handlebarSuggestions?: Array<{ text: string; description?: string }>;
|
|
75
72
|
}
|
|
73
|
+
| {
|
|
74
|
+
language?: "css" | "text" | "markdown" | "yaml" | "xml";
|
|
75
|
+
schema?: any;
|
|
76
|
+
handlebarSuggestions?: never;
|
|
77
|
+
}
|
|
76
78
|
);
|
|
77
79
|
|
|
80
|
+
/**
|
|
81
|
+
* CodeEditor component to render a code editor using Monaco Editor.
|
|
82
|
+
* It supports JSON and HTML languages with optional schema validation and handlebar suggestions.
|
|
83
|
+
* The editor can be configured to be read-only, minimal, and can handle changes in the code.
|
|
84
|
+
* It provides a ref to access the editor's value and validation methods.
|
|
85
|
+
*
|
|
86
|
+
* @param {EditorProps} props - The properties for the CodeEditor component.
|
|
87
|
+
* @param {RefProp<MonacoEditorRef>} ref - The ref to access the editor methods.
|
|
88
|
+
* @return {JSX.Element} The rendered CodeEditor component.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```jsx
|
|
92
|
+
* <CodeEditor
|
|
93
|
+
* value={initialValue}
|
|
94
|
+
* schema={[{ uri: "http://example.com/schema.json", schema: {} }]}
|
|
95
|
+
* handlebarSuggestions={[{ text: "example", description: "An example suggestion" }]}
|
|
96
|
+
* required={true}
|
|
97
|
+
* readOnly={false}
|
|
98
|
+
* minimal={false}
|
|
99
|
+
* onChange={(value) => console.log("Code changed:", value)}
|
|
100
|
+
* language="json"
|
|
101
|
+
* />
|
|
102
|
+
* ```
|
|
103
|
+
*
|
|
104
|
+
* @see {@link https://adarshpastakia.github.io/react-fabric/?path=/story/monaco-playground--playground}
|
|
105
|
+
* @see {@link https://microsoft.github.io/monaco-editor/}
|
|
106
|
+
*/
|
|
78
107
|
export const CodeEditor = ({
|
|
79
108
|
ref,
|
|
80
109
|
value,
|
|
@@ -154,13 +183,13 @@ export const CodeEditor = ({
|
|
|
154
183
|
[required, language],
|
|
155
184
|
);
|
|
156
185
|
|
|
157
|
-
const disposeRef = useRef<AnyObject>();
|
|
186
|
+
const disposeRef = useRef<AnyObject>(null);
|
|
158
187
|
const schemaUri = useCallback(
|
|
159
188
|
(monaco: typeof monacoEditor) => {
|
|
160
189
|
if (language === "json" && schema) {
|
|
161
190
|
const [main, ...rest] = schema;
|
|
162
191
|
// configure the JSON language support with schemas and schema associations
|
|
163
|
-
monaco.languages
|
|
192
|
+
monaco.languages?.json?.jsonDefaults.setDiagnosticsOptions({
|
|
164
193
|
validate: true,
|
|
165
194
|
allowComments: false,
|
|
166
195
|
schemas: [
|
|
@@ -223,11 +252,11 @@ export const CodeEditor = ({
|
|
|
223
252
|
}, []);
|
|
224
253
|
|
|
225
254
|
return (
|
|
226
|
-
<Section>
|
|
255
|
+
<Section className="relative">
|
|
227
256
|
<div
|
|
228
257
|
ref={containerRef}
|
|
229
|
-
data-
|
|
230
|
-
className={classNames(
|
|
258
|
+
data-ref="codeEditor"
|
|
259
|
+
className={classNames("fabric-codeEditor", "absolute inset-0")}
|
|
231
260
|
>
|
|
232
261
|
<MonacoEditor
|
|
233
262
|
editorDidMount={(e, m) => [
|
|
@@ -240,7 +269,7 @@ export const CodeEditor = ({
|
|
|
240
269
|
language={language}
|
|
241
270
|
onChange={handleChange}
|
|
242
271
|
theme={theme}
|
|
243
|
-
className={
|
|
272
|
+
className={"fabric-editor"}
|
|
244
273
|
options={{
|
|
245
274
|
readOnly,
|
|
246
275
|
minimap: {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
@layer util{.codeEditor{border:solid transparent;border-width:1px 1px 2px;direction:ltr;overflow:hidden;&:has(:global(.monaco-editor.focused)){border-color:theme(borderColor.primary.500)}.editor{&>:global(.monaco-editor){--vscode-menu-background:theme(colors.tint.50)!important;--vscode-menu-border:theme(borderColor.base)!important;--vscode-focusBorder:transparent!important;--vscode-menu-selectionBackground:color(from var(--primary) srgb r g b/80%)!important;--vscode-editor-background:var(--fabric-bg)!important;--vscode-editor-foreground:var(--fabric-text)!important;--vscode-breadcrumb-background:var(--fabric-bg)!important;--vscode-editorGutter-background:color(from theme(colors.tint.50) srgb r g g/50%)!important;--vscode-minimapSlider-background:color(from var(--tint) srgb r g b/20%)!important;--vscode-minimapSlider-hoverBackground:color(from var(--tint) srgb r g b/25%)!important;--vscode-minimapSlider-activeBackground:color(from var(--tint) srgb r g b/30%)!important;--vscode-input-border:var(--primary)!important;--vscode-editorStickyScroll-background:var(--fabric-bg)!important;--vscode-editorMarkerNavigation-background:var(--fabric-bg)!important;--vscode-editor-wordHighlightTextBackground:color(from theme(colors.accent.700) srgb r g b/20%)!important}& :global(.minimap-decorations-layer){background-color:color(from theme(colors.tint.50) srgb r g g/50%)!important}& :global(.folded-background){opacity:.5}& :global(.monaco-findInput) textarea{min-height:unset;resize:none}& :global{.editor-widget.suggest-widget .message{font-size:.75rem}}& span{padding:0}}}.editorTools{@apply bg-base}}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
@layer util{.codeEditor{border:solid transparent;border-width:1px 1px 2px;direction:ltr;overflow:hidden;&:has(:global(.monaco-editor.focused)){border-color:theme(borderColor.primary.500)}.editor{&>:global(.monaco-editor){--vscode-menu-background:theme(colors.tint.50)!important;--vscode-menu-border:theme(borderColor.base)!important;--vscode-focusBorder:transparent!important;--vscode-menu-selectionBackground:color(from var(--primary) srgb r g b/80%)!important;--vscode-editor-background:var(--fabric-bg)!important;--vscode-editor-foreground:var(--fabric-text)!important;--vscode-breadcrumb-background:var(--fabric-bg)!important;--vscode-editorGutter-background:color(from theme(colors.tint.50) srgb r g g/50%)!important;--vscode-minimapSlider-background:color(from var(--tint) srgb r g b/20%)!important;--vscode-minimapSlider-hoverBackground:color(from var(--tint) srgb r g b/25%)!important;--vscode-minimapSlider-activeBackground:color(from var(--tint) srgb r g b/30%)!important;--vscode-input-border:var(--primary)!important;--vscode-editorStickyScroll-background:var(--fabric-bg)!important;--vscode-editorMarkerNavigation-background:var(--fabric-bg)!important;--vscode-editor-wordHighlightTextBackground:color(from theme(colors.accent.700) srgb r g b/20%)!important}& :global(.minimap-decorations-layer){background-color:color(from theme(colors.tint.50) srgb r g g/50%)!important}& :global(.folded-background){opacity:.5}& :global(.monaco-findInput) textarea{min-height:unset;resize:none}& :global{.editor-widget.suggest-widget .message{font-size:.75rem}}& span{padding:0}}}.editorTools{@apply bg-base}}
|