@elicdavis/node-flow 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1609,6 +1609,7 @@ var Port = class {
1609
1609
  #dataTypePopupElement;
1610
1610
  #onConnectionAdded;
1611
1611
  #onConnectionRemoved;
1612
+ #widget = null;
1612
1613
  constructor(node, portType, config) {
1613
1614
  this.#node = node;
1614
1615
  this.#connections = new Array();
@@ -1759,10 +1760,23 @@ var Port = class {
1759
1760
  this.#visibilityMayHaveChanged(was);
1760
1761
  }
1761
1762
  #visibilityMayHaveChanged(was) {
1762
- if (was !== this.hidden() || this.#portType === "INPUTARRAY" /* InputArray */) {
1763
+ if (was !== this.hidden() || this.#portType === "INPUTARRAY" /* InputArray */ || this.#widget !== null) {
1763
1764
  this.#node?.invalidateLayout();
1764
1765
  }
1765
1766
  }
1767
+ setWidget(widget) {
1768
+ this.#widget = widget;
1769
+ this.#node?.invalidateLayout();
1770
+ }
1771
+ widget() {
1772
+ return this.#widget;
1773
+ }
1774
+ /**
1775
+ * The widget stands in for a wire, so it leaves once one is connected.
1776
+ */
1777
+ widgetShown() {
1778
+ return this.#widget !== null && this.#portType !== "OUTPUT" /* Output */ && this.#connections.length === 0 && !this.hidden() && !(this.#widget.Hidden?.() ?? false);
1779
+ }
1766
1780
  /**
1767
1781
  * A port asked to hide still shows while anything is connected to it,
1768
1782
  * and while its node is showing its hidden ports.
@@ -5116,6 +5130,7 @@ var FlowNode = class {
5116
5130
  #inputPortPositions;
5117
5131
  #outputPortPositions;
5118
5132
  #widgetPositions;
5133
+ #portWidgetPositions = new List();
5119
5134
  #data;
5120
5135
  #registeredAnyPropertyChangeCallbacks;
5121
5136
  #registeredPropertyChangeCallbacks;
@@ -5603,7 +5618,7 @@ var FlowNode = class {
5603
5618
  }
5604
5619
  this.#portTextStyle.measure(ctx, 1, port.getDisplayName(), tempMeasurement);
5605
5620
  size.y += this.#portRowHeight(port, tempMeasurement.y) + this.#elementSpacing;
5606
- size.x = Math.max(size.x, tempMeasurement.x + doublePadding);
5621
+ size.x = Math.max(size.x, this.#portRowWidth(port, tempMeasurement.x) + doublePadding);
5607
5622
  }
5608
5623
  const widgets = this.#hasHiddenPortsToggle() ? [this.#hiddenPortsToggle, ...this.#widgets] : this.#widgets;
5609
5624
  for (const widget of widgets) {
@@ -5624,6 +5639,9 @@ var FlowNode = class {
5624
5639
  }
5625
5640
  addInput(config) {
5626
5641
  const port = new Port(this, config.array ? "INPUTARRAY" /* InputArray */ : "INPUT" /* Input */, config);
5642
+ if (config.widget !== void 0) {
5643
+ port.setWidget(GlobalWidgetFactory.createFromConfig(this, config.widget));
5644
+ }
5627
5645
  this.#input.push(port);
5628
5646
  return port;
5629
5647
  }
@@ -5749,6 +5767,17 @@ var FlowNode = class {
5749
5767
  intersection.WidgetBox = this.#widgetPositions.At(i);
5750
5768
  }
5751
5769
  }
5770
+ for (let i = 0; i < this.#portWidgetPositions.Count(); i++) {
5771
+ const port = this.#input[i];
5772
+ if (port !== void 0 && port.widgetShown() && InBox(this.#portWidgetPositions.At(i), position)) {
5773
+ intersection.Node = this;
5774
+ intersection.Widget = port.widget();
5775
+ intersection.WidgetBox = this.#portWidgetPositions.At(i);
5776
+ intersection.Port = void 0;
5777
+ intersection.PortIndex = void 0;
5778
+ intersection.PortIsInput = void 0;
5779
+ }
5780
+ }
5752
5781
  return intersection;
5753
5782
  }
5754
5783
  canEditTitle() {
@@ -5863,7 +5892,14 @@ var FlowNode = class {
5863
5892
  }
5864
5893
  #portRowHeight(port, textHeight) {
5865
5894
  const slots = port.slots();
5866
- return slots > 1 ? Math.max(textHeight, slots * ARRAY_SLOT_PITCH) : textHeight;
5895
+ const widget = port.widgetShown() ? port.widget().Size().y : 0;
5896
+ return Math.max(slots > 1 ? slots * ARRAY_SLOT_PITCH : 0, textHeight, widget);
5897
+ }
5898
+ #portRowWidth(port, textWidth) {
5899
+ if (!port.widgetShown()) {
5900
+ return textWidth;
5901
+ }
5902
+ return textWidth + this.#elementSpacing + port.widget().Size().x;
5867
5903
  }
5868
5904
  hasBeenLaidOut() {
5869
5905
  return this.#laidOut;
@@ -5885,6 +5921,7 @@ var FlowNode = class {
5885
5921
  this.#inputPortPositions.Clear();
5886
5922
  this.#outputPortPositions.Clear();
5887
5923
  this.#widgetPositions.Clear();
5924
+ this.#portWidgetPositions.Clear();
5888
5925
  const scaledPadding = this.#padding * camera.zoom;
5889
5926
  const scaledElementSpacing = this.#elementSpacing * camera.zoom;
5890
5927
  const nodeBounds = this.calculateBounds(ctx, camera);
@@ -5979,6 +6016,7 @@ var FlowNode = class {
5979
6016
  const port = this.#input[i];
5980
6017
  if (port.hidden()) {
5981
6018
  this.#inputPortPositions.Push({ Position: { x: nodeBounds.Position.x, y: startY }, Size: { x: 0, y: 0 } });
6019
+ this.#portWidgetPositions.Push({ Position: { x: nodeBounds.Position.x, y: startY }, Size: { x: 0, y: 0 } });
5982
6020
  continue;
5983
6021
  }
5984
6022
  this.#portTextStyle.measure(ctx, 1, port.getDisplayName(), tempMeasurement);
@@ -5988,6 +6026,19 @@ var FlowNode = class {
5988
6026
  position.y = startY + portHeight / 2;
5989
6027
  this.#portTextStyle.setupStyle(ctx, camera.zoom);
5990
6028
  ctx.fillText(port.getDisplayName(), leftSide, position.y);
6029
+ if (port.widgetShown()) {
6030
+ const widget = port.widget();
6031
+ const widgetHeight = widget.Size().y * camera.zoom;
6032
+ const widgetLeft = leftSide + tempMeasurement.x * camera.zoom + scaledElementSpacing;
6033
+ const box = {
6034
+ Position: { x: widgetLeft, y: startY + (portHeight - widgetHeight) / 2 },
6035
+ Size: { x: nodeBounds.Position.x + nodeBounds.Size.x - scaledPadding - widgetLeft, y: widgetHeight }
6036
+ };
6037
+ widget.Draw(ctx, box, camera.zoom, mousePosition);
6038
+ this.#portWidgetPositions.Push(box);
6039
+ } else {
6040
+ this.#portWidgetPositions.Push({ Position: { x: nodeBounds.Position.x, y: startY }, Size: { x: 0, y: 0 } });
6041
+ }
5991
6042
  this.#inputPortPositions.Push(port.render(ctx, position, camera, mousePosition, postProcess));
5992
6043
  startY += portHeight + scaledElementSpacing;
5993
6044
  }
@@ -6073,6 +6124,7 @@ var FlowNode = class {
6073
6124
  return false;
6074
6125
  }
6075
6126
  this.#widgetPositions.Clear();
6127
+ this.#portWidgetPositions.Clear();
6076
6128
  this.#hiddenPortsTogglePosition = null;
6077
6129
  return true;
6078
6130
  }