feat: some shut
This commit is contained in:
@ -8,6 +8,8 @@ import type { NodeInput } from "@nodes/types";
|
||||
|
||||
const logger = createLogger("graph-manager");
|
||||
|
||||
logger.mute();
|
||||
|
||||
function areSocketsCompatible(output: string | undefined, inputs: string | string[] | undefined) {
|
||||
if (Array.isArray(inputs) && output) {
|
||||
return inputs.includes(output);
|
||||
@ -225,6 +227,32 @@ export class GraphManager extends EventEmitter<{ "save": Graph, "result": any, "
|
||||
return this.registry.getNode(id);
|
||||
}
|
||||
|
||||
async loadNode(id: string) {
|
||||
|
||||
await this.registry.load([id]);
|
||||
const nodeType = this.registry.getNode(id);
|
||||
|
||||
if (!nodeType) return;
|
||||
|
||||
const settingTypes = this.settingTypes;
|
||||
const settingValues = this.settings;
|
||||
if (nodeType.inputs) {
|
||||
for (const key in nodeType.inputs) {
|
||||
let settingId = nodeType.inputs[key].setting;
|
||||
if (settingId) {
|
||||
settingTypes[settingId] = nodeType.inputs[key];
|
||||
if (settingValues[settingId] === undefined && "value" in type.inputs[key]) {
|
||||
settingValues[settingId] = nodeType.inputs[key].value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.settings = settingValues;
|
||||
this.settingTypes = settingTypes;
|
||||
this.emit("settings", { types: settingTypes, values: settingValues });
|
||||
}
|
||||
|
||||
getChildrenOfNode(node: Node) {
|
||||
const children = [];
|
||||
const stack = node.tmp?.children?.slice(0);
|
||||
@ -349,6 +377,8 @@ export class GraphManager extends EventEmitter<{ "save": Graph, "result": any, "
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const node: Node = { id: this.createNodeId(), type, position, tmp: { type: nodeType }, props };
|
||||
|
||||
this.nodes.update((nodes) => {
|
||||
|
@ -773,14 +773,13 @@
|
||||
}
|
||||
|
||||
const pos = projectScreenToWorld(mx, my);
|
||||
graph.registry.load([nodeId]).then(() => {
|
||||
graph.loadNode(nodeId).then(() => {
|
||||
graph.createNode({
|
||||
type: nodeId,
|
||||
props: {},
|
||||
position: pos,
|
||||
});
|
||||
});
|
||||
console.log({ nodeId });
|
||||
}
|
||||
|
||||
function handlerDragOver(e: DragEvent) {
|
||||
|
@ -10,7 +10,7 @@ export class RemoteNodeRegistry implements NodeRegistry {
|
||||
|
||||
constructor(private url: string) { }
|
||||
|
||||
private async loadNode(id: `${string}/${string}/${string}`) {
|
||||
async loadNode(id: `${string}/${string}/${string}`) {
|
||||
const wasmResponse = await this.fetchNode(id);
|
||||
|
||||
// Setup Wasm wrapper
|
||||
@ -81,6 +81,8 @@ export class RemoteNodeRegistry implements NodeRegistry {
|
||||
|
||||
log.log("loaded nodes in", duration, "ms");
|
||||
this.status = "ready";
|
||||
|
||||
return nodes
|
||||
}
|
||||
|
||||
getNode(id: string) {
|
||||
|
@ -1,19 +1,15 @@
|
||||
<script lang="ts">
|
||||
import { Select } from "@nodes/ui";
|
||||
import type { Writable } from "svelte/store";
|
||||
|
||||
let activeStore = 0;
|
||||
export let activeId: Writable<string>;
|
||||
$: [activeUser, activeCollection, activeNode] = $activeId.split(`/`);
|
||||
</script>
|
||||
|
||||
<div class="breadcrumbs">
|
||||
{#if activeUser}
|
||||
<button
|
||||
on:click={() => {
|
||||
$activeId = "";
|
||||
}}
|
||||
>
|
||||
root
|
||||
</button>
|
||||
<Select id="root" options={["root"]} bind:value={activeStore}></Select>
|
||||
{#if activeCollection}
|
||||
<button
|
||||
on:click={() => {
|
||||
@ -38,7 +34,7 @@
|
||||
<span>{activeUser}</span>
|
||||
{/if}
|
||||
{:else}
|
||||
<span>root</span>
|
||||
<Select id="root" options={["root"]} bind:value={activeStore}></Select>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
@ -61,7 +57,8 @@
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.breadcrumbs > button::after {
|
||||
.breadcrumbs > button::after,
|
||||
.breadcrumbs :global(select)::after {
|
||||
content: "/";
|
||||
position: absolute;
|
||||
right: -11px;
|
||||
@ -78,4 +75,9 @@
|
||||
font-size: 1em;
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.breadcrumbs :global(select) {
|
||||
padding: 3px 5px;
|
||||
outline: none;
|
||||
}
|
||||
</style>
|
||||
|
@ -26,7 +26,9 @@
|
||||
|
||||
<div class="wrapper">
|
||||
{#if !activeUser}
|
||||
<h3>Users</h3>
|
||||
<div class="header">
|
||||
<h3>Users</h3>
|
||||
</div>
|
||||
{#await nodeRegistry.fetchUsers()}
|
||||
<div>Loading...</div>
|
||||
{:then users}
|
||||
@ -44,7 +46,15 @@
|
||||
{#await nodeRegistry.fetchUser(activeUser)}
|
||||
<div>Loading...</div>
|
||||
{:then user}
|
||||
<h3>Collections</h3>
|
||||
<div class="header">
|
||||
<button
|
||||
on:click={() => {
|
||||
$activeId = "";
|
||||
}}
|
||||
class="i-tabler-arrow-back"
|
||||
></button>
|
||||
<h3>Collections</h3>
|
||||
</div>
|
||||
{#each user.collections as collection}
|
||||
<button
|
||||
on:click={() => {
|
||||
@ -58,35 +68,47 @@
|
||||
<div>{error.message}</div>
|
||||
{/await}
|
||||
{:else if !activeNode}
|
||||
<h3>Nodes</h3>
|
||||
<div class="header">
|
||||
<button
|
||||
on:click={() => {
|
||||
$activeId = activeUser;
|
||||
}}
|
||||
class="i-tabler-arrow-back"
|
||||
></button>
|
||||
<h3>Nodes</h3>
|
||||
</div>
|
||||
{#await nodeRegistry.fetchCollection(`${activeUser}/${activeCollection}`)}
|
||||
<div>Loading...</div>
|
||||
{:then collection}
|
||||
{#each collection.nodes as node}
|
||||
<button
|
||||
on:click={() => {
|
||||
$activeId = node.id;
|
||||
}}
|
||||
>
|
||||
{node.id.split(`/`)[2]}
|
||||
</button>
|
||||
{#await nodeRegistry.fetchNodeDefinition(node.id)}
|
||||
<div>Loading...</div>
|
||||
{:then node}
|
||||
<DraggableNode {node} />
|
||||
{:catch error}
|
||||
<div>{error.message}</div>
|
||||
{/await}
|
||||
{/each}
|
||||
{:catch error}
|
||||
<div>{error.message}</div>
|
||||
{/await}
|
||||
{:else}
|
||||
{#await nodeRegistry.fetchNodeDefinition(`${activeUser}/${activeCollection}/${activeNode}`)}
|
||||
<div>Loading...</div>
|
||||
{:then node}
|
||||
<DraggableNode {node} />
|
||||
{:catch error}
|
||||
<div>{error.message}</div>
|
||||
{/await}
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.wrapper {
|
||||
padding: 1em;
|
||||
padding: 0.8em;
|
||||
max-height: calc(100vh - 170px);
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5em;
|
||||
margin-bottom: 0.5em;
|
||||
}
|
||||
h3 {
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
|
@ -111,6 +111,8 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor {
|
||||
// here we store the intermediate results of the nodes
|
||||
const results: Record<string, string | boolean | number> = {};
|
||||
|
||||
const runSeed = settings["randomSeed"] === true ? Math.floor(Math.random() * 100000000) : 5120983;
|
||||
|
||||
for (const node of sortedNodes) {
|
||||
|
||||
const node_type = this.typeMap.get(node.type)!;
|
||||
@ -120,7 +122,7 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor {
|
||||
for (const [key, input] of Object.entries(node_type.inputs || {})) {
|
||||
|
||||
if (input.type === "seed") {
|
||||
inputs[key] = Math.floor(Math.random() * 100000000);
|
||||
inputs[key] = runSeed;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -93,8 +93,16 @@
|
||||
icon: "i-tabler-chart-bar",
|
||||
id: "graph",
|
||||
settings: writable(ev.detail.values),
|
||||
definition: ev.detail.types,
|
||||
definition: {
|
||||
randomSeed: {
|
||||
type: "boolean",
|
||||
label: "Random Seed",
|
||||
value: true,
|
||||
},
|
||||
...ev.detail.types,
|
||||
},
|
||||
};
|
||||
|
||||
settings = settings;
|
||||
}
|
||||
</script>
|
||||
|
Reference in New Issue
Block a user