@socprime/react-ui 0.0.5
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.
- package/CHANGELOG.md +56 -0
- package/LICENSE +21 -0
- package/README.md +537 -0
- package/attack-flow.d.ts +16 -0
- package/charts.d.ts +32 -0
- package/decorators/index.js +8 -0
- package/decorators/withRouter.js +10 -0
- package/decorators/withTheme.js +10 -0
- package/decorators.d.ts +10 -0
- package/domain.d.ts +23 -0
- package/editor.d.ts +25 -0
- package/index.d.ts +702 -0
- package/lib/cn.js +8 -0
- package/lib/theme.js +26 -0
- package/lib/useFullscreen.js +52 -0
- package/lib/useListenOnResizeDebounce.js +22 -0
- package/lib/useThemeColors.js +39 -0
- package/package.json +113 -0
- package/preset/createConfig.js +98 -0
- package/preset/createPreview.js +53 -0
- package/preset/index.js +6 -0
- package/preset/restoreNativeFocus.js +33 -0
- package/preset/types.js +0 -0
- package/preset.d.ts +27 -0
- package/theme-9m7j1UoI.d.ts +5 -0
- package/ui/Accordion/Accordion.js +82 -0
- package/ui/Accordion/AccordionSection.js +41 -0
- package/ui/Accordion/FolderTreeExpandTrigger.js +29 -0
- package/ui/Accordion/chevronVariants.js +31 -0
- package/ui/Accordion/index.js +16 -0
- package/ui/AnimatedDots/AnimatedDots.js +10 -0
- package/ui/AnimatedDots/index.js +4 -0
- package/ui/Aside/Aside.js +34 -0
- package/ui/Aside/index.js +4 -0
- package/ui/AttackFlow/AttackFlow.js +9 -0
- package/ui/AttackFlow/AttackFlowLayout.js +63 -0
- package/ui/AttackFlow/Controls.js +42 -0
- package/ui/AttackFlow/Node.js +47 -0
- package/ui/AttackFlow/OtherNode.js +44 -0
- package/ui/AttackFlow/index.js +4 -0
- package/ui/AttackFlow/prependData.js +153 -0
- package/ui/AttackFlow/types.js +0 -0
- package/ui/AttackFlow/useAttackFlow.js +193 -0
- package/ui/Badge/Badge.js +57 -0
- package/ui/Badge/index.js +5 -0
- package/ui/Button/Button.css +1 -0
- package/ui/Button/Button.js +109 -0
- package/ui/Button/index.js +5 -0
- package/ui/Charts/AreaChartWithGradient.js +79 -0
- package/ui/Charts/index.js +4 -0
- package/ui/Checkbox/Checkbox.js +31 -0
- package/ui/Checkbox/index.js +4 -0
- package/ui/ConditionalContent/ConditionalContent.js +10 -0
- package/ui/ConditionalContent/index.js +4 -0
- package/ui/CorrelationTimer/CorrelationTimer.js +62 -0
- package/ui/CorrelationTimer/index.js +4 -0
- package/ui/DeleteButtonConfirm/DeleteButtonConfirm.js +65 -0
- package/ui/DeleteButtonConfirm/index.js +4 -0
- package/ui/Dialog/ConfirmDialog.js +54 -0
- package/ui/Dialog/DefaultDialog.js +82 -0
- package/ui/Dialog/Dialog.js +120 -0
- package/ui/Dialog/index.js +32 -0
- package/ui/Dropdown/Dropdown.js +204 -0
- package/ui/Dropdown/DropdownsCheckbox.js +102 -0
- package/ui/Dropdown/DropdownsSelect.js +97 -0
- package/ui/Dropdown/index.js +38 -0
- package/ui/Editor/Editor.js +97 -0
- package/ui/Editor/index.js +4 -0
- package/ui/Editor/monacoSetup.js +38 -0
- package/ui/Editor/theme.js +50 -0
- package/ui/Editor/types.js +0 -0
- package/ui/EmptyState/EmptyState.js +26 -0
- package/ui/EmptyState/index.js +4 -0
- package/ui/Field/Field.js +204 -0
- package/ui/Field/index.js +24 -0
- package/ui/HelperText/HelperText.js +7 -0
- package/ui/HelperText/index.js +4 -0
- package/ui/Input/Input.js +40 -0
- package/ui/Input/index.js +4 -0
- package/ui/InputNumber/InputNumber.js +90 -0
- package/ui/InputNumber/index.js +4 -0
- package/ui/InputPassword/InputPassword.js +30 -0
- package/ui/InputPassword/index.js +4 -0
- package/ui/Label/Label.js +13 -0
- package/ui/Label/LabelInfo.js +14 -0
- package/ui/Label/index.js +6 -0
- package/ui/MultiSelect/MultiSelect.js +163 -0
- package/ui/MultiSelect/index.js +4 -0
- package/ui/PageHeader/PageHeader.js +51 -0
- package/ui/PageHeader/index.js +4 -0
- package/ui/Pagination/Pagination.js +97 -0
- package/ui/Pagination/PaginationWrap.js +149 -0
- package/ui/Pagination/index.js +20 -0
- package/ui/RadioGroup/RadioGroup.js +45 -0
- package/ui/RadioGroup/index.js +5 -0
- package/ui/ScrollArea/ScrollArea.js +57 -0
- package/ui/ScrollArea/index.js +5 -0
- package/ui/SearchInput/SearchInput.js +38 -0
- package/ui/SearchInput/index.js +4 -0
- package/ui/SearchInputFields/SearchInputFields.js +53 -0
- package/ui/SearchInputFields/index.js +4 -0
- package/ui/Select/Select.js +155 -0
- package/ui/Select/SelectDefault.js +43 -0
- package/ui/Select/index.js +26 -0
- package/ui/Separator/Separator.js +26 -0
- package/ui/Separator/index.js +4 -0
- package/ui/Severity/Severity.js +11 -0
- package/ui/Severity/index.js +4 -0
- package/ui/Severity/utils.js +53 -0
- package/ui/Skeleton/Skeleton.js +25 -0
- package/ui/Skeleton/index.js +5 -0
- package/ui/Slider/Slider.js +50 -0
- package/ui/Slider/index.js +4 -0
- package/ui/Spinner/Spinner.js +21 -0
- package/ui/Spinner/index.js +5 -0
- package/ui/SpinnerSquare/SpinnerSquare.css +1 -0
- package/ui/SpinnerSquare/SpinnerSquare.js +22 -0
- package/ui/SpinnerSquare/index.js +4 -0
- package/ui/StatisticCard/StatisticCard.js +27 -0
- package/ui/StatisticCard/index.js +4 -0
- package/ui/StatisticCard/types.js +0 -0
- package/ui/Suggestions/Suggestions.js +244 -0
- package/ui/Suggestions/index.js +4 -0
- package/ui/Switch/Switch.js +64 -0
- package/ui/Switch/index.js +4 -0
- package/ui/SyncProcessBar/SyncProcessBar.js +14 -0
- package/ui/SyncProcessBar/index.js +4 -0
- package/ui/Table/GroupHeaderRow.js +36 -0
- package/ui/Table/RowGrouped.js +19 -0
- package/ui/Table/ServerGroupedTableBody.js +89 -0
- package/ui/Table/SortableHeader.js +46 -0
- package/ui/Table/Table.js +110 -0
- package/ui/Table/TableWrap.js +124 -0
- package/ui/Table/columnStyle.js +14 -0
- package/ui/Table/index.js +28 -0
- package/ui/Tabs/Tabs.js +76 -0
- package/ui/Tabs/index.js +4 -0
- package/ui/TextTruncate/TextTruncate.js +107 -0
- package/ui/TextTruncate/index.js +4 -0
- package/ui/Textarea/Textarea.js +20 -0
- package/ui/Textarea/index.js +4 -0
- package/ui/ThemeToggle/ThemeToggle.js +23 -0
- package/ui/ThemeToggle/index.js +4 -0
- package/ui/Toast/Toast.js +23 -0
- package/ui/Toast/index.js +4 -0
- package/ui/Tooltip/Tooltip.js +17 -0
- package/ui/Tooltip/TooltipLayout.js +60 -0
- package/ui/Tooltip/index.js +14 -0
- package/ui/TreeGuide/TreeGuide.js +23 -0
- package/ui/TreeGuide/index.js +5 -0
- package/ui/entries/charts.js +2 -0
- package/ui/entries/domain.js +3 -0
- package/ui/index.js +45 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Accordion,
|
|
3
|
+
AccordionContent,
|
|
4
|
+
AccordionItem,
|
|
5
|
+
AccordionTrigger
|
|
6
|
+
} from "./Accordion.js";
|
|
7
|
+
import { AccordionSection } from "./AccordionSection.js";
|
|
8
|
+
import { FolderTreeExpandTrigger } from "./FolderTreeExpandTrigger.js";
|
|
9
|
+
export {
|
|
10
|
+
Accordion,
|
|
11
|
+
AccordionContent,
|
|
12
|
+
AccordionItem,
|
|
13
|
+
AccordionSection,
|
|
14
|
+
AccordionTrigger,
|
|
15
|
+
FolderTreeExpandTrigger
|
|
16
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { cn } from "../../lib/cn.js";
|
|
3
|
+
const AnimatedDots = ({ className }) => /* @__PURE__ */ jsxs("span", { className: cn("inline-flex", className), "aria-hidden": "true", children: [
|
|
4
|
+
/* @__PURE__ */ jsx("span", { className: "animate-dot-loading-1", children: "." }),
|
|
5
|
+
/* @__PURE__ */ jsx("span", { className: "animate-dot-loading-2", children: "." }),
|
|
6
|
+
/* @__PURE__ */ jsx("span", { className: "animate-dot-loading-3", children: "." })
|
|
7
|
+
] });
|
|
8
|
+
export {
|
|
9
|
+
AnimatedDots
|
|
10
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Button } from "../Button/Button.js";
|
|
3
|
+
import { cn } from "../../lib/cn.js";
|
|
4
|
+
import {
|
|
5
|
+
NavigationMenu,
|
|
6
|
+
NavigationMenuItem,
|
|
7
|
+
NavigationMenuList
|
|
8
|
+
} from "@radix-ui/react-navigation-menu";
|
|
9
|
+
import { useLocation } from "react-router-dom";
|
|
10
|
+
const isPathActive = (pathname, linkTo) => pathname === linkTo || pathname.startsWith(`${linkTo}/`);
|
|
11
|
+
const Aside = ({ tabs = [], activeId, className }) => {
|
|
12
|
+
const { pathname } = useLocation();
|
|
13
|
+
return /* @__PURE__ */ jsx("aside", { className: cn("w-full", className), children: /* @__PURE__ */ jsx(NavigationMenu, { children: /* @__PURE__ */ jsx(NavigationMenuList, { className: "flex w-full flex-col gap-2", children: tabs.map(({ id, label, title, icon, to, onClick }) => {
|
|
14
|
+
const Icon = icon || void 0;
|
|
15
|
+
const linkTo = to ?? id;
|
|
16
|
+
const isActive = activeId ? activeId === id : isPathActive(pathname, linkTo);
|
|
17
|
+
return /* @__PURE__ */ jsx(NavigationMenuItem, { children: title ? /* @__PURE__ */ jsx("div", { className: "text-gray-chateau text-2xs font-medium tracking-wider uppercase", children: title }) : /* @__PURE__ */ jsxs(
|
|
18
|
+
Button,
|
|
19
|
+
{
|
|
20
|
+
className: `w-full justify-start bg-transparent text-xs ${isActive ? "is-active" : ""}`,
|
|
21
|
+
variant: "ghost",
|
|
22
|
+
size: "l",
|
|
23
|
+
...onClick ? { onClick } : { to: linkTo },
|
|
24
|
+
children: [
|
|
25
|
+
Icon && /* @__PURE__ */ jsx(Icon, { className: "size-6" }),
|
|
26
|
+
label && /* @__PURE__ */ jsx("span", { children: label })
|
|
27
|
+
]
|
|
28
|
+
}
|
|
29
|
+
) }, id);
|
|
30
|
+
}) }) }) });
|
|
31
|
+
};
|
|
32
|
+
export {
|
|
33
|
+
Aside
|
|
34
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { ReactFlowProvider } from "@xyflow/react";
|
|
3
|
+
import { AttackFlowLayout } from "./AttackFlowLayout.js";
|
|
4
|
+
const AttackFlow = ({ content, className }) => {
|
|
5
|
+
return /* @__PURE__ */ jsx(ReactFlowProvider, { children: /* @__PURE__ */ jsx(AttackFlowLayout, { content, className }) });
|
|
6
|
+
};
|
|
7
|
+
export {
|
|
8
|
+
AttackFlow
|
|
9
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ReactFlow } from "@xyflow/react";
|
|
3
|
+
import { useMemo } from "react";
|
|
4
|
+
import { Controls } from "./Controls.js";
|
|
5
|
+
import { Node } from "./Node.js";
|
|
6
|
+
import { OtherNode } from "./OtherNode.js";
|
|
7
|
+
import { useAttackFlow } from "./useAttackFlow.js";
|
|
8
|
+
import "@xyflow/react/dist/style.css";
|
|
9
|
+
const nodeTypes = {
|
|
10
|
+
attack: ({ data }) => /* @__PURE__ */ jsx(Node, { ...data }),
|
|
11
|
+
and: ({ data }) => /* @__PURE__ */ jsx(OtherNode, { ...data })
|
|
12
|
+
};
|
|
13
|
+
const edgeTypes = {};
|
|
14
|
+
const AttackFlowLayout = ({ content, className }) => {
|
|
15
|
+
const {
|
|
16
|
+
nodes,
|
|
17
|
+
edges,
|
|
18
|
+
reactFlowWrapper,
|
|
19
|
+
onNodesChange,
|
|
20
|
+
handleCenterFocus,
|
|
21
|
+
handleZoomIn,
|
|
22
|
+
handleZoomOut
|
|
23
|
+
} = useAttackFlow(content);
|
|
24
|
+
const reactFlowProps = useMemo(
|
|
25
|
+
() => ({
|
|
26
|
+
nodes,
|
|
27
|
+
edges,
|
|
28
|
+
nodeTypes,
|
|
29
|
+
edgeTypes,
|
|
30
|
+
onNodesChange,
|
|
31
|
+
nodesDraggable: true,
|
|
32
|
+
nodesConnectable: false,
|
|
33
|
+
minZoom: 0,
|
|
34
|
+
maxZoom: 2,
|
|
35
|
+
defaultViewport: {
|
|
36
|
+
x: 0,
|
|
37
|
+
y: 0,
|
|
38
|
+
zoom: 0.8
|
|
39
|
+
},
|
|
40
|
+
zoomOnScroll: true,
|
|
41
|
+
zoomOnPinch: true,
|
|
42
|
+
panOnScroll: true,
|
|
43
|
+
selectNodesOnDrag: false,
|
|
44
|
+
multiSelectionKeyCode: null,
|
|
45
|
+
proOptions: { hideAttribution: true }
|
|
46
|
+
}),
|
|
47
|
+
[nodes, edges, onNodesChange]
|
|
48
|
+
);
|
|
49
|
+
return /* @__PURE__ */ jsxs("div", { className: `relative ${className}`, ref: reactFlowWrapper, children: [
|
|
50
|
+
/* @__PURE__ */ jsx(ReactFlow, { ...reactFlowProps }),
|
|
51
|
+
/* @__PURE__ */ jsx("div", { className: "absolute bottom-3 left-3 z-10 flex flex-col gap-1", children: /* @__PURE__ */ jsx(
|
|
52
|
+
Controls,
|
|
53
|
+
{
|
|
54
|
+
handleCenterFocus,
|
|
55
|
+
handleZoomIn,
|
|
56
|
+
handleZoomOut
|
|
57
|
+
}
|
|
58
|
+
) })
|
|
59
|
+
] });
|
|
60
|
+
};
|
|
61
|
+
export {
|
|
62
|
+
AttackFlowLayout
|
|
63
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ScanIcon, ZoomInIcon, ZoomOutIcon } from "lucide-react";
|
|
3
|
+
import { Fragment } from "react";
|
|
4
|
+
import { Button } from "../Button/Button.js";
|
|
5
|
+
import { Tooltip } from "../Tooltip/Tooltip.js";
|
|
6
|
+
const Controls = ({ handleCenterFocus, handleZoomIn, handleZoomOut }) => {
|
|
7
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
8
|
+
/* @__PURE__ */ jsx(Tooltip, { content: "Return to starting point", children: /* @__PURE__ */ jsx(
|
|
9
|
+
Button,
|
|
10
|
+
{
|
|
11
|
+
className: "bg-primary border-border",
|
|
12
|
+
variant: "icon",
|
|
13
|
+
size: "xs",
|
|
14
|
+
onClick: handleCenterFocus,
|
|
15
|
+
children: /* @__PURE__ */ jsx(ScanIcon, { className: "size-4" })
|
|
16
|
+
}
|
|
17
|
+
) }),
|
|
18
|
+
/* @__PURE__ */ jsx(Tooltip, { content: "Zoom in", children: /* @__PURE__ */ jsx(
|
|
19
|
+
Button,
|
|
20
|
+
{
|
|
21
|
+
className: "bg-primary border-border",
|
|
22
|
+
variant: "icon",
|
|
23
|
+
size: "xs",
|
|
24
|
+
onClick: handleZoomIn,
|
|
25
|
+
children: /* @__PURE__ */ jsx(ZoomInIcon, { className: "size-4" })
|
|
26
|
+
}
|
|
27
|
+
) }),
|
|
28
|
+
/* @__PURE__ */ jsx(Tooltip, { content: "Zoom out", children: /* @__PURE__ */ jsx(
|
|
29
|
+
Button,
|
|
30
|
+
{
|
|
31
|
+
className: "bg-primary border-border",
|
|
32
|
+
variant: "icon",
|
|
33
|
+
size: "xs",
|
|
34
|
+
onClick: handleZoomOut,
|
|
35
|
+
children: /* @__PURE__ */ jsx(ZoomOutIcon, { className: "size-4" })
|
|
36
|
+
}
|
|
37
|
+
) })
|
|
38
|
+
] });
|
|
39
|
+
};
|
|
40
|
+
export {
|
|
41
|
+
Controls
|
|
42
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useThemeColors } from "../../lib/useThemeColors.js";
|
|
3
|
+
import { cn } from "../../lib/cn.js";
|
|
4
|
+
import { Handle, Position } from "@xyflow/react";
|
|
5
|
+
const Node = ({ content, color, nodeId }) => {
|
|
6
|
+
const { default: textDefault, primary } = useThemeColors();
|
|
7
|
+
if (!content) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
const nodeClass = nodeId ? `node-${nodeId}` : "node-draggable";
|
|
11
|
+
return /* @__PURE__ */ jsx(
|
|
12
|
+
"div",
|
|
13
|
+
{
|
|
14
|
+
className: cn(
|
|
15
|
+
"border-border w-auto max-w-[312px] min-w-[250px] overflow-hidden rounded-sm border",
|
|
16
|
+
nodeClass
|
|
17
|
+
),
|
|
18
|
+
style: { backgroundColor: primary, color: textDefault, borderColor: color },
|
|
19
|
+
children: /* @__PURE__ */ jsxs("div", { className: "rounded-sm px-2 py-3", style: { backgroundColor: `${color}20` }, children: [
|
|
20
|
+
/* @__PURE__ */ jsx(
|
|
21
|
+
Handle,
|
|
22
|
+
{
|
|
23
|
+
className: "h-1 w-1",
|
|
24
|
+
type: "target",
|
|
25
|
+
isConnectable: false,
|
|
26
|
+
position: Position.Top,
|
|
27
|
+
style: { backgroundColor: color, borderColor: color }
|
|
28
|
+
}
|
|
29
|
+
),
|
|
30
|
+
/* @__PURE__ */ jsx("div", { className: "rounded-3 px-2 py-3 break-words", children: /* @__PURE__ */ jsx("p", { className: "text-xs", dangerouslySetInnerHTML: { __html: content } }) }),
|
|
31
|
+
/* @__PURE__ */ jsx(
|
|
32
|
+
Handle,
|
|
33
|
+
{
|
|
34
|
+
className: "h-1 w-1",
|
|
35
|
+
type: "source",
|
|
36
|
+
isConnectable: false,
|
|
37
|
+
position: Position.Bottom,
|
|
38
|
+
style: { backgroundColor: color, borderColor: color }
|
|
39
|
+
}
|
|
40
|
+
)
|
|
41
|
+
] })
|
|
42
|
+
}
|
|
43
|
+
);
|
|
44
|
+
};
|
|
45
|
+
export {
|
|
46
|
+
Node
|
|
47
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useThemeColors } from "../../lib/useThemeColors.js";
|
|
3
|
+
import { cn } from "../../lib/cn.js";
|
|
4
|
+
import { Handle, Position } from "@xyflow/react";
|
|
5
|
+
const OtherNode = ({ content, color, nodeId }) => {
|
|
6
|
+
const { warning } = useThemeColors();
|
|
7
|
+
if (!content) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
const nodeClass = nodeId ? `node-${nodeId}` : "node-draggable";
|
|
11
|
+
return /* @__PURE__ */ jsxs(
|
|
12
|
+
"div",
|
|
13
|
+
{
|
|
14
|
+
className: cn("relative flex h-10 w-10 items-center justify-center rounded-full", nodeClass),
|
|
15
|
+
style: { backgroundColor: warning },
|
|
16
|
+
children: [
|
|
17
|
+
/* @__PURE__ */ jsx(
|
|
18
|
+
Handle,
|
|
19
|
+
{
|
|
20
|
+
className: "h-1 w-1",
|
|
21
|
+
type: "target",
|
|
22
|
+
isConnectable: false,
|
|
23
|
+
position: Position.Top,
|
|
24
|
+
style: { backgroundColor: color, borderColor: color, opacity: 0.5 }
|
|
25
|
+
}
|
|
26
|
+
),
|
|
27
|
+
/* @__PURE__ */ jsx("div", { className: "flex h-full w-full items-center justify-center", children: /* @__PURE__ */ jsx("p", { className: "text-sm font-bold", children: content }) }),
|
|
28
|
+
/* @__PURE__ */ jsx(
|
|
29
|
+
Handle,
|
|
30
|
+
{
|
|
31
|
+
className: "h-1 w-1",
|
|
32
|
+
type: "source",
|
|
33
|
+
isConnectable: false,
|
|
34
|
+
position: Position.Bottom,
|
|
35
|
+
style: { backgroundColor: color, borderColor: color, opacity: 0.5 }
|
|
36
|
+
}
|
|
37
|
+
)
|
|
38
|
+
]
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
};
|
|
42
|
+
export {
|
|
43
|
+
OtherNode
|
|
44
|
+
};
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
const COLORS = {
|
|
2
|
+
labelBg: "rgba(41, 44, 61, 0.70)",
|
|
3
|
+
background: "#fafafa",
|
|
4
|
+
border: "#e0e0e0",
|
|
5
|
+
text: "#F9F9F9",
|
|
6
|
+
headerText: "#ffffff",
|
|
7
|
+
connector: "#6280A3",
|
|
8
|
+
and: "rgba(238, 157, 35, 0.5)",
|
|
9
|
+
default: "#5c5c5c"
|
|
10
|
+
};
|
|
11
|
+
const AND_REGEX = /\b(AND|and)\b|\bop_and\d*/;
|
|
12
|
+
const determineNodeClass = (id, lines = []) => {
|
|
13
|
+
if (id === "AND" || id.toLowerCase() === "and" || id.match(/^op_and\d*$/)) {
|
|
14
|
+
return "operator";
|
|
15
|
+
}
|
|
16
|
+
for (const line of lines) {
|
|
17
|
+
const nodeWithLabelMatch = line.match(/(\w+)\(\("([^"]+)"\)\)/);
|
|
18
|
+
if (nodeWithLabelMatch && nodeWithLabelMatch[1] === id && nodeWithLabelMatch[2].toUpperCase() === "AND") {
|
|
19
|
+
return "operator";
|
|
20
|
+
}
|
|
21
|
+
const classMatch = line.match(new RegExp(`class\\s+${id}\\s+(\\w+)`));
|
|
22
|
+
if (classMatch) {
|
|
23
|
+
return classMatch[1];
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return "other";
|
|
27
|
+
};
|
|
28
|
+
const createNode = (id, content, classDefinitions, lines, isAndOperator = false) => {
|
|
29
|
+
const nodeClass = determineNodeClass(id, lines);
|
|
30
|
+
const isAnd = isAndOperator || nodeClass === "operator" || id.match(/^op_and\d*$/) || content.toUpperCase() === "AND";
|
|
31
|
+
const color = classDefinitions.get(nodeClass) || COLORS.default;
|
|
32
|
+
if (isAnd) {
|
|
33
|
+
return {
|
|
34
|
+
id,
|
|
35
|
+
type: "and",
|
|
36
|
+
position: { x: 0, y: 0 },
|
|
37
|
+
data: {
|
|
38
|
+
content: "AND",
|
|
39
|
+
nodeClass: "operator",
|
|
40
|
+
color: classDefinitions.get("operator") || COLORS.and
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
id,
|
|
46
|
+
type: "attack",
|
|
47
|
+
position: { x: 0, y: 0 },
|
|
48
|
+
data: {
|
|
49
|
+
content,
|
|
50
|
+
nodeClass,
|
|
51
|
+
color
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
const createPlaceholderNode = (id, classDefinitions, lines) => {
|
|
56
|
+
const nodeClass = determineNodeClass(id, lines);
|
|
57
|
+
const isAndOperator = nodeClass === "operator" || id.match(/^op_and\d*$/) || id.toUpperCase() === "AND";
|
|
58
|
+
if (isAndOperator) {
|
|
59
|
+
return {
|
|
60
|
+
id,
|
|
61
|
+
type: "and",
|
|
62
|
+
position: { x: 0, y: 0 },
|
|
63
|
+
data: {
|
|
64
|
+
content: "AND",
|
|
65
|
+
nodeClass: "operator",
|
|
66
|
+
color: classDefinitions.get("operator") || COLORS.and
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
id,
|
|
72
|
+
type: "attack",
|
|
73
|
+
position: { x: 0, y: 0 },
|
|
74
|
+
data: {
|
|
75
|
+
content: id,
|
|
76
|
+
nodeClass,
|
|
77
|
+
color: classDefinitions.get(nodeClass) || COLORS.default
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
const parseAttackFlow = (mmdText) => {
|
|
82
|
+
const nodes = [];
|
|
83
|
+
const edges = [];
|
|
84
|
+
const nodeMap = /* @__PURE__ */ new Map();
|
|
85
|
+
const lines = mmdText.split("\n");
|
|
86
|
+
const diagramTypeMatch = lines[0].match(/graph\s+(\w+)/);
|
|
87
|
+
const direction = diagramTypeMatch ? diagramTypeMatch[1] : "TB";
|
|
88
|
+
const classDefinitions = /* @__PURE__ */ new Map();
|
|
89
|
+
lines.forEach((line) => {
|
|
90
|
+
const classDefMatch = line.match(
|
|
91
|
+
/classDef\s+(\w+)\s+fill:(#[0-9a-fA-F]{3,6}|rgb\([^)]+\)|rgba\([^)]+\)|[a-zA-Z]+)/
|
|
92
|
+
);
|
|
93
|
+
if (classDefMatch) {
|
|
94
|
+
classDefinitions.set(classDefMatch[1], classDefMatch[2].trim());
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
if (!classDefinitions.has("operator")) {
|
|
98
|
+
classDefinitions.set("operator", COLORS.and);
|
|
99
|
+
}
|
|
100
|
+
lines.forEach((line) => {
|
|
101
|
+
if (line.startsWith(direction) || line.startsWith("classDef")) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const nodeMatch = line.match(/(\w+)\["([^"]+)"\]/);
|
|
105
|
+
const nodeWithParenMatch = line.match(/(\w+)\(\("([^"]+)"\)\)/);
|
|
106
|
+
if (nodeMatch) {
|
|
107
|
+
const id = nodeMatch[1];
|
|
108
|
+
const content = nodeMatch[2];
|
|
109
|
+
const isAndOperator = id === "op_and" || id === "AND" || AND_REGEX.test(id);
|
|
110
|
+
const node = createNode(id, content, classDefinitions, lines, isAndOperator);
|
|
111
|
+
nodeMap.set(id, node);
|
|
112
|
+
} else if (nodeWithParenMatch) {
|
|
113
|
+
const id = nodeWithParenMatch[1];
|
|
114
|
+
const content = nodeWithParenMatch[2];
|
|
115
|
+
const isAndOperator = /^op_and\d*$/.test(id) || id === "AND" || AND_REGEX.test(id) || content.toUpperCase() === "AND";
|
|
116
|
+
const node = createNode(id, content, classDefinitions, lines, isAndOperator);
|
|
117
|
+
nodeMap.set(id, node);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
lines.forEach((line) => {
|
|
121
|
+
if (line.startsWith(direction) || line.startsWith("classDef")) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const edgeMatch = line.match(/(\w+)\s*-->\s*(?:\|([^|]+)\|)?\s*(\w+)/);
|
|
125
|
+
if (edgeMatch) {
|
|
126
|
+
const source = edgeMatch[1];
|
|
127
|
+
const target = edgeMatch[3];
|
|
128
|
+
if (!nodeMap.has(source)) {
|
|
129
|
+
const sourceNode = createPlaceholderNode(source, classDefinitions, lines);
|
|
130
|
+
nodeMap.set(source, sourceNode);
|
|
131
|
+
}
|
|
132
|
+
if (!nodeMap.has(target)) {
|
|
133
|
+
const targetNode = createPlaceholderNode(target, classDefinitions, lines);
|
|
134
|
+
nodeMap.set(target, targetNode);
|
|
135
|
+
}
|
|
136
|
+
const newEdge = {
|
|
137
|
+
id: `edge-${source}-${target}`,
|
|
138
|
+
source,
|
|
139
|
+
target
|
|
140
|
+
};
|
|
141
|
+
edges.push(newEdge);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
nodeMap.forEach((node) => {
|
|
145
|
+
nodes.push(node);
|
|
146
|
+
});
|
|
147
|
+
return { nodes, edges, direction };
|
|
148
|
+
};
|
|
149
|
+
export {
|
|
150
|
+
AND_REGEX,
|
|
151
|
+
COLORS,
|
|
152
|
+
parseAttackFlow
|
|
153
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { useFullscreen } from "../../lib/useFullscreen.js";
|
|
2
|
+
import { useListenOnResizeDebounce } from "../../lib/useListenOnResizeDebounce.js";
|
|
3
|
+
import { applyNodeChanges, MarkerType, useReactFlow } from "@xyflow/react";
|
|
4
|
+
import dagre from "dagre";
|
|
5
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
6
|
+
import { COLORS, parseAttackFlow } from "./prependData.js";
|
|
7
|
+
const useAttackFlow = (mmdContent) => {
|
|
8
|
+
const [nodes, setNodes] = useState([]);
|
|
9
|
+
const [edges, setEdges] = useState([]);
|
|
10
|
+
const [initialScrollPerformed, setInitialScrollPerformed] = useState(false);
|
|
11
|
+
const { zoomIn, zoomOut, setViewport, getViewport, fitView } = useReactFlow();
|
|
12
|
+
const reactFlowWrapper = useRef(null);
|
|
13
|
+
const { isFullscreen, enterFullscreen, exitFullscreen } = useFullscreen(
|
|
14
|
+
reactFlowWrapper,
|
|
15
|
+
(isFull) => {
|
|
16
|
+
if (!isFull) {
|
|
17
|
+
fitView({ minZoom: 0.2, duration: 500 });
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
);
|
|
21
|
+
const layoutWithDagre = useCallback(
|
|
22
|
+
(localNodes, localEdges, direction) => {
|
|
23
|
+
const dagreGraph = new dagre.graphlib.Graph();
|
|
24
|
+
dagreGraph.setDefaultEdgeLabel(() => ({}));
|
|
25
|
+
const nodeWidth = 310;
|
|
26
|
+
const nodeHeights = {};
|
|
27
|
+
const getNodeHeight = (node) => {
|
|
28
|
+
const nodeType = node.type || "attack";
|
|
29
|
+
if (nodeHeights[nodeType]) {
|
|
30
|
+
return nodeHeights[nodeType];
|
|
31
|
+
}
|
|
32
|
+
if (nodeType === "and") {
|
|
33
|
+
nodeHeights[nodeType] = 100;
|
|
34
|
+
} else {
|
|
35
|
+
const contentLength = node.data.content?.length || 0;
|
|
36
|
+
const estimatedHeight = 150 + Math.min(contentLength / 3, 150);
|
|
37
|
+
nodeHeights[nodeType] = estimatedHeight;
|
|
38
|
+
}
|
|
39
|
+
return nodeHeights[nodeType];
|
|
40
|
+
};
|
|
41
|
+
dagreGraph.setGraph({
|
|
42
|
+
rankdir: direction,
|
|
43
|
+
nodesep: 20,
|
|
44
|
+
ranksep: 0,
|
|
45
|
+
edgesep: 20
|
|
46
|
+
});
|
|
47
|
+
localNodes.forEach((node) => {
|
|
48
|
+
const nodeHeight = getNodeHeight(node);
|
|
49
|
+
dagreGraph.setNode(node.id, { width: nodeWidth, height: nodeHeight });
|
|
50
|
+
});
|
|
51
|
+
localEdges.forEach((edge) => {
|
|
52
|
+
dagreGraph.setEdge(edge.source, edge.target);
|
|
53
|
+
});
|
|
54
|
+
dagre.layout(dagreGraph);
|
|
55
|
+
return localNodes.map((node) => {
|
|
56
|
+
const nodeWithPosition = dagreGraph.node(node.id);
|
|
57
|
+
const nodeHeight = getNodeHeight(node);
|
|
58
|
+
return {
|
|
59
|
+
...node,
|
|
60
|
+
dragHandle: `.node-${node.id}`,
|
|
61
|
+
draggable: true,
|
|
62
|
+
data: {
|
|
63
|
+
...node.data,
|
|
64
|
+
nodeId: node.id
|
|
65
|
+
},
|
|
66
|
+
position: {
|
|
67
|
+
x: nodeWithPosition.x - nodeWidth / 2,
|
|
68
|
+
y: nodeWithPosition.y - nodeHeight / 2
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
});
|
|
72
|
+
},
|
|
73
|
+
[]
|
|
74
|
+
);
|
|
75
|
+
const scrollToTopNodes = useCallback(() => {
|
|
76
|
+
if (nodes.length === 0) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const topY = Math.min(...nodes.map((node) => node.position.y));
|
|
80
|
+
const topLevelYThreshold = topY + 50;
|
|
81
|
+
const topLevelNodes = nodes.filter((node) => node.position.y <= topLevelYThreshold);
|
|
82
|
+
if (topLevelNodes.length > 0) {
|
|
83
|
+
const totalX = topLevelNodes.reduce((sum, node) => sum + node.position.x, 0);
|
|
84
|
+
const avgX = totalX / topLevelNodes.length;
|
|
85
|
+
const width = reactFlowWrapper.current?.clientWidth ?? window.innerWidth;
|
|
86
|
+
setViewport(
|
|
87
|
+
{
|
|
88
|
+
x: width / 2 - avgX - 155,
|
|
89
|
+
y: -topY + 100,
|
|
90
|
+
zoom: 1
|
|
91
|
+
},
|
|
92
|
+
{ duration: 500 }
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
}, [nodes, setViewport]);
|
|
96
|
+
const handleCenterFocus = useCallback(() => {
|
|
97
|
+
if (isFullscreen) {
|
|
98
|
+
fitView({ minZoom: 0.8, duration: 500 });
|
|
99
|
+
} else {
|
|
100
|
+
scrollToTopNodes();
|
|
101
|
+
}
|
|
102
|
+
}, [fitView, isFullscreen, scrollToTopNodes]);
|
|
103
|
+
const toggleFullscreen = useCallback(() => {
|
|
104
|
+
if (!isFullscreen) {
|
|
105
|
+
enterFullscreen().then(() => {
|
|
106
|
+
setTimeout(() => {
|
|
107
|
+
fitView({ minZoom: 0.2, duration: 500 });
|
|
108
|
+
}, 600);
|
|
109
|
+
});
|
|
110
|
+
} else {
|
|
111
|
+
exitFullscreen().then(() => {
|
|
112
|
+
setTimeout(() => {
|
|
113
|
+
fitView({ minZoom: 0.8, duration: 500 });
|
|
114
|
+
}, 600);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}, [fitView, enterFullscreen, exitFullscreen, isFullscreen]);
|
|
118
|
+
const handleZoomIn = useCallback(() => {
|
|
119
|
+
zoomIn();
|
|
120
|
+
}, [zoomIn]);
|
|
121
|
+
const handleZoomOut = useCallback(() => {
|
|
122
|
+
zoomOut();
|
|
123
|
+
}, [zoomOut]);
|
|
124
|
+
const onNodesChange = useCallback((changes) => {
|
|
125
|
+
setNodes((nds) => applyNodeChanges(changes, nds));
|
|
126
|
+
}, []);
|
|
127
|
+
useEffect(() => {
|
|
128
|
+
if (nodes.length > 0 && !initialScrollPerformed) {
|
|
129
|
+
setTimeout(() => {
|
|
130
|
+
scrollToTopNodes();
|
|
131
|
+
setInitialScrollPerformed(true);
|
|
132
|
+
}, 300);
|
|
133
|
+
}
|
|
134
|
+
}, [nodes.length, scrollToTopNodes, initialScrollPerformed]);
|
|
135
|
+
const handleResize = () => {
|
|
136
|
+
if (nodes.length > 0 && initialScrollPerformed) {
|
|
137
|
+
const { x, y, zoom } = getViewport();
|
|
138
|
+
setViewport({ x, y, zoom }, { duration: 0 });
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
useListenOnResizeDebounce(handleResize);
|
|
142
|
+
useEffect(() => {
|
|
143
|
+
const loadAttackFlowFile = async () => {
|
|
144
|
+
try {
|
|
145
|
+
if (!mmdContent) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const { nodes: parsedNodes, edges: parsedEdges, direction } = parseAttackFlow(mmdContent);
|
|
149
|
+
if (parsedNodes.length > 0) {
|
|
150
|
+
const layoutedNodes = layoutWithDagre(parsedNodes, parsedEdges, direction);
|
|
151
|
+
setNodes(layoutedNodes);
|
|
152
|
+
const formattedEdges = parsedEdges.map((edge) => ({
|
|
153
|
+
...edge,
|
|
154
|
+
type: "smoothstep",
|
|
155
|
+
animated: false,
|
|
156
|
+
style: {
|
|
157
|
+
stroke: edge.style?.stroke || COLORS.connector,
|
|
158
|
+
strokeWidth: 2
|
|
159
|
+
},
|
|
160
|
+
markerEnd: {
|
|
161
|
+
type: MarkerType.ArrowClosed,
|
|
162
|
+
color: COLORS.connector,
|
|
163
|
+
width: 16,
|
|
164
|
+
height: 16
|
|
165
|
+
},
|
|
166
|
+
pathOptions: {
|
|
167
|
+
offset: 15,
|
|
168
|
+
curvature: 0.3
|
|
169
|
+
}
|
|
170
|
+
}));
|
|
171
|
+
setEdges(formattedEdges);
|
|
172
|
+
}
|
|
173
|
+
} catch (err) {
|
|
174
|
+
console.error(err);
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
loadAttackFlowFile();
|
|
178
|
+
}, [mmdContent, layoutWithDagre]);
|
|
179
|
+
return {
|
|
180
|
+
isFullscreen,
|
|
181
|
+
nodes,
|
|
182
|
+
edges,
|
|
183
|
+
reactFlowWrapper,
|
|
184
|
+
onNodesChange,
|
|
185
|
+
handleCenterFocus,
|
|
186
|
+
handleZoomIn,
|
|
187
|
+
handleZoomOut,
|
|
188
|
+
toggleFullscreen
|
|
189
|
+
};
|
|
190
|
+
};
|
|
191
|
+
export {
|
|
192
|
+
useAttackFlow
|
|
193
|
+
};
|