@lincyaw/aegis-ui 0.12.1 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/dist/components/ui/CommitGraph.cjs +1 -1
  2. package/dist/components/ui/CommitGraph.cjs.map +1 -1
  3. package/dist/components/ui/CommitGraph.d.ts +23 -5
  4. package/dist/components/ui/CommitGraph.js +236 -200
  5. package/dist/components/ui/CommitGraph.js.map +1 -1
  6. package/dist/components/ui/DataTable.cjs +1 -1
  7. package/dist/components/ui/DataTable.cjs.map +1 -1
  8. package/dist/components/ui/DataTable.js +205 -207
  9. package/dist/components/ui/DataTable.js.map +1 -1
  10. package/dist/components/ui/DetailBeside.cjs +2 -0
  11. package/dist/components/ui/DetailBeside.cjs.map +1 -0
  12. package/dist/components/ui/DetailBeside.d.ts +59 -0
  13. package/dist/components/ui/DetailBeside.js +117 -0
  14. package/dist/components/ui/DetailBeside.js.map +1 -0
  15. package/dist/components/ui/FileTree.cjs +1 -1
  16. package/dist/components/ui/FileTree.cjs.map +1 -1
  17. package/dist/components/ui/FileTree.js +118 -111
  18. package/dist/components/ui/FileTree.js.map +1 -1
  19. package/dist/components/ui/ServiceMap.cjs +1 -1
  20. package/dist/components/ui/ServiceMap.cjs.map +1 -1
  21. package/dist/components/ui/ServiceMap.js +320 -271
  22. package/dist/components/ui/ServiceMap.js.map +1 -1
  23. package/dist/components/ui/TraceTree.cjs +1 -1
  24. package/dist/components/ui/TraceTree.cjs.map +1 -1
  25. package/dist/components/ui/TraceTree.d.ts +2 -1
  26. package/dist/components/ui/TraceTree.js +182 -178
  27. package/dist/components/ui/TraceTree.js.map +1 -1
  28. package/dist/components/ui/index.d.ts +3 -1
  29. package/dist/components/ui/selectedRowDetail.cjs +2 -0
  30. package/dist/components/ui/selectedRowDetail.cjs.map +1 -0
  31. package/dist/components/ui/selectedRowDetail.d.ts +25 -0
  32. package/dist/components/ui/selectedRowDetail.js +8 -0
  33. package/dist/components/ui/selectedRowDetail.js.map +1 -0
  34. package/dist/index.cjs +1 -1
  35. package/dist/index.js +259 -257
  36. package/dist/index.js.map +1 -1
  37. package/dist/style.css +1 -1
  38. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"FileTree.cjs","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":"qMAwFA,SAASA,EAAaC,EAAgC,CACpD,MAAMC,EAAiB,CAAA,EACjBC,MAAkB,IACxB,UAAWC,KAAQH,EAAO,CACxB,MAAMI,EAAWD,EAAK,KAAK,MAAM,GAAG,EACpC,IAAIE,EAAWJ,EACXK,EACJ,SAAW,CAACC,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UAAU,wBAAwB,cAAW,GAAC,EAE9DH,EAAAA,IAAC,OAAA,CACC,GAAIP,EACJ,UAAU,wBACV,MAAO9C,EAAM,KAEZ,WAAM,OAAS,OAAUA,EAAM,OAASA,EAAM,KAAQA,EAAM,IAAA,CAAA,EAE9D6C,IAAS,QACRQ,MAAC,OAAA,CAAK,GAAIN,EAAQ,UAAU,wBACzB,SAAAF,CAAA,CACH,CAAA,EAEJ,EAEF,OAAOG,IAAS,OACdK,EAAAA,IAAC,KAAA,CAEC,KAAK,WACL,gBAAeV,EAAc,OAAYC,EACxC,GAAGK,EAEH,SAAAC,CAAA,EALIlD,EAAM,IAAA,EAQbqD,EAAAA,IAAC,KAAA,CAAoB,KAAK,OACxB,SAAAA,EAAAA,IAAC,IAAA,CACC,KAAK,WACL,gBAAeT,EACf,KAAAI,EACA,OAAQvC,EACR,IAAKA,IAAe,SAAW,sBAAwB,OACtD,GAAGwC,EAEH,SAAAC,CAAA,CAAA,CACH,EAVOlD,EAAM,IAWf,CAEJ,CAAC,CAAA,CACH,CAEJ"}
1
+ {"version":3,"file":"FileTree.cjs","sources":["../../../src/components/ui/FileTree.tsx"],"sourcesContent":["import {\n type CSSProperties,\n Fragment,\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":"gPA2FA,SAASA,EAAaC,EAAgC,CACpD,MAAMC,EAAiB,CAAA,EACjBC,MAAkB,IACxB,UAAWC,KAAQH,EAAO,CACxB,MAAMI,EAAWD,EAAK,KAAK,MAAM,GAAG,EACpC,IAAIE,EAAWJ,EACXK,EACJ,SAAW,CAACC,EAAOC,CAAO,IAAKJ,EAAS,MAAM,EAAG,EAAE,EAAE,UAAW,CAC9D,MAAMK,EAAO,GAAGH,GAAQ,MAAQ,EAAE,GAAGE,CAAO,IAC5C,IAAIE,EAAYR,EAAY,IAAIO,CAAI,EAChCC,IAAc,SAChBA,EAAY,CACV,KAAM,YACN,KAAAD,EACA,KAAM,GAAGD,CAAO,IAChB,MAAAD,EACA,WAAYD,GAAQ,KACpB,SAAU,CAAA,EACV,MAAO,CAAA,CAAC,EAEVJ,EAAY,IAAIO,EAAMC,CAAS,EAC/BL,EAAS,KAAKK,CAAS,GAEzBA,EAAU,MAAM,KAAKP,CAAI,EACzBG,EAASI,EACTL,EAAW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C,IAAKI,EACL,KAAK,WACL,gBAAed,EAAc,OAAYC,EACxC,GAAGK,EAEH,SAAAC,CAAA,CAAA,EAGHG,EAAAA,IAAC,KAAA,CAAG,KAAK,OACP,SAAAA,EAAAA,IAAC,IAAA,CACC,IAAKI,EACL,KAAK,WACL,gBAAeb,EACf,KAAAI,EACA,OAAQ1C,EACR,IACEA,IAAe,SAAW,sBAAwB,OAEnD,GAAG2C,EAEH,SAAAC,CAAA,CAAA,EAEL,EAEDN,GAAY9B,GAAW,OACtBuC,EAAAA,IAAC,MAAG,KAAK,OAAQ,SAAAvC,EAAU,MAAA,CAAO,EAChC,IAAA,CAAA,EA7BSjB,EAAM,IA8BrB,CAEJ,CAAC,CAAA,CACH,CAEJ"}
@@ -1,190 +1,197 @@
1
- import { jsx as d, jsxs as z, Fragment as H } from "react/jsx-runtime";
2
- import { useId as W, useMemo as D, useState as E, useRef as X } from "react";
3
- import { RightOutlined as Y, FolderOutlined as Z, FileOutlined as y } from "@ant-design/icons";
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
- function ee(n) {
6
- const r = [], t = /* @__PURE__ */ new Map();
7
- for (const i of n) {
8
- const s = i.path.split("/");
9
- let h = r, f;
10
- for (const [S, v] of s.slice(0, -1).entries()) {
11
- const m = `${f?.path ?? ""}${v}/`;
12
- let l = t.get(m);
13
- l === void 0 && (l = {
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: m,
16
- name: `${v}/`,
17
- depth: S,
16
+ path: u,
17
+ name: `${_}/`,
18
+ depth: R,
18
19
  parentPath: f?.path,
19
20
  children: [],
20
21
  files: []
21
- }, t.set(m, l), h.push(l)), l.files.push(i), f = l, h = l.children;
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: s.length - 1,
29
+ depth: o.length - 1,
29
30
  parentPath: f?.path,
30
31
  note: i.note
31
32
  });
32
33
  }
33
- return r;
34
+ return n;
34
35
  }
35
- function q(n, r, t = []) {
36
+ function B(l, n, t = []) {
36
37
  const i = [
37
- ...n.filter((s) => s.kind === "directory"),
38
- ...n.filter((s) => s.kind === "file")
38
+ ...l.filter((o) => o.kind === "directory"),
39
+ ...l.filter((o) => o.kind === "file")
39
40
  ];
40
- return i.forEach((s, h) => {
41
- t.push({ entry: s, position: h + 1, setSize: i.length }), s.kind === "directory" && r.has(s.path) && q(s.children, r, t);
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 K(n) {
45
- const r = n.split("/").slice(0, -1);
46
- return r.map(
47
- (t, i) => `${r.slice(0, i + 1).join("/")}/`
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 oe({
51
- files: n,
52
- ariaLabel: r,
51
+ function he({
52
+ files: l,
53
+ ariaLabel: n,
53
54
  selectedPath: t,
54
55
  onSelect: i,
55
- fileHref: s,
56
+ fileHref: o,
56
57
  fileTarget: h,
57
58
  expandedPaths: f,
58
- defaultExpandedPaths: S = [],
59
- onExpandedPathsChange: v,
60
- directoryNote: m,
61
- className: l
59
+ defaultExpandedPaths: R = [],
60
+ onExpandedPathsChange: _,
61
+ directoryNote: u,
62
+ className: c
62
63
  }) {
63
- const F = W(), I = D(() => ee(n), [n]), [N, x] = E(() => [
64
- ...S,
65
- ...K(t ?? "")
66
- ]), [B, C] = E(t);
67
- t !== B && (C(t), x([
68
- .../* @__PURE__ */ new Set([...N, ...K(t ?? "")])
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 ?? N, g = D(() => new Set(w), [w]), [L, U] = E(), A = X(null), k = D(
71
- () => q(I, g),
72
- [I, g]
73
- ), G = [L, t].find(
74
- (e) => k.some((o) => o.entry.path === e)
75
- ) ?? k[0]?.entry.path, $ = (e, o) => {
76
- const a = o ? [...w, e] : w.filter((p) => p !== e);
77
- f === void 0 && x(a), v?.(a);
78
- }, u = (e) => {
79
- const o = A.current?.querySelectorAll('[role="treeitem"]').item(e);
80
- o instanceof HTMLElement && o.focus();
81
- }, P = (e) => {
82
- e.kind === "directory" ? $(e.path, !g.has(e.path)) : i?.(e.path);
83
- }, J = (e, o, a, p) => {
84
- const c = a.kind === "directory" && g.has(a.path);
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
- u(o + 1);
90
+ g(s + 1);
88
91
  break;
89
92
  case "ArrowUp":
90
- u(o - 1);
93
+ g(s - 1);
91
94
  break;
92
95
  case "Home":
93
- u(0);
96
+ g(0);
94
97
  break;
95
98
  case "End":
96
- u(k.length - 1);
99
+ g(b.length - 1);
97
100
  break;
98
101
  case "ArrowRight":
99
- c ? u(o + 1) : a.kind === "directory" && $(a.path, !0);
102
+ d ? g(s + 1) : a.kind === "directory" && $(a.path, !0);
100
103
  break;
101
104
  case "ArrowLeft":
102
- if (c)
105
+ if (d)
103
106
  $(a.path, !1);
104
107
  else if (a.parentPath !== void 0) {
105
- const { parentPath: b } = a;
106
- u(k.findIndex((_) => _.entry.path === b));
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
- P(a);
115
+ F(a);
113
116
  break;
114
117
  case " ":
115
- p ? e.currentTarget.click() : P(a);
118
+ p ? e.currentTarget.click() : F(a);
116
119
  break;
117
120
  default:
118
121
  return;
119
122
  }
120
123
  e.preventDefault();
121
- }, Q = ["aegis-file-tree", l ?? ""].filter(Boolean).join(" ");
122
- return /* @__PURE__ */ d("ul", { ref: A, className: Q, role: "tree", "aria-label": r, children: k.map(({ entry: e, position: o, setSize: a }, p) => {
123
- const c = e.kind === "directory", b = !c && e.path === t, _ = c ? m ? m(e.path, e.files) : String(e.files.length) : e.note, j = `${F}-name-${String(p)}`, O = `${F}-note-${String(p)}`, R = c ? void 0 : s?.(e.path), M = {
124
- className: b ? "aegis-file-tree__item aegis-file-tree__item--selected" : "aegis-file-tree__item",
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": j,
127
- "aria-describedby": _ === void 0 ? void 0 : O,
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": o,
131
- "aria-expanded": c ? g.has(e.path) : void 0,
132
- tabIndex: e.path === G ? 0 : -1,
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
- P(e);
137
+ F(e);
135
138
  },
136
- onKeyDown: (V) => {
137
- J(V, p, e, R !== void 0);
139
+ onKeyDown: (X) => {
140
+ V(X, p, e, x !== void 0);
138
141
  },
139
142
  onFocus: () => {
140
- U(e.path);
143
+ J(e.path);
141
144
  }
142
- }, T = /* @__PURE__ */ z(H, { children: [
143
- c ? /* @__PURE__ */ z(H, { children: [
144
- /* @__PURE__ */ d(
145
- Y,
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__ */ d(Z, { className: "aegis-file-tree__icon", "aria-hidden": !0 })
152
- ] }) : /* @__PURE__ */ d(y, { className: "aegis-file-tree__icon", "aria-hidden": !0 }),
153
- /* @__PURE__ */ d(
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: j,
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
- _ !== void 0 && /* @__PURE__ */ d("span", { id: O, className: "aegis-file-tree__note", children: _ })
163
- ] });
164
- return R === void 0 ? /* @__PURE__ */ d(
165
- "li",
166
- {
167
- role: "treeitem",
168
- "aria-selected": c ? void 0 : b,
169
- ...M,
170
- children: T
171
- },
172
- e.path
173
- ) : /* @__PURE__ */ d("li", { role: "none", children: /* @__PURE__ */ d(
174
- "a",
175
- {
176
- role: "treeitem",
177
- "aria-selected": b,
178
- href: R,
179
- target: h,
180
- rel: h === "_blank" ? "noopener noreferrer" : void 0,
181
- ...M,
182
- children: T
183
- }
184
- ) }, e.path);
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
- oe as FileTree
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,G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AAW,wBAAwB;AAAA,QACtD,GAAGwC;AAAA,QAEH,UAAAC;AAAA,MAAA;AAAA,IAAA,EACH,GAVOlD,EAAM,IAWf;AAAA,EAEJ,CAAC,EAAA,CACH;AAEJ;"}
1
+ {"version":3,"file":"FileTree.js","sources":["../../../src/components/ui/FileTree.tsx"],"sourcesContent":["import {\n type CSSProperties,\n Fragment,\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,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,CAAA;AAAA,MAAC,GAEVJ,EAAY,IAAIO,GAAMC,CAAS,GAC/BL,EAAS,KAAKK,CAAS,IAEzBA,EAAU,MAAM,KAAKP,CAAI,GACzBG,IAASI,GACTL,IAAWK,EAAU;AAAA,IACvB;AACA,IAAAL,EAAS,KAAK;AAAA,MACZ,MAAM;AAAA,MACN,MAAMF,EAAK;AAAA,MACX,MAAMA,EAAK,KAAK,MAAMA,EAAK,KAAK,YAAY,GAAG,IAAI,CAAC;AAAA,MACpD,OAAOA,EAAK;AAAA,MACZ,OAAOC,EAAS,SAAS;AAAA,MACzB,YAAYE,GAAQ;AAAA,MACpB,MAAMH,EAAK;AAAA,IAAA,CACZ;AAAA,EACH;AACA,SAAOF;AACT;AAGA,SAASU,EACPC,GACAC,GACAC,IAAc,CAAA,GACP;AACP,QAAMC,IAAU;AAAA,IACd,GAAGH,EAAQ,OAAO,CAACI,MAAUA,EAAM,SAAS,WAAW;AAAA,IACv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EAAK,IAAIN,GAAQ,WAAU,yBACzB,UAAAF,EAAA,CACH;AAAA,IAAA,GAEJ,GAEIY,IAASb,IAAW9B,GAAW,WAAW;AAChD,WACE,gBAAAqC,EAACC,IAAA,EACE,UAAA;AAAA,MAAAJ,MAAS,SACR,gBAAAK;AAAA,QAAC;AAAA,QAAA;AAAA,UACC,KAAKI;AAAA,UACL,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),ariaRole:"group",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 u=require("react/jsx-runtime"),f=require("react"),X=require("@dagrejs/dagre"),m=require("@xyflow/react"),V=require("../../hooks/useIsomorphicLayoutEffect.cjs"),re=require("../../hooks/useMediaQuery.cjs");;/* empty css */const ce=require("./StatusDot.cjs"),le=require("./selectedRowDetail.cjs"),de=require("../../locale/useStrings.cjs"),W=180,Y=64,ue=320,K=28,ge=64,pe={"--aegis-service-map-node-w":`${String(W)}px`,"--aegis-service-map-node-h":`${String(Y)}px`,"--aegis-service-map-node-max-w":`${String(ue)}px`,"--aegis-service-map-group-label-h":`${String(K)}px`},me={width:W,height:Y};function fe(e,n,o,a){const r=e.map(s=>s.id),g=new Set(r);return{direction:a,ids:r,links:n.filter(s=>g.has(s.source)&&g.has(s.target)).map(s=>[s.source,s.target]),groups:o}}function he(e,n){const o=new Set(e),a=new Set,r=n.map(s=>{const l=[...new Set(s.nodeIds)].filter(i=>o.has(i)&&!a.has(i));return l.forEach(i=>a.add(i)),{group:s,ids:l}}),g=e.filter(s=>!a.has(s));return[...r,{ids:g}].filter(s=>s.ids.length>0)}function ve(e,n,o,a){const r=new X.graphlib.Graph;r.setDefaultEdgeLabel(()=>({})),r.setGraph({rankdir:o,nodesep:40,ranksep:80,marginx:16,marginy:16});for(const i of e)r.setNode(i,{...a(i)});for(const[i,t]of n)r.hasNode(i)&&r.hasNode(t)&&r.setEdge(i,t);X.layout(r);const g=new Map(e.map(i=>{const{x:t=0,y:d=0}=r.node(i),h=a(i);return[i,{x:t-h.width/2,y:d-h.height/2}]})),{width:s=0,height:l=0}=r.graph();return{positions:g,width:s,height:l}}function be(e,n,o){const a=t=>`${o}-group-${String(e.groups.indexOf(t))}`,r=e.direction==="LR",g=he(e.ids,e.groups).map(t=>{const d=ve(t.ids,e.links,e.direction,v=>n.get(v)??me),h=t.group===void 0?0:K;return{...t,...d,labelHeight:h,boxHeight:d.height+h}}),s=Math.max(0,...g.map(t=>r?t.boxHeight:t.width));let l=0;const i=g.map(t=>{const d=r?{x:l,y:(s-t.boxHeight)/2}:{x:(s-t.width)/2,y:l};return l+=(r?t.width:t.boxHeight)+ge,{...t,origin:d}});return{groups:i.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:a(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(i.flatMap(t=>[...t.positions].map(([d,h])=>[d,{x:t.origin.x+h.x,y:t.origin.y+t.labelHeight+h.y}]))),groupLabels:new Map(i.flatMap(t=>{const{group:d}=t;return d===void 0?[]:t.ids.map(h=>[h,a(d)])}))}}function _e({data:e}){return u.jsx("div",{className:"aegis-service-map__group",children:u.jsx("span",{id:e.labelId,className:"aegis-service-map__group-label",children:e.label})})}const xe={ok:"ink",active:"ink",warn:"caution",error:"warning",muted:"muted"};function we({data:e}){const{node:n,selected:o}=e,a=n.status??"ok",r=xe[a];return u.jsxs("div",{className:["aegis-service-map__node",`aegis-service-map__node--${a}`,o?"aegis-service-map__node--selected":""].filter(Boolean).join(" "),children:[u.jsx(m.Handle,{type:"target",position:m.Position.Left,className:"aegis-service-map__handle"}),u.jsxs("div",{className:"aegis-service-map__node-body",children:[u.jsxs("div",{className:"aegis-service-map__node-label",children:[u.jsx(ce.StatusDot,{pulse:a==="active",tone:o&&r==="ink"?"inverted":r}),u.jsx("span",{className:"aegis-service-map__node-label-text",children:n.label})]}),n.sublabel!==void 0&&u.jsx("div",{className:"aegis-service-map__node-sublabel",children:n.sublabel})]}),n.badge!==void 0&&n.badge!==""&&u.jsx("span",{className:`aegis-service-map__node-badge aegis-service-map__node-badge--${a}`,children:n.badge}),u.jsx(m.Handle,{type:"source",position:m.Position.Right,className:"aegis-service-map__handle"})]})}function ye(e){const{sourceX:n,sourceY:o,targetX:a,targetY:r,label:g,markerEnd:s,style:l}=e,i=f.useId(),t=(n+a)/2,d=`M${n},${o} C${t},${o} ${t},${r} ${a},${r}`;return u.jsxs(u.Fragment,{children:[u.jsx("path",{d,className:"aegis-service-map__edge-focus",fill:"none"}),u.jsx("path",{id:i,d,className:"aegis-service-map__edge-path",markerEnd:s,style:l,fill:"none"}),g!==void 0&&g!==""&&u.jsx("text",{className:"aegis-service-map__edge-label",children:u.jsx("textPath",{href:`#${i}`,startOffset:"50%",textAnchor:"middle",children:g})})]})}const Se={service:we,serviceGroup:_e},Me={service:ye},Ne="(max-width: 768px)",j=24,U=.1,C=1,J=11/13,Z=15,Q=28,ee=200,z=e=>`${e}px`;function Ee(e,n){return[...new Set([e,...n.filter(([o])=>o===e).map(([,o])=>o),...n.filter(([,o])=>o===e).map(([o])=>o)])]}function Re(e){return e.type==="serviceGroup"?"aegis-service-map__minimap-group":""}function je(e,n,o,a,r,g){const{fitView:s,getNodes:l,getNodesBounds:i,setViewport:t}=m.useReactFlow(),d=m.useStoreApi(),h=m.useStore(x=>x.width>0&&x.height>0),v=f.useMemo(()=>a!==void 0&&e.ids.includes(a)?{id:a,near:Ee(a,e.links)}:void 0,[a,e]),[M,I]=f.useState();return f.useEffect(()=>{if(h&&o){const x=()=>{I(v?.id??null)},w={top:z(j),bottom:z(j),left:z(Z+Q+j),right:z(r?Z+ee+j:j)},{width:N,height:S}=d.getState();if(v===void 0){const O=l(),E=i(O),L=m.getViewportForBounds(E,N,S,U,1,w);if(g&&L.zoom<J){const _=J,T=e.direction==="LR",H=y=>T?y.position.x:y.position.y,P=O.filter(y=>y.type==="service").reduce((y,A)=>H(A)<H(y)?A:y),{width:F=W,height:G=Y}=P.measured??{};t(T?{x:Z+Q+j-E.x*_,y:S/2-(P.position.y+G/2)*_,zoom:_}:{x:N/2-(P.position.x+F/2)*_,y:j-E.y*_,zoom:_}).then(x)}else s({maxZoom:1,padding:w}).then(x)}else{const O=m.getViewportForBounds(i(v.near),N,S,U,C,w).zoom>=C;s({nodes:(O?v.near:[v.id]).map(E=>({id:E})),minZoom:C,maxZoom:C,padding:w}).then(x)}}},[h,o,n,v,r,g,e.direction,d,s,l,i,t]),M===(v?.id??null)}function Oe({nodeId:e,fitted:n,selection:o}){const a=m.useStore(d=>d.transform),r=m.useStore(d=>d.domNode),g=m.useInternalNode(e);V.useIsomorphicLayoutEffect(()=>()=>{o.placeRow(null)},[o]),V.useIsomorphicLayoutEffect(()=>{const d=r?.querySelector(`.react-flow__node[data-id="${CSS.escape(e)}"]`);n&&d instanceof HTMLElement&&o.placeRow(d)},[o,r,e,a,n]);const s=g?.measured.height;if(o.inline===null||g===void 0||s===void 0)return null;const[,l,i]=a,t=(g.internals.positionAbsolute.y+s)*i+l;return u.jsx("div",{className:"aegis-service-map__detail",style:{marginTop:Math.max(t,0)},children:o.inline})}function Le(){const{getViewport:e,setViewport:n}=m.useReactFlow();return f.useCallback(o=>{const a=o.target;if(!(a instanceof Element)||!a.matches(".react-flow__node:focus-visible, .react-flow__edge:focus-visible"))return;const{scrollLeft:r,scrollTop:g}=o.currentTarget,s=o.currentTarget.getBoundingClientRect(),l=a.getBoundingClientRect(),i=l.left-s.left+r,t=l.top-s.top+g;if(i>=0&&t>=0&&i+l.width<=s.width&&t+l.height<=s.height)return;const{x:d,y:h,zoom:v}=e();n({x:d+s.width/2-(i+l.width/2),y:h+s.height/2-(t+l.height/2),zoom:v})},[e,n])}function Te({nodes:e,edges:n,groups:o=[],direction:a="LR",height:r,fillViewport:g=!1,onNodeClick:s,onEdgeClick:l,selectedNodeId:i,focusNodeId:t,minimap:d=t===void 0,ariaLabel:h,className:v}){const M=de.useStrings(),I=f.useId(),x=`aegis-service-map${I.replace(/:/g,"-")}`,w=s!==void 0,N=l!==void 0,[S,O]=f.useState(()=>new Map),E=f.useMemo(()=>JSON.stringify(fe(e,n,o,a)),[e,n,o,a]),L=f.useMemo(()=>JSON.parse(E),[E]),_=f.useMemo(()=>be(L,S,I),[L,S,I]),T=a==="LR",H=f.useMemo(()=>[..._.groups,...e.map(p=>{const c=[_.groupLabels.get(p.id),w?`react-flow__node-desc-${x}`:void 0].filter(Boolean).join(" ");return{id:p.id,type:"service",position:_.positions.get(p.id)??{x:0,y:0},measured:S.get(p.id),ariaLabel:p.label,ariaRole:"group",domAttributes:{"aria-roledescription":M.serviceMapNodeRole,"aria-current":i===p.id?!0:void 0,"aria-describedby":c===""?void 0:c},data:{node:p,selected:i===p.id},sourcePosition:T?m.Position.Right:m.Position.Bottom,targetPosition:T?m.Position.Left:m.Position.Top,draggable:!1,connectable:!1,selectable:w,focusable:w}})],[_,e,S,i,T,w,x,M]),P=f.useMemo(()=>{const p=new Map(e.map(c=>[c.id,c.label]));return n.map(c=>({id:c.id,source:c.source,target:c.target,ariaLabel:M.serviceMapEdgeName(p.get(c.source)??c.source,p.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"}`}))},[e,n,N,M]),{getNode:F}=m.useReactFlow(),G=f.useCallback(p=>{const c=p.flatMap(b=>b.type==="dimensions"&&b.dimensions!==void 0&&F(b.id)?.type==="service"?[[b.id,b.dimensions]]:[]);O(b=>c.every(([R,$])=>b.get(R)?.width===$.width&&b.get(R)?.height===$.height)?b:new Map([...b,...c]))},[F]),y=re.useMediaQuery(Ne),A=d&&!y,D=f.useContext(le.SelectedRowDetailContext),k=je(L,_,e.every(p=>S.has(p.id)),t,A,y),B=i!==void 0&&L.ids.includes(i)?i:void 0,[q,te]=f.useState();k&&q!==B&&te(B),V.useIsomorphicLayoutEffect(()=>{if(!(D===null||B===void 0||k))return D.awaitRow(),()=>{D.placeRow(null)}},[D,B,k]);const se=Le(),oe=f.useCallback((p,c)=>{c.type==="service"&&s?.(c.data.node)},[s]),ie=f.useCallback((p,c)=>{c.data&&l?.(c.data.edge)},[l]),ne=f.useCallback(p=>{if(p.key!=="Enter"&&p.key!==" "||p.repeat)return;const c=p.target;if(!(c instanceof Element))return;const b=c.getAttribute("data-id");if(c.classList.contains("react-flow__node")){const R=e.find($=>$.id===b);R&&s&&(p.preventDefault(),s(R))}else if(c.classList.contains("react-flow__edge")){const R=n.find($=>$.id===b);R&&l&&(p.preventDefault(),l(R))}},[e,n,s,l]),ae={...pe,height:r===void 0?void 0:`${String(r)}px`};return u.jsxs("div",{className:["aegis-service-map",g?"aegis-service-map--fill-viewport":"",v].filter(Boolean).join(" "),style:ae,children:[u.jsx("div",{className:"aegis-service-map__pane",children:u.jsxs(m.ReactFlow,{id:x,"aria-label":h,nodes:H,edges:P,nodeTypes:Se,edgeTypes:Me,minZoom:U,nodesDraggable:!1,nodesConnectable:!1,autoPanOnNodeFocus:!1,panOnDrag:!0,zoomOnScroll:!0,proOptions:{hideAttribution:!0},ariaLabelConfig:M.serviceMapAriaLabels,onNodesChange:G,onNodeClick:w?oe:void 0,onEdgeClick:N?ie:void 0,onKeyDown:ne,onFocus:se,children:[u.jsx(m.Background,{variant:m.BackgroundVariant.Dots,gap:16,size:1}),u.jsx(m.Controls,{showInteractive:!1,position:"top-left"}),A&&u.jsx(m.MiniMap,{pannable:!0,zoomable:!0,position:"bottom-right",style:{width:ee},nodeClassName:Re})]})}),D!==null&&q!==void 0&&u.jsx(Oe,{nodeId:q,fitted:k,selection:D})]})}function De(e){return u.jsx(m.ReactFlowProvider,{children:u.jsx(Te,{...e})})}exports.ServiceMap=De;
2
2
  //# sourceMappingURL=ServiceMap.cjs.map