@vantageos/mosaic-blocks 0.5.35-alpha → 0.5.37-alpha
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/README.md +11 -8
- package/dist/index.cjs +828 -40
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +415 -11
- package/dist/index.d.ts +415 -11
- package/dist/index.js +809 -41
- package/dist/index.js.map +1 -1
- package/dist/styles.css +18 -0
- package/package.json +20 -7
- package/r/mosaic-accordion.json +1 -2
- package/r/mosaic-activity-feed.json +16 -0
- package/r/mosaic-adaptive-grid.json +18 -0
- package/r/mosaic-adaptive-modal.json +18 -0
- package/r/mosaic-adaptive-navigation.json +18 -0
- package/r/mosaic-add-memory-form.json +25 -0
- package/r/mosaic-admin-only-guard.json +18 -0
- package/r/mosaic-agent-builder-modal.json +23 -0
- package/r/mosaic-agent-card.json +16 -0
- package/r/mosaic-agent-chat.json +26 -0
- package/r/mosaic-agent-composer.json +28 -0
- package/r/mosaic-agent-editor.json +25 -0
- package/r/mosaic-agent-list.json +21 -0
- package/r/mosaic-agent-preview.json +21 -0
- package/r/mosaic-alert-dialog.json +23 -0
- package/r/mosaic-animated-list.json +16 -0
- package/r/mosaic-api-key-panel.json +21 -0
- package/r/mosaic-app-sidebar.json +18 -0
- package/r/mosaic-approval-prompt.json +21 -0
- package/r/mosaic-artifact-canvas-adapter.json +26 -0
- package/r/mosaic-artifact-chart.json +18 -0
- package/r/mosaic-artifact-checklist.json +18 -0
- package/r/mosaic-artifact-data-table.json +18 -0
- package/r/mosaic-artifact-document.json +16 -0
- package/r/mosaic-artifact-library.json +18 -0
- package/r/mosaic-artifact-save-as-memory-form.json +24 -0
- package/r/mosaic-artifact-version-history.json +16 -0
- package/r/mosaic-avatar.json +18 -0
- package/r/mosaic-badge.json +23 -0
- package/r/mosaic-blurred-orb.json +16 -0
- package/r/mosaic-button.json +24 -0
- package/r/mosaic-callout.json +23 -0
- package/r/mosaic-card.json +16 -0
- package/r/mosaic-chat-composer.json +21 -0
- package/r/mosaic-chat-message.json +23 -0
- package/r/mosaic-chat-sidebar.json +21 -0
- package/r/mosaic-chat-thread.json +21 -0
- package/r/mosaic-checkbox.json +18 -0
- package/r/mosaic-clerk-org-switcher.json +18 -0
- package/r/mosaic-clerk-webhook-handler.json +18 -0
- package/r/mosaic-collapsible.json +18 -0
- package/r/mosaic-combobox.json +18 -0
- package/r/mosaic-counter.json +16 -0
- package/r/mosaic-dashboard-content.json +18 -0
- package/r/mosaic-dashboard-header.json +18 -0
- package/r/mosaic-dashboard-layout.json +20 -0
- package/r/mosaic-data-table.json +16 -0
- package/r/mosaic-delete-confirmation-dialog.json +18 -0
- package/r/mosaic-device-provider.json +16 -0
- package/r/mosaic-document-table.json +52 -0
- package/r/mosaic-document-upload.json +21 -0
- package/r/mosaic-drawer.json +23 -0
- package/r/mosaic-dropdown-menu.json +18 -0
- package/r/mosaic-edit-memory-dialog.json +27 -0
- package/r/mosaic-edit-session-dialog.json +25 -0
- package/r/mosaic-editable-cell.json +23 -0
- package/r/mosaic-empty-state.json +16 -0
- package/r/mosaic-falling-pattern.json +16 -0
- package/r/mosaic-feature-3col.json +16 -0
- package/r/mosaic-feature-centered-media.json +16 -0
- package/r/mosaic-field.json +18 -0
- package/r/mosaic-filter-bar.json +18 -0
- package/r/mosaic-filter-sidebar.json +18 -0
- package/r/mosaic-footer-simple.json +16 -0
- package/r/mosaic-grille-registre.json +53 -0
- package/r/mosaic-hero-split.json +16 -0
- package/r/mosaic-input-group.json +16 -0
- package/r/mosaic-input.json +18 -0
- package/r/mosaic-integrations-badge.json +16 -0
- package/r/mosaic-kanban-board.json +21 -0
- package/r/mosaic-logos-grid.json +16 -0
- package/r/mosaic-main-nav.json +18 -0
- package/r/mosaic-markdown.json +21 -0
- package/r/mosaic-marketplace-card.json +24 -0
- package/r/mosaic-marketplace-list.json +20 -0
- package/r/mosaic-match-input.json +23 -0
- package/r/mosaic-memory-card.json +21 -0
- package/r/mosaic-memory-dashboard.json +23 -0
- package/r/mosaic-memory-grid.json +21 -0
- package/r/mosaic-memory-list.json +21 -0
- package/r/mosaic-memory-search.json +23 -0
- package/r/mosaic-mention-input.json +23 -0
- package/r/mosaic-message-card.json +16 -0
- package/r/mosaic-message-list.json +19 -0
- package/r/mosaic-message-search.json +18 -0
- package/r/mosaic-model-selector.json +23 -0
- package/r/mosaic-module-card.json +16 -0
- package/r/mosaic-module-library.json +18 -0
- package/r/mosaic-multi-tenant-provider.json +19 -0
- package/r/mosaic-navbar.json +16 -0
- package/r/mosaic-org-context-display.json +18 -0
- package/r/mosaic-org-panel.json +19 -0
- package/r/mosaic-org-profile-page.json +18 -0
- package/r/mosaic-org-switcher.json +16 -0
- package/r/mosaic-pdf-viewer.json +23 -0
- package/r/mosaic-popover.json +23 -0
- package/r/mosaic-preferences-panel.json +18 -0
- package/r/mosaic-pricing-card.json +16 -0
- package/r/mosaic-profile-panel.json +18 -0
- package/r/mosaic-progress.json +18 -0
- package/r/mosaic-quick-action-card.json +16 -0
- package/r/mosaic-quick-actions-menu.json +18 -0
- package/r/mosaic-quick-agent-selector.json +19 -0
- package/r/mosaic-radio-group.json +18 -0
- package/r/mosaic-reply-input.json +21 -0
- package/r/mosaic-resizable-split-pane.json +23 -0
- package/r/mosaic-save-chat-as-memory-form.json +25 -0
- package/r/mosaic-save-template-modal.json +27 -0
- package/r/mosaic-scroll-area.json +18 -0
- package/r/mosaic-select.json +18 -0
- package/r/mosaic-selector-modal.json +18 -0
- package/r/mosaic-separator.json +18 -0
- package/r/mosaic-session-card.json +24 -0
- package/r/mosaic-session-list.json +21 -0
- package/r/mosaic-sign-in-layout.json +18 -0
- package/r/mosaic-sign-up-layout.json +18 -0
- package/r/mosaic-skeleton.json +23 -0
- package/r/mosaic-slider.json +18 -0
- package/r/mosaic-stats-grid.json +16 -0
- package/r/mosaic-step-pipeline.json +21 -0
- package/r/mosaic-switch.json +18 -0
- package/r/mosaic-tabs.json +18 -0
- package/r/mosaic-tag-input.json +23 -0
- package/r/mosaic-template-agent-card.json +21 -0
- package/r/mosaic-template-category-chips.json +21 -0
- package/r/mosaic-template-gallery.json +20 -0
- package/r/mosaic-template-list.json +21 -0
- package/r/mosaic-template-management-panel.json +25 -0
- package/r/mosaic-testimonials-grid.json +16 -0
- package/r/mosaic-textarea.json +16 -0
- package/r/mosaic-theme-provider.json +18 -0
- package/r/mosaic-theme-toggle.json +16 -0
- package/r/mosaic-thread-indicator.json +21 -0
- package/r/mosaic-thread-view.json +21 -0
- package/r/mosaic-toast.json +28 -0
- package/r/mosaic-tool-toggle-list.json +23 -0
- package/r/mosaic-tooltip.json +18 -0
- package/r/mosaic-url-scraper.json +21 -0
- package/r/mosaic-user-button.json +18 -0
- package/r/use-effective-workspace-id.json +18 -0
- package/registry.json +77 -130
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
|
|
3
|
+
"name": "mosaic-match-input",
|
|
4
|
+
"title": "MosaicMatchInput",
|
|
5
|
+
"description": "MosaicMatchInput — autocomplete carrying a match state",
|
|
6
|
+
"dependencies": [],
|
|
7
|
+
"registryDependencies": [
|
|
8
|
+
"https://cdn.jsdelivr.net/npm/@vantageos/mosaic-blocks@0.5.37-alpha/r/mosaic-combobox.json"
|
|
9
|
+
],
|
|
10
|
+
"files": [
|
|
11
|
+
{
|
|
12
|
+
"path": "src/components/match-input/MosaicMatchInput.tsx",
|
|
13
|
+
"type": "registry:ui",
|
|
14
|
+
"content": "/**\n * MosaicMatchInput — autocomplete carrying a match state\n *\n * Composes MosaicCombobox (no autocomplete re-implementation) and adds a\n * match-state indicator. `matchState` and `stateLabels` are REQUIRED\n * props: the four match states are match semantics, never business\n * logic, and the host owns every label — no English fallback.\n *\n * data-slot=\"match-input\" on the wrapper div.\n */\n\nimport {\n MosaicCombobox,\n type MosaicComboboxItem,\n type MosaicComboboxProps,\n} from \"@/components/ui/MosaicCombobox\";\nimport { matchStateSignal, matchStateVariants } from \"./match-input-variants.js\";\n\n// ── Utility ───────────────────────────────────────────────────────────────────\n\nfunction cn(...classes: (string | undefined | null | false)[]): string {\n return classes.filter(Boolean).join(\" \");\n}\n\n// ── Types ─────────────────────────────────────────────────────────────────────\n\nexport type MosaicMatchInputState = \"exact\" | \"partial\" | \"ambiguous\" | \"none\";\n\nexport interface MosaicMatchInputStateLabels {\n exact: string;\n partial: string;\n ambiguous: string;\n none: string;\n}\n\nexport interface MosaicMatchInputProps extends Omit<MosaicComboboxProps, \"disabled\" | \"className\"> {\n /** Required — the four match states are match semantics, never inferred. */\n matchState: MosaicMatchInputState;\n /** Required — the host owns every label, no default copy is generated. */\n stateLabels: MosaicMatchInputStateLabels;\n /** Locked mode: the input becomes read-only/disabled. */\n locked?: boolean;\n className?: string;\n}\n\nexport type { MosaicComboboxItem };\n\n// ── Component ─────────────────────────────────────────────────────────────────\n\n/**\n * MosaicMatchInput — combobox + match-state indicator.\n *\n * @example\n * <MosaicMatchInput\n * items={items}\n * matchState=\"ambiguous\"\n * stateLabels={{\n * exact: t('MatchInput.exact'),\n * partial: t('MatchInput.partial'),\n * ambiguous: t('MatchInput.ambiguous'),\n * none: t('MatchInput.none'),\n * }}\n * emptyMessage={t('MatchInput.empty')}\n * />\n */\nexport function MosaicMatchInput({\n matchState,\n stateLabels,\n locked,\n className,\n ...comboboxProps\n}: MosaicMatchInputProps) {\n const { role, ariaLive } = matchStateSignal(matchState);\n const label = stateLabels[matchState];\n\n return (\n <div data-slot=\"match-input\" className={cn(\"flex flex-col gap-1\", className)}>\n <MosaicCombobox {...comboboxProps} disabled={locked} />\n <span\n role={role}\n aria-live={ariaLive}\n data-match-state={matchState}\n className={matchStateVariants({ matchState })}\n >\n {label}\n </span>\n </div>\n );\n}\n\nMosaicMatchInput.displayName = \"MosaicMatchInput\";\n"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"path": "src/components/match-input/match-input-variants.ts",
|
|
18
|
+
"type": "registry:ui",
|
|
19
|
+
"content": "/**\n * matchStateVariants — pure CVA variant function for the match-state\n * indicator rendered by MosaicMatchInput.\n *\n * Each match state maps to a distinct visual + accessible signal so the\n * four states are mutually distinguishable BY THE COMPONENT, independent\n * of whatever label text the host passes in\n * (see MosaicMatchInput.test.tsx negative-pole tests, which pass an\n * IDENTICAL label for all four states on purpose).\n *\n * Zero browser / React runtime dependencies — safe in RSC / Node.js.\n */\n\nimport { cva } from \"class-variance-authority\";\n\nexport const matchStateVariants = cva([\"text-xs font-medium\"], {\n variants: {\n matchState: {\n exact: \"text-success-700\",\n partial: \"text-warning-700\",\n ambiguous: \"text-warning-700\",\n none: \"text-destructive\",\n },\n },\n defaultVariants: {\n matchState: \"none\",\n },\n});\n\nexport type MosaicMatchInputMatchState = \"exact\" | \"partial\" | \"ambiguous\" | \"none\";\n\nexport interface MatchStateSignal {\n role: \"status\" | \"alert\";\n ariaLive: \"off\" | \"polite\" | \"assertive\";\n}\n\n/**\n * Accessible (role, aria-live) pair per match state. Every one of the four\n * states carries a DIFFERENT pair, so any two states are distinguishable\n * from each other purely from these DOM attributes — never from the\n * label text, which the host controls and must not be relied upon.\n *\n * - exact: status / off — resolved, nothing to announce\n * - partial: status / polite — informational, low urgency\n * - ambiguous: alert / assertive — the dangerous state: a wrong\n * candidate could be silently accepted, so it is the MOST\n * urgent signal, distinct from both \"partial\" (role) and\n * \"none\" (aria-live)\n * - none: alert / polite — terminal, no decision pending, so\n * alert without the assertive urgency of \"ambiguous\"\n */\nexport function matchStateSignal(matchState: MosaicMatchInputMatchState): MatchStateSignal {\n switch (matchState) {\n case \"exact\":\n return { role: \"status\", ariaLive: \"off\" };\n case \"partial\":\n return { role: \"status\", ariaLive: \"polite\" };\n case \"ambiguous\":\n return { role: \"alert\", ariaLive: \"assertive\" };\n case \"none\":\n return { role: \"alert\", ariaLive: \"polite\" };\n }\n}\n"
|
|
20
|
+
}
|
|
21
|
+
],
|
|
22
|
+
"type": "registry:ui"
|
|
23
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
|
|
3
|
+
"name": "mosaic-memory-card",
|
|
4
|
+
"title": "MosaicMemoryCard",
|
|
5
|
+
"description": "MosaicMemoryCard — memory item card (detailed / compact variants)",
|
|
6
|
+
"dependencies": [],
|
|
7
|
+
"registryDependencies": [],
|
|
8
|
+
"files": [
|
|
9
|
+
{
|
|
10
|
+
"path": "src/components/memory-card/MosaicMemoryCard.tsx",
|
|
11
|
+
"type": "registry:ui",
|
|
12
|
+
"content": "\"use client\";\n\n/**\n * MosaicMemoryCard — memory item card (detailed / compact variants)\n *\n * Ported from any-debate-ai's memory-card-desktop.tsx + memory-card-mobile.tsx\n * as ONE component with a `variant` prop, not two components. What actually\n * differed between the two source files:\n * - Layout density: detailed uses a leading icon chip + title/scope-badge\n * stack + separate content paragraph + tags row + footer with a labelled\n * usage count; compact folds title + content into one truncated header\n * row and drops the tags row entirely. Both variants call\n * `formatUsageCount` for the footer usage count — the caller decides\n * whether that renders a label or a bare number.\n * - Hover-reveal actions: the 3-dot menu trigger is `opacity-0\n * group-hover:opacity-100` in detailed (desktop hover affordance), always\n * visible in compact (no hover on touch).\n * - Scope badge chrome: bordered in detailed, borderless in compact.\n * Everything else (scope colors, source icon, edit/delete menu, time-ago\n * footer) is shared and modeled once.\n *\n * Pattern: MosaicAgentCard.tsx (data-slot, manual dropdown + outside-click\n * close, inline SVG icons, React 19 ref prop, displayName, JSDoc).\n * No \"use client\" side effects beyond menu state — prepend-use-client.mjs\n * adds the directive to dist regardless.\n * Design tokens: --card, --card-foreground, --border, --muted-foreground,\n * --accent, --accent-foreground, --destructive, --popover, --ring.\n * No icon library — inline SVGs only (no lucide-react dependency in this repo).\n * a11y: dropdown via role=\"menu\"/\"menuitem\", aria-haspopup, aria-expanded,\n * required aria-label on the trigger.\n * Bilingual (SIN-01): zero user-facing strings hardcoded. Every label is a\n * required prop or a required formatter function — no optional prop with an\n * English default anywhere in this file.\n *\n * Props are pushed into the `MosaicMemoryCardVariantProps` discriminated\n * union exactly where they are read — no prop is required on a variant that\n * never renders it. `formatMoreTags` is required only on the `\"detailed\"`\n * (default) member: the `\"compact\"` variant drops the tags row entirely and\n * never calls it, so it is not part of `\"compact\"`'s member of the union\n * (fixed after being flagged as a \"lying prop contract\" by the\n * `no-lying-prop-contract` guard test — see that file and the memory-card's\n * own type definitions below).\n *\n * Closes T1 (bu-mcp memory wave) — mosaic-memory-card.\n *\n * @example\n * // Detailed variant (default) — full card with tags row and labelled footer\n * <MosaicMemoryCard\n * memory={memory}\n * editLabel=\"Edit\"\n * deleteLabel=\"Delete\"\n * moreActionsLabel=\"Memory actions\"\n * formatScope={(scope) => t(`memory.scope.${scope}`)}\n * formatTimeAgo={(createdAt) => formatRelative(createdAt)}\n * formatUsageCount={(count) => t(\"memory.usageCount\", { count })}\n * formatMoreTags={(count) => `+${count}`}\n * onEdit={(m) => openEditDialog(m)}\n * onDelete={(id) => deleteMemory(id)}\n * />\n *\n * @example\n * // Compact variant — condensed list row, no tags row. formatUsageCount is\n * // still called here; this host simply chooses to render the bare number.\n * <MosaicMemoryCard\n * memory={memory}\n * variant=\"compact\"\n * editLabel=\"Modifier\"\n * deleteLabel=\"Supprimer\"\n * moreActionsLabel=\"Actions sur le souvenir\"\n * formatScope={(scope) => t(`memory.scope.${scope}`)}\n * formatTimeAgo={(createdAt) => formatRelative(createdAt)}\n * formatUsageCount={(count) => `${count}`}\n * formatMoreTags={(count) => `+${count}`}\n * />\n */\n\nimport * as React from \"react\";\nimport {\n memoryActionsMenuTriggerVariants,\n memoryCardVariants,\n memoryScopeBadgeVariants,\n memoryTagBadgeVariants,\n} from \"./memory-card-variants.js\";\n\n// ── Utility ───────────────────────────────────────────────────────────────────\n\nfunction cn(...classes: (string | undefined | null | false)[]): string {\n return classes.filter(Boolean).join(\" \");\n}\n\n// ── Types ─────────────────────────────────────────────────────────────────────\n\nexport type MosaicMemoryScope = \"organization\" | \"workspace\" | \"user\" | \"chat\";\nexport type MosaicMemorySource = \"manual\" | \"document\" | \"url\";\n\nexport interface MosaicMemoryData {\n id: string;\n title: string;\n content: string;\n scope: MosaicMemoryScope;\n source: MosaicMemorySource;\n tags: string[];\n /** Epoch milliseconds. */\n createdAt: number;\n usageCount: number;\n}\n\n/**\n * Props shared by both variants — read unconditionally regardless of\n * `variant`.\n */\nexport interface MosaicMemoryCardBaseProps {\n memory: MosaicMemoryData;\n onEdit?: (memory: MosaicMemoryData) => void;\n onDelete?: (memoryId: string) => void;\n /** Label for the \"edit\" menu item. Required — host-owned, no default. */\n editLabel: string;\n /** Label for the \"delete\" menu item. Required — host-owned, no default. */\n deleteLabel: string;\n /** aria-label for the 3-dot actions menu trigger. Required — host-owned, no default. */\n moreActionsLabel: string;\n /**\n * Formatter mapping `memory.scope` to its displayed label. Required — the\n * host owns the language (e.g. `(scope) => t(\\`memory.scope.\\${scope}\\`)`).\n */\n formatScope: (scope: MosaicMemoryScope) => React.ReactNode;\n /**\n * Formatter producing the relative time caption from `memory.createdAt`.\n * Required — the host owns date formatting and language\n * (e.g. `(createdAt) => t(\"memory.timeAgo\", { value: formatRelative(createdAt) })`).\n */\n formatTimeAgo: (createdAt: number) => React.ReactNode;\n /**\n * Formatter producing the labelled usage-count caption from\n * `memory.usageCount`. Applied in BOTH variants — the raw number is never\n * rendered directly. A host that wants the bare number in compact passes\n * `formatUsageCount={(count) => String(count)}`; that is the host's\n * choice, not a hidden default of the library.\n * Required — host-owned (e.g. `(count) => t(\"memory.usageCount\", { count })`).\n */\n formatUsageCount: (count: number) => React.ReactNode;\n className?: string;\n /** React 19 ref prop — forwarded to the root element. */\n ref?: React.Ref<HTMLDivElement>;\n}\n\n/**\n * Discriminated union on `variant` — the sole property that differs between\n * variants (`formatMoreTags`) is required EXACTLY on the branch that reads\n * it (`\"detailed\"`, the default), not on the shared base. The `\"compact\"`\n * variant never renders a tags row and therefore never calls\n * `formatMoreTags` — requiring it there would force every host to supply a\n * value the library never displays (a \"lying prop contract\"; see the\n * `no-lying-prop-contract` guard test and the file's changelog note below).\n */\nexport type MosaicMemoryCardVariantProps =\n | {\n /**\n * Full-density layout: icon chip + tags row + labelled usage footer.\n * Default when omitted.\n * @default \"detailed\"\n */\n variant?: \"detailed\";\n /**\n * Formatter producing the \"+N\" overflow caption when a memory has more\n * than 3 tags. Only ever rendered in the detailed variant — required\n * here, not on `\"compact\"`. Host-owned (e.g. `(count) => \\`+\\${count}\\``\n * or a pluralized `t()` call).\n */\n formatMoreTags: (count: number) => React.ReactNode;\n }\n | {\n /** Condensed list row, no tags row, no `formatMoreTags` call. */\n variant: \"compact\";\n };\n\nexport type MosaicMemoryCardProps = MosaicMemoryCardBaseProps & MosaicMemoryCardVariantProps;\n\nconst MAX_VISIBLE_TAGS = 3;\n\n// ── Inline SVG icons ──────────────────────────────────────────────────────────\n\nfunction FileTextIcon() {\n return (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"16\"\n height=\"16\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n >\n <path d=\"M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z\" />\n <polyline points=\"14 2 14 8 20 8\" />\n <line x1=\"16\" y1=\"13\" x2=\"8\" y2=\"13\" />\n <line x1=\"16\" y1=\"17\" x2=\"8\" y2=\"17\" />\n <line x1=\"10\" y1=\"9\" x2=\"8\" y2=\"9\" />\n </svg>\n );\n}\n\nfunction FileIcon() {\n return (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"16\"\n height=\"16\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n >\n <path d=\"M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z\" />\n <polyline points=\"14 2 14 8 20 8\" />\n </svg>\n );\n}\n\nfunction LinkIcon() {\n return (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"16\"\n height=\"16\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n >\n <path d=\"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71\" />\n <path d=\"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71\" />\n </svg>\n );\n}\n\nfunction ClockIcon() {\n return (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"12\"\n height=\"12\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n >\n <circle cx=\"12\" cy=\"12\" r=\"10\" />\n <polyline points=\"12 6 12 12 16 14\" />\n </svg>\n );\n}\n\nfunction TagIcon() {\n return (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"12\"\n height=\"12\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n >\n <path d=\"M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z\" />\n <circle cx=\"7.5\" cy=\"7.5\" r=\"1.5\" />\n </svg>\n );\n}\n\nfunction MoreVertIcon() {\n return (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"16\"\n height=\"16\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n >\n <circle cx=\"12\" cy=\"5\" r=\"1\" />\n <circle cx=\"12\" cy=\"12\" r=\"1\" />\n <circle cx=\"12\" cy=\"19\" r=\"1\" />\n </svg>\n );\n}\n\nconst SOURCE_ICONS: Record<MosaicMemorySource, () => React.ReactElement> = {\n manual: FileTextIcon,\n document: FileIcon,\n url: LinkIcon,\n};\n\n// ── Component ─────────────────────────────────────────────────────────────────\n\n/**\n * MosaicMemoryCard — production memory-item card for @vantageos/mosaic-blocks.\n *\n * One component, two density variants (`detailed` default / `compact`) —\n * see file JSDoc for the exact desktop/mobile differences and how they were\n * modeled as `variant` + CVA compound variants rather than as two components.\n */\nexport function MosaicMemoryCard(props: MosaicMemoryCardProps) {\n const {\n memory,\n onEdit,\n onDelete,\n editLabel,\n deleteLabel,\n moreActionsLabel,\n formatScope,\n formatTimeAgo,\n formatUsageCount,\n className,\n ref,\n } = props;\n const variant = props.variant ?? \"detailed\";\n const [menuOpen, setMenuOpen] = React.useState(false);\n const menuRef = React.useRef<HTMLDivElement>(null);\n const SourceIcon = SOURCE_ICONS[memory.source];\n\n React.useEffect(() => {\n if (!menuOpen) return;\n const handler = (event: MouseEvent) => {\n if (menuRef.current && !menuRef.current.contains(event.target as Node)) {\n setMenuOpen(false);\n }\n };\n document.addEventListener(\"mousedown\", handler);\n return () => document.removeEventListener(\"mousedown\", handler);\n }, [menuOpen]);\n\n const visibleTags = memory.tags.slice(0, MAX_VISIBLE_TAGS);\n const hiddenTagCount = memory.tags.length - visibleTags.length;\n\n const actionsMenu = (\n <div ref={menuRef} className=\"relative shrink-0\">\n <button\n type=\"button\"\n onClick={() => setMenuOpen((open) => !open)}\n aria-label={moreActionsLabel}\n aria-haspopup=\"menu\"\n aria-expanded={menuOpen}\n className={cn(memoryActionsMenuTriggerVariants({ variant }))}\n >\n <MoreVertIcon />\n </button>\n\n {menuOpen && (\n <div\n role=\"menu\"\n className={cn(\n \"absolute right-0 top-full z-50 mt-1 min-w-[140px] rounded-md border border-border\",\n \"bg-popover py-1 shadow-md\",\n )}\n >\n {onEdit && (\n <button\n type=\"button\"\n role=\"menuitem\"\n onClick={() => {\n onEdit(memory);\n setMenuOpen(false);\n }}\n className=\"flex w-full items-center px-3 py-2 text-sm text-foreground hover:bg-accent hover:text-accent-foreground\"\n >\n {editLabel}\n </button>\n )}\n {onDelete && (\n <button\n type=\"button\"\n role=\"menuitem\"\n onClick={() => {\n onDelete(memory.id);\n setMenuOpen(false);\n }}\n className=\"flex w-full items-center px-3 py-2 text-sm text-destructive hover:bg-destructive/10\"\n >\n {deleteLabel}\n </button>\n )}\n </div>\n )}\n </div>\n );\n\n return (\n <div\n ref={ref}\n data-slot=\"memory-card\"\n data-variant={variant}\n className={cn(memoryCardVariants({ variant }), className)}\n >\n {props.variant !== \"compact\" ? (\n <div className=\"space-y-3\">\n {/* Header */}\n <div className=\"flex items-start justify-between gap-3\">\n <div className=\"flex min-w-0 flex-1 items-start gap-3\">\n <div className=\"rounded-lg bg-muted p-2 text-muted-foreground\">\n <SourceIcon />\n </div>\n <div className=\"min-w-0 flex-1\">\n <h3 className=\"line-clamp-1 text-base font-semibold\">{memory.title}</h3>\n <span\n className={cn(\n memoryScopeBadgeVariants({ scope: memory.scope, bordered: true }),\n \"mt-1\",\n )}\n >\n {formatScope(memory.scope)}\n </span>\n </div>\n </div>\n {actionsMenu}\n </div>\n\n {/* Content */}\n <p className=\"line-clamp-3 text-sm text-muted-foreground\">{memory.content}</p>\n\n {/* Tags */}\n <div data-slot=\"memory-tags\" className=\"flex flex-wrap gap-1\">\n {visibleTags.map((tag) => (\n <span key={tag} className={cn(memoryTagBadgeVariants())}>\n {tag}\n </span>\n ))}\n {hiddenTagCount > 0 && (\n <span className={cn(memoryTagBadgeVariants())}>\n {props.formatMoreTags(hiddenTagCount)}\n </span>\n )}\n </div>\n\n {/* Footer */}\n <div className=\"flex items-center justify-between border-t pt-2 text-xs text-muted-foreground\">\n <span className=\"flex items-center gap-1\">\n <ClockIcon />\n {formatTimeAgo(memory.createdAt)}\n </span>\n <span className=\"flex items-center gap-1\">\n <TagIcon />\n {formatUsageCount(memory.usageCount)}\n </span>\n </div>\n </div>\n ) : (\n <div className=\"space-y-2\">\n {/* Header */}\n <div className=\"flex items-start justify-between gap-2\">\n <div className=\"min-w-0 flex-1\">\n <h3 className=\"line-clamp-1 text-sm font-medium\">{memory.title}</h3>\n <p className=\"mt-1 line-clamp-2 text-xs text-muted-foreground\">{memory.content}</p>\n </div>\n <div className=\"flex shrink-0 items-center gap-1 text-muted-foreground\">\n <SourceIcon />\n {actionsMenu}\n </div>\n </div>\n\n {/* Footer */}\n <div className=\"flex items-center justify-between gap-2 text-xs text-muted-foreground\">\n <div className=\"flex items-center gap-2\">\n <span\n className={cn(memoryScopeBadgeVariants({ scope: memory.scope, bordered: false }))}\n >\n {formatScope(memory.scope)}\n </span>\n <span className=\"flex items-center gap-1\">\n <ClockIcon />\n {formatTimeAgo(memory.createdAt)}\n </span>\n </div>\n <span className=\"flex items-center gap-1\">\n <TagIcon />\n {formatUsageCount(memory.usageCount)}\n </span>\n </div>\n </div>\n )}\n </div>\n );\n}\n\nMosaicMemoryCard.displayName = \"MosaicMemoryCard\";\n"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"path": "src/components/memory-card/memory-card-variants.ts",
|
|
16
|
+
"type": "registry:ui",
|
|
17
|
+
"content": "/**\n * memoryCardVariants — pure CVA variant functions for MosaicMemoryCard.\n *\n * Isolated in their own module so they can be re-exported from the\n * `@vantageos/mosaic-blocks/server` subpath without pulling in React.\n *\n * Zero browser / React runtime dependencies — safe in RSC / Node.js.\n */\n\nimport { cva } from \"class-variance-authority\";\n\n/** Root card container variants */\nexport const memoryCardVariants = cva(\n [\n \"group relative rounded-lg border border-border bg-card text-card-foreground shadow-sm\",\n \"transition-all\",\n ],\n {\n variants: {\n variant: {\n detailed: \"p-5 hover:shadow-lg\",\n compact: \"min-h-[80px] p-4\",\n },\n },\n defaultVariants: {\n variant: \"detailed\",\n },\n },\n);\n\n/** Scope badge — colored per memory scope, bordered only in the detailed variant */\nexport const memoryScopeBadgeVariants = cva(\n [\"inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium\"],\n {\n variants: {\n scope: {\n organization: \"bg-purple-500/10 text-purple-500\",\n workspace: \"bg-blue-500/10 text-blue-500\",\n user: \"bg-green-500/10 text-green-500\",\n chat: \"bg-orange-500/10 text-orange-500\",\n },\n bordered: {\n true: \"border\",\n false: \"\",\n },\n },\n compoundVariants: [\n { scope: \"organization\", bordered: true, className: \"border-purple-500/20\" },\n { scope: \"workspace\", bordered: true, className: \"border-blue-500/20\" },\n { scope: \"user\", bordered: true, className: \"border-green-500/20\" },\n { scope: \"chat\", bordered: true, className: \"border-orange-500/20\" },\n ],\n defaultVariants: {\n scope: \"user\",\n bordered: false,\n },\n },\n);\n\n/** Tag badge (detailed variant only) */\nexport const memoryTagBadgeVariants = cva([\n \"inline-flex items-center rounded-full border border-border px-2 py-0.5 text-xs\",\n]);\n\n/** Actions menu trigger button — hover-reveal in detailed, always visible in compact */\nexport const memoryActionsMenuTriggerVariants = cva(\n [\n \"inline-flex items-center justify-center rounded-md text-muted-foreground transition-opacity\",\n \"hover:bg-accent hover:text-accent-foreground\",\n \"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\",\n ],\n {\n variants: {\n variant: {\n detailed: \"h-11 w-11 opacity-0 group-hover:opacity-100 group-focus-within:opacity-100\",\n compact: \"h-8 w-8\",\n },\n },\n defaultVariants: {\n variant: \"detailed\",\n },\n },\n);\n"
|
|
18
|
+
}
|
|
19
|
+
],
|
|
20
|
+
"type": "registry:ui"
|
|
21
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
|
|
3
|
+
"name": "mosaic-memory-dashboard",
|
|
4
|
+
"title": "MosaicMemoryDashboard",
|
|
5
|
+
"description": "MosaicMemoryDashboard — landing surface of a knowledge base: a header with a title and a primary \"add\" action, a row of host-supplied summary statistics, an optional slot for a search bar, a host-controlled view-mode toggle (tiles / rows), and a slot for results.",
|
|
6
|
+
"dependencies": [],
|
|
7
|
+
"registryDependencies": [
|
|
8
|
+
"https://cdn.jsdelivr.net/npm/@vantageos/mosaic-blocks@0.5.37-alpha/r/mosaic-button.json"
|
|
9
|
+
],
|
|
10
|
+
"files": [
|
|
11
|
+
{
|
|
12
|
+
"path": "src/components/memory-dashboard/MosaicMemoryDashboard.tsx",
|
|
13
|
+
"type": "registry:ui",
|
|
14
|
+
"content": "\"use client\";\n\n/**\n * MosaicMemoryDashboard — landing surface of a knowledge base: a header with\n * a title and a primary \"add\" action, a row of host-supplied summary\n * statistics, an optional slot for a search bar, a host-controlled view-mode\n * toggle (tiles / rows), and a slot for results.\n *\n * Pure composition — this component never fetches, searches, filters, counts,\n * or invents anything. The statistics are host data (each with its own\n * host-supplied label and value); this component renders exactly the array\n * it is given, in the order it is given, with no minimum or maximum count\n * assumed. Search and results are host-owned React nodes passed in as\n * `searchSlot` and `children` — this component does not implement a search\n * bar or a list itself.\n *\n * The active view mode is a prop (`viewMode`), never internal state invented\n * by this component — toggling it is a callback (`onViewModeChange`) that the\n * host decides how to honor.\n *\n * Every user-facing string is a required prop with no default — this library\n * carries zero words (SIN-01), bilingual FR+EN by design. `searchSlot` and\n * `children` are optional because their absence encodes a real absence of\n * state (no search bar composed / no results yet) — not a missing word.\n *\n * data-slot=\"memory-dashboard\" on the root, data-slot=\"memory-dashboard-stats\"\n * on the stats row, data-slot=\"memory-dashboard-stat\" per stat,\n * data-slot=\"memory-dashboard-search\" on the search slot wrapper (rendered\n * only when `searchSlot` is supplied), data-slot=\"memory-dashboard-view-toggle\"\n * on the toggle group, data-slot=\"memory-dashboard-results\" on the results\n * slot wrapper.\n *\n * Deps: @base-ui/react (via MosaicButton) + class-variance-authority only.\n */\n\nimport type * as React from \"react\";\nimport { MosaicButton } from \"@/components/ui/Button\";\nimport { memoryDashboardViewToggleButtonVariants } from \"./memory-dashboard-variants.js\";\n\n// ── Utility ───────────────────────────────────────────────────────────────────\n\nfunction cn(...classes: (string | undefined | null | false)[]): string {\n return classes.filter(Boolean).join(\" \");\n}\n\n// ── Types ─────────────────────────────────────────────────────────────────────\n\nexport type MosaicMemoryDashboardViewMode = \"tiles\" | \"rows\";\n\nexport interface MosaicMemoryDashboardStat {\n /** Host-owned statistic label — pure data, never invented by this component. */\n label: string;\n /** Host-owned statistic value — pure data, never computed by this component. */\n value: string;\n}\n\nexport interface MosaicMemoryDashboardProps {\n /** Dashboard title. Required, no default. */\n title: string;\n /** Label for the primary \"add\" action button. Required, no default. */\n addLabel: string;\n /** Called when the primary \"add\" action is activated. */\n onAdd: () => void;\n /**\n * Host-supplied summary statistics. Pure data — never fetched, computed, or\n * invented here. Rendered exactly as given, in order, with no assumed count.\n */\n stats: MosaicMemoryDashboardStat[];\n /**\n * Optional host-owned search bar node. Absence means no search bar is\n * composed for this instance — a real absence of state, not a missing word.\n */\n searchSlot?: React.ReactNode;\n /** Current view mode. Host-controlled — this component holds no internal state for it. */\n viewMode: MosaicMemoryDashboardViewMode;\n /** Called with the requested view mode when a toggle button is activated. */\n onViewModeChange: (mode: MosaicMemoryDashboardViewMode) => void;\n /** Label for the \"tiles\" view toggle button. Required, no default. */\n tilesViewLabel: string;\n /** Label for the \"rows\" view toggle button. Required, no default. */\n rowsViewLabel: string;\n /**\n * Host-owned results content, rendered in the results slot. Absence means\n * no results have been composed yet — a real absence of state.\n */\n children?: React.ReactNode;\n className?: string;\n}\n\n// ── Component ─────────────────────────────────────────────────────────────────\n\n/**\n * MosaicMemoryDashboard — production knowledge-base landing surface for\n * @vantageos/mosaic-blocks.\n *\n * @example\n * <MosaicMemoryDashboard\n * title=\"Knowledge base\"\n * addLabel=\"Add memory\"\n * onAdd={() => openAddMemoryForm()}\n * stats={[{ label: \"Total memories\", value: \"128\" }, { label: \"Namespaces\", value: \"6\" }]}\n * searchSlot={<SearchBar />}\n * viewMode={viewMode}\n * onViewModeChange={setViewMode}\n * tilesViewLabel=\"Tiles\"\n * rowsViewLabel=\"Rows\"\n * >\n * <ResultsList />\n * </MosaicMemoryDashboard>\n */\nexport function MosaicMemoryDashboard({\n title,\n addLabel,\n onAdd,\n stats,\n searchSlot,\n viewMode,\n onViewModeChange,\n tilesViewLabel,\n rowsViewLabel,\n children,\n className,\n}: MosaicMemoryDashboardProps) {\n return (\n <div\n data-slot=\"memory-dashboard\"\n className={cn(\n \"flex flex-col gap-4 rounded-lg border border-border bg-background p-4\",\n className,\n )}\n >\n <div className=\"flex items-center justify-between gap-3\">\n <h1 className=\"font-semibold text-foreground text-lg\">{title}</h1>\n <MosaicButton type=\"button\" onClick={onAdd}>\n {addLabel}\n </MosaicButton>\n </div>\n\n {stats.length > 0 && (\n <div data-slot=\"memory-dashboard-stats\" className=\"grid grid-cols-2 gap-3 sm:grid-cols-4\">\n {stats.map((stat) => (\n <div\n key={stat.label}\n data-slot=\"memory-dashboard-stat\"\n className=\"flex flex-col rounded-md border border-border px-3 py-2\"\n >\n <span className=\"font-semibold text-foreground text-lg tabular-nums\">\n {stat.value}\n </span>\n <span className=\"text-muted-foreground text-xs\">{stat.label}</span>\n </div>\n ))}\n </div>\n )}\n\n {searchSlot && (\n <div data-slot=\"memory-dashboard-search\" className=\"w-full\">\n {searchSlot}\n </div>\n )}\n\n <div data-slot=\"memory-dashboard-view-toggle\" className=\"flex items-center gap-2 self-start\">\n <button\n type=\"button\"\n aria-pressed={viewMode === \"tiles\"}\n onClick={() => onViewModeChange(\"tiles\")}\n className={memoryDashboardViewToggleButtonVariants({ pressed: viewMode === \"tiles\" })}\n >\n {tilesViewLabel}\n </button>\n <button\n type=\"button\"\n aria-pressed={viewMode === \"rows\"}\n onClick={() => onViewModeChange(\"rows\")}\n className={memoryDashboardViewToggleButtonVariants({ pressed: viewMode === \"rows\" })}\n >\n {rowsViewLabel}\n </button>\n </div>\n\n <div data-slot=\"memory-dashboard-results\" className=\"flex flex-col gap-2\">\n {children}\n </div>\n </div>\n );\n}\n\nMosaicMemoryDashboard.displayName = \"MosaicMemoryDashboard\";\n"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"path": "src/components/memory-dashboard/memory-dashboard-variants.ts",
|
|
18
|
+
"type": "registry:ui",
|
|
19
|
+
"content": "import { cva } from \"class-variance-authority\";\n\nexport const memoryDashboardViewToggleButtonVariants = cva(\n \"flex items-center justify-center rounded-md border border-border px-3 py-1.5 text-sm transition-colors\",\n {\n variants: {\n pressed: {\n true: \"bg-foreground text-background\",\n false: \"bg-background text-muted-foreground hover:bg-muted\",\n },\n },\n defaultVariants: {\n pressed: false,\n },\n },\n);\n"
|
|
20
|
+
}
|
|
21
|
+
],
|
|
22
|
+
"type": "registry:ui"
|
|
23
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
|
|
3
|
+
"name": "mosaic-memory-grid",
|
|
4
|
+
"title": "MosaicMemoryGrid",
|
|
5
|
+
"description": "MosaicMemoryGrid — presentational, tile-disposition-only grid of host items",
|
|
6
|
+
"dependencies": [],
|
|
7
|
+
"registryDependencies": [],
|
|
8
|
+
"files": [
|
|
9
|
+
{
|
|
10
|
+
"path": "src/components/memory-grid/MosaicMemoryGrid.tsx",
|
|
11
|
+
"type": "registry:ui",
|
|
12
|
+
"content": "/**\n * MosaicMemoryGrid — presentational, tile-disposition-only grid of host items\n *\n * The tile presentation of a knowledge base: a responsive grid of tiles, one\n * per entry. `MosaicMemoryList` is its row-disposition sibling — both take\n * the SAME `items` + `renderItem` + `emptyMessage` contract and differ ONLY\n * in the container's Tailwind layout classes (`memory-grid-variants.ts` vs.\n * `memory-list-variants.ts`).\n *\n * The grid owns disposition ONLY:\n * - `items`: the host's array of entries, each requiring only an `id`.\n * - `renderItem`: the host-supplied per-entry renderer — the grid never\n * renders a tile of its own and never hardcodes a field, a category, a\n * sort order, or any domain content (no-hardcoded-business-knowledge).\n * - `emptyMessage`: required, no default (SIN-01) — the host owns the\n * language, e.g. `t('MemoryGrid.empty')`.\n *\n * Keyboard: roving tabindex across items (native `<ul>` / `<li>` — semantic\n * list roles come from the elements themselves, no explicit `role` needed)\n * — ArrowRight/ArrowDown moves focus to the next item, ArrowLeft/ArrowUp to\n * the previous, Home/End jump to the first/last. Exactly one item is\n * `tabIndex={0}` at a time; the rest are `tabIndex={-1}`.\n */\n\nimport type * as React from \"react\";\nimport { useRef, useState } from \"react\";\nimport { memoryGridVariants } from \"./memory-grid-variants.js\";\n\n// ── Utility ───────────────────────────────────────────────────────────────────\n\nfunction cn(...classes: (string | undefined | null | false)[]): string {\n return classes.filter(Boolean).join(\" \");\n}\n\n// ── Types ─────────────────────────────────────────────────────────────────────\n\nexport interface MosaicMemoryGridProps<T extends { id: string }> {\n /** The entries to lay out as tiles. The grid never inspects their shape beyond `id`. */\n items: T[];\n /** Host-owned renderer for a single entry — the grid owns disposition only. */\n renderItem: (item: T, index: number) => React.ReactNode;\n /** Tile density: \"comfortable\" (default) or \"compact\". Changes gap only. */\n density?: \"comfortable\" | \"compact\";\n /**\n * Message shown when `items` is empty. Required, no default — the host\n * owns the language (e.g. `t('MemoryGrid.empty')`).\n */\n emptyMessage: string;\n /** Additional Tailwind classes on the root container. */\n className?: string;\n /** Additional Tailwind classes on each tile wrapper. */\n itemClassName?: string;\n /** React 19 ref prop — forwarded to the root container. */\n ref?: React.Ref<HTMLDivElement | HTMLUListElement>;\n}\n\n// ── Keyboard navigation ───────────────────────────────────────────────────────\n\nconst NEXT_KEYS = new Set([\"ArrowRight\", \"ArrowDown\"]);\nconst PREV_KEYS = new Set([\"ArrowLeft\", \"ArrowUp\"]);\n\n// ── Component ─────────────────────────────────────────────────────────────────\n\n/**\n * MosaicMemoryGrid — production tile-disposition atom for\n * @vantageos/mosaic-blocks.\n *\n * Purely presentational: no filtering, no sorting, no item rendering — the\n * host owns the entry content via `renderItem`; this component only owns\n * the tile grid layout and keyboard roving-tabindex navigation.\n */\nexport function MosaicMemoryGrid<T extends { id: string }>({\n items,\n renderItem,\n density = \"comfortable\",\n emptyMessage,\n className,\n itemClassName,\n ref,\n}: MosaicMemoryGridProps<T>) {\n const itemRefs = useRef<Array<HTMLLIElement | null>>([]);\n const [focusedIndex, setFocusedIndex] = useState(0);\n\n function focusItem(index: number) {\n if (items.length === 0) {\n return;\n }\n const clamped = Math.max(0, Math.min(items.length - 1, index));\n setFocusedIndex(clamped);\n itemRefs.current[clamped]?.focus();\n }\n\n function handleKeyDown(event: React.KeyboardEvent<HTMLLIElement>, index: number) {\n if (NEXT_KEYS.has(event.key)) {\n event.preventDefault();\n focusItem(index + 1);\n } else if (PREV_KEYS.has(event.key)) {\n event.preventDefault();\n focusItem(index - 1);\n } else if (event.key === \"Home\") {\n event.preventDefault();\n focusItem(0);\n } else if (event.key === \"End\") {\n event.preventDefault();\n focusItem(items.length - 1);\n }\n }\n\n if (items.length === 0) {\n return (\n <div\n ref={ref as React.Ref<HTMLDivElement> | undefined}\n data-slot=\"memory-grid\"\n className={cn(memoryGridVariants({ density }), className)}\n >\n <p\n data-slot=\"memory-grid-empty\"\n className=\"col-span-full py-12 text-center text-sm text-muted-foreground\"\n >\n {emptyMessage}\n </p>\n </div>\n );\n }\n\n return (\n <ul\n ref={ref as React.Ref<HTMLUListElement> | undefined}\n data-slot=\"memory-grid\"\n className={cn(\"list-none\", memoryGridVariants({ density }), className)}\n >\n {items.map((item, index) => (\n <li\n key={item.id}\n ref={(node) => {\n itemRefs.current[index] = node;\n }}\n data-slot=\"memory-grid-item\"\n tabIndex={index === focusedIndex ? 0 : -1}\n onKeyDown={(event) => handleKeyDown(event, index)}\n onFocus={() => setFocusedIndex(index)}\n className={itemClassName}\n >\n {renderItem(item, index)}\n </li>\n ))}\n </ul>\n );\n}\n\nMosaicMemoryGrid.displayName = \"MosaicMemoryGrid\";\n"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"path": "src/components/memory-grid/memory-grid-variants.ts",
|
|
16
|
+
"type": "registry:ui",
|
|
17
|
+
"content": "/**\n * memoryGridVariants — pure CVA variant function for MosaicMemoryGrid.\n *\n * Isolated in its own module so it can be re-exported from the\n * `@vantageos/mosaic-blocks/server` subpath without pulling in React.\n *\n * Zero browser / React runtime dependencies — safe in RSC / Node.js.\n */\n\nimport { cva } from \"class-variance-authority\";\n\n/**\n * Root container layout — a responsive tile grid. Owns disposition ONLY;\n * item content is entirely host-supplied via `renderItem`.\n */\nexport const memoryGridVariants = cva([\"grid\", \"grid-cols-1 sm:grid-cols-2 lg:grid-cols-3\"], {\n variants: {\n density: {\n comfortable: \"gap-4\",\n compact: \"gap-2\",\n },\n },\n defaultVariants: {\n density: \"comfortable\",\n },\n});\n"
|
|
18
|
+
}
|
|
19
|
+
],
|
|
20
|
+
"type": "registry:ui"
|
|
21
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
|
|
3
|
+
"name": "mosaic-memory-list",
|
|
4
|
+
"title": "MosaicMemoryList",
|
|
5
|
+
"description": "MosaicMemoryList — presentational, row-disposition-only list of host items",
|
|
6
|
+
"dependencies": [],
|
|
7
|
+
"registryDependencies": [],
|
|
8
|
+
"files": [
|
|
9
|
+
{
|
|
10
|
+
"path": "src/components/memory-list/MosaicMemoryList.tsx",
|
|
11
|
+
"type": "registry:ui",
|
|
12
|
+
"content": "/**\n * MosaicMemoryList — presentational, row-disposition-only list of host items\n *\n * The row presentation of a knowledge base: a single-column stack of\n * divided rows, one per entry. `MosaicMemoryGrid` is its tile-disposition\n * sibling — both take the SAME `items` + `renderItem` + `emptyMessage`\n * contract and differ ONLY in the container's Tailwind layout classes\n * (`memory-list-variants.ts` vs. `memory-grid-variants.ts`).\n *\n * The list owns disposition ONLY:\n * - `items`: the host's array of entries, each requiring only an `id`.\n * - `renderItem`: the host-supplied per-entry renderer — the list never\n * renders a row of its own and never hardcodes a field, a category, a\n * sort order, or any domain content (no-hardcoded-business-knowledge).\n * - `emptyMessage`: required, no default (SIN-01) — the host owns the\n * language, e.g. `t('MemoryList.empty')`.\n *\n * Keyboard: roving tabindex across items (native `<ul>` / `<li>` — semantic\n * list roles come from the elements themselves, no explicit `role` needed)\n * — ArrowDown/ArrowRight moves focus to the next row, ArrowUp/ArrowLeft to\n * the previous, Home/End jump to the first/last. Exactly one item is\n * `tabIndex={0}` at a time; the rest are `tabIndex={-1}`.\n */\n\nimport type * as React from \"react\";\nimport { useRef, useState } from \"react\";\nimport { memoryListItemVariants, memoryListVariants } from \"./memory-list-variants.js\";\n\n// ── Utility ───────────────────────────────────────────────────────────────────\n\nfunction cn(...classes: (string | undefined | null | false)[]): string {\n return classes.filter(Boolean).join(\" \");\n}\n\n// ── Types ─────────────────────────────────────────────────────────────────────\n\nexport interface MosaicMemoryListProps<T extends { id: string }> {\n /** The entries to lay out as rows. The list never inspects their shape beyond `id`. */\n items: T[];\n /** Host-owned renderer for a single entry — the list owns disposition only. */\n renderItem: (item: T, index: number) => React.ReactNode;\n /** Row density: \"comfortable\" (default) or \"compact\". Changes row padding only. */\n density?: \"comfortable\" | \"compact\";\n /**\n * Message shown when `items` is empty. Required, no default — the host\n * owns the language (e.g. `t('MemoryList.empty')`).\n */\n emptyMessage: string;\n /** Additional Tailwind classes on the root container. */\n className?: string;\n /** Additional Tailwind classes on each row wrapper. */\n itemClassName?: string;\n /** React 19 ref prop — forwarded to the root container. */\n ref?: React.Ref<HTMLDivElement | HTMLUListElement>;\n}\n\n// ── Keyboard navigation ───────────────────────────────────────────────────────\n\nconst NEXT_KEYS = new Set([\"ArrowRight\", \"ArrowDown\"]);\nconst PREV_KEYS = new Set([\"ArrowLeft\", \"ArrowUp\"]);\n\n// ── Component ─────────────────────────────────────────────────────────────────\n\n/**\n * MosaicMemoryList — production row-disposition atom for\n * @vantageos/mosaic-blocks.\n *\n * Purely presentational: no filtering, no sorting, no item rendering — the\n * host owns the entry content via `renderItem`; this component only owns\n * the row list layout and keyboard roving-tabindex navigation.\n */\nexport function MosaicMemoryList<T extends { id: string }>({\n items,\n renderItem,\n density = \"comfortable\",\n emptyMessage,\n className,\n itemClassName,\n ref,\n}: MosaicMemoryListProps<T>) {\n const itemRefs = useRef<Array<HTMLLIElement | null>>([]);\n const [focusedIndex, setFocusedIndex] = useState(0);\n\n function focusItem(index: number) {\n if (items.length === 0) {\n return;\n }\n const clamped = Math.max(0, Math.min(items.length - 1, index));\n setFocusedIndex(clamped);\n itemRefs.current[clamped]?.focus();\n }\n\n function handleKeyDown(event: React.KeyboardEvent<HTMLLIElement>, index: number) {\n if (NEXT_KEYS.has(event.key)) {\n event.preventDefault();\n focusItem(index + 1);\n } else if (PREV_KEYS.has(event.key)) {\n event.preventDefault();\n focusItem(index - 1);\n } else if (event.key === \"Home\") {\n event.preventDefault();\n focusItem(0);\n } else if (event.key === \"End\") {\n event.preventDefault();\n focusItem(items.length - 1);\n }\n }\n\n if (items.length === 0) {\n return (\n <div\n ref={ref as React.Ref<HTMLDivElement> | undefined}\n data-slot=\"memory-list\"\n className={cn(memoryListVariants({ density }), className)}\n >\n <p\n data-slot=\"memory-list-empty\"\n className=\"py-12 text-center text-sm text-muted-foreground\"\n >\n {emptyMessage}\n </p>\n </div>\n );\n }\n\n return (\n <ul\n ref={ref as React.Ref<HTMLUListElement> | undefined}\n data-slot=\"memory-list\"\n className={cn(\"list-none\", memoryListVariants({ density }), className)}\n >\n {items.map((item, index) => (\n <li\n key={item.id}\n ref={(node) => {\n itemRefs.current[index] = node;\n }}\n data-slot=\"memory-list-item\"\n tabIndex={index === focusedIndex ? 0 : -1}\n onKeyDown={(event) => handleKeyDown(event, index)}\n onFocus={() => setFocusedIndex(index)}\n className={cn(memoryListItemVariants({ density }), itemClassName)}\n >\n {renderItem(item, index)}\n </li>\n ))}\n </ul>\n );\n}\n\nMosaicMemoryList.displayName = \"MosaicMemoryList\";\n"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"path": "src/components/memory-list/memory-list-variants.ts",
|
|
16
|
+
"type": "registry:ui",
|
|
17
|
+
"content": "/**\n * memoryListVariants — pure CVA variant function for MosaicMemoryList.\n *\n * Isolated in its own module so it can be re-exported from the\n * `@vantageos/mosaic-blocks/server` subpath without pulling in React.\n *\n * Zero browser / React runtime dependencies — safe in RSC / Node.js.\n */\n\nimport { cva } from \"class-variance-authority\";\n\n/**\n * Root container layout — a single-column, divided row stack. Owns\n * disposition ONLY; item content is entirely host-supplied via `renderItem`.\n */\nexport const memoryListVariants = cva([\"flex flex-col\", \"divide-y divide-border\"], {\n variants: {\n density: {\n comfortable: \"\",\n compact: \"\",\n },\n },\n defaultVariants: {\n density: \"comfortable\",\n },\n});\n\n/**\n * Per-row wrapper — owns the row's vertical rhythm (density-dependent\n * padding). Isolated from `memoryListVariants` because it targets the\n * `<li>` wrapper, not the `<ul>` root.\n */\nexport const memoryListItemVariants = cva([], {\n variants: {\n density: {\n comfortable: \"py-3\",\n compact: \"py-1\",\n },\n },\n defaultVariants: {\n density: \"comfortable\",\n },\n});\n"
|
|
18
|
+
}
|
|
19
|
+
],
|
|
20
|
+
"type": "registry:ui"
|
|
21
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
|
|
3
|
+
"name": "mosaic-memory-search",
|
|
4
|
+
"title": "MosaicMemorySearch",
|
|
5
|
+
"description": "MosaicMemorySearch — search bar over a host-supplied knowledge base: a query input, optional filter chips (by type/tag), a clear action, and a result-count indication.",
|
|
6
|
+
"dependencies": [],
|
|
7
|
+
"registryDependencies": [
|
|
8
|
+
"https://cdn.jsdelivr.net/npm/@vantageos/mosaic-blocks@0.5.37-alpha/r/mosaic-input.json"
|
|
9
|
+
],
|
|
10
|
+
"files": [
|
|
11
|
+
{
|
|
12
|
+
"path": "src/components/memory-search/MosaicMemorySearch.tsx",
|
|
13
|
+
"type": "registry:ui",
|
|
14
|
+
"content": "/**\n * MosaicMemorySearch — search bar over a host-supplied knowledge base: a\n * query input, optional filter chips (by type/tag), a clear action, and a\n * result-count indication.\n *\n * Fully controlled, presentational atom: `query` + `onQueryChange` own the\n * text; the component never searches anything itself. It has no idea what\n * \"type\" or \"tag\" means — the entire filter catalogue (`filters`) is\n * host-supplied DATA, exactly like `MosaicTemplateCategoryChips`. A client\n * with a different taxonomy (legal, healthcare, e-commerce) supplies its own\n * filter list without touching this package.\n *\n * The result count is never assembled by this component: `resultCount` is a\n * number, and `formatResultCount` is a host-supplied function that turns it\n * into a localized, pluralized string (e.g. `(n) => n === 1 ? \"1 result\" :\n * \\`${n} results\\`` or the FR equivalent). Pluralisation is a language; this\n * library speaks none (SIN-01).\n *\n * The clear action only appears once `query` is non-empty — that switch is\n * genuinely presentation state, not a missing word, so `clearButtonLabel`\n * remains a required prop with no default (the host always supplies it, the\n * button simply isn't rendered until there is something to clear).\n *\n * `filters` / `selectedFilterIds` / `onFilterToggle` are optional as a GROUP:\n * a host that has no filter feature at all renders the search bar with none\n * of the three, and no filter chip row is rendered. That optionality encodes\n * the absence of the whole filter FEATURE, not a missing word — every label\n * that IS rendered (each `filter.label`) is still host-owned data, required\n * on the filter object itself.\n *\n * No \"use client\" — prepend-use-client.mjs adds it to dist.\n * Design tokens: --primary, --primary-foreground, --background, --foreground,\n * --border, --muted, --muted-foreground, --input, --ring.\n * a11y: the query input is `type=\"search\"` with an explicit `aria-label`\n * (`searchLabel`, host-owned — no host is forced to also render a visible\n * `<label>`). Each filter chip is a real `<button>` with `aria-pressed` so\n * the selection state reaches screen-reader users without relying on color.\n * The clear button carries its own required `aria-label` for the same\n * reason.\n *\n * Deps: @base-ui/react (via MosaicInput) + class-variance-authority only.\n *\n * @example\n * <MosaicMemorySearch\n * query={query}\n * onQueryChange={setQuery}\n * searchLabel=\"Search knowledge base\"\n * searchPlaceholder=\"Search…\"\n * clearButtonLabel=\"Clear search\"\n * resultCount={results.length}\n * formatResultCount={(n) => (n === 1 ? \"1 result\" : `${n} results`)}\n * filters={[\n * { id: \"type-note\", label: \"Note\" },\n * { id: \"type-decision\", label: \"Decision\" },\n * ]}\n * selectedFilterIds={selectedFilterIds}\n * onFilterToggle={toggleFilter}\n * />\n */\n\nimport type * as React from \"react\";\nimport { MosaicInput } from \"@/components/ui/MosaicInput\";\nimport { memorySearchFilterChipVariants } from \"./memory-search-variants.js\";\n\n// ── Utility ───────────────────────────────────────────────────────────────────\n\nfunction cn(...classes: (string | undefined | null | false)[]): string {\n return classes.filter(Boolean).join(\" \");\n}\n\n// ── Types ─────────────────────────────────────────────────────────────────────\n\n/**\n * One selectable filter (type, tag, or any other host-defined facet). The\n * library knows nothing about any filter by name — the whole catalogue is\n * host-supplied DATA.\n */\nexport interface MosaicMemorySearchFilter {\n /** Stable identifier, matched against `selectedFilterIds` and passed to `onFilterToggle`. */\n id: string;\n /** Host-supplied, host-localized display label. No built-in taxonomy. */\n label: string;\n}\n\nexport interface MosaicMemorySearchProps {\n /** Current query text. Controlled by the host. */\n query: string;\n /** Called with the new query text on every keystroke. */\n onQueryChange: (query: string) => void;\n /** aria-label for the query input. Required, no default. */\n searchLabel: string;\n /** Placeholder for the query input. Required, no default. */\n searchPlaceholder: string;\n /** aria-label for the clear button. Required, no default — rendered only once `query` is non-empty. */\n clearButtonLabel: string;\n /** Total number of results for the current query/filters. Pure data — never computed here. */\n resultCount: number;\n /**\n * Derives the displayed result-count string from `resultCount`. Required —\n * the host owns pluralisation and language, this component never\n * assembles a count string itself.\n */\n formatResultCount: (count: number) => string;\n /**\n * Full open catalogue of filters — a PROP, never a library constant. Omit\n * entirely (with `selectedFilterIds` and `onFilterToggle`) when the host\n * has no filter feature; no filter chip row is then rendered.\n */\n filters?: MosaicMemorySearchFilter[];\n /** Ids of the currently selected filters. Controlled by the host. */\n selectedFilterIds?: string[];\n /** Called with the filter id when a chip is activated. */\n onFilterToggle?: (id: string) => void;\n /** Additional Tailwind classes on the root element. */\n className?: string;\n /** React 19 ref prop — forwarded to the root element. */\n ref?: React.Ref<HTMLDivElement>;\n}\n\n// ── Inline icons ──────────────────────────────────────────────────────────────\n\nfunction SearchIcon() {\n return (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"16\"\n height=\"16\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n >\n <circle cx=\"11\" cy=\"11\" r=\"8\" />\n <line x1=\"21\" y1=\"21\" x2=\"16.65\" y2=\"16.65\" />\n </svg>\n );\n}\n\nfunction ClearIcon() {\n return (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"14\"\n height=\"14\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n >\n <line x1=\"18\" y1=\"6\" x2=\"6\" y2=\"18\" />\n <line x1=\"6\" y1=\"6\" x2=\"18\" y2=\"18\" />\n </svg>\n );\n}\n\n// ── Component ─────────────────────────────────────────────────────────────────\n\n/**\n * MosaicMemorySearch — production search bar for @vantageos/mosaic-blocks.\n *\n * Purely presentational + controlled: renders the query input, an optional\n * host-supplied filter-chip row, a clear action, and a host-formatted\n * result-count string. No network call, no internal query state, no\n * hardcoded filter catalogue.\n */\nexport function MosaicMemorySearch({\n query,\n onQueryChange,\n searchLabel,\n searchPlaceholder,\n clearButtonLabel,\n resultCount,\n formatResultCount,\n filters,\n selectedFilterIds,\n onFilterToggle,\n className,\n ref,\n}: MosaicMemorySearchProps) {\n return (\n <div ref={ref} data-slot=\"memory-search\" className={cn(\"flex flex-col gap-2\", className)}>\n <div className=\"relative\">\n <span className=\"absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground\">\n <SearchIcon />\n </span>\n <MosaicInput\n type=\"search\"\n aria-label={searchLabel}\n placeholder={searchPlaceholder}\n value={query}\n onChange={(event: React.ChangeEvent<HTMLInputElement>) =>\n onQueryChange(event.target.value)\n }\n className=\"pl-9 pr-9\"\n />\n {query.length > 0 && (\n <button\n type=\"button\"\n aria-label={clearButtonLabel}\n onClick={() => onQueryChange(\"\")}\n className={cn(\n \"absolute right-2 top-1/2 -translate-y-1/2\",\n \"flex size-5 items-center justify-center rounded-full\",\n \"text-muted-foreground hover:bg-muted hover:text-foreground\",\n \"focus-visible:outline-none focus-visible:ring-ring focus-visible:ring-[3px]\",\n )}\n >\n <ClearIcon />\n </button>\n )}\n </div>\n\n {filters && filters.length > 0 && (\n <div data-slot=\"memory-search-filters\" className=\"flex flex-wrap items-center gap-2\">\n {filters.map((filter) => {\n const isSelected = (selectedFilterIds ?? []).includes(filter.id);\n return (\n <button\n key={filter.id}\n type=\"button\"\n data-slot=\"memory-search-filter-chip\"\n aria-pressed={isSelected}\n onClick={() => onFilterToggle?.(filter.id)}\n className={memorySearchFilterChipVariants({ selected: isSelected })}\n >\n {filter.label}\n </button>\n );\n })}\n </div>\n )}\n\n <p data-slot=\"memory-search-result-count\" className=\"text-sm text-muted-foreground\">\n {formatResultCount(resultCount)}\n </p>\n </div>\n );\n}\n\nMosaicMemorySearch.displayName = \"MosaicMemorySearch\";\n"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"path": "src/components/memory-search/memory-search-variants.ts",
|
|
18
|
+
"type": "registry:ui",
|
|
19
|
+
"content": "/**\n * memorySearchFilterChipVariants — pure CVA variant function for the\n * optional filter chips rendered by MosaicMemorySearch.\n *\n * Isolated in its own module so it can be re-exported from the\n * `@vantageos/mosaic-blocks/server` subpath without pulling in React.\n *\n * Zero browser / React runtime dependencies — safe in RSC / Node.js.\n */\n\nimport { cva } from \"class-variance-authority\";\n\n/** One filter chip button — selected vs. unselected tone. */\nexport const memorySearchFilterChipVariants = cva(\n [\n \"inline-flex items-center justify-center whitespace-nowrap\",\n \"rounded-full border px-3 py-1 gap-1\",\n \"text-xs font-medium transition-colors\",\n \"focus-visible:outline-none focus-visible:ring-ring focus-visible:ring-[3px]\",\n ],\n {\n variants: {\n selected: {\n true: \"border-transparent bg-primary text-primary-foreground\",\n false: \"border-border bg-background text-foreground hover:bg-muted\",\n },\n },\n defaultVariants: {\n selected: false,\n },\n },\n);\n"
|
|
20
|
+
}
|
|
21
|
+
],
|
|
22
|
+
"type": "registry:ui"
|
|
23
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
|
|
3
|
+
"name": "mosaic-mention-input",
|
|
4
|
+
"title": "MosaicMentionInput",
|
|
5
|
+
"description": "MosaicMentionInput — text input that opens an anchored, host-owned list of mentionable entries when the host-chosen trigger character is typed.",
|
|
6
|
+
"dependencies": [],
|
|
7
|
+
"registryDependencies": [
|
|
8
|
+
"https://cdn.jsdelivr.net/npm/@vantageos/mosaic-blocks@0.5.37-alpha/r/mosaic-popover.json"
|
|
9
|
+
],
|
|
10
|
+
"files": [
|
|
11
|
+
{
|
|
12
|
+
"path": "src/components/mention-input/MosaicMentionInput.tsx",
|
|
13
|
+
"type": "registry:ui",
|
|
14
|
+
"content": "\"use client\";\n\n/**\n * MosaicMentionInput — text input that opens an anchored, host-owned list of\n * mentionable entries when the host-chosen trigger character is typed.\n *\n * Built on `MosaicPopover` for anchoring and dismissal (Escape, outside\n * click) — this component does not re-implement either. It owns exactly\n * three things:\n * 1. Detecting the trigger character and the query fragment typed after it,\n * reported to the host via `onQueryChange` — the host decides what\n * \"matches\" means, this component never filters.\n * 2. Roving keyboard navigation (ArrowUp/ArrowDown, wrap-free, clamped) over\n * whichever entries the host currently supplies via `entries`.\n * 3. Inserting the host-chosen text for the selected entry back into the\n * input value and reporting the selection via `onSelectEntry`.\n *\n * The mentionable entries themselves — their data, their rendering, and the\n * decision of which ones currently match the typed query — belong entirely\n * to the host, exactly like `MosaicTemplateList`'s `renderItem` idiom: this\n * component never hardcodes, invents, fetches, or filters an entry.\n *\n * SIN-01: the component carries zero visible strings. `inputAriaLabel`,\n * `listAriaLabel`, and `emptyMessage` are all required props with no\n * default — the host supplies every word.\n *\n * Trigger-detection note: scans backward from the caret for the trigger\n * character, stopping at the first whitespace. This models a single-glyph\n * trigger (e.g. \"@\") — the common case; a multi-character trigger is not a\n * supported shape here.\n */\n\nimport type * as React from \"react\";\nimport { useRef, useState } from \"react\";\nimport { MosaicPopover } from \"@/components/ui/MosaicPopover\";\nimport {\n mentionInputFieldVariants,\n mentionListItemVariants,\n mentionListVariants,\n} from \"./mention-input-variants.js\";\n\n// ── Utility ──────────────────────────────────────────────────────────────────\n\nfunction cn(...classes: (string | undefined | null | false)[]): string {\n return classes.filter(Boolean).join(\" \");\n}\n\n/**\n * Scans backward from `cursor` for `trigger`, stopping at the first\n * whitespace character. Returns the index of the trigger character, or\n * `null` when the caret is not currently inside a mention context.\n */\nfunction findMentionStart(text: string, cursor: number, trigger: string): number | null {\n for (let i = cursor - 1; i >= 0; i--) {\n const char = text[i];\n if (char === trigger) {\n return i;\n }\n if (/\\s/.test(char)) {\n return null;\n }\n }\n return null;\n}\n\n// ── Types ────────────────────────────────────────────────────────────────────\n\nexport interface MosaicMentionInputProps<T extends { id: string }> {\n /** Controlled input value — the host owns the truth. */\n value: string;\n /** Called with the next value on every keystroke and on mention insertion. */\n onValueChange: (value: string) => void;\n /** The character that opens the mention list (e.g. \"@\"). Single glyph. */\n triggerCharacter: string;\n /**\n * The entries to show in the list. Host-owned and, when the host is\n * filtering as the user types, already filtered — this component never\n * inspects or narrows this array itself.\n */\n entries: T[];\n /** Host-owned renderer for a single entry; `active` marks the roving selection. */\n renderEntry: (entry: T, index: number, active: boolean) => React.ReactNode;\n /** Host-owned mapping from an entry to the plain text inserted on selection. */\n getEntryText: (entry: T) => string;\n /**\n * Called with the fragment typed after the trigger character (may be an\n * empty string right after the trigger), or `null` when the caret is not\n * inside a mention context (list closed).\n */\n onQueryChange: (query: string | null) => void;\n /** Called with the chosen entry when the host or user picks one. */\n onSelectEntry?: (entry: T) => void;\n /** Required accessible name for the text input — no default (SIN-01). */\n inputAriaLabel: string;\n /** Required accessible name for the entries list — no default (SIN-01). */\n listAriaLabel: string;\n /** Required message shown when `entries` is empty while the list is open. */\n emptyMessage: string;\n className?: string;\n inputClassName?: string;\n}\n\n/**\n * MosaicMentionInput — production mention-input atom for\n * @vantageos/mosaic-blocks.\n *\n * @example\n * <MosaicMentionInput\n * value={draft}\n * onValueChange={setDraft}\n * triggerCharacter=\"@\"\n * entries={filteredPeople}\n * getEntryText={(person) => person.name}\n * renderEntry={(person, _i, active) => (\n * <PersonRow person={person} active={active} />\n * )}\n * onQueryChange={(query) => setFragment(query)}\n * onSelectEntry={(person) => trackMention(person)}\n * inputAriaLabel={t('Composer.inputLabel')}\n * listAriaLabel={t('Composer.mentionListLabel')}\n * emptyMessage={t('Composer.noMatches')}\n * />\n */\nexport function MosaicMentionInput<T extends { id: string }>({\n value,\n onValueChange,\n triggerCharacter,\n entries,\n renderEntry,\n getEntryText,\n onQueryChange,\n onSelectEntry,\n inputAriaLabel,\n listAriaLabel,\n emptyMessage,\n className,\n inputClassName,\n}: MosaicMentionInputProps<T>) {\n const inputRef = useRef<HTMLInputElement>(null);\n const [mentionStart, setMentionStart] = useState<number | null>(null);\n const [activeIndex, setActiveIndex] = useState(0);\n\n const open = mentionStart !== null;\n\n function closeMention() {\n setMentionStart(null);\n setActiveIndex(0);\n onQueryChange(null);\n }\n\n function handleChange(event: React.ChangeEvent<HTMLInputElement>) {\n const nextValue = event.target.value;\n const cursor = event.target.selectionStart ?? nextValue.length;\n onValueChange(nextValue);\n\n const start = findMentionStart(nextValue, cursor, triggerCharacter);\n if (start === null) {\n if (open) {\n closeMention();\n }\n return;\n }\n setMentionStart(start);\n setActiveIndex(0);\n onQueryChange(nextValue.slice(start + triggerCharacter.length, cursor));\n }\n\n function selectEntry(entry: T) {\n if (mentionStart === null || !inputRef.current) {\n return;\n }\n const cursor = inputRef.current.selectionStart ?? value.length;\n const insertText = getEntryText(entry);\n const nextValue = `${value.slice(0, mentionStart)}${insertText} ${value.slice(cursor)}`;\n onValueChange(nextValue);\n onSelectEntry?.(entry);\n closeMention();\n }\n\n function handleKeyDown(event: React.KeyboardEvent<HTMLInputElement>) {\n if (!open) {\n return;\n }\n if (event.key === \"Escape\") {\n event.preventDefault();\n closeMention();\n return;\n }\n if (event.key === \"ArrowDown\") {\n event.preventDefault();\n setActiveIndex((index) => Math.min(entries.length - 1, index + 1));\n return;\n }\n if (event.key === \"ArrowUp\") {\n event.preventDefault();\n setActiveIndex((index) => Math.max(0, index - 1));\n return;\n }\n if (event.key === \"Enter\") {\n const entry = entries[activeIndex];\n if (entry) {\n event.preventDefault();\n selectEntry(entry);\n }\n }\n }\n\n return (\n <div data-slot=\"mention-input\" className={className}>\n <input\n ref={inputRef}\n type=\"text\"\n aria-label={inputAriaLabel}\n value={value}\n onChange={handleChange}\n onKeyDown={handleKeyDown}\n className={cn(mentionInputFieldVariants(), inputClassName)}\n />\n <MosaicPopover\n open={open}\n onOpenChange={(nextOpen) => {\n if (!nextOpen) {\n closeMention();\n }\n }}\n anchor={inputRef}\n initialFocus={false}\n aria-label={listAriaLabel}\n >\n {entries.length === 0 ? (\n <p data-slot=\"mention-input-empty\" className=\"px-2 py-1.5 text-sm text-muted-foreground\">\n {emptyMessage}\n </p>\n ) : (\n <ul data-slot=\"mention-input-list\" className={mentionListVariants()}>\n {entries.map((entry, index) => (\n <li\n key={entry.id}\n data-slot=\"mention-input-item\"\n aria-selected={index === activeIndex}\n className={mentionListItemVariants({ active: index === activeIndex })}\n onMouseEnter={() => setActiveIndex(index)}\n onClick={() => selectEntry(entry)}\n onKeyDown={(event) => {\n if (event.key === \"Enter\" || event.key === \" \") {\n event.preventDefault();\n selectEntry(entry);\n }\n }}\n >\n {renderEntry(entry, index, index === activeIndex)}\n </li>\n ))}\n </ul>\n )}\n </MosaicPopover>\n </div>\n );\n}\n\nMosaicMentionInput.displayName = \"MosaicMentionInput\";\n"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"path": "src/components/mention-input/mention-input-variants.ts",
|
|
18
|
+
"type": "registry:ui",
|
|
19
|
+
"content": "/**\n * mentionInputVariants — pure CVA variant functions for MosaicMentionInput.\n *\n * Isolated in its own module so it can be re-exported from the\n * `@vantageos/mosaic-blocks/server` subpath without pulling in React or\n * @base-ui/react.\n *\n * Zero browser / React runtime dependencies — safe in RSC / Node.js.\n */\n\nimport { cva } from \"class-variance-authority\";\n\n/** The text input itself. */\nexport const mentionInputFieldVariants = cva([\n \"flex w-full rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm\",\n \"outline-none transition-colors placeholder:text-muted-foreground\",\n \"focus-visible:ring-1 focus-visible:ring-ring\",\n \"disabled:cursor-not-allowed disabled:opacity-50\",\n]);\n\n/** The mentionable-entries list surface. */\nexport const mentionListVariants = cva([\"m-0 max-h-64 list-none overflow-y-auto p-1\"]);\n\n/** A single entry row inside the list — active variant highlights the roving selection. */\nexport const mentionListItemVariants = cva(\n [\"cursor-pointer rounded-sm px-2 py-1.5 text-sm outline-none\"],\n {\n variants: {\n active: {\n true: \"bg-accent text-accent-foreground\",\n false: \"\",\n },\n },\n defaultVariants: {\n active: false,\n },\n },\n);\n"
|
|
20
|
+
}
|
|
21
|
+
],
|
|
22
|
+
"type": "registry:ui"
|
|
23
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
|
|
3
|
+
"name": "mosaic-message-card",
|
|
4
|
+
"title": "MosaicMessageCard",
|
|
5
|
+
"description": "Generic message/chat card. Sender avatar, like/dislike, bookmark, copy, reply. Compact mode.",
|
|
6
|
+
"dependencies": [],
|
|
7
|
+
"registryDependencies": [],
|
|
8
|
+
"files": [
|
|
9
|
+
{
|
|
10
|
+
"path": "src/components/message-card/MosaicMessageCard.tsx",
|
|
11
|
+
"type": "registry:ui",
|
|
12
|
+
"content": "\"use client\";\n\n/**\n * MosaicMessageCard — generic message/chat card\n *\n * Ported from components/messages/message-card.tsx\n *\n * Features:\n * - Sender avatar (initials fallback) + name + type badge\n * - Message content + relative timestamp\n * - Like/dislike reactions, reply count, bookmark, copy, reply actions\n * - Compact mode\n *\n * Stripped: ChatMessage type from lib/chat/types, sonner toast, formatRelativeTime util.\n * Reactions managed as uncontrolled local state (callbacks still fire).\n */\n\nimport * as React from \"react\";\n\n// ── Utility ───────────────────────────────────────────────────────────────────\n\nfunction cn(...classes: (string | undefined | null | false)[]): string {\n return classes.filter(Boolean).join(\" \");\n}\n\nfunction relativeTime(ts: string | number | Date): string {\n const now = Date.now();\n const then = new Date(ts).getTime();\n const diff = Math.floor((now - then) / 1000);\n if (diff < 60) return \"just now\";\n if (diff < 3600) return `${Math.floor(diff / 60)}m ago`;\n if (diff < 86400) return `${Math.floor(diff / 3600)}h ago`;\n return `${Math.floor(diff / 86400)}d ago`;\n}\n\n// ── Types ─────────────────────────────────────────────────────────────────────\n\nexport type MosaicMessageSenderType = \"user\" | \"ai\" | \"system\";\n\nexport interface MosaicMessageSender {\n id: string;\n name: string;\n type: MosaicMessageSenderType;\n avatarUrl?: string;\n /** Tailwind bg class for the avatar (e.g. \"bg-green-500\") */\n accentColor?: string;\n}\n\nexport interface MosaicMessageReactions {\n likes?: number;\n dislikes?: number;\n}\n\nexport interface MosaicMessage {\n id: string;\n content: string;\n sender: MosaicMessageSender;\n timestamp: string | number | Date;\n reactions?: MosaicMessageReactions;\n replyCount?: number;\n parentMessageId?: string;\n bookmarked?: boolean;\n}\n\nexport interface MosaicMessageCardProps {\n message: MosaicMessage;\n onReply?: (messageId: string) => void;\n onReaction?: (messageId: string, type: \"like\" | \"dislike\") => void;\n onBookmark?: (messageId: string) => void;\n onCopy?: (messageId: string, content: string) => void;\n showThread?: boolean;\n compact?: boolean;\n /** Label for the reply button. Required — host-owned, no default. */\n replyLabel: string;\n /** aria-label for the more-options menu trigger. Required — host-owned, no default. */\n moreOptionsAriaLabel: string;\n /** aria-label for the bookmark button when currently bookmarked. Required, no default. */\n removeBookmarkAriaLabel: string;\n /** aria-label for the bookmark button when not bookmarked. Required, no default. */\n bookmarkAriaLabel: string;\n /** Label for the bookmark toggle menu item when currently bookmarked. Required, no default. */\n removeBookmarkLabel: string;\n /** Label for the bookmark toggle menu item when not bookmarked. Required, no default. */\n bookmarkLabel: string;\n /** Label for the \"copy message\" menu item. Required, no default. */\n copyMessageLabel: string;\n /**\n * Label for the sender-type badge shown next to an AI sender's name.\n * Optional and host-owned — no default, no fallback word. When the sender\n * is an AI (`message.sender.type === \"ai\"`) and this label is provided,\n * the badge renders with it; when omitted, no badge renders at all. The\n * library carries no English/French word of its own for this UI state.\n */\n aiSenderLabel?: string;\n /** Label for the \"view thread\" button, shown when the message has a parent. Required, no default. */\n viewThreadLabel: string;\n /**\n * aria-label for the like button, shown for AI-sender messages. Required —\n * the host formats/pluralizes the count, the library owns no word.\n */\n likeAriaLabel: (count: number) => string;\n /**\n * aria-label for the dislike button, shown for AI-sender messages. Required —\n * the host formats/pluralizes the count, the library owns no word.\n */\n dislikeAriaLabel: (count: number) => string;\n className?: string;\n}\n\n// ── Inline icons ──────────────────────────────────────────────────────────────\n\nconst icons = {\n user: (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"14\"\n height=\"14\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n >\n <path d=\"M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2\" />\n <circle cx=\"12\" cy=\"7\" r=\"4\" />\n </svg>\n ),\n bot: (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"14\"\n height=\"14\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n >\n <rect x=\"3\" y=\"11\" width=\"18\" height=\"10\" rx=\"2\" />\n <circle cx=\"12\" cy=\"5\" r=\"2\" />\n <path d=\"M12 7v4\" />\n <line x1=\"8\" y1=\"16\" x2=\"8\" y2=\"16\" />\n <line x1=\"16\" y1=\"16\" x2=\"16\" y2=\"16\" />\n </svg>\n ),\n thumbUp: (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"13\"\n height=\"13\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n >\n <path d=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3z\" />\n <path d=\"M7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\" />\n </svg>\n ),\n thumbDown: (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"13\"\n height=\"13\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n >\n <path d=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3z\" />\n <path d=\"M17 2h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\" />\n </svg>\n ),\n reply: (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"13\"\n height=\"13\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n >\n <polyline points=\"9 17 4 12 9 7\" />\n <path d=\"M20 18v-2a4 4 0 0 0-4-4H4\" />\n </svg>\n ),\n bookmark: (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"14\"\n height=\"14\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n >\n <path d=\"M19 21l-7-5-7 5V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2z\" />\n </svg>\n ),\n copy: (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"13\"\n height=\"13\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n >\n <rect x=\"9\" y=\"9\" width=\"13\" height=\"13\" rx=\"2\" ry=\"2\" />\n <path d=\"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1\" />\n </svg>\n ),\n msgSquare: (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"13\"\n height=\"13\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n >\n <path d=\"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z\" />\n </svg>\n ),\n more: (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"14\"\n height=\"14\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n >\n <circle cx=\"12\" cy=\"12\" r=\"1\" />\n <circle cx=\"19\" cy=\"12\" r=\"1\" />\n <circle cx=\"5\" cy=\"12\" r=\"1\" />\n </svg>\n ),\n};\n\n// ── Component ─────────────────────────────────────────────────────────────────\n\nexport function MosaicMessageCard({\n message,\n onReply,\n onReaction,\n onBookmark,\n onCopy,\n showThread = true,\n compact = false,\n replyLabel,\n moreOptionsAriaLabel,\n removeBookmarkAriaLabel,\n bookmarkAriaLabel,\n removeBookmarkLabel,\n bookmarkLabel,\n copyMessageLabel,\n aiSenderLabel,\n viewThreadLabel,\n likeAriaLabel,\n dislikeAriaLabel,\n className,\n}: MosaicMessageCardProps) {\n const [bookmarked, setBookmarked] = React.useState(message.bookmarked ?? false);\n const [likes, setLikes] = React.useState(message.reactions?.likes ?? 0);\n const [dislikes, setDislikes] = React.useState(message.reactions?.dislikes ?? 0);\n const [hasLiked, setHasLiked] = React.useState(false);\n const [hasDisliked, setHasDisliked] = React.useState(false);\n const [menuOpen, setMenuOpen] = React.useState(false);\n const menuRef = React.useRef<HTMLDivElement>(null);\n\n const initials = message.sender.name\n .split(\" \")\n .map((n) => n[0])\n .filter(Boolean)\n .slice(0, 2)\n .join(\"\")\n .toUpperCase();\n\n const handleLike = () => {\n if (hasLiked) {\n setLikes(likes - 1);\n setHasLiked(false);\n } else {\n setLikes(likes + 1);\n setHasLiked(true);\n if (hasDisliked) {\n setDislikes(dislikes - 1);\n setHasDisliked(false);\n }\n }\n onReaction?.(message.id, \"like\");\n };\n\n const handleDislike = () => {\n if (hasDisliked) {\n setDislikes(dislikes - 1);\n setHasDisliked(false);\n } else {\n setDislikes(dislikes + 1);\n setHasDisliked(true);\n if (hasLiked) {\n setLikes(likes - 1);\n setHasLiked(false);\n }\n }\n onReaction?.(message.id, \"dislike\");\n };\n\n const handleBookmark = () => {\n setBookmarked((b) => !b);\n onBookmark?.(message.id);\n };\n\n const handleCopy = () => {\n navigator.clipboard.writeText(message.content).catch(() => null);\n onCopy?.(message.id, message.content);\n };\n\n React.useEffect(() => {\n if (!menuOpen) return;\n const h = (e: MouseEvent) => {\n if (menuRef.current && !menuRef.current.contains(e.target as Node)) setMenuOpen(false);\n };\n document.addEventListener(\"mousedown\", h);\n return () => document.removeEventListener(\"mousedown\", h);\n }, [menuOpen]);\n\n return (\n <div\n data-slot=\"message-card\"\n className={cn(\n \"rounded-lg border border-border bg-card p-4 shadow-sm transition-shadow hover:shadow-md\",\n compact && \"p-3\",\n message.sender.type === \"user\" && \"bg-primary/5\",\n className,\n )}\n >\n <div className=\"flex gap-3\">\n {/* Avatar */}\n <span\n className={cn(\n \"inline-flex shrink-0 items-center justify-center rounded-full text-white font-semibold\",\n compact ? \"h-8 w-8 text-xs\" : \"h-10 w-10 text-sm\",\n message.sender.accentColor ?? \"bg-muted text-muted-foreground\",\n )}\n >\n {message.sender.avatarUrl ? (\n <img\n src={message.sender.avatarUrl}\n alt={message.sender.name}\n className=\"h-full w-full rounded-full object-cover\"\n />\n ) : message.sender.type === \"user\" ? (\n initials || icons.user\n ) : (\n icons.bot\n )}\n </span>\n\n <div className=\"min-w-0 flex-1\">\n {/* Header */}\n <div className=\"mb-2 flex items-center justify-between gap-2\">\n <div className=\"flex items-center gap-2\">\n <span className={cn(\"font-medium\", compact ? \"text-sm\" : \"text-base\")}>\n {message.sender.name}\n </span>\n {message.sender.type === \"ai\" && aiSenderLabel && (\n <span className=\"rounded-full bg-secondary px-2 py-0.5 text-xs font-medium text-secondary-foreground\">\n {aiSenderLabel}\n </span>\n )}\n </div>\n <span className=\"shrink-0 text-xs text-muted-foreground\">\n {relativeTime(message.timestamp)}\n </span>\n </div>\n\n {/* Content */}\n <p\n className={cn(\n \"leading-relaxed text-foreground mb-3\",\n compact ? \"text-sm\" : \"text-base\",\n )}\n >\n {message.content}\n </p>\n\n {/* Actions bar */}\n <div className=\"flex items-center justify-between\">\n <div className=\"flex items-center gap-1\">\n {message.sender.type === \"ai\" && (\n <>\n <button\n type=\"button\"\n onClick={handleLike}\n className={cn(\n \"inline-flex h-8 items-center gap-1 rounded-md px-2 text-xs\",\n \"hover:bg-accent hover:text-accent-foreground\",\n \"focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring\",\n hasLiked && \"text-primary\",\n )}\n aria-label={likeAriaLabel(likes)}\n >\n {icons.thumbUp}\n <span>{likes}</span>\n </button>\n <button\n type=\"button\"\n onClick={handleDislike}\n className={cn(\n \"inline-flex h-8 items-center gap-1 rounded-md px-2 text-xs\",\n \"hover:bg-accent hover:text-accent-foreground\",\n \"focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring\",\n hasDisliked && \"text-destructive\",\n )}\n aria-label={dislikeAriaLabel(dislikes)}\n >\n {icons.thumbDown}\n <span>{dislikes}</span>\n </button>\n </>\n )}\n {showThread && (message.replyCount ?? 0) > 0 && (\n <button\n type=\"button\"\n onClick={() => onReply?.(message.id)}\n className=\"inline-flex h-8 items-center gap-1 rounded-md px-2 text-xs hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring\"\n >\n {icons.msgSquare}\n <span>{message.replyCount}</span>\n </button>\n )}\n <button\n type=\"button\"\n onClick={() => onReply?.(message.id)}\n className=\"inline-flex h-8 items-center gap-1 rounded-md px-2 text-xs hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring\"\n >\n {icons.reply}\n <span>{replyLabel}</span>\n </button>\n </div>\n\n <div className=\"flex items-center gap-1\">\n <button\n type=\"button\"\n onClick={handleBookmark}\n className={cn(\n \"inline-flex h-8 w-8 items-center justify-center rounded-md\",\n \"hover:bg-accent hover:text-accent-foreground\",\n \"focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring\",\n bookmarked && \"text-primary\",\n )}\n aria-label={bookmarked ? removeBookmarkAriaLabel : bookmarkAriaLabel}\n aria-pressed={bookmarked}\n >\n {icons.bookmark}\n </button>\n\n {/* More menu */}\n <div ref={menuRef} className=\"relative\">\n <button\n type=\"button\"\n onClick={() => setMenuOpen((v) => !v)}\n className=\"inline-flex h-8 w-8 items-center justify-center rounded-md hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring\"\n aria-label={moreOptionsAriaLabel}\n aria-haspopup=\"menu\"\n >\n {icons.more}\n </button>\n {menuOpen && (\n <div\n role=\"menu\"\n className=\"absolute right-0 top-full z-50 mt-1 min-w-[140px] rounded-md border border-border bg-popover py-1 shadow-md\"\n >\n <button\n type=\"button\"\n role=\"menuitem\"\n onClick={() => {\n handleCopy();\n setMenuOpen(false);\n }}\n className=\"flex w-full items-center gap-2 px-3 py-2 text-sm text-foreground hover:bg-accent hover:text-accent-foreground\"\n >\n {icons.copy}\n {copyMessageLabel}\n </button>\n <button\n type=\"button\"\n role=\"menuitem\"\n onClick={() => {\n onReply?.(message.id);\n setMenuOpen(false);\n }}\n className=\"flex w-full items-center gap-2 px-3 py-2 text-sm text-foreground hover:bg-accent hover:text-accent-foreground\"\n >\n {icons.reply}\n {replyLabel}\n </button>\n <button\n type=\"button\"\n role=\"menuitem\"\n onClick={() => {\n handleBookmark();\n setMenuOpen(false);\n }}\n className=\"flex w-full items-center gap-2 px-3 py-2 text-sm text-foreground hover:bg-accent hover:text-accent-foreground\"\n >\n {icons.bookmark}\n {bookmarked ? removeBookmarkLabel : bookmarkLabel}\n </button>\n </div>\n )}\n </div>\n </div>\n </div>\n\n {message.parentMessageId && showThread && (\n <div className=\"mt-2 border-t border-border pt-2\">\n <button\n type=\"button\"\n onClick={() => onReply?.(message.id)}\n className=\"inline-flex h-7 items-center gap-1 rounded-md text-xs text-muted-foreground hover:bg-accent hover:text-accent-foreground px-2\"\n >\n {icons.msgSquare}\n {viewThreadLabel}\n </button>\n </div>\n )}\n </div>\n </div>\n </div>\n );\n}\n\nMosaicMessageCard.displayName = \"MosaicMessageCard\";\n"
|
|
13
|
+
}
|
|
14
|
+
],
|
|
15
|
+
"type": "registry:ui"
|
|
16
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
|
|
3
|
+
"name": "mosaic-message-list",
|
|
4
|
+
"title": "MosaicMessageList",
|
|
5
|
+
"description": "Responsive message list (responsive-pair). Desktop: sticky header + search. Mobile: compact list.",
|
|
6
|
+
"dependencies": [],
|
|
7
|
+
"registryDependencies": [
|
|
8
|
+
"https://cdn.jsdelivr.net/npm/@vantageos/mosaic-blocks@0.5.37-alpha/r/mosaic-device-provider.json",
|
|
9
|
+
"https://cdn.jsdelivr.net/npm/@vantageos/mosaic-blocks@0.5.37-alpha/r/mosaic-message-card.json"
|
|
10
|
+
],
|
|
11
|
+
"files": [
|
|
12
|
+
{
|
|
13
|
+
"path": "src/components/message-list/MosaicMessageList.tsx",
|
|
14
|
+
"type": "registry:ui",
|
|
15
|
+
"content": "\"use client\";\n\n/**\n * MosaicMessageList — responsive message list (desktop + mobile responsive-pair)\n *\n * Ported from components/messages/message-list.tsx +\n * messages/desktop/message-list-desktop.tsx +\n * messages/mobile/message-list-mobile.tsx\n *\n * Orchestrator reads useDevice → Desktop/Mobile variant.\n * Desktop: scrollable card list with sticky header + search.\n * Mobile: compact card list with sticky \"Load more\" button.\n *\n * Props-driven — no internal state for messages (fully controlled).\n * sonner toast removed.\n */\n\nimport * as React from \"react\";\nimport { useDevice } from \"@/components/ui/MosaicDeviceProvider\";\nimport { type MosaicMessage, MosaicMessageCard } from \"@/components/ui/MosaicMessageCard\";\n\n// ── Utility ───────────────────────────────────────────────────────────────────\n\nfunction cn(...classes: (string | undefined | null | false)[]): string {\n return classes.filter(Boolean).join(\" \");\n}\n\n// ── Types ─────────────────────────────────────────────────────────────────────\n\nexport interface MosaicMessageListProps {\n messages: MosaicMessage[];\n onReply?: (messageId: string) => void;\n onReaction?: (messageId: string, type: \"like\" | \"dislike\") => void;\n onBookmark?: (messageId: string) => void;\n onCopy?: (messageId: string, content: string) => void;\n onLoadMore?: () => void;\n hasMore?: boolean;\n /** Optional title for the list header */\n title?: string;\n /** Whether messages are loading */\n isLoading?: boolean;\n /** Placeholder for the desktop search input. Required, no default. */\n searchPlaceholder: string;\n /** Message shown when the filtered list is empty. Required, no default. */\n emptyMessage: string;\n /** Label for the \"load more\" button. Required, no default. */\n loadMoreLabel: string;\n /** Required host-owned strings forwarded to every MosaicMessageCard. */\n replyLabel: string;\n moreOptionsAriaLabel: string;\n removeBookmarkAriaLabel: string;\n bookmarkAriaLabel: string;\n removeBookmarkLabel: string;\n bookmarkLabel: string;\n copyMessageLabel: string;\n viewThreadLabel: string;\n likeAriaLabel: (count: number) => string;\n dislikeAriaLabel: (count: number) => string;\n className?: string;\n}\n\n// ── Search icon ───────────────────────────────────────────────────────────────\n\nfunction SearchIcon() {\n return (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"16\"\n height=\"16\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n >\n <circle cx=\"11\" cy=\"11\" r=\"8\" />\n <line x1=\"21\" y1=\"21\" x2=\"16.65\" y2=\"16.65\" />\n </svg>\n );\n}\n\n// ── Desktop variant ───────────────────────────────────────────────────────────\n\nfunction MessageListDesktop({\n messages,\n onReply,\n onReaction,\n onBookmark,\n onCopy,\n onLoadMore,\n hasMore,\n title,\n isLoading,\n searchPlaceholder,\n emptyMessage,\n loadMoreLabel,\n replyLabel,\n moreOptionsAriaLabel,\n removeBookmarkAriaLabel,\n bookmarkAriaLabel,\n removeBookmarkLabel,\n bookmarkLabel,\n copyMessageLabel,\n viewThreadLabel,\n likeAriaLabel,\n dislikeAriaLabel,\n className,\n}: MosaicMessageListProps) {\n const [query, setQuery] = React.useState(\"\");\n\n const filtered = query\n ? messages.filter(\n (m) =>\n m.content.toLowerCase().includes(query.toLowerCase()) ||\n m.sender.name.toLowerCase().includes(query.toLowerCase()),\n )\n : messages;\n\n return (\n <div data-slot=\"message-list-desktop\" className={cn(\"flex h-full flex-col\", className)}>\n {/* Header */}\n <div className=\"flex items-center justify-between border-b border-border px-6 py-4\">\n {title && <h2 className=\"text-lg font-semibold\">{title}</h2>}\n <div className=\"relative ml-auto max-w-xs flex-1\">\n <span className=\"absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground\">\n <SearchIcon />\n </span>\n <input\n type=\"search\"\n value={query}\n onChange={(e) => setQuery(e.target.value)}\n placeholder={searchPlaceholder}\n className={cn(\n \"w-full rounded-md border border-input bg-background py-2 pl-9 pr-3\",\n \"text-sm placeholder:text-muted-foreground\",\n \"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\",\n )}\n />\n </div>\n </div>\n\n {/* List */}\n <div className=\"flex-1 space-y-3 overflow-y-auto p-6\">\n {isLoading && (\n <div className=\"space-y-3\">\n {[0, 1, 2].map((i) => (\n <div key={i} className=\"h-24 animate-pulse rounded-lg bg-muted\" />\n ))}\n </div>\n )}\n {!isLoading &&\n filtered.map((message) => (\n <MosaicMessageCard\n key={message.id}\n message={message}\n onReply={onReply}\n onReaction={onReaction}\n onBookmark={onBookmark}\n onCopy={onCopy}\n replyLabel={replyLabel}\n moreOptionsAriaLabel={moreOptionsAriaLabel}\n removeBookmarkAriaLabel={removeBookmarkAriaLabel}\n bookmarkAriaLabel={bookmarkAriaLabel}\n removeBookmarkLabel={removeBookmarkLabel}\n bookmarkLabel={bookmarkLabel}\n copyMessageLabel={copyMessageLabel}\n viewThreadLabel={viewThreadLabel}\n likeAriaLabel={likeAriaLabel}\n dislikeAriaLabel={dislikeAriaLabel}\n />\n ))}\n {!isLoading && filtered.length === 0 && (\n <p className=\"py-12 text-center text-sm text-muted-foreground\">{emptyMessage}</p>\n )}\n </div>\n\n {hasMore && (\n <div className=\"border-t border-border p-4\">\n <button\n type=\"button\"\n onClick={onLoadMore}\n className={cn(\n \"w-full rounded-md border border-border bg-background px-4 py-2 text-sm font-medium\",\n \"hover:bg-accent hover:text-accent-foreground\",\n \"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\",\n )}\n >\n {loadMoreLabel}\n </button>\n </div>\n )}\n </div>\n );\n}\n\n// ── Mobile variant ────────────────────────────────────────────────────────────\n\nfunction MessageListMobile({\n messages,\n onReply,\n onReaction,\n onBookmark,\n onCopy,\n onLoadMore,\n hasMore,\n title,\n isLoading,\n emptyMessage,\n loadMoreLabel,\n replyLabel,\n moreOptionsAriaLabel,\n removeBookmarkAriaLabel,\n bookmarkAriaLabel,\n removeBookmarkLabel,\n bookmarkLabel,\n copyMessageLabel,\n viewThreadLabel,\n likeAriaLabel,\n dislikeAriaLabel,\n className,\n}: MosaicMessageListProps) {\n return (\n <div data-slot=\"message-list-mobile\" className={cn(\"flex flex-col\", className)}>\n {title && (\n <div className=\"sticky top-0 z-10 border-b border-border bg-background px-4 py-3\">\n <h2 className=\"text-base font-semibold\">{title}</h2>\n </div>\n )}\n\n <div className=\"space-y-3 p-4\">\n {isLoading && (\n <div className=\"space-y-3\">\n {[0, 1, 2].map((i) => (\n <div key={i} className=\"h-20 animate-pulse rounded-lg bg-muted\" />\n ))}\n </div>\n )}\n {!isLoading &&\n messages.map((message) => (\n <MosaicMessageCard\n key={message.id}\n message={message}\n onReply={onReply}\n onReaction={onReaction}\n onBookmark={onBookmark}\n onCopy={onCopy}\n replyLabel={replyLabel}\n moreOptionsAriaLabel={moreOptionsAriaLabel}\n removeBookmarkAriaLabel={removeBookmarkAriaLabel}\n bookmarkAriaLabel={bookmarkAriaLabel}\n removeBookmarkLabel={removeBookmarkLabel}\n bookmarkLabel={bookmarkLabel}\n copyMessageLabel={copyMessageLabel}\n viewThreadLabel={viewThreadLabel}\n likeAriaLabel={likeAriaLabel}\n dislikeAriaLabel={dislikeAriaLabel}\n compact\n />\n ))}\n {!isLoading && messages.length === 0 && (\n <p className=\"py-10 text-center text-sm text-muted-foreground\">{emptyMessage}</p>\n )}\n </div>\n\n {hasMore && (\n <div className=\"px-4 pb-4\">\n <button\n type=\"button\"\n onClick={onLoadMore}\n className={cn(\n \"w-full min-h-[44px] rounded-md border border-border bg-background px-4 py-2 text-sm font-medium\",\n \"hover:bg-accent hover:text-accent-foreground\",\n \"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\",\n )}\n >\n {loadMoreLabel}\n </button>\n </div>\n )}\n </div>\n );\n}\n\n// ── Orchestrator ──────────────────────────────────────────────────────────────\n\nexport function MosaicMessageList(props: MosaicMessageListProps) {\n const { isMobile } = useDevice();\n return isMobile ? <MessageListMobile {...props} /> : <MessageListDesktop {...props} />;\n}\n\nMosaicMessageList.displayName = \"MosaicMessageList\";\n\nexport { MessageListDesktop as MosaicMessageListDesktop };\nexport { MessageListMobile as MosaicMessageListMobile };\n"
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
"type": "registry:ui"
|
|
19
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
|
|
3
|
+
"name": "mosaic-message-search",
|
|
4
|
+
"title": "MosaicMessageSearch",
|
|
5
|
+
"description": "MosaicMessageSearch — search bar over the messages of a single, already-open conversation: a query input and a clear action, with the matching results rendered entirely by the host.",
|
|
6
|
+
"dependencies": [],
|
|
7
|
+
"registryDependencies": [
|
|
8
|
+
"https://cdn.jsdelivr.net/npm/@vantageos/mosaic-blocks@0.5.37-alpha/r/mosaic-input.json"
|
|
9
|
+
],
|
|
10
|
+
"files": [
|
|
11
|
+
{
|
|
12
|
+
"path": "src/components/message-search/MosaicMessageSearch.tsx",
|
|
13
|
+
"type": "registry:ui",
|
|
14
|
+
"content": "/**\n * MosaicMessageSearch — search bar over the messages of a single, already-open\n * conversation: a query input and a clear action, with the matching results\n * rendered entirely by the host.\n *\n * Distinct from `MosaicMemorySearch` (which searches a host-supplied\n * knowledge base): this component searches WITHIN a conversation's message\n * history so an agent (or a human) can recall a past instruction without\n * re-reading the whole thread.\n *\n * Fully controlled, presentational atom: `query` + `onQueryChange` own the\n * text; the component never searches anything, filters anything, counts\n * anything, or performs any network I/O. It has no idea what a \"message\" or a\n * \"match\" looks like — the entire results area is a host-owned slot\n * (`resultsSlot`), exactly like `MosaicMemorySearch`'s `filters` catalogue.\n *\n * The clear action only appears once `query` is non-empty — that switch is\n * genuinely presentation state, not a missing word, so `clearButtonLabel`\n * remains a required prop with no default (the host always supplies it, the\n * button simply isn't rendered until there is something to clear).\n *\n * `resultsSlot` and `emptyResultsLabel` are optional as a GROUP, but for two\n * different reasons:\n * - `resultsSlot` omitted encodes \"the host has not rendered a results view\n * yet\" (e.g. the query is empty, or results are still being gathered) —\n * absence of a whole feature, not a missing word.\n * - `emptyResultsLabel` is the one SIN-01 exception: a NAMED, host-worded\n * zero-results state. It is rendered only when `resultsSlot` is absent, so\n * the host signals \"I searched and found nothing\" by supplying this label\n * without a results node. When both are supplied, `resultsSlot` wins — the\n * host is trusted to omit `emptyResultsLabel` once it has real results.\n *\n * No \"use client\" — prepend-use-client.mjs adds it to dist.\n * Design tokens: --primary, --primary-foreground, --background, --foreground,\n * --border, --muted, --muted-foreground, --input, --ring.\n * a11y: the query input is `type=\"search\"` with an explicit `aria-label`\n * (`searchLabel`, host-owned — no host is forced to also render a visible\n * `<label>`). The clear button carries its own required `aria-label` for the\n * same reason.\n *\n * Deps: @base-ui/react (via MosaicInput) + class-variance-authority only.\n *\n * @example\n * <MosaicMessageSearch\n * query={query}\n * onQueryChange={setQuery}\n * searchLabel=\"Search this conversation\"\n * searchPlaceholder=\"Search messages…\"\n * clearButtonLabel=\"Clear search\"\n * resultsSlot={matches.length > 0 ? <MatchList matches={matches} /> : undefined}\n * emptyResultsLabel=\"No messages match your search\"\n * />\n */\n\nimport type * as React from \"react\";\nimport { MosaicInput } from \"@/components/ui/MosaicInput\";\n\n// ── Utility ───────────────────────────────────────────────────────────────────\n\nfunction cn(...classes: (string | undefined | null | false)[]): string {\n return classes.filter(Boolean).join(\" \");\n}\n\n// ── Types ─────────────────────────────────────────────────────────────────────\n\nexport interface MosaicMessageSearchProps {\n /** Current query text. Controlled by the host. */\n query: string;\n /** Called with the new query text on every keystroke. */\n onQueryChange: (query: string) => void;\n /** aria-label for the query input. Required, no default. */\n searchLabel: string;\n /** Placeholder for the query input. Required, no default. */\n searchPlaceholder: string;\n /** aria-label for the clear button. Required, no default — rendered only once `query` is non-empty. */\n clearButtonLabel: string;\n /**\n * Host-owned results view for the current query — a node, never data the\n * component would render itself. The host performs the search; this\n * component never sees a single message.\n */\n resultsSlot?: React.ReactNode;\n /**\n * Host-worded zero-results state. Rendered only when `resultsSlot` is\n * absent — the host signals \"I searched and found nothing\" by supplying\n * this label without a results node. Absence (with `resultsSlot` also\n * absent) encodes a neutral state (e.g. no search performed yet).\n */\n emptyResultsLabel?: string;\n /** Additional Tailwind classes on the root element. */\n className?: string;\n /** React 19 ref prop — forwarded to the root element. */\n ref?: React.Ref<HTMLDivElement>;\n}\n\n// ── Inline icons ──────────────────────────────────────────────────────────────\n\nfunction SearchIcon() {\n return (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"16\"\n height=\"16\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n >\n <circle cx=\"11\" cy=\"11\" r=\"8\" />\n <line x1=\"21\" y1=\"21\" x2=\"16.65\" y2=\"16.65\" />\n </svg>\n );\n}\n\nfunction ClearIcon() {\n return (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"14\"\n height=\"14\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n >\n <line x1=\"18\" y1=\"6\" x2=\"6\" y2=\"18\" />\n <line x1=\"6\" y1=\"6\" x2=\"18\" y2=\"18\" />\n </svg>\n );\n}\n\n// ── Component ─────────────────────────────────────────────────────────────────\n\n/**\n * MosaicMessageSearch — production in-thread message search bar for\n * @vantageos/mosaic-blocks.\n *\n * Purely presentational + controlled: renders the query input, a clear\n * action, and whatever host-owned results view is passed in. No network\n * call, no internal query state, no message model of any kind.\n */\nexport function MosaicMessageSearch({\n query,\n onQueryChange,\n searchLabel,\n searchPlaceholder,\n clearButtonLabel,\n resultsSlot,\n emptyResultsLabel,\n className,\n ref,\n}: MosaicMessageSearchProps) {\n return (\n <div ref={ref} data-slot=\"message-search\" className={cn(\"flex flex-col gap-2\", className)}>\n <div className=\"relative\">\n <span className=\"absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground\">\n <SearchIcon />\n </span>\n <MosaicInput\n type=\"search\"\n aria-label={searchLabel}\n placeholder={searchPlaceholder}\n value={query}\n onChange={(event: React.ChangeEvent<HTMLInputElement>) =>\n onQueryChange(event.target.value)\n }\n className=\"pl-9 pr-9\"\n />\n {query.length > 0 && (\n <button\n type=\"button\"\n aria-label={clearButtonLabel}\n onClick={() => onQueryChange(\"\")}\n className={cn(\n \"absolute right-2 top-1/2 -translate-y-1/2\",\n \"flex size-5 items-center justify-center rounded-full\",\n \"text-muted-foreground hover:bg-muted hover:text-foreground\",\n \"focus-visible:outline-none focus-visible:ring-ring focus-visible:ring-[3px]\",\n )}\n >\n <ClearIcon />\n </button>\n )}\n </div>\n\n {resultsSlot ? (\n <div data-slot=\"message-search-results\">{resultsSlot}</div>\n ) : (\n emptyResultsLabel && (\n <p data-slot=\"message-search-results\" className=\"text-sm text-muted-foreground\">\n {emptyResultsLabel}\n </p>\n )\n )}\n </div>\n );\n}\n\nMosaicMessageSearch.displayName = \"MosaicMessageSearch\";\n"
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
"type": "registry:ui"
|
|
18
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
|
|
3
|
+
"name": "mosaic-model-selector",
|
|
4
|
+
"title": "MosaicModelSelector",
|
|
5
|
+
"description": "MosaicModelSelector — @base-ui/react Combobox primitive",
|
|
6
|
+
"dependencies": [
|
|
7
|
+
"@base-ui/react"
|
|
8
|
+
],
|
|
9
|
+
"registryDependencies": [],
|
|
10
|
+
"files": [
|
|
11
|
+
{
|
|
12
|
+
"path": "src/components/model-selector/MosaicModelSelector.tsx",
|
|
13
|
+
"type": "registry:ui",
|
|
14
|
+
"content": "\"use client\";\n\n/**\n * MosaicModelSelector — @base-ui/react Combobox primitive\n *\n * Ported from any-debate-ai components/agent-composer/ModelSelector.tsx.\n * (gh api repos/elpiarthera/any-debate-ai/contents/components/agent-composer/ModelSelector.tsx)\n *\n * The source component hard-coded AVAILABLE_MODELS + getRecommendedModels\n * from a local catalogue module. That catalogue is business knowledge that\n * changes independently of the library — it does NOT belong in\n * @vantageos/mosaic-blocks. This port strips it entirely: the host supplies\n * `models: MosaicModelOption[]`, the library only knows how to render and\n * navigate a list of options it is handed.\n *\n * Built on @base-ui/react/combobox (native in @base-ui/react@1.5.0).\n * Filtering via built-in useFilter with \"contains\" strategy (same recipe as\n * MosaicCombobox). Keyboard-accessible: ArrowDown/Up navigate, Enter selects,\n * Escape closes. Disabled options are visibly non-interactive\n * (aria-disabled) and never fire onValueChange.\n *\n * Controlled: `value` + `onValueChange` are owned by the host.\n * data-slot=\"model-selector\" on the root wrapper.\n */\n\nimport { Combobox } from \"@base-ui/react/combobox\";\nimport * as React from \"react\";\nimport {\n modelSelectorItemVariants,\n modelSelectorTriggerVariants,\n} from \"./model-selector-variants.js\";\n\n// Positioner placement types, derived from the public Combobox.Positioner\n// props contract (no private subpath import — `@base-ui/react` exports no\n// `./utils` entry point).\ntype PositionerSide = NonNullable<Combobox.Positioner.Props[\"side\"]>;\ntype PositionerAlign = NonNullable<Combobox.Positioner.Props[\"align\"]>;\ntype PositionerCollisionBoundary = Combobox.Positioner.Props[\"collisionBoundary\"];\ntype PositionerCollisionPadding = Combobox.Positioner.Props[\"collisionPadding\"];\n\n// ── Utility ──────────────────────────────────────────────────────────────────\n\nfunction cn(...classes: (string | undefined | null | false)[]): string {\n return classes.filter(Boolean).join(\" \");\n}\n\n// ── Types ─────────────────────────────────────────────────────────────────────\n\nexport interface MosaicModelOption {\n /** Unique identifier the host resolves back to its own model catalogue. */\n value: string;\n /** Display name (e.g. \"GPT-5\", \"Claude Opus\"). */\n label: string;\n /** Optional one-line description, supplied by the host. */\n description?: string;\n /** Optional meta line (e.g. context window / pricing), supplied by the host. */\n meta?: string;\n /** Optional badge text (e.g. \"Recommended\"), supplied by the host. */\n badge?: string;\n /** When true, the option is shown but cannot be selected. */\n disabled?: boolean;\n}\n\nexport interface MosaicModelSelectorProps {\n /** The full list of selectable models. The library knows no model names — host-owned. */\n models: MosaicModelOption[];\n /** Controlled selected value. */\n value?: string;\n /** Callback fired when the host's selection should change. Never fires for disabled options. */\n onValueChange?: (value: string) => void;\n /**\n * Text shown in the trigger when no model is selected. Required — the\n * host owns the language (e.g. `t('ModelSelector.placeholder')`).\n */\n placeholder: string;\n /**\n * Message shown when no model matches the filter. Required — the host\n * owns the language. No default, no fallback.\n */\n emptyMessage: string;\n disabled?: boolean;\n name?: string;\n className?: string;\n /**\n * Which side of the trigger the popup opens against. Base UI may still\n * auto-flip to avoid a collision unless `collisionAvoidance` disables it.\n * @default 'bottom'\n */\n side?: PositionerSide;\n /**\n * How the popup aligns relative to the requested side.\n * @default 'center'\n */\n align?: PositionerAlign;\n /**\n * Element/rect the popup is confined to.\n * @default 'clipping-ancestors'\n */\n collisionBoundary?: PositionerCollisionBoundary;\n /**\n * Space to keep between the popup and the edge of the collision boundary.\n * @default 5\n */\n collisionPadding?: PositionerCollisionPadding;\n}\n\n// ── Component ─────────────────────────────────────────────────────────────────\n\n/**\n * MosaicModelSelector — production model-picker atom for @vantageos/mosaic-blocks.\n *\n * The component owns zero model knowledge: `models` is supplied by the host,\n * filtered as the user types, and the selected id is surfaced through\n * `onValueChange`. All visible strings that are not per-model host data\n * (placeholder, emptyMessage) are required props with no default.\n *\n * @example\n * <MosaicModelSelector\n * models={[{ value: \"gpt-5\", label: \"GPT-5\", description: \"Flagship model\" }]}\n * value={selectedModel}\n * onValueChange={setSelectedModel}\n * placeholder={t('ModelSelector.placeholder')}\n * emptyMessage={t('ModelSelector.empty')}\n * />\n */\nexport function MosaicModelSelector({\n models,\n value,\n onValueChange,\n placeholder,\n emptyMessage,\n disabled,\n name,\n className,\n side,\n align,\n collisionBoundary,\n collisionPadding,\n}: MosaicModelSelectorProps) {\n const [inputValue, setInputValue] = React.useState(\"\");\n\n const filter = Combobox.useFilter({ sensitivity: \"base\" });\n\n const filteredModels = React.useMemo(() => {\n if (!inputValue) return models;\n return models.filter((model) => filter.contains(model.label, inputValue));\n }, [models, inputValue, filter]);\n\n const labelMap = React.useMemo(\n () => Object.fromEntries(models.map((model) => [model.value, model.label])),\n [models],\n );\n\n const handleValueChange = React.useCallback(\n (nextValue: unknown, eventDetails: unknown) => {\n if (typeof nextValue !== \"string\") return;\n const selected = models.find((model) => model.value === nextValue);\n if (!selected || selected.disabled) return;\n onValueChange?.(nextValue);\n void eventDetails;\n },\n [models, onValueChange],\n );\n\n return (\n <Combobox.Root\n value={value}\n onValueChange={handleValueChange}\n disabled={disabled}\n name={name}\n onInputValueChange={setInputValue}\n autoHighlight\n >\n <div data-slot=\"model-selector\" className={cn(\"relative w-full\", className)}>\n <Combobox.Input\n placeholder={placeholder}\n className={modelSelectorTriggerVariants({ className })}\n />\n {value != null && value in labelMap && inputValue === \"\" && (\n <span className=\"pointer-events-none absolute inset-y-0 left-3 flex items-center text-sm text-foreground\">\n {labelMap[value]}\n </span>\n )}\n\n <Combobox.Portal>\n <Combobox.Positioner\n sideOffset={4}\n side={side}\n align={align}\n collisionBoundary={collisionBoundary}\n collisionPadding={collisionPadding}\n >\n <Combobox.Popup\n className={cn(\n \"z-50 min-w-[16rem] overflow-hidden rounded-md border border-border\",\n \"bg-popover p-1 text-popover-foreground shadow-md\",\n \"origin-[var(--transform-origin)]\",\n \"transition-[transform,scale,opacity]\",\n \"data-[open]:scale-100 data-[open]:opacity-100\",\n \"data-[ending-style]:scale-95 data-[ending-style]:opacity-0\",\n \"data-[starting-style]:scale-95 data-[starting-style]:opacity-0\",\n )}\n >\n <Combobox.List>\n {filteredModels.length === 0 ? (\n <Combobox.Empty className=\"py-2 text-center text-sm text-muted-foreground\">\n {emptyMessage}\n </Combobox.Empty>\n ) : (\n filteredModels.map((model) => (\n <Combobox.Item\n key={model.value}\n value={model.value}\n disabled={model.disabled}\n className={modelSelectorItemVariants({ className: undefined })}\n >\n <div className=\"flex items-center justify-between gap-2\">\n <span className=\"font-medium\">{model.label}</span>\n {model.badge && (\n <span className=\"rounded-full bg-secondary px-2 py-0.5 text-xs text-secondary-foreground\">\n {model.badge}\n </span>\n )}\n </div>\n {model.description && (\n <span className=\"text-xs text-muted-foreground\">{model.description}</span>\n )}\n {model.meta && (\n <span className=\"text-xs text-muted-foreground\">{model.meta}</span>\n )}\n </Combobox.Item>\n ))\n )}\n </Combobox.List>\n </Combobox.Popup>\n </Combobox.Positioner>\n </Combobox.Portal>\n </div>\n </Combobox.Root>\n );\n}\n\nMosaicModelSelector.displayName = \"MosaicModelSelector\";\n"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"path": "src/components/model-selector/model-selector-variants.ts",
|
|
18
|
+
"type": "registry:ui",
|
|
19
|
+
"content": "/**\n * modelSelectorVariants — pure CVA variant functions for MosaicModelSelector.\n *\n * Isolated in their own module so they can be re-exported from the\n * `@vantageos/mosaic-blocks/server` subpath without pulling in React.\n *\n * Zero browser / React runtime dependencies — safe in RSC / Node.js.\n */\n\nimport { cva } from \"class-variance-authority\";\n\n/** Root trigger button — shows either the selected model summary or the placeholder. */\nexport const modelSelectorTriggerVariants = cva(\n [\n \"flex w-full min-h-[44px] items-center justify-between gap-2 rounded-md border\",\n \"border-border bg-background px-3 py-2 text-left text-sm text-foreground shadow-xs\",\n \"outline-none transition-colors hover:bg-muted\",\n \"focus-visible:ring-ring focus-visible:ring-[3px]\",\n \"data-[disabled]:cursor-not-allowed data-[disabled]:opacity-50\",\n \"data-[popup-open]:ring-ring data-[popup-open]:ring-[3px]\",\n ],\n {\n variants: {},\n },\n);\n\n/** One model row in the popup list — selected vs. disabled tone. */\nexport const modelSelectorItemVariants = cva(\n [\n \"relative flex cursor-pointer select-none flex-col gap-0.5 rounded-sm px-2 py-1.5\",\n \"text-sm text-popover-foreground outline-none transition-colors\",\n \"data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground\",\n \"data-[disabled]:cursor-not-allowed data-[disabled]:opacity-50\",\n \"data-[selected]:font-medium\",\n ],\n {\n variants: {},\n },\n);\n"
|
|
20
|
+
}
|
|
21
|
+
],
|
|
22
|
+
"type": "registry:ui"
|
|
23
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
|
|
3
|
+
"name": "mosaic-module-card",
|
|
4
|
+
"title": "MosaicModuleCard",
|
|
5
|
+
"description": "Selected-module display card for composer slot. Shows name, description, optional details, emoji icon, tags, edit/remove actions. Props: type, module {name, description, details?, icon?, tags?}, onEdit, onRemove, isSelected, isCustom. Generic — no debate domain types.",
|
|
6
|
+
"dependencies": [],
|
|
7
|
+
"registryDependencies": [],
|
|
8
|
+
"files": [
|
|
9
|
+
{
|
|
10
|
+
"path": "src/components/module-card/MosaicModuleCard.tsx",
|
|
11
|
+
"type": "registry:ui",
|
|
12
|
+
"content": "\"use client\";\n\n/**\n * MosaicModuleCard — selected-module display card (PC-11)\n *\n * Ported (source: private upstream) components/agent-composer/ModuleCard.tsx\n *\n * Displays a selected module (role / persona / framework / any custom type)\n * with name, description, optional tags/details string, and edit/remove actions.\n * Used inside AgentComposer Desktop + Mobile variants.\n *\n * Generalized: removed debate-specific types (Role, Persona, ThinkingFramework)\n * in favour of a generic MosaicModuleData interface.\n * Removed useDevice dependency (parent controls layout context).\n *\n * Framer-motion: N/A.\n * Icons: inline SVG (no lucide dep).\n */\n\nimport type * as React from \"react\";\n\n// ── Utility ───────────────────────────────────────────────────────────────────\n\nfunction cn(...classes: (string | undefined | null | false)[]): string {\n return classes.filter(Boolean).join(\" \");\n}\n\n// ── Types ─────────────────────────────────────────────────────────────────────\n\nexport interface MosaicModuleData {\n name: string;\n description?: string;\n /** Short detail string shown below description (e.g. \"3 steps\", \"Expertise: UX, Research\") */\n details?: string;\n /** Optional emoji or short string icon displayed in the card */\n icon?: string;\n /** Optional array of tag strings shown as badges */\n tags?: string[];\n}\n\nexport type MosaicModuleType = \"role\" | \"persona\" | \"framework\" | string;\n\nexport interface MosaicModuleCardProps {\n type: MosaicModuleType;\n module: MosaicModuleData;\n onRemove?: () => void;\n onEdit?: () => void;\n isSelected?: boolean;\n isCustom?: boolean;\n /** Badge label shown when `isCustom` is true. Required, no default. */\n customBadgeLabel: string;\n /** aria-label for the edit button. Required, no default. */\n editAriaLabel: string;\n /** aria-label for the remove button. Required, no default. */\n removeAriaLabel: string;\n className?: string;\n ref?: React.Ref<HTMLDivElement>;\n}\n\n// ── Inline icons ──────────────────────────────────────────────────────────────\n\nfunction EditIcon() {\n return (\n <svg\n width=\"14\"\n height=\"14\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n >\n <path d=\"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7\" />\n <path d=\"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z\" />\n </svg>\n );\n}\n\nfunction RemoveIcon() {\n return (\n <svg\n width=\"14\"\n height=\"14\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n >\n <line x1=\"18\" y1=\"6\" x2=\"6\" y2=\"18\" />\n <line x1=\"6\" y1=\"6\" x2=\"18\" y2=\"18\" />\n </svg>\n );\n}\n\n// ── Component ─────────────────────────────────────────────────────────────────\n\n/**\n * MosaicModuleCard — filled-state card for a selected module slot.\n * Shows name, description, optional details, icon, tags, and edit/remove actions.\n *\n * @example\n * <MosaicModuleCard\n * type=\"role\"\n * module={{ name: \"Product Manager\", description: \"Drives product strategy\", tags: [\"strategy\", \"roadmap\"] }}\n * onEdit={() => openRolePicker()}\n * onRemove={() => clearRole()}\n * />\n */\nexport function MosaicModuleCard({\n type: _type,\n module,\n onRemove,\n onEdit,\n isSelected = false,\n isCustom = false,\n customBadgeLabel,\n editAriaLabel,\n removeAriaLabel,\n className,\n ref,\n}: MosaicModuleCardProps) {\n return (\n <div\n ref={ref}\n data-slot=\"module-card\"\n className={cn(\n \"min-h-[80px] rounded-xl border border-border bg-card p-4 transition-all\",\n \"flex items-start gap-3\",\n isSelected && \"ring-2 ring-primary bg-primary/5\",\n className,\n )}\n >\n {/* Icon */}\n {module.icon && (\n <span className=\"mt-0.5 shrink-0 text-2xl\" aria-hidden=\"true\">\n {module.icon}\n </span>\n )}\n\n {/* Content */}\n <div className=\"min-w-0 flex-1\">\n <div className=\"mb-1 flex items-center gap-2\">\n <h4 className=\"truncate text-sm font-medium text-foreground\">{module.name}</h4>\n {isCustom && (\n <span className=\"shrink-0 rounded-full bg-secondary px-2 py-0.5 text-xs font-medium text-secondary-foreground\">\n {customBadgeLabel}\n </span>\n )}\n </div>\n\n {module.description && (\n <p className=\"mb-2 line-clamp-2 text-xs text-muted-foreground\">{module.description}</p>\n )}\n\n {module.details && (\n <p className=\"truncate text-xs font-medium text-muted-foreground/80\">{module.details}</p>\n )}\n\n {module.tags && module.tags.length > 0 && (\n <div className=\"mt-2 flex flex-wrap gap-1\">\n {module.tags.slice(0, 4).map((tag) => (\n <span\n key={tag}\n className=\"rounded-full border border-border bg-muted px-2 py-0.5 text-xs text-muted-foreground\"\n >\n {tag}\n </span>\n ))}\n </div>\n )}\n </div>\n\n {/* Actions */}\n {(onEdit || onRemove) && (\n <div className=\"flex shrink-0 items-center gap-1\">\n {onEdit && (\n <button\n type=\"button\"\n onClick={onEdit}\n aria-label={editAriaLabel}\n className=\"flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\"\n >\n <EditIcon />\n </button>\n )}\n {onRemove && (\n <button\n type=\"button\"\n onClick={onRemove}\n aria-label={removeAriaLabel}\n className=\"flex h-8 w-8 items-center justify-center rounded-md text-destructive transition-colors hover:bg-destructive/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\"\n >\n <RemoveIcon />\n </button>\n )}\n </div>\n )}\n </div>\n );\n}\n\nMosaicModuleCard.displayName = \"MosaicModuleCard\";\n"
|
|
13
|
+
}
|
|
14
|
+
],
|
|
15
|
+
"type": "registry:ui"
|
|
16
|
+
}
|