|
@@ -30,6 +30,7 @@ import {
|
|
} from "./SettingsModel";
|
|
} from "./SettingsModel";
|
|
import { BisectModel } from "./BisectModel";
|
|
import { BisectModel } from "./BisectModel";
|
|
import { LocationModel } from "./LocationModel";
|
|
import { LocationModel } from "./LocationModel";
|
|
|
|
+import { createJsonWebEditorClient, vObj, vString } from "@vscode/web-editors";
|
|
|
|
|
|
export class PlaygroundModel {
|
|
export class PlaygroundModel {
|
|
public readonly dispose = Disposable.fn();
|
|
public readonly dispose = Disposable.fn();
|
|
@@ -47,7 +48,25 @@ export class PlaygroundModel {
|
|
@observable
|
|
@observable
|
|
public reloadKey = 0;
|
|
public reloadKey = 0;
|
|
|
|
|
|
- public readonly historyModel = new LocationModel(this);
|
|
|
|
|
|
+ private readonly webEditorClient = createJsonWebEditorClient(
|
|
|
|
+ vObj({
|
|
|
|
+ js: vString(),
|
|
|
|
+ html: vString(),
|
|
|
|
+ css: vString(),
|
|
|
|
+ }),
|
|
|
|
+ (data) => {
|
|
|
|
+ runInAction(() => {
|
|
|
|
+ this.html = data.html;
|
|
|
|
+ this.js = data.js;
|
|
|
|
+ this.css = data.css;
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ public readonly historyModel = new LocationModel(
|
|
|
|
+ this,
|
|
|
|
+ this.webEditorClient === undefined
|
|
|
|
+ );
|
|
|
|
|
|
public reload(): void {
|
|
public reload(): void {
|
|
this.reloadKey++;
|
|
this.reloadKey++;
|
|
@@ -163,6 +182,17 @@ export class PlaygroundModel {
|
|
constructor() {
|
|
constructor() {
|
|
let lastState: IPreviewState | undefined = undefined;
|
|
let lastState: IPreviewState | undefined = undefined;
|
|
|
|
|
|
|
|
+ this.webEditorClient?.onDidConnect.then(() => {
|
|
|
|
+ autorun(() => {
|
|
|
|
+ const state = this.playgroundProject;
|
|
|
|
+ this.webEditorClient!.updateContent({
|
|
|
|
+ js: state.js,
|
|
|
|
+ html: state.html,
|
|
|
|
+ css: state.css,
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+
|
|
this.dispose.track({
|
|
this.dispose.track({
|
|
dispose: reaction(
|
|
dispose: reaction(
|
|
() => ({ state: this.state }),
|
|
() => ({ state: this.state }),
|