Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(node): Inverts the order of inputs/outputs in nodes. #375

Merged
merged 1 commit into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions docs/nodes/nodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,59 @@ export default defineNode({
});
```

There are also other properties that allow you to customize your nodes :

| name | data type | default |
| -------------------- | --------- | --------------------- |
| position.x | number | 0 |
| position.y | number | 0 |
| width | number | settings.defaultWidth |
| disablePointerEvents | boolean | false |
| twoColumn | boolean | false |
| reverseY | boolean? | undefined |

```ts
import { AbstractNode, CalculateFunction, NodeInterface } from "@baklavajs/core";
import { TextareaInputInterface } from "../src/nodeinterfaces/textareainput/TextareaInputInterface";
import { ButtonInterface } from "../src";
import { InputAnswerInterface } from "./interface/InputAnswerInterface";

export default class AnswerNode extends AbstractNode {
public type = "answer";

public inputs: Record<string, NodeInterface<any>> = {
input: new NodeInterface("Content", ""),
description: new TextareaInputInterface("", "").setPort(false),
};
public outputs: Record<string, NodeInterface<any>> = {};

private counter = 0;
public constructor() {
super();
this.initializeIo();
this.width = 400;
this.title = "Answer";
this.reverseY = true;
}

public addChoice(value?: string) {
const name = "answer" + ++this.counter;
this.addOutput(
name,
new InputAnswerInterface(name, value, () => {
this.removeOutput(name);
}),
);
}

public onPlaced() {
this.addInput("addAnswer", new ButtonInterface("Add " + this.title, () => this.addChoice()));
}

calculate?: CalculateFunction<any, any> | undefined;
}
```

## Class-based approach

For nodes that have dynamic inputs and outputs, it is also possible to use a class-based approach similar to BaklavaJS v1.
Expand Down
1 change: 1 addition & 0 deletions docs/visual-editor/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Settings can be changed by accessing the `settings` property of the view model r
| nodes.maxWidth | number | 320 |
| nodes.minWidth | boolean | 150 |
| nodes.resizable | boolean | false |
| nodes.reverseY | boolean | false |
| contextMenu.enabled | boolean | true |
| contextMenu.additionalItems | ContextMenuItem[] | [] |

Expand Down
1 change: 1 addition & 0 deletions packages/renderer-vue/playground/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ baklavaView.settings.enableMinimap = true;
baklavaView.settings.sidebar.resizable = false;
baklavaView.settings.displayValueOnHover = true;
baklavaView.settings.nodes.resizable = true;
baklavaView.settings.nodes.reverseY = false;
baklavaView.settings.contextMenu.additionalItems = [
{ isDivider: true },
{ label: "Copy", command: Commands.COPY_COMMAND },
Expand Down
7 changes: 5 additions & 2 deletions packages/renderer-vue/src/node/Node.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
</slot>

<slot name="content">
<div class="__content" @keydown.delete.stop>
<div class="__content" @keydown.delete.stop :class="classesContent">
<!-- Outputs -->
<div class="__outputs">
<template v-for="output in displayedOutputs" :key="output.id">
Expand Down Expand Up @@ -72,7 +72,6 @@ import { useGraph, useViewModel } from "../utility";
import { ContextMenu } from "../contextmenu";
import VerticalDots from "../icons/VerticalDots.vue";
import NodeInterface from "./NodeInterface.vue";

const props = withDefaults(
defineProps<{
node: AbstractNode;
Expand Down Expand Up @@ -116,6 +115,10 @@ const classes = computed(() => ({
"--two-column": !!props.node.twoColumn,
}));

const classesContent = computed(() => ({
"--reverse-y": props.node.reverseY ?? viewModel.value.settings.nodes.reverseY,
}));

const styles = computed(() => ({
"top": `${props.node.position?.y ?? 0}px`,
"left": `${props.node.position?.x ?? 0}px`,
Expand Down
1 change: 1 addition & 0 deletions packages/renderer-vue/src/overrides.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ declare module "@baklavajs/core/dist/node" {
width: number;
disablePointerEvents: boolean;
twoColumn: boolean;
reverseY?: boolean;
}
}

Expand Down
3 changes: 3 additions & 0 deletions packages/renderer-vue/src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export interface IViewSettings {
defaultWidth: number;
/** Whether users should be able to resize nodes */
resizable: boolean;
/** Inverts the order of inputs/outputs in nodes. */
reverseY: boolean;
};
contextMenu: {
/** Whether the context menu should be enabled */
Expand Down Expand Up @@ -93,6 +95,7 @@ export const DEFAULT_SETTINGS: () => IViewSettings = () => ({
maxWidth: 320,
minWidth: 150,
resizable: false,
reverseY: false,
},
contextMenu: {
enabled: true,
Expand Down
5 changes: 5 additions & 0 deletions packages/themes/src/classic/components/node.scss
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@
& > .__content {
padding: 0.75em;

&.--reverse-y {
display: flex;
flex-direction: column-reverse;
}

& > div > div {
margin: 0.5em 0;
}
Expand Down