access to monaco functions in WebviewEditor

This commit is contained in:
2021-10-28 19:41:42 -04:00
parent 1bfe218e35
commit 7ae6991fd7
6 changed files with 89 additions and 8 deletions

View File

@@ -1,4 +1,5 @@
bin
*.vsix
_activeConfig/
_lastActiveConfig/
_lastActiveConfig/
node_modules/

30
projects/kiss-vscode/package-lock.json generated Normal file
View File

@@ -0,0 +1,30 @@
{
"name": "kiss-vscode",
"version": "0.0.18",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "kiss-vscode",
"version": "0.0.18",
"dependencies": {
"monaco-editor": "^0.29.1"
},
"engines": {
"vscode": "^1.4.0"
}
},
"node_modules/monaco-editor": {
"version": "0.29.1",
"resolved": "https://registry.npmjs.org/monaco-editor/-/monaco-editor-0.29.1.tgz",
"integrity": "sha512-rguaEG/zrPQSaKzQB7IfX/PpNa0qxF1FY8ZXRkN4WIl8qZdTQRSRJCtRto7IMcSgrU6H53RXI+fTcywOBC4aVw=="
}
},
"dependencies": {
"monaco-editor": {
"version": "0.29.1",
"resolved": "https://registry.npmjs.org/monaco-editor/-/monaco-editor-0.29.1.tgz",
"integrity": "sha512-rguaEG/zrPQSaKzQB7IfX/PpNa0qxF1FY8ZXRkN4WIl8qZdTQRSRJCtRto7IMcSgrU6H53RXI+fTcywOBC4aVw=="
}
}
}

View File

@@ -96,5 +96,8 @@
"onCommand:kiss.runKeyboardShortcut",
"onCommand:kiss.reloadConfig"
],
"displayName": "kiss-vscode"
"displayName": "kiss-vscode",
"dependencies": {
"monaco-editor": "^0.29.1"
}
}

View File

@@ -10,8 +10,14 @@
(function :Void updateKissVscode [&opt _]
(trySpawnSync "haxe" ["build.hxml"] (options) handleUpdateFailure)
(if (= "Windows" (Sys.systemName))
(trySpawnSync "cmd.exe" ["/c" "vsce" "package"] (options) handleUpdateFailure)
(trySpawnSync "vsce" ["package"] (options) handleUpdateFailure))
{
(trySpawnSync "cmd.exe" ["/c" "npm" "install"] (options) handleUpdateFailure)
(trySpawnSync "cmd.exe" ["/c" "vsce" "package"] (options) handleUpdateFailure)
}
{
(trySpawnSync "npm" ["install"] (options) handleUpdateFailure)
(trySpawnSync "vsce" ["package"] (options) handleUpdateFailure)
})
(awaitLet [_ (executeCommand
"workbench.extensions.command.installFromVSIX"
(Uri.file (joinPath (kvLibpath) (last (filter (FileSystem.readDirectory (kvLibpath)) ->file (file.endsWith ".vsix"))))))]

View File

@@ -4,6 +4,9 @@
(var &mut :Element content)
(var &mut :Array<KTxt2Element> ktxt2Elements)
// Free-wheeling without externs for now:
(var &mut :Dynamic monaco)
(function main []
(set vscode (EditorExterns.acquireVsCodeApi))
(set window EditorExterns.window)

View File

@@ -64,13 +64,29 @@
null)
(method :String htmlForWebview [:Webview webview]
(let [scriptUri
(webview.asWebviewUri (Uri.joinPath (Uri.parse this.context.extensionUri) "bin" "ktxt2editor.js"))]
"<!DOCTYPE html>
(let [monacoDir
(Uri.joinPath (Uri.parse this.context.extensionUri) "node_modules" "monaco-editor" "min" "vs")
requireConfigDir
(webview.asWebviewUri monacoDir)
cssUri
(webview.asWebviewUri (Uri.joinPath monacoDir "editor" "editor.main.css"))
monacoLoaderUri
(webview.asWebviewUri (Uri.joinPath monacoDir "loader.js"))
monacoEditorNlsUri
(webview.asWebviewUri (Uri.joinPath monacoDir "editor" "editor.main.nls.js"))
monacoEditorUri
(webview.asWebviewUri (Uri.joinPath monacoDir "editor" "editor.main.js"))
scriptContent
(File.getContent .fsPath (Uri.joinPath (Uri.parse this.context.extensionUri) "bin" "ktxt2editor.js"))]
~"<!DOCTYPE html>
<html>
<head>
<meta charset=\"UTF-8\">
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">
<link
rel=\"stylesheet\"
data-name=\"vs/editor/editor.main\"
href=\"${cssUri}\" />
<title>KTxt2</title>
<style>
.block {
@@ -81,7 +97,29 @@
</style>
</head>
<body>
<script src=\"${scriptUri}\"></script>
<div id=\"container\" style=\"width:800px;height:200px;border:1px solid grey\"></div>
<script>
var require = { paths: { vs: \"${requireConfigDir}\" } };
</script>
<script src=\"${monacoLoaderUri}\"></script>
<script src=\"${monacoEditorNlsUri}\"></script>
<script src=\"${monacoEditorUri}\"></script>
<script>
var p = document.createElement(\"p\");
p.innerHTML = \"shtuff\";
document.body.appendChild(p);
</script>
<script>
var p = document.createElement(\"p\");
p.innerHTML = \"shtuff\";
document.body.appendChild(p);
if (monaco !== undefined) {
var p = document.createElement(\"p\");
p.innerHTML = \"shtuff\";
document.body.appendChild(p);
}
</script>
</body>
</html>"))