@wandelbots/wandelbots-js-react-components 1.13.0 → 1.13.1
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/components/LoadingButton.d.ts +1 -1
- package/dist/components/wandelscript-editor/WandelscriptEditor.d.ts +2 -2
- package/dist/components/wandelscript-editor/WandelscriptEditor.d.ts.map +1 -1
- package/dist/index.cjs +25 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +13684 -13681
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/wandelscript-editor/WandelscriptEditor.tsx +28 -29
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import type { Monaco } from "@monaco-editor/react"
|
|
2
|
+
import { lazy, Suspense, useRef, useState } from "react"
|
|
3
3
|
import type { BundledLanguage, HighlighterGeneric } from "shiki"
|
|
4
|
-
import {
|
|
5
|
-
import { shikiToMonaco } from "@shikijs/monaco"
|
|
4
|
+
import type { BundledTheme } from "shiki"
|
|
6
5
|
|
|
7
6
|
import wandelscriptTextmateGrammar from "./wandelscript.tmLanguage"
|
|
8
7
|
import { useTheme } from "@mui/material"
|
|
9
8
|
import type { editor } from "monaco-editor"
|
|
10
9
|
import { externalizeComponent } from "../../externalizeComponent"
|
|
10
|
+
import { LoadingCover } from "../LoadingCover"
|
|
11
11
|
|
|
12
12
|
type WandelscriptEditorProps = {
|
|
13
13
|
/** The current Wandelscript content of the code editor (controlled component) */
|
|
@@ -26,20 +26,24 @@ type WandelscriptEditorProps = {
|
|
|
26
26
|
/** A Monaco (VSCode-style) embedded code editor with Wandelscript syntax highlighting */
|
|
27
27
|
export const WandelscriptEditor = externalizeComponent(
|
|
28
28
|
(props: WandelscriptEditorProps) => {
|
|
29
|
-
const monaco = useMonaco()
|
|
30
29
|
const theme = useTheme()
|
|
31
30
|
const shikiHighlighterRef = useRef<HighlighterGeneric<
|
|
32
31
|
BundledLanguage,
|
|
33
32
|
BundledTheme
|
|
34
33
|
> | null>(null)
|
|
35
|
-
|
|
36
34
|
const [activeShikiTheme, setActiveShikiTheme] =
|
|
37
35
|
useState<BundledTheme>("dark-plus")
|
|
38
|
-
|
|
39
36
|
const targetShikiTheme =
|
|
40
37
|
theme.palette.mode === "dark" ? "dark-plus" : "light-plus"
|
|
41
38
|
|
|
39
|
+
const Editor = lazy(() => import("@monaco-editor/react"))
|
|
40
|
+
|
|
42
41
|
async function setupEditor(monaco: Monaco) {
|
|
42
|
+
const [{ createHighlighter }, { shikiToMonaco }] = await Promise.all([
|
|
43
|
+
import("shiki"),
|
|
44
|
+
import("@shikijs/monaco"),
|
|
45
|
+
])
|
|
46
|
+
|
|
43
47
|
// Register and configure the Wandelscript language
|
|
44
48
|
monaco.languages.register({ id: "wandelscript" })
|
|
45
49
|
|
|
@@ -99,29 +103,24 @@ export const WandelscriptEditor = externalizeComponent(
|
|
|
99
103
|
setActiveShikiTheme(targetShikiTheme)
|
|
100
104
|
}
|
|
101
105
|
|
|
102
|
-
useEffect(() => {
|
|
103
|
-
if (monaco) {
|
|
104
|
-
setupEditor(monaco)
|
|
105
|
-
}
|
|
106
|
-
}, [monaco, targetShikiTheme])
|
|
107
|
-
|
|
108
|
-
if (!monaco) {
|
|
109
|
-
return null
|
|
110
|
-
}
|
|
111
|
-
|
|
112
106
|
return (
|
|
113
|
-
<
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
107
|
+
<Suspense fallback={<LoadingCover />}>
|
|
108
|
+
<Editor
|
|
109
|
+
value={props.code}
|
|
110
|
+
onMount={(_editor, monaco) => {
|
|
111
|
+
setupEditor(monaco)
|
|
112
|
+
}}
|
|
113
|
+
onChange={props.onChange}
|
|
114
|
+
defaultLanguage="wandelscript"
|
|
115
|
+
theme={activeShikiTheme}
|
|
116
|
+
options={{
|
|
117
|
+
minimap: { enabled: false },
|
|
118
|
+
wordWrap: "on",
|
|
119
|
+
automaticLayout: true,
|
|
120
|
+
...props.monacoOptions,
|
|
121
|
+
}}
|
|
122
|
+
/>
|
|
123
|
+
</Suspense>
|
|
125
124
|
)
|
|
126
125
|
},
|
|
127
126
|
)
|