@likec4/diagram 1.38.0 → 1.39.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.
Files changed (86) hide show
  1. package/bundle/{chunk-BZV0K82k.js → chunk-Bg7UjtMS.js} +332 -326
  2. package/bundle/custom.js +59 -59
  3. package/bundle/index.js +244 -170
  4. package/dist/LikeC4Diagram.props.d.ts +15 -8
  5. package/dist/base/BaseXYFlow.js +5 -5
  6. package/dist/base/index.d.ts +1 -2
  7. package/dist/base/primitives/MarkdownBlock.js +2 -1
  8. package/dist/base/primitives/customEdge.d.ts +3 -3
  9. package/dist/base/primitives/element/ElementTitle.js +2 -10
  10. package/dist/base/types.d.ts +62 -5
  11. package/dist/base/types.js +54 -0
  12. package/dist/bundle/LikeC4View.d.ts +2 -2
  13. package/dist/bundle/LikeC4View.props.d.ts +4 -3
  14. package/dist/bundle/ReactLikeC4.d.ts +4 -4
  15. package/dist/custom/customNodes.d.ts +2 -1
  16. package/dist/hooks/useXYFlow.d.ts +28 -29
  17. package/dist/likec4diagram/custom/edges/RelationshipEdge.d.ts +4 -5
  18. package/dist/likec4diagram/custom/nodes/ElementActions.js +1 -1
  19. package/dist/likec4diagram/types.d.ts +2 -1
  20. package/dist/likec4diagram/useViewToNodesEdges.js +1 -1
  21. package/dist/likec4model/LikeC4ModelContext.d.ts +5 -2
  22. package/dist/likec4model/useLikeC4ElementsTree.js +1 -1
  23. package/dist/likec4model/useLikeC4Model.d.ts +7 -20
  24. package/dist/navigationpanel/NavigationPanel.js +3 -1
  25. package/dist/navigationpanel/NavigationPanelDropdown.js +1 -1
  26. package/dist/navigationpanel/walkthrough/ActiveWalkthroughControls.js +6 -4
  27. package/dist/navigationpanel/walkthrough/WalkthroughPanel.d.ts +1 -0
  28. package/dist/navigationpanel/walkthrough/WalkthroughPanel.js +83 -0
  29. package/dist/overlays/element-details/actor.d.ts +556 -557
  30. package/dist/overlays/relationship-details/RelationshipDetails.d.ts +2 -3
  31. package/dist/overlays/relationship-details/actor.d.ts +1 -1
  32. package/dist/overlays/relationship-details/actor.js +7 -7
  33. package/dist/overlays/relationship-details/compute.js +2 -1
  34. package/dist/overlays/relationship-details/custom/edgeTypes.d.ts +2 -3
  35. package/dist/overlays/relationship-details/hooks.d.ts +18 -19
  36. package/dist/overlays/relationship-details/layout.js +2 -1
  37. package/dist/overlays/relationships-browser/RelationshipsBrowser.d.ts +2 -3
  38. package/dist/overlays/relationships-browser/actor.d.ts +12 -12
  39. package/dist/overlays/relationships-browser/actor.js +8 -8
  40. package/dist/overlays/relationships-browser/custom/edgeTypes.d.ts +2 -3
  41. package/dist/overlays/relationships-browser/layout.js +2 -1
  42. package/dist/search/components/ElementsColumn.js +1 -1
  43. package/dist/state/DiagramActorProvider.js +2 -2
  44. package/dist/state/assign.js +6 -6
  45. package/dist/state/diagram-machine.js +14 -14
  46. package/dist/styles-min.css +1 -1
  47. package/dist/styles-xyflow.css +1 -1
  48. package/dist/styles.css +1 -1
  49. package/dist/styles.css2.js +1 -1
  50. package/dist/utils/xyflow.js +2 -2
  51. package/package.json +16 -16
  52. package/panda.buildinfo.json +14 -11
  53. package/src/LikeC4Diagram.props.ts +16 -16
  54. package/src/base/index.ts +1 -2
  55. package/src/base/primitives/MarkdownBlock.tsx +1 -0
  56. package/src/base/primitives/customEdge.ts +5 -5
  57. package/src/base/primitives/element/ElementTitle.tsx +10 -22
  58. package/src/base/types.ts +122 -13
  59. package/src/bundle/LikeC4View.props.ts +4 -3
  60. package/src/bundle/LikeC4View.tsx +6 -6
  61. package/src/bundle/ReactLikeC4.tsx +7 -6
  62. package/src/custom/customNodes.ts +3 -1
  63. package/src/hooks/useSetState.ts +2 -2
  64. package/src/likec4diagram/custom/nodes/ElementActions.tsx +2 -1
  65. package/src/likec4diagram/types.ts +1 -1
  66. package/src/likec4diagram/useViewToNodesEdges.ts +1 -1
  67. package/src/likec4model/LikeC4ModelContext.tsx +5 -2
  68. package/src/likec4model/useLikeC4ElementsTree.ts +3 -3
  69. package/src/likec4model/useLikeC4Model.ts +8 -5
  70. package/src/navigationpanel/NavigationPanel.tsx +2 -0
  71. package/src/navigationpanel/NavigationPanelDropdown.tsx +1 -1
  72. package/src/navigationpanel/walkthrough/ActiveWalkthroughControls.tsx +3 -1
  73. package/src/navigationpanel/walkthrough/WalkthroughPanel.tsx +88 -0
  74. package/src/overlays/relationship-details/compute.ts +3 -12
  75. package/src/overlays/relationship-details/layout.ts +3 -3
  76. package/src/overlays/relationships-browser/actor.ts +2 -1
  77. package/src/overlays/relationships-browser/layout.ts +3 -3
  78. package/src/search/components/ElementsColumn.tsx +3 -3
  79. package/src/utils/xyflow.ts +2 -2
  80. package/dist/base/types.Base.d.ts +0 -54
  81. package/dist/base/types.Base.js +0 -48
  82. package/dist/likec4diagram/custom/edges/NotePopover.d.ts +0 -4
  83. package/src/base/types.Base.ts +0 -104
  84. package/src/likec4diagram/custom/edges/NotePopover.tsx +0 -95
  85. /package/dist/{likec4diagram/custom/edges/NotePopover.css.d.ts → navigationpanel/walkthrough/WalkthroughPanel.css.d.ts} +0 -0
  86. /package/src/{likec4diagram/custom/edges/NotePopover.css.ts → navigationpanel/walkthrough/WalkthroughPanel.css.ts} +0 -0
@@ -1,9 +1,12 @@
1
- import type { aux, LikeC4Model, LikeC4ViewModel } from '@likec4/core/model'
1
+ import type { LikeC4Model, LikeC4ViewModel } from '@likec4/core/model'
2
+ import type * as t from '@likec4/core/types'
2
3
  import { deepEqual } from 'fast-equals'
3
4
  import { useContext, useEffect, useState } from 'react'
4
5
  import { LikeC4ModelContext } from './LikeC4ModelContext'
5
6
 
6
- export function useLikeC4Model<A extends aux.Any = aux.UnknownLayouted>(): LikeC4Model<A> {
7
+ type Any = t.aux.Any
8
+
9
+ export function useLikeC4Model<A extends Any = t.aux.UnknownLayouted>(): LikeC4Model<A> {
7
10
  const model = useContext(LikeC4ModelContext)
8
11
  if (!model) {
9
12
  throw new Error('LikeC4Model not found. Make sure you have LikeC4ModelProvider.')
@@ -11,8 +14,8 @@ export function useLikeC4Model<A extends aux.Any = aux.UnknownLayouted>(): LikeC
11
14
  return model
12
15
  }
13
16
 
14
- export function useLikeC4ViewModel<A extends aux.Any = aux.UnknownLayouted>(
15
- viewId: aux.ViewId<A>,
17
+ export function useLikeC4ViewModel<A extends Any = t.aux.UnknownLayouted>(
18
+ viewId: t.aux.ViewId<A>,
16
19
  ): LikeC4ViewModel<A> {
17
20
  const model = useLikeC4Model<A>()
18
21
  // const [view, setView] = useState(() => model.findView(viewId))
@@ -22,7 +25,7 @@ export function useLikeC4ViewModel<A extends aux.Any = aux.UnknownLayouted>(
22
25
  return model.view(viewId)
23
26
  }
24
27
 
25
- export function useLikeC4Specification() {
28
+ export function useLikeC4Specification(): t.Specification<t.aux.UnknownLayouted> {
26
29
  const model = useLikeC4Model()
27
30
  const [specification, setSpecification] = useState(model.$data.specification)
28
31
  useEffect(() => {
@@ -20,6 +20,7 @@ import { NavigationPanelActorContextProvider } from './hooks'
20
20
  import { NavigationPanelControls } from './NavigationPanelControls'
21
21
  import { NavigationPanelDropdown } from './NavigationPanelDropdown'
22
22
  import { ActiveWalkthroughControls } from './walkthrough'
23
+ import { WalkthroughPanel } from './walkthrough/WalkthroughPanel'
23
24
 
24
25
  export const NavigationPanel = memo(() => {
25
26
  const diagramActor = useDiagramActorRef()
@@ -77,6 +78,7 @@ export const NavigationPanel = memo(() => {
77
78
  <NavigationPanelActorContextProvider value={actorRef}>
78
79
  <NavigationPanelImpl actor={actorRef} />
79
80
  <EditorPanel />
81
+ <WalkthroughPanel />
80
82
  </NavigationPanelActorContextProvider>
81
83
  </VStack>
82
84
  </Portal>
@@ -1,6 +1,6 @@
1
- import { compareNaturalHierarchically, ifilter, ifirst, nonexhaustive, toArray } from '@likec4/core'
2
1
  import { type LikeC4ViewsFolder, LikeC4ViewModel, normalizeViewPath, VIEW_FOLDERS_SEPARATOR } from '@likec4/core/model'
3
2
  import type { ViewId } from '@likec4/core/types'
3
+ import { compareNaturalHierarchically, ifilter, ifirst, nonexhaustive, toArray } from '@likec4/core/utils'
4
4
  import { css, cx } from '@likec4/styles/css'
5
5
  import { Box, HStack, VStack } from '@likec4/styles/jsx'
6
6
  import { hstack, vstack } from '@likec4/styles/patterns'
@@ -1,3 +1,4 @@
1
+ import { RichText } from '@likec4/core'
1
2
  import { css } from '@likec4/styles/css'
2
3
  import { Box } from '@likec4/styles/jsx'
3
4
  import { Badge, Button, Portal } from '@mantine/core'
@@ -89,6 +90,7 @@ export const ActiveWalkthroughControls = () => {
89
90
  hasPrevious,
90
91
  currentStep,
91
92
  totalSteps,
93
+ notes,
92
94
  } = useDiagramContext(s => {
93
95
  const currentStepIndex = s.xyedges.findIndex(e => e.id === s.activeWalkthrough?.stepId)
94
96
  return ({
@@ -97,13 +99,13 @@ export const ActiveWalkthroughControls = () => {
97
99
  hasPrevious: currentStepIndex > 0,
98
100
  currentStep: currentStepIndex + 1,
99
101
  totalSteps: s.xyedges.length,
102
+ notes: s.xyedges[currentStepIndex]?.data?.notes ?? RichText.EMPTY,
100
103
  })
101
104
  })
102
105
 
103
106
  return (
104
107
  <AnimatePresence propagate>
105
108
  <TriggerWalkthroughButton
106
- key="trigger-dynamic-walkthrough"
107
109
  variant="light"
108
110
  color="orange"
109
111
  mr={'sm'}
@@ -0,0 +1,88 @@
1
+ import { RichText } from '@likec4/core'
2
+ import { css, cx } from '@likec4/styles/css'
3
+ import { styled } from '@likec4/styles/jsx'
4
+ import { vstack } from '@likec4/styles/patterns'
5
+ import {
6
+ ScrollAreaAutosize,
7
+ } from '@mantine/core'
8
+ import { isNonNull, isTruthy } from 'remeda'
9
+ import { MarkdownBlock } from '../../custom'
10
+ import { useDiagramContext } from '../../hooks/useDiagram'
11
+ import type { DiagramContext } from '../../state/types'
12
+
13
+ const SectionHeader = styled('div', {
14
+ base: {
15
+ fontSize: 'xs',
16
+ color: 'mantine.colors.dimmed',
17
+ fontWeight: 500,
18
+ userSelect: 'none',
19
+ mb: 'xxs',
20
+ },
21
+ })
22
+
23
+ function selectWalkthroughNotes(s: DiagramContext) {
24
+ const isActive = isNonNull(s.activeWalkthrough)
25
+ const activeStepIndex = isActive ? s.xyedges.findIndex(e => e.id === s.activeWalkthrough?.stepId) : -1
26
+ return {
27
+ isActive,
28
+ isParallel: isActive && isTruthy(s.activeWalkthrough?.parallelPrefix),
29
+ hasNext: isActive && activeStepIndex < s.xyedges.length - 1,
30
+ hasPrevious: isActive && activeStepIndex > 0,
31
+ notes: isActive ? s.xyedges[activeStepIndex]?.data?.notes ?? RichText.EMPTY : null,
32
+ }
33
+ }
34
+
35
+ export const WalkthroughPanel = () => {
36
+ const { notes } = useDiagramContext(selectWalkthroughNotes)
37
+
38
+ if (!notes || notes.isEmpty) {
39
+ return null
40
+ }
41
+
42
+ return (
43
+ <styled.div position={'relative'}>
44
+ <ScrollAreaAutosize
45
+ className={cx(
46
+ 'nowheel nopan nodrag',
47
+ vstack({
48
+ position: 'absolute',
49
+ layerStyle: 'likec4.dropdown',
50
+ gap: 'sm',
51
+ padding: 'md',
52
+ paddingTop: 'xxs',
53
+ pointerEvents: 'all',
54
+ maxWidth: 'calc(100cqw - 32px)',
55
+ minWidth: 'calc(100cqw - 50px)',
56
+ maxHeight: 'calc(100cqh - 100px)',
57
+ width: 'max-content',
58
+ cursor: 'default',
59
+ overflow: 'auto',
60
+ overscrollBehavior: 'contain',
61
+ '@/sm': {
62
+ minWidth: 400,
63
+ maxWidth: 550,
64
+ },
65
+ '@/lg': {
66
+ maxWidth: 700,
67
+ },
68
+ }),
69
+ )}
70
+ // miw={180}
71
+ // maw={450}
72
+ // mah={350}
73
+ type="scroll"
74
+ // mt={2}
75
+ >
76
+ <SectionHeader>Notes</SectionHeader>
77
+ <MarkdownBlock
78
+ value={notes}
79
+ fontSize="sm"
80
+ emptyText="No description"
81
+ className={css({
82
+ userSelect: 'all',
83
+ })}
84
+ />
85
+ </ScrollAreaAutosize>
86
+ </styled.div>
87
+ )
88
+ }
@@ -1,23 +1,14 @@
1
- import {
2
- type EdgeId,
3
- type Fqn,
4
- type NonEmptyReadonlyArray,
5
- type RelationId,
6
- hasAtLeast,
7
- invariant,
8
- isAncestor,
9
- sortParentsFirst,
10
- } from '@likec4/core'
1
+ import type { EdgeId, NonEmptyReadonlyArray } from '@likec4/core'
11
2
  import { treeFromElements } from '@likec4/core/compute-view/relationships'
12
3
  import {
13
4
  type AnyAux,
14
- type DeploymentRelationModel,
15
5
  type ElementModel,
16
- type LikeC4Model,
17
6
  type LikeC4ViewModel,
18
7
  type RelationshipModel,
19
8
  modelConnection,
20
9
  } from '@likec4/core/model'
10
+ import { invariant, isAncestor, sortParentsFirst } from '@likec4/core/utils'
11
+ import { hasAtLeast } from 'remeda'
21
12
 
22
13
  export interface RelationshipDetailsViewData {
23
14
  sources: ReadonlySet<ElementModel>
@@ -16,13 +16,13 @@ import type {
16
16
  } from '@likec4/core/types'
17
17
 
18
18
  import dagre, { type EdgeConfig, type GraphLabel } from '@dagrejs/dagre'
19
+ import { RichText } from '@likec4/core'
20
+ import type { AnyAux, ElementModel, LikeC4ViewModel, RelationshipModel } from '@likec4/core/model'
19
21
  import {
20
22
  DefaultMap,
21
23
  ifind,
22
24
  invariant,
23
- RichText,
24
- } from '@likec4/core'
25
- import type { AnyAux, ElementModel, LikeC4ViewModel, RelationshipModel } from '@likec4/core/model'
25
+ } from '@likec4/core/utils'
26
26
  import {
27
27
  filter,
28
28
  find,
@@ -1,4 +1,5 @@
1
- import { type BBox, type Fqn, type ViewId, delay, invariant, nonNullable } from '@likec4/core'
1
+ import type { BBox, Fqn, ViewId } from '@likec4/core'
2
+ import { delay, invariant, nonNullable } from '@likec4/core/utils'
2
3
  import {
3
4
  type EdgeChange,
4
5
  type NodeChange,
@@ -20,15 +20,15 @@ import type {
20
20
  import { useMemo } from 'react'
21
21
 
22
22
  import dagre, { type EdgeConfig, type GraphLabel } from '@dagrejs/dagre'
23
+ import type { ElementModel, LikeC4ViewModel, RelationshipModel } from '@likec4/core/model'
24
+ import { RichText } from '@likec4/core/types'
23
25
  import {
24
26
  DefaultMap,
25
27
  ifind,
26
28
  invariant,
27
29
  nonNullable,
28
- RichText,
29
30
  toArray,
30
- } from '@likec4/core'
31
- import type { ElementModel, LikeC4ViewModel, RelationshipModel } from '@likec4/core/model'
31
+ } from '@likec4/core/utils'
32
32
  import {
33
33
  concat,
34
34
  filter,
@@ -1,11 +1,11 @@
1
+ import type { LikeC4Model } from '@likec4/core/model'
2
+ import type { Fqn } from '@likec4/core/types'
1
3
  import {
2
4
  ifilter,
3
5
  isAncestor,
4
6
  nameFromFqn,
5
7
  sortParentsFirst,
6
- } from '@likec4/core'
7
- import type { LikeC4Model } from '@likec4/core/model'
8
- import type { Fqn } from '@likec4/core/types'
8
+ } from '@likec4/core/utils'
9
9
  import { cx, cx as clsx } from '@likec4/styles/css'
10
10
  import {
11
11
  type RenderTreeNodePayload,
@@ -1,9 +1,9 @@
1
1
  import type { DiagramEdge, NonEmptyArray, Point } from '@likec4/core'
2
- import { hasAtLeast, invariant } from '@likec4/core'
2
+ import { invariant } from '@likec4/core/utils'
3
3
  import type { InternalNode, Rect, XYPosition } from '@xyflow/react'
4
4
  import { getNodeDimensions } from '@xyflow/system'
5
5
  import { Bezier } from 'bezier-js'
6
- import { isArray } from 'remeda'
6
+ import { hasAtLeast, isArray } from 'remeda'
7
7
 
8
8
  export function distance(a: XYPosition, b: XYPosition) {
9
9
  return Math.sqrt(Math.pow(b.x - a.x, 2) + Math.pow(b.y - a.y, 2))
@@ -1,54 +0,0 @@
1
- import { Edge as RFEdge, Node as RFNode, NodeProps as ReactFlowNodeProps } from '@xyflow/react';
2
- import { Simplify } from 'type-fest';
3
- export type Dimmed = 'immediate' | boolean;
4
- export type NodeData = {
5
- /**
6
- * Whether the cursor is hovering over the node
7
- */
8
- hovered?: boolean;
9
- /**
10
- * Whether the node is dimmed
11
- * 'immediate' means that the node is dimmed without delay
12
- */
13
- dimmed?: Dimmed;
14
- };
15
- export type Node = RFNode<NodeData>;
16
- export type NodeProps = ReactFlowNodeProps<RFNode<NodeData, any>>;
17
- export type EdgeData = {
18
- /**
19
- * Whether the cursor is hovering over the edge
20
- */
21
- hovered?: boolean;
22
- /**
23
- * Whether the edge is active (animated and highlighted)
24
- */
25
- active?: boolean;
26
- /**
27
- * Whether the edge is dimmed
28
- * 'immediate' means that the edge is dimmed without delay
29
- */
30
- dimmed?: Dimmed;
31
- };
32
- export type Edge = Simplify<Omit<RFEdge, 'data'> & {
33
- data: EdgeData;
34
- }>;
35
- type WithDimmed = {
36
- data: {
37
- dimmed?: Dimmed;
38
- };
39
- };
40
- type WithHovered = {
41
- data: {
42
- hovered?: boolean;
43
- };
44
- };
45
- export declare function setDimmed<T extends WithDimmed>(value: T, dimmed: 'immediate' | boolean): T;
46
- export declare function setDimmed(dimmed: 'immediate' | boolean): <T extends WithDimmed>(value: T) => T;
47
- export declare function setHovered<T extends WithHovered>(value: T, hovered: boolean): T;
48
- export declare function setHovered(hovered: boolean): <T extends WithHovered>(value: T) => T;
49
- type WithData<D> = {
50
- data: D;
51
- };
52
- export declare function setData<E extends WithData<any>>(value: E, state: Partial<E['data']>): E;
53
- export declare function setData<E extends WithData<any>>(state: Partial<E['data']>): (value: E) => E;
54
- export {};
@@ -1,48 +0,0 @@
1
- import { hasSubObject } from 'remeda';
2
-
3
- const _setDimmed = (v, dimmed) => (v.data.dimmed ?? false) === dimmed ? v : {
4
- ...v,
5
- data: {
6
- ...v.data,
7
- dimmed
8
- }
9
- };
10
- function setDimmed(arg1, arg2) {
11
- if (arg2 !== void 0) {
12
- return _setDimmed(arg1, arg2);
13
- }
14
- return (v) => _setDimmed(v, arg1);
15
- }
16
- const _setHovered = (v, hovered) => (v.data.hovered ?? false) === hovered ? v : {
17
- ...v,
18
- data: {
19
- ...v.data,
20
- hovered
21
- }
22
- };
23
- function setHovered(arg1, arg2) {
24
- if (arg2 !== void 0) {
25
- return _setHovered(arg1, arg2);
26
- }
27
- return (v) => _setHovered(v, arg1);
28
- }
29
- function _setData(value, state) {
30
- if (hasSubObject(value.data, state)) {
31
- return value;
32
- }
33
- return {
34
- ...value,
35
- data: {
36
- ...value.data,
37
- ...state
38
- }
39
- };
40
- }
41
- function setData(arg1, arg2) {
42
- if (arg2 !== void 0) {
43
- return _setData(arg1, arg2);
44
- }
45
- return (edge) => _setData(edge, arg1);
46
- }
47
-
48
- export { setData, setDimmed, setHovered };
@@ -1,4 +0,0 @@
1
- import { PropsWithChildren } from 'react';
2
- export declare const NotePopover: ({ notes, children }: PropsWithChildren<{
3
- notes: string;
4
- }>) => import("react/jsx-runtime").JSX.Element;
@@ -1,104 +0,0 @@
1
- import type {
2
- Edge as RFEdge,
3
- Node as RFNode,
4
- NodeProps as ReactFlowNodeProps,
5
- } from '@xyflow/react'
6
- import { hasSubObject } from 'remeda'
7
- import type { Simplify } from 'type-fest'
8
-
9
- // 'immediate' means that the node is dimmed without delay
10
- export type Dimmed = 'immediate' | boolean
11
-
12
- export type NodeData = {
13
- /**
14
- * Whether the cursor is hovering over the node
15
- */
16
- hovered?: boolean
17
- /**
18
- * Whether the node is dimmed
19
- * 'immediate' means that the node is dimmed without delay
20
- */
21
- dimmed?: Dimmed
22
- }
23
- export type Node = RFNode<NodeData>
24
-
25
- export type NodeProps = ReactFlowNodeProps<RFNode<NodeData, any>>
26
-
27
- export type EdgeData = {
28
- /**
29
- * Whether the cursor is hovering over the edge
30
- */
31
- hovered?: boolean
32
- /**
33
- * Whether the edge is active (animated and highlighted)
34
- */
35
- active?: boolean
36
- /**
37
- * Whether the edge is dimmed
38
- * 'immediate' means that the edge is dimmed without delay
39
- */
40
- dimmed?: Dimmed
41
- }
42
-
43
- // export type Edge = SetRequired<ReactFlowEdge<EdgeData, 'relation'>, 'data' | 'type'>
44
- export type Edge = Simplify<Omit<RFEdge, 'data'> & { data: EdgeData }>
45
-
46
- type WithDimmed = { data: { dimmed?: Dimmed } }
47
- type WithHovered = { data: { hovered?: boolean } }
48
-
49
- const _setDimmed = <T extends WithDimmed>(v: T, dimmed: Dimmed): T =>
50
- (v.data.dimmed ?? false) === dimmed ? v : ({
51
- ...v,
52
- data: {
53
- ...v.data,
54
- dimmed,
55
- },
56
- })
57
-
58
- export function setDimmed<T extends WithDimmed>(value: T, dimmed: 'immediate' | boolean): T
59
- export function setDimmed(dimmed: 'immediate' | boolean): <T extends WithDimmed>(value: T) => T
60
- export function setDimmed<T extends WithDimmed>(arg1: T | Dimmed, arg2?: Dimmed) {
61
- if (arg2 !== undefined) {
62
- return _setDimmed(arg1 as T, arg2)
63
- }
64
- return (v: T) => _setDimmed(v, arg1 as Dimmed)
65
- }
66
-
67
- const _setHovered = <T extends WithHovered>(v: T, hovered: boolean): T =>
68
- (v.data.hovered ?? false) === hovered ? v : ({
69
- ...v,
70
- data: {
71
- ...v.data,
72
- hovered,
73
- },
74
- })
75
- export function setHovered<T extends WithHovered>(value: T, hovered: boolean): T
76
- export function setHovered(hovered: boolean): <T extends WithHovered>(value: T) => T
77
- export function setHovered<T extends WithHovered>(arg1: T | boolean, arg2?: boolean) {
78
- if (arg2 !== undefined) {
79
- return _setHovered(arg1 as T, arg2)
80
- }
81
- return (v: T) => _setHovered(v, arg1 as boolean)
82
- }
83
-
84
- type WithData<D> = { data: D }
85
- function _setData<D, E extends WithData<D>>(value: E, state: Partial<NoInfer<D>>): E {
86
- if (hasSubObject(value.data as any, state as any)) {
87
- return value
88
- }
89
- return {
90
- ...value,
91
- data: {
92
- ...value.data,
93
- ...state,
94
- },
95
- }
96
- }
97
- export function setData<E extends WithData<any>>(value: E, state: Partial<E['data']>): E
98
- export function setData<E extends WithData<any>>(state: Partial<E['data']>): (value: E) => E
99
- export function setData<E extends WithData<any>>(arg1: E | Partial<E['data']>, arg2?: any) {
100
- if (arg2 !== undefined) {
101
- return _setData(arg1 as E, arg2)
102
- }
103
- return (edge: E) => _setData(edge, arg1 as Partial<EdgeData>)
104
- }
@@ -1,95 +0,0 @@
1
- import {
2
- Button,
3
- CloseButton,
4
- Group,
5
- Popover,
6
- PopoverDropdown,
7
- PopoverTarget,
8
- ScrollAreaAutosize,
9
- Stack,
10
- Text,
11
- } from '@mantine/core'
12
- import { useDebouncedEffect } from '@react-hookz/web'
13
- import { type PropsWithChildren, useState } from 'react'
14
- import { isNonNull, isTruthy } from 'remeda'
15
- import { useMantinePortalProps } from '../../../hooks'
16
- import { useDiagram, useDiagramContext } from '../../../hooks/useDiagram'
17
- import { stopPropagation } from '../../../utils'
18
- import * as edgesCss from './NotePopover.css'
19
-
20
- export const NotePopover = ({ notes, children }: PropsWithChildren<{ notes: string }>) => {
21
- const {
22
- isActive,
23
- isParallel,
24
- hasNext,
25
- hasPrevious,
26
- } = useDiagramContext(s => ({
27
- isActive: isNonNull(s.activeWalkthrough),
28
- isParallel: isTruthy(s.activeWalkthrough?.parallelPrefix),
29
- hasNext: s.xyedges.findIndex(e => e.id === s.activeWalkthrough?.stepId) < s.xyedges.length - 1,
30
- hasPrevious: s.xyedges.findIndex(e => e.id === s.activeWalkthrough?.stepId) > 0,
31
- }))
32
-
33
- const diagram = useDiagram()
34
- const [isOpened, setIsOpened] = useState(false)
35
- const portalProps = useMantinePortalProps()
36
-
37
- useDebouncedEffect(
38
- () => {
39
- setIsOpened(true)
40
- },
41
- [],
42
- 300,
43
- )
44
-
45
- return (
46
- <Popover
47
- shadow="xs"
48
- offset={16}
49
- opened={isOpened}
50
- closeOnClickOutside={false}
51
- {...portalProps}>
52
- <PopoverTarget>
53
- {children}
54
- </PopoverTarget>
55
- <PopoverDropdown
56
- component={Stack}
57
- p={'xs'}
58
- onPointerDownCapture={stopPropagation}
59
- onClick={stopPropagation}
60
- onDoubleClick={stopPropagation}
61
- >
62
- <ScrollAreaAutosize miw={180} maw={450} mah={350} type="scroll" mx={'auto'} mt={2}>
63
- <Text component="div" className={edgesCss.edgeNoteText} p={4}>{notes}</Text>
64
- </ScrollAreaAutosize>
65
- <CloseButton
66
- size={'xs'}
67
- className={edgesCss.edgeNoteCloseButton}
68
- onClick={() => setIsOpened(false)}
69
- />
70
- {(hasPrevious || hasNext) && (
71
- <Group gap={0} justify={hasPrevious ? 'flex-start' : 'flex-end'}>
72
- {hasPrevious && (
73
- <Button
74
- variant="subtle"
75
- radius={'xs'}
76
- size="compact-xs"
77
- onClick={() => diagram.walkthroughStep('previous')}>
78
- back
79
- </Button>
80
- )}
81
- {hasNext && (
82
- <Button
83
- variant="subtle"
84
- radius={'xs'}
85
- size="compact-xs"
86
- onClick={() => diagram.walkthroughStep('next')}>
87
- next
88
- </Button>
89
- )}
90
- </Group>
91
- )}
92
- </PopoverDropdown>
93
- </Popover>
94
- )
95
- }