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.

feat(pdf): add block sidepanel to pdf (#4435)

Seamus5907fe227f38
diff --git a/js/app/packages/app/component/split-layout/components/SplitPanel.tsx b/js/app/packages/app/component/split-layout/components/SplitPanel.tsx
index 96a04b9ad6..53372afd7e 100644
--- a/js/app/packages/app/component/split-layout/components/SplitPanel.tsx
+++ b/js/app/packages/app/component/split-layout/components/SplitPanel.tsx
@@ -234,7 +234,7 @@ export function SplitPanel(props: SplitPanelProps) {
<Panel.Toolbar
class={cn(
- 'items-start py-2 overflow-visible',
+ 'items-start overflow-visible',
!hasToolbarContent() && 'hidden',
isMobile() && 'hidden',
(!previewState() ||
diff --git a/js/app/packages/block-pdf/component/Block.tsx b/js/app/packages/block-pdf/component/Block.tsx
index 7059419c40..862012f5bc 100644
--- a/js/app/packages/block-pdf/component/Block.tsx
+++ b/js/app/packages/block-pdf/component/Block.tsx
@@ -1,6 +1,7 @@
import './block.css';
import { useBlockEntityCommands } from '@app/component/next-soup/actions';
+import { SidePanel } from '@app/component/side-panel';
import {
type LocationBlockParams,
locationChangedSignal,
@@ -45,6 +46,7 @@ import {
import { preprocess } from '../websocket/preprocess';
import { Document } from './Document';
import { ModalsProvider } from './ModalsProvider';
+import { PdfSidePanelSections } from './sidepanel/PdfSidePanelSections';
import { Tabs } from './Tabs';
import { TopBar } from './TopBar';
@@ -189,24 +191,39 @@ export default function BlockPdf() {
data-tut="App"
>
<ModalsProvider>
- <Show when={!isNestedBlock}>
- <TopBar />
- <Show when={showTabBar()}>
- <div class="flex px-2 justify-between min-h-11 items-center gap-2">
- <div class="overflow-x-auto overflow-y-hidden grow customScrollbar w-0">
- <Tabs />
+ <Show
+ when={!isNestedBlock}
+ fallback={
+ <div
+ class="flex size-full relative justify-end overflow-visible z-main-view-layout"
+ id="main-view"
+ >
+ <Document />
+ </div>
+ }
+ >
+ <SidePanel.Layout>
+ <PdfSidePanelSections />
+ <div class="flex size-full min-w-0 flex-col overflow-hidden">
+ <TopBar />
+ <Show when={showTabBar()}>
+ <div class="flex px-2 justify-between min-h-11 items-center gap-2">
+ <div class="overflow-x-auto overflow-y-hidden grow customScrollbar w-0">
+ <Tabs />
+ </div>
+ </div>
+ </Show>
+ <div
+ class="flex size-full relative justify-end overflow-visible z-main-view-layout"
+ id="main-view"
+ >
+ {/* {ENABLE_VIEWER_SIDE_PANEL && <ViewerNavStack />} */}
+ <Document />
+ {/* <CustomCursor /> */}
</div>
</div>
- </Show>
+ </SidePanel.Layout>
</Show>
- <div
- class="flex size-full relative justify-end overflow-visible z-main-view-layout"
- id="main-view"
- >
- {/* {ENABLE_VIEWER_SIDE_PANEL && <ViewerNavStack />} */}
- <Document />
- {/* <CustomCursor /> */}
- </div>
</ModalsProvider>
</div>
</DocumentBlockContainer>
diff --git a/js/app/packages/block-pdf/component/MarkupToolbar.tsx b/js/app/packages/block-pdf/component/MarkupToolbar.tsx
index 8957f660e9..f174df589b 100644
--- a/js/app/packages/block-pdf/component/MarkupToolbar.tsx
+++ b/js/app/packages/block-pdf/component/MarkupToolbar.tsx
@@ -2,7 +2,6 @@ import { useOwnedCommentPlaceableSelector } from '@block-pdf/signal/permissions'
import {
activePlaceableIdSignal,
placeableModeSignal,
- showTabBarSignal,
} from '@block-pdf/signal/placeables';
import { isThreadPlaceable } from '@block-pdf/store/comments/freeComments';
import {
@@ -12,13 +11,11 @@ import {
} from '@core/signal/permissions';
import ChatTeardrop from '@phosphor/chat-teardrop.svg';
import Signature from '@phosphor/signature.svg';
-import Tabs from '@phosphor/tabs.svg';
import Textbox from '@phosphor/textbox.svg';
import Trash from '@phosphor/trash-simple.svg';
import Cancel from '@phosphor/x.svg';
import { Button } from '@ui';
import { createMemo, Show } from 'solid-js';
-import { Dynamic } from 'solid-js/web';
import { placeableIdMap, useDeletePlaceable } from '../store/placeables';
import { PayloadMode } from '../type/placeables';
@@ -28,7 +25,6 @@ export function MarkupToolbar() {
const isDocumentOwner = useIsDocumentOwner();
const [mode, setMode] = placeableModeSignal;
- const [showTabBar, setShowTabBar] = showTabBarSignal;
const activePlaceableId = activePlaceableIdSignal.get;
const deletePlaceable = useDeletePlaceable();
@@ -44,63 +40,10 @@ export function MarkupToolbar() {
return ownedCommentSelector(uuid);
});
- const dynamicButtonMode = () => {
- if (showCancel()) return 'cancel';
- if (showDelete()) return 'delete';
- return 'placeholder';
- };
-
- const dynamicButton = createMemo(() => ({
- cancel: () => (
- <Button
- size="icon-sm"
- variant="danger"
- tooltip="Cancel"
- onClick={() => {
- setMode(PayloadMode.NoMode);
- }}
- >
- <Cancel />
- </Button>
- ),
- delete: () => (
- <Button
- size="icon-sm"
- variant="danger"
- tooltip="Delete"
- onClick={() => {
- const activePlaceableIndex_ = activePlaceableId();
- if (activePlaceableIndex_ == null) return;
- deletePlaceable(activePlaceableIndex_);
- }}
- >
- <Trash />
- </Button>
- ),
- placeholder: () => (
- <div class="invisible">
- <Button size="icon-sm">
- <Cancel />
- </Button>
- </div>
- ),
- }));
-
return (
<Show when={canComment()}>
<div class="flex flex-row items-center">
<Show when={canEdit()}>
- <Button
- size="icon-sm"
- label={showTabBar() ? 'Hide Tabs' : 'Show Tabs'}
- variant="ghost"
- onClick={() => {
- setShowTabBar(!showTabBar());
- }}
- >
- <Tabs />
- </Button>
- <div class="w-px h-5 bg-edge mx-2" />
<Button
size="icon-sm"
label="Text Box"
@@ -130,7 +73,45 @@ export function MarkupToolbar() {
>
<ChatTeardrop />
</Button>
- <Dynamic component={dynamicButton()[dynamicButtonMode()]} />
+ <Show
+ when={showCancel()}
+ fallback={
+ <Show
+ when={showDelete()}
+ fallback={
+ <div class="invisible">
+ <Button size="icon-sm">
+ <Cancel />
+ </Button>
+ </div>
+ }
+ >
+ <Button
+ size="icon-sm"
+ variant="danger"
+ tooltip="Delete"
+ onClick={() => {
+ const activePlaceableIndex_ = activePlaceableId();
+ if (activePlaceableIndex_ == null) return;
+ deletePlaceable(activePlaceableIndex_);
+ }}
+ >
+ <Trash />
+ </Button>
+ </Show>
+ }
+ >
+ <Button
+ size="icon-sm"
+ variant="danger"
+ tooltip="Cancel"
+ onClick={() => {
+ setMode(PayloadMode.NoMode);
+ }}
+ >
+ <Cancel />
+ </Button>
+ </Show>
</div>
</Show>
);
diff --git a/js/app/packages/block-pdf/component/PageNumberInput.tsx b/js/app/packages/block-pdf/component/PageNumberInput.tsx
index c2e317f833..4bc5c3731e 100644
--- a/js/app/packages/block-pdf/component/PageNumberInput.tsx
+++ b/js/app/packages/block-pdf/component/PageNumberInput.tsx
@@ -23,9 +23,9 @@ export function PageNumberInput() {
const getWidthClass = (value: number | string) => {
const strLength = value.toString().length;
- if (strLength < 2) return 'w-[14px]';
- if (strLength < 3) return 'w-[19px]';
- return 'w-[36px]';
+ if (strLength < 2) return 'w-8';
+ if (strLength < 3) return 'w-9';
+ return 'w-11';
};
const onBlur = createCallback((_e: FocusEvent) => {
@@ -61,13 +61,14 @@ export function PageNumberInput() {
<Show when={getPageCount() > 0}>
<div class="text-sm font-medium text-ink flex align-middle items-center justify-start">
<div
- class="flex flex-row items-center justify-center"
+ class="flex flex-row items-center justify-center gap-1.5"
onClick={() => inputRef?.select()}
>
- <div class="px-1 hover:bg-hover hover-transition-bg cursor-default focus-within:bg-active">
+ <div class="cursor-default">
<input
class={cn(
- 'py-0.5 px-0 text-sm bg-transparent text-ink font-medium cursor-default text-center border-none flex-initial focus:bg-surface',
+ 'rounded-md border border-edge-muted bg-transparent px-2 text-sm text-ink outline-none placeholder:text-ink-extra-muted focus:border-accent',
+ 'font-medium cursor-default text-center',
getWidthClass(currentPageNumber())
)}
step="1"
@@ -88,7 +89,7 @@ export function PageNumberInput() {
}}
/>
</div>
- <div class="select-none whitespace-nowrap">
+ <div class="select-none whitespace-nowrap text-ink-muted">
/&thinsp;{getPageCount()}
</div>
</div>
diff --git a/js/app/packages/block-pdf/component/PdfSplitToolbar.tsx b/js/app/packages/block-pdf/component/PdfSplitToolbar.tsx
new file mode 100644
index 0000000000..e9951225ce
--- /dev/null
+++ b/js/app/packages/block-pdf/component/PdfSplitToolbar.tsx
@@ -0,0 +1,52 @@
+import {
+ SplitToolbarLeft,
+ SplitToolbarRight,
+} from '@app/component/split-layout/components/SplitToolbar';
+import { showTabBarSignal } from '@block-pdf/signal/placeables';
+import { ENABLE_PDF_MARKUP } from '@core/constant/featureFlags';
+import { useCanEdit } from '@core/signal/permissions';
+import Tabs from '@phosphor/tabs.svg';
+import { Button } from '@ui';
+import { Show } from 'solid-js';
+import { pdfDocumentProxy } from '../signal/document';
+import { MarkupToolbar } from './MarkupToolbar';
+import { PageNumberInput } from './PageNumberInput';
+
+function TabsToggle() {
+ const canEdit = useCanEdit();
+ const [showTabBar, setShowTabBar] = showTabBarSignal;
+
+ return (
+ <Show when={canEdit()}>
+ <Button
+ size="icon-sm"
+ label={showTabBar() ? 'Hide Tabs' : 'Show Tabs'}
+ variant="ghost"
+ onClick={() => {
+ setShowTabBar(!showTabBar());
+ }}
+ >
+ <Tabs />
+ </Button>
+ </Show>
+ );
+}
+
+export function PdfSplitToolbar() {
+ return (
+ <Show when={pdfDocumentProxy()}>
+ <SplitToolbarLeft>
+ <div class="flex items-center gap-2">
+ <PageNumberInput />
+ <Show when={ENABLE_PDF_MARKUP}>
+ <div class="h-5 w-px bg-edge" />
+ <MarkupToolbar />
+ </Show>
+ </div>
+ </SplitToolbarLeft>
+ <SplitToolbarRight>
+ <TabsToggle />
+ </SplitToolbarRight>
+ </Show>
+ );
+}
diff --git a/js/app/packages/block-pdf/component/TopBar.tsx b/js/app/packages/block-pdf/component/TopBar.tsx
index 964ee72984..9e698daf2b 100644
--- a/js/app/packages/block-pdf/component/TopBar.tsx
+++ b/js/app/packages/block-pdf/component/TopBar.tsx
@@ -15,14 +15,12 @@ import {
SplitHeaderRight,
} from '@app/component/split-layout/components/SplitHeader';
import { BlockItemSplitLabel } from '@app/component/split-layout/components/SplitLabel';
-import { SplitToolbarLeft } from '@app/component/split-layout/components/SplitToolbar';
import { useHasModificationData } from '@block-pdf/signal/save';
import { useHasComments } from '@block-pdf/store/comments/commentStore';
import { doPrint } from '@block-pdf/util/printUtil';
import { exportPdf } from '@block-pdf/websocket/export';
import { useIsAuthenticated } from '@core/auth';
import { useBlockId, useBlockName } from '@core/block';
-import { DETAILS_DRAWER_ID } from '@core/component/DetailsDrawer';
import { BlockLiveIndicators } from '@core/component/LiveIndicators';
import {
REFERENCES_DRAWER_ID,
@@ -34,17 +32,12 @@ import {
ShareTrigger,
useShareDialogContext,
} from '@core/component/TopBar/ShareButton';
-import {
- ENABLE_PDF_MARKUP,
- ENABLE_REFERENCES_MODAL,
-} from '@core/constant/featureFlags';
-import { isMobile } from '@core/mobile/isMobile';
+import { ENABLE_REFERENCES_MODAL } from '@core/constant/featureFlags';
import { blockMetadataSignal } from '@core/signal/load';
import { useBlockDocumentName } from '@core/util/currentBlockDocumentName';
import { downloadFile } from '@filesystem/download';
import IconShared from '@icon/wide-share.svg';
import DownloadIcon from '@phosphor/download-simple.svg';
-import Info from '@phosphor/info.svg';
import Printer from '@phosphor/printer.svg';
import Quotes from '@phosphor/quotes.svg';
import {
@@ -54,11 +47,9 @@ import {
import { createCallback } from '@solid-primitives/rootless';
import { toast } from 'core/component/Toast/Toast';
import { platformFetch } from 'core/util/platformFetch';
-import { Show } from 'solid-js';
import { pdfDocumentProxy } from '../signal/document';
import { LocationType, useCreateShareUrl } from '../signal/location';
-import { MarkupToolbar } from './MarkupToolbar';
-import { PageNumberInput } from './PageNumberInput';
+import { PdfSplitToolbar } from './PdfSplitToolbar';
export function TopBar() {
const isAuth = useIsAuthenticated();
@@ -69,7 +60,6 @@ export function TopBar() {
const fileName = useBlockDocumentName('Unknown Filename');
const referencesControl = useDrawerControl(REFERENCES_DRAWER_ID);
- const detailsControl = useDrawerControl(DETAILS_DRAWER_ID);
const shareCtx = useShareDialogContext();
const createShareUrl = useCreateShareUrl();
@@ -163,11 +153,6 @@ export function TopBar() {
});
const ops: FileOperation[] = [
- {
- label: 'Details',
- icon: Info,
- action: detailsControl.toggle,
- },
{ op: 'rename' },
{ op: 'copy' },
{ op: 'moveToProject' },
@@ -237,6 +222,20 @@ export function TopBar() {
},
];
+ const menuTools: BlockTool[] = [
+ {
+ label: 'Ask Macro',
+ icon: ChatWithAgentIcon,
+ action: () =>
+ openChatWithAgent({
+ type: 'document',
+ id: documentId,
+ name: fileName(),
+ fileType,
+ }),
+ },
+ ];
+
return (
<>
<SplitHeaderLeft>
@@ -248,21 +247,11 @@ export function TopBar() {
<BlockLiveIndicators />
</div>
</SplitHeaderRight>
+ <PdfSplitToolbar />
<ResponsivePermissionsBadge />
- <SplitToolbarLeft>
- <Show when={pdfDocumentProxy()}>
- <div class="flex items-center p-1">
- <Show when={!isMobile()}>
- <div class="w-5" />
- </Show>
- <PageNumberInput />
- <div class="w-5" />
- {ENABLE_PDF_MARKUP && <MarkupToolbar />}
- </div>
- </Show>
- </SplitToolbarLeft>
<ResponsiveBlockToolbar
tools={tools}
+ menuTools={menuTools}
ops={ops}
id={documentId}
itemType={itemType}
diff --git a/js/app/packages/block-pdf/component/sidepanel/PdfSidePanelSections.tsx b/js/app/packages/block-pdf/component/sidepanel/PdfSidePanelSections.tsx
new file mode 100644
index 0000000000..a1d9616080
--- /dev/null
+++ b/js/app/packages/block-pdf/component/sidepanel/PdfSidePanelSections.tsx
@@ -0,0 +1,133 @@
+import { AskMacroButton } from '@app/component/ChatWithAgentButton';
+import { SidePanel } from '@app/component/side-panel';
+import { useBlockId } from '@core/block';
+import { EntityIcon } from '@core/component/EntityIcon';
+import { openDocument } from '@core/component/LexicalMarkdown/component/core/BlockLink';
+import { UserIcon } from '@core/component/UserIcon';
+import { blockMetadataSignal } from '@core/signal/load';
+import { tryMacroId, useDisplayName } from '@core/user';
+import { useBlockDocumentName } from '@core/util/currentBlockDocumentName';
+import { type DateValue, formatDate } from '@core/util/date';
+import { useSplitNavigationHandler } from '@core/util/useSplitNavigationHandler';
+import { useDocumentMetadataQuery } from '@queries/storage/document-metadata';
+import { createCallback } from '@solid-primitives/rootless';
+import { createMemo, Show } from 'solid-js';
+
+export function PdfSidePanelSections() {
+ return (
+ <>
+ <SidePanel.Section id="actions" title="Actions" defaultOpen order={10}>
+ <ActionsSectionContent />
+ </SidePanel.Section>
+ <SidePanel.Section id="details" title="Details" defaultOpen order={20}>
+ <DetailsSectionContent />
+ </SidePanel.Section>
+ </>
+ );
+}
+
+function ActionsSectionContent() {
+ const documentId = useBlockId();
+ const name = useBlockDocumentName('Unknown Filename');
+ const fileType = () => blockMetadataSignal()?.fileType;
+
+ return (
+ <div class="m-px flex items-center justify-start gap-2">
+ <AskMacroButton
+ entity={{
+ type: 'document',
+ id: documentId,
+ name: name(),
+ fileType: fileType(),
+ }}
+ />
+ </div>
+ );
+}
+
+function DetailsSectionContent() {
+ const blockId = useBlockId();
+ const query = useDocumentMetadataQuery(() => blockId);
+ const metadata = createMemo(() => query.data);
+
+ return (
+ <SidePanel.Grid>
+ <Show when={metadata()?.owner}>
+ {(ownerId) => (
+ <SidePanel.Row label="Owner">
+ <OwnerValue ownerId={ownerId()} />
+ </SidePanel.Row>
+ )}
+ </Show>
+ <Show
+ when={(() => {
+ const id = metadata()?.projectId;
+ const name = metadata()?.projectName;
+ return id && name ? { id, name } : undefined;
+ })()}
+ >
+ {(folder) => (
+ <SidePanel.Row label="Folder">
+ <FolderLink projectId={folder().id} projectName={folder().name} />
+ </SidePanel.Row>
+ )}
+ </Show>
+ <Show when={metadata()?.createdAt}>
+ {(created) => (
+ <SidePanel.Row label="Created">
+ <DateValueDisplay value={created()} />
+ </SidePanel.Row>
+ )}
+ </Show>
+ <Show when={metadata()?.updatedAt}>
+ {(updated) => (
+ <SidePanel.Row label="Last updated">
+ <DateValueDisplay value={updated()} />
+ </SidePanel.Row>
+ )}
+ </Show>
+ </SidePanel.Grid>
+ );
+}
+
+function FolderLink(props: { projectId: string; projectName: string }) {
+ const open = createCallback((e: MouseEvent) => {
+ openDocument('project', props.projectId, undefined, !e.shiftKey);
+ });
+ const navHandlers = useSplitNavigationHandler<HTMLSpanElement>(open);
+
+ return (
+ <span
+ {...navHandlers}
+ class={SidePanel.pillClass + ' pointer-events-auto hover:bg-hover'}
+ >
+ <span class="relative size-3 shrink-0">
+ <EntityIcon targetType="project" size="fill" />
+ </span>
+ <span class="truncate underline decoration-current/20 decoration-[max(1px,0.1em)] underline-offset-2">
+ {props.projectName}
+ </span>
+ </span>
+ );
+}
+
+function OwnerValue(props: { ownerId: string }) {
+ const [displayName] = useDisplayName(tryMacroId(props.ownerId));
+
+ return (
+ <SidePanel.Pill>
+ <UserIcon id={props.ownerId} size="sm" showTooltip suppressClick />
+ <span class="truncate">{displayName()}</span>
+ </SidePanel.Pill>
+ );
+}
+
+function DateValueDisplay(props: { value: DateValue }) {
+ return (
+ <SidePanel.Pill>
+ <span class="truncate">
+ {formatDate(props.value, { showTime: true })}
+ </span>
+ </SidePanel.Pill>
+ );
+}
diff --git a/js/app/packages/ui/components/Panel.tsx b/js/app/packages/ui/components/Panel.tsx
index 51ba8bb08f..50b2bf85cc 100644
--- a/js/app/packages/ui/components/Panel.tsx
+++ b/js/app/packages/ui/components/Panel.tsx
@@ -59,7 +59,7 @@ function PanelToolbar(props: SlotProps) {
<Show when={resolved()}>
<div
class={cn(
- 'flex flex-none items-center min-h-10 px-2 overflow-x-hidden border-b border-edge-muted overflow-hidden',
+ 'flex flex-none items-center p-2 overflow-x-hidden border-b border-edge-muted overflow-hidden',
props.class
)}
style={{ 'grid-area': 'toolbar' }}