@igstack/app-catalog-frontend-core 6.14.0 → 6.16.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/esm/api/infra/trpc.d.ts +36 -0
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/internal.d.ts +1 -0
- package/dist/esm/internal.js +2 -0
- package/dist/esm/internal.js.map +1 -1
- package/dist/esm/lib/externalLink.d.ts +8 -0
- package/dist/esm/lib/externalLink.js +9 -0
- package/dist/esm/lib/externalLink.js.map +1 -0
- package/dist/esm/modules/appCatalog/context/AppCatalogContext.d.ts +3 -1
- package/dist/esm/modules/appCatalog/context/AppCatalogContext.js +2 -0
- package/dist/esm/modules/appCatalog/context/AppCatalogContext.js.map +1 -1
- package/dist/esm/modules/appCatalog/hooks/useUpdateApp.d.ts +36 -36
- package/dist/esm/modules/appCatalog/ui/components/SectionTabs.d.ts +2 -1
- package/dist/esm/modules/appCatalog/ui/components/SectionTabs.js +11 -1
- package/dist/esm/modules/appCatalog/ui/components/SectionTabs.js.map +1 -1
- package/dist/esm/modules/appCatalog/ui/components/SourcesList.d.ts +10 -0
- package/dist/esm/modules/appCatalog/ui/components/SourcesList.js +51 -0
- package/dist/esm/modules/appCatalog/ui/components/SourcesList.js.map +1 -0
- package/dist/esm/modules/appCatalog/ui/detail/AppDetails.js +9 -52
- package/dist/esm/modules/appCatalog/ui/detail/AppDetails.js.map +1 -1
- package/dist/esm/modules/appCatalog/ui/pages/ServiceDesksPage.js +12 -7
- package/dist/esm/modules/appCatalog/ui/pages/ServiceDesksPage.js.map +1 -1
- package/dist/esm/modules/communityTools/useCommunityTools.d.ts +6 -6
- package/dist/esm/modules/mcpCatalog/McpAccessLine.d.ts +5 -0
- package/dist/esm/modules/mcpCatalog/McpAccessLine.js +48 -0
- package/dist/esm/modules/mcpCatalog/McpAccessLine.js.map +1 -0
- package/dist/esm/modules/mcpCatalog/McpCatalogPage.d.ts +11 -0
- package/dist/esm/modules/mcpCatalog/McpCatalogPage.js +289 -0
- package/dist/esm/modules/mcpCatalog/McpCatalogPage.js.map +1 -0
- package/dist/esm/modules/mcpCatalog/McpInfoTiles.d.ts +5 -0
- package/dist/esm/modules/mcpCatalog/McpInfoTiles.js +88 -0
- package/dist/esm/modules/mcpCatalog/McpInfoTiles.js.map +1 -0
- package/dist/esm/modules/mcpCatalog/McpSafetyLines.d.ts +5 -0
- package/dist/esm/modules/mcpCatalog/McpSafetyLines.js +82 -0
- package/dist/esm/modules/mcpCatalog/McpSafetyLines.js.map +1 -0
- package/dist/esm/modules/mcpCatalog/McpSearchResult.d.ts +18 -0
- package/dist/esm/modules/mcpCatalog/McpSearchResult.js +150 -0
- package/dist/esm/modules/mcpCatalog/McpSearchResult.js.map +1 -0
- package/dist/esm/modules/mcpCatalog/McpServerDetail.d.ts +8 -0
- package/dist/esm/modules/mcpCatalog/McpServerDetail.js +116 -0
- package/dist/esm/modules/mcpCatalog/McpServerDetail.js.map +1 -0
- package/dist/esm/modules/mcpCatalog/McpServerRow.d.ts +10 -0
- package/dist/esm/modules/mcpCatalog/McpServerRow.js +75 -0
- package/dist/esm/modules/mcpCatalog/McpServerRow.js.map +1 -0
- package/dist/esm/modules/mcpCatalog/McpToolsTable.d.ts +5 -0
- package/dist/esm/modules/mcpCatalog/McpToolsTable.js +24 -0
- package/dist/esm/modules/mcpCatalog/McpToolsTable.js.map +1 -0
- package/dist/esm/modules/mcpCatalog/Triad.d.ts +13 -0
- package/dist/esm/modules/mcpCatalog/Triad.js +175 -0
- package/dist/esm/modules/mcpCatalog/Triad.js.map +1 -0
- package/dist/esm/modules/mcpCatalog/cart/McpCart.d.ts +15 -0
- package/dist/esm/modules/mcpCatalog/cart/McpCart.js +156 -0
- package/dist/esm/modules/mcpCatalog/cart/McpCart.js.map +1 -0
- package/dist/esm/modules/mcpCatalog/cart/useMcpCart.d.ts +11 -0
- package/dist/esm/modules/mcpCatalog/cart/useMcpCart.js +48 -0
- package/dist/esm/modules/mcpCatalog/cart/useMcpCart.js.map +1 -0
- package/dist/esm/modules/mcpCatalog/install/InstallButton.d.ts +12 -0
- package/dist/esm/modules/mcpCatalog/install/InstallButton.js +126 -0
- package/dist/esm/modules/mcpCatalog/install/InstallButton.js.map +1 -0
- package/dist/esm/modules/mcpCatalog/install/InstallMenu.d.ts +14 -0
- package/dist/esm/modules/mcpCatalog/install/InstallMenu.js +139 -0
- package/dist/esm/modules/mcpCatalog/install/InstallMenu.js.map +1 -0
- package/dist/esm/modules/mcpCatalog/install/WhatHappensDialog.d.ts +10 -0
- package/dist/esm/modules/mcpCatalog/install/WhatHappensDialog.js +161 -0
- package/dist/esm/modules/mcpCatalog/install/WhatHappensDialog.js.map +1 -0
- package/dist/esm/modules/mcpCatalog/install/installOptions.d.ts +40 -0
- package/dist/esm/modules/mcpCatalog/install/installOptions.js +204 -0
- package/dist/esm/modules/mcpCatalog/install/installOptions.js.map +1 -0
- package/dist/esm/modules/mcpCatalog/install/useMcpPrefs.d.ts +14 -0
- package/dist/esm/modules/mcpCatalog/install/useMcpPrefs.js +39 -0
- package/dist/esm/modules/mcpCatalog/install/useMcpPrefs.js.map +1 -0
- package/dist/esm/modules/mcpCatalog/searchMcpServers.d.ts +25 -0
- package/dist/esm/modules/mcpCatalog/searchMcpServers.js +44 -0
- package/dist/esm/modules/mcpCatalog/searchMcpServers.js.map +1 -0
- package/dist/esm/modules/mcpCatalog/signIn.d.ts +13 -0
- package/dist/esm/modules/mcpCatalog/signIn.js +29 -0
- package/dist/esm/modules/mcpCatalog/signIn.js.map +1 -0
- package/dist/esm/modules/mcpCatalog/useHasMcpServers.d.ts +8 -0
- package/dist/esm/modules/mcpCatalog/useHasMcpServers.js +13 -0
- package/dist/esm/modules/mcpCatalog/useHasMcpServers.js.map +1 -0
- package/dist/esm/modules/mcpCatalog/useMcpCatalogConfig.d.ts +7 -0
- package/dist/esm/modules/mcpCatalog/useMcpCatalogConfig.js +16 -0
- package/dist/esm/modules/mcpCatalog/useMcpCatalogConfig.js.map +1 -0
- package/dist/esm/node_modules/.pnpm/zod@4.3.5/node_modules/zod/v4/classic/schemas.js +3 -3
- package/dist/esm/node_modules/.pnpm/zod@4.3.5/node_modules/zod/v4/core/api.js +1 -1
- package/dist/esm/node_modules/.pnpm/zod@4.3.5/node_modules/zod/v4/core/checks.js +1 -1
- package/dist/esm/node_modules/.pnpm/zod@4.3.5/node_modules/zod/v4/core/schemas.js +2 -2
- package/dist/esm/routeTree.gen.d.ts +43 -17
- package/dist/esm/routeTree.gen.js +15 -3
- package/dist/esm/routeTree.gen.js.map +1 -1
- package/dist/esm/routes/_layout/community.$slug.d.ts +3 -3
- package/dist/esm/routes/_layout/community.d.ts +3 -3
- package/dist/esm/routes/_layout/mcp.$slug.d.ts +9 -0
- package/dist/esm/routes/_layout/mcp._slug.js +8 -0
- package/dist/esm/routes/_layout/mcp._slug.js.map +1 -0
- package/dist/esm/routes/_layout/mcp.d.ts +5 -1
- package/dist/esm/routes/_layout/mcp.js +45 -5
- package/dist/esm/routes/_layout/mcp.js.map +1 -1
- package/dist/esm/types/uiSettings.d.ts +10 -0
- package/dist/esm/ui/button.d.ts +1 -1
- package/dist/esm/ui/components/header/Header.js +1 -5
- package/dist/esm/ui/components/header/Header.js.map +1 -1
- package/dist/esm/ui/empty.d.ts +1 -1
- package/dist/esm/ui/item.d.ts +1 -1
- package/dist/esm/userDb/AcDb.d.ts +10 -0
- package/dist/esm/userDb/AcDb.js +6 -0
- package/dist/esm/userDb/AcDb.js.map +1 -1
- package/package.json +4 -4
- package/src/__tests__/modules/communityTools/timeAgo.test.ts +16 -0
- package/src/index.tsx +6 -1
- package/src/internal.ts +1 -0
- package/src/lib/externalLink.ts +10 -0
- package/src/modules/appCatalog/context/AppCatalogContext.tsx +5 -0
- package/src/modules/appCatalog/ui/components/SectionTabs.tsx +14 -1
- package/src/modules/appCatalog/ui/components/SourcesList.tsx +62 -0
- package/src/modules/appCatalog/ui/detail/AppDetails.tsx +6 -52
- package/src/modules/appCatalog/ui/pages/ServiceDesksPage.tsx +18 -3
- package/src/modules/mcpCatalog/McpAccessLine.tsx +54 -0
- package/src/modules/mcpCatalog/McpCatalogPage.tsx +324 -0
- package/src/modules/mcpCatalog/McpInfoTiles.tsx +112 -0
- package/src/modules/mcpCatalog/McpSafetyLines.tsx +89 -0
- package/src/modules/mcpCatalog/McpSearchResult.tsx +173 -0
- package/src/modules/mcpCatalog/McpServerDetail.tsx +145 -0
- package/src/modules/mcpCatalog/McpServerRow.tsx +78 -0
- package/src/modules/mcpCatalog/McpToolsTable.tsx +36 -0
- package/src/modules/mcpCatalog/Triad.tsx +213 -0
- package/src/modules/mcpCatalog/cart/McpCart.tsx +171 -0
- package/src/modules/mcpCatalog/cart/useMcpCart.ts +64 -0
- package/src/modules/mcpCatalog/install/InstallButton.tsx +154 -0
- package/src/modules/mcpCatalog/install/InstallMenu.tsx +160 -0
- package/src/modules/mcpCatalog/install/WhatHappensDialog.tsx +199 -0
- package/src/modules/mcpCatalog/install/installOptions.tsx +266 -0
- package/src/modules/mcpCatalog/install/useMcpPrefs.ts +55 -0
- package/src/modules/mcpCatalog/searchMcpServers.ts +84 -0
- package/src/modules/mcpCatalog/signIn.ts +34 -0
- package/src/modules/mcpCatalog/useHasMcpServers.ts +22 -0
- package/src/modules/mcpCatalog/useMcpCatalogConfig.ts +20 -0
- package/src/routeTree.gen.ts +36 -5
- package/src/routes/_layout/mcp.$slug.tsx +10 -0
- package/src/routes/_layout/mcp.tsx +63 -3
- package/src/types/uiSettings.ts +11 -0
- package/src/ui/components/header/Header.tsx +1 -7
- package/src/userDb/AcDb.ts +13 -0
- package/dist/esm/modules/appCatalog/ui/pages/McpPage.d.ts +0 -11
- package/dist/esm/modules/appCatalog/ui/pages/McpPage.js +0 -227
- package/dist/esm/modules/appCatalog/ui/pages/McpPage.js.map +0 -1
- package/dist/esm/modules/appCatalog/utils/fetchMcpTools.d.ts +0 -32
- package/dist/esm/modules/appCatalog/utils/fetchMcpTools.js +0 -79
- package/dist/esm/modules/appCatalog/utils/fetchMcpTools.js.map +0 -1
- package/src/modules/appCatalog/ui/pages/McpPage.tsx +0 -275
- package/src/modules/appCatalog/utils/fetchMcpTools.ts +0 -140
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import type { CatalogMcpServer } from '@igstack/app-catalog-backend-core'
|
|
2
|
+
import {
|
|
3
|
+
Check,
|
|
4
|
+
Eye,
|
|
5
|
+
Share2,
|
|
6
|
+
ShoppingCart,
|
|
7
|
+
TriangleAlert,
|
|
8
|
+
X,
|
|
9
|
+
} from 'lucide-react'
|
|
10
|
+
import { useState } from 'react'
|
|
11
|
+
import { cn } from '~/lib/utils'
|
|
12
|
+
import { Button } from '~/ui/button'
|
|
13
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from '~/ui/tooltip'
|
|
14
|
+
import { InstallButton } from '../install/InstallButton'
|
|
15
|
+
import { copyText, useCopyFlash } from '../install/installOptions'
|
|
16
|
+
import { WhatHappensDialog } from '../install/WhatHappensDialog'
|
|
17
|
+
import { useSensitiveDataLabel } from '../useMcpCatalogConfig'
|
|
18
|
+
import { useMcpCart } from './useMcpCart'
|
|
19
|
+
|
|
20
|
+
const ON_DARK =
|
|
21
|
+
'inline-flex min-h-8 items-center gap-1.5 rounded-[calc(var(--radius)-4px)] px-2.5 text-[13px] font-bold text-white hover:bg-white/15 [&_svg]:size-4'
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Adds `server` to the cart or takes it out. The full button is one width
|
|
25
|
+
* whichever it says; `small` is the home list's icon, named for assistive tech.
|
|
26
|
+
*/
|
|
27
|
+
export function CartButton({
|
|
28
|
+
server,
|
|
29
|
+
small = false,
|
|
30
|
+
}: {
|
|
31
|
+
server: CatalogMcpServer
|
|
32
|
+
small?: boolean
|
|
33
|
+
}) {
|
|
34
|
+
const { has, toggle } = useMcpCart()
|
|
35
|
+
const inCart = has(server.slug)
|
|
36
|
+
const Icon = inCart ? Check : ShoppingCart
|
|
37
|
+
const pressed =
|
|
38
|
+
'aria-pressed:border-primary aria-pressed:bg-primary aria-pressed:text-primary-foreground aria-pressed:hover:bg-primary/90'
|
|
39
|
+
|
|
40
|
+
if (small) {
|
|
41
|
+
const tip = inCart ? 'In your cart' : 'Add to cart'
|
|
42
|
+
return (
|
|
43
|
+
<Tooltip>
|
|
44
|
+
<TooltipTrigger asChild>
|
|
45
|
+
<button
|
|
46
|
+
type="button"
|
|
47
|
+
aria-pressed={inCart}
|
|
48
|
+
aria-label={`${inCart ? 'Remove' : 'Add'} ${server.displayName} ${inCart ? 'from' : 'to'} cart`}
|
|
49
|
+
onClick={() => toggle(server.slug)}
|
|
50
|
+
className={cn(
|
|
51
|
+
'relative z-10 grid size-7 shrink-0 place-items-center rounded-lg border border-border bg-card text-muted-foreground hover:border-ring hover:text-foreground',
|
|
52
|
+
pressed,
|
|
53
|
+
)}
|
|
54
|
+
>
|
|
55
|
+
<Icon aria-hidden="true" className="size-3.5" />
|
|
56
|
+
</button>
|
|
57
|
+
</TooltipTrigger>
|
|
58
|
+
<TooltipContent>{tip}</TooltipContent>
|
|
59
|
+
</Tooltip>
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<Button
|
|
65
|
+
size="sm"
|
|
66
|
+
variant="outline"
|
|
67
|
+
aria-pressed={inCart}
|
|
68
|
+
onClick={() => toggle(server.slug)}
|
|
69
|
+
className={cn('w-[120px]', pressed)}
|
|
70
|
+
>
|
|
71
|
+
<Icon aria-hidden="true" />
|
|
72
|
+
{inCart ? 'In cart' : 'Add to cart'}
|
|
73
|
+
</Button>
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The cart bar, fixed at the bottom while the cart has anything: a chip per
|
|
79
|
+
* server, a warning when any has sensitive data, Share, What happens? and
|
|
80
|
+
* Install for all of them.
|
|
81
|
+
*/
|
|
82
|
+
export function McpCart() {
|
|
83
|
+
const { servers, toggle, shareUrl } = useMcpCart()
|
|
84
|
+
const sensitiveLabel = useSensitiveDataLabel()
|
|
85
|
+
const [whatOpen, setWhatOpen] = useState(false)
|
|
86
|
+
const [flash, setFlash] = useCopyFlash()
|
|
87
|
+
|
|
88
|
+
if (servers.length === 0) return null
|
|
89
|
+
const sensitive = servers.filter((s) => s.sensitiveData)
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<div
|
|
93
|
+
role="region"
|
|
94
|
+
aria-label="Your cart"
|
|
95
|
+
className="fixed bottom-4 left-1/2 z-40 flex w-[min(1100px,calc(100vw-32px))] -translate-x-1/2 flex-wrap items-center gap-3.5 rounded-[calc(var(--radius)+6px)] bg-stone-900 py-3 pr-3.5 pl-[18px] text-white shadow-2xl ring-1 ring-white/10 dark:bg-stone-800"
|
|
96
|
+
>
|
|
97
|
+
<span
|
|
98
|
+
data-testid="mcp-cart-title"
|
|
99
|
+
className="inline-flex items-center gap-2 font-serif text-lg font-semibold whitespace-nowrap"
|
|
100
|
+
>
|
|
101
|
+
<ShoppingCart aria-hidden="true" className="size-[18px]" />
|
|
102
|
+
Cart · {servers.length}
|
|
103
|
+
</span>
|
|
104
|
+
<ul className="m-0 flex min-w-0 flex-1 list-none flex-wrap gap-1.5 p-0">
|
|
105
|
+
{servers.map((s) => (
|
|
106
|
+
<li
|
|
107
|
+
key={s.slug}
|
|
108
|
+
className="inline-flex items-center gap-1 rounded-full bg-white/10 py-[3px] pr-1 pl-2.5 text-[12.5px] font-bold"
|
|
109
|
+
>
|
|
110
|
+
<span data-testid="mcp-cart-item">{s.displayName}</span>
|
|
111
|
+
<button
|
|
112
|
+
type="button"
|
|
113
|
+
aria-label={`Remove ${s.displayName}`}
|
|
114
|
+
onClick={() => toggle(s.slug)}
|
|
115
|
+
className="grid size-[22px] place-items-center rounded-full opacity-70 hover:bg-white/15 hover:opacity-100"
|
|
116
|
+
>
|
|
117
|
+
<X aria-hidden="true" className="size-3" />
|
|
118
|
+
</button>
|
|
119
|
+
</li>
|
|
120
|
+
))}
|
|
121
|
+
</ul>
|
|
122
|
+
{sensitive.length > 0 && (
|
|
123
|
+
<span
|
|
124
|
+
title={`${sensitiveLabel}: ${sensitive.map((s) => s.displayName).join(', ')}`}
|
|
125
|
+
className="inline-flex items-center gap-1.5 text-xs font-semibold text-red-300"
|
|
126
|
+
>
|
|
127
|
+
<TriangleAlert aria-hidden="true" className="size-3.5" />
|
|
128
|
+
<span data-testid="mcp-cart-warning">{sensitiveLabel}</span>
|
|
129
|
+
</span>
|
|
130
|
+
)}
|
|
131
|
+
<button
|
|
132
|
+
type="button"
|
|
133
|
+
title="Copy a link that opens this page with the same cart"
|
|
134
|
+
onClick={() =>
|
|
135
|
+
void copyText(shareUrl()).then((ok) =>
|
|
136
|
+
setFlash(ok ? 'copied' : 'copy-failed'),
|
|
137
|
+
)
|
|
138
|
+
}
|
|
139
|
+
className={cn(ON_DARK, flash === 'copy-failed' && 'text-red-300')}
|
|
140
|
+
>
|
|
141
|
+
{flash === 'copied' ? (
|
|
142
|
+
<Check aria-hidden="true" />
|
|
143
|
+
) : flash === 'copy-failed' ? (
|
|
144
|
+
<TriangleAlert aria-hidden="true" />
|
|
145
|
+
) : (
|
|
146
|
+
<Share2 aria-hidden="true" />
|
|
147
|
+
)}
|
|
148
|
+
{flash === 'copied'
|
|
149
|
+
? 'Link copied'
|
|
150
|
+
: flash === 'copy-failed'
|
|
151
|
+
? 'Copy failed'
|
|
152
|
+
: 'Share'}
|
|
153
|
+
</button>
|
|
154
|
+
<button
|
|
155
|
+
type="button"
|
|
156
|
+
onClick={() => setWhatOpen(true)}
|
|
157
|
+
className={ON_DARK}
|
|
158
|
+
>
|
|
159
|
+
<Eye aria-hidden="true" />
|
|
160
|
+
What happens?
|
|
161
|
+
</button>
|
|
162
|
+
<InstallButton servers={servers} tone="dark" />
|
|
163
|
+
{whatOpen && (
|
|
164
|
+
<WhatHappensDialog
|
|
165
|
+
servers={servers}
|
|
166
|
+
onClose={() => setWhatOpen(false)}
|
|
167
|
+
/>
|
|
168
|
+
)}
|
|
169
|
+
</div>
|
|
170
|
+
)
|
|
171
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { CatalogMcpServer } from '@igstack/app-catalog-backend-core'
|
|
2
|
+
import { useNavigate, useRouter, useSearch } from '@tanstack/react-router'
|
|
3
|
+
import { useCallback, useMemo } from 'react'
|
|
4
|
+
import { useAppCatalogContext } from '../../appCatalog/context/AppCatalogContext'
|
|
5
|
+
|
|
6
|
+
/** `?cart=` as written: slugs in order, blanks dropped. */
|
|
7
|
+
function parseCart(raw: string | undefined): string[] {
|
|
8
|
+
return (raw ?? '').split(',').filter(Boolean)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The cart, kept in `?cart=` so the URL is its only home and a link shares
|
|
13
|
+
* it. Unknown and repeated slugs are ignored and left in the URL as written.
|
|
14
|
+
*/
|
|
15
|
+
export function useMcpCart() {
|
|
16
|
+
const { mcpServers } = useAppCatalogContext()
|
|
17
|
+
const { cart: raw } = useSearch({ strict: false })
|
|
18
|
+
// Unscoped, so `to: '.'` keeps an open server's dialog.
|
|
19
|
+
const navigate = useNavigate()
|
|
20
|
+
const router = useRouter()
|
|
21
|
+
|
|
22
|
+
const servers = useMemo((): CatalogMcpServer[] => {
|
|
23
|
+
const bySlug = new Map(mcpServers?.map((s) => [s.slug, s]))
|
|
24
|
+
return [...new Set(parseCart(raw))].flatMap((slug) => {
|
|
25
|
+
const server = bySlug.get(slug)
|
|
26
|
+
return server ? [server] : []
|
|
27
|
+
})
|
|
28
|
+
}, [raw, mcpServers])
|
|
29
|
+
const slugs = useMemo(() => servers.map((s) => s.slug), [servers])
|
|
30
|
+
|
|
31
|
+
const write = useCallback(
|
|
32
|
+
(next: string[]) =>
|
|
33
|
+
void navigate({
|
|
34
|
+
to: '.',
|
|
35
|
+
search: (prev) => ({ ...prev, cart: next.join(',') || undefined }),
|
|
36
|
+
replace: true,
|
|
37
|
+
}),
|
|
38
|
+
[navigate],
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
const has = useCallback((slug: string) => slugs.includes(slug), [slugs])
|
|
42
|
+
const toggle = useCallback(
|
|
43
|
+
(slug: string) =>
|
|
44
|
+
write(
|
|
45
|
+
slugs.includes(slug)
|
|
46
|
+
? slugs.filter((s) => s !== slug)
|
|
47
|
+
: [...slugs, slug],
|
|
48
|
+
),
|
|
49
|
+
[slugs, write],
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
/** A link to the list with this cart, and nothing else from this page. */
|
|
53
|
+
const shareUrl = useCallback(() => {
|
|
54
|
+
const url = new URL(
|
|
55
|
+
router.buildLocation({ to: '/mcp' }).href,
|
|
56
|
+
window.location.origin,
|
|
57
|
+
)
|
|
58
|
+
// Literal commas: the link reads as `?cart=a,b`.
|
|
59
|
+
url.search = `cart=${slugs.map(encodeURIComponent).join(',')}`
|
|
60
|
+
return url.href
|
|
61
|
+
}, [router, slugs])
|
|
62
|
+
|
|
63
|
+
return { servers, has, toggle, shareUrl }
|
|
64
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import type { CatalogMcpServer } from '@igstack/app-catalog-backend-core'
|
|
2
|
+
import type { InstallOptionId } from '@igstack/app-catalog-shared-core'
|
|
3
|
+
import { Check, ChevronDown, Sparkles, TriangleAlert } from 'lucide-react'
|
|
4
|
+
import { useCallback, useRef, useState } from 'react'
|
|
5
|
+
import { cn } from '~/lib/utils'
|
|
6
|
+
import { useMcpCatalogConfig } from '../useMcpCatalogConfig'
|
|
7
|
+
import { InstallMenu } from './InstallMenu'
|
|
8
|
+
import { INSTALL_OPTIONS, useCopyFlash, useInstall } from './installOptions'
|
|
9
|
+
import { useMcpPrefs } from './useMcpPrefs'
|
|
10
|
+
|
|
11
|
+
const HALF =
|
|
12
|
+
'inline-flex min-h-8 items-center gap-1.5 border-0 bg-transparent text-[13px] font-bold'
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Split button: the main half installs with the remembered option (or, before
|
|
16
|
+
* any choice, opens the menu); the caret always opens the menu. A copy shows
|
|
17
|
+
* "Copied" (or "Copy failed") on the main half for a moment. While the
|
|
18
|
+
* remembered choice is still loading it is a blank, disabled placeholder.
|
|
19
|
+
*/
|
|
20
|
+
export function InstallButton({
|
|
21
|
+
servers,
|
|
22
|
+
tone = 'light',
|
|
23
|
+
}: {
|
|
24
|
+
servers: readonly CatalogMcpServer[]
|
|
25
|
+
/** `dark` for a dark bar, such as the cart's. */
|
|
26
|
+
tone?: 'light' | 'dark'
|
|
27
|
+
}) {
|
|
28
|
+
const { loading, installWith, setInstallWith } = useMcpPrefs()
|
|
29
|
+
const { run } = useInstall(servers)
|
|
30
|
+
const iconUrl = useMcpCatalogConfig()?.installIconUrl
|
|
31
|
+
const splitRef = useRef<HTMLDivElement>(null)
|
|
32
|
+
const [menuOpen, setMenuOpen] = useState(false)
|
|
33
|
+
const [flash, setFlash] = useCopyFlash()
|
|
34
|
+
|
|
35
|
+
const chosen = INSTALL_OPTIONS.find((o) => o.id === installWith && !o.hidden)
|
|
36
|
+
const closeMenu = useCallback(() => setMenuOpen(false), [])
|
|
37
|
+
|
|
38
|
+
const go = async (id: InstallOptionId) => {
|
|
39
|
+
const outcome = await run(id)
|
|
40
|
+
if (outcome !== 'opened') setFlash(outcome)
|
|
41
|
+
}
|
|
42
|
+
const pick = async (id: InstallOptionId) => {
|
|
43
|
+
setMenuOpen(false)
|
|
44
|
+
// Copy first: the clipboard wants the click's user activation. The pick
|
|
45
|
+
// is stored whatever the copy did.
|
|
46
|
+
await go(id)
|
|
47
|
+
await setInstallWith(id)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const hover = tone === 'dark' ? 'hover:bg-white/15' : 'hover:bg-muted'
|
|
51
|
+
|
|
52
|
+
const firstVisit = (
|
|
53
|
+
<>
|
|
54
|
+
{iconUrl ? (
|
|
55
|
+
<img
|
|
56
|
+
src={iconUrl}
|
|
57
|
+
alt=""
|
|
58
|
+
className="-my-[3px] size-[22px] object-contain"
|
|
59
|
+
/>
|
|
60
|
+
) : (
|
|
61
|
+
<Sparkles aria-hidden="true" className="size-4 text-primary" />
|
|
62
|
+
)}
|
|
63
|
+
Let me do it for you
|
|
64
|
+
</>
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<div
|
|
69
|
+
ref={splitRef}
|
|
70
|
+
data-testid="mcp-install"
|
|
71
|
+
aria-busy={loading || undefined}
|
|
72
|
+
className={cn(
|
|
73
|
+
'inline-flex shrink-0 overflow-hidden rounded-[calc(var(--radius)-4px)] border',
|
|
74
|
+
tone === 'dark'
|
|
75
|
+
? 'border-white/20 bg-white/10 text-white'
|
|
76
|
+
: 'border-border bg-card text-foreground',
|
|
77
|
+
)}
|
|
78
|
+
>
|
|
79
|
+
<button
|
|
80
|
+
type="button"
|
|
81
|
+
disabled={loading}
|
|
82
|
+
data-icon={
|
|
83
|
+
loading
|
|
84
|
+
? 'loading'
|
|
85
|
+
: (flash ?? chosen?.id ?? (iconUrl ? 'custom' : 'default'))
|
|
86
|
+
}
|
|
87
|
+
title={
|
|
88
|
+
chosen
|
|
89
|
+
? `Install with ${chosen.label}`
|
|
90
|
+
: 'Pick your AI once and it installs this for you'
|
|
91
|
+
}
|
|
92
|
+
onClick={() => (chosen ? void go(chosen.id) : setMenuOpen((o) => !o))}
|
|
93
|
+
className={cn(
|
|
94
|
+
HALF,
|
|
95
|
+
hover,
|
|
96
|
+
'pr-2.5 pl-2 disabled:hover:bg-transparent',
|
|
97
|
+
flash === 'copied' && 'text-green-700 dark:text-green-400',
|
|
98
|
+
flash === 'copy-failed' && 'text-destructive',
|
|
99
|
+
)}
|
|
100
|
+
>
|
|
101
|
+
{loading ? (
|
|
102
|
+
// Holds the first-visit width without claiming either state.
|
|
103
|
+
<span
|
|
104
|
+
aria-hidden="true"
|
|
105
|
+
className="invisible inline-flex items-center gap-1.5"
|
|
106
|
+
>
|
|
107
|
+
{firstVisit}
|
|
108
|
+
</span>
|
|
109
|
+
) : flash === 'copied' ? (
|
|
110
|
+
<>
|
|
111
|
+
<Check aria-hidden="true" className="size-4" />
|
|
112
|
+
Copied
|
|
113
|
+
</>
|
|
114
|
+
) : flash === 'copy-failed' ? (
|
|
115
|
+
<>
|
|
116
|
+
<TriangleAlert aria-hidden="true" className="size-4" />
|
|
117
|
+
Copy failed
|
|
118
|
+
</>
|
|
119
|
+
) : chosen ? (
|
|
120
|
+
<>
|
|
121
|
+
<chosen.Icon />
|
|
122
|
+
Install
|
|
123
|
+
</>
|
|
124
|
+
) : (
|
|
125
|
+
firstVisit
|
|
126
|
+
)}
|
|
127
|
+
</button>
|
|
128
|
+
<button
|
|
129
|
+
type="button"
|
|
130
|
+
aria-label="Choose how to install"
|
|
131
|
+
aria-haspopup="menu"
|
|
132
|
+
aria-expanded={menuOpen}
|
|
133
|
+
disabled={loading}
|
|
134
|
+
onClick={() => setMenuOpen((o) => !o)}
|
|
135
|
+
className={cn(
|
|
136
|
+
HALF,
|
|
137
|
+
hover,
|
|
138
|
+
'border-l px-1.5',
|
|
139
|
+
tone === 'dark' ? 'border-white/20' : 'border-border',
|
|
140
|
+
)}
|
|
141
|
+
>
|
|
142
|
+
<ChevronDown aria-hidden="true" className="size-3.5" />
|
|
143
|
+
</button>
|
|
144
|
+
{menuOpen && (
|
|
145
|
+
<InstallMenu
|
|
146
|
+
anchor={splitRef}
|
|
147
|
+
current={chosen?.id}
|
|
148
|
+
onPick={(id) => void pick(id).catch(console.error)}
|
|
149
|
+
onClose={closeMenu}
|
|
150
|
+
/>
|
|
151
|
+
)}
|
|
152
|
+
</div>
|
|
153
|
+
)
|
|
154
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import type { InstallOptionId } from '@igstack/app-catalog-shared-core'
|
|
2
|
+
import { Check } from 'lucide-react'
|
|
3
|
+
import { useEffect, useLayoutEffect, useRef, useState } from 'react'
|
|
4
|
+
import { createPortal } from 'react-dom'
|
|
5
|
+
import { useDismissable } from '~/modules/dismiss/DismissStack'
|
|
6
|
+
import type { InstallOption } from './installOptions'
|
|
7
|
+
import { VISIBLE_INSTALL_OPTIONS } from './installOptions'
|
|
8
|
+
|
|
9
|
+
const WIDTH = 280
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The install choices under a split button: "Install with" an AI, or "Text
|
|
13
|
+
* only". Fixed to the viewport beside `anchor`, in a portal at the end of
|
|
14
|
+
* `<body>` so a dialog's clipping cannot cut it and the dismiss stack sees it
|
|
15
|
+
* on top of the dialog that opened it.
|
|
16
|
+
*/
|
|
17
|
+
export function InstallMenu({
|
|
18
|
+
anchor,
|
|
19
|
+
current,
|
|
20
|
+
onPick,
|
|
21
|
+
onClose,
|
|
22
|
+
}: {
|
|
23
|
+
/** What the menu opens beside; a press inside it is not "outside". */
|
|
24
|
+
anchor: React.RefObject<HTMLElement | null>
|
|
25
|
+
current?: InstallOptionId
|
|
26
|
+
onPick: (id: InstallOptionId) => void
|
|
27
|
+
onClose: () => void
|
|
28
|
+
}) {
|
|
29
|
+
const ref = useRef<HTMLDivElement>(null)
|
|
30
|
+
const [pos, setPos] = useState<{ left: number; top: number }>()
|
|
31
|
+
useDismissable(ref, onClose)
|
|
32
|
+
|
|
33
|
+
useLayoutEffect(() => {
|
|
34
|
+
const menu = ref.current
|
|
35
|
+
const r = anchor.current?.getBoundingClientRect()
|
|
36
|
+
if (!menu || !r) return
|
|
37
|
+
const h = menu.offsetHeight
|
|
38
|
+
setPos({
|
|
39
|
+
left: Math.max(8, Math.min(r.right - WIDTH, innerWidth - WIDTH - 8)),
|
|
40
|
+
top:
|
|
41
|
+
r.bottom + 6 + h > innerHeight
|
|
42
|
+
? Math.max(8, r.top - h - 6)
|
|
43
|
+
: r.bottom + 6,
|
|
44
|
+
})
|
|
45
|
+
}, [anchor])
|
|
46
|
+
|
|
47
|
+
// Once placed (a hidden element refuses focus): the remembered choice, else
|
|
48
|
+
// the first, and the arrows walk on from there.
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
if (!pos) return
|
|
51
|
+
const menu = ref.current
|
|
52
|
+
;(
|
|
53
|
+
menu?.querySelector<HTMLElement>('[aria-checked="true"]') ??
|
|
54
|
+
menu?.querySelector<HTMLElement>('[role="menuitemradio"]')
|
|
55
|
+
)?.focus()
|
|
56
|
+
}, [pos])
|
|
57
|
+
|
|
58
|
+
// A press outside, or a scroll that would leave it floating, closes it.
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
const onPointerDown = (e: PointerEvent) => {
|
|
61
|
+
const t = e.target as Node
|
|
62
|
+
if (!ref.current?.contains(t) && !anchor.current?.contains(t)) onClose()
|
|
63
|
+
}
|
|
64
|
+
const onScroll = (e: Event) => {
|
|
65
|
+
if (!ref.current?.contains(e.target as Node)) onClose()
|
|
66
|
+
}
|
|
67
|
+
document.addEventListener('pointerdown', onPointerDown)
|
|
68
|
+
window.addEventListener('scroll', onScroll, true)
|
|
69
|
+
return () => {
|
|
70
|
+
document.removeEventListener('pointerdown', onPointerDown)
|
|
71
|
+
window.removeEventListener('scroll', onScroll, true)
|
|
72
|
+
}
|
|
73
|
+
}, [anchor, onClose])
|
|
74
|
+
|
|
75
|
+
// The ARIA menu keys: arrows wrap, Home and End jump, Tab leaves (closing
|
|
76
|
+
// the menu; the dismiss stack hands the caret back to the button).
|
|
77
|
+
const onKeyDown = (e: React.KeyboardEvent) => {
|
|
78
|
+
if (e.key === 'Tab') {
|
|
79
|
+
e.preventDefault()
|
|
80
|
+
onClose()
|
|
81
|
+
return
|
|
82
|
+
}
|
|
83
|
+
const items = [
|
|
84
|
+
...(ref.current?.querySelectorAll<HTMLElement>(
|
|
85
|
+
'[role="menuitemradio"]',
|
|
86
|
+
) ?? []),
|
|
87
|
+
]
|
|
88
|
+
const i = items.indexOf(document.activeElement as HTMLElement)
|
|
89
|
+
const next = (
|
|
90
|
+
{
|
|
91
|
+
ArrowDown: (i + 1) % items.length,
|
|
92
|
+
ArrowUp: (i - 1 + items.length) % items.length,
|
|
93
|
+
Home: 0,
|
|
94
|
+
End: items.length - 1,
|
|
95
|
+
} as Record<string, number | undefined>
|
|
96
|
+
)[e.key]
|
|
97
|
+
if (next === undefined) return
|
|
98
|
+
e.preventDefault()
|
|
99
|
+
items[next]?.focus()
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const group = (title: string, options: readonly InstallOption[]) => (
|
|
103
|
+
<div role="group" aria-label={title}>
|
|
104
|
+
<div
|
|
105
|
+
aria-hidden="true"
|
|
106
|
+
className="px-2 pt-2 pb-1 text-[11px] font-extrabold tracking-[.06em] text-muted-foreground uppercase"
|
|
107
|
+
>
|
|
108
|
+
{title}
|
|
109
|
+
</div>
|
|
110
|
+
{options.map((o) => (
|
|
111
|
+
<button
|
|
112
|
+
key={o.id}
|
|
113
|
+
type="button"
|
|
114
|
+
role="menuitemradio"
|
|
115
|
+
aria-checked={o.id === current}
|
|
116
|
+
onClick={() => onPick(o.id)}
|
|
117
|
+
className="flex w-full items-center gap-2.5 rounded-[10px] px-2 py-[7px] text-left outline-none hover:bg-muted focus-visible:bg-muted"
|
|
118
|
+
>
|
|
119
|
+
<o.Icon />
|
|
120
|
+
<span className="min-w-0 flex-1">
|
|
121
|
+
<b className="block text-[13.5px]">{o.label}</b>
|
|
122
|
+
<small className="block text-xs text-muted-foreground">
|
|
123
|
+
{o.hint}
|
|
124
|
+
</small>
|
|
125
|
+
</span>
|
|
126
|
+
{o.id === current && (
|
|
127
|
+
<Check aria-hidden="true" className="size-4 text-primary" />
|
|
128
|
+
)}
|
|
129
|
+
</button>
|
|
130
|
+
))}
|
|
131
|
+
</div>
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
return createPortal(
|
|
135
|
+
<div
|
|
136
|
+
ref={ref}
|
|
137
|
+
role="menu"
|
|
138
|
+
aria-label="Choose how to install"
|
|
139
|
+
onKeyDown={onKeyDown}
|
|
140
|
+
style={{ width: WIDTH, ...pos, visibility: pos ? undefined : 'hidden' }}
|
|
141
|
+
className="fixed z-[60] rounded-[var(--radius)] border border-border bg-card p-1.5 text-foreground shadow-2xl"
|
|
142
|
+
>
|
|
143
|
+
{group(
|
|
144
|
+
'Install with',
|
|
145
|
+
VISIBLE_INSTALL_OPTIONS.filter((o) => !o.text),
|
|
146
|
+
)}
|
|
147
|
+
{group(
|
|
148
|
+
'Text only',
|
|
149
|
+
VISIBLE_INSTALL_OPTIONS.filter((o) => o.text),
|
|
150
|
+
)}
|
|
151
|
+
<div
|
|
152
|
+
data-slot="footer"
|
|
153
|
+
className="mt-1 border-t border-border px-2 pt-1.5 pb-1 text-[11.5px] text-muted-foreground"
|
|
154
|
+
>
|
|
155
|
+
We remember your choice for next time.
|
|
156
|
+
</div>
|
|
157
|
+
</div>,
|
|
158
|
+
document.body,
|
|
159
|
+
)
|
|
160
|
+
}
|