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(md): dispatch layout shift events from properties front matter (#257)
Seamus997e187c873b
diff --git a/js/app/packages/block-md/comments/commentLayout.ts b/js/app/packages/block-md/comments/commentLayout.tsindex ef08ce9121..4a173ca88f 100644--- a/js/app/packages/block-md/comments/commentLayout.ts+++ b/js/app/packages/block-md/comments/commentLayout.ts@@ -136,10 +136,10 @@ createBlockEffect(() => {autoRegister(md.editor.registerUpdateListener(() => {throttledUpdate();- })+ }),+ registerInternalLayoutShiftListener(md.editor, throttledUpdate),+ registerEditorWidthObserver(md.editor, throttledUpdate));- registerInternalLayoutShiftListener(md.editor, throttledUpdate);- registerEditorWidthObserver(md.editor, throttledUpdate);}});diff --git a/js/app/packages/block-md/component/FrontMatterProperties.tsx b/js/app/packages/block-md/component/FrontMatterProperties.tsxindex 275bc87a44..2cda27a8db 100644--- a/js/app/packages/block-md/component/FrontMatterProperties.tsx+++ b/js/app/packages/block-md/component/FrontMatterProperties.tsx@@ -2,6 +2,7 @@ import { useBlockId } from '@core/block';import {$getPinnedProperties,ADD_PINNED_PROPERTY_COMMAND,+ dispatchInternalLayoutShift,REMOVE_PINNED_PROPERTY_COMMAND,} from '@core/component/LexicalMarkdown/plugins';import { Modals } from '@core/component/Properties/component/modal';@@ -13,11 +14,14 @@ import CaretRight from '@icon/bold/caret-right-bold.svg';import EyeSlash from '@icon/bold/eye-slash-bold.svg';import LoadingSpinner from '@icon/regular/spinner.svg';import type { EntityType } from '@service-properties/generated/schemas/entityType';+import { createElementSize } from '@solid-primitives/resize-observer';import {createEffect,createMemo,createSignal,type JSX,+ on,+ onCleanup,Show,} from 'solid-js';import {@@ -36,6 +40,11 @@ interface FrontMatterPropertiesProps {export function FrontMatterProperties(props: FrontMatterPropertiesProps) {const blockId = useBlockId();const mdData = mdStore.get; // Access block store at component level+ const layoutShift = () => {+ if (mdData.editor) {+ dispatchInternalLayoutShift(mdData.editor);+ }+ };const { properties, isLoading, error, refetch } = useEntityProperties(blockId,@@ -60,6 +69,7 @@ export function FrontMatterProperties(props: FrontMatterPropertiesProps) {const toggleExpanded = () => {setFrontMatterPreferenceForDoc(blockId, !isExpanded());+ layoutShift();};// Track pinned property IDs from Lexical - reactively updates on editor state changes@@ -84,10 +94,7 @@ export function FrontMatterProperties(props: FrontMatterPropertiesProps) {});});-- return () => {- unregister();- };+ onCleanup(unregister);});// Filter properties to show metadata/system properties and pinned ones@@ -124,9 +131,14 @@ export function FrontMatterProperties(props: FrontMatterPropertiesProps) {}};+ const [containerRef, setContainerRef] = createSignal<HTMLDivElement>();+ const containerSize = createElementSize(containerRef);+ const height = () => containerSize.height;+ createEffect(on(height, layoutShift));+return (<Show when={!error()} fallback={props.fallback}>- <div class="mt-6 mb-6">+ <div class="mt-6 mb-6" ref={setContainerRef}><PropertiesProviderentityType={'DOCUMENT' as EntityType}canEdit={props.canEdit}diff --git a/js/app/packages/core/component/LexicalMarkdown/plugins/shared/utils.ts b/js/app/packages/core/component/LexicalMarkdown/plugins/shared/utils.tsindex d38337bc2e..c9b8b3a526 100644--- a/js/app/packages/core/component/LexicalMarkdown/plugins/shared/utils.ts+++ b/js/app/packages/core/component/LexicalMarkdown/plugins/shared/utils.ts@@ -1,6 +1,8 @@import { mergeRegister } from '@lexical/utils';import {+ COMMAND_PRIORITY_NORMAL,type CommandListenerPriority,+ createCommand,DELETE_CHARACTER_COMMAND,DELETE_LINE_COMMAND,DELETE_WORD_COMMAND,@@ -132,6 +134,8 @@ export function autoRegister(...fns: Array<() => void>) {onCleanup(cleanup);}+const LAYOUT_SHFIT_COMMAND = createCommand<void>('LAYOUT_SHIFT_COMMAND');+/*** Register a callback to run whenever a non-mutating layout shift occurs – like when* a decorator changes size without writing to the lexical state.@@ -143,14 +147,14 @@ export function registerInternalLayoutShiftListener(editor: LexicalEditor,listener: () => void) {- return editor.registerRootListener((root, prevRoot) => {- if (prevRoot) {- prevRoot.removeEventListener('internal-layout-shift', listener);- }- if (root) {- root.addEventListener('internal-layout-shift', listener);- }- });+ return editor.registerCommand(+ LAYOUT_SHFIT_COMMAND,+ () => {+ listener();+ return false;+ },+ COMMAND_PRIORITY_NORMAL+ );}/**@@ -158,9 +162,7 @@ export function registerInternalLayoutShiftListener(* @param editor*/export function dispatchInternalLayoutShift(editor: LexicalEditor) {- editor- .getRootElement()- ?.dispatchEvent(new CustomEvent('internal-layout-shift'));+ editor.dispatchCommand(LAYOUT_SHFIT_COMMAND, undefined);}/**