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
import {
ChatWithAgentButton,
ChatWithAgentIcon,
openChatWithAgent,
} from '@app/features/chat/ChatWithAgentButton';
import { useAnalytics } from '@app/lib/analytics/analytics-context';
import type { BlockTool } from '@components/app/ResponsiveBlockToolbar';
import {
ResponsiveBlockToolbar,
ResponsivePermissionsBadge,
} from '@components/app/ResponsiveBlockToolbar';
import type { FileOperation } from '@components/app/split-layout/components/SplitFileMenu';
import { SplitHeaderLeft } from '@components/app/split-layout/components/SplitHeader';
import { BlockItemSplitLabel } from '@components/app/split-layout/components/SplitLabel';
import { useBlockAliasedName, useBlockId } from '@core/block';
import {
getShareDrawerRecipientInput,
ShareTrigger,
} from '@core/component/TopBar/ShareButton';
import { useShareModal } from '@core/component/TopBar/shareModal';
import { isMobile } from '@core/mobile/isMobile';
import { blockMetadataSignal, blockTextSignal } from '@core/signal/load';
import { useGetPermissions } from '@core/signal/permissions';
import {
useBlockDocumentDownloadName,
useBlockDocumentName,
} from '@core/util/currentBlockDocumentName';
import { fireAndForget } from '@core/util/fireAndForget';
import { downloadFile } from '@filesystem/download';
import IconShared from '@icon/share.svg';
import Download from '@icon/system/regular/download-simple.svg';
import { createCallback } from '@solid-primitives/rootless';
import type { Component } from 'solid-js';
import { Show } from 'solid-js';
import type { CodeBlockMode } from './CodeContent';
import { CodeFileTypeChip } from './CodeFileTypeChip';
import { CodeModeControl } from './CodeModeControl';
export const TopBar: Component<{
isHtmlFile: boolean;
mode: CodeBlockMode;
onModeChange: (mode: CodeBlockMode) => void;
}> = (props) => {
const analytics = useAnalytics();
const blockId = useBlockId();
const text = blockTextSignal.get;
const name = useBlockDocumentName();
const downloadName = useBlockDocumentDownloadName();
const blockAlias = useBlockAliasedName();
const permissions = useGetPermissions();
const openShare = useShareModal(() => ({
id: blockId,
blockAlias,
itemType: 'document',
name: name() ?? '',
userPermissions: permissions(),
owner: blockMetadataSignal()?.owner,
}));
const downloadDocument = createCallback(() => {
const content = text();
if (!text || !name) return;
const file = new Blob([content ?? ''], { type: 'text/plain' });
fireAndForget(downloadFile(file, downloadName()), 'code-top-bar');
analytics.track('download', { blockType: 'code' });
});
const ops: FileOperation[] = [
{ op: 'rename' },
{ op: 'copy' },
{ op: 'moveToProject' },
{
group: 'file',
label: 'Download',
icon: Download,
action: downloadDocument,
},
{ op: 'delete' },
];
const chatEntity = () => ({
type: 'document' as const,
id: blockId,
name: name() ?? '',
fileType: 'code',
});
const tools: BlockTool[] = [
{
label: 'Ask Macro',
icon: ChatWithAgentIcon,
action: () => openChatWithAgent(chatEntity()),
buttonComponent: (control) => (
<ChatWithAgentButton
grouped={control.grouped}
entity={chatEntity()}
label="Ask Macro"
/>
),
},
{
group: 'sharing',
label: 'Share',
icon: IconShared,
action: openShare,
buttonComponent: () => <ShareTrigger onClick={openShare} />,
focusTarget: getShareDrawerRecipientInput,
},
];
return (
<>
<SplitHeaderLeft>
<BlockItemSplitLabel badges={<CodeFileTypeChip />} />
<Show when={props.isHtmlFile && !isMobile()}>
<div class="ph-no-capture mx-2 h-full min-w-0 shrink-0">
<CodeModeControl
mode={props.mode}
onModeChange={props.onModeChange}
/>
</div>
</Show>
</SplitHeaderLeft>
<ResponsivePermissionsBadge />
<ResponsiveBlockToolbar
tools={tools}
ops={ops}
id={blockId}
itemType="document"
name={name()}
/>
</>
);
};