@mastra/playground-ui 70.0.0 → 70.0.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{Section-Dk_Vcsi7.cjs → Section-BdO9TFjY.cjs} +2 -2
- package/dist/{Section-Dk_Vcsi7.cjs.map → Section-BdO9TFjY.cjs.map} +1 -1
- package/dist/{Section-D6JJ926q.js → Section-DV2aLnkc.js} +2 -2
- package/dist/{Section-D6JJ926q.js.map → Section-DV2aLnkc.js.map} +1 -1
- package/dist/components/Section.cjs.js +1 -1
- package/dist/components/Section.es.js +1 -1
- package/dist/components/SideDialog.cjs.js +1 -1
- package/dist/components/SideDialog.es.js +1 -1
- package/dist/domains/datasets/components/add-dataset-item-dialog/add-dataset-item-dialog.cjs.js +1 -1
- package/dist/domains/datasets/components/add-dataset-item-dialog/add-dataset-item-dialog.es.js +1 -1
- package/dist/domains/datasets/components/add-dataset-item-dialog/collapsible-settings-row.cjs.js +1 -1
- package/dist/domains/datasets/components/add-dataset-item-dialog/collapsible-settings-row.es.js +1 -1
- package/dist/domains/knowledge/components/KnowledgePageDetail.cjs.js +99 -58
- package/dist/domains/knowledge/components/KnowledgePageDetail.cjs.js.map +1 -1
- package/dist/domains/knowledge/components/KnowledgePageDetail.es.js +99 -58
- package/dist/domains/knowledge/components/KnowledgePageDetail.es.js.map +1 -1
- package/dist/domains/knowledge/components/KnowledgePageExplorer.cjs.js +21 -0
- package/dist/domains/knowledge/components/KnowledgePageExplorer.cjs.js.map +1 -1
- package/dist/domains/knowledge/components/KnowledgePageExplorer.es.js +21 -0
- package/dist/domains/knowledge/components/KnowledgePageExplorer.es.js.map +1 -1
- package/dist/domains/knowledge/components/KnowledgePageTree.cjs.js +1 -1
- package/dist/domains/knowledge/components/KnowledgePageTree.cjs.js.map +1 -1
- package/dist/domains/knowledge/components/KnowledgePageTree.es.js +2 -2
- package/dist/domains/knowledge/components/KnowledgePageTree.es.js.map +1 -1
- package/dist/domains/knowledge/lib/pageAddress.cjs.js +21 -6
- package/dist/domains/knowledge/lib/pageAddress.cjs.js.map +1 -1
- package/dist/domains/knowledge/lib/pageAddress.es.js +21 -6
- package/dist/domains/knowledge/lib/pageAddress.es.js.map +1 -1
- package/dist/domains/mcps/components/mcp-app-viewer.cjs.js +1 -1
- package/dist/domains/mcps/components/mcp-app-viewer.es.js +1 -1
- package/dist/domains/mcps/hooks/use-mcp-app-tool-call.cjs.js +1 -1
- package/dist/domains/mcps/hooks/use-mcp-app-tool-call.es.js +1 -1
- package/dist/new/settings.cjs.js +2 -2
- package/dist/new/settings.es.js +2 -2
- package/dist/{settings-DIrzLcgE.js → settings-B7RMGKgf.js} +31 -15
- package/dist/settings-B7RMGKgf.js.map +1 -0
- package/dist/{settings-5PdsNlhV.cjs → settings-CYKWxfrJ.cjs} +31 -15
- package/dist/settings-CYKWxfrJ.cjs.map +1 -0
- package/dist/{settings-row-C2HTuwjN.js → settings-row-BnlFZSQL.js} +27 -5
- package/dist/settings-row-BnlFZSQL.js.map +1 -0
- package/dist/{settings-row-Dfi4pLnl.cjs → settings-row-Da1HHyBg.cjs} +27 -5
- package/dist/settings-row-Da1HHyBg.cjs.map +1 -0
- package/dist/src/domains/knowledge/components/KnowledgePageDetail.d.ts +11 -1
- package/dist/src/domains/knowledge/lib/pageAddress.d.ts +4 -2
- package/dist/src/ds/new/settings/settings-list.d.ts +16 -2
- package/dist/src/ds/new/settings/settings-row.d.ts +22 -2
- package/dist/style.css +32 -0
- package/dist/{types-DT1pgDom.cjs → types-CVS7iNs8.cjs} +2 -2
- package/dist/{types-DT1pgDom.cjs.map → types-CVS7iNs8.cjs.map} +1 -1
- package/dist/{types-Dl74jixe.js → types-D64dArGX.js} +2 -2
- package/dist/{types-Dl74jixe.js.map → types-D64dArGX.js.map} +1 -1
- package/package.json +7 -7
- package/dist/settings-5PdsNlhV.cjs.map +0 -1
- package/dist/settings-DIrzLcgE.js.map +0 -1
- package/dist/settings-row-C2HTuwjN.js.map +0 -1
- 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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AAD;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
|
+
{"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,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A,IAAA,CAACC,mCAAAA,cAAD,CAAe,CAAA;KAEb,CAAA;KACN,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD;MAAM,WAAWL,cAAAA,GAAG,2BAA2B,IAAI,KAAK,WAAW,aAAa;MAC7E,UAAAM,0CAAAA,WAAW,IAAI,IAAI;KAChB,CAAA;KACL,IAAI,KAAK,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:
|
|
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;E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AG,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.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,I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AAC,aAAD,CAAc,CAAA,IAEd,oBAAC,cAAD,CAAe,CAAA;KAEb,CAAA;KACN,oBAAC,QAAD;MAAM,WAAW,GAAG,2BAA2B,IAAI,KAAK,WAAW,aAAa;MAC7E,UAAA,WAAW,IAAI,IAAI;KAChB,CAAA;KACL,IAAI,KAAK,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
|
-
|
|
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
|
-
|
|
44
|
-
|
|
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
|
|
50
|
-
|
|
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
|
|
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,MA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AAI,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"}
|
|
@@ -37,16 +37,31 @@ var SOURCES = {
|
|
|
37
37
|
icon: GoogleIcon
|
|
38
38
|
}
|
|
39
39
|
};
|
|
40
|
-
|
|
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
|
-
|
|
43
|
-
|
|
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
|
|
49
|
-
|
|
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
|
|
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,W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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,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_types = require("../../../types-
|
|
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-
|
|
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-
|
|
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-
|
|
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";
|
package/dist/new/settings.cjs.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_settings = require("../settings-
|
|
2
|
+
const require_settings = require("../settings-CYKWxfrJ.cjs");
|
|
3
3
|
const require_settings_layout = require("../settings-layout-BxtShpY6.cjs");
|
|
4
|
-
const require_settings_row = require("../settings-row-
|
|
4
|
+
const require_settings_row = require("../settings-row-Da1HHyBg.cjs");
|
|
5
5
|
exports.SettingsContainer = require_settings.SettingsContainer;
|
|
6
6
|
exports.SettingsDescription = require_settings.SettingsDescription;
|
|
7
7
|
exports.SettingsEmptyRow = require_settings.SettingsEmptyRow;
|
package/dist/new/settings.es.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as SettingsListHeader, c as SettingsGroup, d as SettingsContainer, i as SettingsItemIcon, l as SettingsHeader, n as SettingsEmptyRow, o as SettingsNoticeRow, r as SettingsItem, s as SettingsDescription, t as SettingsSkeleton, u as SettingsTitle } from "../settings-
|
|
1
|
+
import { a as SettingsListHeader, c as SettingsGroup, d as SettingsContainer, i as SettingsItemIcon, l as SettingsHeader, n as SettingsEmptyRow, o as SettingsNoticeRow, r as SettingsItem, s as SettingsDescription, t as SettingsSkeleton, u as SettingsTitle } from "../settings-B7RMGKgf.js";
|
|
2
2
|
import { t as SettingsLayout } from "../settings-layout-UPnWI3FZ.js";
|
|
3
|
-
import { n as SettingsRow, t as SettingsFieldsetRow } from "../settings-row-
|
|
3
|
+
import { n as SettingsRow, t as SettingsFieldsetRow } from "../settings-row-BnlFZSQL.js";
|
|
4
4
|
export { SettingsContainer, SettingsDescription, SettingsEmptyRow, SettingsFieldsetRow, SettingsGroup, SettingsHeader, SettingsItem, SettingsItemIcon, SettingsLayout, SettingsListHeader, SettingsNoticeRow, SettingsRow, SettingsSkeleton, SettingsTitle };
|
|
@@ -2,7 +2,7 @@ import { fieldsOnSurface } from "./primitives/raised-surface.es.js";
|
|
|
2
2
|
import { t as cn } from "./utils-DQx8TpNT.js";
|
|
3
3
|
import { i as TooltipTrigger, n as TooltipContent, t as Tooltip } from "./tooltip-DJcze2VZ.js";
|
|
4
4
|
import { t as Txt } from "./Txt-5efBsb2p.js";
|
|
5
|
-
import { n as SettingsRow } from "./settings-row-
|
|
5
|
+
import { n as SettingsRow } from "./settings-row-BnlFZSQL.js";
|
|
6
6
|
import { n as Skeleton, t as SkeletonText } from "./skeleton-text-BPa4Tg4u.js";
|
|
7
7
|
import { createContext, useContext, useId } from "react";
|
|
8
8
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -23,6 +23,7 @@ function SettingsContainer({ className, ...props }) {
|
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
25
|
// src/ds/new/settings/settings-header.tsx
|
|
26
|
+
var settingsInset = "[--settings-inset:0px] in-data-[slot=settings-layout]:[--settings-inset:--spacing(2.5)] ps-(--settings-inset)";
|
|
26
27
|
var SettingsTitleIdContext = createContext(void 0);
|
|
27
28
|
/** One section of a settings page: a `SettingsTitle` (or `SettingsHeader`) above its `SettingsContainer`. */
|
|
28
29
|
function SettingsGroup({ className, ...props }) {
|
|
@@ -53,12 +54,12 @@ function SettingsHeader({ action, children, className, ...props }) {
|
|
|
53
54
|
function SettingsTitle({ accessory, info, className, children, ...props }) {
|
|
54
55
|
const titleId = useContext(SettingsTitleIdContext);
|
|
55
56
|
return /* @__PURE__ */ jsxs("div", {
|
|
56
|
-
className: "flex min-w-0 flex-wrap items-center gap-2
|
|
57
|
+
className: cn("flex min-w-0 flex-wrap items-center gap-2", settingsInset),
|
|
57
58
|
children: [/* @__PURE__ */ jsx(Txt, {
|
|
58
59
|
as: "h2",
|
|
59
60
|
id: titleId,
|
|
60
61
|
variant: "subheading",
|
|
61
|
-
tone: "
|
|
62
|
+
tone: "ink",
|
|
62
63
|
className,
|
|
63
64
|
...props,
|
|
64
65
|
children: info == null ? children : /* @__PURE__ */ jsx(SettingsTitleInfo, {
|
|
@@ -90,18 +91,21 @@ function SettingsDescription({ className, ...props }) {
|
|
|
90
91
|
as: "p",
|
|
91
92
|
variant: "caption",
|
|
92
93
|
tone: "muted",
|
|
93
|
-
className: cn(
|
|
94
|
+
className: cn(settingsInset, className),
|
|
94
95
|
...props
|
|
95
96
|
});
|
|
96
97
|
}
|
|
97
98
|
// src/ds/new/settings/settings-list.tsx
|
|
98
|
-
/**
|
|
99
|
-
|
|
99
|
+
/**
|
|
100
|
+
* A list's first row: its count, caption or empty text on the left and its one action ("Add account", "Invite
|
|
101
|
+
* member") on the right. A full list and an empty one share this exact look, so the card reads the same either way.
|
|
102
|
+
*/
|
|
103
|
+
function SettingsListBar({ action, className, children, ...props }) {
|
|
100
104
|
return /* @__PURE__ */ jsxs("div", {
|
|
101
|
-
className: cn("flex min-h-8 items-center justify-between gap-3", className),
|
|
105
|
+
className: cn("flex min-h-8 items-center justify-between gap-3 sm:min-h-[calc(var(--text-label)*1.5+1px+var(--text-caption)*1.5+--spacing(6.5))]", className),
|
|
102
106
|
...props,
|
|
103
107
|
children: [/* @__PURE__ */ jsx("div", {
|
|
104
|
-
className:
|
|
108
|
+
className: "min-w-0 truncate text-label text-foreground",
|
|
105
109
|
children
|
|
106
110
|
}), action != null && /* @__PURE__ */ jsx("div", {
|
|
107
111
|
className: "flex shrink-0 items-center gap-2",
|
|
@@ -113,15 +117,16 @@ function SettingsListBar({ tone, action, className, children, ...props }) {
|
|
|
113
117
|
function SettingsListHeader(props) {
|
|
114
118
|
return /* @__PURE__ */ jsx(SettingsListBar, {
|
|
115
119
|
"data-slot": "settings-list-header",
|
|
116
|
-
tone: "title",
|
|
117
120
|
...props
|
|
118
121
|
});
|
|
119
122
|
}
|
|
120
|
-
/**
|
|
123
|
+
/**
|
|
124
|
+
* An empty list's only row: what's missing on the left ("No join links"), the list's action on the right. Looks
|
|
125
|
+
* exactly like `SettingsListHeader`, so empty and full lists match; use it for every empty list in a card.
|
|
126
|
+
*/
|
|
121
127
|
function SettingsEmptyRow(props) {
|
|
122
128
|
return /* @__PURE__ */ jsx(SettingsListBar, {
|
|
123
129
|
"data-slot": "settings-empty-row",
|
|
124
|
-
tone: "muted",
|
|
125
130
|
...props
|
|
126
131
|
});
|
|
127
132
|
}
|
|
@@ -143,11 +148,22 @@ function SettingsItemIcon({ className, ...props }) {
|
|
|
143
148
|
...props
|
|
144
149
|
});
|
|
145
150
|
}
|
|
146
|
-
/**
|
|
151
|
+
/**
|
|
152
|
+
* One thing in a settings list (an account, a member, a session, a source, a package version). Its right side holds
|
|
153
|
+
* the item's status or its own actions (Remove, Revoke, Copy), not a control that changes a setting. Goes in a
|
|
154
|
+
* `SettingsContainer`, usually under a `SettingsListHeader`.
|
|
155
|
+
*
|
|
156
|
+
* For a setting the person changes (an input, select or switch with a label), use `SettingsRow` instead.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* <SettingsItem media={<Avatar size="md" … />} title="Ada Lovelace" description="ada@example.com">
|
|
160
|
+
* <Button size="sm" variant="ghost">Remove</Button>
|
|
161
|
+
* </SettingsItem>
|
|
162
|
+
*/
|
|
147
163
|
function SettingsItem({ media, title, description, children, className, ...props }) {
|
|
148
164
|
return /* @__PURE__ */ jsxs("div", {
|
|
149
165
|
"data-slot": "settings-item",
|
|
150
|
-
className: cn("flex min-w-0 items-center gap-3", className),
|
|
166
|
+
className: cn("flex min-w-0 flex-wrap items-center gap-x-3 gap-y-2 sm:flex-nowrap", className),
|
|
151
167
|
...props,
|
|
152
168
|
children: [
|
|
153
169
|
media,
|
|
@@ -163,7 +179,7 @@ function SettingsItem({ media, title, description, children, className, ...props
|
|
|
163
179
|
})]
|
|
164
180
|
}),
|
|
165
181
|
children != null && /* @__PURE__ */ jsx("div", {
|
|
166
|
-
className: "flex
|
|
182
|
+
className: "flex min-w-0 basis-full items-center gap-2 sm:shrink-0 sm:basis-auto",
|
|
167
183
|
children
|
|
168
184
|
})
|
|
169
185
|
]
|
|
@@ -221,4 +237,4 @@ function RowPlaceholder() {
|
|
|
221
237
|
}
|
|
222
238
|
export { SettingsListHeader as a, SettingsGroup as c, SettingsContainer as d, SettingsItemIcon as i, SettingsHeader as l, SettingsEmptyRow as n, SettingsNoticeRow as o, SettingsItem as r, SettingsDescription as s, SettingsSkeleton as t, SettingsTitle as u };
|
|
223
239
|
|
|
224
|
-
//# sourceMappingURL=settings-
|
|
240
|
+
//# sourceMappingURL=settings-B7RMGKgf.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settings-B7RMGKgf.js","names":[],"sources":["../src/ds/new/settings/settings-container.tsx","../src/ds/new/settings/settings-header.tsx","../src/ds/new/settings/settings-list.tsx","../src/ds/new/settings/settings-skeleton.tsx"],"sourcesContent":["import type { ComponentProps } from 'react';\nimport { fieldsOnSurface } from '@/ds/primitives/raised-surface';\nimport { cn } from '@/lib/utils';\n\n/**\n * A settings card: the card fill with no rim, 14px from its edge to the content, and hairlines between rows that\n * stop at that inset. The card owns its rows' spacing: each direct child gets 13px above and below, and the card\n * adds the last 1px at its edges. Children with nothing in them (an empty `SettingsNoticeRow`) take no space and\n * draw no hairline, so a list can always render its notice row.\n */\nconst settingsCardStyle = cn(\n // `!`: the card owns row spacing, so a row's own reset (`Fieldset`'s `p-0`) can't remove it.\n 'flex min-w-0 flex-col rounded-xl bg-card px-3.5 py-px *:py-3.25! *:empty:hidden',\n '[&>:not(:empty)~:not(:empty)]:border-t [&>:not(:empty)~:not(:empty)]:border-border',\n fieldsOnSurface,\n);\n\nexport type SettingsContainerProps = ComponentProps<'div'>;\n\n/** One settings card. Holds `SettingsRow`s, `SettingsItem`s, a `SettingsListHeader` or a `SettingsEmptyRow`. */\nexport function SettingsContainer({ className, ...props }: SettingsContainerProps) {\n return <div data-slot=\"settings-container\" className={cn(settingsCardStyle, className)} {...props} />;\n}\n","import { createContext, useContext, useId } from 'react';\nimport type { ComponentProps, ReactNode } from 'react';\nimport { Tooltip, TooltipContent, TooltipTrigger } from '@/ds/components/Tooltip';\nimport { Txt } from '@/ds/components/Txt';\nimport { cn } from '@/lib/utils';\n\n// On a settings page (`SettingsLayout`), section titles and descriptions sit 10px inside the card's edge, in line with\n// the inset page title. Anywhere else (forms, other pages) they line up with the page's left edge and field labels.\n// The inset is a custom property, so a caller's `ps-*` class still wins. Written out in full so Tailwind finds it.\nconst settingsInset =\n '[--settings-inset:0px] in-data-[slot=settings-layout]:[--settings-inset:--spacing(2.5)] ps-(--settings-inset)';\n\nconst SettingsTitleIdContext = createContext<string | undefined>(undefined);\n\n/** One section of a settings page: a `SettingsTitle` (or `SettingsHeader`) above its `SettingsContainer`. */\nexport function SettingsGroup({ className, ...props }: ComponentProps<'section'>) {\n const titleId = useId();\n\n return (\n <SettingsTitleIdContext.Provider value={titleId}>\n <section\n aria-labelledby={titleId}\n className={cn('flex min-w-0 scroll-mt-4 flex-col gap-2', className)}\n {...props}\n />\n </SettingsTitleIdContext.Provider>\n );\n}\n\n/** A section title with something beside it. A list's actions go in its card (`SettingsListHeader`), not here. */\nexport function SettingsHeader({\n action,\n children,\n className,\n ...props\n}: ComponentProps<'header'> & { action?: ReactNode }) {\n return (\n <header\n className={cn('flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between sm:gap-4', className)}\n {...props}\n >\n <div className=\"flex min-w-0 flex-col gap-1\">{children}</div>\n {action != null && <div className=\"shrink-0\">{action}</div>}\n </header>\n );\n}\n\nexport function SettingsTitle({\n accessory,\n info,\n className,\n children,\n ...props\n}: Omit<ComponentProps<'h2'>, 'id'> & {\n accessory?: ReactNode;\n /** What the section is for, shown in a tooltip on the title. For sections whose name isn't self-explanatory. */\n info?: ReactNode;\n}) {\n const titleId = useContext(SettingsTitleIdContext);\n\n return (\n <div className={cn('flex min-w-0 flex-wrap items-center gap-2', settingsInset)}>\n <Txt as=\"h2\" id={titleId} variant=\"subheading\" tone=\"ink\" className={className} {...props}>\n {info == null ? children : <SettingsTitleInfo info={info}>{children}</SettingsTitleInfo>}\n </Txt>\n {accessory}\n </div>\n );\n}\n\n/** The title's text as a tooltip trigger, described by `info`. */\nfunction SettingsTitleInfo({ info, children }: { info: ReactNode; children: ReactNode }) {\n const infoId = useId();\n\n return (\n <Tooltip>\n <TooltipTrigger\n render={\n <span\n tabIndex={0}\n aria-describedby={infoId}\n className=\"cursor-help underline decoration-transparent decoration-dotted underline-offset-4 hover:decoration-current focus-visible:decoration-current focus-visible:outline-none\"\n />\n }\n >\n {children}\n </TooltipTrigger>\n <TooltipContent id={infoId} keepMounted className=\"max-w-64\">\n {info}\n </TooltipContent>\n </Tooltip>\n );\n}\n\nexport function SettingsDescription({ className, ...props }: ComponentProps<'p'>) {\n return <Txt as=\"p\" variant=\"caption\" tone=\"muted\" className={cn(settingsInset, className)} {...props} />;\n}\n","import type { ComponentProps, ReactNode } from 'react';\nimport { cn } from '@/lib/utils';\n\n/**\n * A list's first row: its count, caption or empty text on the left and its one action (\"Add account\", \"Invite\n * member\") on the right. A full list and an empty one share this exact look, so the card reads the same either way.\n */\nfunction SettingsListBar({ action, className, children, ...props }: ComponentProps<'div'> & { action?: ReactNode }) {\n return (\n <div\n className={cn(\n // As tall as a `SettingsRow` (label + one-line description) plus the 13px the card puts above and below each\n // row, since this row's own box includes that padding. Keeps a list's first row level with the settings above it.\n 'flex min-h-8 items-center justify-between gap-3 sm:min-h-[calc(var(--text-label)*1.5+1px+var(--text-caption)*1.5+--spacing(6.5))]',\n className,\n )}\n {...props}\n >\n <div className=\"min-w-0 truncate text-label text-foreground\">{children}</div>\n {action != null && <div className=\"flex shrink-0 items-center gap-2\">{action}</div>}\n </div>\n );\n}\n\nexport type SettingsListHeaderProps = ComponentProps<'div'> & {\n /** The list's action, on the right. Refresh and other list controls can sit beside it. */\n action?: ReactNode;\n};\n\n/** The first row of a list's `SettingsContainer`: a count (\"2 accounts\") and the list's action. */\nexport function SettingsListHeader(props: SettingsListHeaderProps) {\n return <SettingsListBar data-slot=\"settings-list-header\" {...props} />;\n}\n\nexport type SettingsEmptyRowProps = ComponentProps<'div'> & {\n /** The same action the list's header would hold, so an empty list still offers it. */\n action?: ReactNode;\n};\n\n/**\n * An empty list's only row: what's missing on the left (\"No join links\"), the list's action on the right. Looks\n * exactly like `SettingsListHeader`, so empty and full lists match; use it for every empty list in a card.\n */\nexport function SettingsEmptyRow(props: SettingsEmptyRowProps) {\n return <SettingsListBar data-slot=\"settings-empty-row\" {...props} />;\n}\n\n/** A list's notices and errors, as a row of its `SettingsContainer`. Takes no space while it has nothing in it. */\nexport function SettingsNoticeRow({ className, ...props }: ComponentProps<'div'>) {\n return <div data-slot=\"settings-notice-row\" className={cn('flex flex-col gap-2', className)} {...props} />;\n}\n\n/** The square on the left of a `SettingsItem` holding an icon or logo. Avatars use `Avatar size=\"md\"`, the\n * same size, so every list's text starts at the same place. */\nexport function SettingsItemIcon({ className, ...props }: ComponentProps<'span'>) {\n return (\n <span\n data-slot=\"settings-item-icon\"\n aria-hidden\n className={cn(\n 'flex size-avatar-md shrink-0 items-center justify-center rounded-lg bg-muted text-muted-foreground [&>svg]:size-icon-md',\n className,\n )}\n {...props}\n />\n );\n}\n\nexport type SettingsItemProps = Omit<ComponentProps<'div'>, 'title'> & {\n /** A `SettingsItemIcon` or an `Avatar size=\"md\"`. */\n media?: ReactNode;\n title: ReactNode;\n /** One line under the title: \"GitHub · Connected 3 weeks ago\". */\n description?: ReactNode;\n /** The item's status or actions, on the right. */\n children?: ReactNode;\n};\n\n/**\n * One thing in a settings list (an account, a member, a session, a source, a package version). Its right side holds\n * the item's status or its own actions (Remove, Revoke, Copy), not a control that changes a setting. Goes in a\n * `SettingsContainer`, usually under a `SettingsListHeader`.\n *\n * For a setting the person changes (an input, select or switch with a label), use `SettingsRow` instead.\n *\n * @example\n * <SettingsItem media={<Avatar size=\"md\" … />} title=\"Ada Lovelace\" description=\"ada@example.com\">\n * <Button size=\"sm\" variant=\"ghost\">Remove</Button>\n * </SettingsItem>\n */\nexport function SettingsItem({ media, title, description, children, className, ...props }: SettingsItemProps) {\n return (\n <div\n data-slot=\"settings-item\"\n // Below `sm` the item's value or actions wrap onto their own full-width line under the title, as a\n // `SettingsRow`'s control does, so a long value (an email, a type) never squeezes the title out.\n className={cn('flex min-w-0 flex-wrap items-center gap-x-3 gap-y-2 sm:flex-nowrap', className)}\n {...props}\n >\n {media}\n <div className=\"flex min-w-0 flex-1 flex-col gap-px\">\n {/* A string title truncates, so it also goes in the hover title to stay readable in full. */}\n <div className=\"truncate text-label text-foreground\" title={typeof title === 'string' ? title : undefined}>\n {title}\n </div>\n {description != null && <div className=\"truncate text-caption text-muted-foreground\">{description}</div>}\n </div>\n {children != null && (\n <div className=\"flex min-w-0 basis-full items-center gap-2 sm:shrink-0 sm:basis-auto\">{children}</div>\n )}\n </div>\n );\n}\n","import { SettingsItem } from './settings-list';\nimport { SettingsRow } from './settings-row';\nimport { Skeleton } from '@/ds/components/Skeleton/skeleton';\nimport { SkeletonText } from '@/ds/components/Skeleton/skeleton-text';\nimport { cn } from '@/lib/utils';\n\nconst bar = 'motion-reduce:before:animate-none';\n\nexport type SettingsSkeletonProps = {\n /** Announced while loading, e.g. \"Loading members\". */\n label: string;\n /** Placeholder rows, matching how many the loaded list usually has. */\n rows?: number;\n /** `row` stands in for `SettingsRow`s (label left, control right); `item` for `SettingsItem`s (icon, title, description). */\n variant?: 'row' | 'item';\n className?: string;\n};\n\n/**\n * The loading state for anything inside a `SettingsContainer`. Placeholders are built from the real `SettingsRow` and\n * `SettingsItem`, so they sit exactly where the loaded rows will.\n *\n * ```tsx\n * <SettingsContainer>\n * {isLoading ? <SettingsSkeleton label=\"Loading members\" variant=\"item\" rows={3} /> : members.map(...)}\n * </SettingsContainer>\n * ```\n */\nexport function SettingsSkeleton({ label, rows = 2, variant = 'row', className }: SettingsSkeletonProps) {\n const Placeholder = variant === 'item' ? ItemPlaceholder : RowPlaceholder;\n\n return (\n // One child of the card, so it takes the card's row padding; inside, rows repeat that rhythm with hairlines.\n <div\n role=\"status\"\n aria-label={label}\n data-slot=\"settings-skeleton\"\n className={cn('grid divide-y divide-border *:py-3.25 *:first:pt-0 *:last:pb-0', className)}\n >\n {Array.from({ length: rows }, (_, index) => (\n <Placeholder key={index} />\n ))}\n </div>\n );\n}\n\nfunction ItemPlaceholder() {\n return (\n <SettingsItem\n aria-hidden\n media={<Skeleton className={cn('size-avatar-md shrink-0 rounded-lg', bar)} />}\n title={<SkeletonText line=\"text-label\" className={cn('w-32', bar)} />}\n description={<SkeletonText line=\"text-caption\" className={cn('w-48 max-w-full', bar)} />}\n />\n );\n}\n\nfunction RowPlaceholder() {\n return (\n <SettingsRow\n aria-hidden\n label={<SkeletonText line=\"text-label\" className={cn('w-28', bar)} />}\n description={<SkeletonText line=\"text-caption\" className={cn('w-48 max-w-full', bar)} />}\n >\n <Skeleton className={cn('h-control-sm w-28 max-w-full rounded-full', bar)} />\n </SettingsRow>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;AAUA,IAAM,oBAAoB,GAExB,mFACA,sFACA,eACF;;AAKA,SAAgB,kBAAkB,EAAE,WAAW,GAAG,SAAiC;CACjF,OAAO,oBAAC,OAAD;EAAK,aAAU;EAAqB,WAAW,GAAG,mBAAmB,SAAS;EAAG,GAAI;CAAQ,CAAA;AACtG;;ACbA,IAAM,gBACJ;AAEF,IAAM,yBAAyB,cAAkC,KAAA,CAAS;;AAG1E,SAAgB,cAAc,EAAE,WAAW,GAAG,SAAoC;CAChF,MAAM,UAAU,MAAM;CAEtB,OACE,oBAAC,uBAAuB,UAAxB;EAAiC,OAAO;EACtC,UAAA,oBAAC,WAAD;GACE,mBAAiB;GACjB,WAAW,GAAG,2CAA2C,SAAS;GAClE,GAAI;EACL,CAAA;CAC8B,CAAA;AAErC;;AAGA,SAAgB,eAAe,EAC7B,QACA,UACA,WACA,GAAG,SAC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