@ankorar/nodex 0.0.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 (62) hide show
  1. package/README.md +228 -0
  2. package/package.json +54 -0
  3. package/src/components/mindMap/Background.tsx +39 -0
  4. package/src/components/mindMap/Board.tsx +159 -0
  5. package/src/components/mindMap/CentalNode.tsx +121 -0
  6. package/src/components/mindMap/DefaultNode.tsx +205 -0
  7. package/src/components/mindMap/Header.tsx +247 -0
  8. package/src/components/mindMap/ImageNode.tsx +345 -0
  9. package/src/components/mindMap/KeyboardHelpDialog.tsx +108 -0
  10. package/src/components/mindMap/MineMap.tsx +237 -0
  11. package/src/components/mindMap/NodeStylePopover.tsx +486 -0
  12. package/src/components/mindMap/Nodes.tsx +113 -0
  13. package/src/components/mindMap/Nodex.tsx +65 -0
  14. package/src/components/mindMap/SaveStatusIndicator.tsx +61 -0
  15. package/src/components/mindMap/Segments.tsx +270 -0
  16. package/src/components/mindMap/ZenCard.tsx +41 -0
  17. package/src/components/ui/dialog.tsx +141 -0
  18. package/src/components/ui/popover.tsx +46 -0
  19. package/src/components/ui/select.tsx +192 -0
  20. package/src/components/ui/toggle-group.tsx +83 -0
  21. package/src/components/ui/toggle.tsx +45 -0
  22. package/src/config/rootKeyBinds.ts +191 -0
  23. package/src/config/shortCuts.ts +28 -0
  24. package/src/contexts/MindMapNodeEditorContext.tsx +47 -0
  25. package/src/handlers/rootKeyBinds/handleAltEKeyBind.ts +6 -0
  26. package/src/handlers/rootKeyBinds/handleAltHKeyBind.ts +6 -0
  27. package/src/handlers/rootKeyBinds/handleAltWKeyBind.ts +6 -0
  28. package/src/handlers/rootKeyBinds/handleAltZKeyBind.ts +6 -0
  29. package/src/handlers/rootKeyBinds/handleArrowHorizontalRootKeyBind.ts +46 -0
  30. package/src/handlers/rootKeyBinds/handleArrowVerticalRootKeyBind.ts +44 -0
  31. package/src/handlers/rootKeyBinds/handleBackEspaceKeyBind.ts +12 -0
  32. package/src/handlers/rootKeyBinds/handleERootKeyBind.ts +16 -0
  33. package/src/handlers/rootKeyBinds/handleEnterRootKeyBind.ts +35 -0
  34. package/src/handlers/rootKeyBinds/handleEscapeKeyBind.ts +24 -0
  35. package/src/handlers/rootKeyBinds/handleEspaceKeyBind.ts +11 -0
  36. package/src/handlers/rootKeyBinds/handleMoveByWorldKeyBind.ts +6 -0
  37. package/src/handlers/rootKeyBinds/handleRedoRootKeyBind.ts +23 -0
  38. package/src/handlers/rootKeyBinds/handleTabRootKeyBind.ts +49 -0
  39. package/src/handlers/rootKeyBinds/handleTransformNodeKeyBind.ts +39 -0
  40. package/src/handlers/rootKeyBinds/handleUndoRootKeyBind.ts +23 -0
  41. package/src/handlers/rootKeyBinds/handleZoonByKeyBind.ts +31 -0
  42. package/src/helpers/centerNode.ts +19 -0
  43. package/src/helpers/getNodeSide.ts +16 -0
  44. package/src/hooks/mindMap/useHelpers.tsx +9 -0
  45. package/src/hooks/mindMap/useMindMapDebounce.ts +47 -0
  46. package/src/hooks/mindMap/useMindMapHistoryDebounce.ts +69 -0
  47. package/src/hooks/mindMap/useMindMapNode.tsx +203 -0
  48. package/src/hooks/mindMap/useMindMapNodeEditor.ts +91 -0
  49. package/src/hooks/mindMap/useMindMapNodeMouseHandlers.ts +24 -0
  50. package/src/hooks/mindMap/useRootKeyBindHandlers.ts +49 -0
  51. package/src/hooks/mindMap/useRootMouseHandlers.ts +124 -0
  52. package/src/hooks/mindMap/useUpdateCenter.ts +54 -0
  53. package/src/index.ts +76 -0
  54. package/src/lib/utils.ts +6 -0
  55. package/src/state/mindMap.ts +793 -0
  56. package/src/state/mindMapHistory.ts +96 -0
  57. package/src/styles.input.css +95 -0
  58. package/src/utils/exportMindMapAsHighQualityImage.ts +327 -0
  59. package/src/utils/exportMindMapAsMarkdown.ts +102 -0
  60. package/src/utils/exportMindMapAsPdf.ts +241 -0
  61. package/src/utils/getMindMapPreviewDataUrl.ts +60 -0
  62. package/styles.css +2 -0
@@ -0,0 +1,192 @@
1
+ import * as React from "react"
2
+ import * as SelectPrimitive from "@radix-ui/react-select"
3
+ import { CheckIcon, ChevronDownIcon, ChevronUpIcon } from "lucide-react"
4
+
5
+ import { cn } from "../../lib/utils"
6
+
7
+ function Select({
8
+ ...props
9
+ }: React.ComponentProps<typeof SelectPrimitive.Root>) {
10
+ return <SelectPrimitive.Root data-slot="select" {...props} />
11
+ }
12
+
13
+ function SelectGroup({
14
+ ...props
15
+ }: React.ComponentProps<typeof SelectPrimitive.Group>) {
16
+ return <SelectPrimitive.Group data-slot="select-group" {...props} />
17
+ }
18
+
19
+ function SelectValue({
20
+ ...props
21
+ }: React.ComponentProps<typeof SelectPrimitive.Value>) {
22
+ return <SelectPrimitive.Value data-slot="select-value" {...props} />
23
+ }
24
+
25
+ function SelectTrigger({
26
+ className,
27
+ size = "default",
28
+ children,
29
+ hideIcon = false,
30
+ ...props
31
+ }: React.ComponentProps<typeof SelectPrimitive.Trigger> & {
32
+ size?: "sm" | "default"
33
+ hideIcon?: boolean
34
+ }) {
35
+ return (
36
+ <SelectPrimitive.Trigger
37
+ data-slot="select-trigger"
38
+ data-size={size}
39
+ className={cn(
40
+ "border-input data-[placeholder]:text-muted-foreground [&_svg:not([class*='text-'])]:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 dark:hover:bg-input/50 flex w-fit items-center justify-between gap-2 rounded-md border bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
41
+ className
42
+ )}
43
+ {...props}
44
+ >
45
+ {children}
46
+ {!hideIcon && (
47
+ <SelectPrimitive.Icon asChild>
48
+ <ChevronDownIcon className="size-4 opacity-50" />
49
+ </SelectPrimitive.Icon>
50
+ )}
51
+ </SelectPrimitive.Trigger>
52
+ )
53
+ }
54
+
55
+ function SelectContent({
56
+ className,
57
+ children,
58
+ position = "item-aligned",
59
+ align = "center",
60
+ ...props
61
+ }: React.ComponentProps<typeof SelectPrimitive.Content>) {
62
+ return (
63
+ <SelectPrimitive.Portal>
64
+ <SelectPrimitive.Content
65
+ data-slot="select-content"
66
+ className={cn(
67
+ "bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border shadow-md",
68
+ position === "popper" &&
69
+ "data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",
70
+ className
71
+ )}
72
+ position={position}
73
+ align={align}
74
+ {...props}
75
+ >
76
+ <SelectScrollUpButton />
77
+ <SelectPrimitive.Viewport
78
+ className={cn(
79
+ "p-1",
80
+ position === "popper" &&
81
+ "h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1"
82
+ )}
83
+ >
84
+ {children}
85
+ </SelectPrimitive.Viewport>
86
+ <SelectScrollDownButton />
87
+ </SelectPrimitive.Content>
88
+ </SelectPrimitive.Portal>
89
+ )
90
+ }
91
+
92
+ function SelectLabel({
93
+ className,
94
+ ...props
95
+ }: React.ComponentProps<typeof SelectPrimitive.Label>) {
96
+ return (
97
+ <SelectPrimitive.Label
98
+ data-slot="select-label"
99
+ className={cn("text-muted-foreground px-2 py-1.5 text-xs", className)}
100
+ {...props}
101
+ />
102
+ )
103
+ }
104
+
105
+ function SelectItem({
106
+ className,
107
+ children,
108
+ ...props
109
+ }: React.ComponentProps<typeof SelectPrimitive.Item>) {
110
+ return (
111
+ <SelectPrimitive.Item
112
+ data-slot="select-item"
113
+ className={cn(
114
+ "focus:bg-accent focus:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",
115
+ className
116
+ )}
117
+ {...props}
118
+ >
119
+ <span
120
+ data-slot="select-item-indicator"
121
+ className="absolute right-2 flex size-3.5 items-center justify-center"
122
+ >
123
+ <SelectPrimitive.ItemIndicator>
124
+ <CheckIcon className="size-4" />
125
+ </SelectPrimitive.ItemIndicator>
126
+ </span>
127
+ <SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
128
+ </SelectPrimitive.Item>
129
+ )
130
+ }
131
+
132
+ function SelectSeparator({
133
+ className,
134
+ ...props
135
+ }: React.ComponentProps<typeof SelectPrimitive.Separator>) {
136
+ return (
137
+ <SelectPrimitive.Separator
138
+ data-slot="select-separator"
139
+ className={cn("bg-border pointer-events-none -mx-1 my-1 h-px", className)}
140
+ {...props}
141
+ />
142
+ )
143
+ }
144
+
145
+ function SelectScrollUpButton({
146
+ className,
147
+ ...props
148
+ }: React.ComponentProps<typeof SelectPrimitive.ScrollUpButton>) {
149
+ return (
150
+ <SelectPrimitive.ScrollUpButton
151
+ data-slot="select-scroll-up-button"
152
+ className={cn(
153
+ "flex cursor-default items-center justify-center py-1",
154
+ className
155
+ )}
156
+ {...props}
157
+ >
158
+ <ChevronUpIcon className="size-4" />
159
+ </SelectPrimitive.ScrollUpButton>
160
+ )
161
+ }
162
+
163
+ function SelectScrollDownButton({
164
+ className,
165
+ ...props
166
+ }: React.ComponentProps<typeof SelectPrimitive.ScrollDownButton>) {
167
+ return (
168
+ <SelectPrimitive.ScrollDownButton
169
+ data-slot="select-scroll-down-button"
170
+ className={cn(
171
+ "flex cursor-default items-center justify-center py-1",
172
+ className
173
+ )}
174
+ {...props}
175
+ >
176
+ <ChevronDownIcon className="size-4" />
177
+ </SelectPrimitive.ScrollDownButton>
178
+ )
179
+ }
180
+
181
+ export {
182
+ Select,
183
+ SelectContent,
184
+ SelectGroup,
185
+ SelectItem,
186
+ SelectLabel,
187
+ SelectScrollDownButton,
188
+ SelectScrollUpButton,
189
+ SelectSeparator,
190
+ SelectTrigger,
191
+ SelectValue,
192
+ }
@@ -0,0 +1,83 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+ import * as ToggleGroupPrimitive from "@radix-ui/react-toggle-group"
5
+ import { type VariantProps } from "class-variance-authority"
6
+
7
+ import { cn } from "../../lib/utils"
8
+ import { toggleVariants } from "./toggle"
9
+
10
+ const ToggleGroupContext = React.createContext<
11
+ VariantProps<typeof toggleVariants> & {
12
+ spacing?: number
13
+ }
14
+ >({
15
+ size: "default",
16
+ variant: "default",
17
+ spacing: 0,
18
+ })
19
+
20
+ function ToggleGroup({
21
+ className,
22
+ variant,
23
+ size,
24
+ spacing = 0,
25
+ children,
26
+ ...props
27
+ }: React.ComponentProps<typeof ToggleGroupPrimitive.Root> &
28
+ VariantProps<typeof toggleVariants> & {
29
+ spacing?: number
30
+ }) {
31
+ return (
32
+ <ToggleGroupPrimitive.Root
33
+ data-slot="toggle-group"
34
+ data-variant={variant}
35
+ data-size={size}
36
+ data-spacing={spacing}
37
+ style={{ "--gap": spacing } as React.CSSProperties}
38
+ className={cn(
39
+ "group/toggle-group flex w-fit items-center gap-[--spacing(var(--gap))] rounded-md data-[spacing=default]:data-[variant=outline]:shadow-xs",
40
+ className
41
+ )}
42
+ {...props}
43
+ >
44
+ <ToggleGroupContext.Provider value={{ variant, size, spacing }}>
45
+ {children}
46
+ </ToggleGroupContext.Provider>
47
+ </ToggleGroupPrimitive.Root>
48
+ )
49
+ }
50
+
51
+ function ToggleGroupItem({
52
+ className,
53
+ children,
54
+ variant,
55
+ size,
56
+ ...props
57
+ }: React.ComponentProps<typeof ToggleGroupPrimitive.Item> &
58
+ VariantProps<typeof toggleVariants>) {
59
+ const context = React.useContext(ToggleGroupContext)
60
+
61
+ return (
62
+ <ToggleGroupPrimitive.Item
63
+ data-slot="toggle-group-item"
64
+ data-variant={context.variant || variant}
65
+ data-size={context.size || size}
66
+ data-spacing={context.spacing}
67
+ className={cn(
68
+ toggleVariants({
69
+ variant: context.variant || variant,
70
+ size: context.size || size,
71
+ }),
72
+ "w-auto min-w-0 shrink-0 px-3 focus:z-10 focus-visible:z-10",
73
+ "data-[spacing=0]:rounded-none data-[spacing=0]:shadow-none data-[spacing=0]:first:rounded-l-md data-[spacing=0]:last:rounded-r-md data-[spacing=0]:data-[variant=outline]:border-l-0 data-[spacing=0]:data-[variant=outline]:first:border-l",
74
+ className
75
+ )}
76
+ {...props}
77
+ >
78
+ {children}
79
+ </ToggleGroupPrimitive.Item>
80
+ )
81
+ }
82
+
83
+ export { ToggleGroup, ToggleGroupItem }
@@ -0,0 +1,45 @@
1
+ import * as React from "react"
2
+ import * as TogglePrimitive from "@radix-ui/react-toggle"
3
+ import { cva, type VariantProps } from "class-variance-authority"
4
+
5
+ import { cn } from "../../lib/utils"
6
+
7
+ const toggleVariants = cva(
8
+ "inline-flex items-center justify-center gap-2 rounded-md text-sm font-medium hover:bg-muted hover:text-muted-foreground disabled:pointer-events-none disabled:opacity-50 data-[state=on]:bg-accent data-[state=on]:text-accent-foreground [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 [&_svg]:shrink-0 focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] outline-none transition-[color,box-shadow] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive whitespace-nowrap",
9
+ {
10
+ variants: {
11
+ variant: {
12
+ default: "bg-transparent",
13
+ outline:
14
+ "border border-input bg-transparent shadow-xs hover:bg-accent hover:text-accent-foreground",
15
+ },
16
+ size: {
17
+ default: "h-9 px-2 min-w-9",
18
+ sm: "h-8 px-1.5 min-w-8",
19
+ lg: "h-10 px-2.5 min-w-10",
20
+ },
21
+ },
22
+ defaultVariants: {
23
+ variant: "default",
24
+ size: "default",
25
+ },
26
+ }
27
+ )
28
+
29
+ function Toggle({
30
+ className,
31
+ variant,
32
+ size,
33
+ ...props
34
+ }: React.ComponentProps<typeof TogglePrimitive.Root> &
35
+ VariantProps<typeof toggleVariants>) {
36
+ return (
37
+ <TogglePrimitive.Root
38
+ data-slot="toggle"
39
+ className={cn(toggleVariants({ variant, size, className }))}
40
+ {...props}
41
+ />
42
+ )
43
+ }
44
+
45
+ export { Toggle, toggleVariants }
@@ -0,0 +1,191 @@
1
+ import { handleAltEKeyBind } from "../handlers/rootKeyBinds/handleAltEKeyBind";
2
+ import { handleAltHKeyBind } from "../handlers/rootKeyBinds/handleAltHKeyBind";
3
+ import { handleAltWKeyBind } from "../handlers/rootKeyBinds/handleAltWKeyBind";
4
+ import { handleAltZKeyBind } from "../handlers/rootKeyBinds/handleAltZKeyBind";
5
+ import { handleArrowHorizontalRootKeyBind } from "../handlers/rootKeyBinds/handleArrowHorizontalRootKeyBind";
6
+ import { handleArrowVerticalRootKeyBind } from "../handlers/rootKeyBinds/handleArrowVerticalRootKeyBind";
7
+ import { handleBackEspaceKeyBind } from "../handlers/rootKeyBinds/handleBackEspaceKeyBind";
8
+ import { handleEscapeKeyBind } from "../handlers/rootKeyBinds/handleEscapeKeyBind";
9
+ import { handleEnterRootKeyBind } from "../handlers/rootKeyBinds/handleEnterRootKeyBind";
10
+ import { handleERootKeyBind } from "../handlers/rootKeyBinds/handleERootKeyBind";
11
+ import { handleEspaceKeyBind } from "../handlers/rootKeyBinds/handleEspaceKeyBind";
12
+ import { handleMoveByWorldKeyBind } from "../handlers/rootKeyBinds/handleMoveByWorldKeyBind";
13
+ import { handleTabRootKeyBind } from "../handlers/rootKeyBinds/handleTabRootKeyBind";
14
+ import { handleTransformNodeKeyBind } from "../handlers/rootKeyBinds/handleTransformNodeKeyBind";
15
+ import { handleRedoRootKeyBind } from "../handlers/rootKeyBinds/handleRedoRootKeyBind";
16
+ import { handleUndoRootKeyBind } from "../handlers/rootKeyBinds/handleUndoRootKeyBind";
17
+ import { handleZoomByKeyBind } from "../handlers/rootKeyBinds/handleZoonByKeyBind";
18
+
19
+ export type KeyBind = {
20
+ description: string;
21
+ shortCut: string;
22
+ handler: () => void;
23
+ skipOnEditing: boolean;
24
+ };
25
+
26
+ export const rootKeyBinds: { [x: string]: KeyBind } = {
27
+ ArrowLeft: {
28
+ description: "Seleciona o node à esquerda ou o node pai.",
29
+ shortCut: "Seta esquerda",
30
+ handler: () => handleArrowHorizontalRootKeyBind("left"),
31
+ skipOnEditing: true,
32
+ },
33
+ ArrowRight: {
34
+ description: "Seleciona o node à direita ou o node pai.",
35
+ shortCut: "Seta direita",
36
+ handler: () => handleArrowHorizontalRootKeyBind("right"),
37
+ skipOnEditing: true,
38
+ },
39
+ ArrowUp: {
40
+ description: "Seleciona o node acima ou o node pai.",
41
+ shortCut: "Seta para cima",
42
+ handler: () => handleArrowVerticalRootKeyBind("up"),
43
+ skipOnEditing: true,
44
+ },
45
+ ArrowDown: {
46
+ description: "Seleciona o node abaixo ou o node pai.",
47
+ shortCut: "Seta para baixo",
48
+ handler: () => handleArrowVerticalRootKeyBind("down"),
49
+ skipOnEditing: true,
50
+ },
51
+ Enter: {
52
+ description: "Cria um node irmão e entra em edição.",
53
+ shortCut: "Enter",
54
+ handler: () => handleEnterRootKeyBind(),
55
+ skipOnEditing: true,
56
+ },
57
+ "Ctrl+Enter": {
58
+ description: "Cria um node irmão e entra em edição.",
59
+ shortCut: "Ctrl + Enter",
60
+ handler: () => handleEnterRootKeyBind(),
61
+ skipOnEditing: false,
62
+ },
63
+ Tab: {
64
+ description: "Cria um node filho e entra em edição.",
65
+ shortCut: "Tab",
66
+ handler: () => handleTabRootKeyBind(),
67
+ skipOnEditing: false,
68
+ },
69
+ e: {
70
+ description: "Alterna a visibilidade dos filhos do node selecionado.",
71
+ shortCut: "E",
72
+ handler: () => handleERootKeyBind(),
73
+ skipOnEditing: true,
74
+ },
75
+ "Ctrl+=": {
76
+ description: "Aumenta o zoom.",
77
+ shortCut: "Ctrl + =",
78
+ handler: () => handleZoomByKeyBind(0.06),
79
+ skipOnEditing: false,
80
+ },
81
+ "Ctrl++": {
82
+ description: "Aumenta o zoom.",
83
+ shortCut: "Ctrl + +",
84
+ handler: () => handleZoomByKeyBind(0.06),
85
+ skipOnEditing: false,
86
+ },
87
+ "Ctrl+-": {
88
+ description: "Diminui o zoom.",
89
+ shortCut: "Ctrl + -",
90
+ handler: () => handleZoomByKeyBind(-0.06),
91
+ skipOnEditing: false,
92
+ },
93
+ "Alt+ArrowLeft": {
94
+ description: "Move o mapa para a esquerda.",
95
+ shortCut: "Alt + Seta esquerda",
96
+ handler: () => handleMoveByWorldKeyBind(80, 0),
97
+ skipOnEditing: false,
98
+ },
99
+ "Alt+ArrowRight": {
100
+ description: "Move o mapa para a direita.",
101
+ shortCut: "Alt + Seta direita",
102
+ handler: () => handleMoveByWorldKeyBind(-80, 0),
103
+ skipOnEditing: false,
104
+ },
105
+ "Alt+ArrowUp": {
106
+ description: "Move o mapa para cima.",
107
+ shortCut: "Alt + Seta para cima",
108
+ handler: () => handleMoveByWorldKeyBind(0, 80),
109
+ skipOnEditing: false,
110
+ },
111
+ "Alt+ArrowDown": {
112
+ description: "Move o mapa para baixo.",
113
+ shortCut: "Alt + Seta para baixo",
114
+ handler: () => handleMoveByWorldKeyBind(0, -80),
115
+ skipOnEditing: false,
116
+ },
117
+ "Alt+e": {
118
+ description: "Mostra todos os nodes.",
119
+ shortCut: "Alt + E",
120
+ handler: () => handleAltEKeyBind(),
121
+ skipOnEditing: true,
122
+ },
123
+ "Alt+w": {
124
+ description: "Oculta os nodes que não são filhos do node central.",
125
+ shortCut: "Alt + W",
126
+ handler: () => handleAltWKeyBind(),
127
+ skipOnEditing: true,
128
+ },
129
+ "Alt+h": {
130
+ description: "Abre ou fecha a ajuda.",
131
+ shortCut: "Alt + H",
132
+ handler: () => handleAltHKeyBind(),
133
+ skipOnEditing: false,
134
+ },
135
+ "Alt+z": {
136
+ description: "Ativa ou desativa o modo zen.",
137
+ shortCut: "Alt + Z",
138
+ handler: () => handleAltZKeyBind(),
139
+ skipOnEditing: false,
140
+ },
141
+ "Ctrl+b": {
142
+ description: "Alterna o texto em negrito.",
143
+ shortCut: "Ctrl + B",
144
+ handler: () => handleTransformNodeKeyBind(["bold"]),
145
+ skipOnEditing: true,
146
+ },
147
+ "Ctrl+i": {
148
+ description: "Alterna o texto em itálico.",
149
+ shortCut: "Ctrl + I",
150
+ handler: () => handleTransformNodeKeyBind(["italic"]),
151
+ skipOnEditing: true,
152
+ },
153
+ "Ctrl+p": {
154
+ description: "Transforma o node em imagem e entra em edição.",
155
+ shortCut: "Ctrl + P",
156
+ handler: () => handleTransformNodeKeyBind(["image"]),
157
+ skipOnEditing: false,
158
+ },
159
+ "Ctrl+z": {
160
+ description: "Desfaz a última alteração.",
161
+ shortCut: "Ctrl + Z",
162
+ handler: () => handleUndoRootKeyBind(),
163
+ skipOnEditing: false,
164
+ },
165
+ "Ctrl+y": {
166
+ description: "Refaz a última alteração desfeita.",
167
+ shortCut: "Ctrl + Y",
168
+ handler: () => handleRedoRootKeyBind(),
169
+ skipOnEditing: false,
170
+ },
171
+ Escape: {
172
+ description: "Sai da edição e remove o node vazio.",
173
+ shortCut: "Esc",
174
+ handler: () => handleEscapeKeyBind(),
175
+ skipOnEditing: false,
176
+ },
177
+ Backspace: {
178
+ description: "Remove o node selecionado.",
179
+ shortCut: "Backspace",
180
+ handler: () => handleBackEspaceKeyBind(),
181
+ skipOnEditing: true,
182
+ },
183
+ " ": {
184
+ description: "Entra em edição do node selecionado.",
185
+ shortCut: "Espaço",
186
+ handler: () => handleEspaceKeyBind(),
187
+ skipOnEditing: true,
188
+ },
189
+ } as const;
190
+
191
+ export type RootKeyBinds = keyof typeof rootKeyBinds;
@@ -0,0 +1,28 @@
1
+ export const shortCutsExistent = [
2
+ "Escape",
3
+ "Tab",
4
+ "Ctrl+Enter",
5
+ "Ctrl+=",
6
+ "Ctrl++",
7
+ "Ctrl+-",
8
+ "Ctrl+ArrowDown",
9
+ "Ctrl+ArrowRight",
10
+ "Ctrl+ArrowLeft",
11
+ "Ctrl+ArrowUp",
12
+ "Ctrl+z",
13
+ "Ctrl+Z",
14
+ "Ctrl+Shift+z",
15
+ "Ctrl+Shift+Z",
16
+ "Ctrl+e",
17
+ "Ctrl+E",
18
+ "Ctrl+l",
19
+ "Ctrl+L",
20
+ "Ctrl+b",
21
+ "Ctrl+B",
22
+ "Ctrl+i",
23
+ "Ctrl+I",
24
+ "Alt+z",
25
+ "Alt+Z",
26
+ "Alt+h",
27
+ "Alt+H",
28
+ ];
@@ -0,0 +1,47 @@
1
+ import {
2
+ type ReactNode,
3
+ createContext,
4
+ useContext,
5
+ useMemo,
6
+ } from "react";
7
+ import type { MindMapNode } from "../state/mindMap";
8
+
9
+ export type NodeEditorCustomButton = {
10
+ key: string;
11
+ children: ReactNode;
12
+ onAction: (node: MindMapNode) => void;
13
+ };
14
+
15
+ type MindMapNodeEditorContextValue = {
16
+ customButtons: NodeEditorCustomButton[];
17
+ };
18
+
19
+ const defaultValue: MindMapNodeEditorContextValue = {
20
+ customButtons: [],
21
+ };
22
+
23
+ const MindMapNodeEditorContext =
24
+ createContext<MindMapNodeEditorContextValue>(defaultValue);
25
+
26
+ export function MindMapNodeEditorProvider({
27
+ customButtons = [],
28
+ children,
29
+ }: {
30
+ customButtons?: NodeEditorCustomButton[];
31
+ children: ReactNode;
32
+ }) {
33
+ const value = useMemo(
34
+ () => ({ customButtons }),
35
+ [customButtons],
36
+ );
37
+
38
+ return (
39
+ <MindMapNodeEditorContext.Provider value={value}>
40
+ {children}
41
+ </MindMapNodeEditorContext.Provider>
42
+ );
43
+ }
44
+
45
+ export function useMindMapNodeEditorContext(): MindMapNodeEditorContextValue {
46
+ return useContext(MindMapNodeEditorContext);
47
+ }
@@ -0,0 +1,6 @@
1
+ import { useMindMapState } from "../../state/mindMap";
2
+
3
+ export const handleAltEKeyBind = () => {
4
+ const { showAllNodes } = useMindMapState.getState();
5
+ showAllNodes();
6
+ };
@@ -0,0 +1,6 @@
1
+ import { useMindMapState } from "../../state/mindMap";
2
+
3
+ export const handleAltHKeyBind = () => {
4
+ const { setHelpOpen, helpOpen } = useMindMapState.getState();
5
+ setHelpOpen(!helpOpen);
6
+ };
@@ -0,0 +1,6 @@
1
+ import { useMindMapState } from "../../state/mindMap";
2
+
3
+ export const handleAltWKeyBind = () => {
4
+ const { hideNonCentralChildren } = useMindMapState.getState();
5
+ hideNonCentralChildren();
6
+ };
@@ -0,0 +1,6 @@
1
+ import { useMindMapState } from "../../state/mindMap";
2
+
3
+ export const handleAltZKeyBind = () => {
4
+ const { zenMode, setZenMode } = useMindMapState.getState();
5
+ setZenMode(!zenMode);
6
+ };
@@ -0,0 +1,46 @@
1
+ import { centerNode } from "../../helpers/centerNode";
2
+ import { getNodeSide } from "../../helpers/getNodeSide";
3
+ import { useMindMapState } from "../../state/mindMap";
4
+
5
+ export const handleArrowHorizontalRootKeyBind = (dir: "left" | "right") => {
6
+ const {
7
+ selectedNodeId,
8
+ getCentralNode,
9
+ setSelectedNode,
10
+ findNode,
11
+ findNodeParent,
12
+ } = useMindMapState.getState();
13
+
14
+ const centralNode = getCentralNode();
15
+ const node = findNode(selectedNodeId ?? centralNode?.id ?? "");
16
+
17
+ if (!node) return;
18
+ const currentSide = getNodeSide(node);
19
+
20
+ const shouldGoParent =
21
+ (dir === "right" && currentSide === "left") ||
22
+ (dir === "left" && currentSide === "right");
23
+
24
+ if (shouldGoParent) {
25
+ const parent = findNodeParent(node.id);
26
+
27
+ if (parent) {
28
+ setSelectedNode(parent.id);
29
+ centerNode(parent);
30
+ }
31
+
32
+ return;
33
+ }
34
+
35
+ const visibleChildren = node.childrens
36
+ .filter((child) => child.isVisible)
37
+ .filter((child) => getNodeSide(child) === dir)
38
+ .sort((a, b) => a.sequence - b.sequence);
39
+
40
+ const target = visibleChildren[0];
41
+
42
+ if (target) {
43
+ setSelectedNode(target.id);
44
+ centerNode(target);
45
+ }
46
+ };