Skip to content

Commit

Permalink
feat(core): add disableValidation and monacoEditorOptions props
Browse files Browse the repository at this point in the history
  • Loading branch information
chongqiangchen committed Apr 20, 2023
1 parent 63efd9e commit 237fff4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ module.exports = {
'react/require-default-props': 'warn',
'react/no-unused-prop-types': 'warn',
'jsx-a11y/click-events-have-key-events': 'warn',
'react/jsx-no-bind': 'off',

// import 相关
'import/prefer-default-export': 'off',
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, { useState } from 'react';
import { Allotment } from 'allotment';
import { CommandLineIcon } from '@heroicons/react/24/outline';
import merge from 'lodash/merge';
import BaseMonaco from 'monaco-editor';

import { ModelInfoType } from '../types/monaco';
import FileNavBar from '../components/FileNavBar';
Expand Down Expand Up @@ -40,10 +41,12 @@ export type TEditorProps = {
id: string;
modelInfos: ModelInfoType[];
height: string;
disableValidation?: boolean;
fileNav?: TFileNavProps;
rounded?: string;
console?: TConsoleProps;
deploy?: TDeployProps;
monacoEditorOptions?: BaseMonaco.editor.IStandaloneEditorConstructionOptions;
// onSuccess?: Dispatch<SetStateAction<number>>;
// onFailure?: () => void;
// onCompile?: () => void;
Expand Down Expand Up @@ -79,6 +82,7 @@ function Main(props: TEditorProps) {
fileNav = {},
rounded = '12px',
modelInfos,
...others
} = props;
const consoleProps = merge(DefaultConsoleProps, console);
const deployProps = merge(DefaultDeployProps, deploy);
Expand Down Expand Up @@ -123,7 +127,7 @@ function Main(props: TEditorProps) {
}}
/>
)}
<MonacoEditor modelInfos={modelInfos} />
<MonacoEditor modelInfos={modelInfos} {...others} />
</Allotment.Pane>
{consoleProps.open && (
<Allotment.Pane
Expand Down
10 changes: 8 additions & 2 deletions packages/core/src/editor/monacoEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ loader.config({ paths: { vs: 'https://cdn.jsdelivr.net/npm/[email protected]/

interface IProps {
modelInfos: ModelInfoType[];
disableValidation?: boolean;
monacoEditorOptions?: BaseMonaco.editor.IStandaloneEditorConstructionOptions;
}

function App({ modelInfos }: IProps) {
function App({ modelInfos, disableValidation = false, monacoEditorOptions = {} }: IProps) {
const {
stateRef, dispatch, actions, id,
} = useEditor();
Expand All @@ -46,7 +48,9 @@ function App({ modelInfos }: IProps) {
actions.updateCodeParserLoading(false);

registerCommandsAndActions(monaco, editor, dispatch, stateRef.current);
registerListeners(editor, editorApiRef.current, stateRef.current);
// TODO 目前监听仅有处理语法校验问题,后续状态控制需要特殊处理
// eslint-disable-next-line no-unused-expressions
!disableValidation && registerListeners(editor, editorApiRef.current, stateRef.current);
}

function handleEditorBeforeMount(monaco: Monaco) {
Expand Down Expand Up @@ -113,6 +117,8 @@ function App({ modelInfos }: IProps) {
minimap: {
enabled: false,
},
fontSize: 14,
...monacoEditorOptions,
}}
/>
);
Expand Down

0 comments on commit 237fff4

Please sign in to comment.