Address Greptile review on UI polish PR
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
parent
c3f4e18a5e
commit
6960ab1106
3 changed files with 51 additions and 19 deletions
|
|
@ -26,22 +26,52 @@ import {
|
||||||
thematicBreakPlugin,
|
thematicBreakPlugin,
|
||||||
type RealmPlugin,
|
type RealmPlugin,
|
||||||
} from "@mdxeditor/editor";
|
} from "@mdxeditor/editor";
|
||||||
import { LinkNode } from "@lexical/link";
|
import { LinkNode, type LinkAttributes } from "@lexical/link";
|
||||||
import { buildAgentMentionHref, buildProjectMentionHref } from "@paperclipai/shared";
|
import { buildAgentMentionHref, buildProjectMentionHref } from "@paperclipai/shared";
|
||||||
import { AgentIcon } from "./AgentIconPicker";
|
import { AgentIcon } from "./AgentIconPicker";
|
||||||
import { applyMentionChipDecoration, clearMentionChipDecoration, parseMentionChipHref } from "../lib/mention-chips";
|
import { applyMentionChipDecoration, clearMentionChipDecoration, parseMentionChipHref } from "../lib/mention-chips";
|
||||||
import { mentionDeletionPlugin } from "../lib/mention-deletion";
|
import { mentionDeletionPlugin } from "../lib/mention-deletion";
|
||||||
import { cn } from "../lib/utils";
|
import { cn } from "../lib/utils";
|
||||||
|
|
||||||
/* ---- Allow custom mention URL schemes in Lexical's LinkNode ---- */
|
const CUSTOM_MENTION_URL_RE = /^(agent|project):\/\//;
|
||||||
// Lexical only allows http(s)/mailto/sms/tel by default, converting
|
|
||||||
// everything else to about:blank. We need agent:// and project://
|
class MentionAwareLinkNode extends LinkNode {
|
||||||
// to survive the markdown→Lexical import so mention chips render.
|
static clone(node: MentionAwareLinkNode): MentionAwareLinkNode {
|
||||||
const _origSanitizeUrl = LinkNode.prototype.sanitizeUrl;
|
return new MentionAwareLinkNode(
|
||||||
LinkNode.prototype.sanitizeUrl = function sanitizeUrl(url: string): string {
|
node.getURL(),
|
||||||
if (/^(agent|project):\/\//.test(url)) return url;
|
{
|
||||||
return _origSanitizeUrl.call(this, url);
|
rel: node.getRel(),
|
||||||
};
|
target: node.getTarget(),
|
||||||
|
title: node.getTitle(),
|
||||||
|
},
|
||||||
|
node.getKey(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(url?: string, attributes?: LinkAttributes, key?: string) {
|
||||||
|
super(url, attributes, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
sanitizeUrl(url: string): string {
|
||||||
|
if (CUSTOM_MENTION_URL_RE.test(url)) return url;
|
||||||
|
return super.sanitizeUrl(url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const mentionAwareLinkNodeReplacement = {
|
||||||
|
replace: LinkNode,
|
||||||
|
with: (node: LinkNode) =>
|
||||||
|
new MentionAwareLinkNode(
|
||||||
|
node.getURL(),
|
||||||
|
{
|
||||||
|
rel: node.getRel(),
|
||||||
|
target: node.getTarget(),
|
||||||
|
title: node.getTitle(),
|
||||||
|
},
|
||||||
|
node.getKey(),
|
||||||
|
),
|
||||||
|
withKlass: MentionAwareLinkNode,
|
||||||
|
} as const;
|
||||||
|
|
||||||
/* ---- Mention types ---- */
|
/* ---- Mention types ---- */
|
||||||
|
|
||||||
|
|
@ -560,6 +590,7 @@ export const MarkdownEditor = forwardRef<MarkdownEditorRef, MarkdownEditorProps>
|
||||||
"paperclip-mdxeditor-content focus:outline-none [&_ul]:list-disc [&_ul]:pl-5 [&_ol]:list-decimal [&_ol]:pl-5 [&_li]:list-item",
|
"paperclip-mdxeditor-content focus:outline-none [&_ul]:list-disc [&_ul]:pl-5 [&_ol]:list-decimal [&_ol]:pl-5 [&_li]:list-item",
|
||||||
contentClassName,
|
contentClassName,
|
||||||
)}
|
)}
|
||||||
|
additionalLexicalNodes={[mentionAwareLinkNodeReplacement]}
|
||||||
plugins={plugins}
|
plugins={plugins}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -664,6 +664,7 @@ export function LiveUpdatesProvider({ children }: { children: ReactNode }) {
|
||||||
const { pushToast } = useToast();
|
const { pushToast } = useToast();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const gateRef = useRef<ToastGate>({ cooldownHits: new Map(), suppressUntil: 0 });
|
const gateRef = useRef<ToastGate>({ cooldownHits: new Map(), suppressUntil: 0 });
|
||||||
|
const pathnameRef = useRef(location.pathname);
|
||||||
const { data: session } = useQuery({
|
const { data: session } = useQuery({
|
||||||
queryKey: queryKeys.auth.session,
|
queryKey: queryKeys.auth.session,
|
||||||
queryFn: () => authApi.getSession(),
|
queryFn: () => authApi.getSession(),
|
||||||
|
|
@ -671,6 +672,10 @@ export function LiveUpdatesProvider({ children }: { children: ReactNode }) {
|
||||||
});
|
});
|
||||||
const currentUserId = session?.user?.id ?? session?.session?.userId ?? null;
|
const currentUserId = session?.user?.id ?? session?.session?.userId ?? null;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
pathnameRef.current = location.pathname;
|
||||||
|
}, [location.pathname]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!selectedCompanyId) return;
|
if (!selectedCompanyId) return;
|
||||||
|
|
||||||
|
|
@ -715,7 +720,7 @@ export function LiveUpdatesProvider({ children }: { children: ReactNode }) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const parsed = JSON.parse(raw) as LiveEvent;
|
const parsed = JSON.parse(raw) as LiveEvent;
|
||||||
handleLiveEvent(queryClient, selectedCompanyId, location.pathname, parsed, pushToast, gateRef.current, {
|
handleLiveEvent(queryClient, selectedCompanyId, pathnameRef.current, parsed, pushToast, gateRef.current, {
|
||||||
userId: currentUserId,
|
userId: currentUserId,
|
||||||
agentId: null,
|
agentId: null,
|
||||||
});
|
});
|
||||||
|
|
@ -747,7 +752,7 @@ export function LiveUpdatesProvider({ children }: { children: ReactNode }) {
|
||||||
socket.close(1000, "provider_unmount");
|
socket.close(1000, "provider_unmount");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}, [queryClient, selectedCompanyId, pushToast, currentUserId, location.pathname]);
|
}, [queryClient, selectedCompanyId, pushToast, currentUserId]);
|
||||||
|
|
||||||
return <>{children}</>;
|
return <>{children}</>;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -112,15 +112,11 @@ function buildAgentIconMask(iconName: string | null): string | null {
|
||||||
if (cached) return cached;
|
if (cached) return cached;
|
||||||
|
|
||||||
const Icon = getAgentIcon(iconName);
|
const Icon = getAgentIcon(iconName);
|
||||||
const rendered = (
|
const iconNode = (
|
||||||
Icon as unknown as {
|
Icon as unknown as {
|
||||||
render: (
|
iconNode?: Array<[string, Record<string, string>]>;
|
||||||
props: Record<string, unknown>,
|
|
||||||
ref: unknown,
|
|
||||||
) => { props?: { iconNode?: Array<[string, Record<string, string>]> } };
|
|
||||||
}
|
}
|
||||||
).render({ size: 12, strokeWidth: 2 }, null);
|
).iconNode;
|
||||||
const iconNode = rendered?.props?.iconNode;
|
|
||||||
if (!Array.isArray(iconNode) || iconNode.length === 0) return null;
|
if (!Array.isArray(iconNode) || iconNode.length === 0) return null;
|
||||||
|
|
||||||
const body = iconNode.map(([tag, attrs]) => {
|
const body = iconNode.map(([tag, attrs]) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue