@industry-theme/principal-view-panels 0.12.45 → 0.12.46

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.
@@ -86441,6 +86441,11 @@ const NodeTooltip = ({ description, otel, sources, references, visible, nodeRef
86441
86441
  }
86442
86442
  return renderTooltipContent();
86443
86443
  };
86444
+ const GraphEditContext = createContext({});
86445
+ const GraphEditProvider = ({ children: children2, value }) => {
86446
+ return jsx(GraphEditContext.Provider, { value, children: children2 });
86447
+ };
86448
+ const useGraphEdit = () => useContext(GraphEditContext);
86444
86449
  function hexToLightColor(hexColor, lightness = 0.88) {
86445
86450
  const hex2 = hexColor.replace("#", "");
86446
86451
  const r2 = parseInt(hex2.substring(0, 2), 16);
@@ -86455,6 +86460,8 @@ function hexToLightColor(hexColor, lightness = 0.88) {
86455
86460
  const CustomNode = ({ data, selected: selected2, dragging }) => {
86456
86461
  var _a, _b, _c, _d, _e2, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
86457
86462
  const { theme: theme2 } = useTheme();
86463
+ const { onNodeResizeEnd } = useGraphEdit();
86464
+ const nodeId = useNodeId();
86458
86465
  const [isHovered, setIsHovered] = useState(false);
86459
86466
  const nodeRef = useRef(null);
86460
86467
  const nodeProps = data;
@@ -86475,6 +86482,14 @@ const CustomNode = ({ data, selected: selected2, dragging }) => {
86475
86482
  // Default to not hidden
86476
86483
  } = nodeProps;
86477
86484
  const nodeOpacity = isHidden ? 0.4 : isActive ? 1 : 0.1;
86485
+ const handleResizeEnd = useCallback((_event, params) => {
86486
+ if (nodeId && onNodeResizeEnd && params.width && params.height) {
86487
+ onNodeResizeEnd(nodeId, {
86488
+ width: Math.round(params.width),
86489
+ height: Math.round(params.height)
86490
+ });
86491
+ }
86492
+ }, [nodeId, onNodeResizeEnd]);
86478
86493
  console.log("[CustomNode] Node data:", {
86479
86494
  name: nodeProps.name,
86480
86495
  nodeDataKeys: nodeData ? Object.keys(nodeData).join(", ") : "undefined",
@@ -86884,7 +86899,7 @@ const CustomNode = ({ data, selected: selected2, dragging }) => {
86884
86899
  }
86885
86900
  return offsetStyle;
86886
86901
  };
86887
- return jsxs(Fragment, { children: [editable && jsx(NodeResizer, { color: strokeColor, isVisible: selected2, minWidth, minHeight, keepAspectRatio, handleStyle: {
86902
+ return jsxs(Fragment, { children: [editable && jsx(NodeResizer, { color: strokeColor, isVisible: selected2, minWidth, minHeight, keepAspectRatio, onResizeEnd: handleResizeEnd, handleStyle: {
86888
86903
  width: 8,
86889
86904
  height: 8,
86890
86905
  borderRadius: 2,
@@ -87347,7 +87362,7 @@ const CenterIndicator = ({ color: color2 }) => {
87347
87362
  zIndex: 5
87348
87363
  }, children: [jsx("line", { x1: screenX, y1: screenY - size, x2: screenX, y2: screenY + size, stroke: color2, strokeWidth, opacity: 0.7 }), jsx("line", { x1: screenX - size, y1: screenY, x2: screenX + size, y2: screenY, stroke: color2, strokeWidth, opacity: 0.7 }), jsx("circle", { cx: screenX, cy: screenY, r: 3, fill: color2, opacity: 0.7 })] });
87349
87364
  };
87350
- const GraphRendererInner = ({ configuration, nodes: propNodes, edges: propEdges, violations = [], configName: _configName, showMinimap = false, showControls = true, showBackground = true, backgroundVariant = "lines", backgroundGap, showCenterIndicator = false, showTooltips = true, fitViewDuration = 200, highlightedNodeId, activeNodeIds, events = [], onEventProcessed, editable = false, onPendingChangesChange, onEditStateChange, editStateRef, onNodeClick: onNodeClickProp, fitViewToNodeIds, fitViewPadding = 0.2, draggableNodeIds, onNodeDragStop: onNodeDragStopProp, onCopy }) => {
87365
+ const GraphRendererInner = ({ configuration, nodes: propNodes, edges: propEdges, violations = [], configName: _configName, showMinimap = false, showControls = true, showBackground = true, backgroundVariant = "lines", backgroundGap, showCenterIndicator = false, showTooltips = true, fitViewDuration = 200, highlightedNodeId, activeNodeIds, events = [], onEventProcessed, editable = false, onPendingChangesChange, onEditStateChange, editStateRef, resetVisualStateRef, onNodeClick: onNodeClickProp, fitViewToNodeIds, fitViewPadding = 0.2, draggableNodeIds, onNodeDragStop: onNodeDragStopProp, onCopy }) => {
87351
87366
  const { fitView: fitView2, fitBounds, getNodes } = useReactFlow();
87352
87367
  const updateNodeInternals2 = useUpdateNodeInternals();
87353
87368
  const { theme: theme2 } = useTheme();
@@ -87441,6 +87456,18 @@ const GraphRendererInner = ({ configuration, nodes: propNodes, edges: propEdges,
87441
87456
  onEditStateChange == null ? void 0 : onEditStateChange(newState);
87442
87457
  onPendingChangesChange == null ? void 0 : onPendingChangesChange(hasChanges);
87443
87458
  }, [editStateRef, onEditStateChange, onPendingChangesChange, checkHasChanges]);
87459
+ const handleNodeResizeEnd = useCallback((nodeId, dimensions) => {
87460
+ if (!editable)
87461
+ return;
87462
+ updateEditState((prev) => {
87463
+ const newDimensions = new Map(prev.dimensionChanges);
87464
+ newDimensions.set(nodeId, dimensions);
87465
+ return { ...prev, dimensionChanges: newDimensions };
87466
+ });
87467
+ }, [editable, updateEditState]);
87468
+ const graphEditContextValue = useMemo(() => ({
87469
+ onNodeResizeEnd: handleNodeResizeEnd
87470
+ }), [handleNodeResizeEnd]);
87444
87471
  const detectAlignmentGuides = useCallback((draggingNodeId, nodes2) => {
87445
87472
  const threshold = 5;
87446
87473
  const guides = [];
@@ -88024,21 +88051,6 @@ const GraphRendererInner = ({ configuration, nodes: propNodes, edges: propEdges,
88024
88051
  });
88025
88052
  }
88026
88053
  const positionChanges = changes.filter((change) => change.type === "position" && "position" in change && change.position !== void 0 && "dragging" in change && change.dragging === false);
88027
- const dimensionChanges = changes.filter((change) => change.type === "dimensions" && "dimensions" in change && change.dimensions !== void 0 && "resizing" in change && change.resizing === false);
88028
- if (dimensionChanges.length > 0) {
88029
- updateEditState((prev) => {
88030
- const newDimensions = new Map(prev.dimensionChanges);
88031
- for (const change of dimensionChanges) {
88032
- if (change.dimensions) {
88033
- newDimensions.set(change.id, {
88034
- width: Math.round(change.dimensions.width),
88035
- height: Math.round(change.dimensions.height)
88036
- });
88037
- }
88038
- }
88039
- return { ...prev, dimensionChanges: newDimensions };
88040
- });
88041
- }
88042
88054
  if (positionChanges.length > 0) {
88043
88055
  updateEditState((prev) => {
88044
88056
  const newPositions = new Map(prev.positionChanges);
@@ -88104,6 +88116,13 @@ const GraphRendererInner = ({ configuration, nodes: propNodes, edges: propEdges,
88104
88116
  setXyflowLocalEdges(xyflowEdgesBase);
88105
88117
  }
88106
88118
  }, [baseEdgesKey, xyflowEdgesBase]);
88119
+ useEffect(() => {
88120
+ resetVisualStateRef.current = () => {
88121
+ setXyflowLocalNodes(xyflowNodesBase);
88122
+ setXyflowLocalEdges(xyflowEdgesBase);
88123
+ onPendingChangesChange == null ? void 0 : onPendingChangesChange(false);
88124
+ };
88125
+ }, [xyflowNodesBase, xyflowEdgesBase, onPendingChangesChange]);
88107
88126
  const xyflowEdges = editable ? xyflowLocalEdges : xyflowEdgesBase;
88108
88127
  const handleEdgesChange = useCallback((changes) => {
88109
88128
  if (!editable)
@@ -88159,7 +88178,7 @@ const GraphRendererInner = ({ configuration, nodes: propNodes, edges: propEdges,
88159
88178
  }, 150);
88160
88179
  return () => clearTimeout(timeoutId);
88161
88180
  }, [fitViewToNodeIdsKey, fitViewToNodeIds, fitViewPadding, fitView2, fitViewDuration, getNodes, fitBounds]);
88162
- return jsxs(Fragment, { children: [jsxs(index$2, { nodes: xyflowNodes, edges: xyflowEdges, nodeTypes, edgeTypes, minZoom: 0.1, maxZoom: 4, defaultEdgeOptions: { type: "custom" }, onEdgeClick, onNodeClick, onNodeDoubleClick, onNodeDrag: handleNodeDrag, onNodeDragStop: handleNodeDragStop, proOptions: { hideAttribution: true }, nodesDraggable: editable || draggableNodeIds && draggableNodeIds.size > 0, elementsSelectable: editable, selectNodesOnDrag: false, nodesConnectable: editable, edgesReconnectable: editable, reconnectRadius: 25, elevateEdgesOnSelect: true, onNodesChange: handleNodesChange, onEdgesChange: handleEdgesChange, onConnect: handleConnect, onReconnectStart: handleReconnectStart, onReconnect: handleReconnect, onReconnectEnd: handleReconnectEnd, onPaneClick, onSelectionChange: handleSelectionChange, panOnDrag: !editable, panOnScroll: true, zoomOnScroll: false, zoomOnPinch: true, zoomOnDoubleClick: false, selectionOnDrag: false, selectionKeyCode: null, multiSelectionKeyCode: "Shift", children: [showBackground && jsx(Background, { color: backgroundVariant === "dots" ? theme2.colors.border : theme2.colors.textMuted, gap: backgroundGap ?? (backgroundVariant === "dots" ? 16 : 50), size: backgroundVariant === "dots" ? 1 : 0.5, variant: backgroundVariant === "dots" ? BackgroundVariant.Dots : backgroundVariant === "lines" ? BackgroundVariant.Lines : BackgroundVariant.Cross }), showControls && jsx(Controls, { showZoom: true, showFitView: true, showInteractive: true }), showMinimap && jsx(MiniMap, { nodeColor: (node2) => {
88181
+ return jsxs(GraphEditProvider, { value: graphEditContextValue, children: [jsxs(index$2, { nodes: xyflowNodes, edges: xyflowEdges, nodeTypes, edgeTypes, minZoom: 0.1, maxZoom: 4, defaultEdgeOptions: { type: "custom" }, onEdgeClick, onNodeClick, onNodeDoubleClick, onNodeDrag: handleNodeDrag, onNodeDragStop: handleNodeDragStop, proOptions: { hideAttribution: true }, nodesDraggable: editable || draggableNodeIds && draggableNodeIds.size > 0, elementsSelectable: editable, selectNodesOnDrag: false, nodesConnectable: editable, edgesReconnectable: editable, reconnectRadius: 25, elevateEdgesOnSelect: true, onNodesChange: handleNodesChange, onEdgesChange: handleEdgesChange, onConnect: handleConnect, onReconnectStart: handleReconnectStart, onReconnect: handleReconnect, onReconnectEnd: handleReconnectEnd, onPaneClick, onSelectionChange: handleSelectionChange, panOnDrag: !editable, panOnScroll: true, zoomOnScroll: false, zoomOnPinch: true, zoomOnDoubleClick: false, selectionOnDrag: false, selectionKeyCode: null, multiSelectionKeyCode: "Shift", children: [showBackground && jsx(Background, { color: backgroundVariant === "dots" ? theme2.colors.border : theme2.colors.textMuted, gap: backgroundGap ?? (backgroundVariant === "dots" ? 16 : 50), size: backgroundVariant === "dots" ? 1 : 0.5, variant: backgroundVariant === "dots" ? BackgroundVariant.Dots : backgroundVariant === "lines" ? BackgroundVariant.Lines : BackgroundVariant.Cross }), showControls && jsx(Controls, { showZoom: true, showFitView: true, showInteractive: true }), showMinimap && jsx(MiniMap, { nodeColor: (node2) => {
88163
88182
  var _a;
88164
88183
  const nodeData = node2.data;
88165
88184
  return ((_a = nodeData == null ? void 0 : nodeData.typeDefinition) == null ? void 0 : _a.color) || theme2.colors.secondary;
@@ -88329,6 +88348,7 @@ const GraphRenderer = forwardRef((props2, ref) => {
88329
88348
  }, []);
88330
88349
  const canvasData = useCanvasToLegacy(canvas, library);
88331
88350
  const editStateRef = useRef(createEmptyEditState());
88351
+ const resetVisualStateRef = useRef(null);
88332
88352
  useImperativeHandle(ref, () => ({
88333
88353
  getPendingChanges: () => {
88334
88354
  const state = editStateRef.current;
@@ -88358,7 +88378,9 @@ const GraphRenderer = forwardRef((props2, ref) => {
88358
88378
  };
88359
88379
  },
88360
88380
  resetEditState: () => {
88381
+ var _a;
88361
88382
  editStateRef.current = createEmptyEditState();
88383
+ (_a = resetVisualStateRef.current) == null ? void 0 : _a.call(resetVisualStateRef);
88362
88384
  },
88363
88385
  hasUnsavedChanges: () => {
88364
88386
  const state = editStateRef.current;
@@ -88378,7 +88400,7 @@ const GraphRenderer = forwardRef((props2, ref) => {
88378
88400
  }
88379
88401
  const { configuration, nodes, edges } = canvasData;
88380
88402
  const { violations, configName, showMinimap, showControls, showBackground, backgroundVariant, backgroundGap, showCenterIndicator, showTooltips, fitViewDuration, highlightedNodeId, activeNodeIds, events, onEventProcessed, editable, onPendingChangesChange, onNodeClick, fitViewToNodeIds, fitViewPadding, draggableNodeIds, onNodeDragStop, onCopy } = props2;
88381
- return jsx("div", { ref: containerRef, className, style: { width, height, position: "relative" }, children: jsx(TooltipPortalContext.Provider, { value: portalTarget, children: jsx(ReactFlowProvider, { children: jsx(GraphRendererInner, { configuration, nodes, edges, violations, configName, showMinimap, showControls, showBackground, backgroundVariant, backgroundGap, showCenterIndicator, showTooltips, fitViewDuration, highlightedNodeId, activeNodeIds, events, onEventProcessed, editable, onPendingChangesChange, editStateRef, onNodeClick, fitViewToNodeIds, fitViewPadding, draggableNodeIds, onNodeDragStop, onCopy }) }) }) });
88403
+ return jsx("div", { ref: containerRef, className, style: { width, height, position: "relative" }, children: jsx(TooltipPortalContext.Provider, { value: portalTarget, children: jsx(ReactFlowProvider, { children: jsx(GraphRendererInner, { configuration, nodes, edges, violations, configName, showMinimap, showControls, showBackground, backgroundVariant, backgroundGap, showCenterIndicator, showTooltips, fitViewDuration, highlightedNodeId, activeNodeIds, events, onEventProcessed, editable, onPendingChangesChange, editStateRef, resetVisualStateRef, onNodeClick, fitViewToNodeIds, fitViewPadding, draggableNodeIds, onNodeDragStop, onCopy }) }) }) });
88382
88404
  });
88383
88405
  GraphRenderer.displayName = "GraphRenderer";
88384
88406
  const DEFAULT_NODE_WIDTH = 200;