Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(md): go to location for comments (#2934)
Seamus5d594e60b85b
diff --git a/js/app/packages/block-call/component/CallBlockAdapter.tsx b/js/app/packages/block-call/component/CallBlockAdapter.tsxindex 902ef57269..8c47c25cf1 100644--- a/js/app/packages/block-call/component/CallBlockAdapter.tsx+++ b/js/app/packages/block-call/component/CallBlockAdapter.tsx@@ -24,28 +24,22 @@ export function CallBlockAdapter() {{(data) => <CallRecordingBody data={data} />}</Match><Match when={callRecord.isLoading}>- <>- <CallRecordingSplitHeaderLoading />- <div class="flex flex-1 min-h-0 items-center justify-center text-sm text-ink-faint">- Loading call...- </div>- </>+ <CallRecordingSplitHeaderLoading />+ <div class="flex flex-1 min-h-0 items-center justify-center text-sm text-ink-faint">+ Loading call...+ </div></Match><Match when={callRecord.isError && isUnauthorized(callRecord.error)}>- <>- <CallRecordingSplitHeaderLoading />- <div class="flex flex-1 min-h-0 overflow-hidden">- <Unauthorized />- </div>- </>+ <CallRecordingSplitHeaderLoading />+ <div class="flex flex-1 min-h-0 overflow-hidden">+ <Unauthorized />+ </div></Match><Match when={callRecord.isError}>- <>- <CallRecordingSplitHeaderLoading />- <div class="flex flex-1 min-h-0 items-center justify-center text-sm text-failure">- Failed to load call recording.- </div>- </>+ <CallRecordingSplitHeaderLoading />+ <div class="flex flex-1 min-h-0 items-center justify-center text-sm text-failure">+ Failed to load call recording.+ </div></Match></Switch></div>diff --git a/js/app/packages/block-md/comments/CommentMargin.tsx b/js/app/packages/block-md/comments/CommentMargin.tsxindex 9843645658..a57eae0492 100644--- a/js/app/packages/block-md/comments/CommentMargin.tsx+++ b/js/app/packages/block-md/comments/CommentMargin.tsx@@ -2,6 +2,7 @@ import {activeCommentThreadSignal,commentsStore,commentWidthSignal,+ highlightedCommentIdSignal,highlightedCommentThreadsSignal,showCommentsPreference,threadStore,@@ -80,8 +81,8 @@ const useCommentsContext = (): CommentsContextType => {updateComment,},inComment: true,+ highlightedCommentId: highlightedCommentIdSignal.get,};-return commentsContext;};diff --git a/js/app/packages/block-md/comments/CommentsProvider.tsx b/js/app/packages/block-md/comments/CommentsProvider.tsxindex 359d01f307..e33236e7b6 100644--- a/js/app/packages/block-md/comments/CommentsProvider.tsx+++ b/js/app/packages/block-md/comments/CommentsProvider.tsx@@ -2,30 +2,100 @@ import {isWrapperWithIds,LexicalWrapperContext,} from '@core/component/LexicalMarkdown/context/LexicalWrapperContext';-import { commentPlugin } from '@core/component/LexicalMarkdown/plugins/comments/commentPlugin';+import {+ commentPlugin,+ MARK_SELECTED_COMMENT_COMMAND,+} from '@core/component/LexicalMarkdown/plugins/comments/commentPlugin';+import { autoRegister } from '@core/component/LexicalMarkdown/plugins';import { blockLoroManagerSignal } from '@core/signal/load';+import { isRoot, type Reply, type Root } from '@core/comments/commentType';+import { useUserId } from '@core/context/user';import type { CommentNode } from '@lexical-core';-import { useContext } from 'solid-js';-import { useDeleteComment } from './commentOperations';+import { COMMAND_PRIORITY_LOW, SELECTION_CHANGE_COMMAND } from 'lexical';+import {+ createEffect,+ createMemo,+ untrack,+ useContext,+ type Accessor,+ type VoidComponent,+} from 'solid-js';+import { reconcile } from 'solid-js/store';+import { useDeleteComment, useDeleteNewComments } from './commentOperations';+import { commentThreadsResource, sortComments } from './commentsResource';+import type { Mark, ThreadMetadata, ThreadStore } from './commentType';import {+ activeCommentThreadSignal,activeMarkIdsSignal,commentMarksInitializedSignal,+ commentsStore,+ highlightedCommentIdSignal,+ highlightedCommentThreadsSignal,markStore,+ threadStore,} from './commentStore';-export function CommentsProvider() {+function getHighlightThread(+ highlight: Mark+): { root: Root; replies: Reply[] } | null {+ const thread = highlight.thread;+ if (!thread) return null;++ const comments = thread.comments;+ const rootComment = comments[0];+ const commentBase = {+ isNew: false,+ threadId: rootComment.threadId,+ rootId: rootComment.commentId,+ anchorId: highlight.id,+ };++ const replies: Reply[] = [];+ for (let i = 1; i < comments.length; i++) {+ const comment = comments[i];+ replies.push({+ ...commentBase,+ id: comment.commentId,+ createdAt: comment.createdAt,+ owner: comment.owner,+ author: comment.sender || comment.owner,+ text: comment.text,+ });+ }++ const root: Root = {+ ...commentBase,+ id: rootComment.commentId,+ createdAt: rootComment.createdAt,+ owner: rootComment.owner,+ author: rootComment.sender || rootComment.owner,+ text: rootComment.text,+ children: replies.map((r) => r.id),+ };++ return { root, replies };+}++export const CommentsProvider: VoidComponent<{+ activeComment?: Accessor<string | undefined>;+}> = (props) => {const wrapper = useContext(LexicalWrapperContext);if (!isWrapperWithIds(wrapper)) {- return '';+ console.error('Cannot use comment plugin without node ids.');+ return null;}- const { plugins } = wrapper;+ const { plugins, editor } = wrapper;const loroManager = blockLoroManagerSignal.get;const currentPeerId = () => loroManager()?.getPeerIdStr();const [marks, setMarks] = markStore;+ const [commentThreadsData] = commentThreadsResource;const [, setCommentsInitialized] = commentMarksInitializedSignal;+ const [highlightedId, setHighlightedId] = highlightedCommentIdSignal;const setActiveMarkIds = activeMarkIdsSignal.set;++ /** Communicates comment ready to block. */const initComments = () => setCommentsInitialized(true);const addCommentMark = (@@ -36,7 +106,6 @@ export function CommentsProvider() {isDraft: boolean,isLocal: boolean) => {- // console.trace('adding comment mark', { markNode, isDraft, isLocal });const markNodeKey = markNode.getKey();const existing = marks[markId];@@ -45,7 +114,6 @@ export function CommentsProvider() {return;}- // Ignore external drafts.if (isDraft && !isLocal) {return;}@@ -61,6 +129,7 @@ export function CommentsProvider() {};const deleteComment = useDeleteComment();+ const deleteNewComments = useDeleteNewComments();const removeCommentMark = (markId: string, markNodeKey: string) => {const existing = marks[markId];@@ -82,6 +151,188 @@ export function CommentsProvider() {}};+ // Remove the temporary draft comment when the active thread is cleared+ createEffect(() => {+ const activeThreadId = activeCommentThreadSignal();+ if (!activeThreadId) {+ deleteNewComments(false);+ return;+ }++ const thread = threadStore.get[activeThreadId];+ if (!thread) return;++ const markId = thread.anchorId;+ const existingMarkIds = untrack(activeMarkIdsSignal);+ if (+ existingMarkIds.length > 0 &&+ existingMarkIds.every((id) => id === markId)+ ) {+ return;+ }++ editor.dispatchCommand(MARK_SELECTED_COMMENT_COMMAND, [markId]);+ });++ // Sync active mark selections to thread signals+ createEffect(() => {+ const activeMarkIds = activeMarkIdsSignal();+ if (activeMarkIds.length === 0) {+ activeCommentThreadSignal.set(null);+ highlightedCommentThreadsSignal.set([]);+ return;+ }++ const threadIds: number[] = [];+ for (const id of activeMarkIds) {+ const mark = marks[id];+ if (!mark) continue;+ if (mark.thread == null) {+ activeCommentThreadSignal.set(-1);+ return;+ } else {+ threadIds.push(mark.thread.threadId);+ }+ }++ activeCommentThreadSignal.set(null);+ highlightedCommentThreadsSignal.set(threadIds);+ });++ // Compute visible comment threads from marks+ const userId = useUserId();+ const highlightComments = createMemo(() => {+ const currentUserId = userId();+ const out: (Root | Reply)[] = [];+ for (const mark of Object.values(marks ?? {})) {+ if (!mark) continue;++ if (!mark.existsOnServer) {+ if (!currentUserId) {+ console.error('User ID not found');+ continue;+ }+ const rootComment: Root = {+ id: -1,+ rootId: -1,+ text: '',+ owner: currentUserId,+ author: currentUserId,+ createdAt: new Date(),+ isNew: true,+ children: [],+ threadId: -1,+ anchorId: mark.id,+ };+ out.push(rootComment);+ continue;+ }++ const result = getHighlightThread(mark);+ if (!result) continue;+ out.push(result.root);+ result.replies.forEach((reply) => out.push(reply));+ }+ return out;+ });++ // Sync highlight comments to commentsStore and threadStore+ createEffect(() => {+ const setComments = commentsStore.set;+ const setThreads = threadStore.set;++ setComments(reconcile({}));++ const combinedComments = highlightComments() ?? [];+ const serverThreads: ThreadStore = {};++ for (const comment of combinedComments) {+ if (isRoot(comment)) {+ serverThreads[comment.threadId] = comment;+ }+ setComments(comment.id, comment);+ }++ setThreads(reconcile(serverThreads, { merge: true, key: 'id' }));+ });++ // Map server comment threads to mark metadata once marks are initialized+ createEffect(() => {+ if (!commentMarksInitializedSignal()) return;++ const commentThreads = commentThreadsData() ?? [];++ const mappedAnchors = commentThreads.map((commentThread) => {+ const threadMetadata = commentThread.thread.metadata as ThreadMetadata;+ if (!threadMetadata) {+ console.error('Unable to parse thread metadata', commentThread);+ return undefined;+ }+ const anchorId = threadMetadata.markId;+ if (!anchorId) {+ console.error('Unable to find anchor id');+ return undefined;+ }++ const sortedComments = commentThread.comments.sort(sortComments);+ const rootComment = sortedComments[0];+ const markNodes = marks[anchorId]?.markNodes;+ if (!markNodes) return undefined;++ const highlight: Mark = {+ id: anchorId,+ markNodes: markNodes ?? {},+ owner: commentThread.thread.owner,+ existsOnServer: true,+ isDraft: false,+ thread: {+ threadId: commentThread.thread.threadId,+ rootId: rootComment.commentId,+ anchorId: anchorId,+ comments: sortedComments,+ isResolved: commentThread.thread.resolved,+ },+ };++ return highlight;+ });++ for (const anchor of mappedAnchors) {+ if (!anchor) continue;+ setMarks(anchor.id, anchor);+ }+ });++ // Navigate to comment from URL param once comments are loaded+ createEffect(() => {+ if (!commentMarksInitializedSignal()) return;+ const rawId = props.activeComment?.();+ if (!rawId) return;+ const commentId = Number(rawId);+ if (isNaN(commentId)) return;+ const comment = commentsStore.get[commentId];+ if (!comment) return;+ activeCommentThreadSignal.set(comment.threadId);+ highlightedCommentIdSignal.set(commentId);+ const mark = marks[comment.anchorId];+ if (mark) {+ const firstEl = Object.values(mark.markNodes)[0];+ firstEl?.scrollIntoView({ behavior: 'smooth', block: 'center' });+ }+ });++ autoRegister(+ editor.registerCommand(+ SELECTION_CHANGE_COMMAND,+ () => {+ if (highlightedId() === null) return false;+ setHighlightedId(null);+ return false;+ },+ COMMAND_PRIORITY_LOW+ )+ );+plugins.use(commentPlugin({ops: {@@ -94,5 +345,5 @@ export function CommentsProvider() {}));- return '';-}+ return null;+};diff --git a/js/app/packages/block-md/comments/commentStore.ts b/js/app/packages/block-md/comments/commentStore.tsindex 6373fc806f..83b14a1685 100644--- a/js/app/packages/block-md/comments/commentStore.ts+++ b/js/app/packages/block-md/comments/commentStore.ts@@ -1,26 +1,8 @@-import { mdStore } from '@block-md/signal/markdownBlockData';-import {- createBlockEffect,- createBlockMemo,- createBlockSignal,- createBlockStore,-} from '@core/block';-import { isRoot, type Reply, type Root } from '@core/comments/commentType';-import { MARK_SELECTED_COMMENT_COMMAND } from '@core/component/LexicalMarkdown/plugins/comments/commentPlugin';-import { useUserId } from '@core/context/user';+import { createBlockSignal, createBlockStore } from '@core/block';import { makePersisted } from '@solid-primitives/storage';import type { NodeKey } from 'lexical';-import { createSignal, untrack } from 'solid-js';-import { reconcile } from 'solid-js/store';-import { useDeleteNewComments } from './commentOperations';-import { commentThreadsResource, sortComments } from './commentsResource';-import type {- CommentStore,- Mark,- MarkStore,- ThreadMetadata,- ThreadStore,-} from './commentType';+import { createSignal } from 'solid-js';+import type { CommentStore, MarkStore, ThreadStore } from './commentType';interface PendingComment {anchorKey: NodeKey;@@ -34,6 +16,9 @@ export const markStore = createBlockStore<MarkStore>({});export const activeMarkIdsSignal = createBlockSignal<string[]>([]);export const activeCommentThreadSignal = createBlockSignal<number | null>(null);+export const highlightedCommentIdSignal = createBlockSignal<number | null>(+ null+);export const commentsStore = createBlockStore<CommentStore>({});@@ -45,216 +30,6 @@ export const highlightedCommentThreadsSignal = createBlockSignal<number[]>([]);export const pendingCommentSignal = createBlockSignal<PendingComment[]>([]);-// Remove the new temporary comment when it is no longer active-createBlockEffect(() => {- const activeThreadId = activeCommentThreadSignal();- if (!activeThreadId) {- const deleteNewComments = useDeleteNewComments();- deleteNewComments(false);- return;- }-- const thread = threadStore.get[activeThreadId];- if (!thread) return;-- const markId = thread.anchorId;-- const existingMarkIds = untrack(activeMarkIdsSignal);- if (- existingMarkIds.length > 0 &&- existingMarkIds.every((id) => id === markId)- ) {- return;- }-- const editor = mdStore.get.editor;- if (!editor) return;-- editor.dispatchCommand(MARK_SELECTED_COMMENT_COMMAND, [markId]);-});--createBlockEffect(() => {- const activeMarkIds = activeMarkIdsSignal();- if (activeMarkIds.length === 0) {- activeCommentThreadSignal.set(null);- highlightedCommentThreadsSignal.set([]);- return;- }-- let threadIds: number[] = [];- for (const id of activeMarkIds) {- const mark = markStore.get[id];- if (!mark) continue;-- if (mark.thread == null) {- activeCommentThreadSignal.set(-1);- return;- } else {- threadIds.push(mark.thread.threadId);- }- }-- activeCommentThreadSignal.set(null);- highlightedCommentThreadsSignal.set(threadIds);-});--createBlockEffect(() => {- const setComments = commentsStore.set;- const setThreads = threadStore.set;-- setComments(reconcile({}));-- const combinedComments = highlightComments() ?? [];- const serverThreads: ThreadStore = {};-- for (const comment of combinedComments) {- if (isRoot(comment)) {- serverThreads[comment.threadId] = comment;- }- setComments(comment.id, comment);- }-- setThreads(- reconcile(serverThreads, {- merge: true,- key: 'id',- })- );-});--export const highlightComments = createBlockMemo(() => {- const userId = useUserId()();-- const out: (Root | Reply)[] = [];- for (const mark of Object.values(markStore.get ?? {})) {- if (!mark) continue;-- // New highlight thread- if (!mark.existsOnServer) {- if (!userId) {- console.error('User ID not found');- continue;- }- const rootComment: Root = {- id: -1,- rootId: -1,- text: '',- owner: userId,- author: userId,- createdAt: new Date(),- isNew: true,- children: [],- threadId: -1,- anchorId: mark.id,- };- out.push(rootComment);- continue;- }-- const highlightThread = getHighlightThread(mark);- if (!highlightThread) continue;-- const { root, replies } = highlightThread;- out.push(root);- replies.forEach((reply) => out.push(reply));- }- return out;-});--const getHighlightThread = (- highlight: Mark-): { root: Root; replies: Reply[] } | null => {- const thread = highlight.thread;- if (!thread) return null;-- const comments = thread.comments;-- const rootComment = comments[0];-- const commentBase = {- isNew: false,- threadId: rootComment.threadId,- rootId: rootComment.commentId,- anchorId: highlight.id,- };-- const replies: Reply[] = [];- for (let i = 1; i < comments.length; i++) {- const comment = comments[i];- replies.push({- ...commentBase,- id: comment.commentId,- createdAt: comment.createdAt,- owner: comment.owner,- author: comment.sender || comment.owner,- text: comment.text,- });- }-- const root: Root = {- ...commentBase,- id: rootComment.commentId,- createdAt: rootComment.createdAt,- owner: rootComment.owner,- author: rootComment.sender || rootComment.owner,- text: rootComment.text,- children: replies.map((r) => r.id),- };-- return { root, replies };-};--createBlockEffect(() => {- if (!commentMarksInitializedSignal()) return;-- const marks = markStore.get;-- const [commentThreadsData] = commentThreadsResource;- const commentThreads = commentThreadsData() ?? [];-- const mappedAnchors = commentThreads.map((commentThread) => {- const threadMetadata = commentThread.thread.metadata as ThreadMetadata;- if (!threadMetadata) {- console.error('Unable to parse thread metadata', commentThread);- return undefined;- }- const anchorId = threadMetadata.markId;- if (!anchorId) {- console.error('Unable to find anchor id');- return undefined;- }-- const sortedComments = commentThread.comments.sort(sortComments);- const rootComment = sortedComments[0];- const markNodes = marks[anchorId]?.markNodes;- if (!markNodes) {- return undefined;- }-- const highlight: Mark = {- id: anchorId,- markNodes: markNodes ?? {},- owner: commentThread.thread.owner,- existsOnServer: true,- isDraft: false,- thread: {- threadId: commentThread.thread.threadId,- rootId: rootComment.commentId,- anchorId: anchorId,- comments: sortedComments,- isResolved: commentThread.thread.resolved,- },- };-- return highlight;- });-- for (const anchor of mappedAnchors) {- if (!anchor) continue;- markStore.set(anchor.id, anchor);- }-});-export const commentWidthSignal = createBlockSignal(true);export const [showCommentsPreference, setShowCommentsPreference] =diff --git a/js/app/packages/block-md/component/MarkdownEditor.tsx b/js/app/packages/block-md/component/MarkdownEditor.tsxindex 87e1668e1f..dbaeeed129 100644--- a/js/app/packages/block-md/component/MarkdownEditor.tsx+++ b/js/app/packages/block-md/component/MarkdownEditor.tsx@@ -2,6 +2,7 @@ import { CommentsProvider } from '@block-md/comments/CommentsProvider';import { keyNavigationPlugin } from '@block-md/plugins/keyboardNavigation';import { markdownBlockErrorSignal } from '@block-md/signal/error';import { FindAndReplaceStore } from '@block-md/signal/findAndReplaceStore';+import { useUrlParams } from '@core/component/ParamsProvider';import { revisionsSignal, rewriteSignal } from '@block-md/signal/rewriteSignal';import { useUserId } from '@core/context/user';import {@@ -148,7 +149,6 @@ import {import { onElementConnect } from '@solid-primitives/lifecycle';import { createCallback } from '@solid-primitives/rootless';import { debounce, throttle } from '@solid-primitives/scheduled';-import { useSearchParams } from '@solidjs/router';import { createDroppable, useDragDropContext } from '@thisbeyond/solid-dnd';import { normalizeEnterPlugin } from 'core/component/LexicalMarkdown/plugins/normalize-enter/';import {@@ -163,6 +163,7 @@ import {createEffect,createMemo,createSignal,+ on,onCleanup,Show,untrack,@@ -184,6 +185,7 @@ import { isMobile } from '@core/mobile/isMobile';import { isIOS } from '@solid-primitives/platform';import { isNativeMobilePlatform } from '@core/mobile/isNativeMobilePlatform';import { URL_PARAMS as CHANNEL_PARAMS } from '@block-channel/constants';+import { URL_PARAMS } from '@block-md/constants';false && fileFolderDrop;@@ -204,24 +206,16 @@ export function MarkdownEditor(props: { autoFocusOnMount?: boolean } = {}) {const mdDocumentName = useBlockDocumentName('');+ const blockHandle = blockHandleSignal.get;const saveMarkdownDocument = useSaveMarkdownDocument();const setMdStore = mdStore.set;const md = mdStore.get;const canEdit = useCanEdit();const canComment = useCanComment();const [blockElement] = blockElementSignal;- const [locationParams, setPendingLocationParams] =- createSignal<Record<string, string>>();const [findAndReplaceStore, setFindAndReplaceStore] = FindAndReplaceStore;const docSource = blockSourceSignal.get;- const blockHandle = blockHandleSignal.get;- createMethodRegistration(blockHandle, {- goToLocationFromParams: (params: Record<string, any>) => {- setPendingLocationParams({ ...params });- },- });-const IS_SYNC = () => {return docSource() && isSourceSyncService(docSource()!);};@@ -421,35 +415,31 @@ export function MarkdownEditor(props: { autoFocusOnMount?: boolean } = {}) {};const [highlightNodeId, setHighlightNodeId] = createSignal<string>();- const [searchParams] = useSearchParams();- const derivedSearchParams = createMemo(() => {- return {- ...searchParams,- ...locationParams(),- };- });+ const [activeCommentIdParam, setActiveCommentIdParam] = createSignal<+ string | undefined+ >(undefined, { equals: false });const [activeLocation, setActiveLocation] =createSignal<PersistentLocation>();const [locationReady, setLocationReady] = createSignal(false);- createEffect(() => {- let nodeId = derivedSearchParams().node_id;- if (Array.isArray(nodeId)) {- nodeId = nodeId.length > 0 ? nodeId[0] : undefined;- }- if (typeof nodeId === 'string' && nodeId) {- setHighlightNodeId(nodeId);- }-- const location = derivedSearchParams().location;- if (location && typeof location === 'string') {- const locationObj = parsePersistentLocation(location);- if (locationObj) {- setActiveLocation(locationObj);+ const { nodeId, location, commentId } = useUrlParams(URL_PARAMS);+ createEffect(on(nodeId, (id) => setHighlightNodeId(id ?? undefined)));+ createEffect(+ on(commentId, (id) => {+ setActiveCommentIdParam(id ?? undefined);+ })+ );+ createEffect(+ on(location, (loc) => {+ if (loc) {+ const locationObj = parsePersistentLocation(loc);+ if (locationObj) {+ setActiveLocation(locationObj);+ }}- }- });+ })+ );plugins.use(locationPlugin({@@ -1044,7 +1034,7 @@ export function MarkdownEditor(props: { autoFocusOnMount?: boolean } = {}) {</Show><Show when={ENABLE_MARKDOWN_COMMENTS}>- <CommentsProvider />+ <CommentsProvider activeComment={activeCommentIdParam} /></Show><ScopedPortal scope="block">diff --git a/js/app/packages/block-md/component/Notebook.tsx b/js/app/packages/block-md/component/Notebook.tsxindex 469ff588e8..9fefff41c7 100644--- a/js/app/packages/block-md/component/Notebook.tsx+++ b/js/app/packages/block-md/component/Notebook.tsx@@ -8,6 +8,7 @@ import {import { useGoToTempRedirect } from '@block-md/signal/location';import { mdStore } from '@block-md/signal/markdownBlockData';import { useBlockAliasedName, useBlockId } from '@core/block';+import { ParamsProvider } from '@core/component/ParamsProvider';import { editorFocusSignal } from '@core/component/LexicalMarkdown/utils';import {ENABLE_MARKDOWN_COMMENTS,@@ -288,10 +289,12 @@ export function Notebook() {documentName={documentName()}fallback={<div class="h-6 w-full" />}/>- <MarkdownEditor autoFocusOnMount={!navigatedFromJK()} />- <Show when={ENABLE_RAIL_CHAT_TASK_COMMENTS && isTask}>- <TaskDiscussion />- </Show>+ <ParamsProvider>+ <MarkdownEditor autoFocusOnMount={!navigatedFromJK()} />+ <Show when={ENABLE_RAIL_CHAT_TASK_COMMENTS && isTask}>+ <TaskDiscussion />+ </Show>+ </ParamsProvider></div><divclass={commentPositioning().classes}diff --git a/js/app/packages/block-md/component/TaskDiscussion.tsx b/js/app/packages/block-md/component/TaskDiscussion.tsxindex 2935ed9acc..47795c6402 100644--- a/js/app/packages/block-md/component/TaskDiscussion.tsx+++ b/js/app/packages/block-md/component/TaskDiscussion.tsx@@ -1,22 +1,37 @@import { DiscussionInput } from './DiscussionInput';import type { InputSnapshot } from '@channel/Input/types';import { Message } from '@channel/Message/Message';-import type { MessageActions } from '@channel/Message/types';+import type {+ MessageActionContext,+ MessageActions,+} from '@channel/Message/types';import { Thread } from '@channel/Thread/Thread';import { ThreadRail } from '@channel/Thread/ThreadRail';import { ThreadReplyInputConnector } from '@channel/Thread/ThreadReplyInputConnector';import { replyInputOffsetX } from '@channel/Thread/utils/thread-rail-geometry';import type { ItemMention } from '@core/component/LexicalMarkdown/plugins';+import { useBlockId } from '@core/block';import { useUserId } from '@core/context/user';import { useCanEdit } from '@core/signal/permissions';import { tryMacroId, useDisplayName } from '@core/user';+import { buildSimpleEntityUrl } from '@core/util/url';+import { toast } from '@core/component/Toast/Toast';import CaretDown from '@icon/bold/caret-down-bold.svg';import CaretRight from '@icon/bold/caret-right-bold.svg';import { StaticMarkdownContext } from '@core/component/LexicalMarkdown/component/core/StaticMarkdown';import type { Comment } from '@service-storage/generated/schemas/comment';import type { CommentThread } from '@service-storage/generated/schemas/commentThread';import type { CreateCommentRequestMentions } from '@service-storage/generated/schemas/createCommentRequestMentions';-import { createSignal, For, Show } from 'solid-js';+import { useUrlParams } from '@core/component/ParamsProvider';+import {+ createEffect,+ createMemo,+ createSignal,+ For,+ onMount,+ Show,+} from 'solid-js';+import { URL_PARAMS } from '../constants';import {commentToApiChannelMessage,commentToMessageData,@@ -52,6 +67,18 @@ export function TaskDiscussion() {const createThread = useCreateDiscussionThread();const [isExpanded, setIsExpanded] = createSignal(true);+ const urlParams = useUrlParams(URL_PARAMS);+ const targetCommentId = createMemo(() => {+ const raw = urlParams.commentId();+ if (!raw) return null;+ const id = Number(raw);+ return isNaN(id) ? null : id;+ });++ createEffect(() => {+ if (targetCommentId() !== null) setIsExpanded(true);+ });+let newThreadInputHandle: { clear: () => void } | undefined;const toggleExpanded = () => {@@ -90,7 +117,12 @@ export function TaskDiscussion() {<div class="py-2 text-xs"><div><For each={discussionThreads() ?? []}>- {(thread) => <DiscussionThread thread={thread} />}+ {(thread) => (+ <DiscussionThread+ thread={thread}+ targetCommentId={targetCommentId()}+ />+ )}</For></div>@@ -113,9 +145,13 @@ export function TaskDiscussion() {);}-function DiscussionThread(props: { thread: CommentThread }) {+function DiscussionThread(props: {+ thread: CommentThread;+ targetCommentId: number | null;+}) {const userId = useUserId();const canEdit = useCanEdit();+ const blockId = useBlockId();const createReply = useCreateDiscussionReply();const editComment = useEditDiscussionComment();const deleteComment = useDeleteDiscussionComment();@@ -139,6 +175,21 @@ function DiscussionThread(props: { thread: CommentThread }) {const isOwn = (comment: Comment) =>(comment.sender ?? comment.owner) === userId();+ const makeCopyLink =+ (comment: Comment): ((ctx: MessageActionContext) => Promise<void>) =>+ async () => {+ const params: Record<string, string> = {+ [URL_PARAMS.commentId]: String(comment.commentId),+ };+ try {+ const url = buildSimpleEntityUrl({ type: 'task', id: blockId }, params);+ await navigator.clipboard.writeText(url);+ toast.success('Link copied to clipboard');+ } catch {+ toast.failure('Could not copy link');+ }+ };+const makeActions = (comment: Comment, isRoot: boolean): MessageActions => {const own = isOwn(comment);return {@@ -158,6 +209,7 @@ function DiscussionThread(props: { thread: CommentThread }) {await deleteComment(comment.commentId, {});}: undefined,+ onCopyLink: makeCopyLink(comment),};};@@ -193,6 +245,9 @@ function DiscussionThread(props: { thread: CommentThread }) {editingId={editingId()}onEditSave={(snapshot) => handleEdit(rootComment(), snapshot)}onEditCancel={() => setEditingId(null)}+ isHighlighted={+ props.targetCommentId === rootComment().commentId+ }/><Show when={hasReplies() || isReplying()}>@@ -214,6 +269,9 @@ function DiscussionThread(props: { thread: CommentThread }) {handleEdit(reply, snapshot)}onEditCancel={() => setEditingId(null)}+ isHighlighted={+ props.targetCommentId === reply.commentId+ }/></div>)}@@ -277,51 +335,65 @@ function DiscussionMessage(props: {editingId: number | null;onEditSave: (snapshot: InputSnapshot) => void;onEditCancel: () => void;+ isHighlighted?: boolean;}) {const isEditing = () => props.editingId === props.comment.commentId;const messageData = () => commentToMessageData(props.comment);+ let containerRef: HTMLDivElement | undefined;+ onMount(() => {+ if (props.isHighlighted) {+ containerRef?.scrollIntoView({ behavior: 'smooth', block: 'center' });+ }+ });+return (- <Show- when={!isEditing()}- fallback={- <DiscussionInput- input={{- mode: 'reply',- placeholder: 'Edit comment...',- value: props.comment.text,- }}- onSend={props.onEditSave}- onClose={() => {- props.onEditCancel();- }}- />- }- >- <Message.Root message={messageData()} actions={props.actions}>- <Message.Layout class="pt-(--regular-message-padding-t)">- <Message.Slot placement="icon">- <Message.SenderIcon />- </Message.Slot>- <Message.Slot- placement="header"- class="flex items-center gap-1 min-w-0 w-full"- >- <Message.SenderName />- <Message.EditedIndicator />- <div class="grow shrink-0 min-w-0 flex justify-end group-hover/message:absolute group-hover/message:right-1 group-hover/message:-top-9 group-hover/message:p-1">- <Message.Timestamp- class="ml-auto shrink-0"- format="dateAndTime"- />- </div>- </Message.Slot>- <Message.Slot placement="content" class="ph-no-capture">- <Message.Content />- </Message.Slot>- <Message.ActionMenu />- </Message.Layout>- </Message.Root>- </Show>+ <div ref={containerRef}>+ <Show+ when={!isEditing()}+ fallback={+ <DiscussionInput+ input={{+ mode: 'reply',+ placeholder: 'Edit comment...',+ value: props.comment.text,+ }}+ onSend={props.onEditSave}+ onClose={() => {+ props.onEditCancel();+ }}+ />+ }+ >+ <Message.Root+ message={messageData()}+ actions={props.actions}+ highlighted={props.isHighlighted}+ >+ <Message.Layout class="pt-(--regular-message-padding-t)">+ <Message.Slot placement="icon">+ <Message.SenderIcon />+ </Message.Slot>+ <Message.Slot+ placement="header"+ class="flex items-center gap-1 min-w-0 w-full"+ >+ <Message.SenderName />+ <Message.EditedIndicator />+ <div class="grow shrink-0 min-w-0 flex justify-end group-hover/message:absolute group-hover/message:right-1 group-hover/message:-top-9 group-hover/message:p-1">+ <Message.Timestamp+ class="ml-auto shrink-0"+ format="dateAndTime"+ />+ </div>+ </Message.Slot>+ <Message.Slot placement="content" class="ph-no-capture">+ <Message.Content />+ </Message.Slot>+ <Message.ActionMenu />+ </Message.Layout>+ </Message.Root>+ </Show>+ </div>);}diff --git a/js/app/packages/block-md/constants.ts b/js/app/packages/block-md/constants.tsindex 8ecf58e139..98f987a035 100644--- a/js/app/packages/block-md/constants.ts+++ b/js/app/packages/block-md/constants.ts@@ -1,4 +1,5 @@export const URL_PARAMS = {nodeId: 'node_id',location: 'location',+ commentId: 'comment_id',} as const;diff --git a/js/app/packages/block-pdf/component/RightMarginLayout.tsx b/js/app/packages/block-pdf/component/RightMarginLayout.tsxindex f74b3ed9fa..5c4e5c313a 100644--- a/js/app/packages/block-pdf/component/RightMarginLayout.tsx+++ b/js/app/packages/block-pdf/component/RightMarginLayout.tsx@@ -92,6 +92,7 @@ const useCommentsContext = (): CommentsContextType => {updateComment,},inComment: true,+ highlightedCommentId: () => null,};return commentsContext;diff --git a/js/app/packages/core/comments/Comment.tsx b/js/app/packages/core/comments/Comment.tsxindex a64f2e5594..d084c970c4 100644--- a/js/app/packages/core/comments/Comment.tsx+++ b/js/app/packages/core/comments/Comment.tsx@@ -14,6 +14,10 @@ import type { Root } from './commentType';import { EditInput } from './Inputs';import { MessageTopRow } from './MessageTopRow';import { CommentsContext, ThreadContext } from './Thread';+import { useMaybeBlockAliasedName } from '@core/block';+import { buildSimpleEntityUrl } from '@core/util/url';+import { URL_PARAMS as MD_URL_PARAMS } from '@block-md/constants';+import { toast } from '@core/component/Toast/Toast';const ThreadLine = () => {return (@@ -29,10 +33,23 @@ const CommentText = (props: { text: string; isThreaded?: boolean }) => {);};-function CommentContainer(props: ParentProps<{ isThreaded?: boolean }>) {+function CommentContainer(+ props: ParentProps<{ isThreaded?: boolean; isHighlighted?: boolean }>+) {return (- <div class="relative isolate group">- <div class="absolute top-0 left-0 size-[calc(100%)] bracket bg-menu/30 -z-1 transition-opacity duration-50 opacity-0 group-hover:opacity-100" />+ <div+ class="relative isolate group rounded-sm"+ classList={{+ 'outline-1 outline-accent/20 -outline-offset-1': props.isHighlighted,+ }}+ >+ <div+ class="absolute top-0 left-0 size-[calc(100%)] rounded-sm -z-1"+ classList={{+ 'bg-accent/5 opacity-100': props.isHighlighted,+ 'bg-hover opacity-0 group-hover:opacity-100': !props.isHighlighted,+ }}+ /><divclass="supports-text-pretty:whitespace-normal wrap-break-word p-1"classList={{@@ -53,7 +70,14 @@ export function Comment(isThreaded?: boolean;}>) {- const { commentOperations, setActiveThread } = useContext(CommentsContext);+ const maybeBlockName = useMaybeBlockAliasedName();+ const commentsContext = useContext(CommentsContext);++ const { commentOperations, setActiveThread, highlightedCommentId } =+ commentsContext;+ const isHighlighted = createMemo(+ () => highlightedCommentId() === props.comment.id+ );const isResolved = createMemo(() => props.comment.resolved ?? false);const date = () => props.comment.createdAt;@@ -68,13 +92,36 @@ export function Comment(}});+ const copyLink = () => {+ if (!maybeBlockName) return;+ return async () => {+ const params: Record<string, string> = {};+ if (maybeBlockName === 'task' || maybeBlockName === 'md') {+ params[MD_URL_PARAMS.commentId] = props.comment.id.toString();+ }+ try {+ const url = buildSimpleEntityUrl(+ { type: maybeBlockName, id: commentsContext.documentId },+ params+ );+ await navigator.clipboard.writeText(url);+ toast.success('Link copied to clipboard');+ } catch (_) {+ toast.failure('Could not copy link');+ }+ };+ };+const mentionsSignal = useContext(ThreadContext).mentionsSignal;return (<Showwhen={isEditing()}fallback={- <CommentContainer isThreaded={props.isThreaded}>+ <CommentContainer+ isThreaded={props.isThreaded}+ isHighlighted={isHighlighted()}+ ><Show when={props.isThreaded}><ThreadLine /></Show>@@ -96,6 +143,7 @@ export function Comment(setActiveThread(props.comment.threadId);setIsEditing(true);}}+ copyLink={copyLink()}/><CommentText text={props.comment.text} />{props.children}@@ -152,8 +200,33 @@ export function CommentReply(}>) {const thisAuthor = useAuthor();- const { getCommentById } = useContext(CommentsContext);+ const { getCommentById, highlightedCommentId, documentId } =+ useContext(CommentsContext);+ const maybeBlockName = useMaybeBlockAliasedName();const reply = createMemo(() => getCommentById(props.replyId));+ const isHighlighted = createMemo(+ () => highlightedCommentId() === props.replyId+ );++ const copyLink = () => {+ if (!maybeBlockName) return;+ return async () => {+ const params: Record<string, string> = {};+ if (maybeBlockName === 'task' || maybeBlockName === 'md') {+ params[MD_URL_PARAMS.commentId] = props.replyId.toString();+ }+ try {+ const url = buildSimpleEntityUrl(+ { type: maybeBlockName, id: documentId },+ params+ );+ await navigator.clipboard.writeText(url);+ toast.success('Link copied to clipboard');+ } catch (_) {+ toast.failure('Could not copy link');+ }+ };+ };const [isEditing, setIsEditing] = createSignal<boolean>(false);const [textValue, setTextValue] = createSignal<string>('');@@ -169,7 +242,10 @@ export function CommentReply(<Showwhen={isEditing()}fallback={- <CommentContainer isThreaded={props.isThreaded}>+ <CommentContainer+ isThreaded={props.isThreaded}+ isHighlighted={isHighlighted()}+ ><Show when={props.isThreaded}><ThreadLine /></Show>@@ -180,6 +256,7 @@ export function CommentReply(isResolved={false}deleteMessage={props.deleteReply}enableEditing={() => setIsEditing(true)}+ copyLink={copyLink()}hideBottomMarginisOwned={props.isOwned}isActive={props.isActive}diff --git a/js/app/packages/core/comments/Inputs.tsx b/js/app/packages/core/comments/Inputs.tsxindex ed461c40db..f4fcdd5e42 100644--- a/js/app/packages/core/comments/Inputs.tsx+++ b/js/app/packages/core/comments/Inputs.tsx@@ -1,10 +1,11 @@-import { DeprecatedIconButton } from '@core/component/DeprecatedIconButton';import { MarkdownTextarea } from '@core/component/LexicalMarkdown/component/core/MarkdownTextarea';import type { ItemMention } from '@core/component/LexicalMarkdown/plugins/mentions/mentionsPlugin';import PaperPlaneRight from '@icon/fill/paper-plane-right-fill.svg';import XIcon from '@icon/regular/x.svg';import { batch, createEffect, createSignal, Show, useContext } from 'solid-js';import { CommentsContext, ThreadContext } from './Thread';+import { Button } from '@ui/components/Button';+import { cn } from '@ui/utils/classname';export function EditBottomRow(props: {handleCancel: (e: MouseEvent) => void;@@ -14,19 +15,26 @@ export function EditBottomRow(props: {}) {return (<div class="absolute bottom-1 right-1 flex items-center">- <DeprecatedIconButton- tooltip={{ label: 'Delete Draft' }}- icon={XIcon}+ <Button+ tooltip="Delete Draft"+ size="icon-sm"+ class="rounded-xs"+ variant="ghost"on:click={props.handleCancel}- theme="muted"- />- <DeprecatedIconButton- tooltip={{ label: 'Send Comment' }}- icon={PaperPlaneRight}+ >+ <XIcon />+ </Button>++ <Button+ tooltip="Send Comment"+ size="icon-sm"+ class="rounded-xs"+ variant="ghost"+ disabled={!props.hasContent}on:click={props.handleSend}- theme={props.hasContent ? 'accent' : 'muted'}- class={props.hasContent ? '' : 'opacity-10'}- />+ >+ <PaperPlaneRight class={cn({ 'text-accent': props.hasContent })} />+ </Button></div>);}@@ -76,7 +84,7 @@ export function EditInput(props: {return (<div class="relative"><div- class="px-2 pt-1 pb-8 relative border border-edge/50 focus-within:bracket focus-within:border-accent"+ class="px-2 pt-1 pb-8 bg-input rounded-sm relative border border-edge-muted focus-within:ring-accent focus-within:ring"on:click={(e) => {e.stopPropagation();focusEditor();@@ -128,7 +136,7 @@ export function NewReplyInput(props: {when={props.isEditing}fallback={<div- class="px-2 pt-2 pb-2 cursor-default text-sm text-ink-extra-muted border border-edge/50"+ class="px-2 py-2 mt-2 cursor-default text-sm text-ink-extra-muted bg-input/50 border border-edge-muted rounded-sm"on:click={(e) => {e.stopPropagation();props.setEditing(true);@@ -138,6 +146,7 @@ export function NewReplyInput(props: {</div>}>+ <div class="h-2"></div><EditInputtextValue={props.textValue}handleCancel={() => props.setTextValue('')}diff --git a/js/app/packages/core/comments/MessageTopRow.tsx b/js/app/packages/core/comments/MessageTopRow.tsxindex 21526afe10..5920c4c337 100644--- a/js/app/packages/core/comments/MessageTopRow.tsx+++ b/js/app/packages/core/comments/MessageTopRow.tsx@@ -1,14 +1,15 @@-import { DeprecatedIconButton } from '@core/component/DeprecatedIconButton';import { UserIcon } from '@core/component/UserIcon';import { isMobileWidth } from '@core/mobile/mobileWidth';import { cn } from '@ui/utils/classname';import { idToDisplayName } from '@core/user';import { type DateValue, formatDate } from '@core/util/date';-import Check from '@phosphor-icons/core/regular/check.svg?component-solid';-import NotePencil from '@phosphor-icons/core/regular/note-pencil.svg?component-solid';+import Check from '@icon/regular/check.svg';+import Link from '@icon/regular/link.svg';+import NotePencil from '@icon/regular/note-pencil.svg';import Trash from '@phosphor-icons/core/regular/trash.svg?component-solid';import { type ParentProps, Show, useContext } from 'solid-js';import { CommentsContext } from './Thread';+import { Button } from '@ui/components/Button';// SCUFFED: how should we define these tag colors?const NewTag = () => {@@ -83,7 +84,7 @@ export function MessageRowUI(>{!props.hideBubble && (<div- class={`w-4 h-4 relative flex items-center justify-center shrink-0 rounded-[2px]`}+ class={`w-4 h-4 relative flex items-center justify-center shrink-0 rounded-xs`}><div class="absolute"><UserIcon@@ -119,6 +120,7 @@ export function MessageTopRow(props: {date?: DateValue | null;deleteMessage?: () => void;enableEditing?: () => void;+ copyLink?: () => void;hideBottomMargin?: boolean;isNew: boolean;isResolved: boolean;@@ -137,33 +139,53 @@ export function MessageTopRow(props: {hideBottomMargin={props.hideBottomMargin}isActive={props.isActive}>- <div class="absolute top-1 right-1 flex flex-row bg-menu border border-edge z-user-highlight">+ <div class="absolute top-0 right-0 flex flex-row bg-menu border border-edge-muted p-1 rounded-sm z-user-highlight">+ <Show when={props.copyLink}>+ <Button+ tooltip="Copy link to comment"+ size="icon-sm"+ variant="ghost"+ class="rounded-xs"+ onClick={props.copyLink}+ >+ <Link />+ </Button>+ </Show><Show when={canComment()}><Show when={props.isOwned}>- {props.toggleResolve && (- <DeprecatedIconButton- tooltip={{ label: 'Resolve Comment' }}- icon={Check}- theme={props.isResolved ? 'accent' : 'clear'}- on:click={props.toggleResolve}- />- )}- {props.enableEditing && (- <DeprecatedIconButton- tooltip={{ label: 'Edit Comment' }}- theme="clear"- icon={NotePencil}- on:click={props.enableEditing}- />- )}+ <Show when={props.toggleResolve}>+ <Button+ tooltip="Resolve Comment"+ size="icon-sm"+ variant="ghost"+ class="rounded-xs"+ onClick={props.toggleResolve}+ >+ <Check />+ </Button>+ </Show>+ <Show when={props.enableEditing}>+ <Button+ tooltip="Edit Comment"+ size="icon-sm"+ variant="ghost"+ class="rounded-xs"+ onClick={props.enableEditing}+ >+ <NotePencil />+ </Button>+ </Show></Show><Show when={!props.isEditing && (props.isOwned || isDocumentOwner())}>- <DeprecatedIconButton- tooltip={{ label: 'Delete Comment' }}- theme="clear"- icon={Trash}- on:click={props.deleteMessage}- />+ <Button+ tooltip="Delete Comment"+ size="icon-sm"+ variant="ghost"+ class="rounded-xs"+ onClick={props.deleteMessage}+ >+ <Trash class="text-failure" />+ </Button></Show></Show></div>diff --git a/js/app/packages/core/comments/MinimizedThreads.tsx b/js/app/packages/core/comments/MinimizedThreads.tsxindex 940d462ab1..56a5ebc295 100644--- a/js/app/packages/core/comments/MinimizedThreads.tsx+++ b/js/app/packages/core/comments/MinimizedThreads.tsx@@ -1,10 +1,16 @@-import { BozzyBracketInnerSibling } from '@core/component/BozzyBracket';import ChatTeardrop from '@icon/regular/chat-teardrop.svg';+import { cn } from '@ui/utils/classname';import type { EditorThemeClasses } from 'lexical';-import { createEffect, createSignal, onCleanup, Show } from 'solid-js';+import {+ createEffect,+ createSignal,+ onCleanup,+ Show,+ useContext,+} from 'solid-js';import type { Layout, Root } from './commentType';import { MeasureContainer } from './MeasureContainer';-import { Thread } from './Thread';+import { CommentsContext, Thread } from './Thread';export function MinimizedThread(props: {comment: Root;@@ -22,6 +28,15 @@ export function MinimizedThread(props: {setExpanded(true);}+ const { highlightedCommentId } = useContext(CommentsContext);+ createEffect(() => {+ const hId = highlightedCommentId();+ if (hId === null) return;+ if (hId === props.comment.id || props.comment.children.includes(hId)) {+ setExpanded(true);+ }+ });+createEffect(() => {if (!expanded()) return;function handleClick(e: MouseEvent) {@@ -77,40 +92,31 @@ export function MinimizedThread(props: {threadId={props.comment.threadId}maxHeight={props.maxHeight}isActive={props.isActive}- transition={true}+ transition={false}><div- class="flex flex-row justify-between p-[2px] gap-1 transition-transform items-center bg-panel text-ink-muted border-edge/50 border relative overflow-clip"- classList={{- '-translate-x-4': props.isActive,- }}+ class={cn(+ 'flex flex-row justify-between p-0.5 gap-1 transition-transform items-center text-ink-muted border-edge-muted border relative overflow-clip rounded-sm pointer-events-auto',+ props.isActive && '-translate-x-4'+ )}onClick={clickHandler}><div- class="size-6 flex items-center justify-center"- classList={{- 'bg-comment-bg text-comment-fg': !props.isActive,- 'bg-comment text-page': props.isActive,- }}+ class={cn(+ 'size-6 flex items-center justify-center rounded-xs',+ props.isActive+ ? 'bg-comment text-page'+ : 'bg-comment-bg text-comment-fg'+ )}><ChatTeardropclass="size-5 pointer-events-auto"onClick={clickHandler}/></div>- <div class="flex items-center px-1 h-6 pointer-events-auto">- <span class="text-xs font-bold text-center font-mono">- [{commentCount()}]- </span>+ <div class="flex items-center px-1 h-6 pointer-events-none">+ <span class="text-xs text-center">{commentCount()}</span></div>- <BozzyBracketInnerSibling- classList={{- 'opacity-0': !props.isActive,- 'transition-transform duration-100': true,- 'scale-110': !props.isActive,- 'scale-100': props.isActive,- }}- /></div></MeasureContainer></Show>diff --git a/js/app/packages/core/comments/Thread.tsx b/js/app/packages/core/comments/Thread.tsxindex a1e7410827..0b47786353 100644--- a/js/app/packages/core/comments/Thread.tsx+++ b/js/app/packages/core/comments/Thread.tsx@@ -69,7 +69,9 @@ export type CommentsContextType = {documentId: string;ownedComment: (id: number) => boolean;inComment: boolean;+ highlightedCommentId: Accessor<number | null>;};+export const CommentsContext = createContext<CommentsContextType>({setActiveThread: () => {},setThreadHeight: () => {},@@ -84,6 +86,7 @@ export const CommentsContext = createContext<CommentsContextType>({documentId: '',ownedComment: () => false,inComment: false,+ highlightedCommentId: () => null,});export function Thread(props: {@@ -98,8 +101,13 @@ export function Thread(props: {}) {let measureContainerRef!: HTMLDivElement;- const { canComment, commentOperations, setActiveThread, ownedComment } =- useContext(CommentsContext);+ const {+ canComment,+ commentOperations,+ setActiveThread,+ ownedComment,+ highlightedCommentId,+ } = useContext(CommentsContext);const [textValue, setTextValue] = createSignal('');const [isEditingNewReply, setIsEditingNewReply] = createSignal(false);@@ -150,6 +158,15 @@ export function Thread(props: {setAllRepliesVisible(false);});+ // expand all replies if we're navigating to a specific reply via URL+ createEffect(() => {+ const hId = highlightedCommentId();+ if (hId === null) return;+ if (replyIds().includes(hId)) {+ setAllRepliesVisible(true);+ }+ });+onMount(() => {if (!props.handleMouseDown) return;const handleMouseDown = props.handleMouseDown;@@ -178,7 +195,7 @@ export function Thread(props: {maxHeight={props.maxHeight}isActive={props.isActive}forceWidth={props.width}- transition={true}+ transition={false}><div// note: pdf-pointer-event-reset is a strange one-off class that mostly normalizesdiff --git a/js/app/packages/core/component/DocumentPreview.tsx b/js/app/packages/core/component/DocumentPreview.tsxindex a196d0b39c..4c1d461b10 100644--- a/js/app/packages/core/component/DocumentPreview.tsx+++ b/js/app/packages/core/component/DocumentPreview.tsx@@ -195,12 +195,17 @@ export const mentionsAccessories = (return;}// Md block handling- else if (blockName === 'md') {+ else if (resolveBlockAlias(blockName) === 'md') {const id = params[URL_PARAMS_MD.nodeId];const loc = params[URL_PARAMS_MD.location];if (id?.trim() || loc?.trim()) {return { icon: 'highlight', note: 'Snippet' };}++ const comment = params[URL_PARAMS_MD.commentId];+ if (comment?.trim()) {+ return { icon: 'message', note: 'Comment' };+ }}};diff --git a/js/app/packages/core/component/LexicalMarkdown/plugins/location/locationPlugin.ts b/js/app/packages/core/component/LexicalMarkdown/plugins/location/locationPlugin.tsindex 85a7189c84..ebdf0c6f49 100644--- a/js/app/packages/core/component/LexicalMarkdown/plugins/location/locationPlugin.ts+++ b/js/app/packages/core/component/LexicalMarkdown/plugins/location/locationPlugin.ts@@ -154,7 +154,7 @@ function persistentLocationToSearchParams(location: PersistentLocation) {* @param location - The highlight location to serialize* @returns A string in the format `anchor=<id>::<offset>&focus=<id>::<offset>`*/-export function getPersitentLocationString(+export function gerPersistentLocationString(location: PersistentLocation): string {return persistentLocationToSearchParams(location).toString();@@ -186,7 +186,9 @@ export const GO_TO_LOCATION_COMMAND = createCommand<PersistentLocation | undefined>('GO_TO_LOCATION_COMMAND');-export const GO_TO_NODE_ID_COMMAND = createCommand<string>('SCROLL_TO_NODE_ID');+export const GO_TO_NODE_ID_COMMAND = createCommand<string>(+ 'GO_TO_NODE_ID_COMMAND'+);export type LocationPluginProps = {mapping: NodeIdMappings;diff --git a/js/app/packages/core/component/ParamsProvider.tsx b/js/app/packages/core/component/ParamsProvider.tsxnew file mode 100644index 0000000000..f375c30c28--- /dev/null+++ b/js/app/packages/core/component/ParamsProvider.tsx@@ -0,0 +1,62 @@+import { blockHandleSignal } from '@core/signal/load';+import { useSearchParams } from '@solidjs/router';+import { createMethodRegistration } from 'core/orchestrator';+import {+ createContext,+ createMemo,+ createSignal,+ type Accessor,+ useContext,+ type ParentProps,+} from 'solid-js';++type ParamSchema = Record<string, string>;++type ParamMap = Record<string, string | undefined>;++type ResolvedParams<T extends ParamSchema> = {+ [K in keyof T]: Accessor<string | undefined>;+};++const ParamsContext = createContext<Accessor<ParamMap>>(() => ({}));++export function ParamsProvider(props: ParentProps) {+ const [searchParams] = useSearchParams();++ const [blockParams, setBlockParams] = createSignal<ParamMap>({});++ const blockHandle = blockHandleSignal.get;++ createMethodRegistration(blockHandle, {+ goToLocationFromParams: (params: Record<string, string>) => {+ setBlockParams({ ...params });+ },+ });++ const merged = createMemo<ParamMap>(() => {+ const flat: ParamMap = {};++ for (const key in searchParams) {+ const val = searchParams[key];+ flat[key] = Array.isArray(val) ? val[0] : val;+ }++ return { ...flat, ...blockParams() };+ });++ return (+ <ParamsContext.Provider value={merged}>+ {props.children}+ </ParamsContext.Provider>+ );+}++export function useUrlParams<T extends ParamSchema>(+ schema: T+): ResolvedParams<T> {+ const raw = useContext(ParamsContext);++ return Object.fromEntries(+ Object.entries(schema).map(([key, param]) => [key, () => raw()[param]])+ ) as ResolvedParams<T>;+}diff --git a/js/app/packages/core/component/StackedAvatarsRow.tsx b/js/app/packages/core/component/StackedAvatarsRow.tsxindex 5cb2824fca..4ee47bcb80 100644--- a/js/app/packages/core/component/StackedAvatarsRow.tsx+++ b/js/app/packages/core/component/StackedAvatarsRow.tsx@@ -388,23 +388,21 @@ export function StackedAvatarsRow<T = unknown>(</Show></Show><Show when={all().length > 0}>- <>- <For each={visible()}>- {(item, index) => {- const lastNoOverflowChip =- index() === visible().length - 1 && overflowCount() === 0;- return (- <div- class={faceWrapperClass(lastNoOverflowChip)}- style={faceWrapperStyle(index(), lastNoOverflowChip)}- >- {props.children(item, index())}- </div>- );- }}- </For>- <Show when={overflowCount() > 0}>{overflowSlot()}</Show>- </>+ <For each={visible()}>+ {(item, index) => {+ const lastNoOverflowChip =+ index() === visible().length - 1 && overflowCount() === 0;+ return (+ <div+ class={faceWrapperClass(lastNoOverflowChip)}+ style={faceWrapperStyle(index(), lastNoOverflowChip)}+ >+ {props.children(item, index())}+ </div>+ );+ }}+ </For>+ <Show when={overflowCount() > 0}>{overflowSlot()}</Show></Show></div>);diff --git a/js/app/packages/core/constant/allBlocks.ts b/js/app/packages/core/constant/allBlocks.tsindex ed206a37d1..8f1a8c1119 100644--- a/js/app/packages/core/constant/allBlocks.ts+++ b/js/app/packages/core/constant/allBlocks.ts@@ -206,7 +206,7 @@ export function blockNameToDefaultFile(block?: BlockName | string | null) {return DefaultFilename;}-type ItemLike = {+export type ItemLike = {type: ItemType | 'call';fileType?: BasicDocumentFileType;subType?: SubType | BasicDocumentSubTypeProperty;diff --git a/js/app/packages/notifications/notification-navigation.ts b/js/app/packages/notifications/notification-navigation.tsindex 510a31479d..8348fee71d 100644--- a/js/app/packages/notifications/notification-navigation.ts+++ b/js/app/packages/notifications/notification-navigation.ts@@ -1,6 +1,10 @@import type { SplitManager } from '@app/component/split-layout/layoutManager';import type { BlockAlias, BlockName } from '@core/block';-import { itemToBlockName } from '@core/constant/allBlocks';+import {+ type ItemLike,+ itemToBlockName,+ resolveBlockAlias,+} from '@core/constant/allBlocks';import type { NotificationType } from '@core/types';import type { UnifiedNotification } from './types';import { getNotificationById } from '@queries/notification/user-notifications';@@ -13,11 +17,28 @@ import {} from '@block-channel/utils/link';import { isChannelNotification } from './notification-helpers';import { CHANNEL_EVENT_TYPES } from './notification-source';+import { URL_PARAMS as PDF_URL_PARAMS } from '@block-pdf/signal/location';+import { URL_PARAMS as MD_URL_PARAMS } from '@block-md/constants';import {stackNotifications,getMostRecentNotification,} from './notification-stacking';+/**+ * Go to location via global block orchestrator.+ */+async function goToLocationInSplit(+ layoutManager: SplitManager,+ type: BlockName | BlockAlias,+ id: string,+ params: Record<string, string>+) {+ const orchestrator = layoutManager.getOrchestrator();+ if (!orchestrator) return;+ const handle = await orchestrator.getBlockHandle(id, resolveBlockAlias(type));+ await handle?.goToLocationFromParams(params);+}+/*** Opens a split if it is not already open.*/@@ -30,16 +51,19 @@ function openSplitIfNotOpen(const existing = layoutManager.getSplitByContent(type, id);if (existing) {existing.activate();- return;+ } else {+ layoutManager.openWithSplit(+ { type, id },+ {+ activate: true,+ referredFrom: null,+ preferNewSplit: options.newSplit,+ }+ );+ }+ if (options.params && type !== 'component') {+ goToLocationInSplit(layoutManager, type, id, options.params);}- layoutManager.openWithSplit(- { type, id, params: options.params },- {- activate: true,- referredFrom: null,- preferNewSplit: options.newSplit,- }- );}export function getChannelNotificationParams(@@ -110,7 +134,13 @@ function safeDocumentContentToBlockName(type: 'document',fileType: entity?.fileType ?? content.fileType ?? undefined,subType: entity?.subType ?? content.subType ?? undefined,- } as Parameters<typeof itemToBlockName>[0]);+ } as ItemLike);+}++function resolveBlockCommentParamName(type: BlockName | BlockAlias) {+ const resolved = resolveBlockAlias(type);+ if (resolved === 'md') return MD_URL_PARAMS.commentId;+ if (resolved === 'pdf') return PDF_URL_PARAMS.annotationId;}type NotSupportedError = {@@ -181,35 +211,56 @@ function getSupportedHandler(.with('mentioned_in_document_comment', () => {const meta = notification.notification_metadata;if (meta.tag !== 'mentioned_in_document_comment') return null;++ const blockName = safeDocumentContentToBlockName(meta.content, entity);+ const commentParamName = resolveBlockCommentParamName(blockName);+ const params = commentParamName+ ? {+ [commentParamName]: meta.content.commentId.toString(),+ }+ : undefined;+return async (lm: SplitManager, newSplit: boolean = false) =>- openSplitIfNotOpen(- lm,- safeDocumentContentToBlockName(meta.content, entity),- notification.entity_id,- { newSplit }- );+ openSplitIfNotOpen(lm, blockName, notification.entity_id, {+ newSplit,+ params,+ });}).with('replied_to_document_comment_thread', () => {const meta = notification.notification_metadata;if (meta.tag !== 'replied_to_document_comment_thread') return null;++ const blockName = safeDocumentContentToBlockName(meta.content, entity);+ const commentParamName = resolveBlockCommentParamName(blockName);+ const params = commentParamName+ ? {+ [commentParamName]: meta.content.commentId.toString(),+ }+ : undefined;+return async (lm: SplitManager, newSplit: boolean = false) =>- openSplitIfNotOpen(- lm,- safeDocumentContentToBlockName(meta.content, entity),- notification.entity_id,- { newSplit }- );+ openSplitIfNotOpen(lm, blockName, notification.entity_id, {+ newSplit,+ params,+ });}).with('commented_on_document', () => {const meta = notification.notification_metadata;if (meta.tag !== 'commented_on_document') return null;++ const blockName = safeDocumentContentToBlockName(meta.content, entity);+ const commentParamName = resolveBlockCommentParamName(blockName);+ const params = commentParamName+ ? {+ [commentParamName]: meta.content.commentId.toString(),+ }+ : undefined;+return async (lm: SplitManager, newSplit: boolean = false) =>- openSplitIfNotOpen(- lm,- safeDocumentContentToBlockName(meta.content, entity),- notification.entity_id,- { newSplit }- );+ openSplitIfNotOpen(lm, blockName, notification.entity_id, {+ newSplit,+ params,+ });}).exhaustive();}@@ -224,7 +275,6 @@ export function openNotification(newSplit: boolean = false,entity?: NotificationEntityOverride): ResultAsync<void, NotSupportedError> {- console.log('NOTIF', notification);const handler = getSupportedHandler(notification, entity);if (!handler) {return errAsync({diff --git a/js/codebook.toml b/js/codebook.tomlnew file mode 100644index 0000000000..95205d0592--- /dev/null+++ b/js/codebook.toml@@ -0,0 +1 @@+words = ["loro"]