Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

feat: only show parts from the bill of material in the @mentions

Brad Barbin1b4e4cfd07db
diff --git a/apps/erp/app/modules/items/ui/Item/BillOfProcess.tsx b/apps/erp/app/modules/items/ui/Item/BillOfProcess.tsx
index 776fce845c..5ff3b5609d 100644
--- a/apps/erp/app/modules/items/ui/Item/BillOfProcess.tsx
+++ b/apps/erp/app/modules/items/ui/Item/BillOfProcess.tsx
@@ -122,7 +122,7 @@ import Procedure from "~/components/Form/Procedure";
import { SupplierProcessPreview } from "~/components/Form/SupplierProcess";
import { useUnitOfMeasure } from "~/components/Form/UnitOfMeasure";
import { ProcedureStepTypeIcon } from "~/components/Icons";
-import { useTools } from "~/stores";
+import { useItems, useTools } from "~/stores";
import { getPrivateUrl, path } from "~/utils/path";
import { methodOperationValidator } from "../../items.models";
import type {
@@ -140,10 +140,15 @@ type ItemWithData = Item & {
data: Operation;
};
+type MethodMaterialType = {
+ itemId: string;
+};
+
type BillOfProcessProps = {
configurable?: boolean;
configurationRules?: ConfigurationRule[];
makeMethod: MakeMethod;
+ materials: MethodMaterialType[];
operations: (Operation & {
methodOperationTool: OperationTool[];
methodOperationParameter: OperationParameter[];
@@ -196,6 +201,7 @@ const BillOfProcess = ({
configurable = false,
configurationRules,
makeMethod,
+ materials,
operations: initialOperations,
parameters,
tags,
@@ -212,6 +218,25 @@ const BillOfProcess = ({
const deleteOperationFetcher = useFetcher<{ success: boolean }>();
const { id: userId } = useUser();
+ const [allItems] = useItems();
+
+ const materialItemIds = useMemo(
+ () => new Set((materials ?? []).map((m) => m.itemId)),
+ [materials]
+ );
+
+ const itemMentions = useMemo(
+ () =>
+ allItems
+ .filter((item) => materialItemIds.has(item.id))
+ .map((item) => ({
+ id: item.id,
+ label: item.name ?? item.readableIdWithRevision,
+ helper: item.name ? item.readableIdWithRevision : undefined,
+ })),
+ [allItems, materialItemIds]
+ );
+
const addOperationButtonRef = useRef<HTMLButtonElement>(null);
const [selectedItemId, setSelectedItemId] = useState<string | null>(null);
@@ -530,6 +555,7 @@ const BillOfProcess = ({
}));
onUpdateWorkInstruction(item.id, content);
}}
+ mentions={[{ char: "@", items: itemMentions }]}
className="py-8"
/>
) : (
@@ -630,6 +656,7 @@ const BillOfProcess = ({
configurable={configurable}
rulesByField={rulesByField}
onConfigure={onConfigure}
+ itemMentions={itemMentions}
/>
</div>
),
@@ -1676,6 +1703,7 @@ function AttributesForm({
temporaryItems,
rulesByField,
onConfigure,
+ itemMentions,
}: {
operationId: string;
configurable: boolean;
@@ -1684,6 +1712,7 @@ function AttributesForm({
temporaryItems: TemporaryItems;
rulesByField: Map<string, ConfigurationRule>;
onConfigure?: (c: Configuration) => void;
+ itemMentions: { id: string; label: string }[];
}) {
const fetcher = useFetcher<typeof newMethodOperationParameterAction>();
const sortOrderFetcher = useFetcher<{ success: boolean }>();
@@ -1841,6 +1870,7 @@ function AttributesForm({
onChange={(value) => {
setDescription(value);
}}
+ mentions={[{ char: "@", items: itemMentions }]}
className="[&_.is-empty]:text-muted-foreground min-h-[120px] p-4 rounded-lg border w-full"
/>
</VStack>
@@ -1935,6 +1965,7 @@ function AttributesForm({
configurable={configurable}
rulesByField={rulesByField}
onConfigure={onConfigure}
+ itemMentions={itemMentions}
/>
</Reorder.Item>
);
@@ -1960,6 +1991,7 @@ function AttributesListItem({
rulesByField,
onConfigure,
isDisabled = false,
+ itemMentions,
}: {
attribute: OperationStep;
operationId: string;
@@ -1969,6 +2001,7 @@ function AttributesListItem({
rulesByField: Map<string, ConfigurationRule>;
onConfigure?: (c: Configuration) => void;
isDisabled?: boolean;
+ itemMentions: { id: string; label: string }[];
}) {
const {
name,
@@ -2092,6 +2125,7 @@ function AttributesListItem({
onChange={(value) => {
setDescription(value);
}}
+ mentions={[{ char: "@", items: itemMentions }]}
className="[&_.is-empty]:text-muted-foreground min-h-[120px] p-4 rounded-lg border w-full"
/>
</VStack>
diff --git a/apps/erp/app/modules/production/ui/Jobs/JobBillOfProcess.tsx b/apps/erp/app/modules/production/ui/Jobs/JobBillOfProcess.tsx
index c7a1955305..d714076a6b 100644
--- a/apps/erp/app/modules/production/ui/Jobs/JobBillOfProcess.tsx
+++ b/apps/erp/app/modules/production/ui/Jobs/JobBillOfProcess.tsx
@@ -137,7 +137,7 @@ import UnitOfMeasure, {
useUnitOfMeasure,
} from "~/components/Form/UnitOfMeasure";
import { ProcedureStepTypeIcon } from "~/components/Icons";
-import { usePeople, useTools } from "~/stores";
+import { useItems, usePeople, useTools } from "~/stores";
import { getPrivateUrl, path } from "~/utils/path";
import {
jobOperationValidator,
@@ -165,9 +165,14 @@ type JobOperationStep = OperationStep & {
| null;
};
+type JobMaterial = {
+ itemId: string;
+};
+
type JobBillOfProcessProps = {
jobMakeMethodId: string;
locationId: string;
+ materials: JobMaterial[];
operations: (Operation & {
jobOperationTool: OperationTool[];
jobOperationParameter: OperationParameter[];
@@ -359,6 +364,7 @@ const usePendingOperations = () => {
const JobBillOfProcess = ({
jobMakeMethodId,
locationId,
+ materials,
operations: initialOperations,
tags,
itemId,
@@ -843,6 +849,7 @@ const JobBillOfProcess = ({
selectedItemId === null || !!temporaryItems[selectedItemId]
}
temporaryItems={temporaryItems}
+ materials={materials}
/>
</div>
),
@@ -1045,11 +1052,13 @@ function StepsForm({
isDisabled,
steps,
temporaryItems,
+ materials,
}: {
operationId: string;
isDisabled: boolean;
steps: JobOperationStep[];
temporaryItems: TemporaryItems;
+ materials: JobMaterial[];
}) {
const fetcher = useFetcher<typeof newJobOperationParameterAction>();
const sortOrderFetcher = useFetcher<{ success: boolean }>();
@@ -1118,6 +1127,24 @@ function StepsForm({
const {
company: { id: companyId },
} = useUser();
+ const [allItems] = useItems();
+
+ const materialItemIds = useMemo(
+ () => new Set((materials ?? []).map((m) => m.itemId)),
+ [materials]
+ );
+
+ const itemMentions = useMemo(
+ () =>
+ allItems
+ .filter((item) => materialItemIds.has(item.id))
+ .map((item) => ({
+ id: item.id,
+ label: item.name ?? item.readableIdWithRevision,
+ helper: item.name ? item.readableIdWithRevision : undefined,
+ })),
+ [allItems, materialItemIds]
+ );
const onUploadImage = async (file: File) => {
const fileType = file.name.split(".").pop();
@@ -1208,6 +1235,7 @@ function StepsForm({
onChange={(value) => {
setDescription(value);
}}
+ mentions={[{ char: "@", items: itemMentions }]}
className="[&_.is-empty]:text-muted-foreground min-h-[120px] p-4 rounded-lg border w-full"
/>
</VStack>
@@ -1302,6 +1330,7 @@ function StepsForm({
operationId={operationId}
typeOptions={typeOptions}
isDisabled={isDisabled}
+ itemMentions={itemMentions}
className={
index === sortOrder.length - 1 ? "border-none" : ""
}
@@ -1321,12 +1350,14 @@ function StepsListItem({
operationId,
typeOptions,
isDisabled = false,
+ itemMentions,
className,
}: {
attribute: JobOperationStep;
operationId: string;
typeOptions: { label: JSX.Element; value: string }[];
isDisabled?: boolean;
+ itemMentions: { id: string; label: string }[];
className?: string;
}) {
const {
@@ -1448,6 +1479,7 @@ function StepsListItem({
onChange={(value) => {
setDescription(value);
}}
+ mentions={[{ char: "@", items: itemMentions }]}
className="[&_.is-empty]:text-muted-foreground min-h-[120px] p-4 rounded-lg border w-full"
/>
</VStack>
diff --git a/apps/erp/app/modules/sales/ui/Quotes/QuoteBillOfProcess.tsx b/apps/erp/app/modules/sales/ui/Quotes/QuoteBillOfProcess.tsx
index 9a8a7628ca..64aaa73850 100644
--- a/apps/erp/app/modules/sales/ui/Quotes/QuoteBillOfProcess.tsx
+++ b/apps/erp/app/modules/sales/ui/Quotes/QuoteBillOfProcess.tsx
@@ -108,7 +108,7 @@ import UnitOfMeasure, {
useUnitOfMeasure,
} from "~/components/Form/UnitOfMeasure";
import { ProcedureStepTypeIcon } from "~/components/Icons";
-import { useTools } from "~/stores";
+import { useItems, useTools } from "~/stores";
import { getPrivateUrl, path } from "~/utils/path";
import { quoteOperationValidator } from "../../sales.models";
import type { Quotation } from "../../types";
@@ -122,8 +122,13 @@ type ItemWithData = Item & {
data: Operation;
};
+type QuoteMaterial = {
+ itemId: string;
+};
+
type QuoteBillOfProcessProps = {
quoteMakeMethodId: string;
+ materials: QuoteMaterial[];
operations: (Operation & {
quoteOperationTool: OperationTool[];
quoteOperationParameter: OperationParameter[];
@@ -266,6 +271,7 @@ const usePendingOperations = () => {
const QuoteBillOfProcess = ({
quoteMakeMethodId,
+ materials,
operations: initialOperations,
tags,
}: QuoteBillOfProcessProps) => {
@@ -278,6 +284,25 @@ const QuoteBillOfProcess = ({
company: { id: companyId },
} = useUser();
+ const [allItems] = useItems();
+
+ const materialItemIds = useMemo(
+ () => new Set((materials ?? []).map((m) => m.itemId)),
+ [materials]
+ );
+
+ const itemMentions = useMemo(
+ () =>
+ allItems
+ .filter((item) => materialItemIds.has(item.id))
+ .map((item) => ({
+ id: item.id,
+ label: item.name ?? item.readableIdWithRevision,
+ helper: item.name ? item.readableIdWithRevision : undefined,
+ })),
+ [allItems, materialItemIds]
+ );
+
const addOperationButtonRef = useRef<HTMLButtonElement>(null);
const { quoteId } = useParams();
@@ -581,6 +606,7 @@ const QuoteBillOfProcess = ({
}));
onUpdateWorkInstruction(content);
}}
+ mentions={[{ char: "@", items: itemMentions }]}
className="py-8"
/>
) : (
@@ -672,6 +698,7 @@ const QuoteBillOfProcess = ({
selectedItemId === null || !!temporaryItems[selectedItemId!]
}
temporaryItems={temporaryItems}
+ itemMentions={itemMentions}
/>
</div>
),
@@ -840,11 +867,13 @@ function AttributesForm({
isDisabled,
steps,
temporaryItems,
+ itemMentions,
}: {
operationId: string;
isDisabled: boolean;
steps: OperationStep[];
temporaryItems: TemporaryItems;
+ itemMentions: { id: string; label: string }[];
}) {
const fetcher = useFetcher<typeof newQuoteOperationParameterAction>();
const sortOrderFetcher = useFetcher<{ success: boolean }>();
@@ -1002,6 +1031,7 @@ function AttributesForm({
onChange={(value) => {
setDescription(value);
}}
+ mentions={[{ char: "@", items: itemMentions }]}
className="[&_.is-empty]:text-muted-foreground min-h-[120px] p-4 rounded-lg border w-full"
/>
</VStack>
@@ -1089,6 +1119,7 @@ function AttributesForm({
operationId={operationId}
typeOptions={typeOptions}
isDisabled={isDisabled}
+ itemMentions={itemMentions}
className={
index === sortOrder.length - 1 ? "border-none" : ""
}
@@ -1108,12 +1139,14 @@ function AttributesListItem({
operationId,
typeOptions,
isDisabled = false,
+ itemMentions,
className,
}: {
attribute: OperationStep;
operationId: string;
typeOptions: { label: JSX.Element; value: string }[];
isDisabled?: boolean;
+ itemMentions: { id: string; label: string }[];
className?: string;
}) {
const {
@@ -1236,6 +1269,7 @@ function AttributesListItem({
onChange={(value) => {
setDescription(value);
}}
+ mentions={[{ char: "@", items: itemMentions }]}
className="[&_.is-empty]:text-muted-foreground min-h-[120px] p-4 rounded-lg border w-full"
/>
</VStack>
diff --git a/apps/erp/app/routes/x+/job+/$jobId.make.$methodId.tsx b/apps/erp/app/routes/x+/job+/$jobId.make.$methodId.tsx
index 79808c4cca..d9accab12c 100644
--- a/apps/erp/app/routes/x+/job+/$jobId.make.$methodId.tsx
+++ b/apps/erp/app/routes/x+/job+/$jobId.make.$methodId.tsx
@@ -150,6 +150,7 @@ export default function JobMakeMethodRoute() {
<JobBillOfProcess
key={`bop:${methodId}`}
jobMakeMethodId={methodId}
+ materials={materials}
// @ts-expect-error
operations={operations}
locationId={routeData?.job?.locationId ?? ""}
diff --git a/apps/erp/app/routes/x+/part+/$itemId.manufacturing.$methodId.make.$makeMethodId.tsx b/apps/erp/app/routes/x+/part+/$itemId.manufacturing.$methodId.make.$makeMethodId.tsx
index 5d9f75633e..7f675180a1 100644
--- a/apps/erp/app/routes/x+/part+/$itemId.manufacturing.$methodId.make.$makeMethodId.tsx
+++ b/apps/erp/app/routes/x+/part+/$itemId.manufacturing.$methodId.make.$makeMethodId.tsx
@@ -158,6 +158,7 @@ export default function MethodMaterialMakePage() {
<BillOfMaterial
key={`bom:${itemId}`}
makeMethod={makeMethod}
+ // @ts-ignore
materials={methodMaterials}
operations={methodOperations}
configurable={routeData?.partManufacturing.requiresConfiguration}
@@ -167,6 +168,7 @@ export default function MethodMaterialMakePage() {
<BillOfProcess
key={`bop:${itemId}`}
makeMethod={makeMethod}
+ materials={methodMaterials}
// @ts-ignore
operations={methodOperations}
configurable={routeData?.partManufacturing.requiresConfiguration}
diff --git a/apps/erp/app/routes/x+/part+/$itemId.manufacturing.$methodId.method.tsx b/apps/erp/app/routes/x+/part+/$itemId.manufacturing.$methodId.method.tsx
index f816e13aa5..edc27f771d 100644
--- a/apps/erp/app/routes/x+/part+/$itemId.manufacturing.$methodId.method.tsx
+++ b/apps/erp/app/routes/x+/part+/$itemId.manufacturing.$methodId.method.tsx
@@ -182,6 +182,8 @@ export default function MakeMethodRoute() {
configurable={
manufacturingRouteData?.partManufacturing.requiresConfiguration
}
+ // @ts-ignore
+ materials={manufacturingRouteData?.methodMaterials ?? []}
configurationRules={manufacturingRouteData?.configurationRules}
parameters={
manufacturingRouteData?.configurationParametersAndGroups.parameters
diff --git a/apps/erp/app/routes/x+/quote+/$quoteId.$lineId.make.$methodId.tsx b/apps/erp/app/routes/x+/quote+/$quoteId.$lineId.make.$methodId.tsx
index dd727e27a3..6c1a4a9a9b 100644
--- a/apps/erp/app/routes/x+/quote+/$quoteId.$lineId.make.$methodId.tsx
+++ b/apps/erp/app/routes/x+/quote+/$quoteId.$lineId.make.$methodId.tsx
@@ -123,6 +123,7 @@ export default function QuoteMakeMethodRoute() {
<QuoteBillOfProcess
key={`bop:${methodId}`}
quoteMakeMethodId={methodId}
+ materials={materials}
// @ts-ignore
operations={operations}
tags={tags}
diff --git a/apps/erp/app/routes/x+/tool+/$itemId.manufacturing.$methodId.make.$makeMethodId.tsx b/apps/erp/app/routes/x+/tool+/$itemId.manufacturing.$methodId.make.$makeMethodId.tsx
index 75a6ffdf93..3d69f8ca23 100644
--- a/apps/erp/app/routes/x+/tool+/$itemId.manufacturing.$methodId.make.$makeMethodId.tsx
+++ b/apps/erp/app/routes/x+/tool+/$itemId.manufacturing.$methodId.make.$makeMethodId.tsx
@@ -148,6 +148,7 @@ export default function MethodMaterialMakePage() {
<BillOfProcess
key={`bop:${itemId}`}
makeMethod={makeMethod}
+ materials={methodMaterials}
// @ts-ignore
operations={methodOperations}
// configurable={routeData?.toolManufacturing.requiresConfiguration}
diff --git a/apps/erp/app/styles/tailwind.css b/apps/erp/app/styles/tailwind.css
index d5ee358302..a357d53e3f 100644
--- a/apps/erp/app/styles/tailwind.css
+++ b/apps/erp/app/styles/tailwind.css
@@ -119,6 +119,10 @@ p.is-editor-empty:first-child:before {
@apply ring-2 ring-primary cursor-move p-2 rounded-lg;
}
+.mention {
+ @apply inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-blue-100 text-blue-800 border border-blue-200;
+}
+
@keyframes thinking-spin-outer {
0% {
transform: rotate(0deg);
diff --git a/apps/mes/app/styles/tailwind.css b/apps/mes/app/styles/tailwind.css
index b20c360888..49e330d3ae 100644
--- a/apps/mes/app/styles/tailwind.css
+++ b/apps/mes/app/styles/tailwind.css
@@ -121,6 +121,10 @@ p.is-editor-empty:first-child:before {
@apply ring-2 ring-primary cursor-move p-2 rounded-lg;
}
+.mention {
+ @apply inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-blue-100 text-blue-800 border border-blue-200;
+}
+
.hexagon-loader-container {
@apply relative w-full py-4;
}
diff --git a/package-lock.json b/package-lock.json
index d8b60e0c03..62ebc6ebf4 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -44607,6 +44607,7 @@
"version": "*",
"dependencies": {
"@radix-ui/react-slot": "^1.1.1",
+ "@tanstack/react-virtual": "^3.5.0",
"@tiptap/core": "^2.11.2",
"@tiptap/extension-character-count": "^2.11.2",
"@tiptap/extension-code-block-lowlight": "^2.11.2",
@@ -44615,6 +44616,7 @@
"@tiptap/extension-horizontal-rule": "^2.11.2",
"@tiptap/extension-image": "^2.11.2",
"@tiptap/extension-link": "^2.11.2",
+ "@tiptap/extension-mention": "^2.11.2",
"@tiptap/extension-placeholder": "^2.11.2",
"@tiptap/extension-task-item": "^2.11.2",
"@tiptap/extension-task-list": "^2.11.2",
@@ -44700,6 +44702,21 @@
"integrity": "sha512-42aWfPrimMfDKDi4YegyS7x+/0tlzaqwPQCULLanv3DMIlu96KTJR0fM5isWX2UViOqlGnX6YFgqWepcX+XMNg==",
"license": "MIT"
},
+ "packages/tiptap/node_modules/@tiptap/extension-mention": {
+ "version": "2.27.1",
+ "resolved": "https://registry.npmjs.org/@tiptap/extension-mention/-/extension-mention-2.27.1.tgz",
+ "integrity": "sha512-8qwPIum0rMK/7BaHEN0+M/VkUn00LqhqyRO8JdC/EBVrUBgxKTQsUhIhSstgVAYzD1w7cCUfTFX4bYu9lcFMEQ==",
+ "license": "MIT",
+ "funding": {
+ "type": "github",
+ "url": "https://github.com/sponsors/ueberdosis"
+ },
+ "peerDependencies": {
+ "@tiptap/core": "^2.7.0",
+ "@tiptap/pm": "^2.7.0",
+ "@tiptap/suggestion": "^2.7.0"
+ }
+ },
"packages/tiptap/node_modules/@tiptap/pm": {
"version": "2.27.1",
"resolved": "https://registry.npmjs.org/@tiptap/pm/-/pm-2.27.1.tgz",
diff --git a/packages/react/src/Editor/Editor.tsx b/packages/react/src/Editor/Editor.tsx
index 5ba99be58e..073f6ea31d 100644
--- a/packages/react/src/Editor/Editor.tsx
+++ b/packages/react/src/Editor/Editor.tsx
@@ -1,8 +1,9 @@
"use client";
-import type { JSONContent } from "@carbon/tiptap";
+import type { JSONContent, MentionSuggestion } from "@carbon/tiptap";
import {
Command,
+ createMentionExtension,
EditorBubble,
EditorCommand,
EditorCommandEmpty,
@@ -18,7 +19,7 @@ import {
renderItems,
} from "@carbon/tiptap";
import TextStyle from "@tiptap/extension-text-style";
-import { useMemo, useState } from "react";
+import { useMemo, useRef, useState } from "react";
import { toast } from "sonner";
import { Separator } from "../Separator";
import { cn } from "../utils/cn";
@@ -29,12 +30,32 @@ import { TextButtons } from "./components/TextButton";
import { defaultExtensions } from "./extensions";
import { getSuggestionItems } from "./slash";
+interface MentionConfig {
+ /**
+ * Trigger character for this mention type (e.g., "@" for items)
+ */
+ char: string;
+ /**
+ * List of suggestions to show
+ */
+ items: MentionSuggestion[];
+}
+
interface EditorProp {
className?: string;
initialValue?: JSONContent;
onChange: (value: JSONContent) => void;
onUpload?: (file: File) => Promise<string>;
disableFileUpload?: boolean;
+ /**
+ * Optional mention configurations. Each config creates a mention extension
+ * with a unique trigger character.
+ * @example
+ * mentions={[
+ * { char: "@", items: [{ id: "1", label: "Widget A" }] }
+ * ]}
+ */
+ mentions?: MentionConfig[];
}
const defaultOnUpload = async (file: File) => {
@@ -50,11 +71,19 @@ const Editor = ({
onChange,
onUpload,
disableFileUpload,
+ mentions,
}: EditorProp) => {
const [openNode, setOpenNode] = useState(false);
const [openColor, setOpenColor] = useState(false);
const [openLink, setOpenLink] = useState(false);
+ // Use a ref to hold the current mention items so the extension can access
+ // the latest items without needing to be recreated
+ const mentionItemsRef = useRef<MentionSuggestion[]>([]);
+ if (mentions && mentions.length > 0) {
+ mentionItemsRef.current = mentions[0].items;
+ }
+
const uploadFn = useMemo(() => {
const uploadHandler = onUpload ? onUpload : defaultOnUpload;
return createImageUpload({
@@ -81,6 +110,21 @@ const Editor = ({
[uploadFn]
);
+ const mentionExtension = useMemo(() => {
+ if (!mentions || mentions.length === 0) return null;
+ // Use the first mention config - if multiple are needed with different
+ // trigger characters, this would need to be extended
+ const config = mentions[0];
+ return createMentionExtension({
+ name: "mention",
+ char: config.char,
+ // Pass a getter function so the extension always gets the latest items
+ items: () => mentionItemsRef.current,
+ });
+ // Only depend on mentions existence and char, not items content
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [mentions?.[0]?.char]);
+
const extensions = useMemo(
() => [
...defaultExtensions,
@@ -91,8 +135,9 @@ const Editor = ({
render: renderItems,
},
}),
+ ...(mentionExtension ? [mentionExtension] : []),
],
- [suggestionItems]
+ [suggestionItems, mentionExtension]
);
return (
diff --git a/packages/react/src/Editor/index.ts b/packages/react/src/Editor/index.ts
index 7c3c23e9c9..6ad7aab59e 100644
--- a/packages/react/src/Editor/index.ts
+++ b/packages/react/src/Editor/index.ts
@@ -1,3 +1,4 @@
import Editor from "./Editor";
export { Editor };
+export type { MentionSuggestion } from "@carbon/tiptap";
diff --git a/packages/react/src/HTML.tsx b/packages/react/src/HTML.tsx
index b0daef2cbf..541312b8fe 100644
--- a/packages/react/src/HTML.tsx
+++ b/packages/react/src/HTML.tsx
@@ -1,3 +1,4 @@
+import { Mention } from "@carbon/tiptap";
import TextStyle from "@tiptap/extension-text-style";
import Underline from "@tiptap/extension-underline";
import type { JSONContent } from "@tiptap/react";
@@ -20,6 +21,11 @@ const generateHTML = (content: JSONContent) => {
TextStyle,
StarterKit,
Underline,
+ Mention.configure({
+ HTMLAttributes: {
+ class: "mention",
+ },
+ }),
]);
};
diff --git a/packages/tiptap/package.json b/packages/tiptap/package.json
index 7d1cc65b8a..2ba2bf2c8d 100644
--- a/packages/tiptap/package.json
+++ b/packages/tiptap/package.json
@@ -2,6 +2,7 @@
"name": "@carbon/tiptap",
"dependencies": {
"@radix-ui/react-slot": "^1.1.1",
+ "@tanstack/react-virtual": "^3.5.0",
"@tiptap/core": "^2.11.2",
"@tiptap/extension-character-count": "^2.11.2",
"@tiptap/extension-code-block-lowlight": "^2.11.2",
@@ -10,6 +11,7 @@
"@tiptap/extension-horizontal-rule": "^2.11.2",
"@tiptap/extension-image": "^2.11.2",
"@tiptap/extension-link": "^2.11.2",
+ "@tiptap/extension-mention": "^2.11.2",
"@tiptap/extension-placeholder": "^2.11.2",
"@tiptap/extension-task-item": "^2.11.2",
"@tiptap/extension-task-list": "^2.11.2",
diff --git a/packages/tiptap/src/components/index.ts b/packages/tiptap/src/components/index.ts
index 0a2bb710ce..21644abe8a 100644
--- a/packages/tiptap/src/components/index.ts
+++ b/packages/tiptap/src/components/index.ts
@@ -7,3 +7,8 @@ export { EditorBubble } from "./editor-bubble";
export { EditorBubbleItem } from "./editor-bubble-item";
export { EditorCommand, EditorCommandList } from "./editor-command";
export { EditorCommandItem, EditorCommandEmpty } from "./editor-command-item";
+export {
+ MentionList,
+ type MentionListRef,
+ type MentionListProps,
+} from "./mention-list";
diff --git a/packages/tiptap/src/components/mention-list.tsx b/packages/tiptap/src/components/mention-list.tsx
new file mode 100644
index 0000000000..1ca1ed895c
--- /dev/null
+++ b/packages/tiptap/src/components/mention-list.tsx
@@ -0,0 +1,153 @@
+import { useVirtualizer } from "@tanstack/react-virtual";
+import type {
+ SuggestionKeyDownProps,
+ SuggestionProps,
+} from "@tiptap/suggestion";
+import {
+ forwardRef,
+ useEffect,
+ useImperativeHandle,
+ useRef,
+ useState,
+} from "react";
+import type { MentionSuggestion } from "../extensions/mention";
+
+export interface MentionListRef {
+ onKeyDown: (props: SuggestionKeyDownProps) => boolean;
+}
+
+export interface MentionListProps extends SuggestionProps<MentionSuggestion> {}
+
+const ITEM_HEIGHT = 44;
+const MAX_VISIBLE_ITEMS = 6;
+
+export const MentionList = forwardRef<MentionListRef, MentionListProps>(
+ (props, ref) => {
+ const [selectedIndex, setSelectedIndex] = useState(0);
+ const parentRef = useRef<HTMLDivElement>(null);
+
+ const virtualizer = useVirtualizer({
+ count: props.items.length,
+ getScrollElement: () => parentRef.current,
+ estimateSize: () => ITEM_HEIGHT,
+ overscan: 5,
+ });
+
+ const selectItem = (index: number) => {
+ const item = props.items[index];
+
+ if (item) {
+ props.command(item);
+ }
+ };
+
+ const upHandler = () => {
+ const newIndex =
+ (selectedIndex + props.items.length - 1) % props.items.length;
+ setSelectedIndex(newIndex);
+ virtualizer.scrollToIndex(newIndex, { align: "auto" });
+ };
+
+ const downHandler = () => {
+ const newIndex = (selectedIndex + 1) % props.items.length;
+ setSelectedIndex(newIndex);
+ virtualizer.scrollToIndex(newIndex, { align: "auto" });
+ };
+
+ const enterHandler = () => {
+ selectItem(selectedIndex);
+ };
+
+ useEffect(() => setSelectedIndex(0), [props.items]);
+
+ useImperativeHandle(ref, () => ({
+ onKeyDown: ({ event }: SuggestionKeyDownProps) => {
+ if (event.key === "ArrowUp") {
+ upHandler();
+ return true;
+ }
+
+ if (event.key === "ArrowDown") {
+ downHandler();
+ return true;
+ }
+
+ if (event.key === "Enter") {
+ enterHandler();
+ return true;
+ }
+
+ return false;
+ },
+ }));
+
+ if (props.items.length === 0) {
+ return (
+ <div className="bg-popover border rounded-md shadow-md p-2 text-muted-foreground text-sm">
+ No results
+ </div>
+ );
+ }
+
+ const virtualItems = virtualizer.getVirtualItems();
+
+ return (
+ <div className="bg-popover text-popover-foreground border rounded-md shadow-md overflow-hidden min-w-[240px]">
+ <div
+ ref={parentRef}
+ className="overflow-auto scrollbar-thin scrollbar-track-transparent scrollbar-thumb-accent"
+ style={{
+ height: `${
+ Math.min(props.items.length, MAX_VISIBLE_ITEMS) * ITEM_HEIGHT
+ }px`,
+ }}
+ >
+ <div
+ style={{
+ height: `${virtualizer.getTotalSize()}px`,
+ width: "100%",
+ position: "relative",
+ }}
+ >
+ {virtualItems.map((virtualRow) => {
+ const item = props.items[virtualRow.index];
+ const isSelected = virtualRow.index === selectedIndex;
+
+ return (
+ <button
+ type="button"
+ className={`absolute top-0 left-0 w-full text-left px-3 text-sm ${
+ isSelected
+ ? "bg-accent text-accent-foreground"
+ : "hover:bg-accent/50"
+ }`}
+ style={{
+ height: `${ITEM_HEIGHT}px`,
+ transform: `translateY(${virtualRow.start}px)`,
+ }}
+ key={item.id}
+ onClick={() => selectItem(virtualRow.index)}
+ >
+ {item.helper ? (
+ <div className="flex flex-col justify-center gap-0.5 py-1 h-full">
+ <p className="line-clamp-1 leading-tight">{item.label}</p>
+ <p className="text-xs text-muted-foreground line-clamp-1 leading-tight">
+ {item.helper}
+ </p>
+ </div>
+ ) : (
+ <div className="flex items-center h-full">
+ <span className="line-clamp-1">{item.label}</span>
+ </div>
+ )}
+ </button>
+ );
+ })}
+ </div>
+ </div>
+ </div>
+ );
+ }
+);
+
+MentionList.displayName = "MentionList";
diff --git a/packages/tiptap/src/extensions/index.ts b/packages/tiptap/src/extensions/index.ts
index 7f19c50cef..89cbfd598a 100644
--- a/packages/tiptap/src/extensions/index.ts
+++ b/packages/tiptap/src/extensions/index.ts
@@ -62,6 +62,7 @@ const Horizontal = HorizontalRule.extend({
});
export * from "./ai-highlight";
+export * from "./mention";
export * from "./slash-command";
export {
CharacterCount,
diff --git a/packages/tiptap/src/extensions/mention.tsx b/packages/tiptap/src/extensions/mention.tsx
new file mode 100644
index 0000000000..0be0eceb31
--- /dev/null
+++ b/packages/tiptap/src/extensions/mention.tsx
@@ -0,0 +1,164 @@
+import Mention from "@tiptap/extension-mention";
+import type { MentionOptions } from "@tiptap/extension-mention";
+import { ReactRenderer } from "@tiptap/react";
+import type {
+ SuggestionProps,
+ SuggestionKeyDownProps,
+} from "@tiptap/suggestion";
+import type { RefObject } from "react";
+import tippy, { type Instance, type Props } from "tippy.js";
+import { MentionList, type MentionListRef } from "../components/mention-list";
+
+export interface MentionSuggestion {
+ id: string;
+ label: string;
+ helper?: string;
+}
+
+export interface CreateMentionSuggestionOptions {
+ /**
+ * The trigger character for this mention type (e.g., "@" for users, "#" for tags)
+ */
+ char: string;
+ /**
+ * The list of suggestions to show, or a function that returns them
+ */
+ items: MentionSuggestion[] | (() => MentionSuggestion[]);
+ /**
+ * Optional ref to the element to append the popup to
+ */
+ elementRef?: RefObject<Element> | null;
+}
+
+export function createMentionSuggestion({
+ char,
+ items,
+ elementRef,
+}: CreateMentionSuggestionOptions): MentionOptions["suggestion"] {
+ return {
+ char,
+ items: ({ query }) => {
+ const itemList = typeof items === "function" ? items() : items;
+ return itemList.filter((item) =>
+ item.label.toLowerCase().startsWith(query.toLowerCase())
+ );
+ },
+ render: () => {
+ let component: ReactRenderer<MentionListRef> | null = null;
+ let popup: Instance<Props>[] | null = null;
+
+ return {
+ onStart: (props: SuggestionProps<MentionSuggestion>) => {
+ component = new ReactRenderer(MentionList, {
+ props,
+ editor: props.editor,
+ });
+
+ if (!props.clientRect) {
+ return;
+ }
+
+ popup = tippy("body", {
+ getReferenceClientRect: props.clientRect as () => DOMRect,
+ appendTo: () => elementRef?.current ?? document.body,
+ content: component.element,
+ showOnCreate: true,
+ interactive: true,
+ trigger: "manual",
+ placement: "bottom-start",
+ });
+ },
+
+ onUpdate(props: SuggestionProps<MentionSuggestion>) {
+ component?.updateProps(props);
+
+ if (!props.clientRect) {
+ return;
+ }
+
+ popup?.[0]?.setProps({
+ getReferenceClientRect: props.clientRect as () => DOMRect,
+ });
+ },
+
+ onKeyDown(props: SuggestionKeyDownProps) {
+ if (props.event.key === "Escape") {
+ popup?.[0]?.hide();
+ return true;
+ }
+
+ return component?.ref?.onKeyDown(props) ?? false;
+ },
+
+ onExit() {
+ popup?.[0]?.destroy();
+ component?.destroy();
+ },
+ };
+ },
+ };
+}
+
+export interface CreateMentionExtensionOptions {
+ /**
+ * A unique name for this mention extension (e.g., "item-mention", "customer-mention")
+ */
+ name: string;
+ /**
+ * The trigger character for this mention type
+ */
+ char: string;
+ /**
+ * The list of suggestions, or a function that returns them
+ */
+ items: MentionSuggestion[] | (() => MentionSuggestion[]);
+ /**
+ * Optional ref to append popup to
+ */
+ elementRef?: RefObject<Element> | null;
+}
+
+/**
+ * Creates a configured mention extension for a specific type of mention.
+ *
+ * @example
+ * // Create an items mention with @ trigger
+ * const ItemMention = createMentionExtension({
+ * name: "item-mention",
+ * char: "@",
+ * items: [
+ * { id: "1", label: "Widget A" },
+ * { id: "2", label: "Widget B" },
+ * ],
+ * });
+ *
+ * @example
+ * // Create a customer mention with # trigger
+ * const CustomerMention = createMentionExtension({
+ * name: "customer-mention",
+ * char: "#",
+ * items: [
+ * { id: "c1", label: "Acme Corp" },
+ * { id: "c2", label: "Global Inc" },
+ * ],
+ * });
+ */
+export function createMentionExtension({
+ name,
+ char,
+ items,
+ elementRef,
+}: CreateMentionExtensionOptions) {
+ return Mention.configure({
+ HTMLAttributes: {
+ class:
+ "inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-blue-100 text-blue-800 dark:bg-blue-900/50 dark:text-blue-400",
+ "data-mention-type": name,
+ },
+ suggestion: createMentionSuggestion({ char, items, elementRef }),
+ }).extend({
+ name,
+ });
+}
+
+export { Mention };
diff --git a/packages/tiptap/src/index.ts b/packages/tiptap/src/index.ts
index f9fec7fa0d..38ac4b1684 100644
--- a/packages/tiptap/src/index.ts
+++ b/packages/tiptap/src/index.ts
@@ -8,10 +8,13 @@ export {
EditorCommandList,
EditorContent,
EditorRoot,
+ MentionList,
useEditor,
type EditorContentProps,
type EditorInstance,
type JSONContent,
+ type MentionListProps,
+ type MentionListRef,
} from "./components";
// Extensions
@@ -22,6 +25,8 @@ export {
CodeBlockLowlight,
Color,
Command,
+ createMentionExtension,
+ createMentionSuggestion,
createSuggestionItems,
CustomKeymap,
GlobalDragHandle,
@@ -31,6 +36,7 @@ export {
ImageResizer,
InputRule,
MarkdownExtension,
+ Mention,
Placeholder,
removeAIHighlight,
renderItems,
@@ -43,6 +49,9 @@ export {
TiptapUnderline,
UpdatedImage,
Youtube,
+ type CreateMentionExtensionOptions,
+ type CreateMentionSuggestionOptions,
+ type MentionSuggestion,
type SuggestionItem,
} from "./extensions";