@wandelbots/wandelbots-js-react-components 1.51.1 → 1.51.2
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/wandelscript-editor/WandelscriptEditor.d.ts.map +1 -1
- package/dist/index.cjs +23 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1669 -1656
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/wandelscript-editor/WandelscriptEditor.tsx +35 -21
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Monaco } from "@monaco-editor/react"
|
|
2
|
-
import { lazy, Suspense,
|
|
2
|
+
import { lazy, Suspense, useState } from "react"
|
|
3
3
|
import type { BundledLanguage, BundledTheme, HighlighterGeneric } from "shiki"
|
|
4
4
|
|
|
5
5
|
import { useTheme } from "@mui/material"
|
|
@@ -24,25 +24,47 @@ type WandelscriptEditorProps = {
|
|
|
24
24
|
|
|
25
25
|
const Editor = lazy(() => import("@monaco-editor/react"))
|
|
26
26
|
|
|
27
|
+
let preparedShiki: {
|
|
28
|
+
shiki: HighlighterGeneric<BundledLanguage, BundledTheme>
|
|
29
|
+
shikiToMonaco: (
|
|
30
|
+
shiki: HighlighterGeneric<BundledLanguage, BundledTheme>,
|
|
31
|
+
monaco: Monaco,
|
|
32
|
+
) => void
|
|
33
|
+
} | null = null
|
|
34
|
+
|
|
35
|
+
async function getShiki() {
|
|
36
|
+
if (!preparedShiki) {
|
|
37
|
+
const [{ createHighlighter }, { shikiToMonaco }] = await Promise.all([
|
|
38
|
+
import("shiki"),
|
|
39
|
+
import("@shikijs/monaco"),
|
|
40
|
+
])
|
|
41
|
+
|
|
42
|
+
const shiki = await createHighlighter({
|
|
43
|
+
// Our textmate grammar doesn't quite conform to the expected type
|
|
44
|
+
// here; I'm not sure what the missing properties mean exactly
|
|
45
|
+
langs: [wandelscriptTextmateGrammar as any],
|
|
46
|
+
themes: ["dark-plus", "light-plus"],
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
preparedShiki = {
|
|
50
|
+
shiki,
|
|
51
|
+
shikiToMonaco,
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return preparedShiki
|
|
56
|
+
}
|
|
57
|
+
|
|
27
58
|
/** A Monaco (VSCode-style) embedded code editor with Wandelscript syntax highlighting */
|
|
28
59
|
export const WandelscriptEditor = externalizeComponent(
|
|
29
60
|
(props: WandelscriptEditorProps) => {
|
|
30
61
|
const theme = useTheme()
|
|
31
|
-
const shikiHighlighterRef = useRef<HighlighterGeneric<
|
|
32
|
-
BundledLanguage,
|
|
33
|
-
BundledTheme
|
|
34
|
-
> | null>(null)
|
|
35
62
|
const [activeShikiTheme, setActiveShikiTheme] =
|
|
36
63
|
useState<BundledTheme>("dark-plus")
|
|
37
64
|
const targetShikiTheme =
|
|
38
65
|
theme.palette.mode === "dark" ? "dark-plus" : "light-plus"
|
|
39
66
|
|
|
40
67
|
async function setupEditor(monaco: Monaco) {
|
|
41
|
-
const [{ createHighlighter }, { shikiToMonaco }] = await Promise.all([
|
|
42
|
-
import("shiki"),
|
|
43
|
-
import("@shikijs/monaco"),
|
|
44
|
-
])
|
|
45
|
-
|
|
46
68
|
// Register and configure the Wandelscript language
|
|
47
69
|
monaco.languages.register({ id: "wandelscript" })
|
|
48
70
|
|
|
@@ -64,19 +86,11 @@ export const WandelscriptEditor = externalizeComponent(
|
|
|
64
86
|
],
|
|
65
87
|
})
|
|
66
88
|
|
|
89
|
+
const { shiki, shikiToMonaco } = await getShiki()
|
|
90
|
+
|
|
67
91
|
// Monaco doesn't support TextMate grammar config directly, so we
|
|
68
92
|
// use Shiki as an intermediary
|
|
69
|
-
|
|
70
|
-
if (!shikiHighlighterRef.current) {
|
|
71
|
-
shikiHighlighterRef.current = await createHighlighter({
|
|
72
|
-
// Our textmate grammar doesn't quite conform to the expected type
|
|
73
|
-
// here; I'm not sure what the missing properties mean exactly
|
|
74
|
-
langs: [wandelscriptTextmateGrammar as any],
|
|
75
|
-
themes: ["dark-plus", "light-plus"],
|
|
76
|
-
})
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
shikiToMonaco(shikiHighlighterRef.current, monaco)
|
|
93
|
+
shikiToMonaco(shiki, monaco)
|
|
80
94
|
|
|
81
95
|
// Override the generated shiki theme to use shiki syntax highlighting
|
|
82
96
|
// but vscode colors
|