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(split): drag entity into split header (#3896)

Seamus932e32890341
diff --git a/js/app/packages/app/component/ItemDragAndDrop.tsx b/js/app/packages/app/component/ItemDragAndDrop.tsx
index cb2df52645..6087b80f60 100644
--- a/js/app/packages/app/component/ItemDragAndDrop.tsx
+++ b/js/app/packages/app/component/ItemDragAndDrop.tsx
@@ -1,12 +1,13 @@
import { TruncatedText } from '@core/component/FileList/TruncatedText';
import type { EntityDragData } from '@entity';
import {
+ type CollisionDetector,
DragDropProvider,
DragDropSensors,
DragOverlay,
- mostIntersecting,
useDragDropContext,
} from '@thisbeyond/solid-dnd';
+import { Layer } from '@ui';
import { EntityIcon, getEntityIconType } from 'core/component/EntityIcon';
import {
type Accessor,
@@ -24,6 +25,40 @@ type DragOperationContextValue = {
const DragOperationContext = createContext<DragOperationContextValue>();
+let pointerPosition: { x: number; y: number } | undefined;
+
+const pointerWithin: CollisionDetector = (_draggable, droppables, context) => {
+ if (!pointerPosition) return null;
+
+ const enabledDroppables = droppables.filter((droppable) => {
+ const isDisabled = droppable.data.isDropTargetDisabled as
+ | (() => boolean)
+ | undefined;
+ return !isDisabled?.();
+ });
+
+ const hits = enabledDroppables.filter((droppable) => {
+ const layout = droppable.layout;
+ return (
+ pointerPosition !== undefined &&
+ pointerPosition.x >= layout.left &&
+ pointerPosition.x <= layout.right &&
+ pointerPosition.y >= layout.top &&
+ pointerPosition.y <= layout.bottom
+ );
+ });
+
+ if (hits.length === 0) return null;
+ if (hits.length === 1) return hits[0];
+
+ return hits.toSorted(
+ (a, b) =>
+ a.layout.width * a.layout.height - b.layout.width * b.layout.height ||
+ Number(b.id === context.activeDroppableId) -
+ Number(a.id === context.activeDroppableId)
+ )[0];
+};
+
export function useDragOperation() {
const context = useContext(DragOperationContext);
if (!context) {
@@ -44,19 +79,36 @@ function ItemDragOverlay() {
return getEntityIconType(data);
});
+ const centeredOnPointerStyle = createMemo(() => {
+ const overlay = state?.active.overlay;
+ const sensor = state?.active.sensor;
+ if (!overlay || !sensor) return;
+
+ return {
+ transform: `translate(${sensor.coordinates.origin.x - overlay.layout.left}px, ${sensor.coordinates.origin.y - overlay.layout.top}px) translate(-50%, -50%)`,
+ };
+ });
+
return (
- <div class="w-auto max-w-75 flex flex-col gap-2 bg-active p-2 rounded-md z-drag shadow-sm pointer-events-none">
- <div class="flex flex-row items-center gap-2">
- <EntityIcon size="sm" targetType={iconType()} />
- <TruncatedText size="sm">{activeDraggable()?.data.name}</TruncatedText>
- </div>
- {/* TODO: when multiselect exists */}
- {/* <Show when={activeDraggable()?.data.selectedItems.length > 1}>
+ <Layer depth={2}>
+ <div
+ class="w-auto max-w-75 flex flex-col gap-2 bg-surface p-2 rounded-lg z-drag shadow-md shadow-drop-shadow pointer-events-none"
+ style={centeredOnPointerStyle()}
+ >
+ <div class="flex flex-row items-center gap-2">
+ <EntityIcon size="xs" targetType={iconType()} />
+ <TruncatedText size="xs">
+ {activeDraggable()?.data.name}
+ </TruncatedText>
+ </div>
+ {/* TODO: when multiselect exists */}
+ {/* <Show when={activeDraggable()?.data.selectedItems.length > 1}>
<div class={`${TEXT_SIZE_CLASSES[size ?? 'sm']} text-ink-muted pl-2`}>
+ {activeDraggable()?.data.selectedItems.length - 1} items
</div>
</Show> */}
- </div>
+ </div>
+ </Layer>
);
}
@@ -75,17 +127,51 @@ export function ItemDndProvider(props: { children: JSXElement }) {
}
};
+ const handlePointerMove = (e: PointerEvent) => {
+ pointerPosition = { x: e.clientX, y: e.clientY };
+ };
+
+ const handleMouseMove = (e: MouseEvent) => {
+ pointerPosition = { x: e.clientX, y: e.clientY };
+ };
+
+ const handlePointerEnd = () => {
+ queueMicrotask(() => {
+ pointerPosition = undefined;
+ });
+ };
+
window.addEventListener('keydown', handleKeyDown);
window.addEventListener('keyup', handleKeyUp);
+ window.addEventListener('pointermove', handlePointerMove, { capture: true });
+ window.addEventListener('pointerup', handlePointerEnd, { capture: true });
+ window.addEventListener('pointercancel', handlePointerEnd, { capture: true });
+ window.addEventListener('mousemove', handleMouseMove, { capture: true });
+ window.addEventListener('mouseup', handlePointerEnd, { capture: true });
onCleanup(() => {
window.removeEventListener('keydown', handleKeyDown);
window.removeEventListener('keyup', handleKeyUp);
+ window.removeEventListener('pointermove', handlePointerMove, {
+ capture: true,
+ });
+ window.removeEventListener('pointerup', handlePointerEnd, {
+ capture: true,
+ });
+ window.removeEventListener('pointercancel', handlePointerEnd, {
+ capture: true,
+ });
+ window.removeEventListener('mousemove', handleMouseMove, {
+ capture: true,
+ });
+ window.removeEventListener('mouseup', handlePointerEnd, {
+ capture: true,
+ });
});
return (
<DragOperationContext.Provider value={{ isAltKey: isAltPressed }}>
- <DragDropProvider collisionDetector={mostIntersecting}>
+ <DragDropProvider collisionDetector={pointerWithin}>
<DragDropSensors />
{props.children}
<DragOverlay class="z-drag">
diff --git a/js/app/packages/app/component/next-soup/utils.ts b/js/app/packages/app/component/next-soup/utils.ts
index 47d6b47060..89363e770a 100644
--- a/js/app/packages/app/component/next-soup/utils.ts
+++ b/js/app/packages/app/component/next-soup/utils.ts
@@ -307,6 +307,7 @@ interface OpenEntityOptions {
location?: SearchLocation;
splitHandle?: SplitHandle;
mergeHistory?: boolean;
+ allowDuplicate?: boolean;
}
/**
@@ -320,7 +321,7 @@ export const openEntityInSplitFromUnifiedList = async (
entity: EntityData,
options: OpenEntityOptions
): Promise<void> => {
- const { openInNewSplit, splitHandle, mergeHistory } = options;
+ const { allowDuplicate, openInNewSplit, splitHandle, mergeHistory } = options;
let { location } = options;
if (!location && isSnippetEntity(entity)) {
@@ -362,6 +363,7 @@ export const openEntityInSplitFromUnifiedList = async (
preferNewSplit: openInNewSplit,
handle: splitHandle,
mergeHistory,
+ allowDuplicate,
}
);
diff --git a/js/app/packages/app/component/split-layout/components/SplitHeader.tsx b/js/app/packages/app/component/split-layout/components/SplitHeader.tsx
index d0afa9b79d..3398852542 100644
--- a/js/app/packages/app/component/split-layout/components/SplitHeader.tsx
+++ b/js/app/packages/app/component/split-layout/components/SplitHeader.tsx
@@ -1,17 +1,17 @@
+import { openEntityInSplitFromUnifiedList } from '@app/component/next-soup/utils';
import { isListViewID } from '@app/constants/list-views';
-import {
- ENABLE_PREVIEW,
- ENABLE_PROJECT_VIEW_PREVIEW,
-} from '@core/constant/featureFlags';
+import type { BlockName } from '@core/block';
+import { fileTypeToBlockName } from '@core/constant/allBlocks';
import { TOKENS } from '@core/hotkey/tokens';
import { isMobile } from '@core/mobile/isMobile';
+import type { EntityDragEvent } from '@entity';
import CollapseIcon from '@phosphor/arrows-in.svg';
import ExpandIcon from '@phosphor/arrows-out.svg';
import CaretLeft from '@phosphor/caret-left.svg';
import CaretRight from '@phosphor/caret-right.svg';
-import EyeIcon from '@phosphor/eye.svg';
-import EyeSlashIcon from '@phosphor/eye-slash.svg';
import CloseIcon from '@phosphor/x.svg';
+import { mergeRefs } from '@solid-primitives/refs';
+import { createDroppable, useDragDropContext } from '@thisbeyond/solid-dnd';
import { Button, cn } from '@ui';
import {
createMemo,
@@ -22,8 +22,33 @@ import {
} from 'solid-js';
import { Portal } from 'solid-js/web';
import { SplitLayoutContext, SplitPanelContext } from '../context';
+import type { SplitContent } from '../layoutManager';
import { canSpotlight } from '../utils/canSpotlight';
+function getEntitySplitContent(data: EntityDragEvent['draggable']['data']):
+ | {
+ type: SplitContent['type'];
+ id: string;
+ }
+ | undefined {
+ if (data.type === 'document') {
+ return {
+ type: fileTypeToBlockName(data.subType?.type ?? data.fileType) as
+ | BlockName
+ | 'unknown',
+ id: data.id,
+ };
+ }
+
+ if (data.type === 'channel_message') {
+ return { type: 'channel', id: data.channelId };
+ }
+
+ if (data.type === 'foreign') return undefined;
+
+ return { type: data.type, id: data.id };
+}
+
function SplitBackButton() {
const context = useContext(SplitPanelContext);
if (!context) return null;
@@ -108,66 +133,74 @@ function SplitCloseButton() {
);
}
-function _SplitPreviewToggle() {
- const context = useContext(SplitPanelContext);
- if (!ENABLE_PREVIEW || !context || !context.previewState) return null;
+export function SplitHeader(props: { ref: Setter<HTMLDivElement | null> }) {
+ const panel = useContext(SplitPanelContext);
+ if (!panel) {
+ throw new Error('<SplitHeader> must be used within a <SplitLayout>');
+ }
- // Only show toggle for unified-list component and project block
- const isUnifiedList = createMemo(() => {
- const content = context.handle.content();
- if (ENABLE_PROJECT_VIEW_PREVIEW && content.type === 'project') return true;
- return content.type === 'component' && content.id === 'unified-list';
+ const droppableId = `split-header-${panel.handle.id}`;
+ const droppable = createDroppable(droppableId, {
+ type: 'split-header',
});
+ const [dragDropState, { onDragEnd }] = useDragDropContext() ?? [
+ undefined,
+ { onDragEnd: () => {} },
+ ];
- const [preview, setPreview] = context.previewState;
+ const isEntityDraggingOver = createMemo(() => {
+ const data = dragDropState?.active.draggable?.data;
+ return (
+ data?.dragType === 'entity' &&
+ dragDropState?.active.droppable?.id === droppableId
+ );
+ });
- return (
- <Show when={isUnifiedList()}>
- <div class="max-sm:rotate-90">
- <Button
- class="p-1 rounded-lg"
- classList={{
- 'bg-accent/20 text-accent': preview(),
- }}
- label={!preview() ? 'Split View (Preview)' : 'Full View (List)'}
- hotkey={TOKENS.unifiedList.togglePreview}
- tabIndex={-1}
- onClick={() => setPreview((prev) => !prev)}
- >
- {preview() ? <EyeSlashIcon /> : <EyeIcon />}
- </Button>
- </div>
- </Show>
- );
-}
+ onDragEnd((event: EntityDragEvent) => {
+ if (event.droppable?.id !== droppableId) return;
-function _SplitControlButtons() {
- return (
- <div class="flex flex-row items-center px-2 h-full shrink-0">
- <div class="mobile:hidden">
- <SplitCloseButton />
- </div>
- <SplitBackButton />
- <SplitForwardButton />
- </div>
- );
-}
+ const data = event.draggable?.data;
+ if (!data || data.dragType !== 'entity') return;
-export function SplitHeader(props: { ref: Setter<HTMLDivElement | null> }) {
- const panel = useContext(SplitPanelContext);
- if (!panel) {
- throw new Error('<SplitHeader> must be used within a <SplitLayout>');
- }
+ const current = panel.handle.content();
+ const next = getEntitySplitContent(data);
+ if (!next) return;
+ if (current.type === next.type && current.id === next.id) return;
+
+ void openEntityInSplitFromUnifiedList(data, {
+ splitHandle: panel.handle,
+ allowDuplicate: true,
+ });
+ });
return (
<div
class={cn(
'isolate relative w-full h-full overflow-clip text-ink',
- isMobile() && isListViewID(panel.handle.content().id) && 'hidden'
+ isMobile() && isListViewID(panel.handle.content().id) && 'hidden',
+ isEntityDraggingOver() && 'bg-active/50'
)}
data-split-header
- ref={props.ref}
+ ref={mergeRefs(droppable, props.ref)}
>
+ <Show when={panel.panelRef()}>
+ {(panelRef) => (
+ <Portal mount={panelRef()}>
+ <Show when={isEntityDraggingOver()}>
+ <div
+ class="pointer-events-none absolute inset-0 rounded-xl z-modal-overlay bg-modal-overlay pattern-diagonal-4 pattern-edge-muted flex items-center justify-center"
+ data-split-header-drop-overlay
+ >
+ <div class="max-w-[min(28rem,calc(100%-3rem))] min-w-0 bg-surface border border-edge rounded-lg shadow-lg shadow-drop-shadow px-4 py-3 flex items-center gap-2 text-sm text-ink">
+ <span class="shrink-0 text-ink-muted">
+ Open in this split
+ </span>
+ </div>
+ </div>
+ </Show>
+ </Portal>
+ )}
+ </Show>
<div class="absolute inset-0 flex justify-start items-center">
<div class="relative flex items-center pl-2 mobile:pl-0 h-full">
<div class="mobile:hidden">
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 f6640261a2..ae4066dc02 100644
--- a/js/app/packages/app/component/split-layout/components/SplitPanel.tsx
+++ b/js/app/packages/app/component/split-layout/components/SplitPanel.tsx
@@ -152,6 +152,7 @@ export function SplitPanel(props: SplitPanelProps) {
</Show>
<div
+ class="relative"
classList={{
'fixed inset-16 z-modal-overlay isolate opacity-50':
props.handle.isSpotLight(),
diff --git a/js/app/packages/core/component/FileDropOverlay.tsx b/js/app/packages/core/component/FileDropOverlay.tsx
index 6ca60bb4fa..634a0c981a 100644
--- a/js/app/packages/core/component/FileDropOverlay.tsx
+++ b/js/app/packages/core/component/FileDropOverlay.tsx
@@ -7,13 +7,13 @@ export const FileDropOverlay = (props: ParentProps<{ valid?: boolean }>) => {
const valid = () => props.valid !== false;
return (
<div
- class="absolute size-full inset-0 z-modal bg-modal-overlay pattern-diagonal-8 flex items-center justify-center"
+ class="absolute size-full inset-0 rounded-xl z-modal bg-modal-overlay pattern-diagonal-4 flex items-center justify-center"
classList={{
'pattern-edge-muted': valid(),
'pattern-failure-bg': !valid(),
}}
>
- <div class="bg-surface border border-edge px-8 py-4 text-xs text-ink-muted shadow-md font-mono">
+ <div class="max-w-[min(28rem,calc(100%-3rem))] min-w-0 bg-surface border border-edge rounded-lg shadow-lg shadow-drop-shadow px-4 py-3 flex items-center gap-2 text-sm text-ink">
{props.children}
</div>
</div>
diff --git a/js/bun.lock b/js/bun.lock
index 772e2c16ae..c1b5aff31b 100644
--- a/js/bun.lock
+++ b/js/bun.lock
@@ -830,7 +830,7 @@
"@img/sharp-win32-x64": ["@img/[email protected]", "", { "os": "win32", "cpu": "x64" }, "sha512-+29YMsqY2/9eFEiW93eqWnuLcWcufowXewwSNIT6UwZdUUCrM3oFjMWH/Z6/TMmb4hlFenmfAVbpWeup2jryCw=="],
- "@inkibra/tauri-plugins": ["@inkibra/tauri-plugins@github:macro-inc/tauri-plugins#26537c8", { "dependencies": { "react": "^18.3.1", "react-dom": "^18.3.1" } }, "macro-inc-tauri-plugins-26537c8", "sha512-6p5xQAkS6Uw6J8Uh0vlj6MjKZXWps5E1Gu0hciBFq1E2BfPBZAgdeeafKnR3diNb4SXWK0JML49nAr+o5PhwKw=="],
+ "@inkibra/tauri-plugins": ["@inkibra/tauri-plugins@github:macro-inc/tauri-plugins#26537c8", { "dependencies": { "react": "^18.3.1", "react-dom": "^18.3.1" } }, "macro-inc-tauri-plugins-26537c8"],
"@inquirer/external-editor": ["@inquirer/[email protected]", "", { "dependencies": { "chardet": "^2.1.1", "iconv-lite": "^0.7.0" }, "peerDependencies": { "@types/node": ">=18" }, "optionalPeers": ["@types/node"] }, "sha512-RWbSrDiYmO4LbejWY7ttpxczuwQyZLBUyygsA9Nsv95hpzUWwnNTVQmAq3xuh7vNwCp07UTmE5i11XAEExx4RA=="],
@@ -2550,7 +2550,7 @@
"pathval": ["[email protected]", "", {}, "sha512-//nshmD55c46FuFw26xV/xFAaB5HF9Xdap7HJBBnrKdAd6/GxDBaNA1870O79+9ueg61cZLSVc+OaFlfmObYVQ=="],
- "pdfjs-dist": ["pdfjs-dist@github:macro-inc/pdf.js#f9b2ce6", { "dependencies": { "dommatrix": "^1.0.3", "web-streams-polyfill": "^3.2.1" }, "peerDependencies": { "worker-loader": "^3.0.8" }, "optionalPeers": ["worker-loader"] }, "macro-inc-pdf.js-f9b2ce6", "sha512-HDFaPbCxLG2GHpf1smUG97nku5aPGBGaCcIbK05dGdp07TBLUlDcXsM4WcE82mO5W4RBPIBVYobX5N/6M6NFrA=="],
+ "pdfjs-dist": ["pdfjs-dist@github:macro-inc/pdf.js#f9b2ce6", { "dependencies": { "dommatrix": "^1.0.3", "web-streams-polyfill": "^3.2.1" }, "peerDependencies": { "worker-loader": "^3.0.8" }, "optionalPeers": ["worker-loader"] }, "macro-inc-pdf.js-f9b2ce6"],
"performance-now": ["[email protected]", "", {}, "sha512-7EAHlyLHI56VEIdK57uwHdHKIaAGbnXPiw0yWbarQZOKaKpvUIgW0jWRVLiatnM+XXlSwsanIBH/hzGMJulMow=="],