likec4 0.57.1 → 0.60.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.
@@ -3,5 +3,5 @@ export function isString(value) {
3
3
  return value != null && typeof value === "string";
4
4
  }
5
5
  export function isNonEmptyArray(arr) {
6
- return arr.length > 0;
6
+ return !!arr && Array.isArray(arr) && arr.length > 0;
7
7
  }
@@ -1,9 +1,9 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
- import { nonNullable, defaultTheme as theme } from "@likec4/core";
2
+ import { defaultTheme as theme, nonNullable } from "@likec4/core";
3
3
  import { useHookableRef, useUpdateEffect } from "@react-hookz/web";
4
4
  import { useSpring } from "@react-spring/konva";
5
5
  import { clamp, isNil } from "rambdax";
6
- import { forwardRef, useEffect, useImperativeHandle, useRef } from "react";
6
+ import { forwardRef, useCallback, useEffect, useImperativeHandle, useRef } from "react";
7
7
  import { AnimatedStage, Layer } from "../konva.js";
8
8
  import { Edges } from "./Edges.js";
9
9
  import { createUseGesture, dragAction, pinchAction } from "@use-gesture/react";
@@ -36,8 +36,8 @@ const DiagramKonva = /* @__PURE__ */ forwardRef(
36
36
  zoomable = true,
37
37
  animate = true,
38
38
  initialPosition,
39
- onEdgeClick,
40
- onNodeClick,
39
+ onEdgeClick: _onEdgeClick,
40
+ onNodeClick: _onNodeClick,
41
41
  onNodeContextMenu,
42
42
  onStageClick,
43
43
  onStageContextMenu,
@@ -49,6 +49,10 @@ const DiagramKonva = /* @__PURE__ */ forwardRef(
49
49
  }, ref) => {
50
50
  const immediate = !animate;
51
51
  const id = diagram.id;
52
+ const handlersRef = useSyncedRef({
53
+ onEdgeClick: _onEdgeClick,
54
+ onNodeClick: _onNodeClick
55
+ });
52
56
  const containerRef = useRef(null);
53
57
  const stageRef = useHookableRef(null, (value) => {
54
58
  containerRef.current = value?.container() ?? null;
@@ -60,6 +64,18 @@ const DiagramKonva = /* @__PURE__ */ forwardRef(
60
64
  const [paddingTop, paddingRight, paddingBottom, paddingLeft] = isNumber(padding) ? [padding, padding, padding, padding] : padding;
61
65
  const width = _width ?? diagram.width + paddingLeft + paddingRight;
62
66
  const height = _height ?? diagram.height + paddingTop + paddingBottom;
67
+ const onNodeClick = useCallback(
68
+ (node, e) => {
69
+ handlersRef.current.onNodeClick?.(node, e);
70
+ },
71
+ [handlersRef]
72
+ );
73
+ const onEdgeClick = useCallback(
74
+ (edge, e) => {
75
+ handlersRef.current.onEdgeClick?.(edge, e);
76
+ },
77
+ [handlersRef]
78
+ );
63
79
  const toCenterOnRect = (centerTo, opts) => {
64
80
  const keepZoom = opts?.keepZoom ?? false;
65
81
  const container = containerRef.current;
@@ -341,8 +357,8 @@ const DiagramKonva = /* @__PURE__ */ forwardRef(
341
357
  scaleX: 1,
342
358
  scaleY: 1,
343
359
  children: [
344
- /* @__PURE__ */ jsx(Nodes, { ...sharedProps, onNodeClick }),
345
- /* @__PURE__ */ jsx(Edges, { ...sharedProps, onEdgeClick })
360
+ /* @__PURE__ */ jsx(Nodes, { ...sharedProps, onNodeClick: _onNodeClick ? onNodeClick : void 0 }),
361
+ /* @__PURE__ */ jsx(Edges, { ...sharedProps, onEdgeClick: _onEdgeClick ? onEdgeClick : void 0 })
346
362
  ]
347
363
  }
348
364
  ),
@@ -239,6 +239,6 @@ const NodeShape = memo(
239
239
  }
240
240
  ) });
241
241
  },
242
- isEqualSimple
242
+ (a, b) => isEqualSimple(a.node, b.node) && a.isHovered === b.isHovered && a.expired === b.expired
243
243
  );
244
244
  NodeShape.displayName = "NodeShape";