Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(md): restyle link preview and actions menu, fix click (#6002)

Seamus20a6f2b33bde
diff --git a/apps/web/src/features/block-channel/component/Compose.tsx b/apps/web/src/features/block-channel/component/Compose.tsx
index e060af7f8c..7f736e844d 100644
--- a/apps/web/src/features/block-channel/component/Compose.tsx
+++ b/apps/web/src/features/block-channel/component/Compose.tsx
@@ -295,7 +295,7 @@ export function ChannelCompose() {
</Input.FormatRibbon>
<Input.EditorShell
ref={setScrollContainer}
- onClick={(event) => {
+ on:click={(event) => {
if (!isTouchDevice()) {
event.stopPropagation();
markdownEditor.controls.focus();
diff --git a/apps/web/src/features/channel/Input/ChannelInput.tsx b/apps/web/src/features/channel/Input/ChannelInput.tsx
index 8b53f6ed5d..f3618552c3 100644
--- a/apps/web/src/features/channel/Input/ChannelInput.tsx
+++ b/apps/web/src/features/channel/Input/ChannelInput.tsx
@@ -454,7 +454,7 @@ export function ChannelInput(props: ChannelInputProps) {
</Input.FormatRibbon>
<Input.EditorShell
ref={setScrollContainer}
- onClick={(event) => {
+ on:click={(event) => {
if (!isTouchDevice()) {
event.stopPropagation();
markdownEditor.controls.focus();
diff --git a/apps/web/src/features/channel/Input/tests/input-slots.test.tsx b/apps/web/src/features/channel/Input/tests/input-slots.test.tsx
index db320c621d..4a082c5227 100644
--- a/apps/web/src/features/channel/Input/tests/input-slots.test.tsx
+++ b/apps/web/src/features/channel/Input/tests/input-slots.test.tsx
@@ -6,7 +6,13 @@ import { render as renderBare, screen } from '@solidjs/testing-library';
import { QueryClient, QueryClientProvider } from '@tanstack/solid-query';
import userEvent from '@testing-library/user-event';
import type { JSX } from 'solid-js';
-import { describe, expect, it, vi } from 'vitest';
+import { Portal } from 'solid-js/web';
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+
+const editorMocks = vi.hoisted(() => ({
+ clear: vi.fn(),
+ focus: vi.fn(),
+}));
vi.hoisted(() => {
Object.defineProperty(window, 'matchMedia', {
@@ -114,12 +120,17 @@ vi.mock('@core/component/VideoPreview', () => ({
vi.mock('@core/component/LexicalMarkdown/builder/MarkdownShell', () => ({
MarkdownShell: (props: { placeholder?: string; initialValue?: string }) => (
- <div
- data-testid="markdown-shell"
- data-initial-value={props.initialValue ?? ''}
- >
- {props.placeholder}
- </div>
+ <>
+ <div
+ data-testid="markdown-shell"
+ data-initial-value={props.initialValue ?? ''}
+ >
+ {props.placeholder}
+ </div>
+ <Portal>
+ <input data-testid="markdown-portal-input" />
+ </Portal>
+ </>
),
}));
@@ -128,8 +139,8 @@ vi.mock(
() => ({
buildConfig: () => {
const controls = {
- clear: vi.fn(),
- focus: vi.fn(),
+ clear: editorMocks.clear,
+ focus: editorMocks.focus,
};
const lexical = {
focus: vi.fn(),
@@ -229,6 +240,24 @@ function render(ui: () => JSX.Element) {
}
describe('Input slots', () => {
+ beforeEach(() => {
+ editorMocks.clear.mockClear();
+ editorMocks.focus.mockClear();
+ });
+
+ it('does not refocus the editor when a portaled editor control is clicked', async () => {
+ const user = userEvent.setup();
+ render(() => <ChannelInput input={baseInput} />);
+
+ await user.click(screen.getByTestId('markdown-shell'));
+ expect(editorMocks.focus).toHaveBeenCalledOnce();
+
+ editorMocks.focus.mockClear();
+ await user.click(screen.getByTestId('markdown-portal-input'));
+
+ expect(editorMocks.focus).not.toHaveBeenCalled();
+ });
+
it('renders the default action composition and wires handlers through context', async () => {
const user = userEvent.setup();
const onSend = vi.fn();
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/FloatingLinkMenu.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/FloatingLinkMenu.tsx
index 24e10ef051..bfbf356ed6 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/FloatingLinkMenu.tsx
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/FloatingLinkMenu.tsx
@@ -13,7 +13,7 @@ import Trash from '@phosphor/link-break.svg';
import Pencil from '@phosphor/pencil-simple.svg';
import LinkText from '@phosphor/text-t.svg';
import type { GetUnfurlResponse } from '@service-unfurl/generated/schemas/getUnfurlResponse';
-import { Button, Tooltip } from '@ui';
+import { Button, Surface } from '@ui';
import {
COMMAND_PRIORITY_CRITICAL,
COMMAND_PRIORITY_HIGH,
@@ -93,10 +93,7 @@ export function FloatingLinkMenu(props: {
// Switch on submit behavior
const [createMode, setCreateMode] = createSignal(false);
- let [activeInput, setActiveInput] = createSignal<HTMLInputElement>();
-
let urlInputRef!: HTMLInputElement | undefined;
- let linkTextInputRef: HTMLInputElement | undefined;
let menuRef: HTMLDivElement | undefined;
const reset = () => {
@@ -357,7 +354,7 @@ export function FloatingLinkMenu(props: {
<Show when={linkInfo()?.linkRef || linkInfo()?.selection}>
<ScopedPortal scope="block">
<div
- class="p-2 fixed border border-edge-muted bg-surface top-0 left-0 text-sm z-modal-content rounded-sm shadow-lg min-w-80"
+ class="fixed top-0 left-0 z-modal-content w-80 max-w-[calc(100vw-1rem)] text-sm menu-open-animation"
use:floatWithElement={floatWithElementProps()}
use:floatWithSelection={floatWithSelectionProps()}
use:clickOutside={() => {
@@ -366,7 +363,9 @@ export function FloatingLinkMenu(props: {
}}
ref={menuRef}
>
- {props.children}
+ <Surface depth={2} class="rounded-xl bg-menu p-1.5 shadow-menu">
+ {props.children}
+ </Surface>
</div>
</ScopedPortal>
</Show>
@@ -380,25 +379,31 @@ export function FloatingLinkMenu(props: {
{(link) => (
<ScopedPortal>
<div
- class="p-2 absolute top-0 left-0 z-10 border border-edge-muted bg-surface w-80 shadow-lg rounded-sm"
+ class="fixed top-0 left-0 z-modal-content w-80 max-w-[calc(100vw-1rem)]"
use:floatWithElement={{
element: () => link().linkRef,
useBlockBoundary: true,
}}
>
- <Show
- when={unfurledDetails()}
- fallback={
- <UnfurlLink
- unfurled={{
- url: link().url ?? '',
- title: link().linkText ?? '',
- }}
- />
- }
+ <Surface
+ depth={2}
+ class="rounded-xl p-1.5 shadow-lg shadow-drop-shadow"
>
- {(details) => <UnfurlLink unfurled={details()} />}
- </Show>
+ <Show
+ when={unfurledDetails()}
+ fallback={
+ <UnfurlLink
+ size="sm"
+ unfurled={{
+ url: link().url ?? '',
+ title: link().linkText ?? '',
+ }}
+ />
+ }
+ >
+ {(details) => <UnfurlLink size="sm" unfurled={details()} />}
+ </Show>
+ </Surface>
</div>
</ScopedPortal>
)}
@@ -406,14 +411,9 @@ export function FloatingLinkMenu(props: {
</Match>
<Match when={menuOpen()}>
<MenuWrapper>
- <div class="flex items-center">
- <div
- class="flex items-center rounded grow gap-1 p-1 pr-2"
- classList={{
- 'bg-active': activeInput() === urlInputRef,
- }}
- >
- <Link class="text-ink-extra-muted size-4" />
+ <div class="flex items-center gap-1.5">
+ <div class="flex h-8 min-w-0 grow items-center gap-2 rounded-md border border-edge-muted bg-surface px-2 focus-within:border-accent">
+ <Link class="size-4 shrink-0 text-ink-extra-muted" />
<input
ref={urlInputRef}
tabIndex={2}
@@ -426,22 +426,18 @@ export function FloatingLinkMenu(props: {
url: e.currentTarget.value,
});
}}
- onFocus={() => {
- setActiveInput(urlInputRef);
- setIsEditing(true);
- }}
- onBlur={() => {
- // setActiveInput();
- }}
+ onFocus={() => setIsEditing(true)}
placeholder="https://example.com"
- class="grow text-ellipsis ease-in-out placeholder-gray-400"
+ class="min-w-0 grow bg-transparent text-ink outline-none placeholder:text-ink-placeholder"
/>
</div>
- <div class="relative flex items-center justify-end shrink">
- <div class="flex ease-in-out" classList={{ hidden: expanded() }}>
+ <div
+ class="relative flex shrink-0 items-center justify-end"
+ classList={{ hidden: expanded() }}
+ >
+ <div class="flex items-center gap-0.5 ease-in-out">
<Button
onClick={openInNewTab}
- class="p-1 hover:bg-hover hover-transition-bg"
variant="accent"
size="icon-sm"
tooltip="Open in new tab"
@@ -450,7 +446,6 @@ export function FloatingLinkMenu(props: {
</Button>
<Button
onClick={handleEditClick}
- class="p-1 hover:bg-hover hover-transition-bg"
variant="ghost"
size="icon-sm"
tooltip="Edit link"
@@ -459,7 +454,6 @@ export function FloatingLinkMenu(props: {
</Button>
<Button
onClick={copyLink}
- class="p-1 hover:bg-hover hover-transition-bg"
variant="ghost"
size="icon-sm"
tooltip="Copy link"
@@ -468,7 +462,6 @@ export function FloatingLinkMenu(props: {
</Button>
<Button
onClick={handleUnlink}
- class="p-1 hover:bg-hover hover-transition-bg"
variant="ghost"
size="icon-sm"
tooltip="Remove link"
@@ -479,23 +472,17 @@ export function FloatingLinkMenu(props: {
</div>
</div>
<div
- class="flex gap-1 ease-in-out overflow-hidden"
+ class="flex overflow-hidden ease-in-out"
classList={{
'max-h-0 mt-0': !expanded(),
- 'max-h-24 mt-1': expanded(),
+ 'max-h-24 mt-1.5': expanded(),
}}
>
- <div
- class="flex items-center gap-1 rounded grow p-1 pr-2"
- classList={{
- 'bg-active': activeInput() === linkTextInputRef,
- }}
- >
- <LinkText class="text-ink-extra-muted size-4" />
+ <div class="flex h-8 min-w-0 grow items-center gap-2 rounded-md border border-edge-muted bg-surface px-2 focus-within:border-accent">
+ <LinkText class="size-4 shrink-0 text-ink-extra-muted" />
<input
tabIndex={3}
type="text"
- ref={linkTextInputRef}
value={pendingLinkInfo()?.linkText ?? ''}
onInput={(e) => {
if (!pendingLinkInfo()) return;
@@ -504,37 +491,28 @@ export function FloatingLinkMenu(props: {
linkText: e.currentTarget.value,
});
}}
- onFocus={() => {
- setActiveInput(linkTextInputRef);
- setIsEditing(true);
- }}
- onBlur={() => {
- setActiveInput();
- }}
+ onFocus={() => setIsEditing(true)}
placeholder="Link text"
- class="grow text-ellipsis ease-in-out placeholder-gray-400"
+ class="min-w-0 grow bg-transparent text-ink outline-none placeholder:text-ink-placeholder"
/>
</div>
</div>
<div
- class="flex gap-1 ease-in-out overflow-hidden justify-end"
+ class="flex justify-end overflow-hidden ease-in-out"
classList={{
'max-h-0 mt-0': !expanded(),
- 'max-h-24 mt-1': expanded(),
+ 'max-h-24 mt-1.5': expanded(),
}}
>
- <Tooltip label="Apply link changes">
- <Button
- onClick={handleSubmit}
- class="focus:ring-failure focus:ring-2 focus:ring-offset-2"
- variant="outline"
- disabled={
- !pendingLinkInfo()?.url && !pendingLinkInfo()?.linkText
- }
- >
- <Check /> Apply
- </Button>
- </Tooltip>
+ <Button
+ onClick={handleSubmit}
+ variant="cta"
+ size="sm"
+ tooltip="Apply link changes"
+ disabled={!pendingLinkInfo()?.url && !pendingLinkInfo()?.linkText}
+ >
+ <Check /> Apply
+ </Button>
</div>
</MenuWrapper>
</Match>
diff --git a/apps/web/src/lib/core/component/Link.tsx b/apps/web/src/lib/core/component/Link.tsx
index 07c8c8e210..b5e6c15ef4 100644
--- a/apps/web/src/lib/core/component/Link.tsx
+++ b/apps/web/src/lib/core/component/Link.tsx
@@ -19,14 +19,20 @@ function extractDomain(url: string) {
}
const [badLinks, setBadLinks] = createStore<Record<string, true>>({});
-type UnfurlLinkProps = { unfurled: GetUnfurlResponse };
+type UnfurlLinkProps = {
+ unfurled: GetUnfurlResponse;
+ size?: 'xs' | 'sm';
+};
export function UnfurlLink(props: UnfurlLinkProps) {
const domain = extractDomain(props.unfurled.url);
return (
<div
- class="hover:bg-hover p-1 px-1.5 overflow-clip text-xs transition-colors hover:transition-none"
+ class={cn(
+ 'hover:bg-hover p-1 px-1.5 overflow-clip transition-colors hover:transition-none',
+ props.size === 'sm' ? 'text-sm' : 'text-xs'
+ )}
onClick={() => openExternalUrl(props.unfurled.url)}
>
<div class="flex flex-row items-center gap-1.5 size-full">
@@ -57,7 +63,14 @@ export function UnfurlLink(props: UnfurlLinkProps) {
<h1 class="font-medium truncate text-ink">
{props.unfurled.title || domain}
</h1>
- <h2 class="font-medium text-xxs text-ink-muted">{domain}</h2>
+ <h2
+ class={cn(
+ 'font-medium text-ink-muted',
+ props.size === 'sm' ? 'text-sm' : 'text-xxs'
+ )}
+ >
+ {domain}
+ </h2>
</div>
</div>
</div>