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: mentions menu usable on mobile (#1625)

Peter Chinman398aa23ee5ce
diff --git a/js/app/packages/app/component/useAppSquishHandlers.ts b/js/app/packages/app/component/useAppSquishHandlers.ts
index 9689abef62..aec87ef720 100644
--- a/js/app/packages/app/component/useAppSquishHandlers.ts
+++ b/js/app/packages/app/component/useAppSquishHandlers.ts
@@ -1,5 +1,8 @@
import { isNativeMobilePlatform } from '@core/mobile/isNativeMobilePlatform';
-import { setVirtualKeyboardVisible } from '@core/mobile/virtualKeyboard';
+import {
+ setVirtualKeyboardHeight,
+ setVirtualKeyboardVisible,
+} from '@core/mobile/virtualKeyboard';
import { isEditableInput } from '@core/util/isEditableInput';
import { isIOS } from '@solid-primitives/platform';
import { onCleanup, onMount } from 'solid-js';
@@ -70,6 +73,7 @@ export function useAppSquishHandlers() {
const handleKeyboardWillShow = (event: VirtualKeyboardEvent) => {
setVirtualKeyboardVisible(true);
+ setVirtualKeyboardHeight(event.detail?.height ?? 0);
const newViewportHeight =
(window.visualViewport?.height ?? 0) - (event.detail?.height ?? 0);
const vh = newViewportHeight * 0.01;
@@ -78,6 +82,7 @@ export function useAppSquishHandlers() {
const handleKeyboardWillHide = () => {
setVirtualKeyboardVisible(false);
+ setVirtualKeyboardHeight(0);
document.documentElement.style.setProperty('--dvh', '1dvh');
};
diff --git a/js/app/packages/core/component/LexicalMarkdown/component/menu/ActionsMenu.tsx b/js/app/packages/core/component/LexicalMarkdown/component/menu/ActionsMenu.tsx
index 8e2b2f86ec..3bfc1874c8 100644
--- a/js/app/packages/core/component/LexicalMarkdown/component/menu/ActionsMenu.tsx
+++ b/js/app/packages/core/component/LexicalMarkdown/component/menu/ActionsMenu.tsx
@@ -31,6 +31,9 @@ false && clickOutside;
false && floatWithSelection;
false && floatWithElement;
+// py-2 on the menu container = 8px top + 8px bottom
+const MENU_DECORATION_HEIGHT = 16;
+
export function ActionsMenuItem(props: {
action: Action;
index: number;
@@ -91,6 +94,14 @@ export function ActionMenu(props: {
const [selectedIndex, setSelectedIndex] = createSignal(0);
let menuRef!: HTMLDivElement;
const [mountSelection, setMountSelection] = createSignal<Selection | null>();
+ const [menuAvailableHeight, setMenuAvailableHeight] = createSignal<
+ number | undefined
+ >(undefined);
+ const contentMaxHeight = () => {
+ const h = menuAvailableHeight();
+ if (h === undefined) return undefined;
+ return Math.max(0, h - MENU_DECORATION_HEIGHT);
+ };
const { isKeypressActive } = useIsKeyPressActive();
const setSelectedIndexFromMouse = (index: number) => {
@@ -253,6 +264,7 @@ export function ActionMenu(props: {
selection: untrack(mountSelection),
reactiveOnContainer: props.editor.getRootElement(),
useBlockBoundary: props.useBlockBoundary,
+ onAvailableHeight: setMenuAvailableHeight,
}
: undefined;
@@ -267,7 +279,17 @@ export function ActionMenu(props: {
ref={menuRef}
>
<div class="relative overflow-hidden ring-1 ring-edge bg-menu shadow-xl py-2">
- {inner()}
+ <div
+ class="overflow-y-auto scrollbar-hidden"
+ style={{
+ 'max-height':
+ contentMaxHeight() !== undefined
+ ? `${contentMaxHeight()}px`
+ : undefined,
+ }}
+ >
+ {inner()}
+ </div>
</div>
<BozzyBracketInnerSibling animOnOpen={true} />
</div>
diff --git a/js/app/packages/core/component/LexicalMarkdown/component/menu/EmojiMenu.tsx b/js/app/packages/core/component/LexicalMarkdown/component/menu/EmojiMenu.tsx
index 9f5da20349..9d48a17ff5 100644
--- a/js/app/packages/core/component/LexicalMarkdown/component/menu/EmojiMenu.tsx
+++ b/js/app/packages/core/component/LexicalMarkdown/component/menu/EmojiMenu.tsx
@@ -27,6 +27,9 @@ import { useMenuKeyboardNavigation } from './useMenuKeyboardNavigation';
false && clickOutside;
false && floatWithSelection;
+// py-2 on the menu container = 8px top + 8px bottom
+const MENU_DECORATION_HEIGHT = 16;
+
export type EmojiMenuProps = {
menu: MenuOperations;
editor: LexicalEditor;
@@ -69,6 +72,14 @@ export function EmojiMenu(props: EmojiMenuProps) {
const [mountSelection, setMountSelection] = createSignal<Selection | null>();
const [selectedIndex, setSelectedIndex] = createSignal(0);
const [virtualHandle, setVirtualHandle] = createSignal<VirtualizerHandle>();
+ const [menuAvailableHeight, setMenuAvailableHeight] = createSignal<
+ number | undefined
+ >(undefined);
+ const contentMaxHeight = () => {
+ const h = menuAvailableHeight();
+ if (h === undefined) return undefined;
+ return Math.min(200, Math.max(0, h - MENU_DECORATION_HEIGHT));
+ };
const { isKeypressActive } = useIsKeyPressActive();
const setSelectedIndexFromMouse = (index: number) => {
@@ -208,6 +219,7 @@ export function EmojiMenu(props: EmojiMenuProps) {
selection: untrack(mountSelection),
reactiveOnContainer: props.editor.getRootElement(),
useBlockBoundary: props.useBlockBoundary,
+ onAvailableHeight: setMenuAvailableHeight,
}}
use:clickOutside={() => {
closeMenu();
@@ -226,7 +238,10 @@ export function EmojiMenu(props: EmojiMenuProps) {
data={emojiOptions()}
ref={setVirtualHandle}
style={{
- height: '200px',
+ height:
+ contentMaxHeight() !== undefined
+ ? `${contentMaxHeight()}px`
+ : '200px',
'max-height': '100%',
width: '100%',
}}
diff --git a/js/app/packages/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.tsx b/js/app/packages/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.tsx
index 3a8177ea0d..44bf3a62b1 100644
--- a/js/app/packages/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.tsx
+++ b/js/app/packages/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.tsx
@@ -44,9 +44,12 @@ import { useMenuKeyboardNavigation } from '../useMenuKeyboardNavigation';
import { useUsersMention } from './hooks/useUsersMention';
import { useEntityMention } from './hooks/useEntityMention';
import { useEmailSearchMention } from './hooks/useEmailSearchMention';
+import { isMobile } from '@core/mobile/isMobile';
const MAX_ITEMS = 8;
const VIRTUAL_ITEM_HEIGHT = 36;
+// Height consumed by ClippedPanel's p-px border (2px) + py-2 padding (16px)
+const PANEL_DECORATION_HEIGHT = 18;
export type MentionsMenuProps = {
editor: LexicalEditor;
@@ -164,7 +167,27 @@ function MentionsMenuInner(props: MentionsMenuProps) {
const [mountSelection, setMountSelection] = createSignal<Selection | null>();
+ // On mobile, combine all sources into a single flat list
+ const mobileAllItems = createLazyMemo((): MentionItem[] => [
+ ...(usersAndGroups() ?? []),
+ ...(docs() ?? []),
+ ...(channels() ?? []),
+ ...(emails() ?? []),
+ ...(dates() ?? []),
+ ]);
+
const bucketConfigs = createLazyMemo((): BucketConfig[] => {
+ if (isMobile()) {
+ return [
+ {
+ id: 'all',
+ label: 'All',
+ getData: mobileAllItems,
+ getFullCount: () => mobileAllItems().length,
+ },
+ ];
+ }
+
const buckets: BucketConfig[] = [
{
id: 'users',
@@ -242,6 +265,9 @@ function MentionsMenuInner(props: MentionsMenuProps) {
if (menuOpen()) {
setMountSelection(document.getSelection());
controller.reset();
+ if (isMobile()) {
+ controller.viewAll('all');
+ }
} else {
setMountSelection(null);
}
@@ -389,6 +415,18 @@ function MentionsMenuInner(props: MentionsMenuProps) {
setMenuOpen(false);
};
+ const [menuAvailableHeight, setMenuAvailableHeight] = createSignal<
+ number | undefined
+ >(undefined);
+
+ // Height available for scrollable content after subtracting ClippedPanel decorations.
+ // Capped at 256px (16rem) to preserve desktop behavior, and floored at 0.
+ const contentMaxHeight = () => {
+ const h = menuAvailableHeight();
+ if (h === undefined) return undefined;
+ return Math.min(256, Math.max(0, h - PANEL_DECORATION_HEIGHT));
+ };
+
const floatWithElementProps = () =>
props.anchor
? {
@@ -403,6 +441,7 @@ function MentionsMenuInner(props: MentionsMenuProps) {
selection: untrack(mountSelection),
reactiveOnContainer: props.editor.getRootElement(),
useBlockBoundary: props.useBlockBoundary,
+ onAvailableHeight: setMenuAvailableHeight,
}
: undefined;
@@ -410,7 +449,7 @@ function MentionsMenuInner(props: MentionsMenuProps) {
<Show when={menuOpen()}>
<ScopedPortal scope={props.portalScope}>
<div
- class="w-96 cursor-default select-none z-modal-content"
+ class="w-96 max-w-[calc(100cqw-1rem-2px)] cursor-default select-none z-modal-content"
ref={(el) => {
floatWithElement(el, floatWithElementProps);
floatWithSelection(el, floatWithSelectionProps);
@@ -464,37 +503,40 @@ function MentionsMenuInner(props: MentionsMenuProps) {
</div>
}
>
- <div class="px-2 pb-2">
- <div class="flex items-center justify-between">
- <span class="text-xs font-medium text-ink-muted">
- {viewAllCategoryLabel()}
- </span>
- <button
- type="button"
- class="text-xs font-medium text-ink-muted hover:text-ink hover:underline flex items-center gap-1"
- onMouseDown={(e) => {
- e.preventDefault();
- e.stopPropagation();
- }}
- onClick={(e) => {
- e.preventDefault();
- e.stopPropagation();
- handleBackToAll();
- }}
- >
- <div class="p-0.5 px-1 -my-2 bg-panel text-ink border border-edge-muted rounded-xs text-xs">
- ←
- </div>
- Back to everything
- </button>
+ <Show when={!isMobile()}>
+ <div class="px-2 pb-2">
+ <div class="flex items-center justify-between">
+ <span class="text-xs font-medium text-ink-muted">
+ {viewAllCategoryLabel()}
+ </span>
+ <button
+ type="button"
+ class="text-xs font-medium text-ink-muted hover:text-ink hover:underline flex items-center gap-1"
+ onMouseDown={(e) => {
+ e.preventDefault();
+ e.stopPropagation();
+ }}
+ onClick={(e) => {
+ e.preventDefault();
+ e.stopPropagation();
+ handleBackToAll();
+ }}
+ >
+ <div class="p-0.5 px-1 -my-2 bg-panel text-ink border border-edge-muted rounded-xs text-xs">
+ ←
+ </div>
+ Back to everything
+ </button>
+ </div>
</div>
- </div>
+ </Show>
<VirtualizedItemList
items={controller.combinedItems()}
selectedIndex={controller.selectedIndex()}
itemAction={itemAction}
setIndex={setSelectedIndexFromMouse}
setOpen={setMenuOpen}
+ maxHeight={contentMaxHeight()}
/>
</Show>
</Show>
@@ -511,6 +553,7 @@ function VirtualizedItemList(props: {
itemAction: (item: MentionItem) => void;
setIndex: (index: number) => void;
setOpen: (open: boolean) => void;
+ maxHeight?: number;
}) {
let scrollContainerRef: HTMLDivElement | undefined;
@@ -534,7 +577,11 @@ function VirtualizedItemList(props: {
return (
<div
ref={scrollContainerRef}
- class="max-h-64 overflow-y-auto scrollbar-hidden"
+ class="overflow-y-auto scrollbar-hidden"
+ style={{
+ 'max-height':
+ props.maxHeight !== undefined ? `${props.maxHeight}px` : '16rem',
+ }}
>
<div
style={{
diff --git a/js/app/packages/core/component/LexicalMarkdown/directive/floatWithElement.ts b/js/app/packages/core/component/LexicalMarkdown/directive/floatWithElement.ts
index b72adbc711..fd882379a5 100644
--- a/js/app/packages/core/component/LexicalMarkdown/directive/floatWithElement.ts
+++ b/js/app/packages/core/component/LexicalMarkdown/directive/floatWithElement.ts
@@ -12,6 +12,7 @@ import {
} from '@floating-ui/dom';
import type { Accessor, JSX } from 'solid-js';
import { createEffect, onCleanup } from 'solid-js';
+import { iosSafePadding } from './iosFloatingMiddleware';
export type FloatWithElementOptions = {
element: () => Element | undefined | null;
@@ -55,15 +56,16 @@ export function floatWithElement(
return;
}
+ const spacing = accessor()?.spacing ?? 8;
const { x, y, middlewareData } = await computePosition(
referenceEl,
floatingEl,
{
placement: 'bottom-start',
middleware: [
- offset(accessor()?.spacing ?? 8),
- flip(),
- shift({ padding: accessor()?.spacing ?? 8, boundary }),
+ offset(spacing),
+ flip({ padding: iosSafePadding(spacing) }),
+ shift({ padding: spacing, boundary }),
hide(),
],
...(accessor()?.floatingOptions ?? {}),
diff --git a/js/app/packages/core/component/LexicalMarkdown/directive/floatWithSelection.ts b/js/app/packages/core/component/LexicalMarkdown/directive/floatWithSelection.ts
index 4b9ea193ef..769b0b862a 100644
--- a/js/app/packages/core/component/LexicalMarkdown/directive/floatWithSelection.ts
+++ b/js/app/packages/core/component/LexicalMarkdown/directive/floatWithSelection.ts
@@ -1,5 +1,4 @@
import { isInBlock } from '@core/block';
-import { isTouchDevice } from '@core/mobile/isTouchDevice';
import { blockElementSignal } from '@core/signal/blockElement';
import { getScrollParent } from '@core/util/scrollParent';
import {
@@ -15,6 +14,7 @@ import {
} from '@floating-ui/dom';
import type { Accessor, JSX } from 'solid-js';
import { createEffect, createSignal, onCleanup, onMount } from 'solid-js';
+import { iosSafePadding, iosSizeMiddleware } from './iosFloatingMiddleware';
const DEFAULT_SPACING = 8;
@@ -37,6 +37,7 @@ type FloatWithSelectionOptions = {
spacing?: number;
floatingOptions?: Partial<ComputePositionConfig>;
moveWithSelection?: boolean;
+ onAvailableHeight?: (height: number) => void;
};
export function floatWithSelection(
@@ -78,19 +79,17 @@ export function floatWithSelection(
if (anchor) {
setCurrentAnchor(anchor);
+ const spacing = accessor()?.spacing ?? DEFAULT_SPACING;
const { placement } = await computePosition(anchor, floatingEl, {
- placement: isTouchDevice() ? 'top-start' : 'bottom-start',
+ placement: 'bottom-start',
middleware: [
- isTouchDevice()
- ? null
- : flip({
- fallbackStrategy: 'initialPlacement',
- fallbackPlacements: ['top-start'],
- boundary,
- padding: accessor()?.spacing ?? DEFAULT_SPACING,
- }),
- offset(accessor()?.spacing ?? DEFAULT_SPACING),
- shift({ padding: accessor()?.spacing ?? DEFAULT_SPACING, boundary }),
+ flip({
+ fallbackPlacements: ['top-start'],
+ boundary,
+ padding: iosSafePadding(spacing),
+ }),
+ offset(spacing),
+ shift({ padding: spacing, boundary }),
hide(),
],
});
@@ -104,14 +103,19 @@ export function floatWithSelection(
let current = currentAnchor();
if (!current || !decidedPlacement) return;
+ const spacing = accessor()?.spacing ?? DEFAULT_SPACING;
+ const onAvailableHeight = accessor()?.onAvailableHeight;
const { x, y, middlewareData } = await computePosition(
current,
floatingEl,
{
placement: decidedPlacement,
middleware: [
- offset(accessor()?.spacing ?? DEFAULT_SPACING),
- shift({ padding: accessor()?.spacing ?? DEFAULT_SPACING, boundary }),
+ offset(spacing),
+ shift({ padding: iosSafePadding(spacing), boundary }),
+ ...(onAvailableHeight
+ ? [iosSizeMiddleware(spacing, onAvailableHeight)]
+ : []),
hide(),
],
}
diff --git a/js/app/packages/core/component/LexicalMarkdown/directive/iosFloatingMiddleware.ts b/js/app/packages/core/component/LexicalMarkdown/directive/iosFloatingMiddleware.ts
new file mode 100644
index 0000000000..ff8544e7d7
--- /dev/null
+++ b/js/app/packages/core/component/LexicalMarkdown/directive/iosFloatingMiddleware.ts
@@ -0,0 +1,54 @@
+import { getSafeAreaInset } from '@core/mobile/safeAreaInsets';
+import { virtualKeyboardHeight } from '@core/mobile/virtualKeyboard';
+import { size, type Placement } from '@floating-ui/dom';
+import { isIOS } from '@solid-primitives/platform';
+
+/**
+ * Returns iOS-aware safe-padding, incorporating the safe area insets and virtual keyboard height.
+ */
+export function iosSafePadding(
+ spacing: number
+): number | { top: number; right: number; bottom: number; left: number } {
+ if (!isIOS) return spacing;
+ return {
+ top: spacing + getSafeAreaInset('top'),
+ right: spacing + getSafeAreaInset('right'),
+ bottom: spacing + (virtualKeyboardHeight() ?? getSafeAreaInset('bottom')),
+ left: spacing + getSafeAreaInset('left'),
+ };
+}
+
+/**
+ * Returns a size middleware that accounts for the iOS keyboard height and safe
+ * area insets when computing available height, and calls onAvailableHeight with
+ * the usable height.
+ * (which can be used to, e.g. set a signal with available height)
+ */
+export function iosSizeMiddleware(
+ spacing: number,
+ onAvailableHeight: (height: number) => void
+) {
+ return size({
+ padding: spacing,
+ apply({
+ availableHeight,
+ elements,
+ placement,
+ }: {
+ availableHeight: number;
+ elements: { floating: HTMLElement };
+ placement: Placement;
+ }) {
+ const safeAreaTop = placement.startsWith('top')
+ ? getSafeAreaInset('top')
+ : 0;
+ const kbHeight =
+ isIOS && placement.startsWith('bottom') ? virtualKeyboardHeight() : 0;
+ const h = Math.max(0, availableHeight - safeAreaTop - kbHeight);
+ Object.assign(elements.floating.style, {
+ maxHeight: `${h}px`,
+ });
+ onAvailableHeight(h - spacing);
+ },
+ });
+}
diff --git a/js/app/packages/core/mobile/safeAreaInsets.ts b/js/app/packages/core/mobile/safeAreaInsets.ts
new file mode 100644
index 0000000000..2c13bc7b5f
--- /dev/null
+++ b/js/app/packages/core/mobile/safeAreaInsets.ts
@@ -0,0 +1,31 @@
+import { isIOS } from '@solid-primitives/platform';
+
+type SafeAreaInsetSide = 'top' | 'right' | 'bottom' | 'left';
+
+const cache: Record<SafeAreaInsetSide, number | null> = {
+ top: null,
+ right: null,
+ bottom: null,
+ left: null,
+};
+
+window.addEventListener('resize', () => {
+ cache.top = null;
+ cache.right = null;
+ cache.bottom = null;
+ cache.left = null;
+});
+
+export function getSafeAreaInset(side: SafeAreaInsetSide): number {
+ if (!isIOS) return 0;
+ if (cache[side] !== null) return cache[side];
+ const el = document.createElement('div');
+ el.style.setProperty(`padding-${side}`, `env(safe-area-inset-${side}, 0px)`);
+ document.body.appendChild(el);
+ cache[side] =
+ Number.parseFloat(
+ getComputedStyle(el).getPropertyValue(`padding-${side}`)
+ ) || 0;
+ el.remove();
+ return cache[side];
+}
diff --git a/js/app/packages/core/mobile/virtualKeyboard.ts b/js/app/packages/core/mobile/virtualKeyboard.ts
index bb5f22c332..4a832e53fc 100644
--- a/js/app/packages/core/mobile/virtualKeyboard.ts
+++ b/js/app/packages/core/mobile/virtualKeyboard.ts
@@ -2,3 +2,6 @@ import { createSignal } from 'solid-js';
export const [virtualKeyboardVisible, setVirtualKeyboardVisible] =
createSignal(false);
+
+export const [virtualKeyboardHeight, setVirtualKeyboardHeight] =
+ createSignal(0);