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
fix: fix focus issues in composers and bigchat (#26)
Seamusc8c40f8f2c36
diff --git a/js/app/packages/app/component/Layout.tsx b/js/app/packages/app/component/Layout.tsxindex a2d7e353b9..91ad38ff86 100644--- a/js/app/packages/app/component/Layout.tsx+++ b/js/app/packages/app/component/Layout.tsx@@ -1,4 +1,4 @@-import { setActiveElement } from '@app/signal/focus';+import { mountGlobalFocusListener } from '@app/signal/focus';import { useIsAuthenticated } from '@core/auth';import { Resize } from '@core/component/Resize';import { useABTest } from '@core/constant/ABTest';@@ -97,19 +97,7 @@ export function Layout(props: RouteSectionProps) {return currentAuth;}, isAuthenticated());- onMount(() => {- const handleFocusChange = () => {- setActiveElement(document.activeElement);- };-- document.addEventListener('focusin', handleFocusChange);- document.addEventListener('focusout', handleFocusChange);-- onCleanup(() => {- document.removeEventListener('focusin', handleFocusChange);- document.removeEventListener('focusout', handleFocusChange);- });- });+ mountGlobalFocusListener(true);useABTest();diff --git a/js/app/packages/app/component/dock/CreateMenu.tsx b/js/app/packages/app/component/dock/CreateMenu.tsxindex 2ab92f5c61..2690e6b34d 100644--- a/js/app/packages/app/component/dock/CreateMenu.tsx+++ b/js/app/packages/app/component/dock/CreateMenu.tsx@@ -18,8 +18,15 @@ import { ok } from '@core/util/maybeResult';import { DropdownMenu } from '@kobalte/core/dropdown-menu';import MacroCreateIcon from '@macro-icons/macro-create-b.svg';import { useCreateProject } from '@service-storage/projects';-import { createMemo, For, onMount, Show } from 'solid-js';-import { useSplitLayout } from '../split-layout/layout'; // except this, not part of the TEMP but biome sorts the imports.+import {+ createEffect,+ createMemo,+ createSignal,+ For,+ onMount,+ Show,+} from 'solid-js';+import { useSplitLayout } from '../split-layout/layout';export const [createMenuOpen, setCreateMenuOpen] = createControlledOpenSignal();@@ -84,6 +91,7 @@ const createBlock = async (spec: {};const createComponent = async (spec: { componentId: string }) => {+ setCreateMenuOpen(false);const { replaceSplit, insertSplit } = useSplitLayout();const shouldInsert = pressedKeys().has('opt');if (shouldInsert) {@@ -91,8 +99,6 @@ const createComponent = async (spec: { componentId: string }) => {} else {replaceSplit({ type: 'component', id: spec.componentId });}-- setCreateMenuOpen(false);};export const CREATABLE_BLOCKS: (Omit<HotkeyRegistrationOptions, 'scopeId'> & {@@ -312,7 +318,9 @@ export function CreateMenu() {// onMount(() => setCreateMenuOpen(true))return (<DropdownMenu open={createMenuOpen()} onOpenChange={setCreateMenuOpen}>- <DropdownMenu.Trigger class="relative flex justify-between items-center gap-2 data-expanded:bg-accent px-3 py-2 border border-edge-muted data-expanded:border-accent **:border-none! font-medium text-ink-muted data-expanded:text-default-bg hover:text-accent text-base bracket-never">+ <DropdownMenu.Trigger+ class="relative flex justify-between items-center gap-2 data-expanded:bg-accent px-3 py-2 border border-edge-muted data-expanded:border-accent **:border-none! font-medium text-ink-muted data-expanded:text-default-bg hover:text-accent text-base bracket-never"+ ><span class="flex items-center"><MacroCreateIconclass={`h-2.5 ${createMenuOpen() ? 'fill-dialog/70' : 'fill-accent/70 transition-all duration-300'}`}diff --git a/js/app/packages/app/component/rightbar/Rightbar.tsx b/js/app/packages/app/component/rightbar/Rightbar.tsxindex 43e77e8932..646c5dbf6b 100644--- a/js/app/packages/app/component/rightbar/Rightbar.tsx+++ b/js/app/packages/app/component/rightbar/Rightbar.tsx@@ -1,3 +1,5 @@+import { activeElement } from '@app/signal/focus';+import { globalSplitManager } from '@app/signal/splitLayout';import { useIsAuthenticated } from '@core/auth';import { DragDropWrapper } from '@core/component/AI/component/DragDrop';import { useChatInput } from '@core/component/AI/component/input/useChatInput';@@ -49,6 +51,7 @@ import { createCognitionWebsocketEffect } from '@service-cognition/websocket';import { useUserId } from '@service-gql/client';import { refetchHistory, useHistory } from '@service-storage/history';import { useOpenInstructionsMd } from 'core/component/AI/util/instructions';+import { LexicalEditor } from 'lexical';import {type Accessor,createEffect,@@ -59,6 +62,7 @@ import {onCleanup,type Setter,Show,+ untrack,} from 'solid-js';import { SplitlikeContainer } from '../split-layout/components/SplitContainer';@@ -341,6 +345,42 @@ export function Rightbar(props: {}};+ const [editor, setEditor] = createSignal<LexicalEditor>();+ let borrowedFocus: Element | null = null;+ const returnFocus = () => {+ if (+ borrowedFocus &&+ borrowedFocus.isConnected &&+ borrowedFocus instanceof HTMLElement+ ) {+ borrowedFocus.focus();+ } else {+ globalSplitManager()?.returnFocus();+ }+ }++ createEffect(() => {+ if (props.isBig) {+ borrowedFocus = document.activeElement;+ editor()?.focus();+ } else {+ if (untrack(isRightPanelOpen)) {+ return;+ } else {+ returnFocus();+ }+ }+ });++ createEffect(() => {+ if (isRightPanelOpen()) {+ borrowedFocus = document.activeElement;+ editor()?.focus();+ } else {+ returnFocus();+ }+ });+return (<DragDropWrapperclass="relative flex flex-col size-full select-none"@@ -382,6 +422,7 @@ export function Rightbar(props: {showActiveTabsonSend={props.onSend}onStop={stopGenerating}+ captureEditor={setEditor}/></div></div>diff --git a/js/app/packages/app/component/split-layout/SplitLayout.tsx b/js/app/packages/app/component/split-layout/SplitLayout.tsxindex 2a7077cf8a..7ed0d75822 100644--- a/js/app/packages/app/component/split-layout/SplitLayout.tsx+++ b/js/app/packages/app/component/split-layout/SplitLayout.tsx@@ -41,6 +41,15 @@ type SplitLayoutContainerProps = {setManager: Setter<SplitManager | undefined>;};+function getParentSplitId(element: Element | null) {+ if (!element || !element.isConnected) return null;+ const splitParent = element.closest('[data-split-container]');+ if (!splitParent) return null;+ const splitId = splitParent.getAttribute('data-split-id');+ if (!splitId) return null;+ return splitId as SplitId;+}+/*** Creates an effect that syncs the layout manager with the URL.*@@ -95,9 +104,24 @@ function createSplitFocusTracker(props: {const DEBOUNCE = 100;const activeSplitId = () => props.splitManager.activeSplitId();- const isElementInPanel = (panelId: SplitId, element: Element): boolean => {+ const currentSplitsIds = () => new Set(props.splits().map((s) => s.id));+ const lastFocusedChildBySplitId: Map<SplitId, HTMLElement | null> = new Map();+ createEffect(+ on(currentSplitsIds, (ids) => {+ for (const key of lastFocusedChildBySplitId.keys()) {+ if (!ids.has(key)) {+ lastFocusedChildBySplitId.delete(key);+ }+ }+ })+ );++ const isElementInPanel = (+ panelId: SplitId,+ element: Element | null+ ): boolean => {const panelRef = props.panelRefs.get(panelId);- if (!panelRef) return false;+ if (!panelRef || element === null) return false;return panelRef === element || panelRef.contains(element);};@@ -108,21 +132,30 @@ function createSplitFocusTracker(props: {return;}+ // return if panel has a child already with focus.+ if (splitPanelRef.contains(document.activeElement)) return;++ // look for a child to return focus to.+ const child = lastFocusedChildBySplitId.get(id);+ if (child && child.isConnected) {+ child.focus();+ return;+ }+splitPanelRef.focus();};const activateFocusedSplit = (element: Element) => {- const activeSplitId_ = activeSplitId();- if (!activeSplitId_) return;+ const splitId = activeSplitId();+ if (!splitId) return;- const doesActiveSplitHaveFocus = isElementInPanel(activeSplitId_, element);+ const doesActiveSplitHaveFocus = isElementInPanel(splitId, element);if (doesActiveSplitHaveFocus) {return;}let splitWithFocus: SplitId | undefined;-for (const split of props.splits()) {if (isElementInPanel(split.id, element)) {splitWithFocus = split.id;@@ -178,7 +211,13 @@ function createSplitFocusTracker(props: {(newEvent) => {if (focusTimeout) {clearTimeout(focusTimeout);- clearTimeout(activateTimeout);+ }+ if (newEvent.type === SplitEvent.ReturnFocus) {+ const id = props.splitManager.activeSplitId();+ if (id) {+ focusSplitById(id);+ }+ return;}focusTimeout = setTimeout(() => {focusFromEvent(newEvent);@@ -194,11 +233,19 @@ function createSplitFocusTracker(props: {clearTimeout(activateTimeout);}if (!element) return;++ const parentId = getParentSplitId(element);+ if (parentId && element instanceof HTMLElement) {+ lastFocusedChildBySplitId.set(parentId, element);+ }+activateTimeout = setTimeout(() => {activateFocusedSplit(element);}, DEBOUNCE);}));++ return { focusSplitById };}export function SplitLayoutContainer(props: SplitLayoutContainerProps) {@@ -209,6 +256,13 @@ export function SplitLayoutContainer(props: SplitLayoutContainerProps) {// Store a ref to each panel by idlet panelRefs = new Map<SplitId, HTMLDivElement>();+ createEffect(+ on(splitManager.events, (event) => {+ if (event.type === SplitEvent.Remove) {+ panelRefs.delete(event.splitId);+ }+ })+ );const splits = createMemo(splitManager.splits);@@ -374,7 +428,6 @@ function SplitPanel(props: SplitPanelProps) {setPanelRef(ref);props.setPanelRef(ref);attachHotKeys(ref);- ref.focus();}}><Dynamic component={props.split.mount.element} />diff --git a/js/app/packages/app/component/split-layout/components/SplitContainer.tsx b/js/app/packages/app/component/split-layout/components/SplitContainer.tsxindex 192d65f28b..47cc271950 100644--- a/js/app/packages/app/component/split-layout/components/SplitContainer.tsx+++ b/js/app/packages/app/component/split-layout/components/SplitContainer.tsx@@ -7,6 +7,7 @@ import {createMemo,createSignal,on,+ onCleanup,type ParentProps,type Setter,Show,@@ -96,6 +97,7 @@ export function SplitlikeContainer() {const [panel, setPanel] = createSignal<HTMLDivElement | null>(null);const panelSize = createElementSize(panel);+return (<SplitModalProvider><SplitDrawerGroup panelSize={panelSize} contentOffsetTop={() => 0}>diff --git a/js/app/packages/app/component/split-layout/layoutManager.ts b/js/app/packages/app/component/split-layout/layoutManager.tsindex 85714a67a1..a51cf0a79d 100644--- a/js/app/packages/app/component/split-layout/layoutManager.ts+++ b/js/app/packages/app/component/split-layout/layoutManager.ts@@ -65,6 +65,7 @@ export enum SplitEvent {Insert,Remove,ContentChange,+ ReturnFocus,}export type SplitEventPayload = {@@ -83,6 +84,7 @@ export type SplitEventPayload = {newContent: SplitContent;previousContent: SplitContent;};+ [SplitEvent.ReturnFocus]: void;};export type SplitEventWithType =@@ -90,7 +92,10 @@ export type SplitEventWithType =| ({ type: SplitEvent.Remove } & SplitEventPayload[SplitEvent.Remove])| ({type: SplitEvent.ContentChange;- } & SplitEventPayload[SplitEvent.ContentChange]);+ } & SplitEventPayload[SplitEvent.ContentChange])+ | ({+ type: SplitEvent.ReturnFocus;+ } & SplitEventPayload[SplitEvent.ReturnFocus]);export type SplitManager = {readonly splits: Accessor<ReadonlyArray<SplitState>>;@@ -139,6 +144,9 @@ export type SplitManager = {/** Get a reactive string that is the display name of the active split. */tabTitle: () => string | undefined;++ /** A function to return focus to the most recent split. */+ returnFocus: () => void;} & UrlCapabilities;export type SplitHandle = {@@ -645,5 +653,6 @@ export function createSplitLayout(unSpotlightSplit,toggleSpotlightSplit,tabTitle,+ returnFocus: () => dispatchEvent(SplitEvent.ReturnFocus, undefined),};}diff --git a/js/app/packages/app/signal/focus.ts b/js/app/packages/app/signal/focus.tsindex 8e9cee11ba..ae048facd9 100644--- a/js/app/packages/app/signal/focus.ts+++ b/js/app/packages/app/signal/focus.ts@@ -1,5 +1,46 @@-import { createSignal } from 'solid-js';+import {+ createEffect,+ createSignal,+ getOwner,+ on,+ onCleanup,+ onMount,+} from 'solid-js';-export const [activeElement, setActiveElement] = createSignal<Element | null>(+const [rawActiveElement, setRawActiveElement] = createSignal<Element | null>(document.activeElement);++const [dirty, setDirty] = createSignal(undefined, { equals: () => false });++export function mountGlobalFocusListener(withDebug?: boolean) {+ const owner = getOwner();+ if (!owner) {+ console.error(+ 'No owner. mountGlobalFocusListener should be called once - from within the component tree.'+ );+ return;+ }+ onMount(() => {+ document.addEventListener('focusin', setDirty);+ document.addEventListener('focusout', setDirty);+ onCleanup(() => {+ document.removeEventListener('focusin', setDirty);+ document.removeEventListener('focusout', setDirty);+ });+ });++ createEffect(+ on(dirty, () => {+ setRawActiveElement(document.activeElement);+ })+ );+ if (withDebug) {+ createEffect(() => {+ console.trace('### ACTIVE ELEMENT', rawActiveElement());+ });+ }+}++export const activeElement = rawActiveElement;+export const recheckFocus = () => setDirty();diff --git a/js/app/packages/block-channel/component/MarkdownArea.tsx b/js/app/packages/block-channel/component/MarkdownArea.tsxindex be8350b822..58f435e140 100644--- a/js/app/packages/block-channel/component/MarkdownArea.tsx+++ b/js/app/packages/block-channel/component/MarkdownArea.tsx@@ -20,6 +20,7 @@ import {mentionsPlugin,NODE_TRANSFORM,type NodeTransformType,+ registerRootEventListener,type SelectionData,tabIndentationPlugin,tableCellResizerPlugin,@@ -328,6 +329,14 @@ function MarkdownArea(props: MarkdownAreaProps & ConsumableMarkdownAreaProps) {));+ // better focus in handling. preserves selection on regain focus!+ autoRegister(+ registerRootEventListener(editor, 'focusin', (e) => {+ e.preventDefault();+ editor.focus();+ })+ );+return (<LexicalWrapperContext.Provider value={props.lexicalWrapper}><div class="relative w-full min-h-8">diff --git a/js/app/packages/block-md/component/MarkdownEditor.tsx b/js/app/packages/block-md/component/MarkdownEditor.tsxindex 1438a60369..fceddfcdbb 100644--- a/js/app/packages/block-md/component/MarkdownEditor.tsx+++ b/js/app/packages/block-md/component/MarkdownEditor.tsx@@ -139,7 +139,11 @@ import { debounce, throttle } from '@solid-primitives/scheduled';import { useSearchParams } from '@solidjs/router';import { createDroppable, useDragDropContext } from '@thisbeyond/solid-dnd';import { normalizeEnterPlugin } from 'core/component/LexicalMarkdown/plugins/normalize-enter/';-import { lazyRegister } from 'core/component/LexicalMarkdown/plugins/shared/utils';+import {+ autoRegister,+ lazyRegister,+ registerRootEventListener,+} from 'core/component/LexicalMarkdown/plugins/shared/utils';import { createMethodRegistration } from 'core/orchestrator';import { $getRoot, $isElementNode, type EditorState } from 'lexical';import {@@ -657,6 +661,14 @@ export function MarkdownEditor() {});});+ // better focus in handling. preserves selection on regain focus!+ autoRegister(+ registerRootEventListener(editor, 'focusin', (e) => {+ e.preventDefault();+ editor.focus();+ })+ );+const additionalCleanups: Array<() => void> = [];onCleanup(() => {@@ -1228,6 +1240,14 @@ 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.tsxindex ba8d86da8d..017a0997f2 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/Limport {autoRegister,type EnhancedSelection,+ registerRootEventListener,} from '@core/component/LexicalMarkdown/plugins';import {HIGHLIGHT_SELECTED_NODES,@@ -174,6 +175,9 @@ export function MarkdownPopup(props: {});}}+ }),+ registerRootEventListener(editor, 'focusout', () => {+ setPopupVisible(false);}));diff --git a/js/app/packages/core/component/AI/component/input/useChatInput.tsx b/js/app/packages/core/component/AI/component/input/useChatInput.tsxindex 5a4e978478..47b017d660 100644--- a/js/app/packages/core/component/AI/component/input/useChatInput.tsx+++ b/js/app/packages/core/component/AI/component/input/useChatInput.tsx@@ -21,6 +21,7 @@ import { isMobileWidth } from '@core/mobile/mobileWidth';import PlusIcon from '@icon/regular/plus.svg';import XIcon from '@icon/regular/x.svg';import { createCallback } from '@solid-primitives/rootless';+import { LexicalEditor } from 'lexical';import type { Accessor, Component, Setter } from 'solid-js';import { createEffect, createSignal, Match, Show, Switch } from 'solid-js';import { ActiveTabAttachment } from './ActiveTabAttachment';@@ -41,6 +42,7 @@ export type ChatInputProps = {onStop?: () => void;isPersistent?: boolean;showActiveTabs?: boolean;+ captureEditor?: (editor: LexicalEditor) => void;};type ChatInputInternalProps = {@@ -126,6 +128,7 @@ export function useChatInput(}function ChatInput(props: ChatInputInternalProps) {+ console.log('CHAT INPUT', props);let containerRef!: HTMLDivElement;const generating = props.isGenerating ?? (() => false);const toolsetSignal = createSignal<ToolSet>({ type: 'all' });@@ -190,15 +193,12 @@ function ChatInput(props: ChatInputInternalProps) {<divid="chat-input"ref={containerRef}- class="relative flex-1 flex flex-col items-center sm:self-center bg-input border-t border-l border-r sm:border border-edge min-h-26 max-h-50 justify-between"+ class="relative flex-1 flex flex-col items-center sm:self-center bg-input border-t border-l border-r sm:border border-edge min-h-26 max-h-50 justify-between focus-within:bracket-offset-2"><div class="relative w-full z-0 pt-2 px-4 flex-1 overflow-hidden"><divid="chat-input-text-area"- class={`- transition-all duration-150 rounded-md- w-full h-full text-base sm:text-sm text-ink- `}+ class="rounded-md w-full h-full text-base sm:text-sm text-ink"><props.markdown.MarkdownAreaonEnter={handleEnter}@@ -206,6 +206,7 @@ function ChatInput(props: ChatInputInternalProps) {history={availableAttachments}dontFocusOnMount={isMobileWidth()}onPasteFile={props.uploadQueue.upload}+ captureEditor={props.captureEditor}/></div></div>diff --git a/js/app/packages/core/component/AI/component/input/useChatMarkdownArea.tsx b/js/app/packages/core/component/AI/component/input/useChatMarkdownArea.tsxindex 48ea081527..2c0a0aac8e 100644--- a/js/app/packages/core/component/AI/component/input/useChatMarkdownArea.tsx+++ b/js/app/packages/core/component/AI/component/input/useChatMarkdownArea.tsx@@ -24,6 +24,7 @@ import {mentionsPlugin,NODE_TRANSFORM,type NodeTransformType,+ registerRootEventListener,type SelectionData,tabIndentationPlugin,tableCellResizerPlugin,@@ -57,6 +58,7 @@ import {COMMAND_PRIORITY_HIGH,FORMAT_TEXT_COMMAND,KEY_ENTER_COMMAND,+ LexicalEditor,type TextFormatType,} from 'lexical';import {@@ -222,6 +224,7 @@ export type ConsumableChatMarkdownAreaProps = {portalScope?: PortalScope;onFocusLeaveStart?: (e: KeyboardEvent) => void;onFocusLeaveEnd?: (e: KeyboardEvent) => void;+ captureEditor?: (editor: LexicalEditor) => void;};function MarkdownArea(@@ -260,6 +263,7 @@ function MarkdownArea(createEffect(on(props.mountRef, (ref) => {+ console.log('EFFECT ON REF', ref);if (!ref) return;editor.setRootElement(ref);editor.setEditable(true);@@ -274,6 +278,10 @@ function MarkdownArea(}));+ if (props.captureEditor) {+ props.captureEditor(editor);+ }+createEffect(() => {props.onChange?.(props.markdownState());});@@ -383,6 +391,14 @@ function MarkdownArea();}+ // better focus in handling. preserves selection on regain focus!+ autoRegister(+ registerRootEventListener(editor, 'focusin', (e) => {+ e.preventDefault();+ editor.focus();+ })+ );+onCleanup(() => {cleanup();});diff --git a/js/app/packages/core/component/LexicalMarkdown/component/core/MarkdownTextarea.tsx b/js/app/packages/core/component/LexicalMarkdown/component/core/MarkdownTextarea.tsxindex 642151e3ae..dbd61333fb 100644--- a/js/app/packages/core/component/LexicalMarkdown/component/core/MarkdownTextarea.tsx+++ b/js/app/packages/core/component/LexicalMarkdown/component/core/MarkdownTextarea.tsx@@ -32,6 +32,7 @@ import {type ItemMention,keyboardFocusPlugin,mentionsPlugin,+ registerRootEventListener,type SelectionData,selectionDataPlugin,tabIndentationPlugin,@@ -122,6 +123,14 @@ export function MarkdownTextarea(props: MarkdownTextareaProps) {}});+ // better focus in handling. preserves selection on regain focus!+ autoRegister(+ registerRootEventListener(editor, 'focusin', (e) => {+ e.preventDefault();+ editor.focus();+ })+ );+createEffect(() => {editor.setEditable(props.editable());});diff --git a/js/app/packages/core/component/LexicalMarkdown/plugins/popup/popupPlugin.ts b/js/app/packages/core/component/LexicalMarkdown/plugins/popup/popupPlugin.tsindex 2e0fdbeafe..3a8fcc1c5c 100644--- a/js/app/packages/core/component/LexicalMarkdown/plugins/popup/popupPlugin.ts+++ b/js/app/packages/core/component/LexicalMarkdown/plugins/popup/popupPlugin.ts@@ -165,7 +165,6 @@ function $updateDomRectInSelction(}function registerPopupPlugin(editor: LexicalEditor, props: PopupPluginProps) {- console.log('register popup ', props);let cachedLastSelection: EnhancedSelection | null = null;function $validateAndSetSelection(selection: BaseSelection) {@@ -195,11 +194,9 @@ function registerPopupPlugin(editor: LexicalEditor, props: PopupPluginProps) {if (!selection) return false;const enhancedSelection = $validateAndSetSelection(selection);- console.log({ enhancedSelection });if (!enhancedSelection) return false;const success = props.setIsPopupVisible(true);- console.log({ success });if (success) {cachedLastSelection = enhancedSelection;props.setSelection({ ...enhancedSelection });diff --git a/js/app/packages/core/component/LexicalMarkdown/plugins/shared/utils.ts b/js/app/packages/core/component/LexicalMarkdown/plugins/shared/utils.tsindex 01400fb672..d38337bc2e 100644--- a/js/app/packages/core/component/LexicalMarkdown/plugins/shared/utils.ts+++ b/js/app/packages/core/component/LexicalMarkdown/plugins/shared/utils.ts@@ -177,3 +177,23 @@ export function registerMutationListener(}});}++/**+ * Wrapper on registerRootListener for nicer ergo on adding a single event+ * listener to the root div of a lexical editor.+ */+export function registerRootEventListener<K extends keyof HTMLElementEventMap>(+ editor: LexicalEditor,+ type: K,+ listener: (event: HTMLElementEventMap[K]) => void,+ options?: boolean | AddEventListenerOptions+) {+ return editor.registerRootListener((root, prevRoot) => {+ if (prevRoot) {+ prevRoot.removeEventListener(type, listener, options);+ }+ if (root) {+ root.addEventListener(type, listener, options);+ }+ });+}diff --git a/js/app/packages/core/signal/layout/bigChat.ts b/js/app/packages/core/signal/layout/bigChat.tsindex 68cfa52265..81405a1609 100644--- a/js/app/packages/core/signal/layout/bigChat.ts+++ b/js/app/packages/core/signal/layout/bigChat.ts@@ -1,31 +1,14 @@-import { useLocation, useNavigate } from '@solidjs/router';-import { type Accessor, createMemo, type Setter } from 'solid-js';+import { useSearchParams } from '@solidjs/router';+import type { Accessor, Setter } from 'solid-js';function useQueryBool(param: string): [Accessor<boolean>, Setter<boolean>] {- const location = useLocation();- const navigate = useNavigate();-- const value = createMemo(() => {- const params = new URLSearchParams(location.search);- return params.get(param) === 'true';- });-+ const [searchParams, setSearchParams] = useSearchParams();+ const value = () => Boolean(searchParams[param]);const setValue: Setter<boolean> = (next) => {const current = value();const resolved = typeof next === 'function' ? next(current) : next;-- const params = new URLSearchParams(location.search);- if (resolved) params.set(param, 'true');- else params.delete(param);-- navigate(`${location.pathname.replace('/app/', '')}?${params.toString()}`, {- replace: true,- scroll: false,- });-- return resolved;+ setSearchParams({ [param]: resolved || undefined });};-return [value, setValue] as const;}diff --git a/js/app/packages/core/util/createControlledOpenSignal.ts b/js/app/packages/core/util/createControlledOpenSignal.tsindex fa48ed2e43..9756e517fa 100644--- a/js/app/packages/core/util/createControlledOpenSignal.ts+++ b/js/app/packages/core/util/createControlledOpenSignal.ts@@ -16,7 +16,7 @@ export const createControlledOpenSignal = (value?: boolean) => {console.info('Borrowing focus from', previouslyFocusedElement);} else {// has to fire two tasks after to prevent Kobalte menus stealing focus and opening menu on up/down keypress- setTimeout(() => {+ // i guess not - until it does once againsetTimeout(() => {if (previouslyFocusedElement instanceof HTMLElement) {if (previouslyFocusedElement.isConnected) {@@ -36,7 +36,6 @@ export const createControlledOpenSignal = (value?: boolean) => {}}}- });});}};