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[mobile]: md touch handling improvements (#1342)

Peter Chinman0f3cd6a703ef
diff --git a/js/app/packages/block-canvas/component/nodes/EntityMention.tsx b/js/app/packages/block-canvas/component/nodes/EntityMention.tsx
index 25db55f7d0..49bf44c7e6 100644
--- a/js/app/packages/block-canvas/component/nodes/EntityMention.tsx
+++ b/js/app/packages/block-canvas/component/nodes/EntityMention.tsx
@@ -204,25 +204,6 @@ export function File(props: { node: EntityMentionNode; mode: RenderMode }) {
trigger={
<div
class="document-mention internal-link"
- ontouchstart={(e) => {
- if (isTouchDevice()) {
- e.preventDefault();
- }
- }}
- ontouchend={(e) => {
- if (isTouchDevice()) {
- e.preventDefault();
- if (
- matches(item(), (i) => !i.loading && i.access === 'access')
- ) {
- replaceOrInsertSplit({
- type: blockName() as BlockName,
- id: props.node.file,
- });
- track(TrackingEvents.BLOCKCANVAS.FILES.OPENFILESIDE);
- }
- }
- }}
on:pointerdown={(e) => {
setSelfMouseDownPosition(vec2(e.pageX, e.pageY));
}}
diff --git a/js/app/packages/core/component/LexicalMarkdown/component/core/LinkWithPreview.tsx b/js/app/packages/core/component/LexicalMarkdown/component/core/LinkWithPreview.tsx
index 86fc05563d..7b3c9b9fa6 100644
--- a/js/app/packages/core/component/LexicalMarkdown/component/core/LinkWithPreview.tsx
+++ b/js/app/packages/core/component/LexicalMarkdown/component/core/LinkWithPreview.tsx
@@ -4,6 +4,7 @@ import { useUnfurl } from '@core/signal/unfurl';
import { debounce } from '@solid-primitives/scheduled';
import { createSignal, type ParentProps, Show } from 'solid-js';
import { floatWithElement } from '../../directive/floatWithElement';
+import { isTouchDevice } from '@core/mobile/isTouchDevice';
false && floatWithElement;
@@ -30,7 +31,10 @@ export function LinkWithPreview(props: UnfurlLinkProps) {
href={props.url}
target="_blank"
class={`${props.class || ''}`}
- onMouseEnter={() => debouncedSetPreviewOpen(true)}
+ onMouseEnter={() => {
+ if (isTouchDevice()) return;
+ debouncedSetPreviewOpen(true);
+ }}
onMouseLeave={() => {
debouncedSetPreviewOpen.clear();
debouncedSetPreviewOpen(false);
diff --git a/js/app/packages/core/component/LexicalMarkdown/component/decorator/DocumentMention.tsx b/js/app/packages/core/component/LexicalMarkdown/component/decorator/DocumentMention.tsx
index de60f226b7..582b3c8b0e 100644
--- a/js/app/packages/core/component/LexicalMarkdown/component/decorator/DocumentMention.tsx
+++ b/js/app/packages/core/component/LexicalMarkdown/component/decorator/DocumentMention.tsx
@@ -12,7 +12,6 @@ import {
import { EntityIcon } from '@core/component/EntityIcon';
import { resolveBlockAlias, verifyBlockName } from '@core/constant/allBlocks';
import { ENABLE_BLOCK_IN_BLOCK } from '@core/constant/featureFlags';
-import { isTouchDevice } from '@core/mobile/isTouchDevice';
import { URL_PARAMS as CHANNEL_URL_PARAMS } from '@block-channel/constants';
import { canNestBlock } from '@core/orchestrator';
import {
@@ -354,21 +353,6 @@ export function DocumentMentionInner(props: DocumentMentionDecoratorProps) {
style={{
'user-select': 'inherit',
}}
- ontouchstart={(e: TouchEvent) => {
- if (isTouchDevice()) {
- e.preventDefault();
- }
- }}
- ontouchend={(e: TouchEvent) => {
- if (isTouchDevice()) {
- e.preventDefault();
- if (
- matches(item(), (i) => !i.loading && i.access === 'access')
- ) {
- open(null);
- }
- }
- }}
{...navHandlers}
>
<Switch>
diff --git a/js/app/packages/core/component/LexicalMarkdown/component/decorator/Snapshot.tsx b/js/app/packages/core/component/LexicalMarkdown/component/decorator/Snapshot.tsx
index 2535401223..1fa833a57d 100644
--- a/js/app/packages/core/component/LexicalMarkdown/component/decorator/Snapshot.tsx
+++ b/js/app/packages/core/component/LexicalMarkdown/component/decorator/Snapshot.tsx
@@ -6,7 +6,6 @@ import {
type EntityIconSelector,
} from '@core/component/EntityIcon';
import { verifyBlockName } from '@core/constant/allBlocks';
-import { isTouchDevice } from '@core/mobile/isTouchDevice';
import { isAccessiblePreviewItem, useItemPreview } from '@queries/preview';
import { matches } from '@core/util/match';
import { openInNewSplitForMention } from '@core/util/openInNewSplit';
@@ -178,21 +177,6 @@ function SnapshotInner(props: SnapshotDecoratorProps) {
style={{
'user-select': 'inherit',
}}
- ontouchstart={(e) => {
- if (isTouchDevice()) {
- e.preventDefault();
- }
- }}
- ontouchend={(e) => {
- if (isTouchDevice()) {
- e.preventDefault();
- if (
- matches(item(), (i) => !i.loading && i.access === 'access')
- ) {
- open(null);
- }
- }
- }}
{...navHandlers}
>
{renderContent()}
diff --git a/js/app/packages/core/component/LexicalMarkdown/plugins/links/linksPlugin.ts b/js/app/packages/core/component/LexicalMarkdown/plugins/links/linksPlugin.ts
index 33316d40a8..d851291777 100644
--- a/js/app/packages/core/component/LexicalMarkdown/plugins/links/linksPlugin.ts
+++ b/js/app/packages/core/component/LexicalMarkdown/plugins/links/linksPlugin.ts
@@ -32,6 +32,7 @@ import {
import linkify, { type Match } from 'linkify-it';
import { createSignal } from 'solid-js';
import { editorFocusSignal } from '../../utils';
+import { isTouchDevice } from '@core/mobile/isTouchDevice';
const strictLinkifier = new linkify(undefined, {
fuzzyLink: false,
@@ -371,6 +372,7 @@ function registerLinksPlugin(editor: LexicalEditor, props: LinkPluginProps) {
};
const handlePointerMove = (e: MouseEvent) => {
+ if (isTouchDevice()) return;
const target = e.target;
const link = getLinkFromDom(target);
if (link === null) {
diff --git a/js/app/packages/core/mobile/isTouchDevice.ts b/js/app/packages/core/mobile/isTouchDevice.ts
index dd95cba836..f407ddcb93 100644
--- a/js/app/packages/core/mobile/isTouchDevice.ts
+++ b/js/app/packages/core/mobile/isTouchDevice.ts
@@ -1,12 +1,21 @@
/**
* This function returns true if the device is PRIMARILY touch device, E.g. this should return false for touchscreen laptops. However, the user might still be using a keyboard, e.g. if they have a physical keyboard attached to their iPad. In that case, you may want to use isModality('touch') instead.
*/
+let cachedIsTouchDevice: boolean | null = null;
+
export function isTouchDevice(): boolean {
- if (typeof window === 'undefined' || typeof window.matchMedia !== 'function')
+ if (cachedIsTouchDevice !== null) return cachedIsTouchDevice;
+
+ if (
+ typeof window === 'undefined' ||
+ typeof window.matchMedia !== 'function'
+ ) {
return false;
+ }
const hasCoarsePointer = window.matchMedia('(pointer: coarse)').matches;
const hasNoHover = window.matchMedia('(hover: none)').matches;
- return hasCoarsePointer && hasNoHover;
+ cachedIsTouchDevice = hasCoarsePointer && hasNoHover;
+ return cachedIsTouchDevice;
}
diff --git a/js/app/packages/core/mobile/mobileWidth.ts b/js/app/packages/core/mobile/mobileWidth.ts
index 8443577eb2..b7d181ddbc 100644
--- a/js/app/packages/core/mobile/mobileWidth.ts
+++ b/js/app/packages/core/mobile/mobileWidth.ts
@@ -9,8 +9,6 @@ if (typeof window !== 'undefined') {
setIsMobileWidth(window.innerWidth < 640);
};
- setIsMobileWidth(window.innerWidth < 640);
-
window.addEventListener('resize', handleResize);
}