@mastra/playground-ui 70.0.0 → 70.1.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/dist/{EmptyState-juw2jci2.js → EmptyState-DJaZF543.js} +43 -23
  2. package/dist/EmptyState-DJaZF543.js.map +1 -0
  3. package/dist/{EmptyState-C5O9fTEq.cjs → EmptyState-DnW6SNEx.cjs} +43 -23
  4. package/dist/EmptyState-DnW6SNEx.cjs.map +1 -0
  5. package/dist/EmptyStateArt.css +12028 -0
  6. package/dist/{Section-Dk_Vcsi7.cjs → Section-BdO9TFjY.cjs} +2 -2
  7. package/dist/{Section-Dk_Vcsi7.cjs.map → Section-BdO9TFjY.cjs.map} +1 -1
  8. package/dist/{Section-D6JJ926q.js → Section-DV2aLnkc.js} +2 -2
  9. package/dist/{Section-D6JJ926q.js.map → Section-DV2aLnkc.js.map} +1 -1
  10. package/dist/components/EmptyState.cjs.js +1 -1
  11. package/dist/components/EmptyState.es.js +1 -1
  12. package/dist/components/EmptyStateArt.cjs.js +9695 -0
  13. package/dist/components/EmptyStateArt.cjs.js.map +1 -0
  14. package/dist/components/EmptyStateArt.d.ts +1 -0
  15. package/dist/components/EmptyStateArt.es.js +9694 -0
  16. package/dist/components/EmptyStateArt.es.js.map +1 -0
  17. package/dist/components/FileDropBackdrop.cjs.js +1 -1
  18. package/dist/components/FileDropBackdrop.es.js +1 -1
  19. package/dist/components/Section.cjs.js +1 -1
  20. package/dist/components/Section.es.js +1 -1
  21. package/dist/components/SideDialog.cjs.js +1 -1
  22. package/dist/components/SideDialog.es.js +1 -1
  23. package/dist/domains/auth/components/permission-denied.cjs.js +1 -1
  24. package/dist/domains/auth/components/permission-denied.es.js +1 -1
  25. package/dist/domains/auth/components/session-expired.cjs.js +1 -1
  26. package/dist/domains/auth/components/session-expired.es.js +1 -1
  27. package/dist/domains/datasets/components/add-dataset-item-dialog/add-dataset-item-dialog.cjs.js +1 -1
  28. package/dist/domains/datasets/components/add-dataset-item-dialog/add-dataset-item-dialog.es.js +1 -1
  29. package/dist/domains/datasets/components/add-dataset-item-dialog/collapsible-settings-row.cjs.js +1 -1
  30. package/dist/domains/datasets/components/add-dataset-item-dialog/collapsible-settings-row.es.js +1 -1
  31. package/dist/domains/knowledge/components/KnowledgePageDetail.cjs.js +99 -58
  32. package/dist/domains/knowledge/components/KnowledgePageDetail.cjs.js.map +1 -1
  33. package/dist/domains/knowledge/components/KnowledgePageDetail.es.js +99 -58
  34. package/dist/domains/knowledge/components/KnowledgePageDetail.es.js.map +1 -1
  35. package/dist/domains/knowledge/components/KnowledgePageExplorer.cjs.js +22 -1
  36. package/dist/domains/knowledge/components/KnowledgePageExplorer.cjs.js.map +1 -1
  37. package/dist/domains/knowledge/components/KnowledgePageExplorer.es.js +22 -1
  38. package/dist/domains/knowledge/components/KnowledgePageExplorer.es.js.map +1 -1
  39. package/dist/domains/knowledge/components/KnowledgePageTree.cjs.js +1 -1
  40. package/dist/domains/knowledge/components/KnowledgePageTree.cjs.js.map +1 -1
  41. package/dist/domains/knowledge/components/KnowledgePageTree.es.js +2 -2
  42. package/dist/domains/knowledge/components/KnowledgePageTree.es.js.map +1 -1
  43. package/dist/domains/knowledge/lib/pageAddress.cjs.js +21 -6
  44. package/dist/domains/knowledge/lib/pageAddress.cjs.js.map +1 -1
  45. package/dist/domains/knowledge/lib/pageAddress.es.js +21 -6
  46. package/dist/domains/knowledge/lib/pageAddress.es.js.map +1 -1
  47. package/dist/domains/logs/components/logs-error-content.cjs.js +1 -1
  48. package/dist/domains/logs/components/logs-error-content.es.js +1 -1
  49. package/dist/domains/logs/components/no-logs-info.cjs.js +1 -1
  50. package/dist/domains/logs/components/no-logs-info.es.js +1 -1
  51. package/dist/domains/mcps/components/mcp-app-viewer.cjs.js +1 -1
  52. package/dist/domains/mcps/components/mcp-app-viewer.es.js +1 -1
  53. package/dist/domains/mcps/hooks/use-mcp-app-tool-call.cjs.js +1 -1
  54. package/dist/domains/mcps/hooks/use-mcp-app-tool-call.es.js +1 -1
  55. package/dist/domains/memory/components/observation-detail-view.cjs.js +1 -1
  56. package/dist/domains/memory/components/observation-detail-view.es.js +1 -1
  57. package/dist/domains/observability/components/observability-capability-gate.cjs.js +1 -1
  58. package/dist/domains/observability/components/observability-capability-gate.es.js +1 -1
  59. package/dist/domains/scores/components/trace-scores-tab.cjs.js +1 -1
  60. package/dist/domains/scores/components/trace-scores-tab.es.js +1 -1
  61. package/dist/domains/traces/components/no-traces-info.cjs.js +1 -1
  62. package/dist/domains/traces/components/no-traces-info.es.js +1 -1
  63. package/dist/domains/traces/components/traces-error-content.cjs.js +1 -1
  64. package/dist/domains/traces/components/traces-error-content.es.js +1 -1
  65. package/dist/domains/workflows/components/workflows-list/no-workflows-info.cjs.js +1 -1
  66. package/dist/domains/workflows/components/workflows-list/no-workflows-info.es.js +1 -1
  67. package/dist/domains/workspace/components/workspace-add-skill-dialog.cjs.js +1 -1
  68. package/dist/domains/workspace/components/workspace-add-skill-dialog.es.js +1 -1
  69. package/dist/domains/workspace/components/workspace-parts.cjs.js +1 -1
  70. package/dist/domains/workspace/components/workspace-parts.es.js +1 -1
  71. package/dist/domains/workspace/components/workspace-search.cjs.js +1 -1
  72. package/dist/domains/workspace/components/workspace-search.es.js +1 -1
  73. package/dist/ee/signals/components/trace-intelligence-entity-detail.cjs.js +1 -1
  74. package/dist/ee/signals/components/trace-intelligence-entity-detail.es.js +1 -1
  75. package/dist/ee/signals/components/trace-intelligence-entity-index.cjs.js +1 -1
  76. package/dist/ee/signals/components/trace-intelligence-entity-index.es.js +1 -1
  77. package/dist/new/settings.cjs.js +2 -2
  78. package/dist/new/settings.es.js +2 -2
  79. package/dist/{settings-DIrzLcgE.js → settings-B7RMGKgf.js} +31 -15
  80. package/dist/settings-B7RMGKgf.js.map +1 -0
  81. package/dist/{settings-5PdsNlhV.cjs → settings-CYKWxfrJ.cjs} +31 -15
  82. package/dist/settings-CYKWxfrJ.cjs.map +1 -0
  83. package/dist/{settings-row-C2HTuwjN.js → settings-row-BnlFZSQL.js} +27 -5
  84. package/dist/settings-row-BnlFZSQL.js.map +1 -0
  85. package/dist/{settings-row-Dfi4pLnl.cjs → settings-row-Da1HHyBg.cjs} +27 -5
  86. package/dist/settings-row-Da1HHyBg.cjs.map +1 -0
  87. package/dist/src/domains/knowledge/components/KnowledgePageDetail.d.ts +11 -1
  88. package/dist/src/domains/knowledge/lib/pageAddress.d.ts +4 -2
  89. package/dist/src/ds/components/EmptyState/EmptyState.d.ts +3 -1
  90. package/dist/src/ds/components/EmptyStateArt/art/alerts-scene.d.ts +2 -0
  91. package/dist/src/ds/components/EmptyStateArt/art/api-keys-scene.d.ts +2 -0
  92. package/dist/src/ds/components/EmptyStateArt/art/byok-scene.d.ts +2 -0
  93. package/dist/src/ds/components/EmptyStateArt/art/connect-scene.d.ts +2 -0
  94. package/dist/src/ds/components/EmptyStateArt/art/databases-scene.d.ts +2 -0
  95. package/dist/src/ds/components/EmptyStateArt/art/deploys-scene.d.ts +2 -0
  96. package/dist/src/ds/components/EmptyStateArt/art/destinations-scene.d.ts +2 -0
  97. package/dist/src/ds/components/EmptyStateArt/art/env-vars-scene.d.ts +2 -0
  98. package/dist/src/ds/components/EmptyStateArt/art/environments-scene.d.ts +2 -0
  99. package/dist/src/ds/components/EmptyStateArt/art/gateway-scene.d.ts +2 -0
  100. package/dist/src/ds/components/EmptyStateArt/art/gateway-threads-scene.d.ts +2 -0
  101. package/dist/src/ds/components/EmptyStateArt/art/importers-scene.d.ts +2 -0
  102. package/dist/src/ds/components/EmptyStateArt/art/knowledge-scene.d.ts +2 -0
  103. package/dist/src/ds/components/EmptyStateArt/art/license-scene.d.ts +2 -0
  104. package/dist/src/ds/components/EmptyStateArt/art/logs-scene.d.ts +2 -0
  105. package/dist/src/ds/components/EmptyStateArt/art/memory-scene.d.ts +2 -0
  106. package/dist/src/ds/components/EmptyStateArt/art/models-scene.d.ts +2 -0
  107. package/dist/src/ds/components/EmptyStateArt/art/projects-scene.d.ts +2 -0
  108. package/dist/src/ds/components/EmptyStateArt/art/scene-style.d.ts +17 -0
  109. package/dist/src/ds/components/EmptyStateArt/art/scenes.d.ts +3 -0
  110. package/dist/src/ds/components/EmptyStateArt/art/traces-scene.d.ts +2 -0
  111. package/dist/src/ds/components/EmptyStateArt/art/upgrade-scene.d.ts +2 -0
  112. package/dist/src/ds/components/EmptyStateArt/art/widgets-scene.d.ts +2 -0
  113. package/dist/src/ds/components/EmptyStateArt/art/workers-scene.d.ts +2 -0
  114. package/dist/src/ds/components/EmptyStateArt/art/workspaces-scene.d.ts +2 -0
  115. package/dist/src/ds/components/EmptyStateArt/art-motion.d.ts +1 -0
  116. package/dist/src/ds/components/EmptyStateArt/empty-state-art.d.ts +11 -0
  117. package/dist/src/ds/components/EmptyStateArt/index.d.ts +3 -0
  118. package/dist/src/ds/new/settings/settings-list.d.ts +16 -2
  119. package/dist/src/ds/new/settings/settings-row.d.ts +22 -2
  120. package/dist/style.css +65 -0
  121. package/dist/{types-DT1pgDom.cjs → types-CVS7iNs8.cjs} +2 -2
  122. package/dist/{types-DT1pgDom.cjs.map → types-CVS7iNs8.cjs.map} +1 -1
  123. package/dist/{types-Dl74jixe.js → types-D64dArGX.js} +2 -2
  124. package/dist/{types-Dl74jixe.js.map → types-D64dArGX.js.map} +1 -1
  125. package/package.json +6 -6
  126. package/dist/EmptyState-C5O9fTEq.cjs.map +0 -1
  127. package/dist/EmptyState-juw2jci2.js.map +0 -1
  128. package/dist/settings-5PdsNlhV.cjs.map +0 -1
  129. package/dist/settings-DIrzLcgE.js.map +0 -1
  130. package/dist/settings-row-C2HTuwjN.js.map +0 -1
  131. package/dist/settings-row-Dfi4pLnl.cjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"KnowledgePageTree.cjs.js","names":["useMemo","buildPageTree","useState","useRef","pageAncestorIds","visiblePageRows","prefersMotion","Fragment","cn","DisclosureChevron","scopeTitle","KnowledgeSourceIcon","IconFolder1","IconFileText","childCountLabel","IconPin"],"sources":["../../../../src/domains/knowledge/components/KnowledgePageTree.tsx"],"sourcesContent":["import { Fragment, useEffect, useMemo, useRef, useState } from 'react';\nimport type { KeyboardEvent } from 'react';\n\nimport { scopeTitle } from '../lib/pageAddress';\nimport { buildPageTree, childCountLabel, pageAncestorIds, visiblePageRows } from '../lib/pageTree';\nimport { prefersMotion } from '../lib/useLeavingNodes';\nimport type { KnowledgePagePayload } from '../pageTypes';\nimport { KnowledgeSourceIcon } from './KnowledgeSourceIcon';\n\nimport { DisclosureChevron } from '@/ds/components/DisclosureChevron';\nimport { IconFileText } from '@/ds/icons/central/IconFileText';\nimport { IconFolder1 } from '@/ds/icons/central/IconFolder1';\nimport { IconPin } from '@/ds/icons/central/IconPin';\nimport { cn } from '@/utils/cn';\n\n/**\n * The box of the nearest ancestor (or the element itself) that really scrolls vertically. The tree sets\n * `overflow-y: auto` itself but, as tall as its rows, never overflows; a parent is what scrolls, so a\n * node counts only when its content is taller than it is.\n */\nfunction scrollingBox(element: HTMLElement | null): DOMRect | undefined {\n let overflowing: HTMLElement | undefined;\n for (let node = element; node; node = node.parentElement) {\n const { overflowY } = getComputedStyle(node);\n if (overflowY !== 'auto' && overflowY !== 'scroll' && overflowY !== 'overlay') continue;\n if (node.scrollHeight > node.clientHeight) return node.getBoundingClientRect();\n overflowing ??= node;\n }\n return (overflowing ?? element)?.getBoundingClientRect();\n}\n\n/** Where in the scroller a row focused from elsewhere lands, as a fraction of its height from the top. */\nconst SCROLL_ROW_AT = 1 / 3;\n/** A row between these fractions of the scroller is comfortably in view and is not moved. */\nconst COMFORT_TOP = 0.1;\nconst COMFORT_BOTTOM = 0.7;\n\n/** The key {@link KnowledgePageTree}'s `loadMore` uses for the root level. */\nexport const KNOWLEDGE_TREE_ROOT = '';\n\n/**\n * The Knowledge page tree: scopes and pages nested by parent, siblings in\n * stored order. Selecting a page from elsewhere (graph, search) opens the path\n * to it. Keyboard follows the WAI-ARIA tree pattern: Up/Down move, Right opens\n * or enters, Left closes or goes to the parent, Enter/Space selects.\n *\n * A host that loads the tree a level at a time passes `mayHaveChildren` (so unloaded pages still offer\n * a chevron), listens to `onExpandedChange` to load the opened levels, and passes `loadMore` for\n * levels with more children to fetch. A page's `childCount`, when the server sends one, shows beside\n * its name. Selecting a page with children also opens it.\n */\nexport function KnowledgePageTree({\n pages,\n pinnedIds,\n selectedPageId,\n onSelect,\n initiallyExpanded,\n mayHaveChildren,\n onExpandedChange,\n loadMore,\n 'aria-label': ariaLabel = 'Knowledge pages',\n}: {\n pages: KnowledgePagePayload[];\n pinnedIds?: readonly string[];\n selectedPageId?: string | null;\n onSelect: (page: KnowledgePagePayload) => void;\n /** Ids open on first render; defaults to every root. */\n initiallyExpanded?: string[];\n /** True for a page whose children are not loaded yet, so it can still be opened. */\n mayHaveChildren?: (page: KnowledgePagePayload) => boolean;\n onExpandedChange?: (expanded: ReadonlySet<string>) => void;\n /** Parent id ({@link KNOWLEDGE_TREE_ROOT} for the roots) to a loader for its next children. */\n loadMore?: ReadonlyMap<string, () => void>;\n 'aria-label'?: string;\n}) {\n const roots = useMemo(() => buildPageTree(pages), [pages]);\n const pinned = useMemo(() => new Set(pinnedIds), [pinnedIds]);\n const [expanded, setExpanded] = useState<Set<string>>(\n () => new Set(initiallyExpanded ?? roots.map(root => root.page.id)),\n );\n const [focusedId, setFocusedId] = useState<string | null>(null);\n const itemRefs = useRef(new Map<string, HTMLDivElement>());\n\n // Open the path to a selection once. Later renders with the same selection and path (a refetch, a\n // level loading) leave it alone, so a parent the user collapses over the selection stays collapsed.\n const revealed = useRef<string | null>(null);\n useEffect(() => {\n if (!selectedPageId) {\n // Forget the last reveal, so picking the same page again after a clear opens its path.\n revealed.current = null;\n return;\n }\n const path = pageAncestorIds(pages, selectedPageId);\n const key = [selectedPageId, ...path].join('/');\n if (revealed.current === key) return;\n revealed.current = key;\n setExpanded(current => (path.every(id => current.has(id)) ? current : new Set([...current, ...path])));\n }, [pages, selectedPageId]);\n\n useEffect(() => {\n onExpandedChange?.(expanded);\n }, [expanded, onExpandedChange]);\n\n const rows = useMemo(\n () =>\n visiblePageRows(roots, expanded).map(row =>\n !row.hasChildren && mayHaveChildren?.(row.page) ? { ...row, hasChildren: true } : row,\n ),\n [roots, expanded, mayHaveChildren],\n );\n // Bring the selected row into view when it is selected, as soon as it exists, and again if rows that load\n // later push it out of view (a deep page's levels arrive one after another). Once the user scrolls, presses a key or\n // a pointer in the tree it is left alone. The row goes a third of the way down the scroller, middle-top, not\n // hard against its bottom edge; keyboard focus is not moved.\n const scroller = useRef<HTMLDivElement>(null);\n const scrolledTo = useRef<string | null>(null);\n const userScrolled = useRef(false);\n useEffect(() => {\n if (!selectedPageId) {\n scrolledTo.current = null;\n return;\n }\n const element = itemRefs.current.get(selectedPageId);\n if (!element) return;\n const first = scrolledTo.current !== selectedPageId;\n if (first) {\n scrolledTo.current = selectedPageId;\n userScrolled.current = false;\n } else if (userScrolled.current) return;\n const box = scrollingBox(scroller.current);\n const at = element.getBoundingClientRect();\n if (!first && !box) return;\n if (!first && box && box.height === 0 && at.top >= box.top && at.bottom <= box.bottom) return;\n if (box && box.height > 0) {\n // A row already well inside the scroller stays where it is.\n const inView = at.top >= box.top + box.height * COMFORT_TOP && at.bottom <= box.top + box.height * COMFORT_BOTTOM;\n if (inView) return;\n // Otherwise it lands a third of the way down; the browser clamps this at the top and bottom of the list.\n element.style.scrollMarginTop = `${box.height * SCROLL_ROW_AT}px`;\n }\n element.scrollIntoView?.({ block: 'start', behavior: first && prefersMotion() ? 'smooth' : 'auto' });\n // The margin only steers this scroll; left on, focus() scrolls and a resized pane would keep a stale gap.\n element.style.scrollMarginTop = '';\n }, [rows, selectedPageId]);\n const activeId =\n focusedId && rows.some(row => row.page.id === focusedId)\n ? focusedId\n : (rows.find(row => row.page.id === selectedPageId)?.page.id ?? rows[0]?.page.id);\n\n const toggle = (id: string, open: boolean) =>\n setExpanded(current => {\n if (current.has(id) === open) return current;\n const next = new Set(current);\n if (open) next.add(id);\n else next.delete(id);\n return next;\n });\n\n const focus = (id: string | undefined) => {\n if (!id) return;\n setFocusedId(id);\n itemRefs.current.get(id)?.focus();\n };\n\n const onKeyDown = (event: KeyboardEvent<HTMLDivElement>, index: number) => {\n const row = rows[index];\n if (!row) return;\n switch (event.key) {\n case 'ArrowDown':\n focus(rows[index + 1]?.page.id);\n break;\n case 'ArrowUp':\n focus(rows[index - 1]?.page.id);\n break;\n case 'ArrowRight':\n if (row.hasChildren && !row.expanded) toggle(row.page.id, true);\n else if (row.expanded) focus(rows[index + 1]?.page.id);\n break;\n case 'ArrowLeft':\n if (row.expanded) toggle(row.page.id, false);\n else focus(rows.slice(0, index).findLast(candidate => candidate.depth < row.depth)?.page.id);\n break;\n case 'Enter':\n case ' ':\n onSelect(row.page);\n break;\n default:\n return;\n }\n event.preventDefault();\n };\n\n if (rows.length === 0) {\n return <p className=\"px-3 py-2 text-body text-muted-foreground\">No pages yet.</p>;\n }\n\n const ancestorAt: string[] = [];\n return (\n <div\n ref={scroller}\n role=\"tree\"\n aria-label={ariaLabel}\n className=\"min-h-0 overflow-y-auto py-1\"\n onWheel={() => (userScrolled.current = true)}\n onTouchMove={() => (userScrolled.current = true)}\n onPointerDown={() => (userScrolled.current = true)}\n onKeyDown={() => (userScrolled.current = true)}\n >\n {rows.map((row, index) => {\n const selected = row.page.id === selectedPageId;\n ancestorAt[row.depth] = row.page.id;\n // Levels whose last loaded child is this row's subtree end here: offer their next children.\n const nextDepth = rows[index + 1]?.depth ?? -1;\n const closing: Array<{ parentId: string; depth: number }> = [];\n for (let depth = row.depth - 1; depth >= nextDepth; depth--) {\n const parentId = depth < 0 ? KNOWLEDGE_TREE_ROOT : ancestorAt[depth];\n if (parentId !== undefined) closing.push({ parentId, depth: depth + 1 });\n }\n if (row.expanded && rows[index + 1]?.depth !== row.depth + 1)\n closing.unshift({ parentId: row.page.id, depth: row.depth + 1 });\n return (\n <Fragment key={row.page.id}>\n <div\n ref={element => {\n if (element) itemRefs.current.set(row.page.id, element);\n else itemRefs.current.delete(row.page.id);\n }}\n role=\"treeitem\"\n aria-level={row.depth + 1}\n aria-selected={selected}\n aria-expanded={row.hasChildren ? row.expanded : undefined}\n tabIndex={row.page.id === activeId ? 0 : -1}\n onFocus={() => setFocusedId(row.page.id)}\n onKeyDown={event => onKeyDown(event, index)}\n onClick={() => {\n onSelect(row.page);\n // Selecting a page with children opens it too, which loads them in a lazily loaded tree.\n if (row.hasChildren) toggle(row.page.id, true);\n }}\n className={cn(\n 'flex h-8 cursor-pointer items-center gap-2 rounded-md pr-2 text-body-sm text-foreground outline-none focus-visible:bg-fill-subtle',\n selected ? 'bg-fill-hover' : 'hover:bg-fill-subtle',\n )}\n style={{ paddingLeft: `${row.depth * 12 + 4}px` }}\n >\n {row.hasChildren ? (\n <button\n type=\"button\"\n tabIndex={-1}\n aria-label={row.expanded ? `Collapse ${row.page.name}` : `Expand ${row.page.name}`}\n className=\"flex size-3 shrink-0 items-center justify-center text-muted-foreground hover:text-foreground\"\n onClick={event => {\n event.stopPropagation();\n toggle(row.page.id, !row.expanded);\n }}\n >\n <DisclosureChevron direction=\"right\" open={row.expanded} className=\"size-3\" />\n </button>\n ) : (\n <span className=\"size-3 shrink-0\" aria-hidden />\n )}\n <span className=\"flex shrink-0 items-center text-muted-foreground [&>svg]:size-icon-sm\" aria-hidden>\n {row.page.isScope && scopeTitle(row.page) !== row.page.name ? (\n <KnowledgeSourceIcon page={row.page} />\n ) : row.hasChildren ? (\n <IconFolder1 />\n ) : (\n <IconFileText />\n )}\n </span>\n <span className={cn('min-w-0 flex-1 truncate', row.page.isScope && 'font-medium')}>\n {scopeTitle(row.page)}\n </span>\n {row.page.childCount ? (\n <span\n data-testid=\"knowledge-tree-count\"\n aria-label={`${childCountLabel(row.page)} below`}\n className=\"shrink-0 text-caption text-placeholder tabular-nums\"\n >\n {childCountLabel(row.page)}\n </span>\n ) : null}\n {pinned.has(row.page.id) ? (\n <IconPin className=\"size-icon-xs shrink-0 text-badge-amber-indicator\" aria-label=\"Pinned\" />\n ) : null}\n {row.page.isScope && row.page.address && row.page.address !== row.page.name ? (\n <span\n data-testid=\"knowledge-tree-address\"\n className=\"max-w-1/2 min-w-0 truncate text-caption text-muted-foreground\"\n >\n {row.page.address}\n </span>\n ) : null}\n </div>\n {closing.map(({ parentId, depth }) => {\n const more = loadMore?.get(parentId);\n return more ? (\n <button\n key={`more-${parentId}`}\n type=\"button\"\n className=\"flex h-8 w-full items-center text-left text-caption text-muted-foreground hover:text-foreground\"\n style={{ paddingLeft: `${depth * 12 + 42}px` }}\n onClick={more}\n >\n Load more\n </button>\n ) : null;\n })}\n </Fragment>\n );\n })}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAoBA,SAAS,aAAa,SAAkD;CACtE,IAAI;CACJ,KAAK,IAAI,OAAO,SAAS,MAAM,OAAO,KAAK,eAAe;EACxD,MAAM,EAAE,cAAc,iBAAiB,IAAI;EAC3C,IAAI,cAAc,UAAU,cAAc,YAAY,cAAc,WAAW;EAC/E,IAAI,KAAK,eAAe,KAAK,cAAc,OAAO,KAAK,sBAAsB;EAC7E,gBAAgB;CAClB;CACA,QAAQ,eAAe,QAAA,EAAU,sBAAsB;AACzD;;AAGA,IAAM,gBAAgB,IAAI;;AAE1B,IAAM,cAAc;AACpB,IAAM,iBAAiB;;AAGvB,IAAa,sBAAsB;;;;;;;;;;;;AAanC,SAAgB,kBAAkB,EAChC,OACA,WACA,gBACA,UACA,mBACA,iBACA,kBACA,UACA,cAAc,YAAY,qBAczB;CACD,MAAM,SAAA,GAAQA,MAAAA,QAAAA,OAAcC,uCAAAA,cAAc,KAAK,GAAG,CAAC,KAAK,CAAC;CACzD,MAAM,UAAA,GAASD,MAAAA,QAAAA,OAAc,IAAI,IAAI,SAAS,GAAG,CAAC,SAAS,CAAC;CAC5D,MAAM,CAAC,UAAU,gBAAA,GAAeE,MAAAA,SAAAA,OACxB,IAAI,IAAI,qBAAqB,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,CAAA,IACJ;IACD;GACJ,CAAA,GAAA,QAAQ,KAAK,EAAE,UAAU,YAAY;IACpC,MAAM,OAAO,UAAU,IAAI,QAAQ;IACnC,OAAO,OACL,iBAAA,GAAA,kBAAA,IAAA,CAAC,UAAD;KAEE,MAAK;KACL,WAAU;KACV,OAAO,EAAE,aAAa,GAAG,QAAQ,KAAK,GAAG,IAAI;KAC7C,SAAS;KACV,UAAA;IAEO,GAPD,QAAQ,UAOP,IACN;GACN,CAAC,CACO,EAAA,GAvFK,IAAI,KAAK,EAuFd;EAEd,CAAC;CACE,CAAA;AAET"}
1
+ {"version":3,"file":"KnowledgePageTree.cjs.js","names":["useMemo","buildPageTree","useState","useRef","pageAncestorIds","visiblePageRows","prefersMotion","Fragment","cn","DisclosureChevron","scopeSource","KnowledgeSourceIcon","IconFolder1","IconFileText","scopeTitle","childCountLabel","IconPin"],"sources":["../../../../src/domains/knowledge/components/KnowledgePageTree.tsx"],"sourcesContent":["import { Fragment, useEffect, useMemo, useRef, useState } from 'react';\nimport type { KeyboardEvent } from 'react';\n\nimport { scopeSource, scopeTitle } from '../lib/pageAddress';\nimport { buildPageTree, childCountLabel, pageAncestorIds, visiblePageRows } from '../lib/pageTree';\nimport { prefersMotion } from '../lib/useLeavingNodes';\nimport type { KnowledgePagePayload } from '../pageTypes';\nimport { KnowledgeSourceIcon } from './KnowledgeSourceIcon';\n\nimport { DisclosureChevron } from '@/ds/components/DisclosureChevron';\nimport { IconFileText } from '@/ds/icons/central/IconFileText';\nimport { IconFolder1 } from '@/ds/icons/central/IconFolder1';\nimport { IconPin } from '@/ds/icons/central/IconPin';\nimport { cn } from '@/utils/cn';\n\n/**\n * The box of the nearest ancestor (or the element itself) that really scrolls vertically. The tree sets\n * `overflow-y: auto` itself but, as tall as its rows, never overflows; a parent is what scrolls, so a\n * node counts only when its content is taller than it is.\n */\nfunction scrollingBox(element: HTMLElement | null): DOMRect | undefined {\n let overflowing: HTMLElement | undefined;\n for (let node = element; node; node = node.parentElement) {\n const { overflowY } = getComputedStyle(node);\n if (overflowY !== 'auto' && overflowY !== 'scroll' && overflowY !== 'overlay') continue;\n if (node.scrollHeight > node.clientHeight) return node.getBoundingClientRect();\n overflowing ??= node;\n }\n return (overflowing ?? element)?.getBoundingClientRect();\n}\n\n/** Where in the scroller a row focused from elsewhere lands, as a fraction of its height from the top. */\nconst SCROLL_ROW_AT = 1 / 3;\n/** A row between these fractions of the scroller is comfortably in view and is not moved. */\nconst COMFORT_TOP = 0.1;\nconst COMFORT_BOTTOM = 0.7;\n\n/** The key {@link KnowledgePageTree}'s `loadMore` uses for the root level. */\nexport const KNOWLEDGE_TREE_ROOT = '';\n\n/**\n * The Knowledge page tree: scopes and pages nested by parent, siblings in\n * stored order. Selecting a page from elsewhere (graph, search) opens the path\n * to it. Keyboard follows the WAI-ARIA tree pattern: Up/Down move, Right opens\n * or enters, Left closes or goes to the parent, Enter/Space selects.\n *\n * A host that loads the tree a level at a time passes `mayHaveChildren` (so unloaded pages still offer\n * a chevron), listens to `onExpandedChange` to load the opened levels, and passes `loadMore` for\n * levels with more children to fetch. A page's `childCount`, when the server sends one, shows beside\n * its name. Selecting a page with children also opens it.\n */\nexport function KnowledgePageTree({\n pages,\n pinnedIds,\n selectedPageId,\n onSelect,\n initiallyExpanded,\n mayHaveChildren,\n onExpandedChange,\n loadMore,\n 'aria-label': ariaLabel = 'Knowledge pages',\n}: {\n pages: KnowledgePagePayload[];\n pinnedIds?: readonly string[];\n selectedPageId?: string | null;\n onSelect: (page: KnowledgePagePayload) => void;\n /** Ids open on first render; defaults to every root. */\n initiallyExpanded?: string[];\n /** True for a page whose children are not loaded yet, so it can still be opened. */\n mayHaveChildren?: (page: KnowledgePagePayload) => boolean;\n onExpandedChange?: (expanded: ReadonlySet<string>) => void;\n /** Parent id ({@link KNOWLEDGE_TREE_ROOT} for the roots) to a loader for its next children. */\n loadMore?: ReadonlyMap<string, () => void>;\n 'aria-label'?: string;\n}) {\n const roots = useMemo(() => buildPageTree(pages), [pages]);\n const pinned = useMemo(() => new Set(pinnedIds), [pinnedIds]);\n const [expanded, setExpanded] = useState<Set<string>>(\n () => new Set(initiallyExpanded ?? roots.map(root => root.page.id)),\n );\n const [focusedId, setFocusedId] = useState<string | null>(null);\n const itemRefs = useRef(new Map<string, HTMLDivElement>());\n\n // Open the path to a selection once. Later renders with the same selection and path (a refetch, a\n // level loading) leave it alone, so a parent the user collapses over the selection stays collapsed.\n const revealed = useRef<string | null>(null);\n useEffect(() => {\n if (!selectedPageId) {\n // Forget the last reveal, so picking the same page again after a clear opens its path.\n revealed.current = null;\n return;\n }\n const path = pageAncestorIds(pages, selectedPageId);\n const key = [selectedPageId, ...path].join('/');\n if (revealed.current === key) return;\n revealed.current = key;\n setExpanded(current => (path.every(id => current.has(id)) ? current : new Set([...current, ...path])));\n }, [pages, selectedPageId]);\n\n useEffect(() => {\n onExpandedChange?.(expanded);\n }, [expanded, onExpandedChange]);\n\n const rows = useMemo(\n () =>\n visiblePageRows(roots, expanded).map(row =>\n !row.hasChildren && mayHaveChildren?.(row.page) ? { ...row, hasChildren: true } : row,\n ),\n [roots, expanded, mayHaveChildren],\n );\n // Bring the selected row into view when it is selected, as soon as it exists, and again if rows that load\n // later push it out of view (a deep page's levels arrive one after another). Once the user scrolls, presses a key or\n // a pointer in the tree it is left alone. The row goes a third of the way down the scroller, middle-top, not\n // hard against its bottom edge; keyboard focus is not moved.\n const scroller = useRef<HTMLDivElement>(null);\n const scrolledTo = useRef<string | null>(null);\n const userScrolled = useRef(false);\n useEffect(() => {\n if (!selectedPageId) {\n scrolledTo.current = null;\n return;\n }\n const element = itemRefs.current.get(selectedPageId);\n if (!element) return;\n const first = scrolledTo.current !== selectedPageId;\n if (first) {\n scrolledTo.current = selectedPageId;\n userScrolled.current = false;\n } else if (userScrolled.current) return;\n const box = scrollingBox(scroller.current);\n const at = element.getBoundingClientRect();\n if (!first && !box) return;\n if (!first && box && box.height === 0 && at.top >= box.top && at.bottom <= box.bottom) return;\n if (box && box.height > 0) {\n // A row already well inside the scroller stays where it is.\n const inView = at.top >= box.top + box.height * COMFORT_TOP && at.bottom <= box.top + box.height * COMFORT_BOTTOM;\n if (inView) return;\n // Otherwise it lands a third of the way down; the browser clamps this at the top and bottom of the list.\n element.style.scrollMarginTop = `${box.height * SCROLL_ROW_AT}px`;\n }\n element.scrollIntoView?.({ block: 'start', behavior: first && prefersMotion() ? 'smooth' : 'auto' });\n // The margin only steers this scroll; left on, focus() scrolls and a resized pane would keep a stale gap.\n element.style.scrollMarginTop = '';\n }, [rows, selectedPageId]);\n const activeId =\n focusedId && rows.some(row => row.page.id === focusedId)\n ? focusedId\n : (rows.find(row => row.page.id === selectedPageId)?.page.id ?? rows[0]?.page.id);\n\n const toggle = (id: string, open: boolean) =>\n setExpanded(current => {\n if (current.has(id) === open) return current;\n const next = new Set(current);\n if (open) next.add(id);\n else next.delete(id);\n return next;\n });\n\n const focus = (id: string | undefined) => {\n if (!id) return;\n setFocusedId(id);\n itemRefs.current.get(id)?.focus();\n };\n\n const onKeyDown = (event: KeyboardEvent<HTMLDivElement>, index: number) => {\n const row = rows[index];\n if (!row) return;\n switch (event.key) {\n case 'ArrowDown':\n focus(rows[index + 1]?.page.id);\n break;\n case 'ArrowUp':\n focus(rows[index - 1]?.page.id);\n break;\n case 'ArrowRight':\n if (row.hasChildren && !row.expanded) toggle(row.page.id, true);\n else if (row.expanded) focus(rows[index + 1]?.page.id);\n break;\n case 'ArrowLeft':\n if (row.expanded) toggle(row.page.id, false);\n else focus(rows.slice(0, index).findLast(candidate => candidate.depth < row.depth)?.page.id);\n break;\n case 'Enter':\n case ' ':\n onSelect(row.page);\n break;\n default:\n return;\n }\n event.preventDefault();\n };\n\n if (rows.length === 0) {\n return <p className=\"px-3 py-2 text-body text-muted-foreground\">No pages yet.</p>;\n }\n\n const ancestorAt: string[] = [];\n return (\n <div\n ref={scroller}\n role=\"tree\"\n aria-label={ariaLabel}\n className=\"min-h-0 overflow-y-auto py-1\"\n onWheel={() => (userScrolled.current = true)}\n onTouchMove={() => (userScrolled.current = true)}\n onPointerDown={() => (userScrolled.current = true)}\n onKeyDown={() => (userScrolled.current = true)}\n >\n {rows.map((row, index) => {\n const selected = row.page.id === selectedPageId;\n ancestorAt[row.depth] = row.page.id;\n // Levels whose last loaded child is this row's subtree end here: offer their next children.\n const nextDepth = rows[index + 1]?.depth ?? -1;\n const closing: Array<{ parentId: string; depth: number }> = [];\n for (let depth = row.depth - 1; depth >= nextDepth; depth--) {\n const parentId = depth < 0 ? KNOWLEDGE_TREE_ROOT : ancestorAt[depth];\n if (parentId !== undefined) closing.push({ parentId, depth: depth + 1 });\n }\n if (row.expanded && rows[index + 1]?.depth !== row.depth + 1)\n closing.unshift({ parentId: row.page.id, depth: row.depth + 1 });\n return (\n <Fragment key={row.page.id}>\n <div\n ref={element => {\n if (element) itemRefs.current.set(row.page.id, element);\n else itemRefs.current.delete(row.page.id);\n }}\n role=\"treeitem\"\n aria-level={row.depth + 1}\n aria-selected={selected}\n aria-expanded={row.hasChildren ? row.expanded : undefined}\n tabIndex={row.page.id === activeId ? 0 : -1}\n onFocus={() => setFocusedId(row.page.id)}\n onKeyDown={event => onKeyDown(event, index)}\n onClick={() => {\n onSelect(row.page);\n // Selecting a page with children opens it too, which loads them in a lazily loaded tree.\n if (row.hasChildren) toggle(row.page.id, true);\n }}\n className={cn(\n 'flex h-8 cursor-pointer items-center gap-2 rounded-md pr-2 text-body-sm text-foreground outline-none focus-visible:bg-fill-subtle',\n selected ? 'bg-fill-hover' : 'hover:bg-fill-subtle',\n )}\n style={{ paddingLeft: `${row.depth * 12 + 4}px` }}\n >\n {row.hasChildren ? (\n <button\n type=\"button\"\n tabIndex={-1}\n aria-label={row.expanded ? `Collapse ${row.page.name}` : `Expand ${row.page.name}`}\n className=\"flex size-3 shrink-0 items-center justify-center text-muted-foreground hover:text-foreground\"\n onClick={event => {\n event.stopPropagation();\n toggle(row.page.id, !row.expanded);\n }}\n >\n <DisclosureChevron direction=\"right\" open={row.expanded} className=\"size-3\" />\n </button>\n ) : (\n <span className=\"size-3 shrink-0\" aria-hidden />\n )}\n <span className=\"flex shrink-0 items-center text-muted-foreground [&>svg]:size-icon-sm\" aria-hidden>\n {scopeSource(row.page)?.icon ? (\n <KnowledgeSourceIcon page={row.page} />\n ) : row.hasChildren ? (\n <IconFolder1 />\n ) : (\n <IconFileText />\n )}\n </span>\n <span className={cn('min-w-0 flex-1 truncate', row.page.isScope && 'font-medium')}>\n {scopeTitle(row.page)}\n </span>\n {row.page.childCount ? (\n <span\n data-testid=\"knowledge-tree-count\"\n aria-label={`${childCountLabel(row.page)} below`}\n className=\"shrink-0 text-caption text-placeholder tabular-nums\"\n >\n {childCountLabel(row.page)}\n </span>\n ) : null}\n {pinned.has(row.page.id) ? (\n <IconPin className=\"size-icon-xs shrink-0 text-badge-amber-indicator\" aria-label=\"Pinned\" />\n ) : null}\n {row.page.isScope && row.page.address && row.page.address !== row.page.name ? (\n <span\n data-testid=\"knowledge-tree-address\"\n className=\"max-w-1/2 min-w-0 truncate text-caption text-muted-foreground\"\n >\n {row.page.address}\n </span>\n ) : null}\n </div>\n {closing.map(({ parentId, depth }) => {\n const more = loadMore?.get(parentId);\n return more ? (\n <button\n key={`more-${parentId}`}\n type=\"button\"\n className=\"flex h-8 w-full items-center text-left text-caption text-muted-foreground hover:text-foreground\"\n style={{ paddingLeft: `${depth * 12 + 42}px` }}\n onClick={more}\n >\n Load more\n </button>\n ) : null;\n })}\n </Fragment>\n );\n })}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAoBA,SAAS,aAAa,SAAkD;CACtE,IAAI;CACJ,KAAK,IAAI,OAAO,SAAS,MAAM,OAAO,KAAK,eAAe;EACxD,MAAM,EAAE,cAAc,iBAAiB,IAAI;EAC3C,IAAI,cAAc,UAAU,cAAc,YAAY,cAAc,WAAW;EAC/E,IAAI,KAAK,eAAe,KAAK,cAAc,OAAO,KAAK,sBAAsB;EAC7E,gBAAgB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AAK,aACR,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD;MACE,eAAY;MACZ,cAAY,GAAGC,uCAAAA,gBAAgB,IAAI,IAAI,EAAE;MACzC,WAAU;MAET,UAAAA,uCAAAA,gBAAgB,IAAI,IAAI;KACrB,CAAA,IACJ;KACH,OAAO,IAAI,IAAI,KAAK,EAAE,IACrB,iBAAA,GAAA,kBAAA,IAAA,CAACC,8BAAAA,SAAD;MAAS,WAAU;MAAmD,cAAW;KAAU,CAAA,IACzF;KACH,IAAI,KAAK,WAAW,IAAI,KAAK,WAAW,IAAI,KAAK,YAAY,IAAI,KAAK,OACrE,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD;MACE,eAAY;MACZ,WAAU;MAET,UAAA,IAAI,KAAK;KACN,CAAA,IACJ;IACD;GACJ,CAAA,GAAA,QAAQ,KAAK,EAAE,UAAU,YAAY;IACpC,MAAM,OAAO,UAAU,IAAI,QAAQ;IACnC,OAAO,OACL,iBAAA,GAAA,kBAAA,IAAA,CAAC,UAAD;KAEE,MAAK;KACL,WAAU;KACV,OAAO,EAAE,aAAa,GAAG,QAAQ,KAAK,GAAG,IAAI;KAC7C,SAAS;KACV,UAAA;IAEO,GAPD,QAAQ,UAOP,IACN;GACN,CAAC,CACO,EAAA,GAvFK,IAAI,KAAK,EAuFd;EAEd,CAAC;CACE,CAAA;AAET"}
@@ -1,4 +1,4 @@
1
- import { scopeTitle } from "../lib/pageAddress.es.js";
1
+ import { scopeSource, scopeTitle } from "../lib/pageAddress.es.js";
2
2
  import { buildPageTree, childCountLabel, pageAncestorIds, visiblePageRows } from "../lib/pageTree.es.js";
3
3
  import { prefersMotion } from "../lib/useLeavingNodes.es.js";
4
4
  import { KnowledgeSourceIcon } from "./KnowledgeSourceIcon.es.js";
@@ -210,7 +210,7 @@ function KnowledgePageTree({ pages, pinnedIds, selectedPageId, onSelect, initial
210
210
  /* @__PURE__ */ jsx("span", {
211
211
  className: "flex shrink-0 items-center text-muted-foreground [&>svg]:size-icon-sm",
212
212
  "aria-hidden": true,
213
- children: row.page.isScope && scopeTitle(row.page) !== row.page.name ? /* @__PURE__ */ jsx(KnowledgeSourceIcon, { page: row.page }) : row.hasChildren ? /* @__PURE__ */ jsx(IconFolder1, {}) : /* @__PURE__ */ jsx(IconFileText, {})
213
+ children: scopeSource(row.page)?.icon ? /* @__PURE__ */ jsx(KnowledgeSourceIcon, { page: row.page }) : row.hasChildren ? /* @__PURE__ */ jsx(IconFolder1, {}) : /* @__PURE__ */ jsx(IconFileText, {})
214
214
  }),
215
215
  /* @__PURE__ */ jsx("span", {
216
216
  className: cn("min-w-0 flex-1 truncate", row.page.isScope && "font-medium"),
@@ -1 +1 @@
1
- {"version":3,"file":"KnowledgePageTree.es.js","names":[],"sources":["../../../../src/domains/knowledge/components/KnowledgePageTree.tsx"],"sourcesContent":["import { Fragment, useEffect, useMemo, useRef, useState } from 'react';\nimport type { KeyboardEvent } from 'react';\n\nimport { scopeTitle } from '../lib/pageAddress';\nimport { buildPageTree, childCountLabel, pageAncestorIds, visiblePageRows } from '../lib/pageTree';\nimport { prefersMotion } from '../lib/useLeavingNodes';\nimport type { KnowledgePagePayload } from '../pageTypes';\nimport { KnowledgeSourceIcon } from './KnowledgeSourceIcon';\n\nimport { DisclosureChevron } from '@/ds/components/DisclosureChevron';\nimport { IconFileText } from '@/ds/icons/central/IconFileText';\nimport { IconFolder1 } from '@/ds/icons/central/IconFolder1';\nimport { IconPin } from '@/ds/icons/central/IconPin';\nimport { cn } from '@/utils/cn';\n\n/**\n * The box of the nearest ancestor (or the element itself) that really scrolls vertically. The tree sets\n * `overflow-y: auto` itself but, as tall as its rows, never overflows; a parent is what scrolls, so a\n * node counts only when its content is taller than it is.\n */\nfunction scrollingBox(element: HTMLElement | null): DOMRect | undefined {\n let overflowing: HTMLElement | undefined;\n for (let node = element; node; node = node.parentElement) {\n const { overflowY } = getComputedStyle(node);\n if (overflowY !== 'auto' && overflowY !== 'scroll' && overflowY !== 'overlay') continue;\n if (node.scrollHeight > node.clientHeight) return node.getBoundingClientRect();\n overflowing ??= node;\n }\n return (overflowing ?? element)?.getBoundingClientRect();\n}\n\n/** Where in the scroller a row focused from elsewhere lands, as a fraction of its height from the top. */\nconst SCROLL_ROW_AT = 1 / 3;\n/** A row between these fractions of the scroller is comfortably in view and is not moved. */\nconst COMFORT_TOP = 0.1;\nconst COMFORT_BOTTOM = 0.7;\n\n/** The key {@link KnowledgePageTree}'s `loadMore` uses for the root level. */\nexport const KNOWLEDGE_TREE_ROOT = '';\n\n/**\n * The Knowledge page tree: scopes and pages nested by parent, siblings in\n * stored order. Selecting a page from elsewhere (graph, search) opens the path\n * to it. Keyboard follows the WAI-ARIA tree pattern: Up/Down move, Right opens\n * or enters, Left closes or goes to the parent, Enter/Space selects.\n *\n * A host that loads the tree a level at a time passes `mayHaveChildren` (so unloaded pages still offer\n * a chevron), listens to `onExpandedChange` to load the opened levels, and passes `loadMore` for\n * levels with more children to fetch. A page's `childCount`, when the server sends one, shows beside\n * its name. Selecting a page with children also opens it.\n */\nexport function KnowledgePageTree({\n pages,\n pinnedIds,\n selectedPageId,\n onSelect,\n initiallyExpanded,\n mayHaveChildren,\n onExpandedChange,\n loadMore,\n 'aria-label': ariaLabel = 'Knowledge pages',\n}: {\n pages: KnowledgePagePayload[];\n pinnedIds?: readonly string[];\n selectedPageId?: string | null;\n onSelect: (page: KnowledgePagePayload) => void;\n /** Ids open on first render; defaults to every root. */\n initiallyExpanded?: string[];\n /** True for a page whose children are not loaded yet, so it can still be opened. */\n mayHaveChildren?: (page: KnowledgePagePayload) => boolean;\n onExpandedChange?: (expanded: ReadonlySet<string>) => void;\n /** Parent id ({@link KNOWLEDGE_TREE_ROOT} for the roots) to a loader for its next children. */\n loadMore?: ReadonlyMap<string, () => void>;\n 'aria-label'?: string;\n}) {\n const roots = useMemo(() => buildPageTree(pages), [pages]);\n const pinned = useMemo(() => new Set(pinnedIds), [pinnedIds]);\n const [expanded, setExpanded] = useState<Set<string>>(\n () => new Set(initiallyExpanded ?? roots.map(root => root.page.id)),\n );\n const [focusedId, setFocusedId] = useState<string | null>(null);\n const itemRefs = useRef(new Map<string, HTMLDivElement>());\n\n // Open the path to a selection once. Later renders with the same selection and path (a refetch, a\n // level loading) leave it alone, so a parent the user collapses over the selection stays collapsed.\n const revealed = useRef<string | null>(null);\n useEffect(() => {\n if (!selectedPageId) {\n // Forget the last reveal, so picking the same page again after a clear opens its path.\n revealed.current = null;\n return;\n }\n const path = pageAncestorIds(pages, selectedPageId);\n const key = [selectedPageId, ...path].join('/');\n if (revealed.current === key) return;\n revealed.current = key;\n setExpanded(current => (path.every(id => current.has(id)) ? current : new Set([...current, ...path])));\n }, [pages, selectedPageId]);\n\n useEffect(() => {\n onExpandedChange?.(expanded);\n }, [expanded, onExpandedChange]);\n\n const rows = useMemo(\n () =>\n visiblePageRows(roots, expanded).map(row =>\n !row.hasChildren && mayHaveChildren?.(row.page) ? { ...row, hasChildren: true } : row,\n ),\n [roots, expanded, mayHaveChildren],\n );\n // Bring the selected row into view when it is selected, as soon as it exists, and again if rows that load\n // later push it out of view (a deep page's levels arrive one after another). Once the user scrolls, presses a key or\n // a pointer in the tree it is left alone. The row goes a third of the way down the scroller, middle-top, not\n // hard against its bottom edge; keyboard focus is not moved.\n const scroller = useRef<HTMLDivElement>(null);\n const scrolledTo = useRef<string | null>(null);\n const userScrolled = useRef(false);\n useEffect(() => {\n if (!selectedPageId) {\n scrolledTo.current = null;\n return;\n }\n const element = itemRefs.current.get(selectedPageId);\n if (!element) return;\n const first = scrolledTo.current !== selectedPageId;\n if (first) {\n scrolledTo.current = selectedPageId;\n userScrolled.current = false;\n } else if (userScrolled.current) return;\n const box = scrollingBox(scroller.current);\n const at = element.getBoundingClientRect();\n if (!first && !box) return;\n if (!first && box && box.height === 0 && at.top >= box.top && at.bottom <= box.bottom) return;\n if (box && box.height > 0) {\n // A row already well inside the scroller stays where it is.\n const inView = at.top >= box.top + box.height * COMFORT_TOP && at.bottom <= box.top + box.height * COMFORT_BOTTOM;\n if (inView) return;\n // Otherwise it lands a third of the way down; the browser clamps this at the top and bottom of the list.\n element.style.scrollMarginTop = `${box.height * SCROLL_ROW_AT}px`;\n }\n element.scrollIntoView?.({ block: 'start', behavior: first && prefersMotion() ? 'smooth' : 'auto' });\n // The margin only steers this scroll; left on, focus() scrolls and a resized pane would keep a stale gap.\n element.style.scrollMarginTop = '';\n }, [rows, selectedPageId]);\n const activeId =\n focusedId && rows.some(row => row.page.id === focusedId)\n ? focusedId\n : (rows.find(row => row.page.id === selectedPageId)?.page.id ?? rows[0]?.page.id);\n\n const toggle = (id: string, open: boolean) =>\n setExpanded(current => {\n if (current.has(id) === open) return current;\n const next = new Set(current);\n if (open) next.add(id);\n else next.delete(id);\n return next;\n });\n\n const focus = (id: string | undefined) => {\n if (!id) return;\n setFocusedId(id);\n itemRefs.current.get(id)?.focus();\n };\n\n const onKeyDown = (event: KeyboardEvent<HTMLDivElement>, index: number) => {\n const row = rows[index];\n if (!row) return;\n switch (event.key) {\n case 'ArrowDown':\n focus(rows[index + 1]?.page.id);\n break;\n case 'ArrowUp':\n focus(rows[index - 1]?.page.id);\n break;\n case 'ArrowRight':\n if (row.hasChildren && !row.expanded) toggle(row.page.id, true);\n else if (row.expanded) focus(rows[index + 1]?.page.id);\n break;\n case 'ArrowLeft':\n if (row.expanded) toggle(row.page.id, false);\n else focus(rows.slice(0, index).findLast(candidate => candidate.depth < row.depth)?.page.id);\n break;\n case 'Enter':\n case ' ':\n onSelect(row.page);\n break;\n default:\n return;\n }\n event.preventDefault();\n };\n\n if (rows.length === 0) {\n return <p className=\"px-3 py-2 text-body text-muted-foreground\">No pages yet.</p>;\n }\n\n const ancestorAt: string[] = [];\n return (\n <div\n ref={scroller}\n role=\"tree\"\n aria-label={ariaLabel}\n className=\"min-h-0 overflow-y-auto py-1\"\n onWheel={() => (userScrolled.current = true)}\n onTouchMove={() => (userScrolled.current = true)}\n onPointerDown={() => (userScrolled.current = true)}\n onKeyDown={() => (userScrolled.current = true)}\n >\n {rows.map((row, index) => {\n const selected = row.page.id === selectedPageId;\n ancestorAt[row.depth] = row.page.id;\n // Levels whose last loaded child is this row's subtree end here: offer their next children.\n const nextDepth = rows[index + 1]?.depth ?? -1;\n const closing: Array<{ parentId: string; depth: number }> = [];\n for (let depth = row.depth - 1; depth >= nextDepth; depth--) {\n const parentId = depth < 0 ? KNOWLEDGE_TREE_ROOT : ancestorAt[depth];\n if (parentId !== undefined) closing.push({ parentId, depth: depth + 1 });\n }\n if (row.expanded && rows[index + 1]?.depth !== row.depth + 1)\n closing.unshift({ parentId: row.page.id, depth: row.depth + 1 });\n return (\n <Fragment key={row.page.id}>\n <div\n ref={element => {\n if (element) itemRefs.current.set(row.page.id, element);\n else itemRefs.current.delete(row.page.id);\n }}\n role=\"treeitem\"\n aria-level={row.depth + 1}\n aria-selected={selected}\n aria-expanded={row.hasChildren ? row.expanded : undefined}\n tabIndex={row.page.id === activeId ? 0 : -1}\n onFocus={() => setFocusedId(row.page.id)}\n onKeyDown={event => onKeyDown(event, index)}\n onClick={() => {\n onSelect(row.page);\n // Selecting a page with children opens it too, which loads them in a lazily loaded tree.\n if (row.hasChildren) toggle(row.page.id, true);\n }}\n className={cn(\n 'flex h-8 cursor-pointer items-center gap-2 rounded-md pr-2 text-body-sm text-foreground outline-none focus-visible:bg-fill-subtle',\n selected ? 'bg-fill-hover' : 'hover:bg-fill-subtle',\n )}\n style={{ paddingLeft: `${row.depth * 12 + 4}px` }}\n >\n {row.hasChildren ? (\n <button\n type=\"button\"\n tabIndex={-1}\n aria-label={row.expanded ? `Collapse ${row.page.name}` : `Expand ${row.page.name}`}\n className=\"flex size-3 shrink-0 items-center justify-center text-muted-foreground hover:text-foreground\"\n onClick={event => {\n event.stopPropagation();\n toggle(row.page.id, !row.expanded);\n }}\n >\n <DisclosureChevron direction=\"right\" open={row.expanded} className=\"size-3\" />\n </button>\n ) : (\n <span className=\"size-3 shrink-0\" aria-hidden />\n )}\n <span className=\"flex shrink-0 items-center text-muted-foreground [&>svg]:size-icon-sm\" aria-hidden>\n {row.page.isScope && scopeTitle(row.page) !== row.page.name ? (\n <KnowledgeSourceIcon page={row.page} />\n ) : row.hasChildren ? (\n <IconFolder1 />\n ) : (\n <IconFileText />\n )}\n </span>\n <span className={cn('min-w-0 flex-1 truncate', row.page.isScope && 'font-medium')}>\n {scopeTitle(row.page)}\n </span>\n {row.page.childCount ? (\n <span\n data-testid=\"knowledge-tree-count\"\n aria-label={`${childCountLabel(row.page)} below`}\n className=\"shrink-0 text-caption text-placeholder tabular-nums\"\n >\n {childCountLabel(row.page)}\n </span>\n ) : null}\n {pinned.has(row.page.id) ? (\n <IconPin className=\"size-icon-xs shrink-0 text-badge-amber-indicator\" aria-label=\"Pinned\" />\n ) : null}\n {row.page.isScope && row.page.address && row.page.address !== row.page.name ? (\n <span\n data-testid=\"knowledge-tree-address\"\n className=\"max-w-1/2 min-w-0 truncate text-caption text-muted-foreground\"\n >\n {row.page.address}\n </span>\n ) : null}\n </div>\n {closing.map(({ parentId, depth }) => {\n const more = loadMore?.get(parentId);\n return more ? (\n <button\n key={`more-${parentId}`}\n type=\"button\"\n className=\"flex h-8 w-full items-center text-left text-caption text-muted-foreground hover:text-foreground\"\n style={{ paddingLeft: `${depth * 12 + 42}px` }}\n onClick={more}\n >\n Load more\n </button>\n ) : null;\n })}\n </Fragment>\n );\n })}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAoBA,SAAS,aAAa,SAAkD;CACtE,IAAI;CACJ,KAAK,IAAI,OAAO,SAAS,MAAM,OAAO,KAAK,eAAe;EACxD,MAAM,EAAE,cAAc,iBAAiB,IAAI;EAC3C,IAAI,cAAc,UAAU,cAAc,YAAY,cAAc,WAAW;EAC/E,IAAI,KAAK,eAAe,KAAK,cAAc,OAAO,KAAK,sBAAsB;EAC7E,gBAAgB;CAClB;CACA,QAAQ,eAAe,QAAA,EAAU,sBAAsB;AACzD;;AAGA,IAAM,gB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ree.es.js","names":[],"sources":["../../../../src/domains/knowledge/components/KnowledgePageTree.tsx"],"sourcesContent":["import { Fragment, useEffect, useMemo, useRef, useState } from 'react';\nimport type { KeyboardEvent } from 'react';\n\nimport { scopeSource, scopeTitle } from '../lib/pageAddress';\nimport { buildPageTree, childCountLabel, pageAncestorIds, visiblePageRows } from '../lib/pageTree';\nimport { prefersMotion } from '../lib/useLeavingNodes';\nimport type { KnowledgePagePayload } from '../pageTypes';\nimport { KnowledgeSourceIcon } from './KnowledgeSourceIcon';\n\nimport { DisclosureChevron } from '@/ds/components/DisclosureChevron';\nimport { IconFileText } from '@/ds/icons/central/IconFileText';\nimport { IconFolder1 } from '@/ds/icons/central/IconFolder1';\nimport { IconPin } from '@/ds/icons/central/IconPin';\nimport { cn } from '@/utils/cn';\n\n/**\n * The box of the nearest ancestor (or the element itself) that really scrolls vertically. The tree sets\n * `overflow-y: auto` itself but, as tall as its rows, never overflows; a parent is what scrolls, so a\n * node counts only when its content is taller than it is.\n */\nfunction scrollingBox(element: HTMLElement | null): DOMRect | undefined {\n let overflowing: HTMLElement | undefined;\n for (let node = element; node; node = node.parentElement) {\n const { overflowY } = getComputedStyle(node);\n if (overflowY !== 'auto' && overflowY !== 'scroll' && overflowY !== 'overlay') continue;\n if (node.scrollHeight > node.clientHeight) return node.getBoundingClientRect();\n overflowing ??= node;\n }\n return (overflowing ?? element)?.getBoundingClientRect();\n}\n\n/** Where in the scroller a row focused from elsewhere lands, as a fraction of its height from the top. */\nconst SCROLL_ROW_AT = 1 / 3;\n/** A row between these fractions of the scroller is comfortably in view and is not moved. */\nconst COMFORT_TOP = 0.1;\nconst COMFORT_BOTTOM = 0.7;\n\n/** The key {@link KnowledgePageTree}'s `loadMore` uses for the root level. */\nexport const KNOWLEDGE_TREE_ROOT = '';\n\n/**\n * The Knowledge page tree: scopes and pages nested by parent, siblings in\n * stored order. Selecting a page from elsewhere (graph, search) opens the path\n * to it. Keyboard follows the WAI-ARIA tree pattern: Up/Down move, Right opens\n * or enters, Left closes or goes to the parent, Enter/Space selects.\n *\n * A host that loads the tree a level at a time passes `mayHaveChildren` (so unloaded pages still offer\n * a chevron), listens to `onExpandedChange` to load the opened levels, and passes `loadMore` for\n * levels with more children to fetch. A page's `childCount`, when the server sends one, shows beside\n * its name. Selecting a page with children also opens it.\n */\nexport function KnowledgePageTree({\n pages,\n pinnedIds,\n selectedPageId,\n onSelect,\n initiallyExpanded,\n mayHaveChildren,\n onExpandedChange,\n loadMore,\n 'aria-label': ariaLabel = 'Knowledge pages',\n}: {\n pages: KnowledgePagePayload[];\n pinnedIds?: readonly string[];\n selectedPageId?: string | null;\n onSelect: (page: KnowledgePagePayload) => void;\n /** Ids open on first render; defaults to every root. */\n initiallyExpanded?: string[];\n /** True for a page whose children are not loaded yet, so it can still be opened. */\n mayHaveChildren?: (page: KnowledgePagePayload) => boolean;\n onExpandedChange?: (expanded: ReadonlySet<string>) => void;\n /** Parent id ({@link KNOWLEDGE_TREE_ROOT} for the roots) to a loader for its next children. */\n loadMore?: ReadonlyMap<string, () => void>;\n 'aria-label'?: string;\n}) {\n const roots = useMemo(() => buildPageTree(pages), [pages]);\n const pinned = useMemo(() => new Set(pinnedIds), [pinnedIds]);\n const [expanded, setExpanded] = useState<Set<string>>(\n () => new Set(initiallyExpanded ?? roots.map(root => root.page.id)),\n );\n const [focusedId, setFocusedId] = useState<string | null>(null);\n const itemRefs = useRef(new Map<string, HTMLDivElement>());\n\n // Open the path to a selection once. Later renders with the same selection and path (a refetch, a\n // level loading) leave it alone, so a parent the user collapses over the selection stays collapsed.\n const revealed = useRef<string | null>(null);\n useEffect(() => {\n if (!selectedPageId) {\n // Forget the last reveal, so picking the same page again after a clear opens its path.\n revealed.current = null;\n return;\n }\n const path = pageAncestorIds(pages, selectedPageId);\n const key = [selectedPageId, ...path].join('/');\n if (revealed.current === key) return;\n revealed.current = key;\n setExpanded(current => (path.every(id => current.has(id)) ? current : new Set([...current, ...path])));\n }, [pages, selectedPageId]);\n\n useEffect(() => {\n onExpandedChange?.(expanded);\n }, [expanded, onExpandedChange]);\n\n const rows = useMemo(\n () =>\n visiblePageRows(roots, expanded).map(row =>\n !row.hasChildren && mayHaveChildren?.(row.page) ? { ...row, hasChildren: true } : row,\n ),\n [roots, expanded, mayHaveChildren],\n );\n // Bring the selected row into view when it is selected, as soon as it exists, and again if rows that load\n // later push it out of view (a deep page's levels arrive one after another). Once the user scrolls, presses a key or\n // a pointer in the tree it is left alone. The row goes a third of the way down the scroller, middle-top, not\n // hard against its bottom edge; keyboard focus is not moved.\n const scroller = useRef<HTMLDivElement>(null);\n const scrolledTo = useRef<string | null>(null);\n const userScrolled = useRef(false);\n useEffect(() => {\n if (!selectedPageId) {\n scrolledTo.current = null;\n return;\n }\n const element = itemRefs.current.get(selectedPageId);\n if (!element) return;\n const first = scrolledTo.current !== selectedPageId;\n if (first) {\n scrolledTo.current = selectedPageId;\n userScrolled.current = false;\n } else if (userScrolled.current) return;\n const box = scrollingBox(scroller.current);\n const at = element.getBoundingClientRect();\n if (!first && !box) return;\n if (!first && box && box.height === 0 && at.top >= box.top && at.bottom <= box.bottom) return;\n if (box && box.height > 0) {\n // A row already well inside the scroller stays where it is.\n const inView = at.top >= box.top + box.height * COMFORT_TOP && at.bottom <= box.top + box.height * COMFORT_BOTTOM;\n if (inView) return;\n // Otherwise it lands a third of the way down; the browser clamps this at the top and bottom of the list.\n element.style.scrollMarginTop = `${box.height * SCROLL_ROW_AT}px`;\n }\n element.scrollIntoView?.({ block: 'start', behavior: first && prefersMotion() ? 'smooth' : 'auto' });\n // The margin only steers this scroll; left on, focus() scrolls and a resized pane would keep a stale gap.\n element.style.scrollMarginTop = '';\n }, [rows, selectedPageId]);\n const activeId =\n focusedId && rows.some(row => row.page.id === focusedId)\n ? focusedId\n : (rows.find(row => row.page.id === selectedPageId)?.page.id ?? rows[0]?.page.id);\n\n const toggle = (id: string, open: boolean) =>\n setExpanded(current => {\n if (current.has(id) === open) return current;\n const next = new Set(current);\n if (open) next.add(id);\n else next.delete(id);\n return next;\n });\n\n const focus = (id: string | undefined) => {\n if (!id) return;\n setFocusedId(id);\n itemRefs.current.get(id)?.focus();\n };\n\n const onKeyDown = (event: KeyboardEvent<HTMLDivElement>, index: number) => {\n const row = rows[index];\n if (!row) return;\n switch (event.key) {\n case 'ArrowDown':\n focus(rows[index + 1]?.page.id);\n break;\n case 'ArrowUp':\n focus(rows[index - 1]?.page.id);\n break;\n case 'ArrowRight':\n if (row.hasChildren && !row.expanded) toggle(row.page.id, true);\n else if (row.expanded) focus(rows[index + 1]?.page.id);\n break;\n case 'ArrowLeft':\n if (row.expanded) toggle(row.page.id, false);\n else focus(rows.slice(0, index).findLast(candidate => candidate.depth < row.depth)?.page.id);\n break;\n case 'Enter':\n case ' ':\n onSelect(row.page);\n break;\n default:\n return;\n }\n event.preventDefault();\n };\n\n if (rows.length === 0) {\n return <p className=\"px-3 py-2 text-body text-muted-foreground\">No pages yet.</p>;\n }\n\n const ancestorAt: string[] = [];\n return (\n <div\n ref={scroller}\n role=\"tree\"\n aria-label={ariaLabel}\n className=\"min-h-0 overflow-y-auto py-1\"\n onWheel={() => (userScrolled.current = true)}\n onTouchMove={() => (userScrolled.current = true)}\n onPointerDown={() => (userScrolled.current = true)}\n onKeyDown={() => (userScrolled.current = true)}\n >\n {rows.map((row, index) => {\n const selected = row.page.id === selectedPageId;\n ancestorAt[row.depth] = row.page.id;\n // Levels whose last loaded child is this row's subtree end here: offer their next children.\n const nextDepth = rows[index + 1]?.depth ?? -1;\n const closing: Array<{ parentId: string; depth: number }> = [];\n for (let depth = row.depth - 1; depth >= nextDepth; depth--) {\n const parentId = depth < 0 ? KNOWLEDGE_TREE_ROOT : ancestorAt[depth];\n if (parentId !== undefined) closing.push({ parentId, depth: depth + 1 });\n }\n if (row.expanded && rows[index + 1]?.depth !== row.depth + 1)\n closing.unshift({ parentId: row.page.id, depth: row.depth + 1 });\n return (\n <Fragment key={row.page.id}>\n <div\n ref={element => {\n if (element) itemRefs.current.set(row.page.id, element);\n else itemRefs.current.delete(row.page.id);\n }}\n role=\"treeitem\"\n aria-level={row.depth + 1}\n aria-selected={selected}\n aria-expanded={row.hasChildren ? row.expanded : undefined}\n tabIndex={row.page.id === activeId ? 0 : -1}\n onFocus={() => setFocusedId(row.page.id)}\n onKeyDown={event => onKeyDown(event, index)}\n onClick={() => {\n onSelect(row.page);\n // Selecting a page with children opens it too, which loads them in a lazily loaded tree.\n if (row.hasChildren) toggle(row.page.id, true);\n }}\n className={cn(\n 'flex h-8 cursor-pointer items-center gap-2 rounded-md pr-2 text-body-sm text-foreground outline-none focus-visible:bg-fill-subtle',\n selected ? 'bg-fill-hover' : 'hover:bg-fill-subtle',\n )}\n style={{ paddingLeft: `${row.depth * 12 + 4}px` }}\n >\n {row.hasChildren ? (\n <button\n type=\"button\"\n tabIndex={-1}\n aria-label={row.expanded ? `Collapse ${row.page.name}` : `Expand ${row.page.name}`}\n className=\"flex size-3 shrink-0 items-center justify-center text-muted-foreground hover:text-foreground\"\n onClick={event => {\n event.stopPropagation();\n toggle(row.page.id, !row.expanded);\n }}\n >\n <DisclosureChevron direction=\"right\" open={row.expanded} className=\"size-3\" />\n </button>\n ) : (\n <span className=\"size-3 shrink-0\" aria-hidden />\n )}\n <span className=\"flex shrink-0 items-center text-muted-foreground [&>svg]:size-icon-sm\" aria-hidden>\n {scopeSource(row.page)?.icon ? (\n <KnowledgeSourceIcon page={row.page} />\n ) : row.hasChildren ? (\n <IconFolder1 />\n ) : (\n <IconFileText />\n )}\n </span>\n <span className={cn('min-w-0 flex-1 truncate', row.page.isScope && 'font-medium')}>\n {scopeTitle(row.page)}\n </span>\n {row.page.childCount ? (\n <span\n data-testid=\"knowledge-tree-count\"\n aria-label={`${childCountLabel(row.page)} below`}\n className=\"shrink-0 text-caption text-placeholder tabular-nums\"\n >\n {childCountLabel(row.page)}\n </span>\n ) : null}\n {pinned.has(row.page.id) ? (\n <IconPin className=\"size-icon-xs shrink-0 text-badge-amber-indicator\" aria-label=\"Pinned\" />\n ) : null}\n {row.page.isScope && row.page.address && row.page.address !== row.page.name ? (\n <span\n data-testid=\"knowledge-tree-address\"\n className=\"max-w-1/2 min-w-0 truncate text-caption text-muted-foreground\"\n >\n {row.page.address}\n </span>\n ) : null}\n </div>\n {closing.map(({ parentId, depth }) => {\n const more = loadMore?.get(parentId);\n return more ? (\n <button\n key={`more-${parentId}`}\n type=\"button\"\n className=\"flex h-8 w-full items-center text-left text-caption text-muted-foreground hover:text-foreground\"\n style={{ paddingLeft: `${depth * 12 + 42}px` }}\n onClick={more}\n >\n Load more\n </button>\n ) : null;\n })}\n </Fragment>\n );\n })}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAoBA,SAAS,aAAa,SAAkD;CACtE,IAAI;CACJ,KAAK,IAAI,OAAO,SAAS,MAAM,OAAO,KAAK,eAAe;EACxD,MAAM,EAAE,cAAc,iBAAiB,IAAI;EAC3C,IAAI,cAAc,UAAU,cAAc,YAAY,cAAc,WAAW;EAC/E,IAAI,KAAK,eAAe,KAAK,cAAc,OAAO,KAAK,sBAAsB;EAC7E,gBAAgB;CAClB;CACA,QAAQ,eAAe,QAAA,EAAU,sBAAsB;AACzD;;AAGA,IAAM,gBAAgB,IAAI;;AAE1B,IAAM,cAAc;AACpB,IAAM,iBAAiB;;AAGvB,IAAa,sBAAsB;;;;;;;;;;;;AAanC,SAAgB,kBAAkB,EAChC,OACA,WACA,gBACA,UACA,mBACA,iBACA,kBACA,UACA,cAAc,YAAY,qBAczB;CACD,MAAM,QAAQ,cAAc,cAAc,KAAK,GAAG,CAAC,KAAK,CAAC;CACzD,MAAM,SAAS,cAAc,IAAI,IAAI,SAAS,GAAG,CAAC,SAAS,CAAC;CAC5D,MAAM,CAAC,UAAU,eAAe,eACxB,IAAI,IAAI,qBAAqB,MAAM,KAAI,SAAQ,KAAK,KAAK,EAAE,CAAC,CACpE;CACA,MAAM,CAAC,WAAW,gBAAgB,SAAwB,IAAI;CAC9D,M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aACR,oBAAC,QAAD;MACE,eAAY;MACZ,cAAY,GAAG,gBAAgB,IAAI,IAAI,EAAE;MACzC,WAAU;MAET,UAAA,gBAAgB,IAAI,IAAI;KACrB,CAAA,IACJ;KACH,OAAO,IAAI,IAAI,KAAK,EAAE,IACrB,oBAAC,SAAD;MAAS,WAAU;MAAmD,cAAW;KAAU,CAAA,IACzF;KACH,IAAI,KAAK,WAAW,IAAI,KAAK,WAAW,IAAI,KAAK,YAAY,IAAI,KAAK,OACrE,oBAAC,QAAD;MACE,eAAY;MACZ,WAAU;MAET,UAAA,IAAI,KAAK;KACN,CAAA,IACJ;IACD;GACJ,CAAA,GAAA,QAAQ,KAAK,EAAE,UAAU,YAAY;IACpC,MAAM,OAAO,UAAU,IAAI,QAAQ;IACnC,OAAO,OACL,oBAAC,UAAD;KAEE,MAAK;KACL,WAAU;KACV,OAAO,EAAE,aAAa,GAAG,QAAQ,KAAK,GAAG,IAAI;KAC7C,SAAS;KACV,UAAA;IAEO,GAPD,QAAQ,UAOP,IACN;GACN,CAAC,CACO,EAAA,GAvFK,IAAI,KAAK,EAuFd;EAEd,CAAC;CACE,CAAA;AAET"}
@@ -38,16 +38,31 @@ var SOURCES = {
38
38
  icon: require_icons_GoogleIcon.GoogleIcon
39
39
  }
40
40
  };
41
- /** The source an imported scope came from, read from its address prefix (`linear:…`). */
41
+ function importerRootKey(page) {
42
+ return !page.isScope && page.parentId === page.scopeId ? page.key : void 0;
43
+ }
44
+ /**
45
+ * The source imported pages came from: an importer's own scope (`linear:…`), or the page an importer
46
+ * writes its pages under, directly inside the organization scope and keyed by its source (`notion`).
47
+ */
42
48
  function scopeSource(page) {
43
- if (!page.isScope || !page.address) return void 0;
44
- const prefix = page.address.slice(0, page.address.indexOf(":"));
45
- return Object.hasOwn(SOURCES, prefix) ? SOURCES[prefix] : void 0;
49
+ const key = page.isScope && page.address ? page.address.slice(0, page.address.indexOf(":")) : importerRootKey(page);
50
+ return key && Object.hasOwn(SOURCES, key) ? SOURCES[key] : void 0;
46
51
  }
47
52
  /** A scope's readable name: an imported scope named only by its address reads as its source, e.g. "Linear". */
53
+ var SCOPE_KINDS = /* @__PURE__ */ new Map([
54
+ ["org", "Organization"],
55
+ ["project", "Project"],
56
+ ["user", "User"],
57
+ ["agent", "Agent"],
58
+ ["team", "Team"]
59
+ ]);
48
60
  function scopeTitle(page) {
49
- const source = scopeSource(page);
50
- return source && page.name === page.address ? source.label : page.name;
61
+ const importerKey = importerRootKey(page);
62
+ if (importerKey && page.name === importerKey) return scopeSource(page)?.label ?? page.name;
63
+ if (!page.address || page.name !== page.address) return page.name;
64
+ const kind = page.address.slice(0, page.address.indexOf(":"));
65
+ return scopeSource(page)?.label ?? SCOPE_KINDS.get(kind) ?? page.name;
51
66
  }
52
67
  /** The page's place from its root scope down, through the pages the graph holds. */
53
68
  function pagePath(page, byId) {
@@ -1 +1 @@
1
- {"version":3,"file":"pageAddress.cjs.js","names":["LinearIcon","NotionIcon","ConfluenceIcon","ZendeskIcon","GithubIcon","SlackIcon","GoogleIcon"],"sources":["../../../../src/domains/knowledge/lib/pageAddress.ts"],"sourcesContent":["import type { ComponentType, SVGProps } from 'react';\n\nimport type { KnowledgePagePayload } from '../pageTypes';\n\nimport { ConfluenceIcon, GithubIcon, GoogleIcon, LinearIcon, NotionIcon, SlackIcon, ZendeskIcon } from '@/ds/icons';\n\ntype KnowledgeSource = { label: string; icon?: ComponentType<SVGProps<SVGSVGElement>> };\n\nconst SOURCES: Record<string, KnowledgeSource> = {\n linear: { label: 'Linear', icon: LinearIcon },\n notion: { label: 'Notion', icon: NotionIcon },\n confluence: { label: 'Confluence', icon: ConfluenceIcon },\n zendesk: { label: 'Zendesk', icon: ZendeskIcon },\n fireflies: { label: 'Fireflies' },\n github: { label: 'GitHub', icon: GithubIcon },\n slack: { label: 'Slack', icon: SlackIcon },\n google: { label: 'Google', icon: GoogleIcon },\n};\n\n/** The source an imported scope came from, read from its address prefix (`linear:…`). */\nexport function scopeSource(page: KnowledgePagePayload) {\n if (!page.isScope || !page.address) return undefined;\n const prefix = page.address.slice(0, page.address.indexOf(':'));\n return Object.hasOwn(SOURCES, prefix) ? SOURCES[prefix] : undefined;\n}\n\n/** A scope's readable name: an imported scope named only by its address reads as its source, e.g. \"Linear\". */\nexport function scopeTitle(page: KnowledgePagePayload): string {\n const source = scopeSource(page);\n return source && page.name === page.address ? source.label : page.name;\n}\n\n/** The page's place from its root scope down, through the pages the graph holds. */\nexport function pagePath(page: KnowledgePagePayload, byId: ReadonlyMap<string, KnowledgePagePayload>): string {\n const names: string[] = [];\n const seen = new Set<string>();\n for (let up = page.parentId ? byId.get(page.parentId) : undefined; up && !seen.has(up.id);) {\n seen.add(up.id);\n names.unshift(up.isScope && up.address ? up.address : up.name);\n up = up.parentId ? byId.get(up.parentId) : undefined;\n }\n return names.join(' › ');\n}\n\n/** How the page is addressed: its scope's address, then the keys down to it. Scopes are just their address. */\nexport function pageRef(\n page: KnowledgePagePayload,\n byId: ReadonlyMap<string, KnowledgePagePayload>,\n): string | undefined {\n if (page.isScope) return page.address;\n const keys: string[] = [];\n const seen = new Set<string>();\n for (\n let at: KnowledgePagePayload | undefined = page;\n at && !seen.has(at.id);\n at = at.parentId ? byId.get(at.parentId) : undefined\n ) {\n seen.add(at.id);\n if (at.isScope) return at.address ? `${at.address}#${keys.reverse().join('/')}` : undefined;\n if (!at.key) return undefined;\n keys.push(at.key);\n }\n return undefined;\n}\n"],"mappings":";;;;;;;;;AAQA,IAAM,UAA2C;CAC/C,QAAQ;EAAE,OAAO;EAAU,MAAMA,yBAAAA;CAAW;CAC5C,QAAQ;EAAE,OAAO;EAAU,MAAMC,yBAAAA;CAAW;CAC5C,YAAY;EAAE,OAAO;EAAc,MAAMC,6BAAAA;CAAe;CACxD,SAAS;EAAE,OAAO;EAAW,MAAMC,0BAAAA;CAAY;CAC/C,WAAW,EAAE,OAAO,YAAY;CAChC,QAAQ;EAAE,OAAO;EAAU,MAAMC,yBAAAA;CAAW;CAC5C,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Q,GAAG,KAAK,QAAQ,CAAC,CAAC,KAAK,GAAG,MAAM,KAAA;EAClF,IAAI,CAAC,GAAG,KAAK,OAAO,KAAA;EACpB,KAAK,KAAK,GAAG,GAAG;CAClB;AAEF"}
1
+ {"version":3,"file":"pageAddress.cjs.js","names":["LinearIcon","NotionIcon","ConfluenceIcon","ZendeskIcon","GithubIcon","SlackIcon","GoogleIcon"],"sources":["../../../../src/domains/knowledge/lib/pageAddress.ts"],"sourcesContent":["import type { ComponentType, SVGProps } from 'react';\n\nimport type { KnowledgePagePayload } from '../pageTypes';\n\nimport { ConfluenceIcon, GithubIcon, GoogleIcon, LinearIcon, NotionIcon, SlackIcon, ZendeskIcon } from '@/ds/icons';\n\ntype KnowledgeSource = { label: string; icon?: ComponentType<SVGProps<SVGSVGElement>> };\n\nconst SOURCES: Record<string, KnowledgeSource> = {\n linear: { label: 'Linear', icon: LinearIcon },\n notion: { label: 'Notion', icon: NotionIcon },\n confluence: { label: 'Confluence', icon: ConfluenceIcon },\n zendesk: { label: 'Zendesk', icon: ZendeskIcon },\n fireflies: { label: 'Fireflies' },\n github: { label: 'GitHub', icon: GithubIcon },\n slack: { label: 'Slack', icon: SlackIcon },\n google: { label: 'Google', icon: GoogleIcon },\n};\n\nfunction importerRootKey(page: KnowledgePagePayload) {\n return !page.isScope && page.parentId === page.scopeId ? page.key : undefined;\n}\n\n/**\n * The source imported pages came from: an importer's own scope (`linear:…`), or the page an importer\n * writes its pages under, directly inside the organization scope and keyed by its source (`notion`).\n */\nexport function scopeSource(page: KnowledgePagePayload) {\n const key = page.isScope && page.address ? page.address.slice(0, page.address.indexOf(':')) : importerRootKey(page);\n return key && Object.hasOwn(SOURCES, key) ? SOURCES[key] : undefined;\n}\n\n/** A scope's readable name: an imported scope named only by its address reads as its source, e.g. \"Linear\". */\nconst SCOPE_KINDS = new Map([\n ['org', 'Organization'],\n ['project', 'Project'],\n ['user', 'User'],\n ['agent', 'Agent'],\n ['team', 'Team'],\n]);\n\nexport function scopeTitle(page: KnowledgePagePayload): string {\n const importerKey = importerRootKey(page);\n if (importerKey && page.name === importerKey) return scopeSource(page)?.label ?? page.name;\n if (!page.address || page.name !== page.address) return page.name;\n const kind = page.address.slice(0, page.address.indexOf(':'));\n return scopeSource(page)?.label ?? SCOPE_KINDS.get(kind) ?? page.name;\n}\n\n/** The page's place from its root scope down, through the pages the graph holds. */\nexport function pagePath(page: KnowledgePagePayload, byId: ReadonlyMap<string, KnowledgePagePayload>): string {\n const names: string[] = [];\n const seen = new Set<string>();\n for (let up = page.parentId ? byId.get(page.parentId) : undefined; up && !seen.has(up.id);) {\n seen.add(up.id);\n names.unshift(up.isScope && up.address ? up.address : up.name);\n up = up.parentId ? byId.get(up.parentId) : undefined;\n }\n return names.join(' › ');\n}\n\n/** How the page is addressed: its scope's address, then the keys down to it. Scopes are just their address. */\nexport function pageRef(\n page: KnowledgePagePayload,\n byId: ReadonlyMap<string, KnowledgePagePayload>,\n): string | undefined {\n if (page.isScope) return page.address;\n const keys: string[] = [];\n const seen = new Set<string>();\n for (\n let at: KnowledgePagePayload | undefined = page;\n at && !seen.has(at.id);\n at = at.parentId ? byId.get(at.parentId) : undefined\n ) {\n seen.add(at.id);\n if (at.isScope) return at.address ? `${at.address}#${keys.reverse().join('/')}` : undefined;\n if (!at.key) return undefined;\n keys.push(at.key);\n }\n return undefined;\n}\n"],"mappings":";;;;;;;;;AAQA,IAAM,UAA2C;CAC/C,QAAQ;EAAE,OAAO;EAAU,MAAMA,yBAAAA;CAAW;CAC5C,QAAQ;EAAE,OAAO;EAAU,MAAMC,yBAAAA;CAAW;CAC5C,YAAY;EAAE,OAAO;EAAc,MAAMC,6BAAAA;CAAe;CACxD,SAAS;EAAE,OAAO;EAAW,MAAMC,0BAAAA;CAAY;CAC/C,WAAW,EAAE,OAAO,YAAY;CAChC,QAAQ;EAAE,OAAO;EAAU,MAAMC,yBAAAA;CAAW;CAC5C,OAAO;EAAE,OAAO;EAAS,MAAMC,wBAAAA;CAA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I;EAC7D,KAAK,GAAG,WAAW,KAAK,IAAI,GAAG,QAAQ,IAAI,KAAA;CAC7C;CACA,OAAO,MAAM,KAAK,KAAK;AACzB;;AAGA,SAAgB,QACd,MACA,MACoB;CACpB,IAAI,KAAK,SAAS,OAAO,KAAK;CAC9B,MAAM,OAAiB,CAAC;CACxB,MAAM,uBAAO,IAAI,IAAY;CAC7B,KACE,IAAI,KAAuC,MAC3C,MAAM,CAAC,KAAK,IAAI,GAAG,EAAE,GACrB,KAAK,GAAG,WAAW,KAAK,IAAI,GAAG,QAAQ,IAAI,KAAA,GAC3C;EACA,KAAK,IAAI,GAAG,EAAE;EACd,IAAI,GAAG,SAAS,OAAO,GAAG,UAAU,GAAG,GAAG,QAAQ,GAAG,KAAK,QAAQ,CAAC,CAAC,KAAK,GAAG,MAAM,KAAA;EAClF,IAAI,CAAC,GAAG,KAAK,OAAO,KAAA;EACpB,KAAK,KAAK,GAAG,GAAG;CAClB;AAEF"}
@@ -37,16 +37,31 @@ var SOURCES = {
37
37
  icon: GoogleIcon
38
38
  }
39
39
  };
40
- /** The source an imported scope came from, read from its address prefix (`linear:…`). */
40
+ function importerRootKey(page) {
41
+ return !page.isScope && page.parentId === page.scopeId ? page.key : void 0;
42
+ }
43
+ /**
44
+ * The source imported pages came from: an importer's own scope (`linear:…`), or the page an importer
45
+ * writes its pages under, directly inside the organization scope and keyed by its source (`notion`).
46
+ */
41
47
  function scopeSource(page) {
42
- if (!page.isScope || !page.address) return void 0;
43
- const prefix = page.address.slice(0, page.address.indexOf(":"));
44
- return Object.hasOwn(SOURCES, prefix) ? SOURCES[prefix] : void 0;
48
+ const key = page.isScope && page.address ? page.address.slice(0, page.address.indexOf(":")) : importerRootKey(page);
49
+ return key && Object.hasOwn(SOURCES, key) ? SOURCES[key] : void 0;
45
50
  }
46
51
  /** A scope's readable name: an imported scope named only by its address reads as its source, e.g. "Linear". */
52
+ var SCOPE_KINDS = /* @__PURE__ */ new Map([
53
+ ["org", "Organization"],
54
+ ["project", "Project"],
55
+ ["user", "User"],
56
+ ["agent", "Agent"],
57
+ ["team", "Team"]
58
+ ]);
47
59
  function scopeTitle(page) {
48
- const source = scopeSource(page);
49
- return source && page.name === page.address ? source.label : page.name;
60
+ const importerKey = importerRootKey(page);
61
+ if (importerKey && page.name === importerKey) return scopeSource(page)?.label ?? page.name;
62
+ if (!page.address || page.name !== page.address) return page.name;
63
+ const kind = page.address.slice(0, page.address.indexOf(":"));
64
+ return scopeSource(page)?.label ?? SCOPE_KINDS.get(kind) ?? page.name;
50
65
  }
51
66
  /** The page's place from its root scope down, through the pages the graph holds. */
52
67
  function pagePath(page, byId) {
@@ -1 +1 @@
1
- {"version":3,"file":"pageAddress.es.js","names":[],"sources":["../../../../src/domains/knowledge/lib/pageAddress.ts"],"sourcesContent":["import type { ComponentType, SVGProps } from 'react';\n\nimport type { KnowledgePagePayload } from '../pageTypes';\n\nimport { ConfluenceIcon, GithubIcon, GoogleIcon, LinearIcon, NotionIcon, SlackIcon, ZendeskIcon } from '@/ds/icons';\n\ntype KnowledgeSource = { label: string; icon?: ComponentType<SVGProps<SVGSVGElement>> };\n\nconst SOURCES: Record<string, KnowledgeSource> = {\n linear: { label: 'Linear', icon: LinearIcon },\n notion: { label: 'Notion', icon: NotionIcon },\n confluence: { label: 'Confluence', icon: ConfluenceIcon },\n zendesk: { label: 'Zendesk', icon: ZendeskIcon },\n fireflies: { label: 'Fireflies' },\n github: { label: 'GitHub', icon: GithubIcon },\n slack: { label: 'Slack', icon: SlackIcon },\n google: { label: 'Google', icon: GoogleIcon },\n};\n\n/** The source an imported scope came from, read from its address prefix (`linear:…`). */\nexport function scopeSource(page: KnowledgePagePayload) {\n if (!page.isScope || !page.address) return undefined;\n const prefix = page.address.slice(0, page.address.indexOf(':'));\n return Object.hasOwn(SOURCES, prefix) ? SOURCES[prefix] : undefined;\n}\n\n/** A scope's readable name: an imported scope named only by its address reads as its source, e.g. \"Linear\". */\nexport function scopeTitle(page: KnowledgePagePayload): string {\n const source = scopeSource(page);\n return source && page.name === page.address ? source.label : page.name;\n}\n\n/** The page's place from its root scope down, through the pages the graph holds. */\nexport function pagePath(page: KnowledgePagePayload, byId: ReadonlyMap<string, KnowledgePagePayload>): string {\n const names: string[] = [];\n const seen = new Set<string>();\n for (let up = page.parentId ? byId.get(page.parentId) : undefined; up && !seen.has(up.id);) {\n seen.add(up.id);\n names.unshift(up.isScope && up.address ? up.address : up.name);\n up = up.parentId ? byId.get(up.parentId) : undefined;\n }\n return names.join(' › ');\n}\n\n/** How the page is addressed: its scope's address, then the keys down to it. Scopes are just their address. */\nexport function pageRef(\n page: KnowledgePagePayload,\n byId: ReadonlyMap<string, KnowledgePagePayload>,\n): string | undefined {\n if (page.isScope) return page.address;\n const keys: string[] = [];\n const seen = new Set<string>();\n for (\n let at: KnowledgePagePayload | undefined = page;\n at && !seen.has(at.id);\n at = at.parentId ? byId.get(at.parentId) : undefined\n ) {\n seen.add(at.id);\n if (at.isScope) return at.address ? `${at.address}#${keys.reverse().join('/')}` : undefined;\n if (!at.key) return undefined;\n keys.push(at.key);\n }\n return undefined;\n}\n"],"mappings":";;;;;;;;AAQA,IAAM,UAA2C;CAC/C,QAAQ;EAAE,OAAO;EAAU,MAAM;CAAW;CAC5C,QAAQ;EAAE,OAAO;EAAU,MAAM;CAAW;CAC5C,YAAY;EAAE,OAAO;EAAc,MAAM;CAAe;CACxD,SAAS;EAAE,OAAO;EAAW,MAAM;CAAY;CAC/C,WAAW,EAAE,OAAO,YAAY;CAChC,QAAQ;EAAE,OAAO;EAAU,MAAM;CAAW;CAC5C,OAAO;EAAE,OAAO;EAAS,MAAM;CAAU;CACzC,QAAQ;EAAE,OAAO;EAAU,MAAM;CAAW;AAC9C;;AAGA,SAAgB,YAAY,MAA4B;CACtD,IAAI,CAAC,KAAK,WAAW,CAAC,KAAK,SAAS,OAAO,KAAA;CAC3C,MAAM,SAAS,KAAK,QAAQ,MAAM,GAAG,KAAK,QAAQ,QAAQ,GAAG,CAAC;CAC9D,OAAO,OAAO,OAAO,SAAS,MAAM,IAAI,QAAQ,UAAU,KAAA;AAC5D;;AAGA,SAAgB,WAAW,MAAoC;CAC7D,MAAM,SAAS,YAAY,IAAI;CAC/B,OAAO,UAAU,KAAK,SAAS,KAAK,UAAU,OAAO,QAAQ,KAAK;AACpE;;AAGA,SAAgB,SAAS,MAA4B,MAAyD;CAC5G,MAAM,QAAkB,CAAC;CACzB,MAAM,uBAAO,IAAI,IAAY;CAC7B,KAAK,IAAI,KAAK,KAAK,WAAW,KAAK,IAAI,KAAK,QAAQ,IAAI,KAAA,GAAW,MAAM,CAAC,KAAK,IAAI,GAAG,EAAE,IAAI;EAC1F,KAAK,IAAI,GAAG,EAAE;EACd,MAAM,QAAQ,GAAG,WAAW,GAAG,UAAU,GAAG,UAAU,GAAG,IAAI;EAC7D,KAAK,GAAG,WAAW,KAAK,IAAI,GAAG,QAAQ,IAAI,KAAA;CAC7C;CACA,OAAO,MAAM,KAAK,KAAK;AACzB;;AAGA,SAAgB,QACd,MACA,MACoB;CACpB,IAAI,KAAK,SAAS,OAAO,KAAK;CAC9B,MAAM,OAAiB,CAAC;CACxB,MAAM,uBAAO,IAAI,IAAY;CAC7B,KACE,IAAI,KAAuC,MAC3C,MAAM,CAAC,KAAK,IAAI,GAAG,EAAE,GACrB,KAAK,GAAG,WAAW,KAAK,IAAI,GAAG,QAAQ,IAAI,KAAA,GAC3C;EACA,KAAK,IAAI,GAAG,EAAE;EACd,IAAI,GAAG,SAAS,OAAO,GAAG,UAAU,GAAG,GAAG,QAAQ,GAAG,KAAK,QAAQ,CAAC,CAAC,KAAK,GAAG,MAAM,KAAA;EAClF,IAAI,CAAC,GAAG,KAAK,OAAO,KAAA;EACpB,KAAK,KAAK,GAAG,GAAG;CAClB;AAEF"}
1
+ {"version":3,"file":"pageAddress.es.js","names":[],"sources":["../../../../src/domains/knowledge/lib/pageAddress.ts"],"sourcesContent":["import type { ComponentType, SVGProps } from 'react';\n\nimport type { KnowledgePagePayload } from '../pageTypes';\n\nimport { ConfluenceIcon, GithubIcon, GoogleIcon, LinearIcon, NotionIcon, SlackIcon, ZendeskIcon } from '@/ds/icons';\n\ntype KnowledgeSource = { label: string; icon?: ComponentType<SVGProps<SVGSVGElement>> };\n\nconst SOURCES: Record<string, KnowledgeSource> = {\n linear: { label: 'Linear', icon: LinearIcon },\n notion: { label: 'Notion', icon: NotionIcon },\n confluence: { label: 'Confluence', icon: ConfluenceIcon },\n zendesk: { label: 'Zendesk', icon: ZendeskIcon },\n fireflies: { label: 'Fireflies' },\n github: { label: 'GitHub', icon: GithubIcon },\n slack: { label: 'Slack', icon: SlackIcon },\n google: { label: 'Google', icon: GoogleIcon },\n};\n\nfunction importerRootKey(page: KnowledgePagePayload) {\n return !page.isScope && page.parentId === page.scopeId ? page.key : undefined;\n}\n\n/**\n * The source imported pages came from: an importer's own scope (`linear:…`), or the page an importer\n * writes its pages under, directly inside the organization scope and keyed by its source (`notion`).\n */\nexport function scopeSource(page: KnowledgePagePayload) {\n const key = page.isScope && page.address ? page.address.slice(0, page.address.indexOf(':')) : importerRootKey(page);\n return key && Object.hasOwn(SOURCES, key) ? SOURCES[key] : undefined;\n}\n\n/** A scope's readable name: an imported scope named only by its address reads as its source, e.g. \"Linear\". */\nconst SCOPE_KINDS = new Map([\n ['org', 'Organization'],\n ['project', 'Project'],\n ['user', 'User'],\n ['agent', 'Agent'],\n ['team', 'Team'],\n]);\n\nexport function scopeTitle(page: KnowledgePagePayload): string {\n const importerKey = importerRootKey(page);\n if (importerKey && page.name === importerKey) return scopeSource(page)?.label ?? page.name;\n if (!page.address || page.name !== page.address) return page.name;\n const kind = page.address.slice(0, page.address.indexOf(':'));\n return scopeSource(page)?.label ?? SCOPE_KINDS.get(kind) ?? page.name;\n}\n\n/** The page's place from its root scope down, through the pages the graph holds. */\nexport function pagePath(page: KnowledgePagePayload, byId: ReadonlyMap<string, KnowledgePagePayload>): string {\n const names: string[] = [];\n const seen = new Set<string>();\n for (let up = page.parentId ? byId.get(page.parentId) : undefined; up && !seen.has(up.id);) {\n seen.add(up.id);\n names.unshift(up.isScope && up.address ? up.address : up.name);\n up = up.parentId ? byId.get(up.parentId) : undefined;\n }\n return names.join(' › ');\n}\n\n/** How the page is addressed: its scope's address, then the keys down to it. Scopes are just their address. */\nexport function pageRef(\n page: KnowledgePagePayload,\n byId: ReadonlyMap<string, KnowledgePagePayload>,\n): string | undefined {\n if (page.isScope) return page.address;\n const keys: string[] = [];\n const seen = new Set<string>();\n for (\n let at: KnowledgePagePayload | undefined = page;\n at && !seen.has(at.id);\n at = at.parentId ? byId.get(at.parentId) : undefined\n ) {\n seen.add(at.id);\n if (at.isScope) return at.address ? `${at.address}#${keys.reverse().join('/')}` : undefined;\n if (!at.key) return undefined;\n keys.push(at.key);\n }\n return undefined;\n}\n"],"mappings":";;;;;;;;AAQA,IAAM,UAA2C;CAC/C,QAAQ;EAAE,OAAO;EAAU,MAAM;CAAW;CAC5C,QAAQ;EAAE,OAAO;EAAU,MAAM;CAAW;CAC5C,YAAY;EAAE,OAAO;EAAc,MAAM;CAAe;CACxD,SAAS;EAAE,OAAO;EAAW,MAAM;CAAY;CAC/C,WAAW,EAAE,OAAO,YAAY;CAChC,QAAQ;EAAE,OAAO;EAAU,MAAM;CAAW;CAC5C,OAAO;EAAE,OAAO;EAAS,MAAM;CAAU;CACzC,QAAQ;EAAE,OAAO;EAAU,MAAM;CAAW;AAC9C;AAEA,SAAS,gBAAgB,MAA4B;CACnD,OAAO,CAAC,KAAK,WAAW,KAAK,aAAa,KAAK,UAAU,KAAK,MAAM,KAAA;AACtE;;;;;AAMA,SAAgB,YAAY,MAA4B;CACtD,MAAM,MAAM,KAAK,WAAW,KAAK,UAAU,KAAK,QAAQ,MAAM,GAAG,KAAK,QAAQ,QAAQ,GAAG,CAAC,IAAI,gBAAgB,IAAI;CAClH,OAAO,OAAO,OAAO,OAAO,SAAS,GAAG,IAAI,QAAQ,OAAO,KAAA;AAC7D;;AAGA,IAAM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,GAAG,SAAS,OAAO,GAAG,UAAU,GAAG,GAAG,QAAQ,GAAG,KAAK,QAAQ,CAAC,CAAC,KAAK,GAAG,MAAM,KAAA;EAClF,IAAI,CAAC,GAAG,KAAK,OAAO,KAAA;EACpB,KAAK,KAAK,GAAG,GAAG;CAClB;AAEF"}
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_domains_auth_components_permission_denied = require("../../auth/components/permission-denied.cjs.js");
3
3
  const require_domains_auth_components_session_expired = require("../../auth/components/session-expired.cjs.js");
4
- const require_EmptyState = require("../../../EmptyState-C5O9fTEq.cjs");
4
+ const require_EmptyState = require("../../../EmptyState-DnW6SNEx.cjs");
5
5
  let react_jsx_runtime = require("react/jsx-runtime");
6
6
  let _mastra_react_hooks_query = require("@mastra/react/hooks/query");
7
7
  // src/domains/logs/components/logs-error-content.tsx
@@ -1,6 +1,6 @@
1
1
  import { PermissionDenied } from "../../auth/components/permission-denied.es.js";
2
2
  import { SessionExpired } from "../../auth/components/session-expired.es.js";
3
- import { n as EmptyState } from "../../../EmptyState-juw2jci2.js";
3
+ import { n as EmptyState } from "../../../EmptyState-DJaZF543.js";
4
4
  import { jsx } from "react/jsx-runtime";
5
5
  import { is401UnauthorizedError, is403ForbiddenError, isObservabilityUnavailableError, isUnsupportedObservabilityOperationError } from "@mastra/react/hooks/query";
6
6
  // src/domains/logs/components/logs-error-content.tsx
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_Button = require("../../../Button-C_tgwxcK.cjs");
3
- const require_EmptyState = require("../../../EmptyState-C5O9fTEq.cjs");
3
+ const require_EmptyState = require("../../../EmptyState-DnW6SNEx.cjs");
4
4
  const require_icons_central_IconSquareArrowTopRight = require("../../../icons/central/IconSquareArrowTopRight.cjs.js");
5
5
  const require_utils_date_format = require("../../../utils/date-format.cjs.js");
6
6
  let react_jsx_runtime = require("react/jsx-runtime");
@@ -1,5 +1,5 @@
1
1
  import { t as Button } from "../../../Button-BcQ4CsoL.js";
2
- import { n as EmptyState } from "../../../EmptyState-juw2jci2.js";
2
+ import { n as EmptyState } from "../../../EmptyState-DJaZF543.js";
3
3
  import { IconSquareArrowTopRight } from "../../../icons/central/IconSquareArrowTopRight.es.js";
4
4
  import { formatDate } from "../../../utils/date-format.es.js";
5
5
  import { jsx } from "react/jsx-runtime";
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_types = require("../../../types-DT1pgDom.cjs");
2
+ const require_types = require("../../../types-CVS7iNs8.cjs");
3
3
  const require_ThemeProvider = require("../../../ThemeProvider-DViLuk6C.cjs");
4
4
  let react = require("react");
5
5
  let react_jsx_runtime = require("react/jsx-runtime");
@@ -1,4 +1,4 @@
1
- import { n as McpError, t as ErrorCode } from "../../../types-Dl74jixe.js";
1
+ import { n as McpError, t as ErrorCode } from "../../../types-D64dArGX.js";
2
2
  import { n as useTheme } from "../../../ThemeProvider-CQdX5j9p.js";
3
3
  import { useCallback, useMemo, useRef, useState } from "react";
4
4
  import { jsx } from "react/jsx-runtime";
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_types = require("../../../types-DT1pgDom.cjs");
2
+ const require_types = require("../../../types-CVS7iNs8.cjs");
3
3
  let react = require("react");
4
4
  let _mastra_react = require("@mastra/react");
5
5
  let _tanstack_react_query = require("@tanstack/react-query");
@@ -1,4 +1,4 @@
1
- import { n as McpError, t as ErrorCode } from "../../../types-Dl74jixe.js";
1
+ import { n as McpError, t as ErrorCode } from "../../../types-D64dArGX.js";
2
2
  import { useCallback } from "react";
3
3
  import { useMastraClient } from "@mastra/react";
4
4
  import { useQueryClient } from "@tanstack/react-query";
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_components_Checkbox = require("../../../components/Checkbox.cjs.js");
3
- const require_EmptyState = require("../../../EmptyState-C5O9fTEq.cjs");
3
+ const require_EmptyState = require("../../../EmptyState-DnW6SNEx.cjs");
4
4
  const require_components_Field = require("../../../components/Field.cjs.js");
5
5
  const require_skeleton_text = require("../../../skeleton-text-Bi4d2-D8.cjs");
6
6
  const require_Txt = require("../../../Txt-_00wWxTd.cjs");
@@ -1,5 +1,5 @@
1
1
  import { Checkbox } from "../../../components/Checkbox.es.js";
2
- import { n as EmptyState } from "../../../EmptyState-juw2jci2.js";
2
+ import { n as EmptyState } from "../../../EmptyState-DJaZF543.js";
3
3
  import { Field, FieldLabel } from "../../../components/Field.es.js";
4
4
  import { n as Skeleton } from "../../../skeleton-text-BPa4Tg4u.js";
5
5
  import { t as Txt } from "../../../Txt-5efBsb2p.js";
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_EmptyState = require("../../../EmptyState-C5O9fTEq.cjs");
2
+ const require_EmptyState = require("../../../EmptyState-DnW6SNEx.cjs");
3
3
  const require_spinner = require("../../../spinner-oS6q4pwx.cjs");
4
4
  const require_Txt = require("../../../Txt-_00wWxTd.cjs");
5
5
  let react_jsx_runtime = require("react/jsx-runtime");
@@ -1,4 +1,4 @@
1
- import { n as EmptyState } from "../../../EmptyState-juw2jci2.js";
1
+ import { n as EmptyState } from "../../../EmptyState-DJaZF543.js";
2
2
  import { t as Spinner } from "../../../spinner-B9ykw74u.js";
3
3
  import { t as Txt } from "../../../Txt-5efBsb2p.js";
4
4
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_data_list = require("../../../data-list-Brb-z6iX.cjs");
3
- const require_EmptyState = require("../../../EmptyState-C5O9fTEq.cjs");
3
+ const require_EmptyState = require("../../../EmptyState-DnW6SNEx.cjs");
4
4
  const require_Metadata = require("../../../Metadata-5GJlO4GU.cjs");
5
5
  const require_MetricsKpiCard = require("../../../MetricsKpiCard-PGMfg5AE.cjs");
6
6
  const require_spinner = require("../../../spinner-oS6q4pwx.cjs");
@@ -1,5 +1,5 @@
1
1
  import { t as DataList } from "../../../data-list-CrOD7X1r.js";
2
- import { n as EmptyState } from "../../../EmptyState-juw2jci2.js";
2
+ import { n as EmptyState } from "../../../EmptyState-DJaZF543.js";
3
3
  import { t as Metadata } from "../../../Metadata-DlVgmRTA.js";
4
4
  import { t as MetricsKpiCard } from "../../../MetricsKpiCard-DmgIgvCg.js";
5
5
  import { t as Spinner } from "../../../spinner-B9ykw74u.js";
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_EmptyState = require("../../../EmptyState-C5O9fTEq.cjs");
2
+ const require_EmptyState = require("../../../EmptyState-DnW6SNEx.cjs");
3
3
  const require_utils_date_format = require("../../../utils/date-format.cjs.js");
4
4
  let react_jsx_runtime = require("react/jsx-runtime");
5
5
  // src/domains/traces/components/no-traces-info.tsx
@@ -1,4 +1,4 @@
1
- import { n as EmptyState } from "../../../EmptyState-juw2jci2.js";
1
+ import { n as EmptyState } from "../../../EmptyState-DJaZF543.js";
2
2
  import { formatDate } from "../../../utils/date-format.es.js";
3
3
  import { jsx } from "react/jsx-runtime";
4
4
  // src/domains/traces/components/no-traces-info.tsx
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_domains_auth_components_permission_denied = require("../../auth/components/permission-denied.cjs.js");
3
3
  const require_domains_auth_components_session_expired = require("../../auth/components/session-expired.cjs.js");
4
- const require_EmptyState = require("../../../EmptyState-C5O9fTEq.cjs");
4
+ const require_EmptyState = require("../../../EmptyState-DnW6SNEx.cjs");
5
5
  const require_errors = require("../../../errors-C4YsnPwI.cjs");
6
6
  let react_jsx_runtime = require("react/jsx-runtime");
7
7
  let _mastra_react_hooks_query = require("@mastra/react/hooks/query");
@@ -1,6 +1,6 @@
1
1
  import { PermissionDenied } from "../../auth/components/permission-denied.es.js";
2
2
  import { SessionExpired } from "../../auth/components/session-expired.es.js";
3
- import { n as EmptyState } from "../../../EmptyState-juw2jci2.js";
3
+ import { n as EmptyState } from "../../../EmptyState-DJaZF543.js";
4
4
  import { t as parseError } from "../../../errors-CHQC35ca.js";
5
5
  import { jsx } from "react/jsx-runtime";
6
6
  import { is401UnauthorizedError, is403ForbiddenError } from "@mastra/react/hooks/query";
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_Button = require("../../../../Button-C_tgwxcK.cjs");
3
- const require_EmptyState = require("../../../../EmptyState-C5O9fTEq.cjs");
3
+ const require_EmptyState = require("../../../../EmptyState-DnW6SNEx.cjs");
4
4
  const require_icons_central_IconSquareArrowTopRight = require("../../../../icons/central/IconSquareArrowTopRight.cjs.js");
5
5
  let react_jsx_runtime = require("react/jsx-runtime");
6
6
  // src/domains/workflows/components/workflows-list/no-workflows-info.tsx
@@ -1,5 +1,5 @@
1
1
  import { t as Button } from "../../../../Button-BcQ4CsoL.js";
2
- import { n as EmptyState } from "../../../../EmptyState-juw2jci2.js";
2
+ import { n as EmptyState } from "../../../../EmptyState-DJaZF543.js";
3
3
  import { IconSquareArrowTopRight } from "../../../../icons/central/IconSquareArrowTopRight.es.js";
4
4
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
5
5
  // src/domains/workflows/components/workflows-list/no-workflows-info.tsx
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_Dialog = require("../../../Dialog-vZiwc-R9.cjs");
3
- const require_EmptyState = require("../../../EmptyState-C5O9fTEq.cjs");
3
+ const require_EmptyState = require("../../../EmptyState-DnW6SNEx.cjs");
4
4
  const require_components_Field = require("../../../components/Field.cjs.js");
5
5
  const require_MarkdownRenderer = require("../../../MarkdownRenderer-Cou0VUzZ.cjs");
6
6
  const require_scroll_area = require("../../../scroll-area-7N9C8DwL.cjs");
@@ -1,5 +1,5 @@
1
1
  import { a as DialogContent, c as DialogHeader, d as DialogTitle, n as DialogBody, o as DialogDescription, p as DialogAction, r as DialogCancel, s as DialogFooter, t as Dialog } from "../../../Dialog-CQ0-jiY3.js";
2
- import { n as EmptyState } from "../../../EmptyState-juw2jci2.js";
2
+ import { n as EmptyState } from "../../../EmptyState-DJaZF543.js";
3
3
  import { Field, FieldLabel } from "../../../components/Field.es.js";
4
4
  import { t as MarkdownRenderer } from "../../../MarkdownRenderer-De9m5Xru.js";
5
5
  import { n as ScrollAreaViewport, t as ScrollArea } from "../../../scroll-area-B3rEr22-.js";
@@ -7,7 +7,7 @@ const require_domains_workspace_components_workspace_context = require("./worksp
7
7
  const require_domains_workspace_components_workspace_create_directory = require("./workspace-create-directory.cjs.js");
8
8
  const require_domains_workspace_components_workspace_search = require("./workspace-search.cjs.js");
9
9
  const require_domains_workspace_components_workspace_tree = require("./workspace-tree.cjs.js");
10
- const require_EmptyState = require("../../../EmptyState-C5O9fTEq.cjs");
10
+ const require_EmptyState = require("../../../EmptyState-DnW6SNEx.cjs");
11
11
  const require_scroll_area = require("../../../scroll-area-7N9C8DwL.cjs");
12
12
  const require_resize_collapsible_panel = require("../../../resize/collapsible-panel.cjs.js");
13
13
  const require_resize_panel_group = require("../../../resize/panel-group.cjs.js");
@@ -6,7 +6,7 @@ import { WorkspaceProvider } from "./workspace-context.es.js";
6
6
  import { WorkspaceCreateDirectory } from "./workspace-create-directory.es.js";
7
7
  import { WorkspaceSearchResults } from "./workspace-search.es.js";
8
8
  import { WorkspaceTree as WorkspaceTree$1 } from "./workspace-tree.es.js";
9
- import { n as EmptyState } from "../../../EmptyState-juw2jci2.js";
9
+ import { n as EmptyState } from "../../../EmptyState-DJaZF543.js";
10
10
  import { t as ScrollArea } from "../../../scroll-area-B3rEr22-.js";
11
11
  import { CollapsiblePanel } from "../../../resize/collapsible-panel.es.js";
12
12
  import { PanelGroup } from "../../../resize/panel-group.es.js";
@@ -2,7 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_domains_workspace_components_use_workspace_context = require("./use-workspace-context.cjs.js");
3
3
  const require_domains_workspace_components_workspace_error = require("./workspace-error.cjs.js");
4
4
  const require_Button = require("../../../Button-C_tgwxcK.cjs");
5
- const require_EmptyState = require("../../../EmptyState-C5O9fTEq.cjs");
5
+ const require_EmptyState = require("../../../EmptyState-DnW6SNEx.cjs");
6
6
  const require_input = require("../../../input-DR9BO7En.cjs");
7
7
  const require_Metadata = require("../../../Metadata-5GJlO4GU.cjs");
8
8
  const require_skeleton_text = require("../../../skeleton-text-Bi4d2-D8.cjs");