From 88ab65b162d5db21fa50141739087c575ee06a71 Mon Sep 17 00:00:00 2001 From: _Kerman Date: Wed, 22 Nov 2023 23:31:42 +0800 Subject: [PATCH] upd: move `toOutput` into `Project` class --- packages/northstar/src/project/project.ts | 22 +++++++++++++++++++++ packages/northstar/src/utils/toOutput.ts | 24 +---------------------- packages/northstar/src/views/preview.r.ts | 6 +++--- packages/northstar/src/views/toolbar.r.ts | 3 +-- 4 files changed, 27 insertions(+), 28 deletions(-) diff --git a/packages/northstar/src/project/project.ts b/packages/northstar/src/project/project.ts index b86a6da..a06537b 100644 --- a/packages/northstar/src/project/project.ts +++ b/packages/northstar/src/project/project.ts @@ -1,4 +1,7 @@ +import { ViewOutput } from "@quasi-dev/compiler"; import { Graph, exportVf, importVf } from "@quasi-dev/visual-flow"; +import { isComponentBlock, toBlockOutput } from "../blocks/component"; +import { SpecialBlock } from "../blocks/special/base"; import { RootBlock } from "../blocks/special/root.r"; export class Project { @@ -75,6 +78,25 @@ export class Project { project.views[0]!.name = "app"; return project; } + + toOutput() { + const viewsOutput: ViewOutput[] = []; + currentProject.views.forEach((view, id) => { + if (view === null) return; + viewsOutput.push({ + name: view.name, + componentBlocks: view.graph.blocks + .filter(isComponentBlock) + .map(toBlockOutput), + specialBlocks: view.graph.blocks + .filter((b) => !isComponentBlock(b)) + .map((b) => (b as unknown as SpecialBlock).toOutput()), + }); + }); + return { + views: viewsOutput, + }; + } } export let currentProject: Project; diff --git a/packages/northstar/src/utils/toOutput.ts b/packages/northstar/src/utils/toOutput.ts index c9491ba..331d22c 100644 --- a/packages/northstar/src/utils/toOutput.ts +++ b/packages/northstar/src/utils/toOutput.ts @@ -1,4 +1,4 @@ -import type { ConnectTo, ViewOutput } from "@quasi-dev/compiler"; +import type { ConnectTo } from "@quasi-dev/compiler"; import type { MultiInSocket, MultiOutSocket, @@ -6,28 +6,6 @@ import type { SingleOutSocket, Socket, } from "@quasi-dev/visual-flow"; -import { isComponentBlock, toBlockOutput } from "../blocks/component"; -import { SpecialBlock } from "../blocks/special/base"; -import { currentProject } from "../project"; - -export function toOutput() { - const viewsOutput: ViewOutput[] = []; - currentProject.views.forEach((view, id) => { - if (view === null) return; - viewsOutput.push({ - name: view.name, - componentBlocks: view.graph.blocks - .filter(isComponentBlock) - .map(toBlockOutput), - specialBlocks: view.graph.blocks - .filter((b) => !isComponentBlock(b)) - .map((b) => (b as unknown as SpecialBlock).toOutput()), - }); - }); - return { - views: viewsOutput, - }; -} export function multiInSocketToOutput( socket: MultiInSocket | undefined, diff --git a/packages/northstar/src/views/preview.r.ts b/packages/northstar/src/views/preview.r.ts index e2a75a2..d7789b4 100644 --- a/packages/northstar/src/views/preview.r.ts +++ b/packages/northstar/src/views/preview.r.ts @@ -2,14 +2,14 @@ import { HTMLElementComponent, ref, view } from "refina"; import runtimeURL from "@quasi-dev/runtime/src/index.ts?url"; -import mduiStyleUrl from "@quasi-dev/runtime/styles.css?url"; // Used in development import mduiStyleContent from "@quasi-dev/runtime/styles.css?inline"; // Used in production +import mduiStyleUrl from "@quasi-dev/runtime/styles.css?url"; // Used in development import iframeURL from "./iframe/index.html?url"; import { compileTailwindCSS } from "@quasi-dev/browser-tailwind"; import { Compiler } from "@quasi-dev/compiler"; import { RefinaTransformer } from "@refina/transformer"; -import { toOutput } from "../utils/toOutput"; +import { currentProject } from "../project"; const transformer = new RefinaTransformer(); @@ -23,7 +23,7 @@ const iframe = ref>(); let errorMsg = ""; export async function startPreview() { - const compiler = new Compiler(toOutput()); + const compiler = new Compiler(currentProject.toOutput()); compiler.runtimeModuleURL = runtimeURL; code.js = transformer.transform("$", await compiler.compile()); code.css = ( diff --git a/packages/northstar/src/views/toolbar.r.ts b/packages/northstar/src/views/toolbar.r.ts index 4630a6a..1093d09 100644 --- a/packages/northstar/src/views/toolbar.r.ts +++ b/packages/northstar/src/views/toolbar.r.ts @@ -24,7 +24,6 @@ import { hasBlocksToRemove, removeBlocks, } from "../utils"; -import { toOutput } from "../utils/toOutput"; import { startPreview } from "./preview.r"; import iconURL from "/favicon.ico?url"; @@ -109,7 +108,7 @@ export default view(_ => { ) { if (_.$ev) { try { - const compiler = new Compiler(toOutput()); + const compiler = new Compiler(currentProject.toOutput()); compiler .compile() .then(v => {