@codespark/react 1.0.6 → 1.0.8
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/codemirror.d.ts +6249 -3
- package/dist/codemirror.js +6 -5
- package/dist/index.d.ts +6269 -11
- package/dist/index.js +248 -59
- package/dist/monaco.d.ts +6250 -4
- package/dist/monaco.js +23 -22
- package/package.json +3 -3
package/dist/monaco.js
CHANGED
|
@@ -5,15 +5,16 @@ import prettier from "prettier/standalone";
|
|
|
5
5
|
import { memo, useEffect, useRef, useState } from "react";
|
|
6
6
|
import { createHighlighterCore } from "shiki/core";
|
|
7
7
|
import { createJavaScriptRegexEngine } from "shiki/engine/javascript";
|
|
8
|
+
import "@codespark/framework";
|
|
8
9
|
import { clsx } from "clsx";
|
|
9
10
|
import { twMerge } from "tailwind-merge";
|
|
10
11
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
11
12
|
|
|
12
13
|
//#region src/lib/editor-adapter/index.ts
|
|
13
|
-
let EditorEngine = /* @__PURE__ */ function(EditorEngine
|
|
14
|
-
EditorEngine
|
|
15
|
-
EditorEngine
|
|
16
|
-
return EditorEngine
|
|
14
|
+
let EditorEngine = /* @__PURE__ */ function(EditorEngine) {
|
|
15
|
+
EditorEngine[EditorEngine["Monaco"] = 0] = "Monaco";
|
|
16
|
+
EditorEngine[EditorEngine["CodeMirror"] = 1] = "CodeMirror";
|
|
17
|
+
return EditorEngine;
|
|
17
18
|
}({});
|
|
18
19
|
|
|
19
20
|
//#endregion
|
|
@@ -138,16 +139,16 @@ const setupOnce = async () => {
|
|
|
138
139
|
},
|
|
139
140
|
engine: createJavaScriptRegexEngine()
|
|
140
141
|
})]);
|
|
141
|
-
return mod.loader.init().then((Monaco
|
|
142
|
-
Monaco
|
|
143
|
-
Monaco
|
|
144
|
-
shikiToMonaco(highlighter, Monaco
|
|
145
|
-
Monaco
|
|
146
|
-
Monaco
|
|
142
|
+
return mod.loader.init().then((Monaco) => {
|
|
143
|
+
Monaco.languages.register({ id: "tsx" });
|
|
144
|
+
Monaco.languages.register({ id: "jsx" });
|
|
145
|
+
shikiToMonaco(highlighter, Monaco);
|
|
146
|
+
Monaco.typescript.typescriptDefaults.setEagerModelSync(true);
|
|
147
|
+
Monaco.typescript.typescriptDefaults.setDiagnosticsOptions({
|
|
147
148
|
noSemanticValidation: false,
|
|
148
149
|
noSyntaxValidation: false
|
|
149
150
|
});
|
|
150
|
-
Monaco
|
|
151
|
+
Monaco.typescript.typescriptDefaults.setCompilerOptions({
|
|
151
152
|
strict: true,
|
|
152
153
|
noImplicitAny: false,
|
|
153
154
|
noUnusedLocals: false,
|
|
@@ -155,16 +156,16 @@ const setupOnce = async () => {
|
|
|
155
156
|
allowUnreachableCode: true,
|
|
156
157
|
allowUnusedLabels: true,
|
|
157
158
|
allowImportingTsExtensions: true,
|
|
158
|
-
target: Monaco
|
|
159
|
+
target: Monaco.typescript.ScriptTarget.ESNext,
|
|
159
160
|
allowNonTsExtensions: true,
|
|
160
|
-
moduleResolution: Monaco
|
|
161
|
-
module: Monaco
|
|
161
|
+
moduleResolution: Monaco.typescript.ModuleResolutionKind.NodeJs,
|
|
162
|
+
module: Monaco.typescript.ModuleKind.ESNext,
|
|
162
163
|
noEmit: true,
|
|
163
|
-
jsx: Monaco
|
|
164
|
+
jsx: Monaco.typescript.JsxEmit.ReactJSX,
|
|
164
165
|
jsxImportSource: "react",
|
|
165
166
|
esModuleInterop: true
|
|
166
167
|
});
|
|
167
|
-
Monaco
|
|
168
|
+
Monaco.languages.registerDocumentFormattingEditProvider("typescript", { async provideDocumentFormattingEdits(model, options) {
|
|
168
169
|
const text = model.getValue();
|
|
169
170
|
const formatted = await prettier.format(text, {
|
|
170
171
|
parser: "typescript",
|
|
@@ -217,7 +218,7 @@ const MONACO_DEFAULT_OPTIONS = {
|
|
|
217
218
|
};
|
|
218
219
|
const Monaco = {
|
|
219
220
|
kind: EditorEngine.Monaco,
|
|
220
|
-
Component: memo(function Monaco
|
|
221
|
+
Component: memo(function Monaco(props) {
|
|
221
222
|
const { value = "", options = {}, onChange, onMount, width, height, id, language, files, imports, ...rest } = props;
|
|
222
223
|
const editorInstance = useRef(null);
|
|
223
224
|
const [monacoInstance, setMonacoInstance] = useState(null);
|
|
@@ -231,8 +232,8 @@ const Monaco = {
|
|
|
231
232
|
editorInstance.current = editor;
|
|
232
233
|
setMonacoInstance(monaco);
|
|
233
234
|
};
|
|
234
|
-
const handleEditorContentChange = (value
|
|
235
|
-
onChange?.(value
|
|
235
|
+
const handleEditorContentChange = (value, evt) => {
|
|
236
|
+
onChange?.(value, evt);
|
|
236
237
|
};
|
|
237
238
|
const addExtraLib = (dts = {}) => {
|
|
238
239
|
Object.entries(dts).forEach(([module, content]) => {
|
|
@@ -249,9 +250,9 @@ const Monaco = {
|
|
|
249
250
|
addedLibs.add(module);
|
|
250
251
|
});
|
|
251
252
|
};
|
|
252
|
-
const createModels = (files
|
|
253
|
+
const createModels = (files = {}) => {
|
|
253
254
|
const prefix = `file:///${id}/`;
|
|
254
|
-
const filePaths = new Set(Object.keys(files
|
|
255
|
+
const filePaths = new Set(Object.keys(files).map((p) => p.replace(/^(\.\.?\/)+/, "")));
|
|
255
256
|
monacoInstance.editor.getModels().forEach((model) => {
|
|
256
257
|
const uriStr = model.uri.toString();
|
|
257
258
|
if (uriStr.startsWith(prefix)) {
|
|
@@ -259,7 +260,7 @@ const Monaco = {
|
|
|
259
260
|
if (!filePaths.has(modelPath)) model.dispose();
|
|
260
261
|
}
|
|
261
262
|
});
|
|
262
|
-
Object.entries(files
|
|
263
|
+
Object.entries(files).forEach(([filePath, code]) => {
|
|
263
264
|
const normalizedPath = filePath.replace(/^(\.\.?\/)+/, "");
|
|
264
265
|
const uri = monacoInstance.Uri.parse(`${prefix}${normalizedPath}`);
|
|
265
266
|
if (!monacoInstance.editor.getModel(uri)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codespark/react",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "React components for codespark ecosystem",
|
|
6
6
|
"keywords": [
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"@codemirror/lang-javascript": "^6.2.4",
|
|
43
43
|
"@codemirror/lang-markdown": "^6.5.0",
|
|
44
44
|
"@codemirror/language-data": "^6.5.2",
|
|
45
|
-
"@codespark/framework": "^1.0.
|
|
45
|
+
"@codespark/framework": "^1.0.3",
|
|
46
46
|
"@monaco-editor/react": "^4.7.0",
|
|
47
47
|
"@shikijs/monaco": "^3.20.0",
|
|
48
48
|
"@uiw/react-codemirror": "^4.25.4",
|
|
@@ -67,6 +67,6 @@
|
|
|
67
67
|
"@types/react-is": "^19.2.0",
|
|
68
68
|
"monaco-editor": "^0.55.1",
|
|
69
69
|
"rollup-plugin-import-raw": "^1.0.2",
|
|
70
|
-
"tsdown": "^0.
|
|
70
|
+
"tsdown": "^0.20.3"
|
|
71
71
|
}
|
|
72
72
|
}
|