@react-fabric/monaco 1.0.0-beta.3 → 1.0.0-beta.30
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/dist/cjs/components/CodeEditor.js +47 -3
- package/dist/cjs/components/CodeEditor.module.css +1 -1
- package/dist/esm/components/CodeEditor.js +48 -4
- package/dist/esm/components/CodeEditor.module.css +1 -1
- package/dist/types/components/CodeEditor.d.ts +17 -5
- package/package.json +7 -9
- package/src/components/CodeEditor.module.css +7 -1
- package/src/components/CodeEditor.tsx +61 -7
|
@@ -18,6 +18,7 @@ var CodeEditor = function CodeEditor(_ref) {
|
|
|
18
18
|
var ref = _ref.ref,
|
|
19
19
|
value = _ref.value,
|
|
20
20
|
schema = _ref.schema,
|
|
21
|
+
handlebarSuggestions = _ref.handlebarSuggestions,
|
|
21
22
|
required = _ref.required,
|
|
22
23
|
readOnly = _ref.readOnly,
|
|
23
24
|
minimal = _ref.minimal,
|
|
@@ -90,8 +91,9 @@ var CodeEditor = function CodeEditor(_ref) {
|
|
|
90
91
|
}
|
|
91
92
|
};
|
|
92
93
|
}, [required, language]);
|
|
94
|
+
var disposeRef = react.useRef();
|
|
93
95
|
var schemaUri = react.useCallback(function (monaco) {
|
|
94
|
-
if (schema) {
|
|
96
|
+
if (language === "json" && schema) {
|
|
95
97
|
var _schema = _toArray(schema),
|
|
96
98
|
main = _schema[0],
|
|
97
99
|
rest = _schema.slice(1);
|
|
@@ -104,7 +106,47 @@ var CodeEditor = function CodeEditor(_ref) {
|
|
|
104
106
|
}, main)].concat(_toConsumableArray(rest))
|
|
105
107
|
});
|
|
106
108
|
}
|
|
107
|
-
|
|
109
|
+
if (language === "html" && handlebarSuggestions) {
|
|
110
|
+
var _disposeRef$current, _disposeRef$current$d;
|
|
111
|
+
(_disposeRef$current = disposeRef.current) === null || _disposeRef$current === void 0 || (_disposeRef$current$d = _disposeRef$current.dispose) === null || _disposeRef$current$d === void 0 || _disposeRef$current$d.call(_disposeRef$current);
|
|
112
|
+
disposeRef.current = monaco.languages.registerCompletionItemProvider("html", {
|
|
113
|
+
triggerCharacters: ["{{"],
|
|
114
|
+
provideCompletionItems: function provideCompletionItems(model, position) {
|
|
115
|
+
// find out if we are completing a property in the 'dependencies' object.
|
|
116
|
+
var textUntilPosition = model.getValueInRange({
|
|
117
|
+
startLineNumber: 1,
|
|
118
|
+
startColumn: 1,
|
|
119
|
+
endLineNumber: position.lineNumber,
|
|
120
|
+
endColumn: position.column
|
|
121
|
+
});
|
|
122
|
+
var match = textUntilPosition.match(/\{\{(.*)([^}])?$/);
|
|
123
|
+
if (!match) {
|
|
124
|
+
return {
|
|
125
|
+
suggestions: []
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
var word = model.getWordUntilPosition(position);
|
|
129
|
+
var range = {
|
|
130
|
+
startLineNumber: position.lineNumber,
|
|
131
|
+
endLineNumber: position.lineNumber,
|
|
132
|
+
startColumn: word.startColumn,
|
|
133
|
+
endColumn: word.endColumn
|
|
134
|
+
};
|
|
135
|
+
return {
|
|
136
|
+
suggestions: handlebarSuggestions.map(function (hs) {
|
|
137
|
+
return {
|
|
138
|
+
label: hs.text,
|
|
139
|
+
kind: monaco.languages.CompletionItemKind.Text,
|
|
140
|
+
documentation: hs.description,
|
|
141
|
+
insertText: hs.text,
|
|
142
|
+
range: range
|
|
143
|
+
};
|
|
144
|
+
})
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}, [schema, language]);
|
|
108
150
|
var resetSchema = react.useCallback(function (_, monaco) {
|
|
109
151
|
monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
|
|
110
152
|
validate: true,
|
|
@@ -113,9 +155,11 @@ var CodeEditor = function CodeEditor(_ref) {
|
|
|
113
155
|
});
|
|
114
156
|
}, []);
|
|
115
157
|
return /*#__PURE__*/jsxRuntime.jsx(core.Section, {
|
|
158
|
+
className: "relative",
|
|
116
159
|
children: /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
117
160
|
ref: containerRef,
|
|
118
|
-
|
|
161
|
+
"data-ref": "codeEditor",
|
|
162
|
+
className: classNames(CodeEditor_module.codeEditor, "absolute inset-0"),
|
|
119
163
|
children: /*#__PURE__*/jsxRuntime.jsx(MonacoEditor, {
|
|
120
164
|
editorDidMount: function editorDidMount(e, m) {
|
|
121
165
|
return [!!e && setEditorRef(e), !!m && setMonacoRef(m)];
|
|
@@ -1 +1 @@
|
|
|
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}& span{padding:0}}}.editorTools{
|
|
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{background-color:theme(backgroundColor.base)}}
|
|
@@ -7,7 +7,7 @@ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
|
7
7
|
import { useIsDark, useResizeObserver, useDebounce, Section } from '@react-fabric/core';
|
|
8
8
|
import { isString, isEmpty } from '@react-fabric/utilities';
|
|
9
9
|
import classNames from 'classnames';
|
|
10
|
-
import { useState, useLayoutEffect, useCallback, useDeferredValue, useMemo, useImperativeHandle } from 'react';
|
|
10
|
+
import { useState, useLayoutEffect, useCallback, useDeferredValue, useMemo, useImperativeHandle, useRef } from 'react';
|
|
11
11
|
import MonacoEditor from 'react-monaco-editor';
|
|
12
12
|
import classes from './CodeEditor.module.css';
|
|
13
13
|
import { jsx } from 'react/jsx-runtime';
|
|
@@ -18,6 +18,7 @@ var CodeEditor = function CodeEditor(_ref) {
|
|
|
18
18
|
var ref = _ref.ref,
|
|
19
19
|
value = _ref.value,
|
|
20
20
|
schema = _ref.schema,
|
|
21
|
+
handlebarSuggestions = _ref.handlebarSuggestions,
|
|
21
22
|
required = _ref.required,
|
|
22
23
|
readOnly = _ref.readOnly,
|
|
23
24
|
minimal = _ref.minimal,
|
|
@@ -90,8 +91,9 @@ var CodeEditor = function CodeEditor(_ref) {
|
|
|
90
91
|
}
|
|
91
92
|
};
|
|
92
93
|
}, [required, language]);
|
|
94
|
+
var disposeRef = useRef();
|
|
93
95
|
var schemaUri = useCallback(function (monaco) {
|
|
94
|
-
if (schema) {
|
|
96
|
+
if (language === "json" && schema) {
|
|
95
97
|
var _schema = _toArray(schema),
|
|
96
98
|
main = _schema[0],
|
|
97
99
|
rest = _schema.slice(1);
|
|
@@ -104,7 +106,47 @@ var CodeEditor = function CodeEditor(_ref) {
|
|
|
104
106
|
}, main)].concat(_toConsumableArray(rest))
|
|
105
107
|
});
|
|
106
108
|
}
|
|
107
|
-
|
|
109
|
+
if (language === "html" && handlebarSuggestions) {
|
|
110
|
+
var _disposeRef$current, _disposeRef$current$d;
|
|
111
|
+
(_disposeRef$current = disposeRef.current) === null || _disposeRef$current === void 0 || (_disposeRef$current$d = _disposeRef$current.dispose) === null || _disposeRef$current$d === void 0 || _disposeRef$current$d.call(_disposeRef$current);
|
|
112
|
+
disposeRef.current = monaco.languages.registerCompletionItemProvider("html", {
|
|
113
|
+
triggerCharacters: ["{{"],
|
|
114
|
+
provideCompletionItems: function provideCompletionItems(model, position) {
|
|
115
|
+
// find out if we are completing a property in the 'dependencies' object.
|
|
116
|
+
var textUntilPosition = model.getValueInRange({
|
|
117
|
+
startLineNumber: 1,
|
|
118
|
+
startColumn: 1,
|
|
119
|
+
endLineNumber: position.lineNumber,
|
|
120
|
+
endColumn: position.column
|
|
121
|
+
});
|
|
122
|
+
var match = textUntilPosition.match(/\{\{(.*)([^}])?$/);
|
|
123
|
+
if (!match) {
|
|
124
|
+
return {
|
|
125
|
+
suggestions: []
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
var word = model.getWordUntilPosition(position);
|
|
129
|
+
var range = {
|
|
130
|
+
startLineNumber: position.lineNumber,
|
|
131
|
+
endLineNumber: position.lineNumber,
|
|
132
|
+
startColumn: word.startColumn,
|
|
133
|
+
endColumn: word.endColumn
|
|
134
|
+
};
|
|
135
|
+
return {
|
|
136
|
+
suggestions: handlebarSuggestions.map(function (hs) {
|
|
137
|
+
return {
|
|
138
|
+
label: hs.text,
|
|
139
|
+
kind: monaco.languages.CompletionItemKind.Text,
|
|
140
|
+
documentation: hs.description,
|
|
141
|
+
insertText: hs.text,
|
|
142
|
+
range: range
|
|
143
|
+
};
|
|
144
|
+
})
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}, [schema, language]);
|
|
108
150
|
var resetSchema = useCallback(function (_, monaco) {
|
|
109
151
|
monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
|
|
110
152
|
validate: true,
|
|
@@ -113,9 +155,11 @@ var CodeEditor = function CodeEditor(_ref) {
|
|
|
113
155
|
});
|
|
114
156
|
}, []);
|
|
115
157
|
return /*#__PURE__*/jsx(Section, {
|
|
158
|
+
className: "relative",
|
|
116
159
|
children: /*#__PURE__*/jsx("div", {
|
|
117
160
|
ref: containerRef,
|
|
118
|
-
|
|
161
|
+
"data-ref": "codeEditor",
|
|
162
|
+
className: classNames(classes.codeEditor, "absolute inset-0"),
|
|
119
163
|
children: /*#__PURE__*/jsx(MonacoEditor, {
|
|
120
164
|
editorDidMount: function editorDidMount(e, m) {
|
|
121
165
|
return [!!e && setEditorRef(e), !!m && setMonacoRef(m)];
|
|
@@ -1 +1 @@
|
|
|
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}& span{padding:0}}}.editorTools{
|
|
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{background-color:theme(backgroundColor.base)}}
|
|
@@ -3,16 +3,28 @@ export interface MonacoEditorRef {
|
|
|
3
3
|
validate: () => boolean;
|
|
4
4
|
getValue: () => string | undefined;
|
|
5
5
|
}
|
|
6
|
-
export interface
|
|
6
|
+
export interface BaseEditorProps {
|
|
7
7
|
value?: string | AnyObject;
|
|
8
8
|
required?: boolean;
|
|
9
9
|
readOnly?: boolean;
|
|
10
10
|
minimal?: boolean;
|
|
11
|
+
language?: "json" | "css" | "html" | "text" | "markdown";
|
|
12
|
+
onChange?: (value: string) => void;
|
|
13
|
+
}
|
|
14
|
+
type EditorProps = BaseEditorProps & ({
|
|
15
|
+
language: "json";
|
|
11
16
|
schema?: Array<{
|
|
12
17
|
uri: string;
|
|
13
18
|
schema: KeyValue;
|
|
14
19
|
}>;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
20
|
+
handlebarSuggestions?: never;
|
|
21
|
+
} | {
|
|
22
|
+
language: "html";
|
|
23
|
+
schema?: never;
|
|
24
|
+
handlebarSuggestions?: Array<{
|
|
25
|
+
text: string;
|
|
26
|
+
description?: string;
|
|
27
|
+
}>;
|
|
28
|
+
});
|
|
29
|
+
export declare const CodeEditor: ({ ref, value, schema, handlebarSuggestions, required, readOnly, minimal, onChange, language, }: EditorProps & RefProp<MonacoEditorRef>) => import("react/jsx-runtime").JSX.Element;
|
|
30
|
+
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.30",
|
|
4
4
|
"description": "RUF: Monaco editor",
|
|
5
5
|
"author": "Adarsh Pastakia <adarshpastakia@outlook.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,23 +33,21 @@
|
|
|
33
33
|
"watch": "npm-run-all -p watch:rollup watch:dts"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@react-fabric/core": "^1.0.0-beta.
|
|
37
|
-
"@react-fabric/utilities": "^1.0.0-beta.
|
|
36
|
+
"@react-fabric/core": "^1.0.0-beta.30",
|
|
37
|
+
"@react-fabric/utilities": "^1.0.0-beta.30",
|
|
38
38
|
"classnames": "^2.5.1",
|
|
39
|
+
"monaco-editor": "^0.52.0",
|
|
39
40
|
"react-monaco-editor": "^0.56.2"
|
|
40
41
|
},
|
|
41
42
|
"peerDependencies": {
|
|
42
43
|
"i18next": "^23.15.1",
|
|
43
|
-
"react": "
|
|
44
|
-
"react-dom": "
|
|
44
|
+
"react": "^19.0.0",
|
|
45
|
+
"react-dom": "^19.0.0",
|
|
45
46
|
"react-i18next": "^15.0.2"
|
|
46
47
|
},
|
|
47
|
-
"devDependencies": {
|
|
48
|
-
"monaco-editor": "^0.52.0"
|
|
49
|
-
},
|
|
50
48
|
"engines": {
|
|
51
49
|
"node": ">=18.12.0",
|
|
52
50
|
"npm": ">=8.19.0"
|
|
53
51
|
},
|
|
54
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "5b10298b7627c2e56bcccf18100b6d85a02c9b06"
|
|
55
53
|
}
|
|
@@ -80,6 +80,12 @@
|
|
|
80
80
|
min-height: unset;
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
+
& :global {
|
|
84
|
+
.editor-widget.suggest-widget .message {
|
|
85
|
+
font-size: 0.75rem;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
83
89
|
& span {
|
|
84
90
|
padding: 0;
|
|
85
91
|
}
|
|
@@ -87,6 +93,6 @@
|
|
|
87
93
|
}
|
|
88
94
|
|
|
89
95
|
.editorTools {
|
|
90
|
-
|
|
96
|
+
background-color: theme(backgroundColor.base);
|
|
91
97
|
}
|
|
92
98
|
}
|
|
@@ -37,6 +37,7 @@ import {
|
|
|
37
37
|
useImperativeHandle,
|
|
38
38
|
useLayoutEffect,
|
|
39
39
|
useMemo,
|
|
40
|
+
useRef,
|
|
40
41
|
useState,
|
|
41
42
|
} from "react";
|
|
42
43
|
import MonacoEditor from "react-monaco-editor";
|
|
@@ -47,7 +48,7 @@ export interface MonacoEditorRef {
|
|
|
47
48
|
getValue: () => string | undefined;
|
|
48
49
|
}
|
|
49
50
|
|
|
50
|
-
export interface
|
|
51
|
+
export interface BaseEditorProps {
|
|
51
52
|
value?: string | AnyObject;
|
|
52
53
|
|
|
53
54
|
required?: boolean;
|
|
@@ -55,17 +56,30 @@ export interface EditorProps {
|
|
|
55
56
|
|
|
56
57
|
minimal?: boolean;
|
|
57
58
|
|
|
58
|
-
schema?: Array<{ uri: string; schema: KeyValue }>;
|
|
59
|
-
|
|
60
59
|
language?: "json" | "css" | "html" | "text" | "markdown";
|
|
61
60
|
|
|
62
61
|
onChange?: (value: string) => void;
|
|
63
62
|
}
|
|
64
63
|
|
|
64
|
+
type EditorProps = BaseEditorProps &
|
|
65
|
+
(
|
|
66
|
+
| {
|
|
67
|
+
language: "json";
|
|
68
|
+
schema?: Array<{ uri: string; schema: KeyValue }>;
|
|
69
|
+
handlebarSuggestions?: never;
|
|
70
|
+
}
|
|
71
|
+
| {
|
|
72
|
+
language: "html";
|
|
73
|
+
schema?: never;
|
|
74
|
+
handlebarSuggestions?: Array<{ text: string; description?: string }>;
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
|
|
65
78
|
export const CodeEditor = ({
|
|
66
79
|
ref,
|
|
67
80
|
value,
|
|
68
81
|
schema,
|
|
82
|
+
handlebarSuggestions,
|
|
69
83
|
required,
|
|
70
84
|
readOnly,
|
|
71
85
|
minimal,
|
|
@@ -140,9 +154,10 @@ export const CodeEditor = ({
|
|
|
140
154
|
[required, language],
|
|
141
155
|
);
|
|
142
156
|
|
|
157
|
+
const disposeRef = useRef<AnyObject>();
|
|
143
158
|
const schemaUri = useCallback(
|
|
144
159
|
(monaco: typeof monacoEditor) => {
|
|
145
|
-
if (schema) {
|
|
160
|
+
if (language === "json" && schema) {
|
|
146
161
|
const [main, ...rest] = schema;
|
|
147
162
|
// configure the JSON language support with schemas and schema associations
|
|
148
163
|
monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
|
|
@@ -157,8 +172,46 @@ export const CodeEditor = ({
|
|
|
157
172
|
],
|
|
158
173
|
});
|
|
159
174
|
}
|
|
175
|
+
if (language === "html" && handlebarSuggestions) {
|
|
176
|
+
disposeRef.current?.dispose?.();
|
|
177
|
+
disposeRef.current = monaco.languages.registerCompletionItemProvider(
|
|
178
|
+
"html",
|
|
179
|
+
{
|
|
180
|
+
triggerCharacters: ["{{"],
|
|
181
|
+
provideCompletionItems: function (model, position) {
|
|
182
|
+
// find out if we are completing a property in the 'dependencies' object.
|
|
183
|
+
const textUntilPosition = model.getValueInRange({
|
|
184
|
+
startLineNumber: 1,
|
|
185
|
+
startColumn: 1,
|
|
186
|
+
endLineNumber: position.lineNumber,
|
|
187
|
+
endColumn: position.column,
|
|
188
|
+
});
|
|
189
|
+
const match = textUntilPosition.match(/\{\{(.*)([^}])?$/);
|
|
190
|
+
if (!match) {
|
|
191
|
+
return { suggestions: [] };
|
|
192
|
+
}
|
|
193
|
+
const word = model.getWordUntilPosition(position);
|
|
194
|
+
const range = {
|
|
195
|
+
startLineNumber: position.lineNumber,
|
|
196
|
+
endLineNumber: position.lineNumber,
|
|
197
|
+
startColumn: word.startColumn,
|
|
198
|
+
endColumn: word.endColumn,
|
|
199
|
+
};
|
|
200
|
+
return {
|
|
201
|
+
suggestions: handlebarSuggestions.map((hs) => ({
|
|
202
|
+
label: hs.text,
|
|
203
|
+
kind: monaco.languages.CompletionItemKind.Text,
|
|
204
|
+
documentation: hs.description,
|
|
205
|
+
insertText: hs.text,
|
|
206
|
+
range,
|
|
207
|
+
})),
|
|
208
|
+
};
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
);
|
|
212
|
+
}
|
|
160
213
|
},
|
|
161
|
-
[schema],
|
|
214
|
+
[schema, language],
|
|
162
215
|
);
|
|
163
216
|
|
|
164
217
|
const resetSchema = useCallback((_: unknown, monaco: typeof monacoEditor) => {
|
|
@@ -170,10 +223,11 @@ export const CodeEditor = ({
|
|
|
170
223
|
}, []);
|
|
171
224
|
|
|
172
225
|
return (
|
|
173
|
-
<Section>
|
|
226
|
+
<Section className="relative">
|
|
174
227
|
<div
|
|
175
228
|
ref={containerRef}
|
|
176
|
-
|
|
229
|
+
data-ref="codeEditor"
|
|
230
|
+
className={classNames(classes.codeEditor, "absolute inset-0")}
|
|
177
231
|
>
|
|
178
232
|
<MonacoEditor
|
|
179
233
|
editorDidMount={(e, m) => [
|