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(md): fix md menu close on submenu, fix(soup): fix no focus events for checkbox clicks (#206)

Seamus72ad88c0c87c
diff --git a/js/app/packages/block-md/component/FormatTools.tsx b/js/app/packages/block-md/component/FormatTools.tsx
index dc713138bf..5d802c6478 100644
--- a/js/app/packages/block-md/component/FormatTools.tsx
+++ b/js/app/packages/block-md/component/FormatTools.tsx
@@ -434,7 +434,6 @@ export function FormatTools(props: { withinPopup?: boolean }) {
const FormatDropDown = (props: { buttonIsDisabled: Accessor<boolean> }) => {
const [menuOpen, setMenuOpen] = createSignal(false);
- // TODO bring up to menu best practives, ie. fully focusable menu items, etc.
return (
<DropdownMenu open={menuOpen()} onOpenChange={setMenuOpen}>
<DropdownMenu.Trigger>
diff --git a/js/app/packages/block-md/component/MarkdownEditor.tsx b/js/app/packages/block-md/component/MarkdownEditor.tsx
index 7374a92953..4e8104a0f3 100644
--- a/js/app/packages/block-md/component/MarkdownEditor.tsx
+++ b/js/app/packages/block-md/component/MarkdownEditor.tsx
@@ -1247,14 +1247,6 @@ export function InstructionsMarkdownEditor() {
);
};
- // better focus in handling. preserves selection on regain focus!
- autoRegister(
- registerRootEventListener(editor, 'focusin', (e) => {
- e.preventDefault();
- editor.focus();
- })
- );
-
const [fileArrayBuffer, setFileArrayBuffer] = createSignal<ArrayBuffer>();
createEffect(() => {
const file = blockFileSignal();
diff --git a/js/app/packages/block-md/component/MarkdownPopup.tsx b/js/app/packages/block-md/component/MarkdownPopup.tsx
index 017a0997f2..44ac25e8e5 100644
--- a/js/app/packages/block-md/component/MarkdownPopup.tsx
+++ b/js/app/packages/block-md/component/MarkdownPopup.tsx
@@ -16,6 +16,7 @@ import { LexicalWrapperContext } from '@core/component/LexicalMarkdown/context/L
import {
autoRegister,
type EnhancedSelection,
+ NODE_TRANSFORM,
registerRootEventListener,
} from '@core/component/LexicalMarkdown/plugins';
import {
@@ -32,7 +33,7 @@ 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';
-import { laggedGate } from '@core/util/debounce';
+import { debouncedDependent } from '@core/util/debounce';
import { createFromMarkdownText } from '@core/util/md';
import { getScrollParentElement } from '@core/util/scrollParent';
import type { NodeIdMappings } from '@lexical-core';
@@ -51,7 +52,7 @@ import {
$getSelectionLocation,
type PersistentLocation,
} from 'core/component/LexicalMarkdown/plugins/location/locationPlugin';
-import { $getRoot } from 'lexical';
+import { $getRoot, COMMAND_PRIORITY_HIGH } from 'lexical';
import {
createEffect,
createSignal,
@@ -79,6 +80,7 @@ export function MarkdownPopup(props: {
}
const [anchorRef, setAnchorRef] = createSignal<HTMLDivElement>();
+ const [menuRef, setMenuRef] = createSignal<HTMLDivElement>();
const [popupVisible, setPopupVisible] = createMenuOpenSignal(
MENU_ID,
@@ -102,8 +104,8 @@ export function MarkdownPopup(props: {
})
);
- // The actual control value for showPopup lags by 200 ms on the "true" side.
- const showPopup = laggedGate(popupVisible, 200);
+ // The actual control value for showPopup lags.
+ const showPopup = debouncedDependent(popupVisible, 100);
const canEdit = useCanEdit();
const canComment = useCanComment();
@@ -176,9 +178,20 @@ export function MarkdownPopup(props: {
}
}
}),
- registerRootEventListener(editor, 'focusout', () => {
+ registerRootEventListener(editor, 'focusout', ({ relatedTarget }) => {
+ if (relatedTarget && relatedTarget instanceof Node) {
+ if (menuRef()?.contains(relatedTarget)) return;
+ }
setPopupVisible(false);
- })
+ }),
+ editor.registerCommand(
+ NODE_TRANSFORM,
+ () => {
+ setPopupVisible(false);
+ return false;
+ },
+ COMMAND_PRIORITY_HIGH
+ )
);
const MarkdownPopupToolbar = () => {
@@ -632,6 +645,7 @@ export function MarkdownPopup(props: {
blockType: 'md',
}}
useBlockBoundary={true}
+ ref={setMenuRef}
/>
</ScopedPortal>
</Show>
diff --git a/js/app/packages/core/component/GeneralizedPopup/Popup.tsx b/js/app/packages/core/component/GeneralizedPopup/Popup.tsx
index 39ebc5578d..e5c7d7ea27 100644
--- a/js/app/packages/core/component/GeneralizedPopup/Popup.tsx
+++ b/js/app/packages/core/component/GeneralizedPopup/Popup.tsx
@@ -8,11 +8,13 @@ import {
offset,
shift,
} from '@floating-ui/dom';
+import { mergeRefs } from '@solid-primitives/refs';
import {
type Component,
createEffect,
createSignal,
onCleanup,
+ type Ref,
} from 'solid-js';
type GeneralizedPopupProps = {
@@ -23,10 +25,11 @@ type GeneralizedPopupProps = {
blockType: BlockName;
};
useBlockBoundary?: boolean;
+ ref?: Ref<HTMLDivElement>;
};
export function GeneralizedPopup(props: GeneralizedPopupProps) {
- let popupRef: HTMLDivElement | undefined;
+ const [popupRef, setPopupRef] = createSignal<HTMLDivElement>();
const [position, setPosition] = createSignal({ x: 0, y: 0 });
let boundary: Boundary = 'clippingAncestors';
@@ -36,8 +39,9 @@ export function GeneralizedPopup(props: GeneralizedPopupProps) {
}
const updatePosition = async () => {
- if (!popupRef) return;
- const { x, y } = await computePosition(props.anchor.ref, popupRef, {
+ const ref = popupRef();
+ if (!ref) return;
+ const { x, y } = await computePosition(props.anchor.ref, ref, {
placement: 'bottom',
middleware: [
offset(12),
@@ -53,15 +57,16 @@ export function GeneralizedPopup(props: GeneralizedPopupProps) {
};
createEffect(() => {
- if (!popupRef) return;
+ const ref = popupRef();
+ if (!ref) return;
- const cleanup = autoUpdate(props.anchor.ref, popupRef, updatePosition);
+ const cleanup = autoUpdate(props.anchor.ref, ref, updatePosition);
onCleanup(() => cleanup());
});
return (
<div
- ref={popupRef}
+ ref={mergeRefs(setPopupRef, props.ref)}
id="generalized-popup"
class="absolute bg-menu shadow-xl ring-1 ring-edge z-highlight-menu rounded-xs inline-flex items-start flex-col p-1"
style={{
diff --git a/js/app/packages/macro-entity/src/components/EntityWithEverything.tsx b/js/app/packages/macro-entity/src/components/EntityWithEverything.tsx
index d71b1b83b9..9601221a5a 100644
--- a/js/app/packages/macro-entity/src/components/EntityWithEverything.tsx
+++ b/js/app/packages/macro-entity/src/components/EntityWithEverything.tsx
@@ -1,13 +1,13 @@
import { matches } from '@core/util/match';
import CheckIcon from '@phosphor-icons/core/assets/regular/check.svg';
import { useEmail } from '@service-gql/client';
+import { mergeRefs } from '@solid-primitives/refs';
import { createDraggable, createDroppable } from '@thisbeyond/solid-dnd';
import { getIconConfig } from 'core/component/EntityIcon';
import { StaticMarkdown } from 'core/component/LexicalMarkdown/component/core/StaticMarkdown';
import { unifiedListMarkdownTheme } from 'core/component/LexicalMarkdown/theme';
import { emailToId, useDisplayName } from 'core/user';
import { onKeyDownClick, onKeyUpClick } from 'core/util/click';
-import { useSplitNavigationHandler } from 'core/util/useSplitNavigationHandler';
import { notificationWithMetadata } from 'notifications/notificationMetadata';
import type { ParentProps, Ref } from 'solid-js';
import {
@@ -96,20 +96,15 @@ export function EntityWithEverything(
const [entityHovered, setEntityHovered] = createSignal(false);
const [actionButtonRef, setActionButtonRef] =
createSignal<HTMLButtonElement | null>(null);
+ const [entityDivRef, setEntityDivRef] = createSignal<HTMLDivElement | null>(
+ null
+ );
const [showRestOfNotifications, setShowRestOfNotifications] =
createSignal(false);
const { keydownDataDuringTask } = trackKeydownDuringTask();
const userEmail = useEmail();
- // onMount(() => {
- // if (document.activeElement === document.body) {
- // if (props.selected && props.highlighted) {
- // tabbableEl.focus();
- // }
- // }
- // });
-
let focusId = 0;
const getIcon = createMemo(() => {
switch (props.entity.type) {
@@ -334,13 +329,18 @@ export function EntityWithEverything(
const { didCursorMove } = useCursorMove();
- const navHandlers = createMemo(() => {
- const onClick = props.onClick;
- if (!onClick) return;
- return useSplitNavigationHandler<HTMLDivElement>((e) =>
- onClick(props.entity, e)
- );
- });
+ // The main click handler for the entity row should navigate to an entity
+ // without forcing focus back to the source split until after navigation.
+ // Certain buttons in the entity need to NOT Navigate AND return focus to
+ // the split. Those buttons should have a 'data-blocks-navigation'
+ function blocksNavigation(e: PointerEvent | MouseEvent): boolean {
+ const { target } = e;
+ if (target instanceof HTMLElement) {
+ const closest = target.closest('[data-blocks-navigation]');
+ if (closest && entityDivRef()?.contains(closest)) return true;
+ }
+ return false;
+ }
return (
<div
@@ -386,7 +386,14 @@ export function EntityWithEverything(
data-entity
data-entity-id={props.entity.id}
class="w-full min-w-0 grid flex-1 items-center suppress-css-bracket grid-cols-[2rem_1fr_auto] pr-2"
- {...navHandlers()}
+ onClick={(e) => {
+ if (blocksNavigation(e)) return;
+ props.onClick?.(props.entity, e);
+ }}
+ onMouseDown={(e) => {
+ if (blocksNavigation(e)) return;
+ e.preventDefault();
+ }}
// Action List is also rendered based on focus, but when focused via Shift+Tab, parent is focused due to Action List dom not present. Here we check if current browser task has captured Shift+Tab focus on Action List
onFocusIn={(e) => {
if (
@@ -407,18 +414,18 @@ export function EntityWithEverything(
onKeyUp={onKeyUpClick((e) => props.onClick?.(props.entity, e as any))}
role="button"
tabIndex={0}
- ref={props.ref}
+ ref={mergeRefs(setEntityDivRef, props.ref)}
>
<button
type="button"
class="col-1 size-full relative group/button flex items-center justify-center"
- onClick={(e) => {
- e.stopPropagation();
+ onClick={() => {
props.onChecked?.(!props.checked);
}}
+ data-blocks-navigation
>
<div
- class="size-4 p-0.5 flex items-center justify-center rounded-xs group-hover/button:border-accent group-hover/button:border"
+ class="size-4 p-0.5 flex items-center justify-center rounded-xs group-hover/button:border-accent group-hover/button:border pointer-events-none"
classList={{
'ring ring-edge-muted': props.selected || entityHovered(),
'bg-panel': !props.checked && (props.selected || entityHovered()),
@@ -479,13 +486,13 @@ export function EntityWithEverything(
<div class="flex gap-1 h-8">
<button
class="flex items-center justify-center size-8 hover:bg-accent hover:text-panel"
- onClick={(e) => {
- e.stopPropagation();
+ onClick={() => {
props.onClickRowAction?.(props.entity, 'done');
}}
ref={setActionButtonRef}
+ data-blocks-navigation
>
- <CheckIcon class="w-4 h-4" />
+ <CheckIcon class="w-4 h-4 pointer-events-none" />
</button>
</div>
</Show>
@@ -639,6 +646,7 @@ export function EntityWithEverything(
e.stopPropagation();
setShowRestOfNotifications((prev) => !prev);
}}
+ data-blocks-navigation
>
<Show
when={!showRestOfNotifications()}