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.

chore: rationalize mobile and touch checks (#1121)

Peter Chinman7627559f7398
diff --git a/js/app/packages/app/component/Layout.tsx b/js/app/packages/app/component/Layout.tsx
index d73aca6aa4..0f8bcdbefe 100644
--- a/js/app/packages/app/component/Layout.tsx
+++ b/js/app/packages/app/component/Layout.tsx
@@ -2,7 +2,6 @@ import { mountGlobalFocusListener } from '@app/signal/focus';
import { useIsAuthenticated } from '@core/auth';
import { Resize } from '@core/component/Resize';
import { usePaywallState } from '@core/constant/PaywallState';
-import { isMobileWidth } from '@core/mobile/mobileWidth';
import {
LAYOUT_CONTEXT_ID,
setPersistedLayoutSizes,
@@ -64,13 +63,6 @@ export function Layout(props: RouteSectionProps) {
}
});
- // This effect handles transitioning from desktop to mobile width to ensure sidebar state is properly reset
- createEffect((_prevMobileWidth: boolean | undefined) => {
- const currentMobileWidth = isMobileWidth();
- // Note: No longer need to reset resizable context since we use simple boolean signal
- return currentMobileWidth;
- }, isMobileWidth());
-
// This effect is to handle moving from unauthenticated to authenticated
createEffect((prevAuth: boolean | undefined) => {
const currentAuth = isAuthenticated();
diff --git a/js/app/packages/app/component/UnifiedListEmptyState.tsx b/js/app/packages/app/component/UnifiedListEmptyState.tsx
index efbe13c5ba..54db0384a4 100644
--- a/js/app/packages/app/component/UnifiedListEmptyState.tsx
+++ b/js/app/packages/app/component/UnifiedListEmptyState.tsx
@@ -3,8 +3,7 @@ import { useMaybeBlockId, useMaybeBlockName } from '@core/block';
import { fileSelector } from '@core/directive/fileSelector';
import { folderSelector } from '@core/directive/folderSelector';
import { useEmailLinksStatus } from '@core/email-link';
-import { isTouchDevice } from '@core/mobile/isTouchDevice';
-import { isMobileWidth } from '@core/mobile/mobileWidth';
+import { isMobile } from '@core/mobile/isMobile';
import type { ViewId } from '@core/types/view';
import { handleFolderSelect } from '@core/util/upload';
import { createMemo, Match, Show, Switch } from 'solid-js';
@@ -134,9 +133,7 @@ export function EmptyStateInner(props: EmptyStateInnerProps) {
</div>
)}
</Show>
- <Show
- when={props.showDropZone && !(isTouchDevice() && isMobileWidth())}
- >
+ <Show when={props.showDropZone && !isMobile()}>
<div class="drop-zone flex flex-col items-center justify-center w-full py-8 border border-dashed border-edge-muted bg-hover">
<p class="text-ink-muted">Drag & drop files and folders here</p>
<p class="text-ink-muted">
diff --git a/js/app/packages/app/component/UnifiedListView.tsx b/js/app/packages/app/component/UnifiedListView.tsx
index c8124d8c54..2d19dc10bc 100644
--- a/js/app/packages/app/component/UnifiedListView.tsx
+++ b/js/app/packages/app/component/UnifiedListView.tsx
@@ -34,8 +34,8 @@ import {
import { useEmailLinksStatus } from '@core/email-link';
import { registerHotkey } from '@core/hotkey/hotkeys';
import { TOKENS } from '@core/hotkey/tokens';
+import { isMobile } from '@core/mobile/isMobile';
import { isTouchDevice } from '@core/mobile/isTouchDevice';
-import { isMobileWidth } from '@core/mobile/mobileWidth';
import { useCombinedRecipients } from '@core/signal/useCombinedRecipient';
import { arrayEquals } from '@core/util/compareUtils';
import { debouncedDependent } from '@core/util/debounce';
@@ -2014,7 +2014,7 @@ export function UnifiedListView(props: UnifiedListViewProps) {
<Show when={contextAndModalState.selectedEntity}>
{(selectedEntity) => (
<ContextMenuContent mobileFullScreen>
- <Show when={isTouchDevice() && isMobileWidth()}>
+ <Show when={isMobile()}>
<Entity
entity={selectedEntity()}
timestamp={
diff --git a/js/app/packages/app/component/dock/Dock.tsx b/js/app/packages/app/component/dock/Dock.tsx
index 3e6907f8fa..3b964bd691 100644
--- a/js/app/packages/app/component/dock/Dock.tsx
+++ b/js/app/packages/app/component/dock/Dock.tsx
@@ -8,7 +8,6 @@ import IconPower from '@phosphor-icons/core/regular/power.svg';
import MacroCreateIcon from '@macro-icons/macro-create-b.svg';
import { globalSplitManager } from '@app/signal/splitLayout';
import { ClippedPanel } from '@core/component/ClippedPanel';
-import { isMobileWidth } from '@core/mobile/mobileWidth';
import { PresentModeGlitch } from './PresentModeGlitch';
import { withAnalytics } from '@coparse/analytics';
import SplitIcon from '@macro-icons/new-split.svg';
@@ -26,6 +25,7 @@ import { playSound } from '@app/util/sound';
import { QuickAccess } from './QuickAccess';
import { Button } from '@ui/components/Button';
import { LabelAndHotKey } from '@core/component/Tooltip';
+import { isMobile } from '@core/mobile/isMobile';
export function Dock() {
const activeSplitId = createMemo(() => globalSplitManager()?.activeSplitId());
@@ -225,7 +225,10 @@ export function Dock() {
</div>
</div>
- <Show when={!isMobileWidth()}>
+ <Show
+ when={!isMobile()}
+ fallback={<div></div>}
+ >
<div style={{
'border-top': '1px solid var(--edge-muted)',
'color': 'var(--ink-extra-muted)',
@@ -250,10 +253,6 @@ export function Dock() {
</div>
</Show>
- <Show when={isMobileWidth()}>
- <div></div>
- </Show>
-
<div style={{
'border-left': '1px solid var(--color-edge-muted)',
'grid-auto-columns': 'min-content',
diff --git a/js/app/packages/app/component/settings/Settings.tsx b/js/app/packages/app/component/settings/Settings.tsx
index 420448cdf6..5bc3d978a8 100644
--- a/js/app/packages/app/component/settings/Settings.tsx
+++ b/js/app/packages/app/component/settings/Settings.tsx
@@ -17,8 +17,7 @@ import { Tabs } from '@kobalte/core/tabs';
import { Account } from './Account';
import { Inbox } from './Inbox';
import { Shortcuts } from './Shortcuts';
-import { isTouchDevice } from '@core/mobile/isTouchDevice';
-import { isMobileWidth } from '@core/mobile/mobileWidth';
+import { isMobile } from '@core/mobile/isMobile';
import { registerHotkey, useHotkeyDOMScope } from '@core/hotkey/hotkeys';
import type { ValidHotkey } from '@core/hotkey/types';
@@ -240,7 +239,7 @@ export function SettingsPanel(props: SettingsPanelProps) {
{/* Header with tabs */}
<div class="relative isolate shrink-0 border-b border-edge-muted">
<div class="flex items-center px-2">
- <Show when={!isTouchDevice() || !isMobileWidth()}>
+ <Show when={!isMobile()}>
<DeprecatedIconButton
icon={CloseIcon}
onClick={closeSettings}
@@ -321,7 +320,7 @@ export function SettingsPanel(props: SettingsPanelProps) {
<div class="flex-1" />
- <Show when={!isTouchDevice() || !isMobileWidth()}>
+ <Show when={!isMobile()}>
<DeprecatedIconButton
icon={spotlight() ? ContractIcon : ExpandIcon}
onClick={() => setSpotlight(!spotlight())}
diff --git a/js/app/packages/app/component/settings/ShortcutsHelper.tsx b/js/app/packages/app/component/settings/ShortcutsHelper.tsx
index f4e7915bc2..76bd06f653 100644
--- a/js/app/packages/app/component/settings/ShortcutsHelper.tsx
+++ b/js/app/packages/app/component/settings/ShortcutsHelper.tsx
@@ -1,6 +1,5 @@
import { useSettingsState } from '@core/constant/SettingsState';
import { isTouchDevice } from '@core/mobile/isTouchDevice';
-import { isMobileWidth } from '@core/mobile/mobileWidth';
import KeyboardIcon from '@icon/regular/keyboard.svg';
import CloseIcon from '@icon/regular/x.svg';
import { makePersisted } from '@solid-primitives/storage';
@@ -24,7 +23,7 @@ export function ShortcutsHelper() {
};
const shouldShow = () =>
- showShortcutsHelper() && !isTouchDevice() && !isMobileWidth();
+ showShortcutsHelper() && !isTouchDevice();
return (
<Show when={shouldShow()}>
diff --git a/js/app/packages/app/component/split-layout/components/SplitContainer.tsx b/js/app/packages/app/component/split-layout/components/SplitContainer.tsx
index c07a9a2a6f..166ac05e7b 100644
--- a/js/app/packages/app/component/split-layout/components/SplitContainer.tsx
+++ b/js/app/packages/app/component/split-layout/components/SplitContainer.tsx
@@ -1,7 +1,5 @@
import MacroJump from '@app/component/MacroJump';
import { MobileDock } from '@app/component/mobile/MobileDock';
-import { isTouchDevice } from '@core/mobile/isTouchDevice';
-import { isMobileWidth } from '@core/mobile/mobileWidth';
import { createElementSize } from '@solid-primitives/resize-observer';
import {
type Accessor,
@@ -21,6 +19,7 @@ import { SplitToolbar } from './SplitToolbar';
import { virtualKeyboardVisible } from '@core/mobile/virtualKeyboard';
import { ClippedPanel } from '@core/component/ClippedPanel';
import { globalSplitManager } from '@app/signal/splitLayout';
+import { isMobile } from '@core/mobile/isMobile';
export function SplitContainer(
props: ParentProps<{
@@ -111,13 +110,7 @@ export function SplitContainer(
<Show when={panel.handle.isSpotLight()}>
<MacroJump tabbableParent={ref} />
</Show>
- <Show
- when={
- isTouchDevice() &&
- isMobileWidth() &&
- !virtualKeyboardVisible()
- }
- >
+ <Show when={isMobile() && !virtualKeyboardVisible()}>
<MobileDock />
</Show>
</div>
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 7130c1cb74..1bc2850044 100644
--- a/js/app/packages/app/component/split-layout/components/SplitHeader.tsx
+++ b/js/app/packages/app/component/split-layout/components/SplitHeader.tsx
@@ -5,8 +5,8 @@ import {
ENABLE_PROJECT_VIEW_PREVIEW,
} from '@core/constant/featureFlags';
import { TOKENS } from '@core/hotkey/tokens';
+import { isMobile } from '@core/mobile/isMobile';
import { isTouchDevice } from '@core/mobile/isTouchDevice';
-import { isMobileWidth } from '@core/mobile/mobileWidth';
import CollapseIcon from '@icon/regular/arrows-in.svg';
import ExpandIcon from '@icon/regular/arrows-out.svg';
import CaretLeft from '@icon/regular/caret-left.svg';
@@ -236,7 +236,7 @@ export function SplitHeader(props: { ref: Setter<HTMLDivElement | null> }) {
{/* space filler */}
<div class="h-full grow-1" />
- <Show when={!isTouchDevice() || !isMobileWidth()}>
+ <Show when={!isMobile()}>
<div
class="min-w-4 h-full shrink-0"
ref={(ref) => {
diff --git a/js/app/packages/app/component/split-layout/layout.ts b/js/app/packages/app/component/split-layout/layout.ts
index 9ad2bc773a..62444b70a1 100644
--- a/js/app/packages/app/component/split-layout/layout.ts
+++ b/js/app/packages/app/component/split-layout/layout.ts
@@ -2,8 +2,7 @@ import { useContext } from 'solid-js';
import { globalSplitManager } from '../../signal/splitLayout';
import { SplitPanelContext } from './context';
import type { ReferredFrom, SplitContent } from './layoutManager';
-import { isMobileWidth } from '@core/mobile/mobileWidth';
-import { isTouchDevice } from '@core/mobile/isTouchDevice';
+import { isMobile } from '@core/mobile/isMobile';
export function useSplitLayout() {
const splitPanelContext = useContext(SplitPanelContext);
@@ -79,7 +78,7 @@ export function useSplitLayout() {
referredFrom: ReferredFrom = null
) {
// On mobile, replace instead of inserting a new split
- if (isMobileWidth() && isTouchDevice()) {
+ if (isMobile()) {
return replaceSplit({ content, referredFrom });
}
diff --git a/js/app/packages/block-channel/component/BaseInput.tsx b/js/app/packages/block-channel/component/BaseInput.tsx
index 51d8a8d442..8f2cb4be5c 100644
--- a/js/app/packages/block-channel/component/BaseInput.tsx
+++ b/js/app/packages/block-channel/component/BaseInput.tsx
@@ -20,7 +20,6 @@ import { setEditorStateFromMarkdown } from '@core/component/LexicalMarkdown/util
import { fileFolderDrop } from '@core/directive/fileFolderDrop';
import { TOKENS } from '@core/hotkey/tokens';
import { isTouchDevice } from '@core/mobile/isTouchDevice';
-import { isMobileWidth } from '@core/mobile/mobileWidth';
import {
type InputAttachment,
isStaticAttachmentType,
@@ -66,6 +65,7 @@ import { FormatRibbon } from './FormatRibbon';
import { useChannelMarkdownArea } from './MarkdownArea';
import { TaskPreviewPanel } from './TaskPreviewPanel';
import { useUserId } from '@core/context/user';
+import { isMobile } from '@core/mobile/isMobile';
false && fileFolderDrop;
@@ -241,7 +241,7 @@ export function BaseInput(props: BaseInputProps) {
onMount(() => {
attachFn(containerRef);
- if (!isTouchDevice() && !isMobileWidth()) {
+ if (!isTouchDevice()) {
setTimeout(() => {
if (
props.autoFocusOnMount === true ||
@@ -306,7 +306,7 @@ export function BaseInput(props: BaseInputProps) {
// Focus when external shouldFocus signal is set to true
createEffect(() => {
if (props.shouldFocus) {
- if (!isMobileWidth()) {
+ if (!isMobile()) {
requestAnimationFrame(() => {
focusMarkdownArea();
props.clearShouldFocus?.();
@@ -501,7 +501,7 @@ export function BaseInput(props: BaseInputProps) {
<MarkdownArea
placeholder={props.placeholder}
onEnter={
- isMobileWidth()
+ isMobile()
? (_e) => false
: (_e) => {
if (hasPendingAttachments() || isPendingSend()) {
diff --git a/js/app/packages/block-channel/component/Message/EditMessageInput.tsx b/js/app/packages/block-channel/component/Message/EditMessageInput.tsx
index e8330d0841..bb2ca37675 100644
--- a/js/app/packages/block-channel/component/Message/EditMessageInput.tsx
+++ b/js/app/packages/block-channel/component/Message/EditMessageInput.tsx
@@ -1,5 +1,4 @@
import { DeprecatedTextButton } from '@core/component/DeprecatedTextButton';
-import { isMobileWidth } from '@core/mobile/mobileWidth';
import FormatIcon from '@icon/regular/text-aa.svg';
import Check from '@phosphor-icons/core/regular/check.svg?component-solid';
import XIcon from '@phosphor-icons/core/regular/x.svg?component-solid';
@@ -7,6 +6,7 @@ import { createSignal, onCleanup, onMount, type Setter, Show } from 'solid-js';
import { ActionButton } from '../ActionButton';
import { FormatRibbon } from '../FormatRibbon';
import { useChannelMarkdownArea } from '../MarkdownArea';
+import { isMobile } from '@core/mobile/isMobile';
export function EditMessageInput(props: {
setEditing: Setter<boolean>;
@@ -56,7 +56,7 @@ export function EditMessageInput(props: {
<MarkdownArea
initialValue={originalContent}
onEnter={(e: KeyboardEvent) => {
- if (isMobileWidth()) return false;
+ if (isMobile()) return false;
e.preventDefault();
const currentContent = markdownState();
if (
diff --git a/js/app/packages/block-channel/component/Message/MessageContainer.tsx b/js/app/packages/block-channel/component/Message/MessageContainer.tsx
index 2faa953698..82aa6d2d3d 100644
--- a/js/app/packages/block-channel/component/Message/MessageContainer.tsx
+++ b/js/app/packages/block-channel/component/Message/MessageContainer.tsx
@@ -13,8 +13,8 @@ import {
} from '@core/component/Menu';
import { Message as MessageComponent } from '@core/component/Message';
import { TOKENS } from '@core/hotkey/tokens';
+import { isMobile } from '@core/mobile/isMobile';
import { isTouchDevice } from '@core/mobile/isTouchDevice';
-import { isMobileWidth } from '@core/mobile/mobileWidth';
import {
isStaticAttachmentType,
STATIC_IMAGE,
@@ -643,12 +643,12 @@ export function MessageContainer(props: MessageProps) {
handleClose={() => {
setReactionSearchOpen(false);
}}
- fullWidth={isTouchDevice() && isMobileWidth()}
+ fullWidth={isMobile()}
insideMenu={true}
/>
</Match>
</Switch>
- <Show when={isTouchDevice() && isMobileWidth()}>
+ <Show when={isMobile()}>
<ContextMenu.Item class="mt-4 shrink-1 overflow-y-scroll overflow-x-hidden">
<MessageComponent
focused={props.isFocused}
diff --git a/js/app/packages/block-email/component/BaseInput.tsx b/js/app/packages/block-email/component/BaseInput.tsx
index 320257326c..f7a04d7a39 100644
--- a/js/app/packages/block-email/component/BaseInput.tsx
+++ b/js/app/packages/block-email/component/BaseInput.tsx
@@ -21,7 +21,6 @@ import { Tooltip } from '@core/component/Tooltip';
import { fileFolderDrop } from '@core/directive/fileFolderDrop';
import { observedSize } from '@core/directive/observedSize';
import { TOKENS } from '@core/hotkey/tokens';
-import { isMobileWidth } from '@core/mobile/mobileWidth';
import { trackMention } from '@core/signal/mention';
import { tryMacroId, useDisplayName } from '@core/user';
import { handleFileFolderDrop } from '@core/util/upload';
@@ -102,6 +101,7 @@ import {
import { EmailAttachmentPill } from '@block-email/component/AttachmentPill';
import type { DraftFormAttachment } from '@block-email/component/createEmailFormState';
import { plural } from '@core/util/string';
+import { isMobile } from '@core/mobile/isMobile';
false && fileFolderDrop;
false && fileSelector;
@@ -824,7 +824,7 @@ export function BaseInput(props: {
// Focus when external shouldFocus signal is set to true
createEffect(() => {
if (form().shouldFocusInput()) {
- if (!isMobileWidth()) {
+ if (!isMobile()) {
requestAnimationFrame(() => {
editor()?.focus();
form().setShouldFocusInput(false);
diff --git a/js/app/packages/block-md/component/MarkdownPopup.tsx b/js/app/packages/block-md/component/MarkdownPopup.tsx
index c72b0af5b4..7c841eb2eb 100644
--- a/js/app/packages/block-md/component/MarkdownPopup.tsx
+++ b/js/app/packages/block-md/component/MarkdownPopup.tsx
@@ -33,8 +33,6 @@ import {
} from '@core/component/LexicalMarkdown/plugins/checkbox-to-task';
import { toast } from '@core/component/Toast/Toast';
import { ScopedPortal } from '@core/component/ScopedPortal';
-import { isTouchDevice } from '@core/mobile/isTouchDevice';
-import { isMobileWidth } from '@core/mobile/mobileWidth';
import { blockElementSignal } from '@core/signal/blockElement';
import { blockMetadataSignal } from '@core/signal/load';
import { useCanComment, useCanEdit } from '@core/signal/permissions';
@@ -72,6 +70,7 @@ import {
useContext,
} from 'solid-js';
import { FormatTools } from './FormatTools';
+import { isMobile } from '@core/mobile/isMobile';
const MENU_ID = 'markdown-popup';
@@ -445,13 +444,7 @@ export function MarkdownPopup(props: {
}}
/>
</Show>
- <Show
- when={
- !isMobileWidth() &&
- !isTouchDevice() &&
- (canEdit() || canComment())
- }
- >
+ <Show when={!isMobile() && (canEdit() || canComment())}>
<FormatTools withinPopup />
</Show>
<Show when={shouldShowCheckboxToTaskButton()}>
diff --git a/js/app/packages/core/component/AI/component/AIChatEmptyState.tsx b/js/app/packages/core/component/AI/component/AIChatEmptyState.tsx
index 80a88ac809..b60165909e 100644
--- a/js/app/packages/core/component/AI/component/AIChatEmptyState.tsx
+++ b/js/app/packages/core/component/AI/component/AIChatEmptyState.tsx
@@ -1,13 +1,13 @@
import { modifierMap } from '@core/component/Hotkey';
-import { isMobileWidth } from '@core/mobile/mobileWidth';
import { Show } from 'solid-js';
import { useOpenInstructionsMd } from '../util/instructions';
+import { isMobile } from '@core/mobile/isMobile';
export function AiChatEmptyState() {
const openInstructions = useOpenInstructionsMd();
return (
<div class="relative p-2 border border-edge-muted bg-dialog text-sm flex flex-col gap-2 text-ink">
- <Show when={!isMobileWidth()}>
+ <Show when={!isMobile()}>
<div class="grid justify-start grid-cols-[max-content_auto] gap-y-1 grid-template items-center">
<span class="p-1 bg-accent text-panel mr-2 text-center">@</span>
<span>To attach, files, emails, and channel</span>
diff --git a/js/app/packages/core/component/AI/component/input/useChatMarkdownArea.tsx b/js/app/packages/core/component/AI/component/input/useChatMarkdownArea.tsx
index 60db6e7340..68c7f2ac7e 100644
--- a/js/app/packages/core/component/AI/component/input/useChatMarkdownArea.tsx
+++ b/js/app/packages/core/component/AI/component/input/useChatMarkdownArea.tsx
@@ -46,7 +46,7 @@ import { shortcutBadgeStyles } from '@core/component/Themes';
import { toast } from '@core/component/Toast/Toast';
import { TOKENS } from '@core/hotkey/tokens';
import { getPrettyHotkeyStringByToken } from '@core/hotkey/utils';
-import { isMobileWidth } from '@core/mobile/mobileWidth';
+import { isMobile } from '@core/mobile/isMobile';
import type { IOrganizationUser } from '@core/user';
import { handleFileFolderDrop } from '@core/util/upload';
import { $isDocumentMentionNode } from '@lexical-core';
@@ -270,7 +270,7 @@ function MarkdownArea(
} else {
initializeEditorEmpty(editor);
}
- if (!isMobileWidth() && !props.dontFocusOnMount) {
+ if (!isMobile() && !props.dontFocusOnMount) {
editor.focus();
}
};
diff --git a/js/app/packages/core/component/DeprecatedIconButton.tsx b/js/app/packages/core/component/DeprecatedIconButton.tsx
index c7ae57b656..b3466c848f 100644
--- a/js/app/packages/core/component/DeprecatedIconButton.tsx
+++ b/js/app/packages/core/component/DeprecatedIconButton.tsx
@@ -1,5 +1,4 @@
import type { HotkeyToken } from '@core/hotkey/tokens';
-import { isMobileWidth } from '@core/mobile/mobileWidth';
import { onKeyDownClick, onKeyUpClick } from '@core/util/click';
import CaretDown from '@phosphor-icons/core/regular/caret-down.svg';
import {
@@ -188,10 +187,7 @@ export function DeprecatedIconButton(props: IconButtonProps) {
<Show when={props.showShortcut && primaryHotkeyToken()}>
{(token) => {
return (
- <div
- class="absolute bottom-[-0.5px] right-[-0.5px] text-[7.5px] uppercase pointer-events-none font-semibold"
- classList={{ invisible: isMobileWidth() }}
- >
+ <div class="absolute bottom-[-0.5px] right-[-0.5px] text-[7.5px] uppercase pointer-events-none font-semibold mobile-width:invisible">
<BasicHotkey token={token()} />
</div>
);
diff --git a/js/app/packages/core/component/ImageGalleryPreview.tsx b/js/app/packages/core/component/ImageGalleryPreview.tsx
index 758a9c2ef5..54be86ac42 100644
--- a/js/app/packages/core/component/ImageGalleryPreview.tsx
+++ b/js/app/packages/core/component/ImageGalleryPreview.tsx
@@ -1,7 +1,7 @@
import { SERVER_HOSTS } from '@core/constant/servers';
import * as stackingContext from '@core/constant/stackingContext';
+import { isMobile } from '@core/mobile/isMobile';
import { isTouchDevice } from '@core/mobile/isTouchDevice';
-import { isMobileWidth } from '@core/mobile/mobileWidth';
import ExpandIcon from '@icon/regular/arrows-out-simple.svg';
import ChevronLeftIcon from '@icon/regular/caret-left.svg';
import ChevronRightIcon from '@icon/regular/caret-right.svg';
@@ -97,13 +97,13 @@ export const ImageGalleryPreview: Component<ImageGalleryPreviewProps> = (
};
const handleTouchStart = (e: TouchEvent) => {
- if (!isMobileWidth() || !isTouchDevice()) return;
+ if (!isMobile()) return;
setTouchStartX(e.touches[0].clientX);
setIsSwiping(false);
};
const handleTouchMove = (e: TouchEvent) => {
- if (!isMobileWidth() || !isTouchDevice()) return;
+ if (!isMobile()) return;
setTouchEndX(e.touches[0].clientX);
const diffX = Math.abs(touchStartX() - e.touches[0].clientX);
@@ -113,7 +113,7 @@ export const ImageGalleryPreview: Component<ImageGalleryPreviewProps> = (
};
const handleTouchEnd = () => {
- if (!isMobileWidth() || !isTouchDevice() || !isSwiping()) return;
+ if (!isMobile() || !isSwiping()) return;
const swipeThreshold = 50;
const diff = touchStartX() - touchEndX();
@@ -172,7 +172,7 @@ export const ImageGalleryPreview: Component<ImageGalleryPreviewProps> = (
};
const handleMouseMove = () => {
- if (isMobileWidth() || isTouchDevice()) return;
+ if (isTouchDevice()) return;
setIsToolbarVisible(true);
@@ -358,7 +358,7 @@ export const ImageGalleryPreview: Component<ImageGalleryPreviewProps> = (
window.addEventListener('keydown', handleKeyDown);
- if (!isMobileWidth() && !isTouchDevice()) {
+ if (!isMobile()) {
setTimeout(() => {
window.addEventListener('mousemove', handleMouseMove);
}, 500);
@@ -388,7 +388,7 @@ export const ImageGalleryPreview: Component<ImageGalleryPreviewProps> = (
}
};
- if (isMobileWidth() && isTouchDevice()) {
+ if (isMobile()) {
image.addEventListener('touchstart', handleTouchStartWrapper, {
passive: true,
});
@@ -411,7 +411,7 @@ export const ImageGalleryPreview: Component<ImageGalleryPreviewProps> = (
clearTimeout(hideToolbarTimeout);
}
- if (isMobileWidth() && isTouchDevice()) {
+ if (isMobile()) {
image.removeEventListener('touchstart', handleTouchStartWrapper);
image.removeEventListener('touchmove', handleTouchMoveWrapper);
image.removeEventListener('touchend', handleTouchEndWrapper);
@@ -525,10 +525,9 @@ export const ImageGalleryPreview: Component<ImageGalleryPreviewProps> = (
<div
class="absolute top-4 right-4 bg-dialog backdrop-blur-sm rounded-lg border border-edge p-1 flex flex-row items-center gap-1 shadow-md transition-opacity duration-300"
classList={{
- 'opacity-100':
- isMobileWidth() || isTouchDevice() || isToolbarVisible(),
+ 'opacity-100': isMobile() || isToolbarVisible(),
'opacity-0 pointer-events-none':
- !isMobileWidth() && !isTouchDevice() && !isToolbarVisible(),
+ !isMobile() && !isToolbarVisible(),
}}
style={{ 'z-index': stackingContext.zModal + 1 }}
>
@@ -555,18 +554,15 @@ export const ImageGalleryPreview: Component<ImageGalleryPreviewProps> = (
</div>
{/* Navigation arrows */}
- <Show when={!isMobileWidth() || !isTouchDevice()}>
+ <Show when={!isMobile()}>
<Show when={props.images.length > 1}>
<button
class="absolute left-4 top-1/2 -translate-y-1/2 bg-dialog backdrop-blur-sm rounded-lg border border-edge p-2 shadow-md hover:bg-button transition-opacity duration-300"
classList={{
hidden: !hasPrevious(),
- 'opacity-100':
- isMobileWidth() || isTouchDevice() || isToolbarVisible(),
+ 'opacity-100': isTouchDevice() || isToolbarVisible(),
'opacity-0 pointer-events-none':
- !isMobileWidth() &&
- !isTouchDevice() &&
- !isToolbarVisible(),
+ !isTouchDevice() && !isToolbarVisible(),
}}
style={{ 'z-index': stackingContext.zModal + 1 }}
onClick={navigatePrevious}
@@ -574,19 +570,13 @@ export const ImageGalleryPreview: Component<ImageGalleryPreviewProps> = (
>
<ChevronLeftIcon class="w-5 h-5 text-ink" />
</button>
- </Show>
-
- <Show when={props.images.length > 1}>
<button
class="absolute right-4 top-1/2 -translate-y-1/2 bg-dialog backdrop-blur-sm rounded-lg border border-edge p-2 shadow-md hover:bg-button transition-opacity duration-300"
classList={{
hidden: !hasNext(),
- 'opacity-100':
- isMobileWidth() || isTouchDevice() || isToolbarVisible(),
+ 'opacity-100': isTouchDevice() || isToolbarVisible(),
'opacity-0 pointer-events-none':
- !isMobileWidth() &&
- !isTouchDevice() &&
- !isToolbarVisible(),
+ !isTouchDevice() && !isToolbarVisible(),
}}
style={{ 'z-index': stackingContext.zModal + 1 }}
onClick={navigateNext}
@@ -602,10 +592,9 @@ export const ImageGalleryPreview: Component<ImageGalleryPreviewProps> = (
<div
class="absolute top-4 left-4 bg-dialog backdrop-blur-sm rounded-lg border border-edge px-3 py-1.5 shadow-md transition-opacity duration-300"
classList={{
- 'opacity-100':
- isMobileWidth() || isTouchDevice() || isToolbarVisible(),
+ 'opacity-100': isTouchDevice() || isToolbarVisible(),
'opacity-0 pointer-events-none':
- !isMobileWidth() && !isTouchDevice() && !isToolbarVisible(),
+ !isTouchDevice() && !isToolbarVisible(),
}}
style={{ 'z-index': stackingContext.zModal + 1 }}
>
diff --git a/js/app/packages/core/component/ImagePreview.tsx b/js/app/packages/core/component/ImagePreview.tsx
index d18a37edef..23f99a5103 100644
--- a/js/app/packages/core/component/ImagePreview.tsx
+++ b/js/app/packages/core/component/ImagePreview.tsx
@@ -1,7 +1,6 @@
import { SERVER_HOSTS } from '@core/constant/servers';
import * as stackingContext from '@core/constant/stackingContext';
import { isTouchDevice } from '@core/mobile/isTouchDevice';
-import { isMobileWidth } from '@core/mobile/mobileWidth';
import { maybeThrow } from '@core/util/maybeResult';
import ExpandIcon from '@icon/regular/arrows-out-simple.svg';
import ClipboardIcon from '@icon/regular/clipboard.svg';
@@ -139,8 +138,6 @@ export function ImagePreview(props: ImagePreviewProps) {
};
const handleMouseMove = () => {
- if (isMobileWidth() || isTouchDevice()) return;
-
setIsToolbarVisible(true);
if (hideToolbarTimeout) {
@@ -241,7 +238,7 @@ export function ImagePreview(props: ImagePreviewProps) {
image.addEventListener('panzoomchange', updateCursor);
image.addEventListener('wheel', panzoom.zoomWithWheel);
- if (!isMobileWidth() && !isTouchDevice()) {
+ if (!isTouchDevice()) {
setTimeout(() => {
window.addEventListener('mousemove', handleMouseMove);
}, 500);
@@ -331,10 +328,9 @@ export function ImagePreview(props: ImagePreviewProps) {
<div
class="absolute top-4 right-4 bg-dialog rounded-lg border border-edge p-1 flex flex-row items-center gap-1 shadow-md transition-opacity duration-300"
classList={{
- 'opacity-100':
- isMobileWidth() || isTouchDevice() || isToolbarVisible(),
+ 'opacity-100': isTouchDevice() || isToolbarVisible(),
'opacity-0 pointer-events-none':
- !isMobileWidth() && !isTouchDevice() && !isToolbarVisible(),
+ !isTouchDevice() && !isToolbarVisible(),
}}
style={{ 'z-index': stackingContext.zModal + 1 }}
>
diff --git a/js/app/packages/core/component/LexicalMarkdown/component/decorator/MediaButtons.tsx b/js/app/packages/core/component/LexicalMarkdown/component/decorator/MediaButtons.tsx
index cb6233d587..245e201a40 100644
--- a/js/app/packages/core/component/LexicalMarkdown/component/decorator/MediaButtons.tsx
+++ b/js/app/packages/core/component/LexicalMarkdown/component/decorator/MediaButtons.tsx
@@ -5,8 +5,7 @@ import {
MenuSeparator,
} from '@core/component/Menu';
import clickOutside from '@core/directive/clickOutside';
-import { isTouchDevice } from '@core/mobile/isTouchDevice';
-import { isMobileWidth } from '@core/mobile/mobileWidth';
+import { isMobile } from '@core/mobile/isMobile';
import NewTab from '@icon/regular/arrow-square-out.svg';
import ArrowsOut from '@icon/regular/arrows-out-simple.svg';
import ThreeDotsIcon from '@icon/regular/dots-three.svg';
@@ -62,7 +61,7 @@ export function MediaButtons(props: MediaButtonsProps) {
/>
</Dialog.Trigger>
</Show>
- <Show when={props.newTab && !isMobileWidth() && !isTouchDevice}>
+ <Show when={props.newTab && !isMobile()}>
<DeprecatedIconButton
class="m-0"
icon={() => <NewTab class="size-5" />}
@@ -127,9 +126,7 @@ export function MediaButtons(props: MediaButtonsProps) {
}}
/>
</Show>
- <Show
- when={props.newTab && !isMobileWidth() && !isTouchDevice()}
- >
+ <Show when={props.newTab && !isMobile()}>
<MenuItem
text="Open in new tab"
icon={NewTab}
diff --git a/js/app/packages/core/component/Menu.tsx b/js/app/packages/core/component/Menu.tsx
index 62df1a078f..fb69a3eb31 100644
--- a/js/app/packages/core/component/Menu.tsx
+++ b/js/app/packages/core/component/Menu.tsx
@@ -1,6 +1,5 @@
import type { HotkeyToken } from '@core/hotkey/tokens';
-import { isTouchDevice } from '@core/mobile/isTouchDevice';
-import { isMobileWidth } from '@core/mobile/mobileWidth';
+import { isMobile } from '@core/mobile/isMobile';
import CheckIcon from '@icon/bold/check-bold.svg?component-solid';
import CaretRight from '@icon/regular/caret-right.svg?component-solid';
import { ContextMenu } from '@kobalte/core/context-menu';
@@ -129,7 +128,7 @@ export type MenuItemProps =
| CheckboxMenuItemProps
| RadioMenuItemProps;
-export const MENU_ITEM_CLASS = `flex flex-row w-full gap-1.5 tracking-tight ${isMobileWidth() && isTouchDevice() ? 'py-2 px-1 text-base' : 'py-1 pl-2 pr-2 text-sm'} font-medium justify-between items-center focus-bracket`;
+export const MENU_ITEM_CLASS = `flex flex-row w-full gap-1.5 tracking-tight ${isMobile() ? 'py-2 px-1 text-base' : 'py-1 pl-2 pr-2 text-sm'} font-medium justify-between items-center focus-bracket`;
/**
* A menu item component that can be used interchangeably within either a ContextMenu or DropdownMenu.
@@ -187,7 +186,7 @@ export function MenuItem(props: MenuItemProps) {
>
<Show when={props.selectorType === 'checkbox'}>
<div
- class={`${isMobileWidth() && isTouchDevice() ? 'w-5 h-5' : 'w-4 h-4'} shrink-0 flex items-center justify-center`}
+ class={`${isMobile() ? 'w-5 h-5' : 'w-4 h-4'} shrink-0 flex items-center justify-center`}
>
<CheckIcon
class={`w-[14px] h-[14px] shrink-0 rounded-sm p-[2px] ${
@@ -200,7 +199,7 @@ export function MenuItem(props: MenuItemProps) {
</Show>
<Show when={props.selectorType === 'radio'}>
<div
- class={`flex items-center justify-center shrink-0 ${isMobileWidth() && isTouchDevice() ? 'w-5 h-5' : 'w-4 h-4'}`}
+ class={`flex items-center justify-center shrink-0 ${isMobile() ? 'w-5 h-5' : 'w-4 h-4'}`}
>
<div
class={`w-[14px] h-[14px] shrink-0 rounded-full ${
@@ -218,7 +217,7 @@ export function MenuItem(props: MenuItemProps) {
component={
props.icon as Component<JSX.SvgSVGAttributes<SVGSVGElement>>
}
- class={`${isMobileWidth() && isTouchDevice() ? 'w-5 h-5' : 'w-4 h-4'} shrink-0 ${props.iconClass ?? ''}`}
+ class={`${isMobile() ? 'w-5 h-5' : 'w-4 h-4'} shrink-0 ${props.iconClass ?? ''}`}
/>
</Show>
<Show when={typeof props.icon === 'object'}>
@@ -256,7 +255,7 @@ export function SubTrigger(props: {
component={
props.icon as Component<JSX.SvgSVGAttributes<SVGSVGElement>>
}
- class={`${isMobileWidth() && isTouchDevice() ? 'w-5 h-5' : 'w-4 h-4'} shrink-0 ${props.iconClass ?? ''}`}
+ class={`${isMobile() ? 'w-5 h-5' : 'w-4 h-4'} shrink-0 ${props.iconClass ?? ''}`}
/>
</Show>
<Show when={typeof props.icon === 'object'}>
@@ -316,10 +315,7 @@ function MobileConditionalOverlay(
props: ParentProps<{ mobileFullScreen?: boolean }>
) {
return (
- <Show
- when={props.mobileFullScreen && isTouchDevice() && isMobileWidth()}
- fallback={props.children}
- >
+ <Show when={props.mobileFullScreen && isMobile()} fallback={props.children}>
<div class="z-modal fixed inset-0 flex justify-center items-center bg-modal-overlay backdrop-blur-sm">
{props.children}
</div>
@@ -395,7 +391,7 @@ export function ContextMenuContent(props: ParentProps<MenuContentProps>) {
const positioner = contentRef?.closest('[data-popper-positioner]');
if (!positioner || !(positioner instanceof HTMLElement)) return;
- if (!isTouchDevice() || !isMobileWidth()) {
+ if (!isMobile()) {
return;
}
@@ -435,7 +431,7 @@ export function ContextMenuContent(props: ParentProps<MenuContentProps>) {
${props.class} ${props.width ? menuWidths[props.width] : ''}
${
props.mobileFullScreen
- ? isTouchDevice() && isMobileWidth()
+ ? isMobile()
? 'flex flex-col justify-center px-4 max-h-[80vh] shrink w-[calc(100vw-1rem)]'
: ''
: ''
diff --git a/js/app/packages/core/component/OldMenu.tsx b/js/app/packages/core/component/OldMenu.tsx
index 3d4c2030fa..6d01089b3e 100644
--- a/js/app/packages/core/component/OldMenu.tsx
+++ b/js/app/packages/core/component/OldMenu.tsx
@@ -4,8 +4,8 @@
* This file is only for legacy support of a few non-standard menus that have not yet been migrated.
*/
+import { isMobile } from '@core/mobile/isMobile';
import { isTouchDevice } from '@core/mobile/isTouchDevice';
-import { isMobileWidth } from '@core/mobile/mobileWidth';
import {
autoUpdate,
computePosition,
@@ -125,7 +125,7 @@ export function OldMenuItem(props: OldMenuItemProps) {
ref={setMenuItemRef}
>
<div
- class={`flex flex-row w-full ${isMobileWidth() && isTouchDevice() ? 'py-2 px-1' : 'p-1'} justify-between items-center rounded ${
+ class={`flex flex-row w-full ${isMobile() ? 'py-2 px-1' : 'p-1'} justify-between items-center rounded ${
props.disabled
? 'opacity-50 cursor-not-allowed text-ink'
: (selected())
@@ -139,13 +139,13 @@ export function OldMenuItem(props: OldMenuItemProps) {
}}
>
<div
- class={`flex flex-row w-full gap-1.5 justify-start items-center ${props.textSize === 'base' ? 'text-base' : isMobileWidth() && isTouchDevice() ? 'text-base' : 'text-sm'} font-medium ${
+ class={`flex flex-row w-full gap-1.5 justify-start items-center ${props.textSize === 'base' ? 'text-base' : isMobile() ? 'text-base' : 'text-sm'} font-medium ${
props.secondaryActionHandler ? `max-w-[calc(100%-18px)]` : ''
}`}
>
{props.icon && (
<div
- class={`flex ${isMobileWidth() && isTouchDevice() ? 'w-5 h-5' : 'w-4 h-4'} justify-center items-center shrink-0 ${
+ class={`flex ${isMobile() ? 'w-5 h-5' : 'w-4 h-4'} justify-center items-center shrink-0 ${
selected() ? 'text-accent-ink' : ''
} ${props.iconClass ?? ''}`}
>
diff --git a/js/app/packages/core/component/ResponsiveResizable.tsx b/js/app/packages/core/component/ResponsiveResizable.tsx
deleted file mode 100644
index 49681b1ac6..0000000000
--- a/js/app/packages/core/component/ResponsiveResizable.tsx
+++ /dev/null
@@ -1,116 +0,0 @@
-import { isMobileWidth } from '@core/mobile/mobileWidth';
-import Resizable, { type ContextValue } from '@corvu/resizable';
-import {
- createEffect,
- type JSX,
- Match,
- type ParentProps,
- Show,
- Switch,
- splitProps,
-} from 'solid-js';
-
-function ContextWrapper(
- props: ParentProps<{
- setResizableContext?: (context: ContextValue) => void;
- }>
-) {
- const context = Resizable.useContext();
- createEffect(() => {
- props.setResizableContext?.(context);
- });
- return props.children;
-}
-
-/**
- * @file This is a drop-in replacement for Resizable that by-passes Resizable componenets at mobile width, to allow for correct responsive styling.
- */
-
-type ResponsiveResizableProps = ParentProps<{
- class?: string;
- style?: JSX.CSSProperties;
- setResizableContext?: (context: ContextValue) => void;
- [key: string]: any;
-}>;
-
-export function ResponsiveResizable(props: ResponsiveResizableProps) {
- const [local, resizableProps] = splitProps(props, [
- 'children',
- 'class',
- 'style',
- 'setResizableContext',
- ]);
- // wrap the resizables in a component that either returns a resizable or a div, rather than switch match ugly mayhem
- return (
- <Switch>
- <Match when={isMobileWidth()}>
- <div class={local.class} style={local.style}>
- {local.children}
- </div>
- </Match>
- <Match when={!isMobileWidth()}>
- <Resizable class={local.class} style={local.style} {...resizableProps}>
- <ContextWrapper setResizableContext={local.setResizableContext}>
- {local.children}
- </ContextWrapper>
- </Resizable>
- </Match>
- </Switch>
- );
-}
-
-type PanelProps = ParentProps<{
- class?: string;
- style?: JSX.CSSProperties;
- [key: string]: any;
-}>;
-
-ResponsiveResizable.Panel = function Panel(props: PanelProps) {
- const [local, panelProps] = splitProps(props, ['children', 'class', 'style']);
-
- return (
- <Switch>
- <Match when={isMobileWidth()}>
- <div class={local.class} style={local.style}>
- {local.children}
- </div>
- </Match>
- <Match when={!isMobileWidth()}>
- <Resizable.Panel
- class={local.class}
- style={local.style}
- {...panelProps}
- >
- {local.children}
- </Resizable.Panel>
- </Match>
- </Switch>
- );
-};
-
-// Handle component for ResponsiveResizable
-type HandleProps = ParentProps<{
- class?: string;
- 'aria-label'?: string;
- [key: string]: any;
-}>;
-
-ResponsiveResizable.Handle = function Handle(props: HandleProps) {
- const [local, handleProps] = splitProps(props, [
- 'class',
- 'aria-label',
- 'children',
- ]);
-
- return (
- <Show when={!isMobileWidth()}>
- <Resizable.Handle
- aria-label={local['aria-label'] || 'Resize Handle'}
- class={local.class}
- {...handleProps}
- >
- {props.children}
- </Resizable.Handle>
- </Show>
- );
-};
diff --git a/js/app/packages/core/mobile/isMobile.ts b/js/app/packages/core/mobile/isMobile.ts
new file mode 100644
index 0000000000..b0fb1a67d1
--- /dev/null
+++ b/js/app/packages/core/mobile/isMobile.ts
@@ -0,0 +1,11 @@
+import { isMobileWidth } from './mobileWidth';
+import { isTouchDevice } from './isTouchDevice';
+
+/**
+ * Returns true if the device is likely in a mobile context.
+ * This checks for both a narrow screen width AND a primarily touch-based device.
+ * Use this for behavior that should differ on phones vs tablets/desktops.
+ */
+export function isMobile(): boolean {
+ return isMobileWidth() && isTouchDevice();
+}