@likec4/diagram 1.27.0 → 1.27.1

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.
Files changed (57) hide show
  1. package/bundle/index.js +327 -281
  2. package/dist/LikeC4Diagram.js +2 -8
  3. package/dist/base/primitives/compound/CompoundNodeContainer.js +1 -1
  4. package/dist/base/primitives/edge/EdgeLabel.css.js +1 -4
  5. package/dist/base/primitives/edge/EdgeLabelContainer.js +1 -1
  6. package/dist/base/primitives/edge/EdgePath.js +0 -3
  7. package/dist/base/primitives/edge/edge.css.js +2 -0
  8. package/dist/base/primitives/element/ElementNodeContainer.css.js +1 -0
  9. package/dist/base/primitives/element/ElementShape.css.js +1 -12
  10. package/dist/base/primitives/element/ElementTitle.css.js +3 -2
  11. package/dist/base/types.js +2 -2
  12. package/dist/components/Link.js +1 -1
  13. package/dist/hooks/useDiagram.d.ts +320 -490
  14. package/dist/likec4diagram/DiagramXYFlow.js +10 -9
  15. package/dist/likec4diagram/custom/edges/RelationshipEdge.js +30 -41
  16. package/dist/likec4diagram/custom/nodes/toolbar/Toolbar.js +1 -1
  17. package/dist/likec4diagram/custom/nodes/toolbar/styles.css.js +6 -1
  18. package/dist/likec4diagram/ui/controls/LayoutDriftNotification.js +13 -5
  19. package/dist/likec4diagram/useLayoutConstraints.d.ts +11 -10
  20. package/dist/likec4diagram/useLayoutConstraints.js +64 -61
  21. package/dist/overlays/Overlays.js +2 -2
  22. package/dist/overlays/overlay/Overlay.css.js +31 -12
  23. package/dist/overlays/overlay/Overlay.js +30 -27
  24. package/dist/overlays/relationship-details/useLayoutedDetails.js +1 -1
  25. package/dist/overlays/relationships-browser/SelectElement.js +4 -4
  26. package/dist/state/DiagramActorProvider.d.ts +4 -2
  27. package/dist/state/DiagramActorProvider.js +30 -37
  28. package/dist/state/assign.js +2 -2
  29. package/dist/state/diagram-machine.d.ts +450 -608
  30. package/dist/state/diagram-machine.js +87 -57
  31. package/dist/styles.css.js +1 -1
  32. package/package.json +5 -5
  33. package/src/LikeC4Diagram.tsx +1 -7
  34. package/src/base/primitives/compound/CompoundNodeContainer.tsx +1 -1
  35. package/src/base/primitives/edge/EdgeLabel.css.ts +1 -4
  36. package/src/base/primitives/edge/EdgeLabelContainer.tsx +1 -1
  37. package/src/base/primitives/edge/EdgePath.tsx +0 -3
  38. package/src/base/primitives/edge/edge.css.ts +2 -0
  39. package/src/base/primitives/element/ElementNodeContainer.css.ts +1 -0
  40. package/src/base/primitives/element/ElementShape.css.ts +1 -12
  41. package/src/base/primitives/element/ElementTitle.css.ts +3 -2
  42. package/src/base/types.ts +2 -7
  43. package/src/components/Link.tsx +3 -1
  44. package/src/likec4diagram/DiagramXYFlow.tsx +11 -9
  45. package/src/likec4diagram/custom/edges/RelationshipEdge.tsx +39 -48
  46. package/src/likec4diagram/custom/nodes/toolbar/Toolbar.tsx +2 -2
  47. package/src/likec4diagram/custom/nodes/toolbar/styles.css.ts +5 -0
  48. package/src/likec4diagram/ui/controls/LayoutDriftNotification.tsx +8 -4
  49. package/src/likec4diagram/useLayoutConstraints.ts +84 -89
  50. package/src/overlays/Overlays.tsx +2 -2
  51. package/src/overlays/overlay/Overlay.css.ts +30 -12
  52. package/src/overlays/overlay/Overlay.tsx +35 -29
  53. package/src/overlays/relationship-details/useLayoutedDetails.ts +1 -1
  54. package/src/overlays/relationships-browser/SelectElement.tsx +5 -5
  55. package/src/state/DiagramActorProvider.tsx +40 -50
  56. package/src/state/assign.ts +2 -2
  57. package/src/state/diagram-machine.ts +100 -69
@@ -1,4 +1,4 @@
1
- import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
1
+ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
2
2
  import { ancestorsFqn } from '@likec4/core';
3
3
  import { useTree, Group, Box, Popover, PopoverTarget, Button, Text, PopoverDropdown, ScrollAreaAutosize, Tree, ActionIcon, Tooltip, SegmentedControl } from '@mantine/core';
4
4
  import { IconSelector, IconChevronRight } from '@tabler/icons-react';
@@ -44,8 +44,8 @@ const SelectElement = memo(() => {
44
44
  });
45
45
  tree.select(subjectId);
46
46
  }, [subjectId]);
47
- return /* @__PURE__ */ jsxs(Group, { ref: root, gap: "xs", wrap: "nowrap", pos: "relative", children: [
48
- enableSelectSubject && /* @__PURE__ */ jsxs(Fragment, { children: [
47
+ return /* @__PURE__ */ jsxs(Group, { ref: root, gap: "xs", pos: "relative", children: [
48
+ enableSelectSubject && /* @__PURE__ */ jsxs(Group, { gap: 4, wrap: "nowrap", children: [
49
49
  /* @__PURE__ */ jsx(
50
50
  Box,
51
51
  {
@@ -153,7 +153,7 @@ const SelectElement = memo(() => {
153
153
  }
154
154
  ) })
155
155
  ] }),
156
- enableChangeScope && /* @__PURE__ */ jsxs(Fragment, { children: [
156
+ enableChangeScope && /* @__PURE__ */ jsxs(Group, { gap: 4, wrap: "nowrap", children: [
157
157
  enableSelectSubject && /* @__PURE__ */ jsx(
158
158
  Box,
159
159
  {
@@ -1,7 +1,9 @@
1
+ import { WhereOperator } from '@likec4/core';
1
2
  import { PropsWithChildren } from 'react';
2
3
  import { Input } from './diagram-machine';
3
- type ActorContextInput = Omit<Input, 'xystore' | 'features'>;
4
- export declare function DiagramActorProvider({ input, children }: PropsWithChildren<{
4
+ type ActorContextInput = Omit<Input, 'xystore' | 'xynodes' | 'xyedges'>;
5
+ export declare function DiagramActorProvider({ input: { view, ...inputs }, where, children, }: PropsWithChildren<{
5
6
  input: ActorContextInput;
7
+ where?: WhereOperator<string, string> | undefined;
6
8
  }>): import("react/jsx-runtime").JSX.Element;
7
9
  export {};
@@ -1,20 +1,30 @@
1
- import { jsxs, jsx } from 'react/jsx-runtime';
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import { useDeepCompareEffect } from '@react-hookz/web';
2
3
  import { useActorRef, useSelector } from '@xstate/react';
3
4
  import { useStoreApi } from '@xyflow/react';
4
5
  import { shallowEqual } from 'fast-equals';
5
- import { useMemo, useEffect, useRef } from 'react';
6
+ import { useEffect } from 'react';
6
7
  import { useDiagramEventHandlersRef } from '../context/DiagramEventHandlers.js';
7
8
  import { useEnabledFeatures, DiagramFeatures } from '../context/DiagramFeatures.js';
8
9
  import { DiagramActorSafeContext } from '../hooks/safeContext.js';
9
10
  import { useUpdateEffect } from '../hooks/useUpdateEffect.js';
11
+ import { useViewToNodesEdges } from '../likec4diagram/useViewToNodesEdges.js';
10
12
  import { diagramMachine } from './diagram-machine.js';
11
13
  import { syncManualLayoutActorLogic } from './syncManualLayoutActor.js';
12
14
 
13
- function DiagramActorProvider({ input, children }) {
15
+ const selectToggledFeatures = (state) => state.context.toggledFeatures;
16
+ function DiagramActorProvider({
17
+ input: {
18
+ view,
19
+ ...inputs
20
+ },
21
+ where,
22
+ children
23
+ }) {
14
24
  const handlersRef = useDiagramEventHandlersRef();
15
25
  const xystore = useStoreApi();
16
- const logic = useMemo(() => {
17
- return diagramMachine.provide({
26
+ const actorRef = useActorRef(
27
+ diagramMachine.provide({
18
28
  actions: {
19
29
  "trigger:NavigateTo": (_, { viewId }) => {
20
30
  handlersRef.current.onNavigateTo?.(viewId);
@@ -35,52 +45,35 @@ function DiagramActorProvider({ input, children }) {
35
45
  }
36
46
  })
37
47
  }
38
- });
39
- }, [handlersRef]);
40
- const actorRef = useActorRef(
41
- logic,
48
+ }),
42
49
  {
43
- id: `diagram:${input.view.id}`,
50
+ id: `diagram:${view.id}`,
44
51
  systemId: "diagram",
45
52
  // ...inspector,
46
53
  input: {
47
54
  xystore,
48
- ...input
55
+ view,
56
+ ...inputs
49
57
  }
50
58
  }
51
59
  );
52
- return /* @__PURE__ */ jsxs(DiagramActorSafeContext, { value: actorRef, children: [
53
- /* @__PURE__ */ jsx(SyncStore, { input, actorRef }),
54
- /* @__PURE__ */ jsx(DiagramActorToggledFeatures, { actorRef, children })
55
- ] });
56
- }
57
- const SyncStore = ({ input: { view, xyedges, xynodes, ...inputs }, actorRef }) => {
58
60
  const features = useEnabledFeatures();
59
61
  useUpdateEffect(() => {
60
62
  actorRef.send({ type: "update.inputs", inputs });
61
- }, [actorRef, inputs]);
63
+ }, [inputs]);
62
64
  useEffect(() => {
63
65
  actorRef.send({ type: "update.features", features });
64
- }, [actorRef, features]);
65
- const frameReq = useRef(null);
66
- useUpdateEffect(() => {
67
- frameReq.current = requestAnimationFrame(() => {
68
- frameReq.current = null;
69
- actorRef.send({ type: "update.view", view, xyedges, xynodes });
70
- });
71
- return () => {
72
- if (frameReq.current != null) {
73
- cancelAnimationFrame(frameReq.current);
74
- }
75
- frameReq.current = null;
76
- };
77
- }, [actorRef, view, xyedges, xynodes]);
78
- return null;
79
- };
80
- const selectToggledFeatures = (state) => state.context.toggledFeatures;
81
- function DiagramActorToggledFeatures({ children, actorRef }) {
66
+ }, [features]);
67
+ const { xyedges, xynodes } = useViewToNodesEdges({
68
+ view,
69
+ where,
70
+ nodesSelectable: inputs.nodesSelectable
71
+ });
72
+ useDeepCompareEffect(() => {
73
+ actorRef.send({ type: "update.view", view, xyedges, xynodes });
74
+ }, [view, xyedges, xynodes]);
82
75
  const toggledFeatures = useSelector(actorRef, selectToggledFeatures, shallowEqual);
83
- return /* @__PURE__ */ jsx(DiagramFeatures, { overrides: toggledFeatures, children });
76
+ return /* @__PURE__ */ jsx(DiagramActorSafeContext, { value: actorRef, children: /* @__PURE__ */ jsx(DiagramFeatures, { overrides: toggledFeatures, children }) });
84
77
  }
85
78
 
86
79
  export { DiagramActorProvider };
@@ -338,8 +338,8 @@ function updateActiveWalkthrough({ context }) {
338
338
  });
339
339
  }),
340
340
  xynodes: context.xynodes.map((node) => {
341
- const active = step.source === node.id || step.target === node.id;
342
- return Base.setDimmed(node, !active);
341
+ const dimmed = step.source !== node.id && step.target !== node.id;
342
+ return Base.setDimmed(node, dimmed);
343
343
  })
344
344
  };
345
345
  }