Skip to content

Commit 7b71c4d

Browse files
committed
feat: 引入react、react-dom types
1 parent a0eaa0c commit 7b71c4d

File tree

8 files changed

+28
-19
lines changed

8 files changed

+28
-19
lines changed

packages/demo/src/components/Editor/demo/Multiple.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import React, { useState } from 'react';
44
const App: React.FC = () => {
55
return (
66
<>
7-
<MultipleEditor />
7+
<MultipleEditor style={{ marginTop: 24 }} />
88
</>
99
);
1010
};

packages/demo/src/components/Editor/props.mdx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import Table from '../table.tsx';
2-
3-
export const params = [];
4-
5-
## API 列表
6-
7-
<Table name="input" params={params} />
1+
import Table from '../table.tsx'
2+
export const params = []
3+
## API 列表
4+
<Table name='editor' params={params}/>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import React from 'react';
2+
import { PivotDesignProps } from './';
3+
export interface MultipleEditorProps extends PivotDesignProps {
4+
5+
}

packages/design-props/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ export * from './components/popover';
88
export * from './components/modal';
99
export * from './components/transition';
1010
export * from './components/tabs';
11+
export * from './components/editor';

packages/design/components/MonacoEditor/MultipleEditor.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { EditorProps } from '@monaco-editor/react';
2-
import { useRef, useState } from 'react';
2+
import { FC, useRef, useState } from 'react';
33
import { CodeType, Module } from './types';
44
import { testCode } from './code';
55
import Tabs from '../Tabs';
66
import MonacoEditor from './Editor';
77
import { useLocalStorage } from '../hooks';
8+
import { MultipleEditorProps } from 'pivot-design-props';
89

910
const FILENAME1 = 'index.tsx';
1011
const FILENAME2 = 'index.scss';
@@ -39,13 +40,13 @@ const items: Module[] = [
3940
// todo: 1. 编译文件的独立性。现在修改css实际走的是tsx的编译
4041
// 2.引入scss
4142
// 3.代码优化;
42-
const MultipleEditor = () => {
43+
const MultipleEditor: FC<MultipleEditorProps> = ({ style }) => {
4344
const [tabsValue, setTabsValue] = useLocalStorage<Module[]>('tabs', {
4445
defaultValue: items,
4546
});
4647

4748
return (
48-
<div style={{ width: '100%', padding: 12 }}>
49+
<div style={{ width: '100%', padding: 12, ...style }}>
4950
<Tabs
5051
items={tabsValue}
5152
renderCommonContent={(item) => {

packages/design/components/MonacoEditor/components/Preview/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@
3838
const compileScript = document.createElement('script');
3939
compileScript.id = CompileScriptId;
4040
compileScript.type = 'module';
41-
compileScript.innerHTML = `try{${code}}catch(err){console.log(err)}`;
41+
compileScript.innerHTML = `${code}`;
4242
document.body.appendChild(compileScript);
4343

44+
// code runner exhibition
4445
document.getElementById('__CODE_RUN__').innerHTML = runcode.replace(
4546
/[\n]/g,
4647
'<br />'

packages/design/components/MonacoEditor/plugins/initPlugin.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
11
import { Monaco } from '@monaco-editor/react';
22
import REACT_TYPES from '!!raw-loader!/node_modules/@types/react/index.d.ts';
3+
import REACT_DOM_TYPES from '!!raw-loader!/node_modules/@types/react-dom/client.d.ts';
34
const InitPlugin = (monaco: Monaco) => {
45
// 添加ts编译设置
56
monaco.languages.typescript.typescriptDefaults.setCompilerOptions({
67
target: monaco.languages.typescript.ScriptTarget.Latest,
7-
allowNonTsExtensions: true,
8-
moduleResolution: monaco.languages.typescript.ModuleResolutionKind.NodeJs,
9-
module: monaco.languages.typescript.ModuleKind.ES2015,
8+
moduleResolution: monaco.languages.typescript.ModuleResolutionKind.NodeJs, // 模块解析策略 nodejs
9+
module: monaco.languages.typescript.ModuleKind.ES2015, // 代码生成格式
1010
noEmit: true,
11-
esModuleInterop: true,
11+
esModuleInterop: true, // 通过为所有导入创建命名空间对象,实现CommonJS和ES模块之间的互操作性
1212
jsx: monaco.languages.typescript.JsxEmit.React,
1313
reactNamespace: 'React',
1414
allowJs: true,
15-
typeRoots: ['node_modules/@types'],
15+
typeRoots: ['node_modules/@types'], // 声明类型依赖目录
1616
});
1717

1818
/** 添加额外的依赖包,lib是源代码,第二个参数是自己为其设置的文件路径*/
1919
monaco.languages.typescript.typescriptDefaults.addExtraLib(
2020
REACT_TYPES,
21-
'file:///node_modules/@react/types/index.d.ts'
21+
'file:///node_modules/@types/react/index.d.ts'
22+
);
23+
monaco.languages.typescript.typescriptDefaults.addExtraLib(
24+
REACT_DOM_TYPES,
25+
'file:///node_modules/@types/react-dom/client.d.ts'
2226
);
2327
};
2428

packages/design/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
"exclude": ["lib", ".*"],
55
"compilerOptions": {
66
"baseUrl": ".",
7-
"outDir": "lib",
7+
"outDir": "lib"
88
}
99
}

0 commit comments

Comments
 (0)