@particle-academy/fancy-flow 0.20.0 → 0.21.0

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.
@@ -1,6 +1,6 @@
1
1
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
2
  import ReactExports, { createContext, forwardRef, memo, useMemo, useState, useRef, useEffect, useCallback, useContext, useSyncExternalStore, useDebugValue, useLayoutEffect } from 'react';
3
- import 'react-dom';
3
+ import { createPortal } from 'react-dom';
4
4
 
5
5
  // node_modules/d3-dispatch/src/dispatch.js
6
6
  var noop = { value: () => {
@@ -109,9 +109,9 @@ function creator_default(name) {
109
109
  // node_modules/d3-selection/src/selector.js
110
110
  function none() {
111
111
  }
112
- function selector_default(selector) {
113
- return selector == null ? none : function() {
114
- return this.querySelector(selector);
112
+ function selector_default(selector2) {
113
+ return selector2 == null ? none : function() {
114
+ return this.querySelector(selector2);
115
115
  };
116
116
  }
117
117
 
@@ -138,9 +138,9 @@ function array(x) {
138
138
  function empty() {
139
139
  return [];
140
140
  }
141
- function selectorAll_default(selector) {
142
- return selector == null ? empty : function() {
143
- return this.querySelectorAll(selector);
141
+ function selectorAll_default(selector2) {
142
+ return selector2 == null ? empty : function() {
143
+ return this.querySelectorAll(selector2);
144
144
  };
145
145
  }
146
146
 
@@ -165,14 +165,14 @@ function selectAll_default(select) {
165
165
  }
166
166
 
167
167
  // node_modules/d3-selection/src/matcher.js
168
- function matcher_default(selector) {
168
+ function matcher_default(selector2) {
169
169
  return function() {
170
- return this.matches(selector);
170
+ return this.matches(selector2);
171
171
  };
172
172
  }
173
- function childMatcher(selector) {
173
+ function childMatcher(selector2) {
174
174
  return function(node) {
175
- return node.matches(selector);
175
+ return node.matches(selector2);
176
176
  };
177
177
  }
178
178
 
@@ -241,11 +241,11 @@ EnterNode.prototype = {
241
241
  insertBefore: function(child, next) {
242
242
  return this._parent.insertBefore(child, next);
243
243
  },
244
- querySelector: function(selector) {
245
- return this._parent.querySelector(selector);
244
+ querySelector: function(selector2) {
245
+ return this._parent.querySelector(selector2);
246
246
  },
247
- querySelectorAll: function(selector) {
248
- return this._parent.querySelectorAll(selector);
247
+ querySelectorAll: function(selector2) {
248
+ return this._parent.querySelectorAll(selector2);
249
249
  }
250
250
  };
251
251
 
@@ -856,8 +856,8 @@ Selection.prototype = selection.prototype = {
856
856
  var selection_default = selection;
857
857
 
858
858
  // node_modules/d3-selection/src/select.js
859
- function select_default2(selector) {
860
- return typeof selector === "string" ? new Selection([[document.querySelector(selector)]], [document.documentElement]) : new Selection([[selector]], root);
859
+ function select_default2(selector2) {
860
+ return typeof selector2 === "string" ? new Selection([[document.querySelector(selector2)]], [document.documentElement]) : new Selection([[selector2]], root);
861
861
  }
862
862
 
863
863
  // node_modules/d3-selection/src/sourceEvent.js
@@ -3871,6 +3871,40 @@ function createMarkerIds(edges, { id: id2, defaultColor, defaultMarkerStart, def
3871
3871
  return markers;
3872
3872
  }, []).sort((a, b) => a.id.localeCompare(b.id));
3873
3873
  }
3874
+ function getNodeToolbarTransform(nodeRect, viewport, position, offset, align) {
3875
+ let alignmentOffset = 0.5;
3876
+ if (align === "start") {
3877
+ alignmentOffset = 0;
3878
+ } else if (align === "end") {
3879
+ alignmentOffset = 1;
3880
+ }
3881
+ let pos = [
3882
+ (nodeRect.x + nodeRect.width * alignmentOffset) * viewport.zoom + viewport.x,
3883
+ nodeRect.y * viewport.zoom + viewport.y - offset
3884
+ ];
3885
+ let shift = [-100 * alignmentOffset, -100];
3886
+ switch (position) {
3887
+ case Position.Right:
3888
+ pos = [
3889
+ (nodeRect.x + nodeRect.width) * viewport.zoom + viewport.x + offset,
3890
+ (nodeRect.y + nodeRect.height * alignmentOffset) * viewport.zoom + viewport.y
3891
+ ];
3892
+ shift = [0, -100 * alignmentOffset];
3893
+ break;
3894
+ case Position.Bottom:
3895
+ pos[1] = (nodeRect.y + nodeRect.height) * viewport.zoom + viewport.y + offset;
3896
+ shift[1] = 0;
3897
+ break;
3898
+ case Position.Left:
3899
+ pos = [
3900
+ nodeRect.x * viewport.zoom + viewport.x - offset,
3901
+ (nodeRect.y + nodeRect.height * alignmentOffset) * viewport.zoom + viewport.y
3902
+ ];
3903
+ shift = [-100, -100 * alignmentOffset];
3904
+ break;
3905
+ }
3906
+ return `translate(${pos[0]}px, ${pos[1]}px) translate(${shift[0]}%, ${shift[1]}%)`;
3907
+ }
3874
3908
  var SELECTED_NODE_Z = 1e3;
3875
3909
  var ROOT_PARENT_Z_INCREMENT = 10;
3876
3910
  var defaultOptions = {
@@ -4238,10 +4272,10 @@ function isParentSelected(node, nodeLookup) {
4238
4272
  }
4239
4273
  return isParentSelected(parentNode, nodeLookup);
4240
4274
  }
4241
- function hasSelector(target, selector, domNode) {
4275
+ function hasSelector(target, selector2, domNode) {
4242
4276
  let current = target;
4243
4277
  do {
4244
- if (current?.matches?.(selector))
4278
+ if (current?.matches?.(selector2))
4245
4279
  return true;
4246
4280
  if (current === domNode)
4247
4281
  return false;
@@ -5199,6 +5233,8 @@ var ResizeControlVariant;
5199
5233
  ResizeControlVariant2["Line"] = "line";
5200
5234
  ResizeControlVariant2["Handle"] = "handle";
5201
5235
  })(ResizeControlVariant || (ResizeControlVariant = {}));
5236
+ var XY_RESIZER_HANDLE_POSITIONS = ["top-left", "top-right", "bottom-left", "bottom-right"];
5237
+ var XY_RESIZER_LINE_POSITIONS = ["top", "right", "bottom", "left"];
5202
5238
  function getResizeDirection({ width, prevWidth, height, prevHeight, affectsX, affectsY }) {
5203
5239
  const deltaWidth = width - prevWidth;
5204
5240
  const deltaHeight = height - prevHeight;
@@ -5573,7 +5609,7 @@ function cc(names) {
5573
5609
  }
5574
5610
  return out;
5575
5611
  }
5576
- function useSyncExternalStoreWithSelector(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) {
5612
+ function useSyncExternalStoreWithSelector(subscribe, getSnapshot, getServerSnapshot, selector2, isEqual) {
5577
5613
  const instRef = useRef(null);
5578
5614
  let inst;
5579
5615
  if (instRef.current === null) {
@@ -5590,7 +5626,7 @@ function useSyncExternalStoreWithSelector(subscribe, getSnapshot, getServerSnaps
5590
5626
  if (!hasMemo) {
5591
5627
  hasMemo = true;
5592
5628
  memoizedSnapshot = nextSnapshot;
5593
- const nextSelection2 = selector(nextSnapshot);
5629
+ const nextSelection2 = selector2(nextSnapshot);
5594
5630
  if (isEqual !== void 0 && inst.hasValue) {
5595
5631
  const currentSelection = inst.value;
5596
5632
  if (isEqual(currentSelection, nextSelection2)) {
@@ -5606,7 +5642,7 @@ function useSyncExternalStoreWithSelector(subscribe, getSnapshot, getServerSnaps
5606
5642
  if (Object.is(prevSnapshot, nextSnapshot)) {
5607
5643
  return prevSelection;
5608
5644
  }
5609
- const nextSelection = selector(nextSnapshot);
5645
+ const nextSelection = selector2(nextSnapshot);
5610
5646
  if (isEqual !== void 0 && isEqual(prevSelection, nextSelection)) {
5611
5647
  memoizedSnapshot = nextSnapshot;
5612
5648
  return prevSelection;
@@ -5619,7 +5655,7 @@ function useSyncExternalStoreWithSelector(subscribe, getSnapshot, getServerSnaps
5619
5655
  const getSnapshotWithSelector = () => memoizedSelector(getSnapshot());
5620
5656
  const getServerSnapshotWithSelector = maybeGetServerSnapshot === null ? void 0 : () => memoizedSelector(maybeGetServerSnapshot());
5621
5657
  return [getSnapshotWithSelector, getServerSnapshotWithSelector];
5622
- }, [getSnapshot, getServerSnapshot, selector, isEqual]);
5658
+ }, [getSnapshot, getServerSnapshot, selector2, isEqual]);
5623
5659
  const value = useSyncExternalStore(subscribe, getSelection, getServerSelection);
5624
5660
  useEffect(() => {
5625
5661
  inst.hasValue = true;
@@ -5666,12 +5702,12 @@ var createStore = (createState) => createState ? createStoreImpl(createState) :
5666
5702
  var { useDebugValue: useDebugValue2 } = ReactExports;
5667
5703
  var { useSyncExternalStoreWithSelector: useSyncExternalStoreWithSelector2 } = use_sync_external_store_with_selector_default;
5668
5704
  var identity3 = (arg) => arg;
5669
- function useStoreWithEqualityFn(api, selector = identity3, equalityFn) {
5705
+ function useStoreWithEqualityFn(api, selector2 = identity3, equalityFn) {
5670
5706
  const slice = useSyncExternalStoreWithSelector2(
5671
5707
  api.subscribe,
5672
5708
  api.getState,
5673
5709
  api.getServerState || api.getInitialState,
5674
- selector,
5710
+ selector2,
5675
5711
  equalityFn
5676
5712
  );
5677
5713
  useDebugValue2(slice);
@@ -5679,7 +5715,7 @@ function useStoreWithEqualityFn(api, selector = identity3, equalityFn) {
5679
5715
  }
5680
5716
  var createWithEqualityFnImpl = (createState, defaultEqualityFn) => {
5681
5717
  const api = createStore(createState);
5682
- const useBoundStoreWithEqualityFn = (selector, equalityFn = defaultEqualityFn) => useStoreWithEqualityFn(api, selector, equalityFn);
5718
+ const useBoundStoreWithEqualityFn = (selector2, equalityFn = defaultEqualityFn) => useStoreWithEqualityFn(api, selector2, equalityFn);
5683
5719
  Object.assign(useBoundStoreWithEqualityFn, api);
5684
5720
  return useBoundStoreWithEqualityFn;
5685
5721
  };
@@ -5725,12 +5761,12 @@ function shallow$1(objA, objB) {
5725
5761
  var StoreContext = createContext(null);
5726
5762
  var Provider$1 = StoreContext.Provider;
5727
5763
  var zustandErrorMessage = errorMessages["error001"]("react");
5728
- function useStore(selector, equalityFn) {
5764
+ function useStore(selector2, equalityFn) {
5729
5765
  const store = useContext(StoreContext);
5730
5766
  if (store === null) {
5731
5767
  throw new Error(zustandErrorMessage);
5732
5768
  }
5733
- return useStoreWithEqualityFn(store, selector, equalityFn);
5769
+ return useStoreWithEqualityFn(store, selector2, equalityFn);
5734
5770
  }
5735
5771
  function useStoreApi() {
5736
5772
  const store = useContext(StoreContext);
@@ -8928,8 +8964,70 @@ function ResizeControl({ nodeId, position, variant = ResizeControlVariant.Handle
8928
8964
  ...color2 && { [isHandleControl ? "backgroundColor" : "borderColor"]: color2 }
8929
8965
  }, children: children2 });
8930
8966
  }
8931
- memo(ResizeControl);
8967
+ var NodeResizeControl = memo(ResizeControl);
8968
+ function NodeResizer({ nodeId, isVisible = true, handleClassName, handleStyle, lineClassName, lineStyle, color: color2, minWidth = 10, minHeight = 10, maxWidth = Number.MAX_VALUE, maxHeight = Number.MAX_VALUE, keepAspectRatio = false, autoScale = true, shouldResize, onResizeStart, onResize, onResizeEnd }) {
8969
+ if (!isVisible) {
8970
+ return null;
8971
+ }
8972
+ return jsxs(Fragment, { children: [XY_RESIZER_LINE_POSITIONS.map((position) => jsx(NodeResizeControl, { className: lineClassName, style: lineStyle, nodeId, position, variant: ResizeControlVariant.Line, color: color2, minWidth, minHeight, maxWidth, maxHeight, onResizeStart, keepAspectRatio, autoScale, shouldResize, onResize, onResizeEnd }, position)), XY_RESIZER_HANDLE_POSITIONS.map((position) => jsx(NodeResizeControl, { className: handleClassName, style: handleStyle, nodeId, position, color: color2, minWidth, minHeight, maxWidth, maxHeight, onResizeStart, keepAspectRatio, autoScale, shouldResize, onResize, onResizeEnd }, position))] });
8973
+ }
8974
+ var selector = (state) => state.domNode?.querySelector(".react-flow__renderer");
8975
+ function NodeToolbarPortal({ children: children2 }) {
8976
+ const wrapperRef = useStore(selector);
8977
+ if (!wrapperRef) {
8978
+ return null;
8979
+ }
8980
+ return createPortal(children2, wrapperRef);
8981
+ }
8982
+ var nodeEqualityFn = (a, b) => a?.internals.positionAbsolute.x !== b?.internals.positionAbsolute.x || a?.internals.positionAbsolute.y !== b?.internals.positionAbsolute.y || a?.measured.width !== b?.measured.width || a?.measured.height !== b?.measured.height || a?.selected !== b?.selected || a?.internals.z !== b?.internals.z;
8983
+ var nodesEqualityFn = (a, b) => {
8984
+ if (a.size !== b.size) {
8985
+ return false;
8986
+ }
8987
+ for (const [key, node] of a) {
8988
+ if (nodeEqualityFn(node, b.get(key))) {
8989
+ return false;
8990
+ }
8991
+ }
8992
+ return true;
8993
+ };
8994
+ var storeSelector = (state) => ({
8995
+ x: state.transform[0],
8996
+ y: state.transform[1],
8997
+ zoom: state.transform[2],
8998
+ selectedNodesCount: state.nodes.filter((node) => node.selected).length
8999
+ });
9000
+ function NodeToolbar({ nodeId, children: children2, className, style: style2, isVisible, position = Position.Top, offset = 10, align = "center", ...rest }) {
9001
+ const contextNodeId = useNodeId();
9002
+ const nodesSelector = useCallback((state) => {
9003
+ const nodeIds = Array.isArray(nodeId) ? nodeId : [nodeId || contextNodeId || ""];
9004
+ const internalNodes = nodeIds.reduce((res, id2) => {
9005
+ const node = state.nodeLookup.get(id2);
9006
+ if (node) {
9007
+ res.set(node.id, node);
9008
+ }
9009
+ return res;
9010
+ }, /* @__PURE__ */ new Map());
9011
+ return internalNodes;
9012
+ }, [nodeId, contextNodeId]);
9013
+ const nodes = useStore(nodesSelector, nodesEqualityFn);
9014
+ const { x, y, zoom, selectedNodesCount } = useStore(storeSelector, shallow$1);
9015
+ const isActive = typeof isVisible === "boolean" ? isVisible : nodes.size === 1 && nodes.values().next().value?.selected && selectedNodesCount === 1;
9016
+ if (!isActive || !nodes.size) {
9017
+ return null;
9018
+ }
9019
+ const nodeRect = getInternalNodesBounds(nodes);
9020
+ const nodesArray = Array.from(nodes.values());
9021
+ const zIndex = Math.max(...nodesArray.map((node) => node.internals.z + 1));
9022
+ const wrapperStyle2 = {
9023
+ position: "absolute",
9024
+ transform: getNodeToolbarTransform(nodeRect, { x, y, zoom }, position, offset, align),
9025
+ zIndex,
9026
+ ...style2
9027
+ };
9028
+ return jsx(NodeToolbarPortal, { children: jsx("div", { style: wrapperStyle2, className: cc(["react-flow__node-toolbar", className]), ...rest, "data-id": nodesArray.reduce((acc, node) => `${acc}${node.id} `, "").trim(), children: children2 }) });
9029
+ }
8932
9030
 
8933
- export { Background, BackgroundVariant, Controls, Handle, MiniMap, Position, ReactFlowProvider, addEdge2 as addEdge, applyEdgeChanges, applyNodeChanges, index, reconnectEdge2 as reconnectEdge, useReactFlow };
8934
- //# sourceMappingURL=chunk-XETAGLH6.js.map
8935
- //# sourceMappingURL=chunk-XETAGLH6.js.map
9031
+ export { Background, BackgroundVariant, Controls, Handle, MiniMap, NodeResizer, NodeToolbar, Position, ReactFlowProvider, addEdge2 as addEdge, applyEdgeChanges, applyNodeChanges, index, reconnectEdge2 as reconnectEdge, useReactFlow };
9032
+ //# sourceMappingURL=chunk-ZB4HHQMR.js.map
9033
+ //# sourceMappingURL=chunk-ZB4HHQMR.js.map