@easyv/biz-components 0.0.52-beta.3 → 0.0.52
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/_virtual/index.es2.js +2 -2
- package/dist/_virtual/index.es3.js +2 -2
- package/dist/_virtual/index.es4.js +2 -2
- package/dist/components/easyv-monaco-editor/easyv-monaco-editor.es.js +46 -47
- package/dist/components/easyv-monaco-editor/easyv-monaco-editor.es.js.map +1 -1
- package/dist/components/easyv-monaco-editor/index.d.ts +1 -0
- package/dist/components/easyv-monaco-editor/types.d.ts +14 -0
- package/dist/hooks/use-initialized.d.ts +4 -2
- package/dist/hooks/use-initialized.es.js +4 -5
- package/dist/hooks/use-initialized.es.js.map +1 -1
- package/dist/node_modules/.pnpm/classnames@2.3.2/node_modules/classnames/index.es.js +1 -1
- package/dist/node_modules/.pnpm/co-web-worker@1.0.1/node_modules/co-web-worker/index.es.js +1 -1
- package/dist/node_modules/.pnpm/prop-types@15.8.1/node_modules/prop-types/index.es.js +1 -1
- package/dist/stats.html +1 -1
- package/package.json +1 -1
- package/dist/components/easyv-monaco-editor/monaco-setup.d.ts +0 -0
- package/dist/node_modules/.pnpm/ahooks@3.8.5_react@18.2.0/node_modules/ahooks/es/useLatest/index.es.js +0 -10
- package/dist/node_modules/.pnpm/ahooks@3.8.5_react@18.2.0/node_modules/ahooks/es/useLatest/index.es.js.map +0 -1
- package/dist/node_modules/.pnpm/ahooks@3.8.5_react@18.2.0/node_modules/ahooks/es/useMount/index.es.js +0 -17
- package/dist/node_modules/.pnpm/ahooks@3.8.5_react@18.2.0/node_modules/ahooks/es/useMount/index.es.js.map +0 -1
- package/dist/node_modules/.pnpm/ahooks@3.8.5_react@18.2.0/node_modules/ahooks/es/useUnmount/index.es.js +0 -21
- package/dist/node_modules/.pnpm/ahooks@3.8.5_react@18.2.0/node_modules/ahooks/es/useUnmount/index.es.js.map +0 -1
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { j as jsxRuntimeExports } from "../../node_modules/.pnpm/react@18.2.0/node_modules/react/jsx-runtime.es.js";
|
|
2
|
-
import { useRef
|
|
2
|
+
import { useRef } from "react";
|
|
3
3
|
import useMemoizedFn from "../../node_modules/.pnpm/ahooks@3.8.5_react@18.2.0/node_modules/ahooks/es/useMemoizedFn/index.es.js";
|
|
4
|
-
import useMount from "../../node_modules/.pnpm/ahooks@3.8.5_react@18.2.0/node_modules/ahooks/es/useMount/index.es.js";
|
|
5
|
-
import useUnmount from "../../node_modules/.pnpm/ahooks@3.8.5_react@18.2.0/node_modules/ahooks/es/useUnmount/index.es.js";
|
|
6
4
|
import classNames from "../../node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.es.js";
|
|
5
|
+
import { useInitialized } from "../../hooks/use-initialized.es.js";
|
|
7
6
|
import { useWatchValue } from "../../hooks/use-watch-value/use-watch-value.es.js";
|
|
8
7
|
function EasyvMonacoEditor(props) {
|
|
9
|
-
var _a;
|
|
10
8
|
const {
|
|
11
9
|
className,
|
|
12
10
|
style,
|
|
@@ -15,7 +13,9 @@ function EasyvMonacoEditor(props) {
|
|
|
15
13
|
monacoEditorOptions,
|
|
16
14
|
globalVarType = "",
|
|
17
15
|
monacoSpace,
|
|
18
|
-
onChange
|
|
16
|
+
onChange,
|
|
17
|
+
onCodeMark,
|
|
18
|
+
onBlur
|
|
19
19
|
} = props;
|
|
20
20
|
const editorRef = useRef(null);
|
|
21
21
|
const editorInstanceRef = useRef();
|
|
@@ -41,7 +41,7 @@ function EasyvMonacoEditor(props) {
|
|
|
41
41
|
// 忽略特定错误
|
|
42
42
|
});
|
|
43
43
|
if (editorRef.current) {
|
|
44
|
-
|
|
44
|
+
editorInstanceRef.current = monacoSpace.editor.create(editorRef.current, {
|
|
45
45
|
value: code,
|
|
46
46
|
language: languageMode,
|
|
47
47
|
theme: "vs-dark",
|
|
@@ -52,71 +52,72 @@ function EasyvMonacoEditor(props) {
|
|
|
52
52
|
// 启用智能提示的关键设置
|
|
53
53
|
suggest: {
|
|
54
54
|
showKeywords: true,
|
|
55
|
+
// 关键字建议
|
|
55
56
|
showSnippets: true
|
|
57
|
+
// 代码片段建议
|
|
56
58
|
},
|
|
57
59
|
quickSuggestions: true,
|
|
60
|
+
// 在输入时自动显示建议列表
|
|
58
61
|
suggestOnTriggerCharacters: true,
|
|
62
|
+
// 当输入触发字符(如点号.)时自动显示建议
|
|
59
63
|
hover: { enabled: true },
|
|
60
64
|
// 必须启用 hover
|
|
61
65
|
renderValidationDecorations: "on"
|
|
62
66
|
// 确保错误渲染开启
|
|
63
67
|
});
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
"%c 🐱 cat ==== on did change model content:",
|
|
70
|
-
"color: orange; font-size: 16px;",
|
|
71
|
-
currentValue
|
|
72
|
-
);
|
|
68
|
+
if (!editorInstanceRef.current) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
editorInstanceRef.current.onDidChangeModelContent(() => {
|
|
72
|
+
const currentValue = editorInstanceRef.current.getValue();
|
|
73
73
|
onChange == null ? void 0 : onChange(currentValue);
|
|
74
74
|
});
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
console.log("当前错误 ==== :", markers);
|
|
79
|
-
});
|
|
80
|
-
console.log("disposable: ====", disposable);
|
|
81
|
-
monacoSpace.editor.onDidChangeMarkers(() => {
|
|
82
|
-
const markers = monacoSpace.editor.getModelMarkers({});
|
|
83
|
-
markers.forEach((m) => {
|
|
84
|
-
console.log("🔍 Marker:", m.message, m.severity);
|
|
75
|
+
monacoSpace.editor.onDidChangeMarkers(() => {
|
|
76
|
+
const markers = monacoSpace.editor.getModelMarkers({});
|
|
77
|
+
onCodeMark == null ? void 0 : onCodeMark(markers);
|
|
85
78
|
});
|
|
79
|
+
}
|
|
80
|
+
const disposable = editorInstanceRef.current.onDidBlurEditorText(() => {
|
|
81
|
+
const currentValue = editorInstanceRef.current.getValue();
|
|
82
|
+
onBlur == null ? void 0 : onBlur(currentValue);
|
|
86
83
|
});
|
|
84
|
+
return () => {
|
|
85
|
+
var _a;
|
|
86
|
+
disposable.dispose();
|
|
87
|
+
(_a = editorInstanceRef.current) == null ? void 0 : _a.dispose();
|
|
88
|
+
};
|
|
87
89
|
});
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
editorInstanceRef.current.setValue(code);
|
|
90
|
+
useInitialized(initFn);
|
|
91
|
+
useWatchValue({
|
|
92
|
+
value: code,
|
|
93
|
+
callback: () => {
|
|
94
|
+
if (editorInstanceRef.current) {
|
|
95
|
+
const currentValue = editorInstanceRef.current.getValue();
|
|
96
|
+
if (currentValue !== code) {
|
|
97
|
+
editorInstanceRef.current.setValue(code);
|
|
98
|
+
}
|
|
98
99
|
}
|
|
99
100
|
}
|
|
100
|
-
}
|
|
101
|
+
});
|
|
101
102
|
useWatchValue({
|
|
102
103
|
value: languageMode,
|
|
103
104
|
callback(newLanguage) {
|
|
104
|
-
var
|
|
105
|
-
const
|
|
106
|
-
if (!
|
|
105
|
+
var _a;
|
|
106
|
+
const model = (_a = editorInstanceRef.current) == null ? void 0 : _a.getModel();
|
|
107
|
+
if (!model) {
|
|
107
108
|
return;
|
|
108
109
|
}
|
|
109
|
-
monacoSpace.editor.setModelLanguage(
|
|
110
|
+
monacoSpace.editor.setModelLanguage(model, newLanguage);
|
|
110
111
|
}
|
|
111
112
|
});
|
|
112
113
|
useWatchValue({
|
|
113
114
|
value: monacoEditorOptions,
|
|
114
115
|
callback: () => {
|
|
115
|
-
var
|
|
116
|
+
var _a;
|
|
116
117
|
if (!monacoEditorOptions) {
|
|
117
118
|
return;
|
|
118
119
|
}
|
|
119
|
-
(
|
|
120
|
+
(_a = editorInstanceRef.current) == null ? void 0 : _a.updateOptions(monacoEditorOptions);
|
|
120
121
|
}
|
|
121
122
|
});
|
|
122
123
|
useWatchValue({
|
|
@@ -129,13 +130,11 @@ function EasyvMonacoEditor(props) {
|
|
|
129
130
|
globalVarType,
|
|
130
131
|
"global-data.d.ts"
|
|
131
132
|
);
|
|
133
|
+
},
|
|
134
|
+
options: {
|
|
135
|
+
immediate: true
|
|
132
136
|
}
|
|
133
137
|
});
|
|
134
|
-
const model = (_a = editorInstanceRef.current) == null ? void 0 : _a.getModel();
|
|
135
|
-
console.log("%c 🐶 dog ==== markers:", "color: green; font-size: 16px;", {
|
|
136
|
-
getModelMarkers: monacoSpace.editor.getModelMarkers({}),
|
|
137
|
-
modelId: model == null ? void 0 : model.getLanguageId()
|
|
138
|
-
});
|
|
139
138
|
return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { ref: editorRef, className: classNames("biz-min-h-[200px]", className), style });
|
|
140
139
|
}
|
|
141
140
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"easyv-monaco-editor.es.js","sources":["../../../src/components/easyv-monaco-editor/easyv-monaco-editor.tsx"],"sourcesContent":["import React, {
|
|
1
|
+
{"version":3,"file":"easyv-monaco-editor.es.js","sources":["../../../src/components/easyv-monaco-editor/easyv-monaco-editor.tsx"],"sourcesContent":["import React, { useRef } from 'react';\nimport { useMemoizedFn } from 'ahooks';\nimport classNames from 'classnames';\nimport type * as monaco from 'monaco-editor/esm/vs/editor/editor.api';\nimport { useInitialized, useWatchValue } from '@/hooks';\nimport { EasyvMonacoEditorProps } from './types';\n\nexport function EasyvMonacoEditor(props: EasyvMonacoEditorProps) {\n const {\n className,\n style,\n languageMode,\n code,\n monacoEditorOptions,\n globalVarType = '',\n monacoSpace,\n onChange,\n onCodeMark,\n onBlur,\n } = props;\n const editorRef = useRef<HTMLDivElement | null>(null);\n const editorInstanceRef = useRef<monaco.editor.IStandaloneCodeEditor>();\n const globalDataLibRef = useRef<monaco.IDisposable>();\n\n const initFn = useMemoizedFn(() => {\n // 配置 JavaScript 语言服务\n monacoSpace.languages.typescript.javascriptDefaults.setCompilerOptions({\n target: monacoSpace.languages.typescript.ScriptTarget.ESNext,\n allowNonTsExtensions: true,\n allowJs: true,\n checkJs: true, // 关键:启用 JS 校验\n noLib: false,\n lib: ['esnext', 'dom'], // dom 会带上浏览器里可使用的方法 如 console, window\n typeRoots: ['node_modules/@types'],\n });\n\n monacoSpace.languages.typescript.javascriptDefaults.setDiagnosticsOptions({\n noSemanticValidation: false, // 启用语义校验\n noSyntaxValidation: false, // 启用语法校验\n diagnosticCodesToIgnore: [], // 忽略特定错误\n });\n\n if (editorRef.current) {\n editorInstanceRef.current = monacoSpace.editor.create(editorRef.current, {\n value: code,\n language: languageMode,\n theme: 'vs-dark',\n automaticLayout: true,\n minimap: {\n enabled: false,\n },\n // 启用智能提示的关键设置\n suggest: {\n showKeywords: true, // 关键字建议\n showSnippets: true, // 代码片段建议\n },\n quickSuggestions: true, // 在输入时自动显示建议列表\n suggestOnTriggerCharacters: true, // 当输入触发字符(如点号.)时自动显示建议\n hover: { enabled: true }, // 必须启用 hover\n renderValidationDecorations: 'on', // 确保错误渲染开启\n });\n if (!editorInstanceRef.current) {\n return;\n }\n editorInstanceRef.current.onDidChangeModelContent(() => {\n const currentValue = editorInstanceRef.current!.getValue();\n // 更新状态\n onChange?.(currentValue);\n });\n\n // 监听诊断变化\n monacoSpace.editor.onDidChangeMarkers(() => {\n const markers = monacoSpace.editor.getModelMarkers({});\n onCodeMark?.(markers);\n });\n }\n // 添加失焦事件监听\n const disposable = editorInstanceRef.current!.onDidBlurEditorText(() => {\n const currentValue = editorInstanceRef.current!.getValue();\n onBlur?.(currentValue);\n });\n return () => {\n disposable.dispose();\n editorInstanceRef.current?.dispose();\n };\n });\n\n useInitialized(initFn);\n\n useWatchValue({\n value: code,\n callback: () => {\n if (editorInstanceRef.current) {\n // 获取当前编辑器的值\n const currentValue = editorInstanceRef.current.getValue();\n // 如果状态中的value和编辑器的当前值不同,则更新编辑器\n if (currentValue !== code) {\n editorInstanceRef.current.setValue(code);\n }\n }\n },\n });\n\n useWatchValue({\n value: languageMode,\n callback(newLanguage) {\n const model = editorInstanceRef.current?.getModel();\n if (!model) {\n return;\n }\n monacoSpace.editor.setModelLanguage(model, newLanguage);\n },\n });\n\n useWatchValue({\n value: monacoEditorOptions,\n callback: () => {\n if (!monacoEditorOptions) {\n return;\n }\n editorInstanceRef.current?.updateOptions(monacoEditorOptions);\n },\n });\n\n useWatchValue({\n value: globalVarType,\n callback() {\n if (globalDataLibRef.current) {\n globalDataLibRef.current.dispose();\n }\n globalDataLibRef.current = monacoSpace.languages.typescript.javascriptDefaults.addExtraLib(\n globalVarType,\n 'global-data.d.ts',\n );\n },\n options: {\n immediate: true,\n },\n });\n\n return (\n <div ref={editorRef} className={classNames('biz-min-h-[200px]', className)} style={style} />\n );\n}\n"],"names":["jsx"],"mappings":"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"}
|
|
@@ -32,6 +32,7 @@ export interface EasyvMonacoEditorProps {
|
|
|
32
32
|
* 传入你从 monaco-editor 导入的 monaco。
|
|
33
33
|
* - vite 项目中的 按需导入可以参见如下方式, webpack 项目注意 worker 的导入方式和处理方式:
|
|
34
34
|
* ```ts
|
|
35
|
+
* // vite 项目
|
|
35
36
|
import type * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
|
|
36
37
|
import 'monaco-editor/esm/vs/editor/editor.all.js';
|
|
37
38
|
import 'monaco-editor/esm/vs/language/json/monaco.contribution';
|
|
@@ -55,6 +56,19 @@ export interface EasyvMonacoEditorProps {
|
|
|
55
56
|
},
|
|
56
57
|
};
|
|
57
58
|
```
|
|
59
|
+
- webpack 项目中,推荐使用 monaco-editor-webpack-plugin
|
|
60
|
+
```ts
|
|
61
|
+
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
|
|
62
|
+
|
|
63
|
+
plugins: [
|
|
64
|
+
new MonacoWebpackPlugin({
|
|
65
|
+
languages: ['json', 'javascript', 'typescript'],
|
|
66
|
+
}),
|
|
67
|
+
],
|
|
68
|
+
```
|
|
58
69
|
*/
|
|
59
70
|
monacoSpace: typeof monaco;
|
|
71
|
+
/** monaco 对代码检查时的错误或者警告等等。 */
|
|
72
|
+
onCodeMark?: (errors: monaco.editor.IMarker[]) => void;
|
|
73
|
+
onBlur?: (code: string) => void;
|
|
60
74
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
type FunctionType = () => void;
|
|
1
2
|
/** 传入的函数只会初始化运行一次
|
|
2
|
-
* @param fn
|
|
3
|
+
* @param fn 初始化函数, fn 返回的如果是一个函数,会在卸载时运行。
|
|
3
4
|
* @returns initialized 是否初始化,boolean 值是一个 react state,会触发重新渲染
|
|
4
5
|
*/
|
|
5
|
-
export declare function useInitialized(fn: () => void
|
|
6
|
+
export declare function useInitialized(fn: () => void | FunctionType): boolean;
|
|
7
|
+
export {};
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import { useState, useRef, useEffect } from "react";
|
|
2
|
-
function useInitialized(fn
|
|
2
|
+
function useInitialized(fn) {
|
|
3
3
|
const [initialized, setInitialized] = useState(false);
|
|
4
4
|
const initializedRef = useRef(false);
|
|
5
5
|
const updateFnRef = useRef(fn);
|
|
6
|
-
const cleanFnRef = useRef(
|
|
6
|
+
const cleanFnRef = useRef();
|
|
7
7
|
updateFnRef.current = fn;
|
|
8
|
-
cleanFnRef.current = cleanFn;
|
|
9
8
|
useEffect(() => {
|
|
10
9
|
if (!initializedRef.current) {
|
|
11
|
-
updateFnRef.current();
|
|
10
|
+
cleanFnRef.current = updateFnRef.current();
|
|
12
11
|
setInitialized(true);
|
|
13
12
|
initializedRef.current = true;
|
|
14
13
|
}
|
|
15
14
|
return () => {
|
|
16
|
-
if (cleanFnRef.current) {
|
|
15
|
+
if (typeof cleanFnRef.current === "function") {
|
|
17
16
|
cleanFnRef.current();
|
|
18
17
|
}
|
|
19
18
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-initialized.es.js","sources":["../../src/hooks/use-initialized.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\n/** 传入的函数只会初始化运行一次\n * @param fn
|
|
1
|
+
{"version":3,"file":"use-initialized.es.js","sources":["../../src/hooks/use-initialized.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\ntype FunctionType = () => void;\n/** 传入的函数只会初始化运行一次\n * @param fn 初始化函数, fn 返回的如果是一个函数,会在卸载时运行。\n * @returns initialized 是否初始化,boolean 值是一个 react state,会触发重新渲染\n */\nexport function useInitialized(fn: () => void | FunctionType) {\n const [initialized, setInitialized] = useState(false);\n const initializedRef = useRef(false);\n const updateFnRef = useRef(fn);\n const cleanFnRef = useRef<FunctionType | void>();\n updateFnRef.current = fn;\n\n useEffect(() => {\n if (!initializedRef.current) {\n cleanFnRef.current = updateFnRef.current();\n setInitialized(true);\n initializedRef.current = true;\n }\n return () => {\n if (typeof cleanFnRef.current === 'function') {\n cleanFnRef.current();\n }\n };\n }, []);\n\n return initialized;\n}\n"],"names":[],"mappings":";AAOO,SAAS,eAAe,IAA+B;AAC5D,QAAM,CAAC,aAAa,cAAc,IAAI,SAAS,KAAK;AAC9C,QAAA,iBAAiB,OAAO,KAAK;AAC7B,QAAA,cAAc,OAAO,EAAE;AAC7B,QAAM,aAAa,OAA4B;AAC/C,cAAY,UAAU;AAEtB,YAAU,MAAM;AACV,QAAA,CAAC,eAAe,SAAS;AAChB,iBAAA,UAAU,YAAY,QAAQ;AACzC,qBAAe,IAAI;AACnB,qBAAe,UAAU;AAAA,IAAA;AAE3B,WAAO,MAAM;AACP,UAAA,OAAO,WAAW,YAAY,YAAY;AAC5C,mBAAW,QAAQ;AAAA,MAAA;AAAA,IAEvB;AAAA,EACF,GAAG,EAAE;AAEE,SAAA;AACT;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getDefaultExportFromCjs } from "../../../../../_virtual/_commonjsHelpers.es.js";
|
|
2
|
-
import { __module as classnames$1 } from "../../../../../_virtual/index.
|
|
2
|
+
import { __module as classnames$1 } from "../../../../../_virtual/index.es3.js";
|
|
3
3
|
/*!
|
|
4
4
|
Copyright (c) 2018 Jed Watson.
|
|
5
5
|
Licensed under the MIT License (MIT), see
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getDefaultExportFromCjs } from "../../../../../_virtual/_commonjsHelpers.es.js";
|
|
2
|
-
import { __module as coWebWorker } from "../../../../../_virtual/index.
|
|
2
|
+
import { __module as coWebWorker } from "../../../../../_virtual/index.es4.js";
|
|
3
3
|
class CrossOriginWorker extends Worker {
|
|
4
4
|
constructor(scriptUrl) {
|
|
5
5
|
const b = new Blob([`importScripts('${new URL(scriptUrl).toString()}')`], { type: "application/javascript" });
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getDefaultExportFromCjs } from "../../../../../_virtual/_commonjsHelpers.es.js";
|
|
2
|
-
import { __module as propTypes } from "../../../../../_virtual/index.
|
|
2
|
+
import { __module as propTypes } from "../../../../../_virtual/index.es2.js";
|
|
3
3
|
import { __require as requireReactIs } from "../../../react-is@16.13.1/node_modules/react-is/index.es.js";
|
|
4
4
|
import { __require as requireFactoryWithTypeCheckers } from "./factoryWithTypeCheckers.es.js";
|
|
5
5
|
import { __require as requireFactoryWithThrowingShims } from "./factoryWithThrowingShims.es.js";
|