implement quickWebview function for Kiss-VSCode use

This commit is contained in:
2022-03-24 13:29:55 -06:00
parent 1073ae618a
commit 8ae016b816
3 changed files with 22 additions and 4 deletions

View File

@@ -16,12 +16,18 @@ import ktxt2.KTxt2;
import re_flex.R;
import kiss_tools.KeyShortcutHandler;
import JSDomExterns;
import haxe.Constraints;
import js.html.Document;
import js.node.Timers;
using haxe.io.Path;
using StringTools;
typedef Command = (String) -> Void;
typedef QuickWebviewSetup = (Document) -> Void;
typedef QuickWebviewUpdate = (Document, Float, Function) -> Void;
@:expose
@:build(kiss.Kiss.buildAll(["KissConfig.kiss", "Config.kiss"]))
class KissConfig {}

View File

@@ -255,7 +255,19 @@
(function registerConversion [:KTxt2Conversion conversion] (conversions.push conversion)))
(function quickWebview []
(let [dom (new JSDOM "<!DOCTYPE html><p>Hello world</p>")
// TODO provide for passing messages between webview and VSCode API
(function :WebviewPanel quickWebview [:String title :QuickWebviewSetup setup :QuickWebviewUpdate update &opt :ViewColumn column :Int fps]
(let [dom (new JSDOM "<!DOCTYPE html><html><head><title>${title}</title></head><body></body></html>")
document dom.window.document]
document))
(setup document)
(let [panel (Vscode.window.createWebviewPanel "kissVscodeQuickWebview" title (or column ViewColumn.Beside) (object))]
(set panel.webview.html document.documentElement.innerHTML)
// TODO setInterval of the update function and allow for stopping it by disposing the panel or calling a close function passed to update
(let [&mut :Function close null
deltaMilli (/ 1000.0 (or fps 30))
deltaSec (/ deltaMilli 1000)
interval (Timers.setInterval ->{(update document deltaSec close) (set panel.webview.html document.documentElement.innerHTML)}deltaMilli)]
(panel.onDidDispose ->e (Timers.clearInterval interval))
(set close ->(panel.dispose)))
panel)))

View File

@@ -4,7 +4,7 @@ typedef JSDOMWindow = {
document:Document
};
@:jsRequire("jsdom")
@:jsRequire("jsdom", "JSDOM")
extern class JSDOM {
function new(html:String);
var window:JSDOMWindow;