From 2c85eae121f18e8c9458b9fcbae6fb620ad28ada Mon Sep 17 00:00:00 2001 From: Starker-xp Date: Thu, 1 Feb 2024 11:04:32 +0100 Subject: [PATCH] feat(node): Inverts the order of inputs/outputs in nodes. --- docs/nodes/nodes.md | 53 +++++++++++++++++++ docs/visual-editor/setup.md | 1 + packages/renderer-vue/playground/App.vue | 1 + packages/renderer-vue/src/node/Node.vue | 7 ++- packages/renderer-vue/src/overrides.d.ts | 1 + packages/renderer-vue/src/settings.ts | 3 ++ .../themes/src/classic/components/node.scss | 5 ++ 7 files changed, 69 insertions(+), 2 deletions(-) diff --git a/docs/nodes/nodes.md b/docs/nodes/nodes.md index c460b73f..40afb749 100644 --- a/docs/nodes/nodes.md +++ b/docs/nodes/nodes.md @@ -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> = { + input: new NodeInterface("Content", ""), + description: new TextareaInputInterface("", "").setPort(false), + }; + public outputs: Record> = {}; + + 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 | 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. diff --git a/docs/visual-editor/setup.md b/docs/visual-editor/setup.md index 202b2273..92bc396f 100644 --- a/docs/visual-editor/setup.md +++ b/docs/visual-editor/setup.md @@ -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[] | [] | diff --git a/packages/renderer-vue/playground/App.vue b/packages/renderer-vue/playground/App.vue index 0996ff00..cc7c29ec 100644 --- a/packages/renderer-vue/playground/App.vue +++ b/packages/renderer-vue/playground/App.vue @@ -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 }, diff --git a/packages/renderer-vue/src/node/Node.vue b/packages/renderer-vue/src/node/Node.vue index f805a79b..bd8edfee 100644 --- a/packages/renderer-vue/src/node/Node.vue +++ b/packages/renderer-vue/src/node/Node.vue @@ -41,7 +41,7 @@ -
+