@lincyaw/aegis-ui 0.12.0 → 0.13.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.
- package/dist/components/ui/DataTable.cjs +1 -1
- package/dist/components/ui/DataTable.cjs.map +1 -1
- package/dist/components/ui/DataTable.js +205 -207
- package/dist/components/ui/DataTable.js.map +1 -1
- package/dist/components/ui/DetailBeside.cjs +2 -0
- package/dist/components/ui/DetailBeside.cjs.map +1 -0
- package/dist/components/ui/DetailBeside.d.ts +37 -0
- package/dist/components/ui/DetailBeside.js +113 -0
- package/dist/components/ui/DetailBeside.js.map +1 -0
- package/dist/components/ui/FileTree.cjs +1 -1
- package/dist/components/ui/FileTree.cjs.map +1 -1
- package/dist/components/ui/FileTree.js +118 -111
- package/dist/components/ui/FileTree.js.map +1 -1
- package/dist/components/ui/ServiceMap.cjs +1 -1
- package/dist/components/ui/ServiceMap.cjs.map +1 -1
- package/dist/components/ui/ServiceMap.js +305 -262
- package/dist/components/ui/ServiceMap.js.map +1 -1
- package/dist/components/ui/TraceTree.cjs +1 -1
- package/dist/components/ui/TraceTree.cjs.map +1 -1
- package/dist/components/ui/TraceTree.js +182 -178
- package/dist/components/ui/TraceTree.js.map +1 -1
- package/dist/components/ui/index.d.ts +2 -0
- package/dist/components/ui/selectedRowDetail.cjs +2 -0
- package/dist/components/ui/selectedRowDetail.cjs.map +1 -0
- package/dist/components/ui/selectedRowDetail.d.ts +25 -0
- package/dist/components/ui/selectedRowDetail.js +8 -0
- package/dist/components/ui/selectedRowDetail.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +259 -257
- package/dist/index.js.map +1 -1
- package/dist/style.css +1 -1
- package/package.json +1 -1
|
@@ -1,190 +1,197 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useId as
|
|
3
|
-
import { RightOutlined as
|
|
1
|
+
import { jsx as r, jsxs as D, Fragment as K } from "react/jsx-runtime";
|
|
2
|
+
import { useId as Y, useContext as Z, useMemo as P, useState as E, useRef as y, Fragment as ee } from "react";
|
|
3
|
+
import { RightOutlined as te, FolderOutlined as ie, FileOutlined as ae } from "@ant-design/icons";
|
|
4
4
|
/* empty css */
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
import { SelectedRowDetailContext as oe } from "./selectedRowDetail.js";
|
|
6
|
+
function se(l) {
|
|
7
|
+
const n = [], t = /* @__PURE__ */ new Map();
|
|
8
|
+
for (const i of l) {
|
|
9
|
+
const o = i.path.split("/");
|
|
10
|
+
let h = n, f;
|
|
11
|
+
for (const [R, _] of o.slice(0, -1).entries()) {
|
|
12
|
+
const u = `${f?.path ?? ""}${_}/`;
|
|
13
|
+
let c = t.get(u);
|
|
14
|
+
c === void 0 && (c = {
|
|
14
15
|
kind: "directory",
|
|
15
|
-
path:
|
|
16
|
-
name: `${
|
|
17
|
-
depth:
|
|
16
|
+
path: u,
|
|
17
|
+
name: `${_}/`,
|
|
18
|
+
depth: R,
|
|
18
19
|
parentPath: f?.path,
|
|
19
20
|
children: [],
|
|
20
21
|
files: []
|
|
21
|
-
}, t.set(
|
|
22
|
+
}, t.set(u, c), h.push(c)), c.files.push(i), f = c, h = c.children;
|
|
22
23
|
}
|
|
23
24
|
h.push({
|
|
24
25
|
kind: "file",
|
|
25
26
|
path: i.path,
|
|
26
27
|
name: i.path.slice(i.path.lastIndexOf("/") + 1),
|
|
27
28
|
label: i.label,
|
|
28
|
-
depth:
|
|
29
|
+
depth: o.length - 1,
|
|
29
30
|
parentPath: f?.path,
|
|
30
31
|
note: i.note
|
|
31
32
|
});
|
|
32
33
|
}
|
|
33
|
-
return
|
|
34
|
+
return n;
|
|
34
35
|
}
|
|
35
|
-
function
|
|
36
|
+
function B(l, n, t = []) {
|
|
36
37
|
const i = [
|
|
37
|
-
...
|
|
38
|
-
...
|
|
38
|
+
...l.filter((o) => o.kind === "directory"),
|
|
39
|
+
...l.filter((o) => o.kind === "file")
|
|
39
40
|
];
|
|
40
|
-
return i.forEach((
|
|
41
|
-
t.push({ entry:
|
|
41
|
+
return i.forEach((o, h) => {
|
|
42
|
+
t.push({ entry: o, position: h + 1, setSize: i.length }), o.kind === "directory" && n.has(o.path) && B(o.children, n, t);
|
|
42
43
|
}), t;
|
|
43
44
|
}
|
|
44
|
-
function
|
|
45
|
-
const
|
|
46
|
-
return
|
|
47
|
-
(t, i) => `${
|
|
45
|
+
function q(l) {
|
|
46
|
+
const n = l.split("/").slice(0, -1);
|
|
47
|
+
return n.map(
|
|
48
|
+
(t, i) => `${n.slice(0, i + 1).join("/")}/`
|
|
48
49
|
);
|
|
49
50
|
}
|
|
50
|
-
function
|
|
51
|
-
files:
|
|
52
|
-
ariaLabel:
|
|
51
|
+
function he({
|
|
52
|
+
files: l,
|
|
53
|
+
ariaLabel: n,
|
|
53
54
|
selectedPath: t,
|
|
54
55
|
onSelect: i,
|
|
55
|
-
fileHref:
|
|
56
|
+
fileHref: o,
|
|
56
57
|
fileTarget: h,
|
|
57
58
|
expandedPaths: f,
|
|
58
|
-
defaultExpandedPaths:
|
|
59
|
-
onExpandedPathsChange:
|
|
60
|
-
directoryNote:
|
|
61
|
-
className:
|
|
59
|
+
defaultExpandedPaths: R = [],
|
|
60
|
+
onExpandedPathsChange: _,
|
|
61
|
+
directoryNote: u,
|
|
62
|
+
className: c
|
|
62
63
|
}) {
|
|
63
|
-
const
|
|
64
|
-
...
|
|
65
|
-
...
|
|
66
|
-
]), [
|
|
67
|
-
t !==
|
|
68
|
-
.../* @__PURE__ */ new Set([...
|
|
64
|
+
const I = Y(), S = Z(oe), N = P(() => se(l), [l]), [A, j] = E(() => [
|
|
65
|
+
...R,
|
|
66
|
+
...q(t ?? "")
|
|
67
|
+
]), [L, U] = E(t);
|
|
68
|
+
t !== L && (U(t), j([
|
|
69
|
+
.../* @__PURE__ */ new Set([...A, ...q(t ?? "")])
|
|
69
70
|
]));
|
|
70
|
-
const w = f ??
|
|
71
|
-
() =>
|
|
72
|
-
[
|
|
73
|
-
),
|
|
74
|
-
(e) =>
|
|
75
|
-
) ??
|
|
76
|
-
const a =
|
|
77
|
-
f === void 0 &&
|
|
78
|
-
},
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
},
|
|
84
|
-
|
|
71
|
+
const w = f ?? A, k = P(() => new Set(w), [w]), [G, J] = E(), O = y(null), b = P(
|
|
72
|
+
() => B(N, k),
|
|
73
|
+
[N, k]
|
|
74
|
+
), Q = [G, t].find(
|
|
75
|
+
(e) => b.some((s) => s.entry.path === e)
|
|
76
|
+
) ?? b[0]?.entry.path, $ = (e, s) => {
|
|
77
|
+
const a = s ? [...w, e] : w.filter((p) => p !== e);
|
|
78
|
+
f === void 0 && j(a), _?.(a);
|
|
79
|
+
}, g = (e) => {
|
|
80
|
+
const s = O.current?.querySelectorAll(
|
|
81
|
+
':scope > [role="treeitem"], :scope > li > [role="treeitem"]'
|
|
82
|
+
).item(e);
|
|
83
|
+
s instanceof HTMLElement && s.focus();
|
|
84
|
+
}, F = (e) => {
|
|
85
|
+
e.kind === "directory" ? $(e.path, !k.has(e.path)) : i?.(e.path);
|
|
86
|
+
}, V = (e, s, a, p) => {
|
|
87
|
+
const d = a.kind === "directory" && k.has(a.path);
|
|
85
88
|
switch (e.key) {
|
|
86
89
|
case "ArrowDown":
|
|
87
|
-
|
|
90
|
+
g(s + 1);
|
|
88
91
|
break;
|
|
89
92
|
case "ArrowUp":
|
|
90
|
-
|
|
93
|
+
g(s - 1);
|
|
91
94
|
break;
|
|
92
95
|
case "Home":
|
|
93
|
-
|
|
96
|
+
g(0);
|
|
94
97
|
break;
|
|
95
98
|
case "End":
|
|
96
|
-
|
|
99
|
+
g(b.length - 1);
|
|
97
100
|
break;
|
|
98
101
|
case "ArrowRight":
|
|
99
|
-
|
|
102
|
+
d ? g(s + 1) : a.kind === "directory" && $(a.path, !0);
|
|
100
103
|
break;
|
|
101
104
|
case "ArrowLeft":
|
|
102
|
-
if (
|
|
105
|
+
if (d)
|
|
103
106
|
$(a.path, !1);
|
|
104
107
|
else if (a.parentPath !== void 0) {
|
|
105
|
-
const { parentPath:
|
|
106
|
-
|
|
108
|
+
const { parentPath: m } = a;
|
|
109
|
+
g(b.findIndex((v) => v.entry.path === m));
|
|
107
110
|
}
|
|
108
111
|
break;
|
|
109
112
|
case "Enter":
|
|
110
113
|
if (p)
|
|
111
114
|
return;
|
|
112
|
-
|
|
115
|
+
F(a);
|
|
113
116
|
break;
|
|
114
117
|
case " ":
|
|
115
|
-
p ? e.currentTarget.click() :
|
|
118
|
+
p ? e.currentTarget.click() : F(a);
|
|
116
119
|
break;
|
|
117
120
|
default:
|
|
118
121
|
return;
|
|
119
122
|
}
|
|
120
123
|
e.preventDefault();
|
|
121
|
-
},
|
|
122
|
-
return /* @__PURE__ */
|
|
123
|
-
const
|
|
124
|
-
className:
|
|
124
|
+
}, W = ["aegis-file-tree", c ?? ""].filter(Boolean).join(" ");
|
|
125
|
+
return /* @__PURE__ */ r("ul", { ref: O, className: W, role: "tree", "aria-label": n, children: b.map(({ entry: e, position: s, setSize: a }, p) => {
|
|
126
|
+
const d = e.kind === "directory", m = !d && e.path === t, v = d ? u ? u(e.path, e.files) : String(e.files.length) : e.note, C = `${I}-name-${String(p)}`, M = `${I}-note-${String(p)}`, x = d ? void 0 : o?.(e.path), T = {
|
|
127
|
+
className: m ? "aegis-file-tree__item aegis-file-tree__item--selected" : "aegis-file-tree__item",
|
|
125
128
|
style: { "--aegis-file-tree-depth": e.depth },
|
|
126
|
-
"aria-labelledby":
|
|
127
|
-
"aria-describedby":
|
|
129
|
+
"aria-labelledby": C,
|
|
130
|
+
"aria-describedby": v === void 0 ? void 0 : M,
|
|
128
131
|
"aria-level": e.depth + 1,
|
|
129
132
|
"aria-setsize": a,
|
|
130
|
-
"aria-posinset":
|
|
131
|
-
"aria-expanded":
|
|
132
|
-
tabIndex: e.path ===
|
|
133
|
+
"aria-posinset": s,
|
|
134
|
+
"aria-expanded": d ? k.has(e.path) : void 0,
|
|
135
|
+
tabIndex: e.path === Q ? 0 : -1,
|
|
133
136
|
onClick: () => {
|
|
134
|
-
|
|
137
|
+
F(e);
|
|
135
138
|
},
|
|
136
|
-
onKeyDown: (
|
|
137
|
-
|
|
139
|
+
onKeyDown: (X) => {
|
|
140
|
+
V(X, p, e, x !== void 0);
|
|
138
141
|
},
|
|
139
142
|
onFocus: () => {
|
|
140
|
-
|
|
143
|
+
J(e.path);
|
|
141
144
|
}
|
|
142
|
-
},
|
|
143
|
-
|
|
144
|
-
/* @__PURE__ */
|
|
145
|
-
|
|
145
|
+
}, z = /* @__PURE__ */ D(K, { children: [
|
|
146
|
+
d ? /* @__PURE__ */ D(K, { children: [
|
|
147
|
+
/* @__PURE__ */ r(
|
|
148
|
+
te,
|
|
146
149
|
{
|
|
147
150
|
className: "aegis-file-tree__chevron",
|
|
148
151
|
"aria-hidden": !0
|
|
149
152
|
}
|
|
150
153
|
),
|
|
151
|
-
/* @__PURE__ */
|
|
152
|
-
] }) : /* @__PURE__ */
|
|
153
|
-
/* @__PURE__ */
|
|
154
|
+
/* @__PURE__ */ r(ie, { className: "aegis-file-tree__icon", "aria-hidden": !0 })
|
|
155
|
+
] }) : /* @__PURE__ */ r(ae, { className: "aegis-file-tree__icon", "aria-hidden": !0 }),
|
|
156
|
+
/* @__PURE__ */ r(
|
|
154
157
|
"span",
|
|
155
158
|
{
|
|
156
|
-
id:
|
|
159
|
+
id: C,
|
|
157
160
|
className: "aegis-file-tree__name",
|
|
158
161
|
title: e.path,
|
|
159
162
|
children: e.kind === "file" ? e.label ?? e.name : e.name
|
|
160
163
|
}
|
|
161
164
|
),
|
|
162
|
-
|
|
163
|
-
] });
|
|
164
|
-
return
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
"
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
165
|
+
v !== void 0 && /* @__PURE__ */ r("span", { id: M, className: "aegis-file-tree__note", children: v })
|
|
166
|
+
] }), H = m ? S?.placeRow : void 0;
|
|
167
|
+
return /* @__PURE__ */ D(ee, { children: [
|
|
168
|
+
x === void 0 ? /* @__PURE__ */ r(
|
|
169
|
+
"li",
|
|
170
|
+
{
|
|
171
|
+
ref: H,
|
|
172
|
+
role: "treeitem",
|
|
173
|
+
"aria-selected": d ? void 0 : m,
|
|
174
|
+
...T,
|
|
175
|
+
children: z
|
|
176
|
+
}
|
|
177
|
+
) : /* @__PURE__ */ r("li", { role: "none", children: /* @__PURE__ */ r(
|
|
178
|
+
"a",
|
|
179
|
+
{
|
|
180
|
+
ref: H,
|
|
181
|
+
role: "treeitem",
|
|
182
|
+
"aria-selected": m,
|
|
183
|
+
href: x,
|
|
184
|
+
target: h,
|
|
185
|
+
rel: h === "_blank" ? "noopener noreferrer" : void 0,
|
|
186
|
+
...T,
|
|
187
|
+
children: z
|
|
188
|
+
}
|
|
189
|
+
) }),
|
|
190
|
+
m && S?.inline ? /* @__PURE__ */ r("li", { role: "none", children: S.inline }) : null
|
|
191
|
+
] }, e.path);
|
|
185
192
|
}) });
|
|
186
193
|
}
|
|
187
194
|
export {
|
|
188
|
-
|
|
195
|
+
he as FileTree
|
|
189
196
|
};
|
|
190
197
|
//# sourceMappingURL=FileTree.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileTree.js","sources":["../../../src/components/ui/FileTree.tsx"],"sourcesContent":["import {\n type CSSProperties,\n type HTMLAttributes,\n type KeyboardEvent,\n type ReactNode,\n useId,\n useMemo,\n useRef,\n useState,\n} from 'react';\n\nimport { FileOutlined, FolderOutlined, RightOutlined } from '@ant-design/icons';\n\nimport './FileTree.css';\n\nexport interface FileTreeFile {\n /** Path from the tree root with `/` between segments, e.g. `tests/grading.toml`. */\n path: string;\n /** Shown in place of the file name, e.g. a note's name without `.md`. The row's title keeps the path. */\n label?: ReactNode;\n /** Trailing note, typically the file size. It is the row's accessible description, not part of its name. */\n note?: ReactNode;\n}\n\nexport interface FileTreeProps {\n files: FileTreeFile[];\n /** Accessible name of the tree. */\n ariaLabel: string;\n /**\n * Path of the selected file. Whenever it changes, the directories above\n * it open, unless `expandedPaths` controls them.\n */\n selectedPath?: string;\n /** Called with a file's path when it is clicked or activated with Enter or Space. */\n onSelect?: (path: string) => void;\n /**\n * A file's URL. With it each file row is a link, so the browser's own\n * link actions (open in a new tab, copy the address) work on it, and\n * opening the row follows the link as well as calling `onSelect`.\n */\n fileHref?: (path: string) => string;\n /** Where file links open, e.g. `_blank`. */\n fileTarget?: string;\n /** Open directories, each written with a trailing `/`, e.g. `tests/`. Omit it to let the tree track them. */\n expandedPaths?: string[];\n /** Directories open on first render when `expandedPaths` is omitted. */\n defaultExpandedPaths?: string[];\n /** Called with the open directories whenever one opens or closes. */\n onExpandedPathsChange?: (paths: string[]) => void;\n /**\n * A directory's trailing note, from its path (with a trailing `/`) and\n * every file below it at any depth, e.g. how many of them changed. Return\n * `undefined` for no note. Default: the number of files.\n */\n directoryNote?: (path: string, files: FileTreeFile[]) => ReactNode;\n className?: string;\n}\n\ninterface DirectoryEntry {\n kind: 'directory';\n /** The directory's path with a trailing `/`, e.g. `tests/cases/`. */\n path: string;\n name: string;\n depth: number;\n parentPath?: string;\n children: Entry[];\n /** Every file below the directory, at any depth. */\n files: FileTreeFile[];\n}\n\ninterface FileEntry {\n kind: 'file';\n path: string;\n name: string;\n label?: ReactNode;\n depth: number;\n parentPath?: string;\n note?: ReactNode;\n}\n\ntype Entry = DirectoryEntry | FileEntry;\n\ninterface Row {\n entry: Entry;\n position: number;\n setSize: number;\n}\n\nfunction buildEntries(files: FileTreeFile[]): Entry[] {\n const roots: Entry[] = [];\n const directories = new Map<string, DirectoryEntry>();\n for (const file of files) {\n const segments = file.path.split('/');\n let siblings = roots;\n let parent: DirectoryEntry | undefined;\n for (const [depth, segment] of segments.slice(0, -1).entries()) {\n const path = `${parent?.path ?? ''}${segment}/`;\n let directory = directories.get(path);\n if (directory === undefined) {\n directory = {\n kind: 'directory',\n path,\n name: `${segment}/`,\n depth,\n parentPath: parent?.path,\n children: [],\n files: [],\n };\n directories.set(path, directory);\n siblings.push(directory);\n }\n directory.files.push(file);\n parent = directory;\n siblings = directory.children;\n }\n siblings.push({\n kind: 'file',\n path: file.path,\n name: file.path.slice(file.path.lastIndexOf('/') + 1),\n label: file.label,\n depth: segments.length - 1,\n parentPath: parent?.path,\n note: file.note,\n });\n }\n return roots;\n}\n\n/** Rows of the open part of the tree; each level lists its directories before its files. */\nfunction visibleRows(\n entries: Entry[],\n expanded: ReadonlySet<string>,\n rows: Row[] = [],\n): Row[] {\n const ordered = [\n ...entries.filter((entry) => entry.kind === 'directory'),\n ...entries.filter((entry) => entry.kind === 'file'),\n ];\n ordered.forEach((entry, index) => {\n rows.push({ entry, position: index + 1, setSize: ordered.length });\n if (entry.kind === 'directory' && expanded.has(entry.path)) {\n visibleRows(entry.children, expanded, rows);\n }\n });\n return rows;\n}\n\nfunction ancestorPaths(path: string): string[] {\n const segments = path.split('/').slice(0, -1);\n return segments.map(\n (_, index) => `${segments.slice(0, index + 1).join('/')}/`,\n );\n}\n\nexport function FileTree({\n files,\n ariaLabel,\n selectedPath,\n onSelect,\n fileHref,\n fileTarget,\n expandedPaths,\n defaultExpandedPaths = [],\n onExpandedPathsChange,\n directoryNote,\n className,\n}: FileTreeProps) {\n const idPrefix = useId();\n const entries = useMemo(() => buildEntries(files), [files]);\n const [trackedPaths, setTrackedPaths] = useState<string[]>(() => [\n ...defaultExpandedPaths,\n ...ancestorPaths(selectedPath ?? ''),\n ]);\n const [revealedPath, setRevealedPath] = useState(selectedPath);\n if (selectedPath !== revealedPath) {\n setRevealedPath(selectedPath);\n setTrackedPaths([\n ...new Set([...trackedPaths, ...ancestorPaths(selectedPath ?? '')]),\n ]);\n }\n const openPaths = expandedPaths ?? trackedPaths;\n const expanded = useMemo(() => new Set(openPaths), [openPaths]);\n const [focusedPath, setFocusedPath] = useState<string>();\n const listRef = useRef<HTMLUListElement>(null);\n const rows = useMemo(\n () => visibleRows(entries, expanded),\n [entries, expanded],\n );\n const tabStop =\n [focusedPath, selectedPath].find((path) =>\n rows.some((row) => row.entry.path === path),\n ) ?? rows[0]?.entry.path;\n\n const setDirectoryExpanded = (path: string, open: boolean): void => {\n const next = open\n ? [...openPaths, path]\n : openPaths.filter((item) => item !== path);\n if (expandedPaths === undefined) {\n setTrackedPaths(next);\n }\n onExpandedPathsChange?.(next);\n };\n\n const focusRow = (index: number): void => {\n const item = listRef.current\n ?.querySelectorAll('[role=\"treeitem\"]')\n .item(index);\n if (item instanceof HTMLElement) {\n item.focus();\n }\n };\n\n const activate = (entry: Entry): void => {\n if (entry.kind === 'directory') {\n setDirectoryExpanded(entry.path, !expanded.has(entry.path));\n } else {\n onSelect?.(entry.path);\n }\n };\n\n const handleKeyDown = (\n event: KeyboardEvent<HTMLElement>,\n index: number,\n entry: Entry,\n isLink: boolean,\n ): void => {\n const open = entry.kind === 'directory' && expanded.has(entry.path);\n switch (event.key) {\n case 'ArrowDown':\n focusRow(index + 1);\n break;\n case 'ArrowUp':\n focusRow(index - 1);\n break;\n case 'Home':\n focusRow(0);\n break;\n case 'End':\n focusRow(rows.length - 1);\n break;\n case 'ArrowRight':\n if (open) {\n focusRow(index + 1);\n } else if (entry.kind === 'directory') {\n setDirectoryExpanded(entry.path, true);\n }\n break;\n case 'ArrowLeft':\n if (open) {\n setDirectoryExpanded(entry.path, false);\n } else if (entry.parentPath !== undefined) {\n const { parentPath } = entry;\n focusRow(rows.findIndex((row) => row.entry.path === parentPath));\n }\n break;\n case 'Enter':\n // A link's own Enter follows it and clicks it, which activates it.\n if (isLink) {\n return;\n }\n activate(entry);\n break;\n case ' ':\n if (isLink) {\n event.currentTarget.click();\n } else {\n activate(entry);\n }\n break;\n default:\n return;\n }\n event.preventDefault();\n };\n\n const cls = ['aegis-file-tree', className ?? ''].filter(Boolean).join(' ');\n\n return (\n <ul ref={listRef} className={cls} role=\"tree\" aria-label={ariaLabel}>\n {rows.map(({ entry, position, setSize }, index) => {\n const isDirectory = entry.kind === 'directory';\n const selected = !isDirectory && entry.path === selectedPath;\n const note = !isDirectory\n ? entry.note\n : directoryNote\n ? directoryNote(entry.path, entry.files)\n : String(entry.files.length);\n const nameId = `${idPrefix}-name-${String(index)}`;\n const noteId = `${idPrefix}-note-${String(index)}`;\n const href = isDirectory ? undefined : fileHref?.(entry.path);\n const itemProps: HTMLAttributes<HTMLElement> = {\n className: selected\n ? 'aegis-file-tree__item aegis-file-tree__item--selected'\n : 'aegis-file-tree__item',\n style: { '--aegis-file-tree-depth': entry.depth } as CSSProperties,\n 'aria-labelledby': nameId,\n 'aria-describedby': note === undefined ? undefined : noteId,\n 'aria-level': entry.depth + 1,\n 'aria-setsize': setSize,\n 'aria-posinset': position,\n 'aria-expanded': isDirectory ? expanded.has(entry.path) : undefined,\n tabIndex: entry.path === tabStop ? 0 : -1,\n onClick: () => {\n activate(entry);\n },\n onKeyDown: (event) => {\n handleKeyDown(event, index, entry, href !== undefined);\n },\n onFocus: () => {\n setFocusedPath(entry.path);\n },\n };\n const content = (\n <>\n {isDirectory ? (\n <>\n <RightOutlined\n className=\"aegis-file-tree__chevron\"\n aria-hidden\n />\n <FolderOutlined className=\"aegis-file-tree__icon\" aria-hidden />\n </>\n ) : (\n <FileOutlined className=\"aegis-file-tree__icon\" aria-hidden />\n )}\n <span\n id={nameId}\n className=\"aegis-file-tree__name\"\n title={entry.path}\n >\n {entry.kind === 'file' ? (entry.label ?? entry.name) : entry.name}\n </span>\n {note !== undefined && (\n <span id={noteId} className=\"aegis-file-tree__note\">\n {note}\n </span>\n )}\n </>\n );\n return href === undefined ? (\n <li\n key={entry.path}\n role=\"treeitem\"\n aria-selected={isDirectory ? undefined : selected}\n {...itemProps}\n >\n {content}\n </li>\n ) : (\n <li key={entry.path} role=\"none\">\n <a\n role=\"treeitem\"\n aria-selected={selected}\n href={href}\n target={fileTarget}\n rel={fileTarget === '_blank' ? 'noopener noreferrer' : undefined}\n {...itemProps}\n >\n {content}\n </a>\n </li>\n );\n })}\n </ul>\n );\n}\n"],"names":["buildEntries","files","roots","directories","file","segments","siblings","parent","depth","segment","path","directory","visibleRows","entries","expanded","rows","ordered","entry","index","ancestorPaths","_","FileTree","ariaLabel","selectedPath","onSelect","fileHref","fileTarget","expandedPaths","defaultExpandedPaths","onExpandedPathsChange","directoryNote","className","idPrefix","useId","useMemo","trackedPaths","setTrackedPaths","useState","revealedPath","setRevealedPath","openPaths","focusedPath","setFocusedPath","listRef","useRef","tabStop","row","setDirectoryExpanded","open","next","item","focusRow","activate","handleKeyDown","event","isLink","parentPath","cls","position","setSize","isDirectory","selected","note","nameId","noteId","href","itemProps","content","jsxs","Fragment","jsx","RightOutlined","FolderOutlined","FileOutlined"],"mappings":";;;;AAwFA,SAASA,GAAaC,GAAgC;AACpD,QAAMC,IAAiB,CAAA,GACjBC,wBAAkB,IAAA;AACxB,aAAWC,KAAQH,GAAO;AACxB,UAAMI,IAAWD,EAAK,KAAK,MAAM,GAAG;AACpC,QAAIE,IAAWJ,GACXK;AACJ,eAAW,CAACC,GAAOC,CAAO,KAAKJ,EAAS,MAAM,GAAG,EAAE,EAAE,WAAW;AAC9D,YAAMK,IAAO,GAAGH,GAAQ,QAAQ,EAAE,GAAGE,CAAO;AAC5C,UAAIE,IAAYR,EAAY,IAAIO,CAAI;AACpC,MAAIC,MAAc,WAChBA,IAAY;AAAA,QACV,MAAM;AAAA,QACN,MAAAD;AAAA,QACA,MAAM,GAAGD,CAAO;AAAA,QAChB,OAAAD;AAAA,QACA,YAAYD,GAAQ;AAAA,QACpB,UAAU,CAAA;AAAA,QACV,OAAO,CAA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n type HTMLAttributes,\n type KeyboardEvent,\n type ReactNode,\n useContext,\n useId,\n useMemo,\n useRef,\n useState,\n} from 'react';\n\nimport { FileOutlined, FolderOutlined, RightOutlined } from '@ant-design/icons';\n\nimport './FileTree.css';\nimport { SelectedRowDetailContext } from './selectedRowDetail';\n\nexport interface FileTreeFile {\n /** Path from the tree root with `/` between segments, e.g. `tests/grading.toml`. */\n path: string;\n /** Shown in place of the file name, e.g. a note's name without `.md`. The row's title keeps the path. */\n label?: ReactNode;\n /** Trailing note, typically the file size. It is the row's accessible description, not part of its name. */\n note?: ReactNode;\n}\n\nexport interface FileTreeProps {\n files: FileTreeFile[];\n /** Accessible name of the tree. */\n ariaLabel: string;\n /**\n * Path of the selected file. Whenever it changes, the directories above\n * it open, unless `expandedPaths` controls them.\n */\n selectedPath?: string;\n /** Called with a file's path when it is clicked or activated with Enter or Space. */\n onSelect?: (path: string) => void;\n /**\n * A file's URL. With it each file row is a link, so the browser's own\n * link actions (open in a new tab, copy the address) work on it, and\n * opening the row follows the link as well as calling `onSelect`.\n */\n fileHref?: (path: string) => string;\n /** Where file links open, e.g. `_blank`. */\n fileTarget?: string;\n /** Open directories, each written with a trailing `/`, e.g. `tests/`. Omit it to let the tree track them. */\n expandedPaths?: string[];\n /** Directories open on first render when `expandedPaths` is omitted. */\n defaultExpandedPaths?: string[];\n /** Called with the open directories whenever one opens or closes. */\n onExpandedPathsChange?: (paths: string[]) => void;\n /**\n * A directory's trailing note, from its path (with a trailing `/`) and\n * every file below it at any depth, e.g. how many of them changed. Return\n * `undefined` for no note. Default: the number of files.\n */\n directoryNote?: (path: string, files: FileTreeFile[]) => ReactNode;\n className?: string;\n}\n\ninterface DirectoryEntry {\n kind: 'directory';\n /** The directory's path with a trailing `/`, e.g. `tests/cases/`. */\n path: string;\n name: string;\n depth: number;\n parentPath?: string;\n children: Entry[];\n /** Every file below the directory, at any depth. */\n files: FileTreeFile[];\n}\n\ninterface FileEntry {\n kind: 'file';\n path: string;\n name: string;\n label?: ReactNode;\n depth: number;\n parentPath?: string;\n note?: ReactNode;\n}\n\ntype Entry = DirectoryEntry | FileEntry;\n\ninterface Row {\n entry: Entry;\n position: number;\n setSize: number;\n}\n\nfunction buildEntries(files: FileTreeFile[]): Entry[] {\n const roots: Entry[] = [];\n const directories = new Map<string, DirectoryEntry>();\n for (const file of files) {\n const segments = file.path.split('/');\n let siblings = roots;\n let parent: DirectoryEntry | undefined;\n for (const [depth, segment] of segments.slice(0, -1).entries()) {\n const path = `${parent?.path ?? ''}${segment}/`;\n let directory = directories.get(path);\n if (directory === undefined) {\n directory = {\n kind: 'directory',\n path,\n name: `${segment}/`,\n depth,\n parentPath: parent?.path,\n children: [],\n files: [],\n };\n directories.set(path, directory);\n siblings.push(directory);\n }\n directory.files.push(file);\n parent = directory;\n siblings = directory.children;\n }\n siblings.push({\n kind: 'file',\n path: file.path,\n name: file.path.slice(file.path.lastIndexOf('/') + 1),\n label: file.label,\n depth: segments.length - 1,\n parentPath: parent?.path,\n note: file.note,\n });\n }\n return roots;\n}\n\n/** Rows of the open part of the tree; each level lists its directories before its files. */\nfunction visibleRows(\n entries: Entry[],\n expanded: ReadonlySet<string>,\n rows: Row[] = [],\n): Row[] {\n const ordered = [\n ...entries.filter((entry) => entry.kind === 'directory'),\n ...entries.filter((entry) => entry.kind === 'file'),\n ];\n ordered.forEach((entry, index) => {\n rows.push({ entry, position: index + 1, setSize: ordered.length });\n if (entry.kind === 'directory' && expanded.has(entry.path)) {\n visibleRows(entry.children, expanded, rows);\n }\n });\n return rows;\n}\n\nfunction ancestorPaths(path: string): string[] {\n const segments = path.split('/').slice(0, -1);\n return segments.map(\n (_, index) => `${segments.slice(0, index + 1).join('/')}/`,\n );\n}\n\nexport function FileTree({\n files,\n ariaLabel,\n selectedPath,\n onSelect,\n fileHref,\n fileTarget,\n expandedPaths,\n defaultExpandedPaths = [],\n onExpandedPathsChange,\n directoryNote,\n className,\n}: FileTreeProps) {\n const idPrefix = useId();\n const selection = useContext(SelectedRowDetailContext);\n const entries = useMemo(() => buildEntries(files), [files]);\n const [trackedPaths, setTrackedPaths] = useState<string[]>(() => [\n ...defaultExpandedPaths,\n ...ancestorPaths(selectedPath ?? ''),\n ]);\n const [revealedPath, setRevealedPath] = useState(selectedPath);\n if (selectedPath !== revealedPath) {\n setRevealedPath(selectedPath);\n setTrackedPaths([\n ...new Set([...trackedPaths, ...ancestorPaths(selectedPath ?? '')]),\n ]);\n }\n const openPaths = expandedPaths ?? trackedPaths;\n const expanded = useMemo(() => new Set(openPaths), [openPaths]);\n const [focusedPath, setFocusedPath] = useState<string>();\n const listRef = useRef<HTMLUListElement>(null);\n const rows = useMemo(\n () => visibleRows(entries, expanded),\n [entries, expanded],\n );\n const tabStop =\n [focusedPath, selectedPath].find((path) =>\n rows.some((row) => row.entry.path === path),\n ) ?? rows[0]?.entry.path;\n\n const setDirectoryExpanded = (path: string, open: boolean): void => {\n const next = open\n ? [...openPaths, path]\n : openPaths.filter((item) => item !== path);\n if (expandedPaths === undefined) {\n setTrackedPaths(next);\n }\n onExpandedPathsChange?.(next);\n };\n\n const focusRow = (index: number): void => {\n // Only the tree's own rows: a detail drawn among them may hold a tree.\n const item = listRef.current\n ?.querySelectorAll(\n ':scope > [role=\"treeitem\"], :scope > li > [role=\"treeitem\"]',\n )\n .item(index);\n if (item instanceof HTMLElement) {\n item.focus();\n }\n };\n\n const activate = (entry: Entry): void => {\n if (entry.kind === 'directory') {\n setDirectoryExpanded(entry.path, !expanded.has(entry.path));\n } else {\n onSelect?.(entry.path);\n }\n };\n\n const handleKeyDown = (\n event: KeyboardEvent<HTMLElement>,\n index: number,\n entry: Entry,\n isLink: boolean,\n ): void => {\n const open = entry.kind === 'directory' && expanded.has(entry.path);\n switch (event.key) {\n case 'ArrowDown':\n focusRow(index + 1);\n break;\n case 'ArrowUp':\n focusRow(index - 1);\n break;\n case 'Home':\n focusRow(0);\n break;\n case 'End':\n focusRow(rows.length - 1);\n break;\n case 'ArrowRight':\n if (open) {\n focusRow(index + 1);\n } else if (entry.kind === 'directory') {\n setDirectoryExpanded(entry.path, true);\n }\n break;\n case 'ArrowLeft':\n if (open) {\n setDirectoryExpanded(entry.path, false);\n } else if (entry.parentPath !== undefined) {\n const { parentPath } = entry;\n focusRow(rows.findIndex((row) => row.entry.path === parentPath));\n }\n break;\n case 'Enter':\n // A link's own Enter follows it and clicks it, which activates it.\n if (isLink) {\n return;\n }\n activate(entry);\n break;\n case ' ':\n if (isLink) {\n event.currentTarget.click();\n } else {\n activate(entry);\n }\n break;\n default:\n return;\n }\n event.preventDefault();\n };\n\n const cls = ['aegis-file-tree', className ?? ''].filter(Boolean).join(' ');\n\n return (\n <ul ref={listRef} className={cls} role=\"tree\" aria-label={ariaLabel}>\n {rows.map(({ entry, position, setSize }, index) => {\n const isDirectory = entry.kind === 'directory';\n const selected = !isDirectory && entry.path === selectedPath;\n const note = !isDirectory\n ? entry.note\n : directoryNote\n ? directoryNote(entry.path, entry.files)\n : String(entry.files.length);\n const nameId = `${idPrefix}-name-${String(index)}`;\n const noteId = `${idPrefix}-note-${String(index)}`;\n const href = isDirectory ? undefined : fileHref?.(entry.path);\n const itemProps: HTMLAttributes<HTMLElement> = {\n className: selected\n ? 'aegis-file-tree__item aegis-file-tree__item--selected'\n : 'aegis-file-tree__item',\n style: { '--aegis-file-tree-depth': entry.depth } as CSSProperties,\n 'aria-labelledby': nameId,\n 'aria-describedby': note === undefined ? undefined : noteId,\n 'aria-level': entry.depth + 1,\n 'aria-setsize': setSize,\n 'aria-posinset': position,\n 'aria-expanded': isDirectory ? expanded.has(entry.path) : undefined,\n tabIndex: entry.path === tabStop ? 0 : -1,\n onClick: () => {\n activate(entry);\n },\n onKeyDown: (event) => {\n handleKeyDown(event, index, entry, href !== undefined);\n },\n onFocus: () => {\n setFocusedPath(entry.path);\n },\n };\n const content = (\n <>\n {isDirectory ? (\n <>\n <RightOutlined\n className=\"aegis-file-tree__chevron\"\n aria-hidden\n />\n <FolderOutlined className=\"aegis-file-tree__icon\" aria-hidden />\n </>\n ) : (\n <FileOutlined className=\"aegis-file-tree__icon\" aria-hidden />\n )}\n <span\n id={nameId}\n className=\"aegis-file-tree__name\"\n title={entry.path}\n >\n {entry.kind === 'file' ? (entry.label ?? entry.name) : entry.name}\n </span>\n {note !== undefined && (\n <span id={noteId} className=\"aegis-file-tree__note\">\n {note}\n </span>\n )}\n </>\n );\n const rowRef = selected ? selection?.placeRow : undefined;\n return (\n <Fragment key={entry.path}>\n {href === undefined ? (\n <li\n ref={rowRef}\n role=\"treeitem\"\n aria-selected={isDirectory ? undefined : selected}\n {...itemProps}\n >\n {content}\n </li>\n ) : (\n <li role=\"none\">\n <a\n ref={rowRef}\n role=\"treeitem\"\n aria-selected={selected}\n href={href}\n target={fileTarget}\n rel={\n fileTarget === '_blank' ? 'noopener noreferrer' : undefined\n }\n {...itemProps}\n >\n {content}\n </a>\n </li>\n )}\n {selected && selection?.inline ? (\n <li role=\"none\">{selection.inline}</li>\n ) : null}\n </Fragment>\n );\n })}\n </ul>\n );\n}\n"],"names":["buildEntries","files","roots","directories","file","segments","siblings","parent","depth","segment","path","directory","visibleRows","entries","expanded","rows","ordered","entry","index","ancestorPaths","_","FileTree","ariaLabel","selectedPath","onSelect","fileHref","fileTarget","expandedPaths","defaultExpandedPaths","onExpandedPathsChange","directoryNote","className","idPrefix","useId","selection","useContext","SelectedRowDetailContext","useMemo","trackedPaths","setTrackedPaths","useState","revealedPath","setRevealedPath","openPaths","focusedPath","setFocusedPath","listRef","useRef","tabStop","row","setDirectoryExpanded","open","next","item","focusRow","activate","handleKeyDown","event","isLink","parentPath","cls","position","setSize","isDirectory","selected","note","nameId","noteId","href","itemProps","content","jsxs","Fragment","jsx","RightOutlined","FolderOutlined","FileOutlined","rowRef"],"mappings":";;;;;AA2FA,SAASA,GAAaC,GAAgC;AACpD,QAAMC,IAAiB,CAAA,GACjBC,wBAAkB,IAAA;AACxB,aAAWC,KAAQH,GAAO;AACxB,UAAMI,IAAWD,EA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L,MAAK;AAAA,UACL,iBAAed,IAAc,SAAYC;AAAA,UACxC,GAAGK;AAAA,UAEH,UAAAC;AAAA,QAAA;AAAA,MAAA,IAGH,gBAAAG,EAAC,MAAA,EAAG,MAAK,QACP,UAAA,gBAAAA;AAAA,QAAC;AAAA,QAAA;AAAA,UACC,KAAKI;AAAA,UACL,MAAK;AAAA,UACL,iBAAeb;AAAA,UACf,MAAAI;AAAA,UACA,QAAQ1C;AAAA,UACR,KACEA,MAAe,WAAW,wBAAwB;AAAA,UAEnD,GAAG2C;AAAA,UAEH,UAAAC;AAAA,QAAA;AAAA,MAAA,GAEL;AAAA,MAEDN,KAAY9B,GAAW,SACtB,gBAAAuC,EAAC,QAAG,MAAK,QAAQ,UAAAvC,EAAU,OAAA,CAAO,IAChC;AAAA,IAAA,EAAA,GA7BSjB,EAAM,IA8BrB;AAAA,EAEJ,CAAC,EAAA,CACH;AAEJ;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react/jsx-runtime"),f=require("react"),Z=require("@dagrejs/dagre"),p=require("@xyflow/react"),te=require("../../hooks/useMediaQuery.cjs");;/* empty css */const se=require("./StatusDot.cjs"),oe=require("../../locale/useStrings.cjs"),B=180,G=64,ie=320,U=28,ae=64,ne={"--aegis-service-map-node-w":`${String(B)}px`,"--aegis-service-map-node-h":`${String(G)}px`,"--aegis-service-map-node-max-w":`${String(ie)}px`,"--aegis-service-map-group-label-h":`${String(U)}px`},re={width:B,height:G};function ce(e,o,r,i){const n=e.map(s=>s.id),m=new Set(n);return{direction:i,ids:n,links:o.filter(s=>m.has(s.source)&&m.has(s.target)).map(s=>[s.source,s.target]),groups:r}}function le(e,o){const r=new Set(e),i=new Set,n=o.map(s=>{const l=[...new Set(s.nodeIds)].filter(a=>r.has(a)&&!i.has(a));return l.forEach(a=>i.add(a)),{group:s,ids:l}}),m=e.filter(s=>!i.has(s));return[...n,{ids:m}].filter(s=>s.ids.length>0)}function de(e,o,r,i){const n=new Z.graphlib.Graph;n.setDefaultEdgeLabel(()=>({})),n.setGraph({rankdir:r,nodesep:40,ranksep:80,marginx:16,marginy:16});for(const a of e)n.setNode(a,{...i(a)});for(const[a,t]of o)n.hasNode(a)&&n.hasNode(t)&&n.setEdge(a,t);Z.layout(n);const m=new Map(e.map(a=>{const{x:t=0,y:u=0}=n.node(a),h=i(a);return[a,{x:t-h.width/2,y:u-h.height/2}]})),{width:s=0,height:l=0}=n.graph();return{positions:m,width:s,height:l}}function ge(e,o,r){const i=t=>`${r}-group-${String(e.groups.indexOf(t))}`,n=e.direction==="LR",m=le(e.ids,e.groups).map(t=>{const u=de(t.ids,e.links,e.direction,_=>o.get(_)??re),h=t.group===void 0?0:U;return{...t,...u,labelHeight:h,boxHeight:u.height+h}}),s=Math.max(0,...m.map(t=>n?t.boxHeight:t.width));let l=0;const a=m.map(t=>{const u=n?{x:l,y:(s-t.boxHeight)/2}:{x:(s-t.width)/2,y:l};return l+=(n?t.width:t.boxHeight)+ae,{...t,origin:u}});return{groups:a.flatMap(t=>t.group===void 0?[]:[{id:`group:${t.group.id}`,type:"serviceGroup",position:t.origin,width:t.width,height:t.boxHeight,data:{label:t.group.label,labelId:i(t.group)},domAttributes:{"aria-roledescription":void 0,"aria-describedby":void 0},zIndex:-1,style:{pointerEvents:"none"},draggable:!1,connectable:!1,selectable:!1,focusable:!1}]),positions:new Map(a.flatMap(t=>[...t.positions].map(([u,h])=>[u,{x:t.origin.x+h.x,y:t.origin.y+t.labelHeight+h.y}]))),groupLabels:new Map(a.flatMap(t=>{const{group:u}=t;return u===void 0?[]:t.ids.map(h=>[h,i(u)])}))}}function ue({data:e}){return d.jsx("div",{className:"aegis-service-map__group",children:d.jsx("span",{id:e.labelId,className:"aegis-service-map__group-label",children:e.label})})}const pe={ok:"ink",active:"ink",warn:"caution",error:"warning",muted:"muted"};function me({data:e}){const{node:o,selected:r}=e,i=o.status??"ok",n=pe[i];return d.jsxs("div",{className:["aegis-service-map__node",`aegis-service-map__node--${i}`,r?"aegis-service-map__node--selected":""].filter(Boolean).join(" "),children:[d.jsx(p.Handle,{type:"target",position:p.Position.Left,className:"aegis-service-map__handle"}),d.jsxs("div",{className:"aegis-service-map__node-body",children:[d.jsxs("div",{className:"aegis-service-map__node-label",children:[d.jsx(se.StatusDot,{pulse:i==="active",tone:r&&n==="ink"?"inverted":n}),d.jsx("span",{className:"aegis-service-map__node-label-text",children:o.label})]}),o.sublabel!==void 0&&d.jsx("div",{className:"aegis-service-map__node-sublabel",children:o.sublabel})]}),o.badge!==void 0&&o.badge!==""&&d.jsx("span",{className:`aegis-service-map__node-badge aegis-service-map__node-badge--${i}`,children:o.badge}),d.jsx(p.Handle,{type:"source",position:p.Position.Right,className:"aegis-service-map__handle"})]})}function he(e){const{sourceX:o,sourceY:r,targetX:i,targetY:n,label:m,markerEnd:s,style:l}=e,a=f.useId(),t=(o+i)/2,u=`M${o},${r} C${t},${r} ${t},${n} ${i},${n}`;return d.jsxs(d.Fragment,{children:[d.jsx("path",{d:u,className:"aegis-service-map__edge-focus",fill:"none"}),d.jsx("path",{id:a,d:u,className:"aegis-service-map__edge-path",markerEnd:s,style:l,fill:"none"}),m!==void 0&&m!==""&&d.jsx("text",{className:"aegis-service-map__edge-label",children:d.jsx("textPath",{href:`#${a}`,startOffset:"50%",textAnchor:"middle",children:m})})]})}const fe={service:me,serviceGroup:ue},be={service:he},ve="(max-width: 768px)",R=24,k=.1,A=1,q=11/13,F=15,V=28,W=200,H=e=>`${e}px`;function _e(e,o){return[...new Set([e,...o.filter(([r])=>r===e).map(([,r])=>r),...o.filter(([,r])=>r===e).map(([r])=>r)])]}function xe(e){return e.type==="serviceGroup"?"aegis-service-map__minimap-group":""}function we(e,o,r,i,n,m){const{fitView:s,getNodes:l,getNodesBounds:a,setViewport:t}=p.useReactFlow(),u=p.useStoreApi(),h=p.useStore(b=>b.width>0&&b.height>0),_=f.useMemo(()=>i!==void 0&&e.ids.includes(i)?{id:i,near:_e(i,e.links)}:void 0,[i,e]);f.useEffect(()=>{if(h&&r){const b={top:H(R),bottom:H(R),left:H(F+V+R),right:H(n?F+W+R:R)},{width:E,height:j}=u.getState();if(_===void 0){const x=l(),w=a(x),O=p.getViewportForBounds(w,E,j,k,1,b);if(m&&O.zoom<q){const M=q,D=e.direction==="LR",$=S=>D?S.position.x:S.position.y,y=x.filter(S=>S.type==="service").reduce((S,T)=>$(T)<$(S)?T:S),{width:P=B,height:I=G}=y.measured??{};t(D?{x:F+V+R-w.x*M,y:j/2-(y.position.y+I/2)*M,zoom:M}:{x:E/2-(y.position.x+P/2)*M,y:R-w.y*M,zoom:M})}else s({maxZoom:1,padding:b})}else{const x=p.getViewportForBounds(a(_.near),E,j,k,A,b).zoom>=A;s({nodes:(x?_.near:[_.id]).map(w=>({id:w})),minZoom:A,maxZoom:A,padding:b})}}},[h,r,o,_,n,m,e.direction,u,s,l,a,t])}function ye(){const{getViewport:e,setViewport:o}=p.useReactFlow();return f.useCallback(r=>{const i=r.target;if(!(i instanceof Element)||!i.matches(".react-flow__node:focus-visible, .react-flow__edge:focus-visible"))return;const{scrollLeft:n,scrollTop:m}=r.currentTarget,s=r.currentTarget.getBoundingClientRect(),l=i.getBoundingClientRect(),a=l.left-s.left+n,t=l.top-s.top+m;if(a>=0&&t>=0&&a+l.width<=s.width&&t+l.height<=s.height)return;const{x:u,y:h,zoom:_}=e();o({x:u+s.width/2-(a+l.width/2),y:h+s.height/2-(t+l.height/2),zoom:_})},[e,o])}function Se({nodes:e,edges:o,groups:r=[],direction:i="LR",height:n,fillViewport:m=!1,onNodeClick:s,onEdgeClick:l,selectedNodeId:a,focusNodeId:t,minimap:u=t===void 0,ariaLabel:h,className:_}){const b=oe.useStrings(),E=f.useId(),j=`aegis-service-map${E.replace(/:/g,"-")}`,x=s!==void 0,w=l!==void 0,[O,M]=f.useState(()=>new Map),D=f.useMemo(()=>JSON.stringify(ce(e,o,r,i)),[e,o,r,i]),$=f.useMemo(()=>JSON.parse(D),[D]),y=f.useMemo(()=>ge($,O,E),[$,O,E]),P=i==="LR",I=f.useMemo(()=>[...y.groups,...e.map(g=>{const c=[y.groupLabels.get(g.id),x?`react-flow__node-desc-${j}`:void 0].filter(Boolean).join(" ");return{id:g.id,type:"service",position:y.positions.get(g.id)??{x:0,y:0},measured:O.get(g.id),ariaLabel:g.label,ariaRole:"group",domAttributes:{"aria-roledescription":b.serviceMapNodeRole,"aria-current":a===g.id?!0:void 0,"aria-describedby":c===""?void 0:c},data:{node:g,selected:a===g.id},sourcePosition:P?p.Position.Right:p.Position.Bottom,targetPosition:P?p.Position.Left:p.Position.Top,draggable:!1,connectable:!1,selectable:x,focusable:x}})],[y,e,O,a,P,x,j,b]),S=f.useMemo(()=>{const g=new Map(e.map(c=>[c.id,c.label]));return o.map(c=>({id:c.id,source:c.source,target:c.target,ariaLabel:b.serviceMapEdgeName(g.get(c.source)??c.source,g.get(c.target)??c.target),domAttributes:{"aria-roledescription":b.serviceMapEdgeRole},type:"service",data:{edge:c},label:c.label,selectable:w,focusable:w,className:`aegis-service-map__edge aegis-service-map__edge--${c.status??"ok"}`}))},[e,o,w,b]),{getNode:T}=p.useReactFlow(),Y=f.useCallback(g=>{const c=g.flatMap(v=>v.type==="dimensions"&&v.dimensions!==void 0&&T(v.id)?.type==="service"?[[v.id,v.dimensions]]:[]);M(v=>c.every(([N,L])=>v.get(N)?.width===L.width&&v.get(N)?.height===L.height)?v:new Map([...v,...c]))},[T]),z=te.useMediaQuery(ve),C=u&&!z;we($,y,e.every(g=>O.has(g.id)),t,C,z);const X=ye(),J=f.useCallback((g,c)=>{c.type==="service"&&s?.(c.data.node)},[s]),Q=f.useCallback((g,c)=>{c.data&&l?.(c.data.edge)},[l]),K=f.useCallback(g=>{if(g.key!=="Enter"&&g.key!==" "||g.repeat)return;const c=g.target;if(!(c instanceof Element))return;const v=c.getAttribute("data-id");if(c.classList.contains("react-flow__node")){const N=e.find(L=>L.id===v);N&&s&&(g.preventDefault(),s(N))}else if(c.classList.contains("react-flow__edge")){const N=o.find(L=>L.id===v);N&&l&&(g.preventDefault(),l(N))}},[e,o,s,l]),ee={...ne,height:n===void 0?void 0:`${String(n)}px`};return d.jsx("div",{className:["aegis-service-map",m?"aegis-service-map--fill-viewport":"",_].filter(Boolean).join(" "),style:ee,children:d.jsx("div",{className:"aegis-service-map__pane",children:d.jsxs(p.ReactFlow,{id:j,"aria-label":h,nodes:I,edges:S,nodeTypes:fe,edgeTypes:be,minZoom:k,nodesDraggable:!1,nodesConnectable:!1,autoPanOnNodeFocus:!1,panOnDrag:!0,zoomOnScroll:!0,proOptions:{hideAttribution:!0},ariaLabelConfig:b.serviceMapAriaLabels,onNodesChange:Y,onNodeClick:x?J:void 0,onEdgeClick:w?Q:void 0,onKeyDown:K,onFocus:X,children:[d.jsx(p.Background,{variant:p.BackgroundVariant.Dots,gap:16,size:1}),d.jsx(p.Controls,{showInteractive:!1,position:"top-left"}),C&&d.jsx(p.MiniMap,{pannable:!0,zoomable:!0,position:"bottom-right",style:{width:W},nodeClassName:xe})]})})})}function Me(e){return d.jsx(p.ReactFlowProvider,{children:d.jsx(Se,{...e})})}exports.ServiceMap=Me;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react/jsx-runtime"),h=require("react"),Y=require("@dagrejs/dagre"),g=require("@xyflow/react"),Z=require("../../hooks/useIsomorphicLayoutEffect.cjs"),ne=require("../../hooks/useMediaQuery.cjs");;/* empty css */const ae=require("./StatusDot.cjs"),re=require("./selectedRowDetail.cjs"),ce=require("../../locale/useStrings.cjs"),U=180,W=64,le=320,Q=28,de=64,ue={"--aegis-service-map-node-w":`${String(U)}px`,"--aegis-service-map-node-h":`${String(W)}px`,"--aegis-service-map-node-max-w":`${String(le)}px`,"--aegis-service-map-group-label-h":`${String(Q)}px`},ge={width:U,height:W};function pe(t,o,r,n){const a=t.map(s=>s.id),p=new Set(a);return{direction:n,ids:a,links:o.filter(s=>p.has(s.source)&&p.has(s.target)).map(s=>[s.source,s.target]),groups:r}}function me(t,o){const r=new Set(t),n=new Set,a=o.map(s=>{const l=[...new Set(s.nodeIds)].filter(i=>r.has(i)&&!n.has(i));return l.forEach(i=>n.add(i)),{group:s,ids:l}}),p=t.filter(s=>!n.has(s));return[...a,{ids:p}].filter(s=>s.ids.length>0)}function fe(t,o,r,n){const a=new Y.graphlib.Graph;a.setDefaultEdgeLabel(()=>({})),a.setGraph({rankdir:r,nodesep:40,ranksep:80,marginx:16,marginy:16});for(const i of t)a.setNode(i,{...n(i)});for(const[i,e]of o)a.hasNode(i)&&a.hasNode(e)&&a.setEdge(i,e);Y.layout(a);const p=new Map(t.map(i=>{const{x:e=0,y:m=0}=a.node(i),f=n(i);return[i,{x:e-f.width/2,y:m-f.height/2}]})),{width:s=0,height:l=0}=a.graph();return{positions:p,width:s,height:l}}function he(t,o,r){const n=e=>`${r}-group-${String(t.groups.indexOf(e))}`,a=t.direction==="LR",p=me(t.ids,t.groups).map(e=>{const m=fe(e.ids,t.links,t.direction,v=>o.get(v)??ge),f=e.group===void 0?0:Q;return{...e,...m,labelHeight:f,boxHeight:m.height+f}}),s=Math.max(0,...p.map(e=>a?e.boxHeight:e.width));let l=0;const i=p.map(e=>{const m=a?{x:l,y:(s-e.boxHeight)/2}:{x:(s-e.width)/2,y:l};return l+=(a?e.width:e.boxHeight)+de,{...e,origin:m}});return{groups:i.flatMap(e=>e.group===void 0?[]:[{id:`group:${e.group.id}`,type:"serviceGroup",position:e.origin,width:e.width,height:e.boxHeight,data:{label:e.group.label,labelId:n(e.group)},domAttributes:{"aria-roledescription":void 0,"aria-describedby":void 0},zIndex:-1,style:{pointerEvents:"none"},draggable:!1,connectable:!1,selectable:!1,focusable:!1}]),positions:new Map(i.flatMap(e=>[...e.positions].map(([m,f])=>[m,{x:e.origin.x+f.x,y:e.origin.y+e.labelHeight+f.y}]))),groupLabels:new Map(i.flatMap(e=>{const{group:m}=e;return m===void 0?[]:e.ids.map(f=>[f,n(m)])}))}}function ve({data:t}){return d.jsx("div",{className:"aegis-service-map__group",children:d.jsx("span",{id:t.labelId,className:"aegis-service-map__group-label",children:t.label})})}const be={ok:"ink",active:"ink",warn:"caution",error:"warning",muted:"muted"};function _e({data:t}){const{node:o,selected:r}=t,n=o.status??"ok",a=be[n];return d.jsxs("div",{className:["aegis-service-map__node",`aegis-service-map__node--${n}`,r?"aegis-service-map__node--selected":""].filter(Boolean).join(" "),children:[d.jsx(g.Handle,{type:"target",position:g.Position.Left,className:"aegis-service-map__handle"}),d.jsxs("div",{className:"aegis-service-map__node-body",children:[d.jsxs("div",{className:"aegis-service-map__node-label",children:[d.jsx(ae.StatusDot,{pulse:n==="active",tone:r&&a==="ink"?"inverted":a}),d.jsx("span",{className:"aegis-service-map__node-label-text",children:o.label})]}),o.sublabel!==void 0&&d.jsx("div",{className:"aegis-service-map__node-sublabel",children:o.sublabel})]}),o.badge!==void 0&&o.badge!==""&&d.jsx("span",{className:`aegis-service-map__node-badge aegis-service-map__node-badge--${n}`,children:o.badge}),d.jsx(g.Handle,{type:"source",position:g.Position.Right,className:"aegis-service-map__handle"})]})}function xe(t){const{sourceX:o,sourceY:r,targetX:n,targetY:a,label:p,markerEnd:s,style:l}=t,i=h.useId(),e=(o+n)/2,m=`M${o},${r} C${e},${r} ${e},${a} ${n},${a}`;return d.jsxs(d.Fragment,{children:[d.jsx("path",{d:m,className:"aegis-service-map__edge-focus",fill:"none"}),d.jsx("path",{id:i,d:m,className:"aegis-service-map__edge-path",markerEnd:s,style:l,fill:"none"}),p!==void 0&&p!==""&&d.jsx("text",{className:"aegis-service-map__edge-label",children:d.jsx("textPath",{href:`#${i}`,startOffset:"50%",textAnchor:"middle",children:p})})]})}const we={service:_e,serviceGroup:ve},ye={service:xe},Se="(max-width: 768px)",j=24,V=.1,B=1,X=11/13,q=15,J=28,K=200,C=t=>`${t}px`;function Me(t,o){return[...new Set([t,...o.filter(([r])=>r===t).map(([,r])=>r),...o.filter(([,r])=>r===t).map(([r])=>r)])]}function Ne(t){return t.type==="serviceGroup"?"aegis-service-map__minimap-group":""}function Ee(t,o,r,n,a,p){const{fitView:s,getNodes:l,getNodesBounds:i,setViewport:e}=g.useReactFlow(),m=g.useStoreApi(),f=g.useStore(x=>x.width>0&&x.height>0),v=h.useMemo(()=>n!==void 0&&t.ids.includes(n)?{id:n,near:Me(n,t.links)}:void 0,[n,t]),[M,P]=h.useState();return h.useEffect(()=>{if(f&&r){const x=()=>{P(v?.id??null)},w={top:C(j),bottom:C(j),left:C(q+J+j),right:C(a?q+K+j:j)},{width:N,height:S}=m.getState();if(v===void 0){const O=l(),E=i(O),L=g.getViewportForBounds(E,N,S,V,1,w);if(p&&L.zoom<X){const _=X,T=t.direction==="LR",H=y=>T?y.position.x:y.position.y,A=O.filter(y=>y.type==="service").reduce((y,I)=>H(I)<H(y)?I:y),{width:F=U,height:z=W}=A.measured??{};e(T?{x:q+J+j-E.x*_,y:S/2-(A.position.y+z/2)*_,zoom:_}:{x:N/2-(A.position.x+F/2)*_,y:j-E.y*_,zoom:_}).then(x)}else s({maxZoom:1,padding:w}).then(x)}else{const O=g.getViewportForBounds(i(v.near),N,S,V,B,w).zoom>=B;s({nodes:(O?v.near:[v.id]).map(E=>({id:E})),minZoom:B,maxZoom:B,padding:w}).then(x)}}},[f,r,o,v,a,p,t.direction,m,s,l,i,e]),M===(v?.id??null)}function Re({nodeId:t,selection:o}){const r=g.useStore(e=>e.transform),n=g.useStore(e=>e.domNode),a=g.useInternalNode(t);Z.useIsomorphicLayoutEffect(()=>()=>{o.placeRow(null)},[o]),Z.useIsomorphicLayoutEffect(()=>{const e=n?.querySelector(`.react-flow__node[data-id="${CSS.escape(t)}"]`);e instanceof HTMLElement&&o.placeRow(e)},[o,n,t,r]);const p=a?.measured.height;if(o.inline===null||a===void 0||p===void 0)return null;const[,s,l]=r,i=(a.internals.positionAbsolute.y+p)*l+s;return d.jsx("div",{className:"aegis-service-map__detail",style:{marginTop:Math.max(i,0)},children:o.inline})}function je(){const{getViewport:t,setViewport:o}=g.useReactFlow();return h.useCallback(r=>{const n=r.target;if(!(n instanceof Element)||!n.matches(".react-flow__node:focus-visible, .react-flow__edge:focus-visible"))return;const{scrollLeft:a,scrollTop:p}=r.currentTarget,s=r.currentTarget.getBoundingClientRect(),l=n.getBoundingClientRect(),i=l.left-s.left+a,e=l.top-s.top+p;if(i>=0&&e>=0&&i+l.width<=s.width&&e+l.height<=s.height)return;const{x:m,y:f,zoom:v}=t();o({x:m+s.width/2-(i+l.width/2),y:f+s.height/2-(e+l.height/2),zoom:v})},[t,o])}function Oe({nodes:t,edges:o,groups:r=[],direction:n="LR",height:a,fillViewport:p=!1,onNodeClick:s,onEdgeClick:l,selectedNodeId:i,focusNodeId:e,minimap:m=e===void 0,ariaLabel:f,className:v}){const M=ce.useStrings(),P=h.useId(),x=`aegis-service-map${P.replace(/:/g,"-")}`,w=s!==void 0,N=l!==void 0,[S,O]=h.useState(()=>new Map),E=h.useMemo(()=>JSON.stringify(pe(t,o,r,n)),[t,o,r,n]),L=h.useMemo(()=>JSON.parse(E),[E]),_=h.useMemo(()=>he(L,S,P),[L,S,P]),T=n==="LR",H=h.useMemo(()=>[..._.groups,...t.map(u=>{const c=[_.groupLabels.get(u.id),w?`react-flow__node-desc-${x}`:void 0].filter(Boolean).join(" ");return{id:u.id,type:"service",position:_.positions.get(u.id)??{x:0,y:0},measured:S.get(u.id),ariaLabel:u.label,ariaRole:"group",domAttributes:{"aria-roledescription":M.serviceMapNodeRole,"aria-current":i===u.id?!0:void 0,"aria-describedby":c===""?void 0:c},data:{node:u,selected:i===u.id},sourcePosition:T?g.Position.Right:g.Position.Bottom,targetPosition:T?g.Position.Left:g.Position.Top,draggable:!1,connectable:!1,selectable:w,focusable:w}})],[_,t,S,i,T,w,x,M]),A=h.useMemo(()=>{const u=new Map(t.map(c=>[c.id,c.label]));return o.map(c=>({id:c.id,source:c.source,target:c.target,ariaLabel:M.serviceMapEdgeName(u.get(c.source)??c.source,u.get(c.target)??c.target),ariaRole:"group",domAttributes:{"aria-roledescription":M.serviceMapEdgeRole},type:"service",data:{edge:c},label:c.label,selectable:N,focusable:N,className:`aegis-service-map__edge aegis-service-map__edge--${c.status??"ok"}`}))},[t,o,N,M]),{getNode:F}=g.useReactFlow(),z=h.useCallback(u=>{const c=u.flatMap(b=>b.type==="dimensions"&&b.dimensions!==void 0&&F(b.id)?.type==="service"?[[b.id,b.dimensions]]:[]);O(b=>c.every(([R,D])=>b.get(R)?.width===D.width&&b.get(R)?.height===D.height)?b:new Map([...b,...c]))},[F]),y=ne.useMediaQuery(Se),I=m&&!y,$=h.useContext(re.SelectedRowDetailContext),G=Ee(L,_,t.every(u=>S.has(u.id)),e,I,y),k=i!==void 0&&L.ids.includes(i)?i:void 0;Z.useIsomorphicLayoutEffect(()=>{if(!($===null||k===void 0||G))return $.awaitRow(),()=>{$.placeRow(null)}},[$,k,G]);const ee=je(),te=h.useCallback((u,c)=>{c.type==="service"&&s?.(c.data.node)},[s]),se=h.useCallback((u,c)=>{c.data&&l?.(c.data.edge)},[l]),oe=h.useCallback(u=>{if(u.key!=="Enter"&&u.key!==" "||u.repeat)return;const c=u.target;if(!(c instanceof Element))return;const b=c.getAttribute("data-id");if(c.classList.contains("react-flow__node")){const R=t.find(D=>D.id===b);R&&s&&(u.preventDefault(),s(R))}else if(c.classList.contains("react-flow__edge")){const R=o.find(D=>D.id===b);R&&l&&(u.preventDefault(),l(R))}},[t,o,s,l]),ie={...ue,height:a===void 0?void 0:`${String(a)}px`};return d.jsxs("div",{className:["aegis-service-map",p?"aegis-service-map--fill-viewport":"",v].filter(Boolean).join(" "),style:ie,children:[d.jsx("div",{className:"aegis-service-map__pane",children:d.jsxs(g.ReactFlow,{id:x,"aria-label":f,nodes:H,edges:A,nodeTypes:we,edgeTypes:ye,minZoom:V,nodesDraggable:!1,nodesConnectable:!1,autoPanOnNodeFocus:!1,panOnDrag:!0,zoomOnScroll:!0,proOptions:{hideAttribution:!0},ariaLabelConfig:M.serviceMapAriaLabels,onNodesChange:z,onNodeClick:w?te:void 0,onEdgeClick:N?se:void 0,onKeyDown:oe,onFocus:ee,children:[d.jsx(g.Background,{variant:g.BackgroundVariant.Dots,gap:16,size:1}),d.jsx(g.Controls,{showInteractive:!1,position:"top-left"}),I&&d.jsx(g.MiniMap,{pannable:!0,zoomable:!0,position:"bottom-right",style:{width:K},nodeClassName:Ne})]})}),$!==null&&G&&k!==void 0&&d.jsx(Re,{nodeId:k,selection:$})]})}function Le(t){return d.jsx(g.ReactFlowProvider,{children:d.jsx(Oe,{...t})})}exports.ServiceMap=Le;
|
|
2
2
|
//# sourceMappingURL=ServiceMap.cjs.map
|