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
soup: preview mode hotkey to focus preview block (#248)
Caleb Taylorb47bae607351
diff --git a/js/app/packages/app/component/Soup.tsx b/js/app/packages/app/component/Soup.tsxindex 7b3e3526dc..42e405a145 100644--- a/js/app/packages/app/component/Soup.tsx+++ b/js/app/packages/app/component/Soup.tsx@@ -140,13 +140,12 @@ const PreviewPanelContent: Component<{: props.selectedEntity.type,props.selectedEntity.id);- const [interactedWithMouseDown, setInteractedWithMouseDown] =- createSignal(false);+ const [interactedWith, setInteractedWith] = createSignal(false);createRenderEffect((prevId: string) => {const id = props.selectedEntity.id;if (id !== prevId) {- setInteractedWithMouseDown(false);+ setInteractedWith(false);}return id;}, props.selectedEntity.id);@@ -155,16 +154,22 @@ const PreviewPanelContent: Component<{<divclass="size-full"onFocusIn={(event) => {- if (interactedWithMouseDown()) return;+ if (interactedWith()) return;const relatedTarget = event.relatedTarget as HTMLElement;const currentTarget = event.currentTarget as HTMLElement;+ // TODO: use state instead to determine when preview block can recieve focus+ if (event.target.hasAttribute('data-allow-focus-in-preview')) {+ setInteractedWith(true);+ return;+ }+if (!currentTarget.contains(relatedTarget)) {relatedTarget.focus();}}}onPointerDown={() => {- setInteractedWithMouseDown(true);+ setInteractedWith(true);}}><SplitPanelContext.Provider@@ -226,20 +231,8 @@ export function Soup() {},} = splitPanelContext;const view = createMemo(() => viewsData[selectedView()]);- // Use preview state from SplitPanelContext (created in SplitLayout for unified-list)const previewState = () => splitPanelContext.previewState;- const preview = () => previewState()?.[0]?.() ?? false;- const setPreview = (value: boolean | ((prev: boolean) => boolean)) => {- const state = previewState();- if (state) {- const [, setState] = state;- if (typeof value === 'function') {- setState((prev) => value(prev));- } else {- setState(value);- }- }- };+ const [preview, setPreview] = previewState();const selectedEntity = () => view().selectedEntity;const orchestrator = useGlobalBlockOrchestrator();diff --git a/js/app/packages/app/component/SoupContext.tsx b/js/app/packages/app/component/SoupContext.tsxindex 83e34f7472..29df46e91e 100644--- a/js/app/packages/app/component/SoupContext.tsx+++ b/js/app/packages/app/component/SoupContext.tsx@@ -1,4 +1,5 @@import { fileTypeToBlockName } from '@core/constant/allBlocks';+import { activeScope, hotkeyScopeTree } from '@core/hotkey/state';import { TOKENS } from '@core/hotkey/tokens';import type { ValidHotkey } from '@core/hotkey/types';import {@@ -14,9 +15,12 @@ import type { EntityData } from '@macro-entity';import { useTutorialCompleted } from '@service-gql/client';import { storageServiceClient } from '@service-storage/client';import { createLazyMemo } from '@solid-primitives/memo';-import { useQuery } from '@tanstack/solid-query';-import { registerHotkey, useHotkeyDOMScope } from 'core/hotkey/hotkeys';+import {+ registerHotkey,+ runCommand,+ useHotkeyDOMScope,+} from 'core/hotkey/hotkeys';import {type Accessor,batch,@@ -196,11 +200,13 @@ export function createNavigationEntityListShortcut({splitHandle,splitHotkeyScope,unifiedListContext,+ previewState,}: {splitName: Accessor<string>;splitHandle: SplitHandle;splitHotkeyScope: string;unifiedListContext: UnifiedListContext;+ previewState: Signal<boolean>;}) {const {viewsDataStore: viewsData,@@ -872,6 +878,9 @@ export function createNavigationEntityListShortcut({scopeId: entityHotkeyScope,description: 'Open',keyDownHandler: () => {+ const [preview] = previewState;+ if (!preview()) return false;+const entity = getHighlightedEntity()?.entity;if (!entity) return false;@@ -880,6 +889,57 @@ export function createNavigationEntityListShortcut({},displayPriority: 4,});+ registerHotkey({+ hotkey: ['cmd+enter'],+ scopeId: entityHotkeyScope,+ description: 'Focus Preview',+ keyDownHandler: () => {+ const [preview] = previewState;++ const entity = getHighlightedEntity()?.entity;+ if (!entity) return false;++ if (preview()) {+ // focus inside preview block+ const blockEl = document.getElementById(`block-${entity.id}`);+ if (blockEl) {+ // TODO: use state instead to determine when preview block can recieve focus+ blockEl.setAttribute('data-allow-focus-in-preview', '');++ blockEl.focus();+ const getEnterCommand = () => {+ const currentActiveScope = activeScope();+ if (!currentActiveScope) return undefined;+ let activeScopeNode = hotkeyScopeTree.get(currentActiveScope);+ if (!activeScopeNode) return undefined;+ if (activeScopeNode?.type !== 'dom') return;+ const dom = activeScopeNode.element;+ const closestBlockScope = dom.closest(`[id="block-${entity.id}"]`);+ if (+ !closestBlockScope ||+ !(closestBlockScope instanceof HTMLElement)+ )+ return;+ const scopeId = closestBlockScope.dataset.hotkeyScope;+ if (!scopeId) return undefined;+ const splitNode = hotkeyScopeTree.get(scopeId);+ if (!splitNode) return undefined;+ return splitNode.hotkeyCommands.get('enter');+ };+ // runCommandByToken(TOKENS.block.focus);+ const command = getEnterCommand();+ if (command) {+ runCommand(command);+ }+ }+ return true;+ }++ openEntity(entity);+ return true;+ },+ displayPriority: 4,+ });registerHotkey({hotkey: ['e'],scopeId: entityHotkeyScope,diff --git a/js/app/packages/app/component/UnifiedListView.tsx b/js/app/packages/app/component/UnifiedListView.tsxindex d999f63fff..d1ab5b4e68 100644--- a/js/app/packages/app/component/UnifiedListView.tsx+++ b/js/app/packages/app/component/UnifiedListView.tsx@@ -200,7 +200,7 @@ export function UnifiedListView(props: UnifiedListViewProps) {const splitContext = useSplitPanelOrThrow();const { isPanelActive, unifiedListContext, panelRef, previewState } =splitContext;- const preview = () => previewState?.[0]?.() ?? false;+ const [preview] = previewState;const {viewsDataStore: viewsData,setViewDataStore,diff --git a/js/app/packages/app/component/split-layout/SplitLayout.tsx b/js/app/packages/app/component/split-layout/SplitLayout.tsxindex dcf717d9fa..807348b0cf 100644--- a/js/app/packages/app/component/split-layout/SplitLayout.tsx+++ b/js/app/packages/app/component/split-layout/SplitLayout.tsx@@ -417,17 +417,16 @@ function SplitPanel(props: SplitPanelProps) {const unifiedListContext = createSoupContext();+ const [previewState, setPreviewState] = createSignal(false);+createNavigationEntityListShortcut({splitName,splitHandle: props.handle,splitHotkeyScope,unifiedListContext,+ previewState: [previewState, setPreviewState],});- // Create ephemeral preview state for unified-list component- const isUnifiedList = createMemo(() => splitName() === 'unified-list');- const [previewState, setPreviewState] = createSignal(false);-return (<SplitPanelContext.Providervalue={{@@ -440,9 +439,7 @@ function SplitPanel(props: SplitPanelProps) {layoutRefs: {},contentOffsetTop,setContentOffsetTop,- previewState: isUnifiedList()- ? [previewState, setPreviewState]- : undefined,+ previewState: [previewState, setPreviewState],}}><SplitContainerdiff --git a/js/app/packages/app/component/split-layout/context.ts b/js/app/packages/app/component/split-layout/context.tsindex e6305663d5..d5326fc386 100644--- a/js/app/packages/app/component/split-layout/context.ts+++ b/js/app/packages/app/component/split-layout/context.ts@@ -27,7 +27,7 @@ export type SplitPanelContextType = {contentOffsetTop: Accessor<number>;setContentOffsetTop: Setter<number>;halfSplitState?: Accessor<HalfSplitState | undefined>;- previewState?: Signal<boolean>;+ previewState: Signal<boolean>;layoutRefs: {headerLeft?: HTMLDivElement;headerRight?: HTMLDivElement;diff --git a/js/app/packages/block-channel/component/Channel.tsx b/js/app/packages/block-channel/component/Channel.tsxindex efb92bc619..f049f729d0 100644--- a/js/app/packages/block-channel/component/Channel.tsx+++ b/js/app/packages/block-channel/component/Channel.tsx@@ -214,7 +214,7 @@ export function Channel(props: { data: Required<ChannelData> }) {}return false;},- hotkeyToken: TOKENS.channel.focusInput,+ hotkeyToken: TOKENS.block.focus,hide: true,});diff --git a/js/app/packages/block-chat/component/Chat.tsx b/js/app/packages/block-chat/component/Chat.tsxindex 960c346dc1..6879b396c6 100644--- a/js/app/packages/block-chat/component/Chat.tsx+++ b/js/app/packages/block-chat/component/Chat.tsx@@ -19,6 +19,7 @@ import {} from '@core/component/AI/util/storage';import { usePaywallState } from '@core/constant/PaywallState';import { registerHotkey } from '@core/hotkey/hotkeys';+import { TOKENS } from '@core/hotkey/tokens';import { createMethodRegistration } from '@core/orchestrator';import {blockElementSignal,@@ -161,6 +162,7 @@ export function Chat(props: { data: ChatData }) {}return false;},+ hotkeyToken: TOKENS.block.focus,hide: true,});}diff --git a/js/app/packages/block-email/component/Email.tsx b/js/app/packages/block-email/component/Email.tsxindex 112c531833..df31d4fe83 100644--- a/js/app/packages/block-email/component/Email.tsx+++ b/js/app/packages/block-email/component/Email.tsx@@ -1,5 +1,6 @@import { useGlobalNotificationSource } from '@app/component/GlobalAppState';import { registerHotkey } from '@core/hotkey/hotkeys';+import { TOKENS } from '@core/hotkey/tokens';import {blockElementSignal,blockHotkeyScopeSignal,@@ -560,6 +561,7 @@ export function Email(props: EmailProps) {}return false;},+ hotkeyToken: TOKENS.block.focus,hide: true,});}diff --git a/js/app/packages/block-md/component/Notebook.tsx b/js/app/packages/block-md/component/Notebook.tsxindex f535d75dd5..069a13a67a 100644--- a/js/app/packages/block-md/component/Notebook.tsx+++ b/js/app/packages/block-md/component/Notebook.tsx@@ -13,6 +13,7 @@ import {ENABLE_PROPERTIES_METADATA,} from '@core/constant/featureFlags';import { registerHotkey } from '@core/hotkey/hotkeys';+import { TOKENS } from '@core/hotkey/tokens';import {blockElementSignal,blockHotkeyScopeSignal,@@ -158,6 +159,7 @@ export function Notebook() {registerHotkey({hotkey: 'enter',scopeId: scopeId(),+ hotkeyToken: TOKENS.block.focus,description: 'Focus Title or Markdown Editor',keyDownHandler: () => {const titleEditor = md.titleEditor;diff --git a/js/app/packages/core/hotkey/tokens.ts b/js/app/packages/core/hotkey/tokens.tsindex 9f047ca471..117aa7bae8 100644--- a/js/app/packages/core/hotkey/tokens.ts+++ b/js/app/packages/core/hotkey/tokens.ts@@ -143,6 +143,7 @@ export const TOKENS = {// sharingblock: {share: 'block.share',+ focus: 'block.focus',},// channel