Skip to content

Commit

Permalink
upd: move toOutput into Project class
Browse files Browse the repository at this point in the history
  • Loading branch information
KermanX committed Nov 22, 2023
1 parent 1869ec4 commit 88ab65b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 28 deletions.
22 changes: 22 additions & 0 deletions packages/northstar/src/project/project.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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;
Expand Down
24 changes: 1 addition & 23 deletions packages/northstar/src/utils/toOutput.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,11 @@
import type { ConnectTo, ViewOutput } from "@quasi-dev/compiler";
import type { ConnectTo } from "@quasi-dev/compiler";
import type {
MultiInSocket,
MultiOutSocket,
SingleInSocket,
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,
Expand Down
6 changes: 3 additions & 3 deletions packages/northstar/src/views/preview.r.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -23,7 +23,7 @@ const iframe = ref<HTMLElementComponent<"iframe">>();
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 = (
Expand Down
3 changes: 1 addition & 2 deletions packages/northstar/src/views/toolbar.r.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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 => {
Expand Down

0 comments on commit 88ab65b

Please sign in to comment.